Chain in RPG IV

765 pts.
Tags:
AS400 Data Definitions
CHAIN
RPG IV
What is your definition of CHAIN and when do you use it in your programming?

Answer Wiki

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

A chain operation is used to get a specific record from the database. It is mostly used with the file’s primary key.

This operation blocks the record, so you can modify it later.

If I need to get some records, I use SETLL, SETGT, READ and READP operations, but if I need to get a specific record for update later then I use CHAIN.

In RPG IV you can use %found (if %found …) to determine if the record was found, or you can use an indicator like commonly used in RPG.

Regards.

Discuss This Question: 12  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
  • Jaymz69
    So I can take a customer phone number (it is the key) from custmast and look at the custpaid file to see if they paid? CPHON CHAIN CUSTMAST IF %FOUND(CUSTMAST) EVAL AMTDUE = AMTDUE - AMTPD UPDATE AMTDUE ENDIF
    765 pointsBadges:
    report
  • Jaymz69
    CPHON CHAIN CUSTMAST
    IF %FOUND(CUSTMAST)
    EVAL AMTDUE = AMTDUE - AMTPD
    UPDATE AMTDUE
    ENDIF
    765 pointsBadges:
    report
  • Jaymz69
    But how do I match custpaid file KEY CPHONE to the custmast file KEY CPHONE to do the math if there was a payment
    765 pointsBadges:
    report
  • CharlieBrowne
    This seems to be an extremely basic question. I suggest you purchase some books or go to your local library and do some reading before asking more questions of this level. We are here with techincal issues, not be a classroom for someone who has not started the learning process by themselves.
    41,380 pointsBadges:
    report
  • TomLiotta
    ...how do I match custpaid file KEY CPHONE to the custmast file KEY CPHONE... That kind of gets into why the op-code was named "CHAIN" way back when it became part of RPG in RPG II. As long as the variable definitions are the same, you simply "chain" to the second file with the same value. You can even use the same variable for both files as long as the data types/sizes match the key definitions. The value and the data type/size are important; it doesn't matter what variable is used to hold the value. You get some field value into your program, perhaps input through a display file or through reading any file. That value is used as the key to "chain" to a record in another file, and perhaps a third, fourth or more files. The files can be linked by issuing CHAIN requests. This is (in a sense) the dynamic creation of JOIN views under program control. Under many circumstances, CHAIN might even be removed from the programming by using a JOIN view and letting DB2 "chain" records together. Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    BTW, I tend to agree with CharlieBrowne that this site isn't a good one for what can appear to be "homework" kinds of problems. I don't have the impression that this fits there mostly because of your past history at this site. It looks like you're trying to expand your job into new areas, perhaps even on your own initiative. Consider adding context to questions to help us know appropriate responses. Tom
    125,585 pointsBadges:
    report
  • Kaisersosa
    Ditto, Tom and Charlie. Kinda like asking a chef "whats a fridge for?"
    275 pointsBadges:
    report
  • YuVa47
    You can find answers for these type of your questions at: Good Luck YuVa
    1,300 pointsBadges:
    report
  • YuVa47
    The link is http://forum.tutorialindia.com/
    1,300 pointsBadges:
    report
  • Jaymz69
    That is all I was wanting, another person view besides the text book I read. Thank you... "That kind of gets into why the op-code was named “CHAIN” way back when it became part of RPG in RPG II. As long as the variable definitions are the same, you simply “chain” to the second file with the same value. You can even use the same variable for both files as long as the data types/sizes match the key definitions. The value and the data type/size are important; it doesn’t matter what variable is used to hold the value. You get some field value into your program, perhaps input through a display file or through reading any file. That value is used as the key to “chain” to a record in another file, and perhaps a third, fourth or more files. The files can be linked by issuing CHAIN requests. This is (in a sense) the dynamic creation of JOIN views under program control. Under many circumstances, CHAIN might even be removed from the programming by using a JOIN view and letting DB2 “chain” records together."
    765 pointsBadges:
    report
  • Jaymz69
    [...] 4. Jaymz69 got some other perspectives on his text book reading on chain in RPG IV. [...]
    0 pointsBadges:
    report
  • Jaymz69
    [...] Chain in RPG IV [...]
    0 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