Now, Get RPG Codes in all three formats only on this website on every RPGLE related programming article.

Fixed, /Free and Fully Free RPG


Using outfiles in CL

Using outfile in CL program.
Using outfiles in CL, outfile in cl, dsppgm, dspobjd, outfile, ovrdbf, dowhile loop, leave, cpf0864, rcvf, monmsg, return, pgm, endpgm, do, enddo, dclf, if, if condition in cl,CRTBNDCL, as400, ibmi, as400 and sql tricks, as400 tutorial, ibmi tutorial
Using outfiles in CL

What is Outfile in CL?

Outfile is used to retain the output information in a file.

  • DSPPGM command does not have outfile support.
  •                             Display Program (DSPPGM)                        
                                                                                
     Type choices, press Enter.                                                 
                                                                                
     Program  . . . . . . . . . . . . PGM            CLPGM4                     
       Library  . . . . . . . . . . .                  EASYCLASS1               
     Output . . . . . . . . . . . . . OUTPUT         *                          
     Detail . . . . . . . . . . . . . DETAIL         *ALL                       
                               + for more values                                
    
                       Specify Value for Parameter OUTPUT 
                                                          
     Type choice, press Enter.                            
                                                          
                                                          
     Output . . . . . . . . . . . . .   *                 
                                                          
       *                                                  
       *PRINT                                             
    
  • On the other hand, DSPOBJD command has the outfile support. So, in this article we will use DSPOBJD command to demonstrate outfile usage in CL programming.
  •                       Display Object Descrioption (DSPOBJD)                 
                                                                               
     Type choices, press Enter.                                                
                                                                               
     Object . . . . . . . . . . . . . OBJ          > CLPF1                     
       Library  . . . . . . . . . . .              >   EASYCLASS1              
     Object type  . . . . . . . . . . OBJTYPE      > *FILE                     
                               + for more values                               
     Detail . . . . . . . . . . . . . DETAIL         *BASIC                    
     ASP device:                      ASPDEV                                   
       Device . . . . . . . . . . . .                *                         
       Search type  . . . . . . . . .                                          
     Output . . . . . . . . . . . . . OUTPUT       > *OUTFILE                 
     File to receive output . . . . . OUTFILE        ABC                       
       Library  . . . . . . . . . . .                  QTEMP                   
     Output member options:           OUTMBR                                   
       Member to receive output . . .                *FIRST                    
       Replace or add records . . . .                *REPLACE                  
    

    CL program using outfile

                  PGM                                                                    
                  DCLF       FILE(ALLOBJPF)                                              
                                                                                         
                  DSPOBJD    OBJ(EASYCLASS1/*ALL) OBJTYPE(*ALL) +                        
                               OUTPUT(*OUTFILE) OUTFILE(QTEMP/ALLOBJPF)                  
                                                                                         
                  OVRDBF     FILE(ALLOBJPF) TOFILE(QTEMP/ALLOBJPF)                       
                                                                                         
                  DOWHILE (1=1)                                                          
                  RCVF                                                                   
                  MONMSG     MSGID(CPF0864) EXEC(LEAVE)                                  
                                                                                         
                  IF         COND(&ODOBTP = '*FILE' *AND &ODOBNM = +                     
                               'CLPF1') THEN(DO)                                         
                  SNDPGMMSG  MSG(FOUND)                                                  
                  RETURN                                                                 
                  ENDDO                                                                  
                  ENDDO                                                                  
                  ENDPGM                                                                 
    
    

    Explanation of the above code

    DCLF       FILE(ALLOBJPF)

    This DCLF command is used to declare file named ALLOBJPF in cl program.

    DSPOBJD    OBJ(EASYCLASS1/*ALL) OBJTYPE(*ALL) +                        
    OUTPUT(*OUTFILE) OUTFILE(QTEMP/ALLOBJPF)

    This DSPOBJD command will create the outfile named ALLOBJPF in QTEMP library containing all the objects information from library EASYCLASS1.

    OVRDBF     FILE(ALLOBJPF) TOFILE(QTEMP/ALLOBJPF)

    This OVRDBF command will override the file ALLOBJPF from QTEMP library.

                  DOWHILE (1=1)                                                          
                  RCVF                                                                   
                  MONMSG     MSGID(CPF0864) EXEC(LEAVE)                                  
                                                                                         
                  IF         COND(&ODOBTP = '*FILE' *AND &ODOBNM = +                     
                               'CLPF1') THEN(DO)                                         
                  SNDPGMMSG  MSG(FOUND)                                                  
                  RETURN                                                                 
                  ENDDO                                                                  
                  ENDDO
    
  • Here, infinite DOWHILE LOOP is running as per the condition 1=1 which always true.
  • After that, ALLOBJPF outfile being read using the RCVF command and monitor message CPF0864 has been handled to leave the infinite loop when last record of the file being read.
  • Then, the condition being checked i.e &ODOBTP = '*FILE' *AND &ODOBNM = 'CLPF1' and if met then the message 'FOUND' being send to the program and return from the program otherwise the file reading will be continued until the last record has been read.
  • Program compilation steps

  • First run the below DSPOBJD command to create outfile ALLOBJPF in library EASYCLASS1.
  •               DSPOBJD    OBJ(EASYCLASS1/*ALL) OBJTYPE(*ALL) +                        
                               OUTPUT(*OUTFILE) OUTFILE(EASYCLASS1/ALLOBJPF)
    
  • Take option 14 (Create Bound CL Program (CRTBNDCL)) to create the cl program object.
  • Post a Comment

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