IBMiAccess




Results 1 to 5 of 5

Thread: How to Read a file interactively in CLP

  1. #1
    Code400 Newbie
    Join Date
    May 2006
    Location
    India
    Posts
    18
    Rep Power
    0

    Exclamation 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. # 666
    Circuit advertisement
    Join Date
    Aug 1965
    Location
    Yakutsk, Russia
    Posts
    1,000,000
     

  3. #2
    Analyst ChrisL's Avatar
    Join Date
    Jan 2006
    Location
    Coventry
    Posts
    348
    Rep Power
    1044

    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.

  4. #3
    Analyst ChrisL's Avatar
    Join Date
    Jan 2006
    Location
    Coventry
    Posts
    348
    Rep Power
    1044

    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.

  5. #4
    Code400 Newbie
    Join Date
    May 2006
    Location
    India
    Posts
    18
    Rep Power
    0

    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.

  6. #5
    Analyst ChrisL's Avatar
    Join Date
    Jan 2006
    Location
    Coventry
    Posts
    348
    Rep Power
    1044

    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.

  7. # 666
    Circuit advertisement
    Join Date
    Aug 1965
    Location
    Yakutsk, Russia
    Posts
    1,000,000
     

Facebook Comments


Similar Threads

  1. Regarding Journaling
    By Sandeep D in forum RPG/RPGLE
    Replies: 3
    Last Post: November 16th, 2009, 07:37 AM
  2. read text file on IFS from RPG
    By jamief in forum Tips for the Iseries/AS400
    Replies: 8
    Last Post: January 9th, 2007, 07:54 AM
  3. how to read comma separated file in RPGLE
    By donna_ny in forum RPG/RPGLE
    Replies: 7
    Last Post: October 12th, 2006, 04:31 PM
  4. reg RLU
    By shankar.as400 in forum ANY THING GOES
    Replies: 7
    Last Post: April 5th, 2006, 11:18 PM
  5. OVRDBF and Activation Groups.
    By coder400 in forum CLP/CLLE
    Replies: 8
    Last Post: December 12th, 2005, 09:56 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •