HP 3000 Manuals

Using RPG [ HP RPG/iX Reference Manual ] MPE/iX 5.0 Documentation


HP RPG/iX Reference Manual

Using RPG 

The next seven sections give an overview of how to use RPG. Figure 1-1
(*) gives a pictorial representation of this process.

[]
Figure 1-1. Steps in Preparing and Running an RPG Program Step 1: Analyze the Task Analyze the data to be processed by the program. Determine the calculations and other operations that must be performed on the data. Decide what data should be output and in what format. Also decide what devices to use for input and output files. For example, Figure 1-2 shows the layout of a new report that needs to be produced. The report is detailed on a printer spacing chart. The chart shows all of the fields on the report along with headings.
[]
Figure 1-2. A Report Defined on the Printer Spacing Chart Step 2: Plan the Program Plan the general program steps required to produce the desired output. In doing this, you may want to prepare a flowchart of the program. Step 3: Create the Source Program Create RPG specifications for the program. You can enter them using any line editor or word processor that produces a standard ASCII file. For example, you may want to use EDITOR or TDP. Alternatively, you can use the RPG Interactive System Environment (RISE) to enter the specifications. The HP RPG Programmer's Guide gives more details on entering a program. Also, RISE is discussed in detail in the RPG Utilities Reference Manual. The eight types of RPG specifications are listed below. Each specification is identified by a unique letter code in the sixth position (column). The specifications are listed below in the order that you enter them. For general rules about entering specifications, see Chapter 2. For details about entering a particular specification, turn to the chapter in this manual where it is discussed. * Header Specification (H) Contains run-time options such as how to handle certain editing codes and run-time errors, and whether to print a compiler Cross-Reference listing. This specification is optional. Use just one Header Specification in each program. * File Description Specification (F) Defines a file used in the program, assigns a name to it, describes its type and record size and how it is accessed. This specification is optional. * File Extension Specification (E) Describes a table or array used in the program. This specification is also used to supply additional File Description file information. This specification is optional. * Line Counter Specification (L) Provides information about a line printer file, such as the form length and printer carriage control information. This specification is optional. * Input Specification (I) Describes the types of input records in a file and the fields they contain. This specification is optional. * Calculation Specification (C) Defines an operation to perform on data once it is read into memory. Operations include moving data in memory, performing arithmetic and branching operations, and calls to subroutines. This specification lets you directly control input and output. It is optional. * Output Specification (O) Defines the output records in a file, including the fields that it contains. This specification is optional. * Array/Table File Name Specification (A) Names a file containing a table or array to be processed. Figure 1-3 shows how specifications are used in an RPG program. This program was written using the printer layout chart shown in Figure 1-2 (*) ___________________________________________________________________________________ | | | 1 2 3 4 5 6 7 | | 678901234567890123456789012345678901234567890123456789012345678901234| | _______________________________________________________ | | | | 1 H XLS | | | | 2 FINPUT IP F 80 DISK | | FTABFILE IT F 80 EDISK | | FREPORT O F 132 OF LLP | | | | 3 E TABFILE TABA 8 160 5 ATABB 5 0 ALTERNATING TAB | | | | 4 LREPORT 66FL 55OL | | | | 5 IINPUT AA 15 | | I 1 5 STOKNO | | I 6 15 GSAREAL2 | | I 16 25 SUBJ L1 | | I 26 35 AUTH | | I 36 55 TITLE | | I 56 58 EDITN | | I 59 622PPCOPY | | I 64 680NUMSHP | | | | 6 C PPCOPY MULT NUMSHP BKSL 72 SALES/BOOK | | C BKSL ADD SUBSL SUBSL 92 SALES/SUBJECT | | C BKSL ADD GARSL GARSL 102 SALES/GEN AREA | | C BKSL ADD TOTSL TOTSL 122 TOTAL SALES | | C STOKNO LOKUPTABA TABB 10 | | C 10 TABB SUB NUMSHP TABB UPDATE INV TAB | | | | | ___________________________________________________________________________________ Figure 1-3. An RPG Source Program ___________________________________________________________________________________ | | | 1 2 3 4 5 6 7 | | 678901234567890123456789012345678901234567890123456789012345678901234| | _______________________________________________________ | | | | 7 OREPORT H 1P | | O 24 "TEXTBOOK SALES" | | O UDATE Y 50 | | O 100 "PAGE" | | O PAGE 106 | | O H 6 0F | | O 100 "PAGE" | | O PAGE 106 | | O H 33 1P | | O OR 0F | | O 18 "STOCK NO." | | O 26 "AUTHOR" | | O 40 "TITLE" | | O 68 "EDN" | | O 77 "NO. SOLD" | | O 95 "PRICE/COPY" | | O 112 "SALES/BOOK" | | O D 1 15 | | O . | | O . | | O . | | | | | ___________________________________________________________________________________ Figure 1-3. An RPG Source Program (Continued) Comments 1 This line is the Header Specification for the program. 2 This line begins the File Description Specifications. 3 This line is the File Extension Specification. 4 This line is the Line Counter Specification. 5 This line begins the Input Specifications. 6 This line begins the Calculation Specifications. 7 This line begins the Output Specifications. Step 4: Compile the Source Program Once you enter the specifications for a program and desk-check it, you can compile it. The following command compiles the program, SALES: :RPGXL SALES.SOURCE, SALEO.SOURCE The RPG compiler translates the source program into an object program assigning storage areas and creating routines to handle input and output. The object program is saved as the relocatable object file, SALEO.SOURCE. Optionally, the compiler prints a Cross-Reference listing. When there are source errors, appropriate error messages are generated. Appendix A in this manual lists compile-time error messages. See the HP RPG Programmer's Guide for additional examples on how to compile an RPG program.
NOTE You can compile and link in one step (bypassing Step 5) by using the RPGXLLK command. Or, you can compile, link, and execute in one step (bypassing Steps 5 and 6) by using the RPGXLGO command.
Step 5: Prepare the Object Program for Execution When you compile a program using the RPGXL command (see the previous section), the program cannot be executed directly. You must prepare the compiled program for execution by linking it to external subroutines and procedures that it uses. The result is an executable program file. The following MPE/iX command links the program, SALEO, which was compiled in the previous section: :LINK SALEO.SOURCE, SALEP.PROGRAM See the HP RPG Programmer's Guide for additional examples on how to link an RPG program. Step 6: Execute the Object Program Once a compiled program is linked or prepared for execution, you can execute it. The following command executes the program, SALEP, which was prepared for execution in the previous section: :RUN SALEP.PROGRAM If errors occur during execution, appropriate messages are displayed (see Appendix A for a complete description of run-time error messages). See the HP RPG Programmer's Guide for hints on debugging RPG programs. A valuable feature of the MPE operating system is the ability to assign files to specific hardware devices at run time. This enables you to run a program using different devices without recompiling the program. Figure 1-4 shows the output sales report generated by the program in Figure 1-3 . The report can be assigned to the printer or to a disk file at run time.
[]
Figure 1-4. Output From an RPG Program


MPE/iX 5.0 Documentation