Pages

Saturday, June 11, 2022

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. 

No comments:

Post a Comment

Numeric data types in Python

Numeric Data types There are three different data types to store numeric data.  int float complex int (integer) Data type 'int' is u...