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

Update a file from a CL program

I am trying to find a way to update a file from a CL program. I found the following code and wanted to know if it has to be two different programs or could it be just one, since the END program came before the CMD PROMPT portion of the code.

What is CMD PROMPT?

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.

CODE

 
 /***********************************************************************/
 /* 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) 

I am not familiar with this example command but the author is trying to convey two separate types of source members. The first one, (WRTRECCP) is a CL program. The Second source member WRTREC is source for a command and would typically reside in a source file called QCMDSRC. The prompt parameter on the command source usually provides additional text about the command. For instance you could change the first line of this command to be CMD PROMPT ('Write records to a file') It will just give the user a little more info. The CL program is meant to be the command-processing program.

To create this command you would need to do the following steps. CRTCLPGM PGM(MYLIB/WRTRECCP) SRCFILE(MYLIB/QCLSRC)
CRTCMD CMD(MYLIB/WRTREC) PGM(MYLIB/WRTRECCP) SRCFILE(MYLIB/QCMDSRC)

==================================
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.


Dig Deeper on RPG iSeries programming

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close