160 pts.
 Reading (EVAL) a file in 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



Software/Hardware used:
ASKED: September 14, 2010  8:29 PM
UPDATED: September 15, 2010  5:43 PM

Answer Wiki:
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
Last Wiki Answer Submitted:  September 15, 2010  2:02 pm  by  Rudedog   950 pts.
All Answer Wiki Contributors:  Rudedog   950 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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

 108,085 pts.

 

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.

 32,855 pts.