Copy To Stream File (CPYTOSTMF) in IBM i

This article will explain the use of CPYTOSTMF command in IBM i.
Copy To Stream File CPYTOSTMF in IBM i, database file member, save file, nput/output (I/O) operations, source member, stream file, current working directory, Current Directory, Home Directory, ifs, ifs directory, ifs directories, directory, directories, Absolute IFS path, Relative IFS path, DSPCURDIR command, Current Working Directory, Stream file,ibmi,as400,iseries,systemi, working with ifs,as400 and sql tricks, as400 tutorial, ibmi tutorial, crtsavf, savobj, savlib, wrklnk, ifs, integrated file system, save file, copy save file to the stream file, copy pf to stream file, stmf in ifs as400, ifs ibmi, using cpytostmf command
Copy To Stream File CPYTOSTMF in IBM i

Copy To Stream File (CPYTOSTMF)

The Copy To Stream File (CPYTOSTMF) command copies either a database file member or a save file to a stream file. This command can operate on regular files and on the /dev/null character special file. A regular file is a file that supports the integrated file system input/output (I/O) operations open, read, and write.

Using Copy To Stream File (CPYTOSTMF) to copy database file members to stream file

We would be copying source member APIPGM present at source file DDSTODDL2 in library EASYCLASS1.

                           Work with Members Using PDM                 
                                                                       
 File  . . . . . .   DDSTODDL2                                         
   Library . . . .     EASYCLASS1           Position to  . . . . .     
                                                                       
 Type options, press Enter.                                            
  2=Edit         3=Copy  4=Delete 5=Display       6=Print     7=Rename 
  8=Display description  9=Save  13=Change text  14=Compile  15=Create 
                                                                       
 Opt  Member      Type        Text                                     
      APIPGM      SQLRPGLE    QSQGNDDL API                             
      APIPGM#1    SQLRPGLE    QSQGNDDL API                             
      APIPGM#2    SQLRPGLE    QSQGNDDL API                             
      APIPGM2     SQLRPGLE    QSQGNDDL API                             
      DDLG1       SQL                                                  
      MBR1                                                             
      MBR2                                                             
      MBR3NEW                                                                                                        

CPYTOSTMF command will copy the source member to the IFS stream file CPYTOSTMF1.

                         Copy To Stream File (CPYTOSTMF)                        
                                                                                
 Type choices, press Enter.                                                     
                                                                                
 From file member or save file  . FROMMBR      > '/QSYS.LIB/EASYCLASS1.LIB/DDSTODDL2.FILE/APIPGM.MBR'                                                           
 To stream file . . . . . . . . . TOSTMF       > '/HOME/EASYCLASS/CPYTOSTMF1'   
                                                                                
 Stream file option . . . . . . . STMFOPT        *ADD                           
 Data conversion options  . . . . CVTDTA         *AUTO                          
 Database file CCSID  . . . . . . DBFCCSID       *FILE                          
 Stream file CCSID  . . . . . . . STMFCCSID      *STMF                          
 End of line characters . . . . . ENDLINFMT      *CRLF                          
 Authority  . . . . . . . . . . . AUT            *DFT                                                                                                                     

Here, This command copies the data contained in database file member /QSYS.LIB/EASYCLASS1.LIB/DDSTODD12.FILE/APIPGM.MBR to a stream file named /HOME/EASYCLASS/CPYTOSTMF1 in the current working directory. Also Line-feed followed by carriage-return is appended to the end of each line since we used *CRLF as End of Line character.

 Selection or command          
 ===>                          
                               
 F3=Exit   F4=Prompt   F9=Retri
 F23=Set initial menu          
 Object copied.                

wrklnk CPYTOSTMF1

                            Work with Object Links                        
                                                                          
Directory  . . . . :   /home/EASYCLASS                                    
                                                                          
Type options, press Enter.                                                
  2=Edit   3=Copy   4=Remove   5=Display   7=Rename   8=Display attributes
  11=Change current directory ...                                         
                                                                          
Opt   Object link            Type             Attribute    Text           
      CPYTOSTMF1             STMF
 Browse : /home/EASYCLASS/CPYTOSTMF1                                                     
 Record :       1   of     171 by  18                      Column :    1     62 by 131   
 Control :                                                                               
                                                                                         
....+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....
 ************Beginning of data**************                                             
      * format of Input Tempalate parameter of SQLR0100 format                           
     D SQLR0100        DS                                                                
     D databaseobjectname...                                                             
     D                              258a                                                 
     D databaseobjectlibraryname...                                                      
     D                              258a                                                 
     D databaseobjecttype...                                                             
     D                               10a                                                 
     D databasesourcefilename...                                                         
     D                               10a                                                 
     D databasesourcefilelibraryname...                                                  
     D                               10a                                                 
     D databasesourcefilemembername...                                                   
     D                               10a                                                 
     D severitylevel...                                                                  
     D                               10i 0 INZ(30)                                       
     D replaceoption...                                                                  
     D                                1a   INZ('0')                                      

Using Copy To Stream file (CPYTOSTMF) command to copy save file to stream file

We would be copying save file TESTSAV2 to a stream file SAVF1 using CPYTOSTMF command.

  • First we need to create a save file named TESTSAV2 in library EASYCLASS1 using CL command CRTSAVF.
  • CRTSAVF FILE(EASYCLASS1/TESTSAV2)

    Save file gets created once we execute above CRTSAVF command through IBM i command line.

    File TESTSAV2 created in library EASYCLASS1

    wrkobj EASYCLASS1/TESTSAV2

                                   Work with Objects                             
                                                                                 
     Type options, press Enter.                                                  
       2=Edit authority        3=Copy   4=Delete   5=Display authority   7=Rename
       8=Display description   13=Change description                             
                                                                                 
     Opt  Object      Type      Library     Attribute   Text                     
          TESTSAV2    *FILE     EASYCLASS1  SAVF
  • Save an object or set of objects using command SAVOBJ or save the library using SAVLIB command in the newly created save file named TESTSAV2. Here, supoose we use SAVOBJ command to save only one object EXTPGM5 of type *PGM present in library EASYCLASS1 to the save file TESTSAV2 using following command.
  • SAVOBJ OBJ(EXTPGM5)             
           LIB(EASYCLASS1)          
           DEV(*SAVF)               
           SAVF(EASYCLASS1/TESTSAV2)
           TGTRLS(*CURRENT)

    One object saved in save file TESTSAV2.

    1 objects saved from library EASYCLASS1.

    Use DSPSAVF command to see the objects saved in a save file TESTSAV2.

    dspsavf easyclass1/testsav2

    Display saved objects in a save file

                                Display Saved Objects                   
                                                                        
    Library saved . . . . . . . :   EASYCLASS1                          
                                                                        
    Type Options, press Enter.                                          
      5=Display                                                         
                                                                        
    Opt  Object      Type      Attribute   Owner          Size (K)  Data
         EXTPGM5     *PGM      RPGLE       EASYCLASS           136  YES
  • Execute following CPYTOSTMF command to copy save file TESTSAV2 to the stream file SAVF1 in current directory.
  •                          Copy To Stream File (CPYTOSTMF)                        
                                                                                    
     Type choices, press Enter.                                                     
                                                                                    
     From file member or save file  . FROMMBR      > '/QSYS.LIB/EASYCLASS1.LIB/TESTS
    AV2.FILE'                                                                       
     To stream file . . . . . . . . . TOSTMF       > '/HOME/EASYCLASS/SAVF1'        
                                                                                    
     Stream file option . . . . . . . STMFOPT      > *REPLACE

    Here, this command copies the data contained in save file /QSYS.LIB/EASYCLASS1.LIB/TESTSAV2.FILE to the stream file /HOME/EASYCLASS1/SAVF1.

    Object copied.
  • Browse stream file eing created at the ifs location.
  • wrklnk savf1

    Work with object links

                                 Work with Object Links                        
                                                                               
     Directory  . . . . :   /home/EASYCLASS                                    
                                                                               
     Type options, press Enter.                                                
       2=Edit   3=Copy   4=Remove   5=Display   7=Rename   8=Display attributes
       11=Change current directory ...                                         
                                                                               
     Opt   Object link            Type             Attribute    Text           
           savf1                  STMF

    Take option 5 to display the content of the stream file

     Browse : /home/EASYCLASS/savf1                                                                                                     
     Record :       1   of    1248 by  18                      Column :    1    132 by 131                                              
     Control :                                                                                                                          
                                                                                                                                        
    ....+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+....0....+....1....+....2....+....3. 
     ************Beginning of data**************                                                                                        
    y ÒÜÃøÛ         41G 9009                          ã                                                                                 
                                                                                                                                        
                                                                                                                                        
                                                                                                                            hÂñhJüÍ $ÍÒµ
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                            y ÒÜÃøÛ     
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                            y ÒÜÃøÛ   - 
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                            y ÒÜÃøÛ   Ø 
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
     F3=Exit   F10=Display Hex   F12=Cancel   F15=Services   F16=Repeat find   F19=Left   F20=Right                                     
     Record length of 132 used.

    Post a Comment

    © AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain