Reading (EVAL) a file in RPG

160 pts.
Tags:
AS/400
CL programming
EVAL function
RPG
Hi,

I'm a newbie when it comes to RPG and I couldn't find anything when searching.

So this is what I need.  I'm adding a record to a file but don't want any duplicates so I guess I need s simple RPG proogram that takes in one parm, reads a file (with one field) and if it comes across an exact match, I need to be notified that the record exists.

From there I should be able to modify a CL to alert me if that the record was added, deleted... etc.

Thanks for any help

bgg

ASKED: September 14, 2010  8:29 PM
UPDATED: September 15, 2010  5:43 PM

Answer Wiki

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

in your file DDS define the file with a UNIQUE key

in your RPG

/Free
Chain (key1 : key2 : Etc) FileName;
if Not %Found;
Write record;
EndIf;
/End-Free

Or

c KEY klist
c kfld key1
c kfld key2
c kfld etc

c KEY chain file 99
c if *in99 = *On
c write record
c endif

-Sarge

Discuss This Question: 2  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
  • TomLiotta
    If you don't want duplicate records, define the file as uniquely keyed. Then when you attempt to insert a duplicate, your program will be signaled of the error condition. You can certainly code the process that you asked about, but it's a long way around to get what the system will give you for little effort. Tom
    125,585 pointsBadges:
    report
  • CharlieBrowne
    Tom's suggestion is the best answer, because by putting a UNIQUE key on the file, you never have to worry about how the file is updated. If you do a CPYF or DBU, or DFU, it will ALWAYS stop the process and not allow records with duplicate keys.
    39,780 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