You are currently viewing Reading Every Records on CLP – Using Record Format

Reading Every Records on CLP – Using Record Format

At this time I will discuss about reading each record in a file in CLP using the record format in a file. To find out which file format to read, we can use the Display File Field Description (DSPFFD) command.

In CLP, to read a file using the DCLF command first. Automatically all fields in the file become variables in the program that we make. The DSPFFD command is used to find out the record format and fields in the file.

Here is an example:

             DCLF       FILE(SOOLDAT/TESTFILE)                        
             DCL        VAR(&OUTPUT) TYPE(*CHAR) LEN(50)              
 LOOP:       RCVF       RCDFMT(TESTFILE)                              
             MONMSG     MSGID(CPF0864) EXEC(GOTO CMDLBL(EOP))         
             CHGVAR     VAR(&OUTPUT) VALUE('Name :' *CAT &NAME *TCAT +
                          ', Address : ' *CAT &ADDRESS)               
             SNDPGMMSG  MSG(&OUTPUT)                                  
             GOTO       CMDLBL(LOOP)                                  
 EOP:        ENDPGM                                                   

Some notes in the program above:

  1. The file must be declared at the beginning of the program.
  2. All fields in the file that are declared will automatically become variables in the program (without having to declare variables).
  3. In reading files, RCVF commands are needed with a record format in accordance with the declared file.
  4. The concept of reading files is actually like looping each record, so there is a process back to the loop label.

Output result:

Leave a Reply