AS/400 CL program

620 pts.
Tags:
AS/400
CL Program
In CL program I need to take a mbrlist for a particular file and read the member names. I have to write PGM but I got below errors. Please help me.
 
    301-              DCLF       FILE(QTEMP/EMP2)                  
* CPD0736 30  Declare command occurs after first operable command. 
    500-  READ:       RCVF                                         
* CPD0865 40  File not previously declared.                        
Program:
0001.00 PGM                                                                
0001.02              DCL        VAR(&A) TYPE(*CHAR) LEN(8)                 
0001.03              DSPFD      FILE(EMP) TYPE(*MBRLIST) OUTPUT(*OUTFILE) +
0001.04                           OUTFILE(QTEMP/EMP2)                      
0003.01              DCLF       FILE(QTEMP/EMP2)                           
0005.00  READ:       RCVF                                                  
0005.01              MONMSG     MSGID(CPF8064) EXEC(GOTO CMDLBL(E))        
0006.00              CHGVAR     VAR(&A) VALUE(&MLNAME)                     
0007.00              SNDUSRMSG  MSG(&A)                                    
0008.00              GOTO       CMDLBL(READ)                               
0009.00    E:        ENDPGM                                                
        ****************** End of data ************************************
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hi,

DSPFD Command should be after DCLF.
Your code should be like this.
0001.02              DCL        VAR(&A) TYPE(*CHAR) LEN(8)                 
0003.01              DCLF       FILE(QTEMP/EMP2)                           
0003.02              DSPFD      FILE(EMP) TYPE(*MBRLIST) OUTPUT(*OUTFILE) +
0003.03                           OUTFILE(QTEMP/EMP2)                      

0005.00  READ:       RCVF                                                  
0005.01              MONMSG     MSGID(CPF8064) EXEC(GOTO CMDLBL(E))        
0006.00              CHGVAR     VAR(&A) VALUE(&MLNAME)                     
0007.00              SNDUSRMSG  MSG(&A)                                    
0008.00              GOTO       CMDLBL(READ)                               
0009.00    E:        ENDPGM                                                
        ****************** End of data ************************************

You will have to create the Outfile EMP2 in QTEMP, just before compilation to avoid compilation error.

Pradeep.

Discuss This Question: 10  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • chowas400
    Pradeep,
         Thank you very much for your speedy response..

    Is there any way to create out file in program and read it self.?plz advise..

    620 pointsBadges:
    report
  • Splat
    chowas400, the code above does create an outfile & read it.  Are you asking if you can create a second outfile and read it in the same program?

    BTW, it's not necessary to create a temporary copy of the DSPFD outfile. The below technique allows you to use the system definition:

    DCLF       FILE(QaFdMbrL)  
    
    . . .
    
    CRTDUPOBJ  OBJ(QaFdMbrl) FROMLIB(*LIBL) OBJTYPE(*FILE) +
                 TOLIB(QTEMP)                               
    MONMSG     MSGID(CPF2130)                               
                                                            
    CHGPF      FILE(QTEMP/QaFdMbrl) MAXMBRS(*NOMAX) +       
                 SIZE(*NOMAX)                               
    
    . . .
    
    DSPFD      FILE(&Library/&File) TYPE(*MBRLIST) +       
                 OUTPUT(*OUTFILE) OUTFILE(QTEMP/QAFDMBRL) +
                 OUTMBR(&Library)                          
    MONMSG     MSGID(CPF3000) EXEC(RETURN)                 
                                                           
    OVRDBF     FILE(QAFDMBRL) TOFILE(QTEMP/QAFDMBRL) +     
                 MBR(&Library) SHARE(*YES)                 
    
    . . .
    
    RCVF       RCDFMT(QWHFDML)            
    MONMSG     MSGID(CPF0864) EXEC(RETURN)


    12,915 pointsBadges:
    report
  • philpl1jb

    Pradeep's code creates the outfiile at run time in line

    0003.02              DSPFD      FILE(EMP) TYPE(*MBRLIST) OUTPUT(*OUTFILE) +

    0003.03                           OUTFILE(QTEMP/EMP2)  
    However, the program cannot be compiled without an outfile that has the structure of the file you want.  Because the compiler must map the file structure to be used when it sees the DCLF.
    0003.01              DCLF       FILE(QTEMP/EMP2)


     

        
    54,090 pointsBadges:
    report
  • chowas400
    Hi Pradeep,

      i need to take a list of all members in a file in cl program and read those members in rpg.i got the runtime error. plz advise..

    Error message CPF4102 appeared during OPEN for file TEST1.


    CL program:

    0001.00 PGM                                                         
    0001.02              DCL        VAR(&A) TYPE(*CHAR) LEN(5)          
    0003.01              DCLF       FILE(QTEMP/mbrlist)     
    0005.00  READ:       RCVF                                           
    0005.01              MONMSG     MSGID(CPF0864) EXEC(GOTO CMDLBL(E)) 
    0006.00              CHGVAR     VAR(&A) VALUE(&MLNAME)              
    0006.01              CALL       PGM(CHOW12011/MBR1) PARM(&A)        
    0008.00              GOTO       CMDLBL(READ)                        
    0009.00    E:        ENDPGM       


    RPG program:

    0001.00 FTEST1     IF   E           K DISK    EXTMBR('A')                       
    0002.00 C     *ENTRY        PLIST                                               
    0003.00 C                   PARM                    A                 8         
    0004.00 C                   READ      TEST1                                     
    0005.00 C                   DOW       NOT%EOF()                                 
    0006.00 C     ACCID         DSPLY                                               
    0007.00 C     ACCNAME       DSPLY                                               
    0008.00 C                   READ      TEST1                                     
    0009.00 C                   ENDDO                                               
    0010.00 C                   SETON                                        LR     

    620 pointsBadges:
    report
  • philpl1jb

    EXTMBR('A')  would mean that the member name is literally the letter 'A'

    EXTMBR(A)   would take care of that issue.


    54,090 pointsBadges:
    report
  • deepu9321
    You should mention the member name as suggested by Phil.

    If you are hard coding member name you should use it with Single Quotes. In this case compiler assumes your file has a member called 'A'.

    If you are having member name being passed into variable. You shouldn't enclose the variable with single quotes.

    Pradeep.

    4,980 pointsBadges:
    report
  • WoodEngineer
    We use this technique.  Prompt DSPFD then display the help text for "File to receive output".  There you will see the standard IBM files used for the various types of information requested.  Specify that IBM file in your program.  It will now compile cleanly.
    When you run the command, direct output to the file of your choice, then override IBM's file to your file.
    8,225 pointsBadges:
    report
  • chowas400
    Thank you All,
      Now my program running successfully...

    620 pointsBadges:
    report
  • AnushaMS
    Could you post the working code here please.

    10 pointsBadges:
    report
  • ToddN2000
    AnushaMS: Sounds like a class assignment. We can help, but give it a try. Post your code and any errors and we will help you fix them. Things get much tougher down the road.
    134,495 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: