55 pts.
 Update duplicate record in rpgle
I have a file where in filed1, field2 and field3 are key fields. Now these key fields are not unique, I need to update field 4, 5 and 6 based on the selection by user via subfile. To say f1 f2 f3 f4 f5 f6 A0123 A0123A *FILE CLM/D07 D07 1 A0123 A0123A *FILE CLM/D08 D08 2 A0123 A0123A *FILE CLM/D05 D05 1 A0123 A0123A *FILE CLM/D05 D05 2 Now i need to change the 4th record's f6 to 3. Whenever i do Chain its picking 3rd record that is fine by definition of chain, please help me to build logic to update 4th record when user selects option '2' against 4th record and to update 3rd record when user selects '2' against 3rd record. Please help..

Software/Hardware used:
ASKED: July 23, 2012  11:41 AM
UPDATED: July 23, 2012  11:47 AM

Answer Wiki:
You have various options: 1. Create a new LF where the key would be unique. 2. Instead of using a Chain, use Setll and Reade. When you write the subfile records include more fields as "H"idden fields. Then on the ReadE, compare those fields to the data in the file to get the record you need.
Last Wiki Answer Submitted:  July 23, 2012  11:56 am  by  CharlieBrowne   32,865 pts.
All Answer Wiki Contributors:  CharlieBrowne   32,865 pts. , nasrunisar   55 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


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


 

Thank you Charlie,
1. Create a new LF where the key would be unique. = In this option what would be my key fields. Are the same field1, 2 and 3 will be the key fields?
2. In the hidden fields only the record will be available right? Could you please send me some sample code?
 

 55 pts.

 

This is why I use logical views for display sequencing and physical RRN for updating.

 5,670 pts.

 

Since there are no unique fields between the 3rd and 4th records except for F6, you would need all six fields as your key for any LF that you create. A possible better choice would be to grab the RRN of each row and store it as a ‘H’idden field in the subfile. When you are ready to update, use the RRN to CHAIN to the PF record, and update that record. Tom

 108,135 pts.

 

Thank you Tom and all, its updating correctly thru RRN.

 55 pts.

 

Another option is to use SQL to update the record using criteria that makes it unique.

 3,115 pts.

 

And that means putting the original field value into a hidden field or the relative record # into a hidden field.
Also you can change the Chain to a SETLL and read until all fields match the original values… then you have the record you want to update…unless someone else updates it before you get to it.
 

 44,180 pts.

 

Subfile Rrn and PF Rrn is not matching while comparing after deleting any record, therefore giving errror update without prior input operation. Could any one suggest how to solve this issue.?
 

 55 pts.

 

Subfile Rrn and PF Rrn is not matching…
 
The subfile RRN is not the same as the PF RRN unless your program logic makes them the same.
 
You must retrieve the PF RRN (DB_RRN) from the device-specific-feedback area at the time the PF record is retrieved. You would store each DB_RRN in a ‘H’idden subfile field so your program knows which PF record to access later.
 
Tom

 108,135 pts.

 

Thank you very much Tom, Got DB Rrn during each read operation thru INFDS and written into subfile ‘H’idden field (HRRN) and for update, used Chain with HRRN and update working fine. And for delete, pointer at *start setll and the file processed within Dow Not %EOF and compared delete screen fields with file fields, and the matching record deleted.                            Everything works fine till now as far as write, update and delete is concern. Now got some validations to perform. Once again I thank you vey much for your quick response.

 55 pts.