Altering keyfields inside RPG Program

1420 pts.
Tags:
AS/400
Logical Files
Physical File
RPG Program
Hi all,
I have a  Physical file PF with 5 different logical files (LF). PF don't have any keys at all. In RPG program I need to perform a CHAIN on this file with 2 key-fields in which 1 of the key is defined as key field in some LF's. But the other is not. Now I was asked to perform CHAIN without creating new Logical file and asked to use the existing LF's only to CHAIN with req keys. How to alter the key fields here? Please help me providing some inputs. Thanks!


Software/Hardware used:
AS400, RPG 400,CLP/CLLE.

Answer Wiki

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

You cannot CHAIN to a file using a key where there is not access path built over that key.

You can have a LF with multiple fields as a key. Like: COMPANY, WHAREHOUSE, DEPT, SALESMAN, PART# and then only use part of the key to chain, COMPANY, WHAREHOUSE, DEPT.

But if you only have 3 fields in the access path, you cannot chain with 5 fields.

You can use SQL to select record(s) with any number of fields. 

Discuss This Question: 10  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
  • Sai4AS400
    Yes, we can't perform CHAIN as you said. But i need to chain the file with  fields for which the values will be papulated inside the program before CHAIN. And this process is in loop, so that every time it will CHAIN the file with new values. In this case, how to proceed with the SQL to get the data from file, based on the values of those two fields?..
    1,420 pointsBadges:
    report
  • TomLiotta

    In the case of SQL, you can't "CHAIN" at all. CHAIN isn't a SQL function.

    How to alter the key fields here?

    What do you mean by "alter"? Are you being asked to redesign the files? Is this a work task? Or is it an exercise?

    For the PF, it might be easy. If the intended key result would be unique keys, you could run ADDPFCST for a *PRIKEY constraint over the two keys. But there doesn't seem to be any reason to CHAIN to the PF at all. Just READ it.

    Those keys have no necessary relationship to the LFs. As long as the LFs are all over the same PF, the key values for the LFs will be populated automatically whenever you read a PF record.

    However, there also doesn't seem to be any reason to access the LFs since you're already READing the underlying PF record anyway. Generally, you'd just get the same record back again. Overall, the whole request doesn't make any good sense... unless none of the LFs are based on that PF.

    Tom

    125,585 pointsBadges:
    report
  • Sai4AS400
     I tried using  OVRDBF and OPNQRY in this scenario to override the Key fields of a  LF through CL Program, and then tried to CHAIN  in RPG program with the Keys specified in OPNQRY statement of CL. But still it is Throwing the error saying " The key fields in KLIST and File level are different. Can any one explain why?... Thanks!
    1,420 pointsBadges:
    report
  • philpl1jb

    You could use SETLL to position based on the field that is first in the key and then loop through the subset with READE until you find a record with  the additional field(s) that match your requirement.

    51,355 pointsBadges:
    report
  • TomLiotta

    But still it is Throwing the error saying ” The key fields in KLIST and File level are different. Can any one explain why?

    We might be able to explain why, or we might not.

    Before we can know, we need to see the file descriptions, the OVRDBF and OPNQRYF commands, the program code that threw the error and the error message especially including the message ID. Without basic information about a problem, we can't know if we can give a useful answer.

    Tom

    125,585 pointsBadges:
    report
  • Sai4AS400
    Is it Possible to do CHAIN after data recieved from the file through OPNQRY? i .e  inside the  RPG program with same Key fields Specified in OPNQRY statement at CL program. Can we do CHAIN or Cannot?..Please help me find the answer. Thanks!
    1,420 pointsBadges:
    report
  • TomLiotta

    Is it Possible to do CHAIN after data recieved from the file through OPNQRY?

    Yes. You can do a CHAIN any time as long as you have values to construct a key.

    Tom

    125,585 pointsBadges:
    report
  • Sai4AS400
    Tom,
    here in the OPNQRY statement i am specifying new Keys with which there is no such LF. I need to Chain with these in RPG. But the problem is the moment i used the key files in RPG KLIST, i am not able to generate the object at compilr time Itsself because key mis-match. How to go about this?...
    1,420 pointsBadges:
    report
  • TomLiotta

    How to go about this?

    We need to see the OPNQRYF command, the OVRDBF command and the definitions of the file and of the key list from the source. We should also be shown the error message identifier and any relevant message text.

    Tom

    125,585 pointsBadges:
    report
  • philpl1jb

    Compiling the RPG program over a file with a different key structure than any permanent file structure is a bit tricky.

    Perhaps, a cl that does the override and opnqryfile and then calls the compiler.

     

    51,355 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