Read a source physical file

195 pts.
Tags:
AS/400
DCLF
dclf statement
Is there any way to declare all the files present in a source physical file using CL by the single DCLF statement?

Software/Hardware used:
AS400

Answer Wiki

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

Would you like to get all the Files present in a particular Library?
Source Physical file doesnt contain the list of Files(Objects) in it. But, It will store the Source of a File or Program as Members.
If you declare Source Physical file using CL and if you try to Read the file, You can be able to get the Source details(DDS) of First Member of Source Physical file.

Instead of that, Maybe you can try DSPOBJD and store the Objects in OUTFILE.

<pre>DSPOBJD OBJ(LIBNAM/*ALL) OBJTYPE(*FILE) OUTPUT(*OUTFILE) OUTFILE(TEMP) </pre>

You can use the OUTFILE for getting the Available Files details in a Particular Library.

Pradeep.

Discuss This Question: 21  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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Sasikumarr
    Actually i want to read all the files in a source physical files without declaring all the members in the F-Spec in rpgle. For example Input src-pf consists of members A,B,C & D.(A,B,C,D are PF-DTA) I have to read A,B,C & D without declaring them in F- Spec. But INPUT(src-pf) can be used in F-Spec.
    195 pointsBadges:
    report
  • deepu9321
    Do you mean, You want to Read the Data available in FIles? I guess, you will not be able to do this. Because, Source Physical file doesnt contain the Data of the Files. But, It will just contain the Souce information as members. Eg: If we consider There are three Files in a Source Physical file. And each file contains 100 Records. You would have wrote the DDS Instructions for creating file. like,
    R RECFMT
      FLD1   10A
      FLD2   20A
    In this case, Source physical file will be holding the above DDS statements not the 100 records under that Physical File. Pradeep.
    3,650 pointsBadges:
    report
  • Sasikumarr
    Is there any other ways to perform this task?
    195 pointsBadges:
    report
  • pdsathishkumar
    it will not able to do this... becoz object searching by library only... object doesn't consider source physical file... object depend library...
    3,790 pointsBadges:
    report
  • deepu9321
    I think we cant be able to do this exactly. Will you be little more specific about your requirement? As, you mentioned, If you have A,B,C & D in your source physical file, You would like to Read the Data from those files. What If you have more Files(Eg: 50 or 100)? Mentioned more info about your requirement. But, In Practical, Objects(*FILE) will be stored in Libraries. So, Those cant be differenciated until you go and check for the Object Description. Pradeep.
    3,650 pointsBadges:
    report
  • Sasikumarr
    The Source PF consists only Data PFs and no other object types. I want to read all those data PFs. Read a SRCPF then Read the Data PFs then write those datas to a Printer file . If there are 50 Data PFs in that particular SRCPF i have to perform the read and write one by one upto the last file in that SRCPF. Is this a possible one?
    195 pointsBadges:
    report
  • deepu9321
    Then, I think you can follow the below procedure. Maybe you can be able to do it. Get the List of Files which were stored under that Source physical file and store it to Temporary file.
    DSPFD FILE(LIBNAM/SRCPFNM) TYPE(*MBRLIST) OUTPUT(*OUTFILE) FILEATR(*PF)
    OUTFILE(LIBNAM/TEMPFL)
    Then, Read the OUTFILE for getting the list of Files(Available under Source Physical File). and the Read the Specified file using SQL(Defining in F - Spec is not Required) and populate the values to Printer File.
    READ TEMPFL 
    Dow Not %EOF() 
    //Build Cursor on File FILENM //We are Reading FILENM from OutFile
    //Fetch from Cursor and Store in Local Varables
    Dow SqlCode <> 100 //SqlCod = 100 means End of File Receieved for the file Specified on Cursor.
    //Perform Required Operations(Writing to Printer file
    //Fetch Next from Cursor and Store in Local Varables
    EndDo 
    READ TEMPFL
    EndDo
    
    In the above code, First Do loop will repeat till the Physical Files exist in the Outfile. Second Do Loop will fetch the Data from the corresponding PF and will write to Printer file. It will Repeat the loop until the End of File of corresponding Physical File. Try with the similar approach and let me know if you have any doubts in above procedure. Pradeep.
    3,650 pointsBadges:
    report
  • TomLiotta
    If all you want to do is print them:
    CPYF FROMFILE( mylib/mysrcpf ) TOFILE(*PRINT) FROMMBR(*ALL)
    And it's done. Tom
    125,585 pointsBadges:
    report
  • deepu9321
    Tom, Above CPYF will print the Source(DDS Instructions) of the files under Source Physical file, isn't it? Pradeep.
    3,650 pointsBadges:
    report
  • TomLiotta
    Above CPYF will print the Source(DDS Instructions) of the files under Source Physical file, isn’t it? First, there is only one "file". It can have many "members" (not "files"). Second, I don't know if I understand your question. If the source file contains DDS source members, then the CPYF will print the DDS source. But if it contains RPG source members, then it will print the RPG source. If your question is about whether the CPYF command will print the DDS that defines the source file, no. It prints the content of the members, all members in the file (unless they contain some invalid data that throws an exception). Tom
    125,585 pointsBadges:
    report
  • deepu9321
    Yeah, I understood Tom. But, The Requirement of Sasi Kumar is bit different here. So, Just got confused with your answer. You can find the Sasi Kumar's post in Discussion for better understanding of his requirement. Pradeep.
    3,650 pointsBadges:
    report
  • philpl1jb
    During this discussion, we've got a bit of a clearer statement. Print the actual data from a list of files -- the list being derrived from the member names in a source physical file -- I still doubt that the person asking this request has a clear understanding of the implications of their request. In the real world I would go back to them to discuss the issue further. Additional spec requirements 1. What to do with rows that are wider than the printer 2. What to do with fields that are wider than the printer 3. What to do with files with millions of rows 4. What format of dates, numbers, negative numbers, what to do with large objects then on the technical side The CPYF to printer (of the data file) is the easist method and requires no RPG but leaves some fields in non-printing form. Works great, as Tom showed, for listing the source (all text and short lines). The copy command CPYTOIMPF can create a readable file -- doubt that it has a *PRINT option so this solution might copy the data to a "flat" file followed with a CPYF to send it to the printer. Again no RPG a few CL steps in a loop But the RPG method contains dragons. Somehow, between the select/fetch/write the actual field list for that file will need to be used to create a 80 or 132 character strings for printing. Phil
    49,570 pointsBadges:
    report
  • Sasikumarr
    Actually ERRSRC is my Source PF and it contains the files like ErrPF1, ErrPF2,...ErrPFn. All the Data PF consists of just a Common record 'ERRDESC'. Now my requirement is i have to read all those 'n' PFs without declaring them using the F-spec and write the 'ERRDESC' to a printer file named as 'ErrPRTF'. Is This possible or not? I had already created an outfile for DSPOBJD of that SrcPF(ERRSRC). What i have to do further?
    195 pointsBadges:
    report
  • philpl1jb
    OK Option 1 CL program declares the outfile in a DCLF command It uses the RCvf to get the next member name If uses the CYPF to write the member to *print it loops to the RCVF to get the next member or Rpgle has an F-spec specifing one of the files 9for compile purpuses only) the F spec has the keywords USROPN and EXTNAME ( MyName ) and an input f spec for the file created in the out file and a d-spec declaring MyName standalone 10 character Program reads a record from Memberlist sets MyFile = member name in member list Opens file reads each recor in file writes each record in file close file loop to read record frm Memberlist PHIL
    49,570 pointsBadges:
    report
  • TomLiotta
    Actually ERRSRC is my Source PF and it contains the files like ErrPF1, ErrPF2,…ErrPFn. If ERRSRC is a source PF, then it doesn't contain multiple files. It contains multiple "members". But if ERRSRC is really a 'library', then it might contain multiple files. You need to clarify if ERRSRC is file or a library. If it is a file, then how did you create it? What command was used to create it? That will tell us if it is a source PF or a data PF. We need to know what ERRSRC really is in order to know how to process it. Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    For a few minutes there, I actually thought I understood what you wanted to do. Then I got confused again, must be age. Abbott and Costello - "Who's on First?" <-- very funny/confusing American skit about baseball. So what has a source file to do with the DSPOBJD command?
    49,570 pointsBadges:
    report
  • TomLiotta
    Abbott and Costello WHO's my current library, and WHAT's a product library in my job's library list. Tom
    125,585 pointsBadges:
    report
  • Sasikumarr
    ErrSRC is created by the command CRTSRCPF in my library. It consists of the members like ErrPF1,ErrPF2,.....ErrPFn. All these members are of type 'PF'.
    195 pointsBadges:
    report
  • philpl1jb
    "ErrSRC is created by the command CRTSRCPF in my library. It consists of the members like ErrPF1,ErrPF2,…..ErrPFn. All these members are of type ‘PF’." Is the data that you want to print in the file CRtSRCPF in the members ErrPF1 etcc or is the data that you want to print in the fiels ErrPF1, ErrPF2 ... --- assuming the latter , that you have mulliple files NOT multiple members to work with The files have the same record name and field structure. The list of files could be obtained with the dspfd (mbrlst) of the sorce file or The list of files could be obtained with the dspobjd of objedts with names like ErrPF* Quick and rough listing could be made in a CL program using looping throujgh DSPFD or DSPOBJD list to the cpyf each file to print. More sophicated RPG program can loop throujgh the same file. The ErrFile IF f-sped includes the EXTFILE( myvariable) and the USROPN keyword - we're open this file after we've actually got it's name. The program reads a record from the DSPFD/DSPOBJD file and sets myvariable = name from file then it reads each record fro the file and prints a line after all lines it reads the next record from the DSPFD/DSPOBJD file and as long as there are records it loops. If my assumption was wrong, then instead of using the EXTFILE keyword use he EXTMEM) keyword on the F-spec Note: make the F-Spec refer to one of the existing files so it can compile. Hope this helps. And on with the game...The second baseman thows the ball to who, he catches it and throws the ball to the Catcher Tomorrow. Why did Who wait so logns?. Phil
    49,570 pointsBadges:
    report
  • TomLiotta
    All these members are of type ‘PF’. Ah! You are referring to the 'Type' column in a PDM list. You probably should learn that the PDM 'Type' is really only meaningful to PDM. It has nothing to do with what is contained in a member. You can put anything you want into the 'Type' and it won't change anything important. In fact, the you have described them, PF is probably not a good choice. You should change all of them to TXT or TEXT. They don't appear to be intended as PF members. (But maybe they haven't been explained to us completely.) Try this program for an example:
         FERRSRC    ipe  e             disk    infds( ESds )
         DESds             ds
         D MEMBER                129    138
    
         D PrvMbr          s             10    inz
    
          /free
           if PrvMbr <> MEMBER ;
              PrvMbr = MEMBER ;
              dsply    MEMBER ;
           endif ;
          /end-free
    Compile it and run it to see what it does. Then execute this command first and run the program again to see the difference:
    OVRDBF FILE(ERRSRC) MBR(*ALL) OVRSCOPE(*JOB)
    After you run the example program, run this command to clean up the previous override:
    DLTOVR FILE(ERRSRC) LVL(*JOB)
    See if you can make sense out of it.
    
    Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    It's in color when Dorothy is in Oz, but black and white in Kansas, Thanks Tom. Finally, it make sense, no I'm sorry it's fading away! What does the DSPOBJD do if the data is stored in a single file. ErrSRC is created by the command CRTSRCPF ? Then how does it have a record name? ERRDESC! Phil
    49,570 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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following