Read a file line by line in RPG

85 pts.
Tags:
COBOL
RPG
I need to read a RPG source code file where I need to search a particular string in that file and I need to display RPG file when string found. It is similar to FNDSTRPDM in WRKMBRPDM. How can we do programatically using RPG/CL/COBOL.


Software/Hardware used:
as400
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 6  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.
  • philpl1jb

    The source files are readable just like physical files Fields are:

    SRCSEQ ZONED 6  2 6 1 Both
    SRCDAT ZONED 6  0 6 7 Both
    SRCDTA CHAR 100 100 13 Both

    You would either use OVRDBF (remember Share *yes) to specify the member

    Or the RPGLE F spec with keyword extfile(FileToSearch)

    and keyword extmbr(MbrToSearch)


    FileToSearch = 'MYLIB/MYFILE'  (all caps!!!)

    MbrToSeach = 'MYGREATSRC'


    54,090 pointsBadges:
    report
  • Geek511
    When we are using FNDSTRPDM is there any way to skip searching of string from comment line? We can skip through command or we  need to handle it programmatically?
    85 pointsBadges:
    report
  • TheRealRaven
    FNDSTRPDM has no documented method of ignoring comment lines. Other utilities from QShell such as sed and grep might be used in a QSH script to ignore comment lines if you can define in your script how to recognize comments.
    35,130 pointsBadges:
    report
  • ToddN2000
    I assume you could read the source fie by member. Then you could search records that do not have the * in the comment position. When you do find your search item, log that info to a table and read the next file member. At job end read and display or print your table.

    Any reason why you cannot use this ability in PDM? You can set the flags to PRINT LIST = 'Y' and if you want to see the actual code set PRINT RECORDS = 'Y'.
    132,810 pointsBadges:
    report
  • TheRealRaven
    Comments also may begin with "//" in any part of a statement, including executable statements, or might be in the 'comment area' of any statement.
    35,130 pointsBadges:
    report
  • TheRealRaven
    With RPG, you can use Cycle coding to process an Input Primary file, or you can use READ in a loop to process a full-procedural file, or you can use SELECT and FETCH with embedded SQL to access all rows (or only rows containing your search-string). And other methods are possible. COBOL can be used similarly though it has no "Cycle" function.

    CL would normally use RCVF to read each record, but it might run CREATE VIEW to limit which rows would be read.

    In all cases, you'll need to use either OVRDBF or native language features to specify which source member(s) to read before opening any of the members.

    In general, you read source file members just like you'd read any physical file.
    35,130 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: