Difference between READE and CHAIN

1885 pts.
Tags:
AS/400
RPG/400
Hi,
What is difference between CHAIN and READE both reads equal key record?
Looping possible do while in both so that both will filter equivalent key records but what is main difference then?
Thanks!


Software/Hardware used:
AS400

Answer Wiki

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

Google each of the opcodes in question and there are a plethora of answers.

Discuss This Question: 16  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.
  • Harisheldon
    Googling it is one way to find the answer, or just open your textbook and read the chapter to find the answer to that and many other topics.
    12,870 pointsBadges:
    report
  • ToddN2000
    Is there an issue with your code when using these op-codes? They are the basics to the RPG language. If you do not understand these, you are going to have a tough time going any further. Go back and review the course material.
    92,795 pointsBadges:
    report
  • philpl1jb

    Chain positions to and then acquires the first qualifying record.

    Reade reads the next record if it qualifies.

    54,090 pointsBadges:
    report
  • ToddN2000
    Chaining to a record will lock it unless you use the opcode CHAIN(N).
    We started using this when we were just making sure data was valid. This helped cut down on the number of record locks in a bunch of our jobs. A lot of older programs would chain to see if the customer number was valid and when our A/R was trying to make a change they could not. The Chain in another program had the record locked even though it was just an inquiry program.
    92,795 pointsBadges:
    report
  • Splat
    ToddN2000, how was the file being chained in the inquiry program defined? Input or Update?
    11,615 pointsBadges:
    report
  • CharlieBrowne
    Splat  --  I record will only be lock if it is an Update file. It intent is so no one will change it in another program before this update is done.
    62,340 pointsBadges:
    report
  • ToddN2000
    Update. Some old coding habits of years gone by we are still trying to clean up. Granted some of this code is from the 1990's by an outside source.
    92,795 pointsBadges:
    report
  • Splat
    CharlieBrowne, that's my understanding. That's why I was asking for clarification.

    ToddN2000, you have my sympathy. I'm dealing with a package written, in part, on the S/38 by S/34 programmers. Lots of those 'old coding habits'.
    11,615 pointsBadges:
    report
  • azohawk

    I hear that, been reviewing a program as RPGLE (RPG IV columns) but has a ton of conditioning indicators and goto statements. There are some indicator conditioned IFxx statements. I have done a little with RPG II (school and run in to a few programs) but RPG IV was just making headway (first place I worked didn't even have the RPG IV complier). So I get this.

    I know some schools are only training students in RPG /free. Which is fine if all they do is write new code. I can't imagine what the panic that would set in if they took a look at some of this old code we maintain. I guess that is another discussion post.

    3,005 pointsBadges:
    report
  • ToddN2000
    Yes I learned RPG back in 1980. Back then it was RPG II and RPG III. We used all kinds if indicators, like H1 and L1 that today are mostly obsolete. You may still run into them in legacy code. That's the beauty of these forums, you just may find someone who can tell what that 30-40 year old code is doing you are trying to maintain.
    92,795 pointsBadges:
    report
  • CharlieBrowne

    Back in the 1970's it was just RPG.

    No CHAIN command. Had to put indicators M1, M2,.. on field on the input specs. Many applications were on 80 column cards. On a 25600 MFCU (Multi Function Card Unit) the was one place for the input cards, another place for blank cards to be read in and then punched, and 5 stackers for the out of the cards. The was a column in the Output specs for Stacker Select. We have come a long way

    62,340 pointsBadges:
    report
  • CharlieBrowne

    Sorry that was C1, c2, .. for Chains

    The M1, M2, .. was for Matching Record Logic.

    There was also no read command. Input files we specified as Primary or Secondary. All we had was the RPG Cycle.

    62,340 pointsBadges:
    report
  • Splat
    Depending on the circumstances I still make the occasional use of primary and secondary input files (sequential - I never did get the hang of matching records processing).
    11,615 pointsBadges:
    report
  • AjitK29
    Chain: Used for the random access of the record in the database file. It’s equal to the SETLL+READE.

    Reade: Set the pointer to the equal key value.

    2,475 pointsBadges:
    report
  • BigKat
    @AjiitK29

    The CHAIN will only retrieve the first record that matches the key(s) regardless of how many do match.

    The SETLL sets the pointer just prior to the first record equal to or greater than the key(s)

    The READE retrieves the next record after the pointer if it matches the key(s) or returns EOF if it does not match.
    9,010 pointsBadges:
    report
  • anandx
    Both are used to access from an indexed (format) file
    basic difference: %reade is sequential retrieval (which means file pointer must have already been placed somewhere on the file thru setll or chain prior to reade)
    %chain is random retrieval (positioning of file pointer prior to chain is not required)
    Lock: Both can read a rec which is already locked if usage is *input, both have to wait if rec already locked if usage is *update
    Re-positioning file pointer: In both cases, if access ends up in %eof the file pointer needs to be repositioned
    Next sequential read: read followed after chain or reade try to fetch next record in the index
    %kds: is optional in reade. Both "READE fileX" and "READE %Kds(kds_ds) filex" are acceptable. In the former, system picks up the key field(s) from the last rec read while in the later case sys tries to match with contents of kds_ds. in chain %kds is mandatory
    550 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: