Query in CL programming

0 pts.
Tags:
i5
iSeries
OS/400
Im trying to get the following details within a CL program. Pointers to achieve the same would be highly appreciated. 1. Obtain the number of members in a given Physical file. 2. Facility to override a particular member in a multiple member physical file using a reference instead of member name. i.e. if i want to override the 4th member (i dont know its name) how do i do it? Thanks in advance. C
ASKED: November 23, 2004  9:23 AM
UPDATED: November 24, 2004  5:15 PM

Answer Wiki

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

Bottom line, you need the member name in order to override to it (unless it is the only member or it is the first/last member). So you need to generate a list of the member names and choose from this.
To get the number of members of a physical file simply use the command:
DSPFD &library/&file TYPE(*MBRLIST) OUTPUT(*OUTFILE) OUTFILE(qtemp/&outfile)
This will generate an outfile with a record for each member of the physical file containing all the details of the member.
You will find that there is a field MLNOMB on each record which has the total number of members in the file.
To determine which is say the 4th member depends whether you mean the 4th member alphabetically or the 4th member by date. If it is the 4th listed member alphabetically just read the outfile 4 times to get the member name then you can perform the override using OVRDBF specifying the member name in the record.
If it is the 4th member by date this is a little trickier since the DSPFD only lists members in alphabetical order.
It is possible to pick up the first member by date using:
RTVMBRD &library/&file MBR(*FIRST) RTNMBR(&member)
as opposed to:
RTVMBRD &library/&file MBR(*FIRSTMBR) RTNMBR(&member)
which picks up the first member by name.
However, you can’t then get the next member by date using:
RTVMBRD &library/&file MBR(&member *NEXT) RTNMBR(&member)
because the *NEXT option only gets the next member by name.
Oddly there is no equivalent *NEXT option to retrieve by date!
You only solution in this case is to list the members to an outfile as before and perform a sort by the create date field perhaps using a logical file.
I suspect you are probably only interested in the alphabetical scenario so go with the first method.

Discuss This Question:  

 
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

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