Update without prior read or chain error

170 pts.
Tags:
RPG UPDATE ERROR
I am getting RNX1221:Update or delete in file without prior input operation on the update of file SRCDTAL in the following code. I don't see what the issue is. Any help would be appreciated. FSRCDTAL UF A E K DISK RENAME(QWHFDML:SRCDTAR) F Prefix('S') D HistData ds qualified D In likerec(SRCDTAR:*input) D Out likerec(SRCDTAR:*output) D overlay(In) Chain (ds2.MLLIB:ds2.MLFILE:ds2.MLNAME) SRCDTAL HistData.In; . . . If %Found(SRCDTAL); HistData.Out = ds2; update SRCDTAR HistData.Out; Else; HistData.Out = ds2; Write SRCDTAR HistData.Out; ENDIF;

Answer Wiki

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

Do you have any other file operations on SRCDTAL between the Chain and the If %Found statements because the code you have supplied looks OK.

Another idea :
Have you check that you do not modify the key fields between the chain and the update ?

Discuss This Question: 5  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.
  • wai8tiu
    wat the tupai?
    10 pointsBadges:
    report
  • Subhendu Sen
    @wai8tiu, from what reference you are talking about? What software/hardware are you using now? What devices are there?
    86,560 pointsBadges:
    report
  • ToddN2000
    You can always try running your code through DEBUG. Trace it line by line to find your error.
    82,110 pointsBadges:
    report
  • aceofdelts

    This error is always because the key fields being written do not match the key that was most recently read.

    Could be the program field value changed (look for use of the physical file via a different logical with same field names)

    Could be the data record got deleted since the Read


    2,410 pointsBadges:
    report
  • GregManzo
    Changing key field values is perfectly valid (at least from DB point of view - might not make sense in your application). You can even do it in DFU. We have DB triggers that specifically check for changing key values and give an error ('cos it doesn't make sense in most of our apps, but some allow it).
    And if you have read a record for update, you have it locked - nobody _can_ delete it.

    Update or delete without prior read can be caused by:
    a) trying to update before reading the record,
    b) trying to update when the read failed (chain - not found or read - eof),
    c) trying to update twice for one read (yeah, logic error),
    d) trying to update after unlocking the record,
    e) issuing a commit or rollback between the read & update (only applies if using commit control).
    This last one is the one that bites me most often.
    1,635 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: