Skip to main content

Working with Save Files - IBM i

Save files (SAVF)

Save file is a type of file in IBM  which allows saving objects (files, programs, save files etc...) and libraries. 

Creating a save file

CRTSAVF (Create Save File) is the command to create a save file. 

CRTSAVF FILE(<library name>/<save file name>) TEXT(<description>)

E.g.:

Create Save File (CRTSAVF)

Saving objects/library into a save file

SAVOBJ (Save Object) is the command to save objects into a save file. 

SAVOBJ OBJ(<objects to save>) LIB(<library where objects are present>) DEV(*SAVF) SAVF(<save file name>)

E.g.: 

Save objects into a save file (SAVOBJ)

In the above command, 
  • OBJ (Objects) parameter is used to specify the objects that need to be saved to a save file. 
  • LIB (Library) parameter is used to specify the library from which objects need to be saved. 
  • DEV (Device) parameter is used to specify the device type (*SAVF for saving into save file).
  • OBJTYPE (Object types) parameter is used to specify what object types are to be considered for saving into save file. 
    • This is very useful when we have different objects with same name and different type (*FILE, *PGM etc...) in the same library. 
    • By default *ALL is considered and all objects with the name specified against OBJ parameter are saved. 
  • SAVF (Save file) parameter is used to specify the save file name and library to which objects are saved.
These are the mandatory parameters need to enter while saving an object. There are few other additional parameters, below are some of them. 
  • TGTRLS (Target Release) parameter is used to specify the release of the operating system on which objects are to be restored to and use the objects. 
    • By default *CURRENT is considered and objects are saved with the current system's OS release. And, objects cannot be restored to any other system which is lower OS release than current system. 
  • SELECT (Select) parameter is used to Include or Omit the objects from the list of objects specified against OBJ parameter. 
  • DTACPR (Data Compression) is used to specify whether data compression is used or not.
Above command is used to save objects into a save file. There is a different command SAVLIB (Save Library), Most of the parameters of this command are same except that SAVOBJ accepts object names and object types and SAVLIB accepts library name and saves the whole library instead. 

SAVLIB LIB(<library to save>) DEV(*SAVF) SAVF(<save file name>)

E.g.:

Save library (SAVLIB) into save file

We often notice a message like 'Save file TESTSAVF in REDDYP1 already contains data. (C G)
when we run SAVOBJ or SAVLIB. This is because the save file already has the data (possibly from the SAVOBJ or SAVLIB run earlier). 

Save library into save file

Valid reply values are - 
  • C - Cancel processing, it will cancel the processing of SAVOBJ or SAVLIB command that has been run. 
  • G - Clear file and continue processing, it will clear the data already present in the save file and continue saving objects/library to the save file. 

Display Save File (DSPSAVF)

In the above example, In order to take option 'C' or 'G', we should know what's already in the save file so we can decide if it can be cleared or not. 

DSPSAVF (Display Save File) can be used to display what objects/library is saved into the save file. 

DSPSAVF FILE(<library name>/<save file name>)

E.g.: 

Display Save file (DSPSAVF)

We have one other parameter 'OUTPUT' which is '*' by default. Using '*' would display the contents of the save file on the screen. Other valid option is '*PRINT' which prints the contents of the save file into spool file. 

Restore Objects/Library from Save file

RSTOBJ (Restore Object) is the command to restore the objects saved in a save file.

RSTOBJ OBJ(<Objects to restore>) SAVLIB(<Library objects were saved from>) DEV(*SAVF) SAVF(<Save file name>) RSTLIB(<Library objects to be restored into>)

E.g.:

Rest Objects from Save file (RSTOBJ) - IBM i

In the above command, 
  • Objects (OBJ) parameter is used to specify the objects need to be restored from the save file. *ALL can be specified to restore all the objects saved, generic* (E.g.: TEST* would consider all objects starting with TEST) to restore objects starting specific text or list of object names can be specified. 
  • Saved Library (SAVLIB) parameter is used to specify the library name from which objects were saved into save file. If not sure, this can be found by using DSPSAVF command. 
  • Object Types (OBJTYPE) parameter is used to specify the objects of specific types that are to be restored from save file. *ALL is the default and restores all object types matching with OBJ.
  • Save File (SAVF) parameter is used to specify the save file name and library. 
One thing to note here is, by using the above command objects are restored into the same library from which objects were saved. This is because of the RSTLIB (Restore to library).

Default value for RSTLIB parameter is *SAVLIB which indicates to restore the objects into the same library it was saved from. For various reasons, we may need to restore the objects to a different library. In this case, we can specify the corresponding library name against RSTLIB parameter.

RSTLIB parameter in RSTOBJ

Above command (RSTOBJ) is used to restore objects saved into a save file. 

RSTLIB (Restore Library) command is used if a library was saved into a save file using SAVLIB command.

RSTLIB SAVLIB(<Library Saved>) DEV(*SAVF) SAVF(<Save file name>) RSTLIB(<Restore to library>)

E.g.:

Restore Library (RSTLIB) - IBM i

Similar to RSTOBJ, by default RSTLIB restores the library with the same name as the library saved. RSTLIB parameter to be specified with different library name if objects are to be restored into different library.

Transfer Save file from IBM i to PC

Often it is essential to transfer save file from one IBM i to another IBM i or IBM i to PC. Save file can be transferred from IBM i to PC by using FTP. 

Below is the FTP script required to transfer the save file from IBM i to PC. 

1

2

3

4

5

6

FTP <IBM i System Name>

User

Password

BIN

GET <Library>/<Save file> <Save file name>

QUIT


Open the command line/terminal in order to run the FTP connection with IBM i. 

In the above script,
  • Line - 1: FTP command to be issued followed by IBM i system name or IP address. This establishes a connection with IBM i and prompts for credentials.
  • Lines 2 & 3: IBM i credentials (User & Password) are to be entered. 
  • Line - 4: BIN command to be issued to set the representation type is Binary IMAGE. 
  • Line - 5: GET command to be issued to get the save file from IBM i library and place into PC. 
    • <Library>/<Save file> - IBM i Library name and Save file name
    • <Save file name> - Name save file to be saved with on PC. 
  • Line - 6: QUIT command to be issued to quit the FTP session.

Transfer Save file from PC to IBM i

Below is the FTP script required to transfer save file from PC to IBM i.

1

2

3

4

5

6

FTP <IBM i System Name>

User

Password

BIN

PUT <Save file name> <Library>/<Save file> 

QUIT


Open the command line/terminal in order to run the FTP connection with IBM i. 

In the above script,
  • Line - 1: FTP command to be issued followed by IBM i system name or IP address. This establishes a connection with IBM i and prompts for credentials.
  • Lines 2 & 3: IBM i credentials (User & Password) are to be entered. 
  • Line - 4: BIN command to be issued to set the representation type is Binary IMAGE. 
  • Line - 5: PUT command to be issued to put the save file from PC and place into IBM i Library. 
    • <Save file name> - Name of the save file on PC. 
    • <Library>/<Save file> - IBM i Library name and Save file name.
  • Line - 6: QUIT command to be issued to quit the FTP session.
One thing to note is if the objects were saved into save file for the higher version of the OS, Objects cannot be restored into a system which is on lower OS release (E.g.: If objects were saved for Target Release V7R4, Objects cannot be restored into V7R3 or lower).


If you have any Suggestions or Feedback, Please leave a comment below or use Contact Form. 

Comments

Popular posts from this blog

All about READ in RPGLE & Why we use it with SETLL/SETGT?

READ READ is one of the most used Opcodes in RPGLE. As the name suggests main purpose of this Opcode is to read a record from Database file. What are the different READ Opcodes? To list, Below are the five Opcodes.  READ - Read a Record READC - Read Next Changed Record READE - Read Equal Key Record READP - Read Prior Record READPE - Read Prior Equal Record We will see more about each of these later in this article. Before that, We will see a bit about SETLL/SETGT .  SETLL (Set Lower Limit) SETLL accepts Key Fields or Relative Record Number (RRN) as Search Arguments and positions the file at the Corresponding Record (or Next Record if exact match isn't found).  SETGT (Set Greater Than) SETGT accepts Key Fields or Relative Record Number (RRN) as Search Arguments and positions the file at the Next Record (Greater Than the Key value). Syntax: SETLL SEARCH-ARGUMENTS/KEYFIELDS FILENAME SETGT  SEARCH-ARGUMENTS/KEYFIELDS FILENAME One of the below can be passed as Search Arguments. Key Fiel

What we need to know about CHAIN (RPGLE) & How is it different from READ?

CHAIN READ & CHAIN, These are one of the most used (& useful) Opcodes by any RPG developer. These Opcodes are used to read a record from file. So, What's the difference between CHAIN & READ?   CHAIN operation retrieves a record based on the Key specified. It's more like Retrieving Random record from a Database file based on the Key fields.  READ operation reads the record currently pointed to from a Database file. There are multiple Opcodes that start with READ and all are used to read a record but with slight difference. We will see more about different Opcodes and How they are different from each other (and CHAIN) in another article. Few differences to note.  CHAIN requires Key fields to read a record where as READ would read the record currently pointed to (SETLL or SETGT are used to point a Record).  If there are multiple records with the same Key data, CHAIN would return the same record every time. READE can be used to read all the records with the specified Ke

Extract a portion of a Date/Time/Timestamp in RPGLE - IBM i

%SUBDT Extracting Year, Month, Day, Hour, Minutes, Seconds or Milli seconds of a given Date/Time/Timestamp is required most of the times.  This can be extracted easily by using %SUBDT. BIF name looks more similar to %SUBST which is used to extract a portion of string by passing from and two positions of the original string. Instead, We would need to pass a value (i.e., Date, Time or Timestamp ) and Unit (i.e., *YEARS, *MONTHS, *DAYS, *HOURS, *MINUTES, *SECONDS or *MSECONDS) to %SUBDT.  Valid unit should be passed for the type of the value passed. Below are the valid values for each type. Date - *DAYS, *MONTHS, *YEARS Time - *HOURS, *MINUTES, *SECONDS Timestamp - *DAYS, *MONTHS, *YEARS, *HOURS, *MINUTES, *SECONDS, *MSECONDS Syntax: %SUBDT(value : unit { : digits { : decpos} }) Value and Unit are the mandatory arguments.  Digits and Decimal positions are optional and can only be used with *SECONDS for Timestamp. We can either pass the full form for the unit or use the short form. Below i