We have 8 fields in a file.In those fields sixth is the only Non Key Field(Other 7 are keyed fields).Now I want to pull the unique records according to the Sixth field using RPG.
Software/Hardware used:
AS400
ASKED:
February 3, 2012 10:04 AM
UPDATED:
March 17, 2012 1:54 AM
So you want to get the file in order on the 6th field or access a recird based on the value of the 6th field
optons are:
- build a logical file keyed on the 6th field
- build an SQL index based on the 6th field
- use imbedded SQL – if it needs it, the system will build a temporary index
- use OVRDBF and OPNQrY to deliver the file keyed on the 6th fie
Surely other options exist
Phil
Tks Phil …I will appreciate if you can provide some reference code which can help me better in understanding this scenario.
What!!! Not time for code.
Time to identify which one of the 4 options fits your needs.
You want to do discreate accesses (like Chains)
It would be good to either
- build logical and use Chain
- create an index and use embedded SQL select
Phil
I want to pull the unique records according to the Sixth field…
If all of the other fields are key fields, the implication is that this field may be duplicated many times. It’s possible that there could be only a few ‘unique’ values out of every 1000 records. It’s possible that there could only be a few ‘unique’ values in the entire file.
It can be done in RPG.
But some methods actually require RPG plus some CL, or RPG plus some SQL, or RPG plus some DDS.
Are you trying to find a way to do it only in RPG? If so, are you using ILE RPG?
In RPG, you would do it by reading each record and storing the field value in an array (or some other container). Every time you found a value that was already in the array (or container), you’d go to the next record. You would only store values that hadn’t been stored before. When you reached the end of the file, the array would contain each unique value in a different element.
But if you used other tools such as SQL, you could simply SELECT DISTINCT values of that field and FETCH the distinct values.
In any case, it’s not clear precisely what you need to do. Are you trying to learn RPG? Or are you trying to solve a business problem?
The methods we might suggest will probably be very different depending on exactly what your goal is.
Tom