RPGLE Flat File

85 pts.
Tags:
Flat files
RPGLE
how can i keyed a flat file in RPGLE

Software/Hardware used:
file

Answer Wiki

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

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).

Discuss This Question: 7  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
  • Teandy
    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: http://archive.midrange.com/rpg400-l/200409/msg00354.html 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.
    5,860 pointsBadges:
    report
  • CharlieBrowne
    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.
    41,370 pointsBadges:
    report
  • philpl1jb
    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
    49,720 pointsBadges:
    report
  • BigKat
    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.
    8,010 pointsBadges:
    report
  • MurrayInfoSys
    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.
    940 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • NarasimhaReddy
    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.
    225 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