Problem solve Get help with specific problems with your technologies, process and projects.

Who said you can't write to file from CL?

Here you'll learn how to write to a specified Physical File from within CL.

Here you'll learn how to write to a specified physical file from within CL. I have added the command WRTREC with parameters of DATA (what you want to write to the file.) And TOFILE with TOLIB naming the file you want to write to. You can amend or enhance the CL to your hearts content as the basics work fine.


  
/***********************************************************************/  
/* PGM    - WRTRECCPP                                                  */  
/* AUTHOR - CLIVE GRIFFITHS                                            */  
/* DESC   - WRITE A RECORD TO SEPCIFIED FILE                           */  
/* PARMS  - &RECORD 100 CHARACTER - DATA TO BE WRITTEN TO FILE         */  
/*        - &TOLIB 10 CHARACTER   - LIBRARY NAME OF FILE TO BE WRITTEN */  
/*        - &TOFILE 10 CHARACTER  - NAME OF FILE TO BE WRITTEN TO      */  
/***********************************************************************/  
PGM (&RECORD &TOFILE &TOLIB)                                               
DCL &RECORD *CHAR 100                                                      
DCL &TOFILE *CHAR 10                                                       
DCL &TOLIB  *CHAR 10                                                       
DCL &NBRCURREC *DEC 10 0                                                   
DCL &RCDNBR *DEC 10 0                                                      
CRTPF QTEMP/QMHMDT RCDLEN(100)                                             
MONMSG CPF0000                                                             
SNDPGMMSG  MSG(&RECORD)                                                    
DSPJOBLOG  OUTPUT(*OUTFILE) OUTFILE(QTEMP/TEMPF)                           
CPYF FROMFILE(QTEMP/TEMPF) TOFILE(QTEMP/QMHMDT) +                             
  MBROPT(*ADD) NBRRCDS(1) INCREL((*IF QMHMDT *EQ &RECORD)) FMTOPT(*MAP *DROP) 
RTVMBRD FILE(QTEMP/QMHMDT) NBRCURRCD(&NBRCURREC)                              
CPYF FROMFILE(QTEMP/QMHMDT) TOFILE(&TOLIB/&TOFILE) MBROPT(*ADD) +             
  FROMRCD(&NBRCURREC) FMTOPT(*NOCHK)                                          
ENDPGM                                                                        


/***********************************************************************/ 
/* CMD    - WRTREC  - COMMAND FOR CPP WRTRECCPP                        */ 
/* AUTHOR - CLIVE GRIFFITHS                                            */ 
/* DESC   - WRITE A RECORD TO SEPCIFIED FILE                           */ 
/* PARMS  - DATA 100 CHARACTER - DATA TO BE WRITTEN TO FILE            */ 
/*        - TOFILE 10 CHARACTER  - NAME OF FILE TO BE WRITTEN TO       */ 
/*        - TOLIB 10 CHARACTER   - LIBRARY NAME OF FILE TO BE WRITTEN  */ 
/***********************************************************************/ 
CMD PROMPT                                                                
             PARM       KWD(DATA) TYPE(*CHAR) LEN(100) +                  
                          CHOICE('Enter data to be written') +            
                          PROMPT(DATA)                                    
             PARM       KWD(TOFILE) TYPE(*NAME) LEN(10) +                 
                          CHOICE('Target file name') PROMPT(TOFILE)       
             PARM       KWD(TOLIB) TYPE(*NAME) LEN(10) +                  
                          CHOICE('Library name') PROMPT(TOLIB)    

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: Tips, tutorials and more.

Ask your systems management questions--or help out your peers by answering them--in our live discussion forums.

Read this Search400.com Featured Topic: Managing your iSeries.

Ask the Experts yourself: Our systems management gurus are waiting to answer your technical questions.

Dig Deeper on Performance

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close