Using Source Physical Files - IBM - RPG

Creating a Library and Source Physical File
Source statements are entered into a member of a source physical file. Before you can enter your program, you must have a library and a source physical file.

To create a library, use the CRTLIB command. To create a source physical, use the Create Source Physical file (CRTSRCPF) command. The recommended record length of the file is 112 characters. This record length takes into account the new ILE RPG structure as shown below.

ILE RPG Record Length Breakdown
ILE RPG Record Length Breakdown

Since the system default for a source physical file is 92 characters, you should explicitly specify a minimum record length of 112. If you specify a length less than 92 characters, the program may not compile since you may be truncating source code.

For more information about creating libraries and source physical files.

Using the Source Entry Utility (SEU)

You can use the Source Entry Utility (SEU) to enter your source statements. SEU also provides prompting for the different specification templates as well as syntax checking. To start SEU, use the STRSEU (Start Source Entry Utility) command. For other ways to start and use SEU, refer to the ADTS for AS/400: Source Entry Utility manual.

If you name your source file QRPGLESRC, SEU automatically sets the source type to RPGLE when it starts the editing session for a new member. Otherwise, you have to specify RPGLE when you create the member.

If you need prompting after you type STRSEU, press F4. The STRSEU display appears, lists the para meters, and supplies the default values. If you supply parameter values before you request prompting, the display appears with those values filled in.

In the following example you enter source statements for a program which will print employee information from a master file. This example shows you how to:

  • Create a library
  • Create a source physical file
  • Start an SEU editing session
  • Enter source statements.
  1. To create a library called MYLIB, type:
    CRTLIB LIB(MYLIB) The CRTLIB command
    creates a library called MYLIB.
  2. To create a source physical file called QRPGLESRC type:
    CRTSRCPF FILE(MYLIB/QRPGLESRC) RCDLEN(112) TEXT(’Source physical file for ILE RPG programs’) The CRTSRCPF command creates a source physical file QRPGLESRC in library MYLIB.
  3. To start an editing session and create source member EMPRPT type:
  4. STRSEU SRCFILE(MYLIB/QRPGLESRC) SRCMBR(EMPRPT) TYPE(RPGLE) OPTION(2)

    Entering OPTION(2) indicates that you want to start a session for a new member. The STRSEU command creates a new member EMPRPT in file QRPGLESRC in library MYLIB and starts an edit session.

    The SEU Edit display appears as shown below. Note that the screen is automatically shifted so that position 6 is (for specification type) at the left edge.

    Edit Display for a New Member
    Edit Display for a New Member

  5. Type the following source in your SEU Edit display, using the following SEU prefix commands to provide prompting:
    • IPF — for file description specifications
    • IPD — for definition specifications
    • IPI — for input specifications
    • IPC — for calculation specifications
    • IPCX — for calculation specifications with extended Factor 2
    • IPO — for output specifications
    • IPP — for output specifications continuation
    • IPPR — for procedure specifications

    Source for EMPRPT member
    Source for EMPRPT member

  6. Press F3 (Exit) to go to the Exit display. Type Y (Yes) to save EMPRPT. The member EMPRPT is saved.

This shows the DDS which is referenced by the EMPRPT source.

DDS for EMPRP
DDS for EMPRP

To create a program from this source use the CRTBNDRPG command, specifying DFTACTGRP (*NO).

Using SQL Statements

The DB2 UDB for iSeries® database can be accessed from an ILE RPG program by embedding SQL statements into your program source. Use the following rules to enter your SQL statements:

  • Enter your SQL statements on the Calculation specification
  • Start your SQL statements using the delimiter /EXEC SQL in positions 7-15 (with the / in position 7)
  • You can start entering your SQL statements on the same line as the starting delimiter
  • Use the continuation line delimiter (a + in position 7) to continue your statements on any subsequent lines
  • Use the ending delimiter /END-EXEC in positions 7-15 (with the slash in position 7) to signal the end of your SQL statements.

Note:SQL statements cannot go past position 80 in your program.

SQL Statements in an ILE RPG Program
SQL Statements in an ILE RPG Program

You must enter a separate command to process the SQL statements.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

IBM - RPG Topics