Primary file

RPG Logic Cycle
While declaring a file, In file designation If I give 'P' for primary file, I read it will use RPG logic cycle to read file instead of file opcodes read/chain etc. But can anyone let me know how these primary file is read? I couldnt get a clear explanation in google search. If anybody elaborate the primary file read process it will be helpful.

Software/Hardware used:

Answer Wiki

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

Essentially, the RPG Cycle does a do while not end of file loop and reads in the file one record at a time.

You only code the logic within the loop (that is the processing that is to be done for each record) It is possible to specify some initialization, finalization (LR) and “level break” (total) logic. But at its simplest, the primary file program is simply program that processes every record in a driving file.

Check out the image at IBM infocenter

Discuss This Question: 8  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.
  • TomLiotta
    But can anyone let me know how these primary file is read? Can you explain what you mean by the word "how"? One answer is that the compiler inserts instructions to call the DB2 routines that read records into the compiled program. The DB2 routines perform the reads just like they would if you coded READ instructions into your program source. Another answer might show an example from SQL:
    INSERT INTO TSTINSERT                                     
    with t1 (num, nam) as (SELECT CUSNUM, LSTNAM from QIWS/QCUSTCDT)
     SELECT num, nam from t1
    That will insert rows into a table named TSTINSERT by retrieving rows from IBM's example file in QIWS named QCUSTCDT. But "how" does it read records in order to get the values? In some sense, the answer is simply "It just does it. It doesn't matter how." Tom
    125,585 pointsBadges:
  • philpl1jb
    This is a supported but mature subset of RPG. It allows the creation of reports with no statements (C specs), although it can be used in conjunction with C specs. It's a powerful tool, almost a seperate language. Some programmers swear by and others swear at it. Phil
    54,090 pointsBadges:
  • MDratwa
    Sorry - I am a COBOL programmer. Many, many years ago - back on old RPG, if you did not enter a "K" for keyed, the file is read by arrival sequence. Not sure what the latest version of RPG handle the file, but I would think that is would be read by arrival sequence or by key. (Why not dup the file (in test lib) and copy a few dozen records and run the program and see how the file is read.)
    785 pointsBadges:
  • nuccio
    Post your "F" and "I" and first "C" spec, then we can explain method Work with the "primary" files is very efficient, but it is of difficulty understanding, it depends how the primary key is defined, what breakups of level is desired to manage...... You must search RPGII cicle. Bye
    305 pointsBadges:
  • ToddN2000
    Just curious as to how many people still use the "P" file spec for input primary?? I have not seen or used that in about 15 years. Mainly because of controlling level breaks. Those L1, L2, L3.... break could be a nightmare to work with at times.
    135,295 pointsBadges:
  • Splat
    Haven't used the cycle for reports in ages, but for going through an entire file it's a good method.
    12,915 pointsBadges:
  • TomLiotta
    I might still do it once a year; probably less. It's rare that I'm doing anything simple enough that using a 'P'rimary file makes sense. For such basic uses, SQL almost always is simpler to use. And for complex processes, I no longer use anything but 'F'ull-function specs if I use native I/O. . Tom
    125,585 pointsBadges:
  • gfprogrammer
    I am in a shop that still has some old RPGII code (S36 mode), using (P)primary, (S)secondary, (L)level breaks, and the dreaded (M)matching records. I am getting rid of them as fast as I can.
    250 pointsBadges:

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.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: