ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

How to Read a file interactively in CLP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to Read a file interactively in CLP

    Hi all,
    i have a doubt regarding CLP.
    I want to read a file interactively (without closing) ????

    eg. If i called the pgm first time it should read the First Record & when i call the same pgm 2nd time then. it should read the 2nd record & so on .

    (I used RETURN,but for 2nd call it is showing 1st record only.)

  • #2
    Re: How to Read a file interactively in CLP

    You will have to override the file before calling your CL program, depending on whether you want to access your file by key or RRN will depend what data you need to save in your CLP.

    eg..

    Code:
    OVRDBF     FILE(FILE) TOFILE(LIBRARY/FILE) MBR(MEMBER) +  
                 POSITION(*RRN &RRN)
    You'd need to store the RRN of the record you last read somewhere (eg in a data area).

    ** Specify the relative record number (its position from the beginning of the file) of the record that is read first. The value *RRN must precede the relative record number. For example, *RRN 480 specifies that record 480 is read next. If a read-previous record operation is requested, the 479th record in the file is read.

    Or if the file is keyed..

    Code:
    OVRDBF     FILE(FILE) TOFILE(LIBRARY/FILE) MBR(MEMBER) 
                 POSITION(*KEYA &NUMKEYS &RECFMT &KEYDATA)
    Again, you'll have to make a note of the data from the last record you read, and use that to position your file pointer in the CL

    Hope this helps.

    Comment


    • #3
      Re: How to Read a file interactively in CLP

      I've just done some tests here, seem to get some strange results for the first couple of records, but after that everything is fine, not got time at the moment to figure out where things are going astray..

      A1 - Performs override and creates a data area in qtemp..

      Code:
                   PGM                                                             
                   DCL &KEYDATA *CHAR 10                                           
                                                                                   
                   CHKOBJ     OBJ(QTEMP/KEYDATA) OBJTYPE(*DTAARA)                  
                   MONMSG     MSGID(CPF0000) EXEC(DO)                              
                   CRTDTAARA  DTAARA(QTEMP/KEYDATA) TYPE(*CHAR) LEN(10)            
                   GOTO       CMDLBL(CALL)                                         
                   ENDDO                                                           
                                                                                   
                   RTVDTAARA  DTAARA(QTEMP/KEYDATA) RTNVAR(&KEYDATA)               
                   OVRDBF     FILE(CSPBSHA) TOFILE(LOMASC/CSPBSHA) +               
                                MBR(*FIRST) POSITION(*KEYA 1 CSPBSHR +             
                                &KEYDATA)                                          
                   OPNDBF     FILE(LOMASC/CSPBSHA) OPTION(*INP)                    
                   MONMSG CPF0000                                                  
                                                                                   
       CALL:       CALL       PGM(A2)                                              
                                                                                   
                   DLTOVR     FILE(CSPBHW)                                         
                   MONMSG CPF0000    
                   ENDPGM
      A2 - Does a RCVF and sends a message to my message queue with the results..

      Code:
                  PGM                                                    
                  DCLF       FILE(LOMASC/CSPBSHA)                        
                                                                         
                  RCVF                                                   
                  SNDMSG     MSG(&BHSCNM) TOUSR(LOMASC)                  
                  CHGDTAARA  DTAARA(QTEMP/KEYDATA) VALUE(&BHSCNM)        
                  RCVF                                                   
                  SNDMSG     MSG(&BHSCNM) TOUSR(LOMASC)                  
                  CHGDTAARA  DTAARA(QTEMP/KEYDATA) VALUE(&BHSCNM)        
                                                                         
                  ENDPGM
      Hopefully that gives you something to start from.

      Comment


      • #4
        Re: How to Read a file interactively in CLP

        Hi ChrisL,
        Thanks for ur suggestion.
        I will try ur Logic.

        But still i have a doubt that , u r using endpgm & not RETURN ,
        when the file will be closed ??

        Thanks,
        Prashant.

        Comment


        • #5
          Re: How to Read a file interactively in CLP

          The End Program (ENDPGM) command specifies the end of a CL program.
          When the command is processed, it performs the same function as a
          RETURN command. That is, control is returned to the command
          immediately following the CALL command in the calling program.

          The ENDPGM command is not required at the end of a CL program. If
          the last statement in a CL program source file is reached and no
          ENDPGM command is found, an ENDPGM command is assumed by the
          compiler.
          The file will be closed when you end the first program, I've double checked this by checking my open files once I have returned from A1.

          Comment

          Working...
          X