RPGLE Flat File
80 pts.
0
Q:
RPGLE Flat File
how can i keyed a flat file in RPGLE

Software/Hardware used:
file
ASKED: Nov 5 2009  10:58 AM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
410 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
The most common way to put an index (key) on a file is to define it in the source.
e.g.
A UNIQUE
A R ITEMSR

A ICITEM 20 COLHDG('Item #')
A IMANF 8S 0 COLHDG('Last Date Sold')

A K ICITEM

So the 1st 20 characters (the item number) are the key in this example. Note that the UNIQUE keyword is optional - it prevents duplicate keys.
Your source should match your flat file, with the addition of the "K" line(s) of code to define the new key.
Move your flat file to another library.
Compile the source to replace the flat file.
Verify that the file lengths and number of fields match.
CPYF the flat file data into the keyed file (*nochk).
Last Answered: Nov 5 2009  3:51 PM GMT by Aceofdelts   410 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Teandy   3250 pts.  |   Nov 5 2009  9:40PM GMT

Are you talking about a flat file with only one long field defined and part of that field is the key? Or are you talking about a physical file with no key defined?

If it is the first one, there is a way to define the key inside your program. It has been literally years since I have done this and I no longer have examples. However, you should be able to Google on INTERNAL FILE SPECS or PROGRAM DESCRIBED FILES and find what you need.

This thread here may offer some insight:

 <a href="http://archive.midrange.com/rpg400-l/200409/msg00354.html" title="http://archive.midrange.com/rpg400-l/200409/msg00354.html" target="_blank">http://archive.midrange.com/rpg400-l/200…</a>

If this is the second type, then you can just create a keyed logical file over the physical, or you can use SQL or the OPNQRYF command to pull the data in the order you want.

 

CharlieBrowne   6540 pts.  |   Nov 5 2009  10:35PM GMT

I think what Teandy is referencing is no longer available.
Early on in RPG (before RPGII) you could put a C1 –> C9 on the I spec line for a field. THis allow you to do a chain.
Other options were M1 - M9 for Matching Record and L1 to L9 for Level breaks.
You can still use these two options but you must use the RPG cycle to have them work.

 

Philpl1jb   24610 pts.  |   Nov 6 2009  12:14PM GMT

Two routes have been proposed — using an RPG III method that sets the F spec as P(rimary) and has I spec’s … I’m old but I was playing with other stuff back then.

the other route is to use the dbf. I typically build a pf with fields and keys and copy the flat file into the PF .. if the fielding isn’t quite right I fix the description recomile the Pf and copy the data again. this copy process and calling the rpg program to use the data is done by a cl. the pf with structure and keys is used by the RPG program.
Phil

 

BigKat   2540 pts.  |   Nov 6 2009  3:01PM GMT

It should also be possible to do an OPNQRYF to define a field and key off of it. I am no OPNQRYF magician, but I’m sure some of them are around here and could help.

I would use embedded SQL to define a cursor that breaks out the data and orders it as needed.

 

MurrayInfoSys   570 pts.  |   Nov 6 2009  11:14PM GMT

I’ve used the methods described above - OPNQRY, RPG III and CPYF.

IMHO, IF the source is good at formatting the flat file, then this is the way to go. Simply copy the flat file to your DDS defined PF and run the program. If the source is not good at defining a flat file, for example, columns vary in length from run to run, I would use the OPNQRY method to format the flat file to a DDS defined PF. Yes, it takes a bit of OPNQRY knowledge, but it is quick and simple once you get the hang of it. Plus the program has not changed. Just front end changes.

PS: The RPG III cycle is still there. You can do Matching Record (M1->M9) and Level processing (L1 -> L9). I do not remember the C1 thru C9. AND, you can use Auto-Report, a very simple way to create a listing w/ totals and Sub-totals.

 

TomLiotta   8025 pts.  |   Nov 27 2009  10:41AM GMT

If the file is a “flat file” that doesn’t actually have an external key (no keyed access path exists), then it doesn’t matter how you code the RPG. “Flat file” and “key” are mutually exclusive in that sense.

However, you might be able to cause a keyed access path to be created. Maybe. It’s been far too many years.

STRIDU — Start Interactive Data Definition Utility — IDDU

Maybe you can apply a data definition to your flat file and define a key. (I can’t recall if this is even possible, and I sure don’t have time to re-learn IDDU nowadays.)

Tom

 

NarasimhaReddy   175 pts.  |   Nov 28 2009  10:40AM GMT

If it is a single field flat file, you can use OPNQRYF and define a field with substring of flat file record and make the new field as Key. OPNQRYF has option to define new field and use it as Key.

 
0