ILE RPG Programmer's Guide
ILE RPG Programmer's Guide
iSeries
Note! Before using this information and the product it supports, be sure to read the general information under Notices on page 463.
Fourth Edition (May 2001) This edition applies to Version 5, Release 1, Modification Level 0, of IBM WebSphere Development Studio for iSeries (5722-WDS), ILE RPG compiler, and to all subsequent releases and modifications until otherwise indicated in new editions. This edition applies only to reduced instruction set computer (RISC) systems. This edition replaces SC09-2507-02. Order publications through your IBM representative or the IBM branch office serving your locality. Publications are not stocked at the address that is given below. IBM welcomes your comments. You can send your comments to: IBM Canada Ltd. Laboratory Information Development 2G/KB7/1150/TOR 1150 Eglinton Avenue East North York, Ontario, Canada
M3C 1H7
You can also send your comments by facsimile (attention: RCF Coordinator), or you can send your comments electronically to IBM. See How to Send Your Comments for a description of the methods. When you send information to IBM, you grant IBM a nonexclusive right to use or distribute the information in any way it believes appropriate without incurring any obligation to you. Copyright International Business Machines Corporation 1994, 2001. All rights reserved. US Government Users Restricted Rights Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
Contents
About This Guide . . . . . . . . . . ix
Who Should Use This Guide . . . . . . . . . ix Prerequisite and Related Information . . . . . . ix How to Send Your Comments . . . . . . . . x What's New This Release? . . . . . . . . . . x Changes to this Guide Since V4R4. . . . . . xv The Entire ARRSRPT Program . Coding Considerations . . . . General Considerations . . . Program Creation . . . . . Main Procedure Considerations. Subprocedure Considerations . For Further Information . . . . Main Procedures . . . . . Subprocedures . . . . . . Prototyped Call . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 47 47 47 47 48 48 48 49 49
| |
. . . .
. . . .
33 33 34 37
iii
89
89 89 90 91 91 91 95 96 97 98
Returning from a Called Program or Procedure Returning from a Main Procedure . . . Returning from a Subprocedure . . . . Returning using ILE Bindable APIs . . . Using Bindable APIs . . . . . . . . . Examples of Using Bindable APIs . . . Calling a Graphics Routine . . . . . . . Calling Special Routines . . . . . . . . Multithreading Considerations . . . . . How to Share Data Across More Than One Module . . . . . . . . . . . . How to Avoid Deadlock Between Modules
. . . . . . . . . . .
. . . . . . . . .
. 154 . 155
| | | | | | | | | | |
iv
Setting and Removing Conditional Thread Breakpoints . . . . . . . . . . . . . 205 Removing All Job and Thread Breakpoints . . 206 Setting and Removing Watch Conditions . . . . 206 Characteristics of Watches . . . . . . . . 207 Setting Watch Conditions . . . . . . . . 208 Displaying Active Watches . . . . . . . . 210 Removing Watch Conditions . . . . . . . 210 Example of Setting a Watch Condition . . . . . 211 Stepping Through the Program Object . . . . . 212 Stepping Over Call Statements . . . . . . 213 Stepping Into Call Statements . . . . . . . 213 Displaying Data and Expressions . . . . . . 217 Changing the Value of Fields . . . . . . . . 226 Displaying Attributes of a Field . . . . . . . 227 Equating a Name with a Field, Expression, or Command . . . . . . . . . . . . . . 228 Source Debug National Language Support for ILE RPG . . . . . . . . . . . . . . . . 229 Sample Source for Debug Examples . . . . . . 229
Renaming Record-Format Names. . . Renaming Field Names . . . . . . Ignoring Record Formats . . . . . Using Input Specifications to Modify an External Description . . . . . . . Using Output Specifications . . . . Level Checking . . . . . . . . . Defining Program-Described Files . . . Data Management Operations and ILE RPG Operations . . . . . . . . . . .
. . .
. . .
. . . . . . . . I/O . .
. 289
. 297
. 265
. 335
Contents
Changing Forms Control Information Program-Described File . . . . . Accessing Tape Devices . . . . . . Accessing Display Devices . . . . . Using Sequential Files . . . . . . Specifying a Sequential File. . . . Using SPECIAL Files . . . . . . . Example of Using a Special File . .
in a . . . . . . . . . . . . . .
. . . . . . .
. . . . . . .
345
. 345 . 345 . 347 . 348 . 348 . 349 . 352 . 353 . . . . . . 354 355 355 356 356 356
427
. . . . . . 427 427 428 431 442 444
Notices . . . . . . . . . . . . . . 463
Programming Interface Information . Trademarks and Service Marks . . . . . . . . . . . 464 . 464
Bibliography . . . . . . . . . . . . 467
vi
Index . . . . . . . . . . . . . . . 471
Contents
vii
viii
v Convert programs from an RPG III format to RPG IV format v Read compiler listings
ix
iSeries Information Center, SK3T-4091-00. This package also includes the PDF versions of iSeries manuals, iSeries Information Center: Supplemental Manuals, SK3T-4092-00, which replaces the Softcopy Library CD-ROM. The iSeries Information Center contains advisors and important topics such as CL commands, system application programming interfaces (APIs), logical partitions, clustering, Java , TCP/IP, Web serving, and secured networks. It also includes links to related IBM Redbooks and Internet links to other IBM Web sites such as the Technical Studio and the IBM home page. The manuals that are most relevant to the ILE RPG compiler are listed in the Bibliography on page 467.
M3C 1H7
If you are mailing a readers comment form from a country other than the United States, you can give the form to the local IBM branch office or IBM representative for postage-paid mailing. v If you prefer to send comments by FAX, use the following number: 1-416-448-6161 v If you prefer to send comments electronically, use one of these e-mail addresses: Comments on books: [email protected] IBMLink: toribm(torrcf) Comments on the Information Center: [email protected] Be sure to include the following: v The name of the book. v The publication number of the book. v The page number or topic to which your comment applies. | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
The following list describes these enhancements: v Improved support for calls between Java and ILE RPG using the Java Native Interface (JNI): A new data type: Object A new definition specification keyword: CLASS The LIKE definition specification keyword has been extended to support objects. The EXTPROC definition specification keyword has been extended to support Java procedures. New status codes. v New built-in functions: Functions for converting a number into a duration that can be used in arithmetic expressions: %MSECONDS, %SECONDS, %MINUTES, %HOURS, %DAYS, %MONTHS, and %YEARS. The %DIFF function, for subtracting one date, time, or timestamp value from another. Functions for converting a character string (or date or timestamp) into a date, time, or timestamp: %DATE, %TIME, and %TIMESTAMP. The %SUBDT function, for extracting a subset of a date, time, or timestamp. Functions for allocating or reallocating storage: %ALLOC and %REALLOC. Functions for finding an element in an array: %LOOKUP, %LOOKUPGT, %LOOKUPGE, %LOOKUPLT, and %LOOKUPLE. Functions for finding an element in a table: %TLOOKUP, %TLOOKUPGT, %TLOOKUPGE, %TLOOKUPLT, and %TLOOKUPLE. Functions for verifying that a string contains only specified characters (or finding the first or last exception to this rule): %CHECK and %CHECKR The %XLATE function, for translating a string based on a list of from-characters and to-characters. The %OCCUR function, for getting or setting the current occurrence in a multiple-occurrence data structure. The %SHTDN function, for determining if the operator has requested shutdown. The %SQRT function, for calculating the square root of a number. v A new free-form syntax for calculation specifications. A block of free-form calculation specifcations is delimited by the compile directives /FREE and /END-FREE v You can specify the EXTFILE and EXTMBR keywords on the file specification to control which external file is used when a file is opened. v Support for qualified names in data structures: A new definition specification keyword: QUALIFIED. This keyword specifies that subfield names will be qualified with the data structure name. A new definition specification keyword: LIKEDS. This keyword specifies that subfields are replicated from another data structure. The subfield names will be qualified with the new data structure name. LIKEDS is allowed for prototyped parameters; it allows the parameters subfields to be used directly in the called procedure. The INZ definition specification keyword has been extended to allow a data structure to be initialized based on its parent data structure. v Enhanced error handling:
About This Guide
xi
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Three new operation codes (MONITOR, ON-ERROR, and ENDMON) allow you to define a group of operations with conditional error handling based on the status code. Other enhancements have been made to this release as well. These include: v You can specify parentheses on a procedure call that has no parameters. v You can specify that a procedure uses ILE C or ILE CL calling conventions, on the EXTPROC definition specification keyword. v The following /DEFINE names are predefined: *VnRnMn, *ILERPG, *CRTBNDRPG, and *CRTRPGMOD. v The search string in a %SCAN operation can now be longer than string being searched. (The string will not be found, but this will no longer generate an error condition.) v The parameter to the DIM, OCCURS, and PERRCD keywords no longer needs to be previously defined. v The %PADDR built-in function can now take either a prototype name or an entry point name as its argument. v A new operation code, ELSEIF, combines the ELSE and IF operation codes without requiring an additional ENDIF. v The DUMP operation code now supports the A extender, which means that a dump is always produced - even if DEBUG(*NO) was specified. v A new directive, /INCLUDE, is equivalent to /COPY except that /INCLUDE is not expanded by the SQL preprocessor. Included files cannot contain embedded SQL or host variables. v The OFLIND file-specification keyword can now take any indicator, including a named indicator, as an argument. v The LICOPT (licensed internal code options) keyword is now available on the CRTRPGMOD and CRTBNDRPG commands. v The PREFIX file description keyword can now take an uppercase character literal as an argument. The literal can end in a period, which allows the file to be used with qualified subfields. v The PREFIX definition specification keyword can also take an uppercase character literal as an argument. This literal cannot end in a period. The following tables summarize the changed and new language elements, based on the part of the language affected.
Table 1. Changed Language Elements Since V4R4 Language Unit Built-in functions Element %CHAR(expression{:format}) Description The optional second parameter specifies the desired format for a date, time, or timestamp. The result uses the format and separators of the specified format, not the format and separators of the input. This function can now take either a prototype name or an entry point name as its argument.
%PADDR(prototype-name)
xii
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Table 1. Changed Language Elements Since V4R4 (continued) Language Unit Definition specification keywords Element EXTPROC(*JAVA:class-name:procname) EXTPROC(*CL:proc-name) EXTPROC(*CWIDEN:proc-name) EXTPROC(*CNOWIDEN:proc-name) INZ(*LIKEDS) Description Specifies that a Java method is called. Specifies a procedure that uses ILE CL conventions for return values. Specifies a procedure that uses ILE C conventions with parameter widening. Specifies a procedure that uses ILE C conventions without parameter widening. Specifies that a data structure defined with the LIKEDS keyword inherits the initialization from its parent data structure. Specifies that an object has the same class as another object. Prefixes the subfields with the specified character literal, optionally replacing the specified number of characters. This keyword can now take any named indicator as a parameter. Prefixes the subfields with the specified character literal, optionally replacing the specified number of characters. This operation code can now take the A extender, which causes a dump to be produced even if DEBUG(*NO) was specified.
LIKE(object-name) PREFIX(character-literal{:number})
OFLIND(name) PREFIX(character-literal{:number})
Operation codes
DUMP (A)
Table 2. New Language Elements Since V4R4 Language Unit Data types Compiler directives Element Object /FREE ... /END-FREE /INCLUDE Description Used for Java objects The /FREE... /END-FREE compiler directives denote a free-form calculation specifications block. Equivalent to /COPY, except that it is not expanded by the SQL preprocessor. Can be used to include nested files that are within the copied file. The copied file cannot have embedded SQL or host variables. Specifies the class for an object. Specifies that a data structure, prototyped parameter, or return value inherits the subfields of another data structure. Specifies that the subfield names in a data structure are qualified with the data structure name. Specifies which file is opened. The value can be a literal or a variable. The default file name is the name specified in position 7 of the file specification. The default library is *LIBL. Specifies which member is opened. The value can be a literal or a variable. The default is *FIRST.
CLASS(*JAVA:class-name) LIKEDS(dsname)
QUALIFIED
EXTFILE(filename)
EXTMBR(membername)
xiii
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Table 2. New Language Elements Since V4R4 (continued) Language Unit Built-in functions Element %ALLOC(num) %CHECK(comparator:base{:start}) %CHECKR(comparator:base{:start}) %DATE(expression{:date-format}) %DAYS(num) %DIFF(op1:op2:unit) Description Allocates the specified amount of storage. Finds the first character in the base string that is not in the comparator. Finds the last character in the base string that is not in the comparator. Converts the expression to a date. Converts the number to a duration, in days. Calculates the difference (duration) between two date, time, or timestamp values in the specified units. Converts the number to a duration, in hours. Finds the specified argument, or the specified type of near-match, in the specified array. Converts the number to a duration, in minutes. Converts the number to a duration, in months. Converts the number to a duration, in microseconds. Sets or gets the current position of a multiple-occurrence data structure. Reallocates the specified amount of storage for the specified pointer. Converts the number to a duration, in seconds. Checks if the system operator has requested shutdown. Calculates the square root of the specified number. Extracts the specified portion of a date, time, or timestamp value. Returns an Object value that contains a reference to the class instance on whose behalf the native method is being called. Converts the expression to a time. Converts the expression to a timestamp. Finds the specified argument, or the specified type of near-match, in the specified table. Translates the specified string, based on the from-string and to-string. Converts the number to a duration, in years.
%HOURS(num) %LOOKUPxx(arg:array{:startindex {:numelems}}) %MINUTES(num) %MONTHS(num) %MSECONDS(num) %OCCUR(dsn-name) %REALLOC(pointer:number) %SECONDS(num) %SHTDN %SQRT(numeric-expression) %SUBDT(value:unit) %THIS
xiv
| | | | | | | | | | | | | | | | | | | | | | |
Table 2. New Language Elements Since V4R4 (continued) Language Unit Operation codes Element MONITOR ON-ERROR ENDMON ELSEIF CRTBNDRPG and LICOPT(options) CRTRPGMOD keywords Description Begins a group of operations with conditional error handling. Performs conditional error handling, based on the status code. Ends a group of operations with conditional error handling. Equivalent to an ELSE operation code followed by an IF operation code. Specifies Licensed Internal Code options.
xv
xvi
RPG IV Specifications
RPG code is written on a variety of specification forms, each with a specific set of functions. Many of the entries which make up a specification type are position-dependent. Each entry must start in a specific position depending on the type of entry and the type of specification. There are seven types of RPG IV specifications. Each specification type is optional. Specifications must be entered into your source program in the order shown below. Main source section: 1. Control specifications provide the compiler with information about generating and running programs, such as the program name, date format, and use of alternate collating sequence or file translation. 2. 3. 4. 5. File description specifications describe all the files that your program uses. Definition specifications describe the data used by the program. Input specifications describe the input records and fields used by the program. Calculation specifications describe the calculations done on the data and the order of the calculations. Calculation specifications also control certain input and output operations. 6. Output specifications describe the output records and fields used by the program. Subprocedure section: 1. Procedure specifications mark the beginning and end of the subprocedure, indicate the subprocedure name, and whether it is exported. 2. Definition specifications describe the local data used by the subprocedure. 3. Calculation specifications describe the calculations done on both the global and local data and the order of the calculations.
RPG IV Overview
Cycle Programming
When a system processes data, it must do the processing in a particular order. This logical order is provided by: v The ILE RPG compiler v The program code The logic the compiler supplies is called the program cycle. When you let the compiler provide the logic for your programs, it is called cycle programming. The program cycle is a series of steps that your program repeats until an end-of-file condition is reached. Depending on the specifications you code, the program may or may not use each step in the cycle. If you want to have files controlled by the cycle, the information that you code on RPG specifications in your source program need not specify when records for these files are read. The compiler supplies the logical order for these operations, and some output operations, when your source program is compiled. If you do not want to have files controlled by the cycle, you must end your program some other way, either by creating an end-of-file condition by setting on the last record (LR) indicator, by creating a return condition by setting on the return (RT) indicator, or by returning directly using the RETURN operation. Note: No cycle code is generated for subprocedures or when NOMAIN is specified on the control specification. Figure 1 shows the specific steps in the general flow of the RPG program cycle.
Start
No Move fields
LR on
Yes
End of program
RPG processes all heading and detail lines (H or D in position 17 of the output specifications).
RPG IV Overview
2 3 4 5 6 7 RPG reads the next record and sets on the record identifying and control level indicators. RPG processes total calculations (conditioned by control level indicators L1 through L9, an LR indicator, or an L0 entry). RPG processes all total output lines (identified by a T in position 17 of the output specifications). RPG determines if the LR indicator is on. If it is on, the program ends. The fields of the selected input records move from the record to a processing area. RPG sets on field indicators. RPG processes all detail calculations (not conditioned by control level indicators in positions 7 and 8 of the calculation specifications). It uses the data from the record at the beginning of the cycle.
The first cycle The first and last time through the program cycle differ somewhat from other cycles. Before reading the first record the first time through the cycle, the program does three things: v handles input parameters, opens files, initializes program data v writes the records conditioned by the 1P (first page) indicator v processes all heading and detail output operations. For example, heading lines printed before reading the first record might consist of constant or page heading information, or special fields such as PAGE and *DATE. The program also bypasses total calculations and total output steps on the first cycle. The last cycle The last time a program goes through the cycle, when no more records are available, the program sets the LR (last record) indicator and the L1 through L9 (control level) indicators to on. The program processes the total calculations and total output, then all files are closed, and then the program ends.
Subprocedure logic
The general flow of a subprocedure is much simpler: the calculations of a subprocedure are done once, and then the subprocedure returns. There is no cycle code generated for a subprocedure.
Indicators
An indicator is a one-byte character field that is either set on (1) or off (0). It is generally used to indicate the result of an operation or to condition (control) the processing of an operation. Indicators are like switches in the flow of the program logic. They determine the path the program will take during processing, depending on how they are set or used. Indicators can be defined as variables on the definition specifications. You can also use RPG IV indicators, which are defined either by an entry on a specification or by the RPG IV program itself.
RPG IV Overview
Each RPG IV indicator has a two-character name (for example, LR, 01, H3), and is referred to in some entries of some specifications just by the two-character name, and in others by the special name *INxx where xx is the two-character name. You can use several types of these indicators; each type signals something different. The positions on the specification in which you define an indicator determine the use of the indicator. Once you define an indicator in your program, it can limit or control calculation and output operations. Indicator variables can be used any place an indicator of the form *INxx may be used with the exception of the OFLIND and EXTIND keywords on the file description specifications. An RPG program sets and resets certain indicators at specific times during the program cycle. In addition, the state of indicators can be changed explicitly in calculation operations.
Operation Codes
The RPG IV programming language allows you to do many different types of operations on your data. Operation codes, entered on the calculation specifications, indicate what operations will be done. For example, if you want to read a new record, you could use the READ operation code. The following is a list of the types of operations available. v Arithmetic operations v Array operations v Bit operations v Branching operations v Call operations v Compare operations v Conversion operations v Data-area operations v Date operations v Declarative operations v Error-handling operations v File operations v Indicator-setting operations v Information operations v Initialization operations v Memory management operations v Move operations v Move zone operations v Result operations v Size operations v String operations v Structured programming operations v Subroutine operations v Test operations
22
27
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ..* A..........T.Name++++++RLen++TDpB......Functions++++++++++++++++++++* A R EMP_REC A EMP_NUMBER 5 TEXT('EMPLOYEE NUMBER') A EMP_NAME 16 TEXT('EXPLOYEE NAME') A EMP_RATE 5 2 TEXT('EXPLOYEE RATE') A K EMP_NUMBER Figure 2. DDS for Employee physical file
The second file, TRANSACT, tracks the number of hours each employee worked for that week and any bonus that employee may have received. The figure below shows the format of a transaction record:
TRN_REC
TRN_NUMBER
TRN_HOURS
TRN_BONUS
10
16
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ..* A..........T.Name++++++RLen++TDpB......Functions++++++++++++++++++++* A R TRN_REC A TRN_NUMBER 5 TEXT('EMPLOYEE NUMBER') A TRN_HOURS 4 1 TEXT('HOURS WORKED') A TRN_BONUS 6 2 TEXT('BONUS') Figure 3. DDS for TRANSACT physical file
Each employees pay is calculated by multiplying the hours (from the TRANSACT file) and the rate (from the EMPLOYEE file) and adding the bonus from the TRANSACT file. If more than 40 hours were worked, the employee is paid for for 1.5 times the normal rate. Control Specifications
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 HKeywords++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ H DATEDIT(*DMY/)
Today's date will be printed in day, month, year format with / as the separator.
Chapter 1. Overview of the RPG IV Programming Language
There are three files defined on the file description specifications: v The TRANSACT file is defined as the Input Primary file. The ILE RPG program cycle controls the reading of records from this file. v The EMPLOYEE file is defined as the Input Full-Procedure file. The reading of records from this file is controlled by operations in the calculation specifications. v The QSYSPRT file is defined as the Output Printer file. Definition Specifications
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... D+Name++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++ D Pay S 8P 2 D Heading1 C 'NUMBER NAME RATE HD OURS BONUS PAY ' D Heading2 C '______ ________________ ______ _D ____ _______ __________' D CalcPay PR 8P 2 D Rate 5P 2 VALUE D Hours 10U 0 VALUE D Bonus 5P 2 VALUE
Using the definition specifications, declare a variable called Pay to hold an employees weekly pay and two constants Heading1 and Heading2 to aid in the printing of the report headings. Calculation Specifications
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... /free chain trn_number emp_rec; if %found(emp_rec); pay = CalcPay (emp_rate: trn_hours: trn_bonus); endif; /end-free
The coding entries on the calculation specifications include: v Using the CHAIN operation code, the field TRN_NUMBER from the transaction file is used to find the record with the same employee number in the employee file. v If the CHAIN operation is successful (that is, indicator 99 is off), the pay for that employee is evaluated. The result is rounded and stored in the variable called Pay. Output Specifications
The output specifications describe what fields are to be written on the QSYSPRT output: v The Heading Lines that contain the constant string PAYROLL REGISTER as well as headings for the detail information will be printed if indicator 1P is on. Indicator 1P is turned on by the ILE RPG program cycle during the first cycle. v The Detail Lines are conditioned by the indicators 1P and 99. Detail Lines are not printed at 1P time. The N99 will only allow the Detail lines to be printed if indicator 99 is off, which indicates that the corresponding employee record has been found. If the indicator 99 is on, then the employee number and the constant string ** NOT ON EMPLOYEE FILE ** will be printed instead. v The Total Line contains the constant string END OF LISTING. It will be printed during the last program cycle. A Subprocedure The subprocedure calculates the pay for the employee using the parameters passed to it. The resulting value is returned to the caller using the RETURN statement. The procedure specifications indicate the beginning and end of the procedure. The definition specifications define the return type of the procedure, the parameters to the procedure, and the local variable Overtime.
/free // Determine any overtime hours to be paid. if Hours > 40; Overtime = (Hours - 40) * Rate * 1.5; Hours = 40; endif; // Calculate the total pay and return it to the caller. return Rate * Hours + Bonus + Overtime; /end-free P CalcPay E
The Entire Source Program The following figure combines all the specifications used in this program. This is what you should enter into the source file for this program.
*------------------------------------------------------------------------* * DESCRIPTION: This program creates a printed output of employee's pay * * for the week. * *------------------------------------------------------------------------* H DATEDIT(*DMY/) *------------------------------------------------------------------------* * File Definitions * *------------------------------------------------------------------------* FTRANSACT IP E K DISK FEMPLOYEE IF E K DISK FQSYSPRT O F 80 PRINTER *------------------------------------------------------------------------* * Variable Declarations * *------------------------------------------------------------------------* D Pay S 8P 2 Figure 4. A Sample Payroll Calculation Program (Part 1 of 3)
10
11
If you have internet access, you can obtain a complete list of publications that discuss the OS/400 system at the following URL:
http://publib.boulder.ibm.com/
You can also order the AS/400 V4 System Library Poster, G325-6334-02.
12
Compiling
CRTxxxMOD CRTBNDxxx
Binding
Creates a program from ILE modules Creates a service program Updates a bound program object
Debugging
STRDBG ENDDBG
Creating Files
Creates Print File Creates Physical File Creates Source Physical File Creates Logical File
13
v Modify any fields or records that are documented in a dictionary v Examine the calling hierarchy
14
15
16
Compared to OPM, ILE provides RPG users with improvements or enhancements in the following areas of application development: v Program creation v Program management v Program call v Source debugging v Bindable application program interfaces (APIs) Each of the above areas is explained briefly in the following paragraphs and discussed further in the following chapters.
Program Creation
In ILE, program creation consists of: 1. Compiling source code into modules 2. Binding (combining) one or more modules into a program object You can create a program object much like you do in the OPM framework, with a one-step process using the Create Bound RPG Program (CRTBNDRPG) command. This command creates a temporary module which is then bound into a program object. It also allows you to bind other objects through the use of a binding directory. Alternatively, you may create a program using separate commands for compilation and binding. This two-step process allows you to reuse a module or update one
Copyright IBM Corp. 1994, 2001
17
Once a program is created you can update the program using the Update Program (UPDPGM) or Update Service Program (UPDSRVPGM) commands. This is useful, because it means you only need to have the new or changed module objects available to update the program. For more information on the one-step process, see Chapter 6. Creating a Program with the CRTBNDRPG Command on page 59. For more information on the two-step process, see Chapter 7. Creating a Program with the CRTRPGMOD and
18
Program Management
ILE provides a common basis for: v Managing program flow v Sharing resources v Using application program interfaces (APIs) v Handling exceptions during a programs run time It gives RPG users much better control over resources than was previously possible. ILE programs and service programs are activated into activation groups which are specified at program-creation time. The process of getting a program or service program ready to run is known as activation. Activation allocates resources within a job so that one or more programs can run in that space. If the specified activation group for a program does not exist when the program is called, then it is created within the job to hold the programs activation. An activation group is the key element governing an ILE applications resources and behavior. For example, you can scope commitment-control operations to the activation group level. You can also scope file overrides and shared open data paths to the activation group of the running application. Finally, the behavior of a program upon termination is also affected by the activation group in which the program runs. For more information on activation groups, see Managing Activation Groups on page 107. You can dynamically allocate storage for a run-time array using the bindable APIs provided for all ILE programming languages. These APIs allow single- and mixed-language applications to access a central set of storage management functions and offer a storage model to languages that do not now provide one. RPG offers some storage management capabilities using operation codes. For more information on storage management, see Managing Dynamically-Allocated Storage on page 111.
Program Call
In ILE, you can write applications in which ILE RPG programs and OPM RPG/400 programs continue to interrelate through the traditional use of dynamic program calls. When using such calls, the calling program specifies the name of the called program on a call statement. The called programs name is resolved to an address at run time, just before the calling program passes control to the called program. You can also write ILE applications that can interrelate with faster static calls. Static calls involve calls between procedures. A procedure is a self-contained set of code that performs a task and then returns to the caller. An ILE RPG module consists of an optional main procedure followed by zero or more subprocedures. Because the procedure names are resolved at bind time (that is, when you create the program), static calls are faster than dynamic calls. Static calls also allow
Chapter 2. RPG Programming in ILE
19
Operational descriptors and omitted parameters can be useful when calling bindable APIs or procedures written in other ILE languages. For information on running a program refer to Chapter 9. Running a Program on page 101. For information on program/procedure call, refer to Chapter 10. Calling Programs and Procedures on page 125.
Source Debugging
In ILE, you can perform source-level debugging on any single- or mixed-language ILE application. The ILE source debugger also supports OPM programs. You can control the flow of a program by using debug commands while the program is running. You can set conditional and unconditional job or thread breakpoints prior to running the program. After you call the program, you can then step through a specified number of statements, and display or change variables. When a program stops because of a breakpoint, a step command, or a run-time error, the pertinent module is shown on the display at the point where the program stopped. At that point, you can enter more debug commands. For information on the debugger, refer to Chapter 12. Debugging Programs on page 183.
Bindable APIs
ILE offers a number of bindable APIs that can be used to supplement the function currently offered by ILE RPG. The bindable APIs provide program calling and activation capability, condition and storage management, math functions, and dynamic screen management. Some APIs that you may wish to consider using in an ILE RPG application include: v CEETREC Signal the Termination-Imminent Condition v CEE4ABN Abnormal End v CEECRHP Create your own heap v CEEDSHP Discard your own heap v CEEFRST Free Storage in your own heap v CEEGTST Get Heap Storage in your own heap v CEECZST Reallocate Storage in your own heap v CEEDOD Decompose Operational Descriptor Note: You cannot use these or any other ILE bindable APIs from within a program created with DFTACTGRP(*YES). This is because bound calls are not allowed in this type of program. For more information on these ILE bindable APIs, see Chapter 9. Running a Program on page 101.
20
Multithreaded Applications
The iSeries system now supports multithreading. ILE RPG does not directly support initiating or managing program threads. However, ILE RPG procedures can run as threads in multithreaded environments. If you want to call an ILE RPG procedure in a multithreaded application, you must ensure that the ILE RPG procedure is threadsafe. You must also ensure that any system functions that your procedure accesses are also threadsafe. The THREAD(*SERIALIZE) control specification keyword can be specified to help you achieve thread safety for an ILE RPG module. Specifying THREAD(*SERIALIZE) will protect most of your variables and all your internal control structures from being accessed improperly by multiple threads. The thread safe module will be locked when a procedure in the module is entered and unlocked when when no procedure in the module is still running. This serialized access, ensures that only one thread is active in any one module, within an activation group, at any one time. However, it is still up to the programmer to handle thread safety for storage that is shared across modules. This is done by adding logic in the application to synchronize access to the storage. For more information, see Multithreading Considerations on page 153.
21
22
Method
Use the following general approach to create such a program: 1. Convert your source to RPG IV using the CVTRPGSRC command. Be sure to convert all /COPY members that are used by the source you are converting. 2. Create a program object using the CRTBNDRPG command, specifying DFTACTGRP(*YES). Specifying DFTACTGRP(*YES) means that the program object will run only in the default activation group. (The default activation group is the activation group where all OPM programs are run.) As a result, the program object will interact well with OPM programs in the areas of override scoping, open scoping, and RCLRSC. When you use this approach you cannot make use of ILE static binding. This means that you cannot code a bound procedure call in your source, nor can you use the BNDDIR or ACTGRP parameters on the CRTBNDRPG command when creating this program.
23
OPM-Compatible Application
program and two RPG programs. In this example, one of the RPG programs has been moved to ILE; the remaining programs are unchanged.
Job
Default Activation Group *PGM(X) OPM CL
Effect of ILE
The following deals with the effects of ILE on the way your application handles: Program call OPM programs behave as before. The system automatically creates the OPM default activation group when you start your job, and all OPM applications run in it. One program can call another program in the default activation group by using a dynamic call. Storage for static data is created when the program is activated, and it exists until the program is deactivated. When the program ends (either normally or abnormally), the programs storage is deleted. To clean up storage for a program that returns without ending, use the Reclaim Resource (RCLRSC) command. File processing is the same as in previous releases. Files are closed when the program ends normally or abnormally. As in previous releases, the compiler handles errors within each program separately. The errors you see that originated within your program are the same as before. However, the errors are now communicated between programs by the ILE condition manager, so you may see different messages between programs. The messages may have new message IDs, so if your CL program monitors for a specific message ID, you may have to change that ID.
Data
Files Errors
Related Information
Converting to RPG IV One-step creation process ILE static binding Converting Your Source on page 404 Chapter 6. Creating a Program with the CRTBNDRPG Command on page 59 Chapter 10. Calling Programs and Procedures on page 125; also ILE Concepts
24
OPM-Compatible Application
Exception handling differences Differences between OPM and ILE RPG Exception Handling on page 240
Method
Use the following general approach to create such a program: 1. If starting with RPG III source, convert your source to RPG IV using the CVTRPGSRC command. If converting, be sure to convert all /COPY members and any programs that are called by the source you are converting. Also, if you are using CL to call the program, you should also make sure that you are using ILE CL instead of OPM CL. 2. Determine the activation group the program will run in. You may want to name it after the application name, as in this example. 3. Identify the names of the binding directories, if any, to be used. It is assumed with this approach that if you are using a binding directory, it is one that is already created for you. For example, there may be a third-party service program that you may want to bind to your source. Consequently, all you need to know is the name of the binding directory. 4. Create an ILE program using CRTBNDRPG, specifying DFTACTGRP(*NO), the activation group on the ACTGRP parameter, and the binding directory, if any, on the BNDDIR parameter. Note that if ACTGRP(*CALLER) is specified and this program is called by a program running in the default activation group, then this program will behave according to ILE semantics in the areas of override scoping, open scoping, and RCLRSC. The main drawback of this strategy is that you do not have a permanent module object that you can later reuse to bind with other modules to create an ILE program. Furthermore, any procedure calls must be to modules or service programs that are identified in a binding directory. If you want to bind two or more modules without using a binding directory when you create the program, you need to use the third strategy.
25
Effect of ILE
The following deals with the effects of ILE on the way your program handles: Program call The system automatically creates the activation group if it does not already exist, when the application starts. The application can contain dynamic program calls or static procedure calls. Procedures within bound programs call each other by using static calls. Procedures call ILE and OPM programs by using dynamic calls. Data The lifetime of a programs storage is the same as the lifetime of the activation group. Storage remains active until the activation group is deleted. The ILE RPG run time manages data so that the semantics of ending programs and reinitializing the data are the same as for OPM RPG, although the actual storage is not deleted as it was when an OPM RPG program ended. Data is reinitialized if the previous call to the procedure ended with LR on, or ended abnormally. Program data that is identified as exported or imported (using the keywords EXPORT and IMPORT respectively) is external to the individual modules. It is known among the modules that are bound into a program. Files By default, file processing (including opening, sharing, overriding, and commitment control) by the system is scoped to the activation group level. You cannot share files at the data management level with programs in different activation groups. If you want to share a file across activation groups, you must open it at the job level by specifying SHARE(*YES) on an override command or create the file with SHARE(*YES). When you call an ILE RPG program or procedure in the same
Errors
26
Related Information
Converting to RPG IV One-step creation process Activation groups RCLRSC ILE static binding Converting Your Source on page 404 Chapter 6. Creating a Program with the CRTBNDRPG Command on page 59 Managing Activation Groups on page 107 Reclaim Resources Command on page 110 Chapter 10. Calling Programs and Procedures on page 125; also ILE Concepts
Exception handling differences Differences between OPM and ILE RPG Exception Handling on page 240 Override and open scope Overriding and Redirecting File Input and Output on page 291 and Sharing an Open Data Path on page 295; also ILE Concepts
27
Method
Because this approach is the most flexible, it includes a number of ways in which you might create an ILE application. The following list describes the main steps that you may need to perform: 1. Create a module from each source member using the appropriate command, for example, CRTRPGMOD for RPG source, CRTCLMOD for CL source, etc.. 2. Determine the ILE characteristics for the application, for example: v Determine which module will contain the procedure that will be the starting point for the application. The module you choose as the entry module is the first one that you want to get control. In an OPM application, this would be the command processing program, or the program called because a menu item was selected. v Determine the activation group the application will run in. (Most likely you will want to run in a named activation group, where the name is based on the name of the application.) v Determine the exports and imports to be used. 3. Determine if any of the modules will be bound together to create a service program. If so, create the service programs using CRTSRVPGM. 4. Identify the names of the binding directories, if any, to be used. It is assumed with this approach that if you are using a binding directory, it is one that is already created for you. For example, there may be a third-party service program that you may want to bind to your source. Consequently, all you need to know is the name of the binding directory. 5. Bind the appropriate modules and service programs together using CRTPGM, specifying values for the parameters based on the characteristics determined in step 2. An application created using this approach can run fully protected, that is, within its own activation group. Furthermore, it can be updated easily through use of the UPDPGM or UPDSRVPGM commands. With these commands you can add or replace one or more modules without having to re-create the program object.
28
RPG *MODULE(Y2)
RPG *MODULE(Y3)
RPG *MODULE(Y4)
The call from program X to program Y is a dynamic call. The calls among the modules in program Y are static calls. See Effect of ILE on page 26 for details on the effects of ILE on the way your application handles calls, data, files and errors.
29
CL *MODULE(Y1)
RPG *MODULE(Y2)
C *MODULE(Y3)
RPG *MODULE(Y4)
The call from program Y to the OPM API is a dynamic call. The calls among the modules in program Y are static calls. See Effect of ILE on page 26 for details on the effects of ILE on the way your application handles calls, data, files and errors.
30
*SRVPGM(Z) C *MODULE(Z1)
CL *MODULE(Z2)
The calls from program X to service programs Y and Z are static calls. See Effect of ILE on page 26 for details on the effects of ILE on the way your application handles calls, data, files and errors.
Related Information
Two-step creation process Chapter 7. Creating a Program with the CRTRPGMOD and CRTPGM Commands on page 73 Managing Activation Groups on page 107 Chapter 10. Calling Programs and Procedures on page 125; also ILE Concepts Chapter 13. Handling Exceptions on page 235; also ILE Concepts Chapter 8. Creating a Service Program on page 89; also ILE Concepts Using the UPDPGM Command on page 85
Activation groups ILE static binding Exception Handling Service programs Updating a Program
A Strategy to Avoid
ILE provides many alternatives for creating programs and applications. However, not all are equally good. In general, you should avoid a situation where an application consisting of OPM and ILE programs is split across the OPM default activation group and a named activation group. In other words, try to avoid the scenario shown in Figure 11 on page 32.
31
A Strategy to Avoid
Job
Default Activation Group *PGM(X) CL
*SRVPGM(Z) RPG
Figure 11. Scenario to Avoid. An application is split between the OPM default activation group and a named activation group.
When split across the default activation group and any named activation group, you are mixing OPM behavior with ILE behavior. For example, programs in the default activation group may be expecting the ILE programs to free their resources when the program ends. However, this will not occur until the activation group ends. Similarly, the scope of overrides and shared ODPs will be more difficult to manage when an application is split between the default activation group and a named one. By default, the scope for the named group will be at the activation group level, but for the default activation group, it can be either call level or job level, not activation group level.
32
Subprocedures can provide independence from other procedures because the data items are local. Local data items are normally stored in automatic storage, which means that the value of a local variable is not preserved between calls to the procedure. Subprocedures offer another feature. You can pass parameters to a subprocedure by value, and you can call a subprocedure in an expression to return a value.
33
*MODULE
Main Procedure H specifications F specifications D specifications - Data items visible throughout module I specifications C specifications O specifications Subprocedure 1 P specification D specifications - Data items visible only to Subprocedure 1 C specifications - Can access local and global data items P specifications Global Scope
Local Scope
Subprocedure 2 P specification D specifications - Data items visible only to Subprocedure 2 C specifications - Can access local and global data items P specifications
Local Scope
As the picture suggests, you can now code subprocedures to handle particular tasks. These tasks may be needed by the main procedures or by other modules in the application. Furthermore, you can declare temporary data items in subprocedures and not have to worry if you have declared them elsewhere in the module.
Prototyped Calls
To call a subprocedure, you must use a prototyped call. You can also call any program or procedure that is written in any language in this way. A prototyped call is one where the call interface is checked at compile time through the use of a prototype. A prototype is a definition of the call interface. It includes the following information: v Whether the call is bound (procedure) or dynamic (program) v How to find the program or procedure (the external name) v The number and nature of the parameters
34
| | |
To convert character strings to a number, InArrears calls a procedure CharToNum. CharToNum has a character input parameter, and returns a numeric field. Figure 14 on page 36 shows the prototype for CharToNum.
35
If the program or procedure is prototyped, you call it with CALLP or within an expression if you want to use the return value. You pass parameters in a list that follows the name of the prototype, for example, name (parm1 : parm2 : ...). Figure 15 shows a call to FmtCust. Note that the names of the output parameters, shown above in Figure 13 on page 35, do not match those in the call statement. The parameter names in a prototype are for documentation purposes only. The prototype serves to describe the attributes of the call interface. The actual definition of call parameters takes place inside the procedure itself.
C CALLP FmtCust(RPTNAME : RPTADDR)
Using prototyped calls you can call (with the same syntax): v Programs that are on the system at run time
36
The use of procedures to return values, as in the above figure, allows you to write any user-defined function you require. In addition, the use of a prototyped call interface opens up a number of new options for parameter passing. v Prototyped parameters can be passed in several ways: by reference, by value (for procedures only), or by read-only reference. The default method for RPG is to pass by reference. However, passing by value or by read-only reference gives you more options for passing parameters. v If the prototype indicates that it is allowed for a given parameter, you may be able to do one or more of the following: Pass *OMIT Leave out a parameter entirely Pass a shorter parameter than is specified (for character and graphic parameters, and for array parameters)
37
Now consider the first subprocedure, InArrears, which is shown in Figure 18 on page 39 . InArrears is called by the main procedure to determine if the current record is in arrears.
TIP When coding subprocedures that use global fields, you may want to establish a naming convention that shows the item to be global. In this example, the uppercase field names indicate DDS fields. Another option would be to prefix g_, or some other string to indicate global scope. | | | | | | Since the data comes from another type of computer system, the AMOUNTC field is a character string that represents a numeric value, for example 12.35. One of the tasks requires reading a string containing a numeric value and extracting the numeric value. This conversion is a very common task, so we decided to code it as a separate subprocedure, CharToNum. This subprocedure takes a character string and returns a packed number with 30 digits and 9 decimal positions. If the record is in arrears, the subprocedure returns 1 to the main procedure.
38
Figure 18 shows the main elements that are common to all subprocedures. 1 2 All subprocedures begin and end with procedure specifications. After the Begin-Procedure specification (B in position 24 of the procedure specification), you code a procedure interface definition. The return value, if any, is defined on the PI specification. Any parameters are listed after the PI specification. Any variables or prototypes that are used by the subprocedure are defined after the procedure interface definition. The return value, if specified, is returned to the caller with a RETURN operation. If the record is not in arrears, the subprocedure returns 0 to the main procedure.
3 4 5
For all subprocedures, and also for a main procedure with prototyped entry parameters, you need to define a procedure interface. A procedure interface definition is a repeat of the prototype information within the definition of a procedure. It is used to define the entry parameters for the procedure. The procedure interface definition is also used to ensure that the internal definition of the procedure is consistent with the external definition (the prototype). In the case of InArrears, there are no entry parameters. Consider next the subprocedure FmtCust, which is shown in Figure 19 on page 40. FmtCust is called by ARRSRPT to format the relevant fields of a record into an output record for the final report. (The record represents an account that is in
39
100A 100A 5A
/free //-------------------------------------------------------------// CUSTNAME and CUSTNUM are formatted to look like this: // A&P Electronics (Customer number 157) //-------------------------------------------------------------Name = CUSTNAME + ' ' + '(Customer number ' + %char(CUSTNUM) + ')'; //-------------------------------------------------------------// STREETNUM, STREETNAME, CITY, STATE, and ZIP are formatted to // look like: // 27 Garbanzo Avenue, Smallville IN 51423 //-------------------------------------------------------------ZipChar = %editc(ZIP:'X'); Address = %char(STREETNUM) + ' ' + %trimr(STREETNAME) + ', ' + %trim(CITY) + ' ' + %trim(STATE) + ' ' + ZipChar; /end-free P FmtCust E Figure 19. Source for Subprocedure FmtCust
Finally, consider the last subprocedure of this application, CharToNum. Notice that CharToNum does not appear in the ARRSRPT module, that is shown in Figure 17 on page 38. We decided to place CharToNum inside another module called CVTPROCS. CVTPROCS is a utility module that will contain any conversion procedures that other modules might need to use. Figure 20 on page 41 shows the source of the module CVTPROCS. Since this is a prototyped procedure, it needs the prototype to be available. So that the prototype can be shared, we have placed the prototype into a /COPY file.
40
41
CVTPROCS is a NOMAIN module, meaning that it consists only of subprocedures; there is no main procedure. A NOMAIN module compiles faster and requires less storage because there is no cycle code that is created for the module. You specify a NOMAIN module, by coding the NOMAIN keyword on the control specification. For more information on NOMAIN modules, see Program Creation on page 47.
42
43
Figure 22. ILE RPG Complete Source for ARRSRPT Module (Part 2 of 3)
44
*-------------------------------------------------------------* FmtCust formats CUSTNAME, CUSTNUM, STREETNAME etc into * readable forms * * Parameters: Name (output) * Address (output) * Globals: CUSTNAME, CUSTNUM, STREETNUM, STREETNAME, CITY STATE, ZIP * Returns: (none) *-------------------------------------------------------------P FmtCust B D FmtCust PI D Name 100A D Address 100A D ZipChar S 5A *-------------------------------------------------------------* CUSTNAME and CUSTNUM are formatted to look like this: * A&P Electronics (Customer number 157) *-------------------------------------------------------------C EVAL Name = CUSTNAME + ' ' C + '(Customer number ' C + %char(CUSTNUM) + ')' *-------------------------------------------------------------* StreetNum, STREETNAME, CITY, STATE, and ZIP are formatted to look like: * 27 Garbanzo Avenue, Smallville 51423 *-------------------------------------------------------------C MOVEL ZIP ZipChar C EVAL Address = %char(STREETNUM)) C + ' ' + %trimr(STREETNAME) + ', ' C + %trim(CITY) + ' ' + %trim(STATE) C + ' ' + ZipChar P FmtCust E Figure 22. ILE RPG Complete Source for ARRSRPT Module (Part 3 of 3)
Note the following about ARRSRPT: v The definition specifications begin with the prototypes for the prototyped calls. A /COPY file is used to supply the prototype for the called procedure CharToNum. The prototypes do not have to be first, but you should establish an order for the different types of definitions for consistency. v The date field CurDate is a global field, meaning that any procedure in the module can access it. v The main procedure is simple to follow. It contains calculation specifications for the two main tasks: the I/O, and an initialization routine. v Each subprocedure that follows the main procedure contains the details of one of the tasks. Sample output for the program ARRSRPT is shown in Figure 23 on page 46.
45
Figure 24 and Figure 25 show the DDS source for the files CUSTFILE and CUSTRPT respectively.
A*================================================================* A* FILE NAME : CUSTFILE A* RELATED PGMS : ARRSRPT A* DESCRIPTIONS : THIS IS THE PHYSICAL FILE CUSTFILE. IT HAS A* ONE RECORD FORMAT CALLED CUSTREC. A*================================================================* A* CUSTOMER MASTER FILE -- CUSTFILE A R CUSTREC A CUSTNUM 5 0 TEXT('CUSTOMER NUMBER') A CUSTNAME 20 TEXT('CUSTOMER NAME') A STREETNUM 5 0 TEXT('CUSTOMER ADDRESS') A STREETNAME 20 TEXT('CUSTOMER ADDRESS') A CITY 20 TEXT('CUSTOMER CITY') A STATE 2 TEXT('CUSTOMER STATE') A ZIP 5 0 TEXT('CUSTOMER ZIP CODE') A AMOUNTC 15 TEXT('AMOUNT OUTSTANDING') A DUEDATE 10 TEXT('DATE DUE') Figure 24. DDS for CUSTFILE A*================================================================* A* FILE NAME : CUSTRPT A* RELATED PGMS : ARRSRPT A* DESCRIPTIONS : THIS IS THE PRINTER FILE CUSTRPT. IT HAS A* ONE RECORD FORMAT CALLED ARREARS. A*================================================================* A R ARREARS A 2 6 A 'Customer number:' A RPTNUM 5 0 2 23 A TEXT('CUSTOMER NUMBER') A RPTNAME 100A 3 10 A TEXT('CUSTOMER NAME') A RPTADDR 100A 4 10 A TEXT('CUSTOMER ADDRESS') A 5 10'Amount outstanding:' A AMOUNT 10 2 5 35EDTWRD(' $0. ') A TEXT('AMOUNT OUTSTANDING') A 5 50'Due date:' A DUEDATE 10 5 60 A TEXT('DATE DUE') Figure 25. DDS for CUSTRPT
46
Coding Considerations
Coding Considerations
This section presents some considerations that you should be aware of before you begin designing applications with multiple-procedure modules. The items are grouped into the following categories: v v v v General Program Creation Main Procedures Subprocedures
General Considerations
v When coding a module with multiple procedures, you will want to make use of /COPY files, primarily to contain any prototypes that your application may require. If you are creating a service program, you will need to provide both the service program and the prototypes, if any. v Maintenance of the application means ensuring that each component is at the most current level and that any changes do not affect the different pieces. You may want to consider using a tool such as Application Development Manager to maintain your applications. For example, suppose that another programmer makes a change to the /COPY file that contains the prototypes. When you request a rebuild of your application, any module or program that makes use of the /COPY file will be recompiled automatically. You will find out quickly if the changes to the /COPY file affect the calls or procedure interfaces in your application. If there are compilation errors, you can then decide whether to accept the change to prototypes to avoid these errors, or whether to change the call interface.
Program Creation
v If you specify that a module does not have a main procedure then you cannot use the CRTBNDRPG command to create the program. (A module does not have a main procedure if the NOMAIN keyword is specified on a control specification.) This is because the CRTBNDRPG command requires that the module contain a program entry procedure and only a main procedure can be a program entry procedure. v Similarly, when using CRTPGM to create the program, keep in mind that a NOMAIN module cannot be an entry module since it does not have a program entry procedure. v A program that is created to run in the default OPM activation group (by specifying DFTACTGRP(*YES) on the CRTBNDRPG command) cannot contain bound procedure calls.
47
Coding Considerations
v The functionality of an *ENTRY PLIST is similar to a prototyped call interface. However, a prototyped call interface is much more robust since it provides parameter checking at compile time. If you prototype the main procedure, then you specify how it is to be called by specifying either the EXTPROC or EXTPGM keyword on the prototype definition. If EXTPGM is specified, then an external program call is used; if EXTPROC is specified or if neither keyword is specified, it will be called by using a procedure call. v You cannot define return values for a main procedure, nor can you specify that its parameters be passed by value.
Subprocedure Considerations
v Any of the calculation operations may be coded in a subprocedure. However, all files must be defined globally, so all input and output specifications must be defined in the main source section. Similarly, all data areas must be defined in the main procedure, although they can be used in a subprocedure. v The control specification can only be coded in the main source section since it controls the entire module. v A subprocedure can be called recursively.Each recursive call causes a new invocation of the procedure to be placed on the call stack. The new invocation has new storage for all data items in automatic storage, and that storage is unavailable to other invocations because it is local. (A data item that is defined in a subprocedure uses automatic storage unless the STATIC keyword is specified for the definition.) The automatic storage that is associated with earlier invocations is unaffected by later invocations. All invocations share the same static storage, so later invocations can affect the value held by a variable in static storage. Recursion can be a powerful programming technique when properly understood. v The run-time behavior of a subprocedure differs somewhat from that of a main procedure, because there is no cycle code for the subprocedure. When a subprocedure ends, it simply returns to the caller. None of the usual termination activities, such as closing of files, occurs until the main procedure that is associated with the subprocedure itself ends. You should code a cleanup subprocedure that is called both by the program entry procedure at application-end, and by a cancel handler enabled for the program entry procedure. An alternative is to code the NOMAIN module so that there is no implicit file opening or data area locking, and that within any subprocedure, an open is matched by a close, an IN by an OUT, a CRT<temp obj> by a DLT<temp obj>, and so on. This alternative applies to modules that may have a subprocedure active when the main procedure is not active. Exception handling within a subprocedure differs from a main procedure primarily because there is no default exception handler for subprocedures. As a result, situations where the default handler would be called for a main procedure correspond to abnormal end of the subprocedure.
Main Procedures
Topic See
48
Subprocedures
Topic Defining NOMAIN module Exception handling Procedure Specification Procedure Interface Subprocedure End See Chapter on subprocedures, in the ILE RPG Reference Creating a NOMAIN Module on page 75 Exception Handling within Subprocedures on page 239 Chapter on procedure specifications, in the ILE RPG Reference Chapter on defining data and prototypes in the ILE RPG Reference Returning from a Subprocedure on page 150
Prototyped Call
Topic Free-form call General Information Passing parameters Prototypes See Using a Prototyped Call on page 130 ILE RPG Reference, Chapter 24 Passing Prototyped Parameters on page 132 Chapter on defining data and prototypes in the ILE RPG Reference
49
50
Many Integrated Language Environment terms and concepts are discussed briefly in the following pages. These terms and concepts are more fully discussed in ILE Concepts.
51
52
Minimum Record Length (92 characters) Recommended Record Length (112 characters)
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, refer to the ADTS for AS/400: Source Entry Utility manual and the ADTS/400: Programming Development Manager manual.
53
Using SEU
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:
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 in Figure 27 on page 55. Note that the screen is automatically shifted so that position 6 is (for specification type) at the left edge.
54
Using SEU
Columns . . . : 6 76 Edit MYLIB/QRPGLESRC SEU==> ___________________________________________________________ EMPRPT FMT H HKeywords++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *************** Beginning of data ************************************* ''''''' ''''''' ''''''' ''''''' ''''''' ''''''' ''''''' ''''''' ''''''' ''''''' ''''''' ''''''' ''''''' ''''''' ''''''' ****************** End of data **************************************** F3=Exit F4=Prompt F5=Refresh F9=Retrieve F10=Cursor F16=Repeat find F17=Repeat change F24=More keys Member EMPRPT added to file MYLIB/QRPGLESRC. +
4. Type the following source in your SEU Edit display, using the following SEU prefix commands to provide prompting: v IPF for file description specifications v IPD for definition specifications v IPI for input specifications v v v v v 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
55
Using SEU
*===============================================================* * MODULE NAME: EMPRPT * RELATED FILES: EMPMST (PHYSICAL FILE) * QSYSPRT (PRINTER FILE) * DESCRIPTION: This program prints employee information * from the file EMPMST. *===============================================================* FQSYSPRT O F 80 PRINTER FEMPMST IP E K DISK D TYPE S 8A D EMPTYPE PR 8A D CODE 1A IEMPREC 01 C EVAL TYPE = EMPTYPE(ETYPE) OPRINT H 1P 2 6 O 50 'EMPLOYEE INFORMATION' O H 1P O 12 'NAME' O 34 'SERIAL #' O 45 'DEPT' O 56 'TYPE' O D 01 O ENAME 20 O ENUM 32 O EDEPT 45 O TYPE 60 * Procedure EMPTYPE returns a string representing the employee * type indicated by the parameter CODE. P EMPTYPE B D EMPTYPE PI 8A D CODE 1A C SELECT C WHEN CODE = 'M' C RETURN 'Manager' C WHEN CODE = 'R' C RETURN 'Regular' C OTHER C RETURN 'Unknown' C ENDSL P EMPTYPE E Figure 28. Source for EMPRPT member
5. Press F3 (Exit) to go to the Exit display. Type Y (Yes) to save EMPRPT. The member EMPRPT is saved. Figure 29 on page 57 shows the DDS which is referenced by the EMPRPT source.
56
Using SEU
A***************************************************************** A* DESCRIPTION: This is the DDS for the physical file EMPMST. * A* It contains one record format called EMPREC. * A* This file contains one record for each employee * A* of the company. * A***************************************************************** A* A R EMPREC A ENUM 5 0 TEXT('EMPLOYEE NUMBER') A ENAME 20 TEXT('EMPLOYEE NAME') A ETYPE 1 TEXT('EMPLOYEE TYPE') A EDEPT 3 0 TEXT('EMPLOYEE DEPARTMENT') A ENHRS 3 1 TEXT('EMPLOYEE NORMAL WEEK HOURS') A K ENUM Figure 29. DDS for EMPRPT
To create a program from this source use the CRTBNDRPG command, specifying DFTACTGRP(*NO).
You must enter a separate command to process the SQL statements. For more information, refer to the DB2 Universal Database for AS/400 section of the Database
Chapter 5. Entering Source Statements
57
58
59
60
See Appendix C. The Create Commands on page 427 for the syntax diagram and parameter descriptions of CRTBNDRPG.
The program will be created in the library MYLIB with the same name as the source member on which it is based, namely, EMPRPT. Note that by default, it will run in the default named activation group, QILE. This program object can be debugged using a source view. 2. To debug the program type:
STRDBG EMPRPT
Figure 31 on page 62 shows the screen which appears after entering the above command.
61
More... Debug . . . _________________________________________________________________ _______________________________________________________________________________ F3=End program F6=Add/Clear breakpoint F10=Step F11=Display variable F12=Resume F17=Watch variable F18=Work with watch F24=More keys
From this screen (the Display Module Source display) you can enter debug commands to display or change field values and set breakpoints to control program flow while debugging. For more information on debugging see Chapter 12. Debugging Programs on page 183.
The source will be bound to the service program specified in the binding directory MATH at program-creation time. This means that calls to the procedures in the service program will take less time than if they were dynamic calls. When the program is called, it will run in the named activation group GRP1. The default value ACTGRP parameter on CRTBNDRPG is QILE. However, it is recommended that you run your application as a unique group to ensure that the associated resources are fully protected. Note: DFTACTGRP must be set to *NO in order for you to enter a value for the ACTGRP and BNDDIR parameters.
62
The CRTBNDRPG command creates the program PAYROLL in MYLIB, which will run in the default activation group. By default, a compiler listing is produced. Note: The setting of DFTACTGRP(*YES) is what provides the OPM compatibility. This setting also prevents you from entering a value for the ACTGRP and BNDDIR parameters. Furthermore, if the source contains any bound procedure calls, an error is issued and the compilation ends. 2. Type one of the following CL commands to see the listing that is created: v DSPJOB and then select option 4 (Display spooled files) v WRKJOB v WRKOUTQ queue-name v WRKSPLF
63
64
65
66
67
In this example, an indicator has been incorrectly placed in positions 72 - 73 instead of 71 - 72 or 73 - 74. The three fingers aa, bb, and cccccc identify the parts of the line where there are errors. The actual columns are highlighted with variables which are further explained by the messages. In this case, message RNF5051 indicates that the fields marked by aa and bb do not contain a valid
68
In this example, FLD1 is defined like FLD2 with a length 5 bytes greater. Later, FLD2 is defined as a date, which makes the length adjustment in the definition of FLD1 invalid. Message RNF3479 is issued pointing at listing line 1. Note that the SEU sequence number (000100) is also given, to aid you in finding the source line in error more quickly. (The SEU sequence number can also be found at listing line 1).
69
70
2 3 4 5
6-10 11-12
71
72
73
74
When requested, the CRTRPGMOD command creates a compiler listing which is for the most part identical to the listing that is produced by the CRTBNDRPG command. (The listing created by CRTRPGMOD will never have a binding section.) For information on using the compiler listing, see Using a Compiler Listing on page 65. A sample compiler listing is provided in Appendix D. Compiler Listings on page 447.
The module will be created in the library MYLIB with the name specified in the command, TRANSSVC. The source for the module is the source member TRANSSVC in file QRPGLESRC in the library MYLIB. You bind a module containing NOMAIN to another module using one of the following commands: a. CRTPGM command b. CRTSRVPGM command
75
76
* Prototype for Trans_Inc D Trans_Inc PR D Prod D Quantity D Discount * Prototype for Prod_Name D Prod_Name PR D Prod
11P 10P 5P 2P
2 0 0 2
40A 10P 0
VALUE
The module is created in the library MYLIB with the same name as the source file on which it is based, namely, TRANSRPT. This module object can be debugged using a source view. For information on the other views available, see Preparing a Program for Debugging on page 186. A compiler listing for the TRANSRPT module will be produced.
77
The DDS for the file TRNSDTA is shown in Figure 39 on page 79. The /COPY member is shown in Figure 37 on page 77.
78
Additional Examples
For additional examples of creating modules, see: v Sample Service Program on page 91, for an example of creating a module for a service program. v Binding to a Program on page 96. for an example of creating a module to be used with a service program. v Managing Your Own Heap Using ILE Bindable APIs on page 117, for an example of creating a module for dynamically allocating storage for a run-time array v Sample Source for Debug Examples on page 229, for example of creating an RPG and C module for use in a sample debug program.
Related CL Commands
The following CL commands can be used with modules: v Display Module (DSPMOD) v Change Module (CHGMOD) v Delete Module (DLTMOD) v Work with Modules (WRKMOD) For further information on these commands see the CL and APIs section of the Programming category in the iSeries 400 Information Center at this Web site http://www.ibm.com/eserver/iseries/infocenter.
79
Main Procedure
Trans_Inc
Prod_Name
Within a bound object, procedures can interrelate using static procedure calls. These bound calls are faster than external calls. Therefore, an application consisting of a single bound program with many bound calls should perform faster than a similar application consisting of separate programs with many external interapplication calls. In addition to binding modules together, you can also bind them to service programs (type *SRVPGM). Service programs allow you to code and maintain modules separately from the program modules. Common routines can be created as service programs and if the routine changes, the change can be incorporated by binding the service program again. The programs that use these common routines do not have to be recreated. For information on creating service programs see Chapter 8. Creating a Service Program on page 89.
80
81
Once you have entered the CRTPGM command, the system performs the following actions: 1. Copies listed modules into what will become the program object, and links any service programs to the program object. 2. Identifies the module containing the program entry procedure, and locates the first import in this module. 3. Checks the modules in the order in which they are listed, and matches the first import with a module export. 4. Returns to the first module, and locates the next import. 5. Resolves all imports in the first module. 6. Continues to the next module, and resolves all imports. 7. Resolves all imports in each subsequent module until all of the imports have been resolved. 8. If any imports cannot be resolved with an export, the binding process terminates without creating a program object. 9. Once all the imports have been resolved, the binding process completes and the program object is created. Note: If you have specified that a variable or procedure is to be exported (using the EXPORT keyword), it is possible that the variable or procedure name will be identical to a variable or procedure in another procedure within the bound program object. In this case, the results may not be as expected. See ILE Concepts for information on how to handle this situation.
82
The CRTPGM command creates a program object TRPT in the library MYLIB. Note that TRANSRPT is listed first in the MODULE parameter. ENTMOD(*FIRST) will find the first module with a program entry procedure. Since only one of the two modules has a program entry procedure, they can be entered in either order. The program TRPT will run in the named activation group TRPT. The program runs in a named group to ensure that no other programs can affect its resources. Figure 41 shows an output file created when TRPT is run.
Product name Quantity ------------------------------ -------Large 245 Super 15 Super Large 0 Super Jumbo 123 Incredibly Large Super Jumbo 15 ***Unknown*** 12 Total: 4,247,250.00 Figure 41. File QSYSPRT for TRPT Income -----------330,750.00 52,500.00 .00 2,952,000.00 912,000.00 .00
Additional Examples
For additional examples of creating programs, see: v Binding to a Program on page 96, for an example of binding a module and a service program. v Sample Source for Debug Examples on page 229, for an example of creating a program consisting of an RPG and C module.
Related CL Commands
The following CL commands can be used with programs: v Change Program (CHGPGM) v Delete Program (DLTPGM) v Display Program (DSPPGM) v Display Program References (DSPPGMREF)
Chapter 7. Creating a Program with the CRTRPGMOD and CRTPGM Commands
83
The information in this listing can help you diagnose problems if the binding was not successful, or give feedback about what the binder encountered in the process. You may want to store the listing for an ILE program in the file where you store the modules or the module source for a program. To copy this listing to a database file, you can use the Copy Spool File (CPYSPLF) command. Note: The CRTBNDRPG command will not create a binder listing. However, if any binding errors occur during the binding phase, the errors will be noted in your job log, and the compiler listing will include a message to this effect. For an example of a basic binder listing, see Sample Binder Listing on page 98. For more information on binder listings see ILE Concepts.
84
85
Removing Observability
Observability involves the kinds of data that can be stored with an object, and that allow the object to be changed without recompiling the source. The addition of this data increases the size of the object. Consequently, you may want to remove the data in order to reduce object size. But once the data is removed, observability is also removed. You must recompile the source and recreate the program to replace the data. The types of data are: Create Data Represented by the *CRTDTA value. This data is necessary to translate the code to machine instructions. The object must have this data before you can change the optimization level. Represented by the *DBGDTA value. This data is necessary to allow an object to be debugged.
Debug Data
Profiling Data Represented by the *BLKORD and *PRCORD values. This data is necessary to allow the system to re-apply block order and procedure order profiling data. Use the CHGPGM command or the CHGMOD command to remove some or all the data from a program or module respectively. Removing all observability reduces an object to its minimum size (without compression). It is not possible to change the object in any way unless you re-create it. Therefore, ensure that you
86
87
88
89
TIP If you are planning a module with only subprocedures (that is, with a module with keyword NOMAIN specified on the control specification) you may want to create it as a service program. Only one copy of a service program is needed on a system, and so you will need less storage for the module. Also, you can copyright your service programs using the COPYRIGHT keyword on the control specification. Binder language gives you control over the exports of a service program. This control can be very useful if you want to: v Mask certain service program procedures from service-program users v Fix problems v Enhance function v Reduce the impact of changes to the users of an application. See Sample Service Program on page 91 for an example of using binder language to create a service program. For information on binder language, masking exports, and other service program concepts, see ILE Concepts.
90
See Creating the Service Program on page 95 for an example of using the CRTSRVPGM command.
Related CL commands
The following CL commands are also used with service programs: v Change Service Program (CHGSRVPGM) v Display Service Program (DSPSRVPGM) v Delete Service Program (DLTSRVPGM) v Update Service Program (UPDSRVPGM) v Work with Service Program (WRKSRVPGM)
91
92
*-----------------------------------------------------------------* * Other fields used by the program * *-----------------------------------------------------------------* D HexDigits C CONST('0123456789ABCDEF') D IntDs DS D IntNum 5I 0 INZ(0) D IntChar 1 OVERLAY(IntNum:2) D HexDs DS D HexC1 1 D HexC2 1 D InChar S 1 D Pos S 5P 0 D HexPos S 5P 0
93
: : : :
94
When designing this service program, it was decided to make use of binder language to determine the interface, so that the program could be more easily updated at a later date. Figure 44 shows the binder language needed to define the exports of the service program CVTTOHEX. This source is used in the EXPORT, SRCFILE and SRCMBR parameters of the CRTSRVPGM command.
STRPGMEXP SIGNATURE('CVTHEX') EXPORT SYMBOL('CVTTOHEX') ENDPGMEXP Figure 44. Source for Binder Language for CvtToHex
The parameter SIGNATURE on STRPGMEXP identifies the interface that the service program will provide. In this case, the export identified in the binder language is the interface. Any program bound to CVTTOHEX will make use of this signature. The binder language EXPORT statements identify the exports of the service program. You need one for each procedure whose exports you want to make available to the caller. In this case, the service program contains one module which contains one procedure. Hence, only one EXPORT statement is required. For more information on binder language and signatures, see ILE Concepts.
2. Create the service program using the module CVTTOHEX and the binder language shown in Figure 44.
CRTSRVPGM SRVPGM(MYLIB/CVTTOHEX) MODULE(*SRVPGM) EXPORT(*SRCFILE) SRCFILE(MYLIB/QSRVSRC) SRCMBR(*SRVPGM)
The last three parameters in the above command identify the exports which the service program will make available. In this case, it is based on the source found in the member CVTTOHEX in the file QSRVSRC in the library MYLIB. Note that a binding directory is not required here because all modules needed to create the service program have been specified with the MODULE parameter.
95
Binding to a Program
To complete the example, we will create an application consisting of a program CVTHEXPGM which is bound to the service program. It uses a seven-character string which it passes to CVTTOHEX twice, once where the value of the hex string is 10 (that is, convert 5 characters) and again where the value is 14, that is, the actual length. Note that the program CVTHEXPGM serves to show the use of the service program CVTTOHEX. In a real application the caller of CVTTOHEX would have another primary purpose other than testing CVTTOHEX. Furthermore, a service program would normally be used by many other programs, or many times by a few programs; otherwise the overhead of initial call does not justify making it into a service program. To create the application follow these steps: 1. Create the module from the source in Figure 45 on page 97, by entering:
CRTRPGMOD MODULE(MYLIB/CVTHEXPGM) SRCFILE(MYLIB/QRPGLESRC)
When CVTHEXPGM is created, it will include information regarding the interface it uses to interact with the service program. This is the same as reflected in the binder language for CVTTOHEX. 3. Call the program, by typing:
CALL CVTHEXPGM
During the process of making CVTHEXPGM ready to run, the system verifies that: v The service program CVTTOHEX in library MYLIB can be found v The public interface used by CVTHEXPGM when it was created is still valid at run time. If either of the above is not true, then an error message is issued. The output of CVTHEXPGM is shown below. (The input string is ABC123*.)
Result14++++++ Result10++ C1C2C3F1F2 C1C2C3F1F2F35C 10 character output 14 character output
96
97
98
Program entry procedures . . . . . . . . . . Symbol Type Library Object *MODULE MYLIB CVTHEXPGM Multiple strong definitions . . . . . . . . Unresolved references . . . . . . . . . . . * * * * * E 5769SS1 V4R4M0 23:24:00 990521
T A B L E
* * * * * AS400S01
MYLIB/CVTHEXPGM
Page 07/30/99
Binding Statistics Symbol collection CPU time . . . . . . . . . . . . . . . . . : .016 Symbol resolution CPU time . . . . . . . . . . . . . . . . . : .004 Binding directory resolution CPU time . . . . . . . . . . . : .175 Binder language compilation CPU time . . . . . . . . . . . . : .000 Listing creation CPU time . . . . . . . . . . . . . . . . . : .068 Program/service program creation CPU time . . . . . . . . . : .234 Total CPU time . . . . . . . . . . . . . . . . . . . . . . . : .995 Total elapsed time . . . . . . . . . . . . . . . . . . . . . : 3.531 * * * * * E N D O F B I N D I N G S T A T I S T I C S * * * * * *CPC5D07 - Program CVTHEXPGM created in library MYLIB. * * * * * E N D O F C R E A T E P R O G R A M L I S T I N G * * * * *
99
100
The program object specified must exist in a library and this library must be contained in the library list *LIBL. You can also explicitly specify the library in the CL CALL command as follows:
CALL MYLIB/EMPRPT
For further information about using the CL CALL command, see the CL and APIs section of the Programming category in the iSeries 400 Information Center at this Web site - http://www.ibm.com/eserver/iseries/infocenter. Once you call your program, the OS/400 system performs the instructions found in the program.
You can also type the parameters without specifying any keywords:
Copyright IBM Corp. 1994, 2001
101
Each parameter value can be specified as a CL program variable or as one of the following: v A character string constant v A numeric constant v A logical constant If you are passing parameters to a program where an ILE RPG procedure is the program entry procedure, then that program must have one and only one *ENTRY PLIST specified. The parameters that follow (in the PARM statements) should correspond on a one-to-one basis to those passed through the CALL command. Refer to the CALL Command in the section on Passing Parameters between Programs in the CL Programming manual for a full description of how parameters are handled. For example, the program EMPRPT2 requires the correct password to be passed to it when it first started; otherwise it will not run. Figure 47 shows the source. 1. To create the program, type:
CRTBNDRPG PGM(MYLIB/EMPRPT2)
When the CALL command is issued, the contents of the parameter passed by the command is stored and the program parameter PSWORD points to its location. The program then checks to see if the contents of PSWORD matches the value stored in the program, ('HELLO'). In this case, the two values are the same, and so the program continues to run.
*===============================================================* * PROGRAM NAME: EMPRPT2 * * RELATED FILES: EMPMST (PHYSICAL FILE) * * PRINT (PRINTER FILE) * * DESCRIPTION: This program prints employee information * * stored in the file EMPMST if the password * * entered is correct. * * Run the program by typing "CALL library name/ * * EMPRPT2 (PSWORD)" on the command line, where * * PSWORD is the password for this program. * * The password for this program is 'HELLO'. * *===============================================================* FPRINT O F 80 PRINTER FEMPMST IP E K DISK IEMPREC 01 Figure 47. ILE RPG Program that Requires Parameters at Run Time (Part 1 of 2)
102
103
Selection or command ===> _________________________________________________________________________ _______________________________________________________________________________ F3=Exit F4=Prompt F9=Retrieve F12=Cancel F13=Information Assistant F16=AS/400 main menu
The menu shown in Figure 49 is displayed by a menu program in which each option calls a separate ILE program. You can create the menu by using STRSDA and selecting option 2 (Design menus). Figure 50 on page 105 shows the DDS for the display file of the above PAYROLL DEPARTMENT MENU. The source member is called PAYROL and has a source type of MNUDDS. The file was created using SDA.
104
Figure 51 shows the source of the application menu illustrated in Figure 49 on page 104 . The source member is called PAYROLQQ and has a source type of MNUCMD. It was also created using SDA.
PAYROLQQ,1 0001 call RPGINQ 0002 call RPGCHG 0003 call RPGADD Figure 51. Source for Menu Program
If the user enters 1, 2, or 3 from the application menu, the source in Figure 51 calls the programs RPGINQ, RPGCHG, or RPGADD respectively.
105
Note: ILE RPG inquiry messages have a message id prefix of RNQ. To add inquiry messages to a system reply list using the Add Reply List Entry command enter:
ADDRPYLE sequence-no message-id
106
You can also use the Work with Reply List Entry (WRKRPYLE) command to change or remove entries in the system reply list. For details of the ADDRPYLE and WRKRPYLE commands, see the CL and APIs section of the Programming category in the iSeries 400 Information Center at this Web site http://www.ibm.com/eserver/iseries/infocenter.
is issued and control is returned to the caller. A CL program can monitor for this exception by using the Monitor Message (MONMSG) command. You can also monitor for exceptions in other ILE languages. If the ILE program is running in the same activation group as its caller and it ends abnormally, then the message issued will depend on why the program ends. If it ends with a function check, then CPF9999 will be issued. If the exception is issued by an RPG procedure, then it will have a message prefix of RNX. For more information on exception messages, see Exception Handling Overview on page 235.
107
108
109
110
111
112
113
114
115
116
Similarly, errors can occur in the following cases: v A similar error can be made if a pointer is copied before being reallocated or deallocated. Great care must be taken when copying pointers to allocated storage, to ensure that they are not used after the storage is deallocated or reallocated. v If a pointer to heap storage is copied, the copy can be used to deallocate or reallocate the storage. In this case, the original pointer should not be used until it is set to a new value. v If a pointer to heap storage is passed as a parameter, the callee could deallocate or reallocate the storage. After the call returns, attempts to access the pointer could cause problems. v If a pointer to heap storage is set in the *INZSR, a later RESET of the pointer could cause the pointer to get set to storage that is no longer allocated. v Another type of problem can be caused if a pointer to heap storage is lost (by being cleared, or set to a new pointer by an ALLOC operation, for example). Once the pointer is lost, the storage it pointed to cannot be freed. This storage is unavailable to be allocated since the system does not know that the storage is no longer addressable. The storage will not be freed until the activation group ends.
117
DYNARRAY performs these actions using the three ILE bindable storage APIs, CEECRHP (Create Heap), CEEGTST (Get Storage), and CEEDSHP (Discard Heap), as well as the REALLOC operation code. For specific information about the storage management bindable APIs, refer to the CL and APIs section of the Programming category in the iSeries 400 Information Center at this Web site http://www.ibm.com/eserver/iseries/infocenter. Figure 54 shows the /COPY file DYNARRI containing the prototypes for the procedures in DYNARRAY. This /COPY file is used by the DYNARRAY module as well as any other modules that call the procedures in DYNARRAY. DYNARRAY has been defined for use with a (15,0) packed decimal array. It could easily be converted to handle a character array simply by changing the definition of DYNA_TYPE to a character field.
*================================================================= * DYNARRAY : Handle a (practically) unbounded run-time * Packed(15,0) array. The DYNARRAY module contains * procedures to allocate the array, return or set * an array value and deallocate the array. *================================================================= D DYNA_TYPE S 15P 0 D DYNA_INIT PR D DYNA_TERM PR D DYNA_SET PR D Element VALUE LIKE(DYNA_TYPE) D Index 5I 0 VALUE D DYNA_GET PR LIKE(DYNA_TYPE) D Index 5I 0 VALUE Figure 54. /COPY file DYNARRI containing prototypes for DYNARRAY module
Figure 55 on page 119 shows the beginning of module DYNARRAY containing the Control specification, and Definition specifications.
118
119
120
* * Initialize the storage for the array. * C 1 DO NumElems C CLEAR C ENDDO P DYNA_INIT E
I DynArr(I)
5 0
*================================================================= * DYNA_TERM: Terminate array handling. * * Function: Delete the heap. *================================================================= P DYNA_TERM B EXPORT C CALLP CEEDSHP(HeapId : *OMIT) C RESET HeapVars P DYNA_TERM E Figure 56. DYNARRAY Subprocedures (Part 1 of 4)
121
122
C C C C C
* * Calculate the new size of the array * C EVAL Size = NumElems * %SIZE(DynArr) * * Reallocate the storage. The new storage has the same value * as the old storage. * C REALLOC Size DynArr@ * * Initialize the new elements for the array. * C 1 ADD OldElems I C I DO NumElems I 5 0 C CLEAR DynArr(I) C ENDDO C ENDSR P DYNA_SET E Figure 56. DYNARRAY Subprocedures (Part 3 of 4)
*================================================================= * DYNA_GET: Return an array element. * * Function: Return the current value of the array element if * the element is within the size of the array, or * the default value otherwise. *================================================================= P DYNA_GET B EXPORT *----------------------------------------------------------------* Input parameters for this procedure. *----------------------------------------------------------------D DYNA_GET PI LIKE(DYNA_TYPE) D Index 5I 0 VALUE *----------------------------------------------------------------* Local variables. *----------------------------------------------------------------D Element S LIKE(DYNA_TYPE) INZ *----------------------------------------------------------------* If the element requested is within the current size of the * array then return the element's current value. Otherwise * the default (initialization) value can be used. *----------------------------------------------------------------C Index IFLE NumElems C EVAL Element = DynArr(Index) C ENDIF C RETURN Element P DYNA_GET E Figure 56. DYNARRAY Subprocedures (Part 4 of 4)
123
The procedure can then be bound with other modules using CRTPGM or CRTSRVPGM. Figure 57 shows another module that tests the procedures in DYNARRAY.
*================================================================= * DYNTEST: Test program for DYNARRAY module. *================================================================= /COPY EXAMPLES,DYNARRI D X S LIKE(DYNA_TYPE) * Initialize the array C CALLP DYNA_INIT * Set a few elements C CALLP DYNA_SET (25 : 3) C CALLP DYNA_SET (467252232 : 1) C CALLP DYNA_SET (-2311 : 750) * Retrieve a few elements C EVAL X = DYNA_GET (750) C '750' DSPLY X C EVAL X = DYNA_GET (8001) C '8001' DSPLY X C EVAL X = DYNA_GET (2) C '2' DSPLY X C C * Clean up CALLP SETON DYNA_TERM
LR
124
125
Calling Programs
You can call OPM or ILE programs by using program calls. A program call is a call that is made to a program object (*PGM). The called programs name is resolved to an address at run time, just before the calling program passes control to the called program for the first time. For this reason, program calls are often referred to as dynamic calls. Calls to an ILE program, an EPM program, or an OPM program are all examples of program calls. A call to a non-bindable API is also an example of a program call. You use the CALLP operation or both the CALL and PARM operations to make a program call. If you use the CALL and PARM operations, then the compiler cannot perform type checking on the parameters, which may result in run-time errors. When an ILE program is called, the program entry procedure receives the program parameters and is given initial control for the program. In addition, all procedures within the program become available for procedure calls.
Calling Procedures
Unlike OPM programs, ILE programs are not limited to using program calls. ILE programs can also use static procedure calls or procedure pointer calls to call other procedures. Procedure calls are also referred to as bound calls. A static procedure call is a call to an ILE procedure where the name of the procedure is resolved to an address during binding hence, the term static. As a result, run-time performance using static procedure calls is faster than run-time performance using program calls. Static calls allow operational descriptors, omitted parameters, and they extend the limit (to 399) on the number of parameters that are passed. Procedure pointer calls provide a way to call a procedure dynamically. For example, you can pass a procedure pointer as a parameter to another procedure which would then run the procedure that is specified in the passed parameter. You can also manipulate arrays of procedure names or addresses to dynamically route a procedure call to different procedures. If the called procedure is in the same activation group, the cost of a procedure pointer call is almost identical to the cost of a static procedure call. Using either type of procedure call, you can call: v A procedure in a separate module within the same ILE program or service program. v A procedure in a separate ILE service program. Any procedure that can be called by using a static procedure call can also be called through a procedure pointer. For a list of examples using static procedure calls, see Examples of Free-Form Call on page 132 and Examples of CALL and CALLB on page 146. For examples of using procedure pointers, see the section on the procedure pointer data type in ILE RPG Reference. You use the CALLP or both the CALLB and PARM operations to make a procedure call. You can also call a prototyped procedure with an expression if the
126
ILE PEP Procedure Call (by system) ILE Procedure Procedure Call ILE Procedure Procedure Call
C Module Procedure
ILE Procedure
Note: In a program call, the calls to the program entry procedure and the user entry procedure (UEP) occur together, since the call to the UEP is automatic. Therefore, from now on, the two steps of a program call will be combined in later diagrams involving the call stack in this and remaining chapters.
Recursive Calls
Recursive calls are only allowed for subprocedures. A recursive call is one where procedure A calls itself or calls procedure B which then calls procedure A again. Each recursive call causes a new invocation of the procedure to be placed on the call stack. The new invocation has new storage for all data items in automatic storage, and that storage is unavailable to other invocations because it is local. (A data item that is defined in a subprocedure uses automatic storage unless the
Chapter 10. Calling Programs and Procedures
127
You are running a program where procedure A in module X calls procedure B in module Y. You are not aware of what procedure B does except that it processes some fields. Procedure B in turn calls procedure C, which in turn calls procedure A. Once procedure C calls procedure A, a recursive call has been made. The call stack sequence is shown in Figure 60. Note that the most recent call stack entry is at the bottom.
PGM X
PRC_A
PRC_B
PRC_C
PRC_A
Recursive Call
So while subprocedures can be called recursively, if you are not aware that recursion is occurring, you may exhaust system resources.
128
Attention! Unconditional recursive calls can lead to infinite recursion which leads to excessive use of system resources. Infinite recursion can be avoided with proper programming. In general, a proper recursive procedure begins with a test to determine if the desired result has been obtained. If it has been obtained, then the recursive procedure returns to the most recent caller.
Parameter-Passing Considerations
When designing a call interface, you must make a number of decisions in terms of how parameters will be passed. On the other hand, if you are the caller then most of the decisions have already been made for you. The following lists some of the parameter-passing considerations to keep in mind when you are designing a call interface. v Compile-time parameter checking The call interface of a prototyped call is checked at compile time. This checking ensures that: the data types are correctly used all required parameters are passed *OMIT is only passed where it is allowed. v Parameter passing method Each HLL provides one or more ways of passing parameters. These may include: passing a pointer to the parameter value, passing a copy of the value, or passing the value itself. v Passing operational descriptors Sometimes you may not be sure of the exact format of the data that is being passed to you. In this case you may request that operational descriptor be passed to provide additional information regarding the format of the passed parameters. v Number of parameters In general, you should pass the same number of parameters as expected by the called program or procedure. If you pass fewer parameters than are expected, and the callee references a parameter for which no data was passed, then the callee will get an error. v Passing less data If you pass a parameter and you pass too little data, your application may not work correctly. If changing the parameter, you may overwrite storage. If using the parameter, you may misinterpret the parameter. By prototyping the parameter, the compiler will check to see that the length is appropriate for the parameter. If the callee has indicated (through documentation or through that prototype) that a parameter can be shorter than the maximum length, you can safely pass shorter parameters. (Note, however, that the called procedure must be written in a way to handle less data than required.) v Order of evaluation There is no guaranteed order for evaluation of parameters on a prototyped call. This fact may be important, if a parameter occurs more than once in the parameter list, and there is the possibility of side effects. v Interlanguage call considerations
Chapter 10. Calling Programs and Procedures
129
130
In free-form calculations, you can omit CALLP if there are no operation extenders. The free-form operation can use either of the following forms:
/free callp name { (parm1 { :parm2 ...} ) }; name( {parm1 {:parm2 ... }} ); /end-free
To call a prototyped program or procedure follow these general steps: 1. Include the prototype of the program or procedure to be called in the definition specifications. 2. Enter the prototype name of the program or procedure in the extended Factor-2 field, followed by the parameters if any, within parentheses. Separate the parameters with a colon (:). Factor 1 must be blank. The following example shows a call to a procedure Switch, which changes the state of the indicator that is passed to it, in this case *IN10..
C CALLP Switch(*in10)
A maximum of 255 parameters are allowed on a program call, and a maximum of 399 for a procedure call. You can use CALLP from anywhere within the module. If the keyword EXTPGM is specified on the prototype, the call will be a dynamic external call; otherwise it will be a bound procedure call. Note that if CALLP is used to call a procedure which returns a value, that value will not be available to the caller. If the value is required, call the prototyped procedure within an expression.
131
C EVAL STRING = 'Address: ' + C %TRIM(CVTCHR(StreetNum)) C + ' ' + StreetName * If STREETNUM = 427 and STREETNAME = 'Mockingbird Lane', after the * EVAL operation STRING = 'ADDRESS: 427 Mockingbird Lane' Figure 62. Calling a Prototyped Procedure within an Expression
For examples of calling by using an expression, see: v v v v Figure 4 on page 10 Figure 19 on page 40 Figure 38 on page 78 Figure 121 on page 230
132
Passing by Reference
The default parameter passing style for ILE RPG is to pass by reference. Consequently, you do not have to code any keywords on the parameter definition to pass the parameter by reference. You should pass parameters by reference to a procedure when you expect the callee to modify the field passed. You may also want to pass by reference to improve run-time performance, for example, when passing large character fields. Note also that parameters that are passed on external program calls can only be passed by reference.
Passing by Value
With a prototyped procedure, you can pass a parameter by value instead of by reference. When a parameter is passed by value, the compiler passes the actual value to the called procedure. Note: OS/400 program calls require that parameters be passed by reference. Consequently, you cannot pass a parameter by value to a program. Passing by value allows you to: v Pass literals and expressions as parameters. v Pass parameters that do not match exactly the type and length that are expected. v Pass a variable that, from the callers perspective, will not be modified. When a parameter is passed by value, the called program or procedure can change the value of the parameter, but the caller will never see the changed value. One primary use for passing by value is that you can allow less stringent matching of the attributes of the passed parameter. For example, if the definition is for a numeric field of type packed-decimal and length 5 with 2 decimal positions, you must pass a numeric value, but it can be: v A packed, zoned or binary constant or variable, with any number of digits and number of decimal positions v A built-in function returning a numeric value v A procedure returning a numeric value v A complex numeric expression such as
2 * (Min(Length(First) + Length(Last) + 1): %size(Name))
If the prototype requires an array of 4 elements, the passed parameter can be: v An array with fewer than 4 elements. In this case, the remaining elements in the received parameter will contain the default value for the type. v An array with 4 elements. In this case, each element of the received parameter will correspond to an element of the passed parameter. v An array with more than 4 elements. In this case, some of the elements of the passed array will not be passed to the received parameter. v A non-array. In this case, each element of the received parameter will contain the passed parameter value. To pass a parameter by value, specify the keyword VALUE on the parameter definition in the prototype, as shown in the figures below.
133
P DO_CALC B EXPORT *------------------------------------------------------------* This procedure performs a function on the 3 numeric values * passed to it as value parameters. It also returns a value. *------------------------------------------------------------D DO_CALC PI 10I 0 D Term1 5I 0 VALUE D Term2 5I 0 VALUE D Term3 5I 0 VALUE D Result S 10I 0 C EVAL Result = Term1 ** 2 * 17 C + Term2 * 7 C + Term3 C RETURN Result * 45 + 23 P E Figure 64. Procedure Interface Definition for DO_CALC Procedure
134
The second parameter passed to CEETSTA can be any numeric field, a literal, a built-in function, or expression.
135
For an example of how to use operational descriptors see Sample Service Program on page 91. The example consists of a service program which converts character strings which are passed to it to their hexadecimal equivalent. The service program uses operational descriptors to determine the length of the character string and the length to be converted.
Omitting Parameters
When calling a procedure, you may sometimes want to leave out a parameter. It may be that it is not relevant to the called procedure. For example, this situation might arise when you are calling the ILE bindable APIs. Another reason might be that you are calling an older procedure that does not handle this particular parameter. If you need to omit a parameter on a call, you have two choices: v Specify OPTIONS(*OMIT) and pass *OMIT v Specify OPTIONS(*NOPASS) and do not pass the parameter. The primary difference between the two methods has to do with how you check to see if a parameter has been omitted. In either case, an omitted parameter cannot be referenced by the called procedure; if it is, unpredictable results will occur. So if the called procedure is designed to handle different numbers of parameters, you will have to check for the number of parameters passed. If *OMIT is passed, it will count as a parameter.
Passing *OMIT
You can pass *OMIT for a prototyped parameter if the called procedure is aware that *OMIT might be passed. In other words, you can pass *OMIT if the keyword OPTIONS(*OMIT) is specified on the corresponding parameter definition in the prototype. When *OMIT is specified, the compiler will generate the necessary code to indicate to the called procedure that the parameter has been omitted. Note: *OMIT can only be specified for parameters passed by reference. To determine if *OMIT has been passed to an ILE RPG procedure, use the %ADDR built-in function to check the address of the parameter in question. If the address is
136
137
Using %PARMS
In this example, a procedure FMTADDR has been changed several times to allow for a change in the address information for the employees of a company. FMTADDR is called by three different procedures. The procedures differ only in the number of parameters they use to process the employee information. That is, new requirements for the FMTADDR have arisen, and to support them, new parameters have been added. However, old procedures calling FMTADDR are still supported and do not have to be changed or recompiled. The changes to the employee address can be summarized as follows: v Initially only the street name and number were required because all employees lived in the same city. Thus, the city and province could be supplied by default. v At a later point, the company expanded, and so the city information became variable for some company-wide applications. v Further expansion resulted in variable province information. The procedure processes the information based on the number of parameters passed. The number may vary from 3 to 5. The number tells the program whether to provide default city or province values or both. Figure 68 on page 139 shows the source for this procedure. Figure 69 on page 140 shows the source for /COPY member containing the prototype. The main logic of FMTADDR is as follows: 1. Check to see how many parameters were passed by using %PARMS. This built-in function returns the number of passed parameters. v If the number is greater than 4, then the default province is replaced with the actual province supplied by the fifth parameter P_Province. v If the number is greater than 3, then the default city is replaced with the actual city supplied by the fourth parameter P_City. 2. Correct the street number for printing using the subroutine GetStreet#. 3. Concatenate the complete address. 4. Return.
138
139
*=================================================================* * Prototype for FMTADDR - format an address *=================================================================* DFmtAddr PR D addr 70 D strno 5 0 CONST D st 20 CONST D cty 15 OPTIONS(*NOPASS) CONST D prov 15 OPTIONS(*NOPASS) CONST Figure 69. Source for /COPY member with Prototype for Procedure FMTADDR
Figure 70 on page 141 shows the source for the procedure PRTADDR. This procedure serves to illustrate the use of FMTADDR. For convenience, the three procedures which would each call FMTADDR are combined into this single procedure. Also, for the purposes of the example, the data is program-described. Since PRTADDR is 'three procedures-in-one', it must define three different address data structures. Similarly, there are three parts in the calculation specifications, each one corresponding to programs at each stage. After printing the address, the procedure PRTADDR ends.
140
141
** 00123Bumble Bee Drive 01243Hummingbird Lane ** 00003Cowslip Street 01150Eglinton Avenue ** 00012Jasper Avenue 00027Avenue Road
To create these programs, follow these steps: 1. To create FMTADDR, using the source in Figure 68 on page 139, type:
CRTRPGMOD MODULE(MYLIB/FMTADDR)
142
Order of Evaluation
There is no guaranteed order for evaluation of parameters on a prototyped call. This fact may be important when using parameters that cause side effects, as the results may not be what you would expect. A side effect occurs if the processing of the parameter changes: v The value of a reference parameter v The value of a global variable v An external object, such as a file or data area If a side effect occurs, then, if the parameter is used elsewhere in the parameter list, then the value used for the parameter in one part of the list may not be the same as the value used in another part. For example, consider this call statement.
CALLP procA (fld : procB(fld) : fld)
Assume that procA has all value parameters, and procB has a reference parameter. Assume also that fld starts off with the value 3, and that procB modifies fld to be 5, and returns 10. Depending on the order in which the parameters are evaluated, procA will receive either 3, 10, and 5 or possibly, 3, 10, and 3. Or possibly, 5, 10, and 3; or even 5, 10, and 5. In short, it is important to be aware of the possibility of side effects occurring. In particular, if you are providing an application for third-party use, where the end user may not know the details of some of the procedures, it is important ensure that the values of the passed parameters are the expected ones.
Interlanguage Calls
When passing or receiving data from a program or procedure written in another language, it is important to know whether the other language supports the same parameter passing methods and the same data types as ILE RPG. Table 12 shows the different parameter passing methods allowed by ILE RPG and, where applicable, how they would be coded in the other the ILE languages. The table also includes the OPM RPG/400 compiler for comparison.
Table 12. RPG Parameter Passing Methods Passing By Reference ILE RPG prototype D D C proc PR parm 1A CALLP proc(fld)
143
void proc(char parm); proc('a'); CALL PROCEDURE "PROC" USING BY VALUE PARM N/A N/A
Passing By Read-Only Reference ILE RPG prototype D D C proc PR parm 1A CALLP proc(fld) CONST
1. Do not confuse passing by read-only reference with COBOLs passing BY CONTENT. In RPG terms, to pass Fld1 by content, you would code: C PARM Fld1 TEMP
Fld1 is protected from being changed, but TEMP is not. There is no expectation that the parameter will not be changed.
For information on the data types supported by different HLLs, consult the appropriate language manual.
144
145
146
Value transferred from Result Field Value placed in Result Field entry entry upon return. when call occurs. Value transferred from Result Field Value placed in Result Field entry entry when call occurs. upon return.
Note: The moves to either the factor 1 entry or the result-field entry occur only when the called procedure returns normally to its caller. If an error occurs while attempting to move data to either entry, then the move is not completed. If insufficient parameters are specified when calling a procedure, an error occurs when an unresolved parameter is used by the called procedure. To avoid the error, you can either: v Check %PARMS to determine the number of parameters passed. For an example using %PARMS, see Checking for the Number of Passed Parameters on page 137. v Specify *OMIT in the result field of the PARM operations of the unpassed parameters. The called procedure can then check to see if the parameter has been omitted by checking to see if the parameter has value of *NULL, using %ADDR(parameter) = *NULL. For more information, refer to Omitting Parameters on page 136. Keep in mind the following when specifying a PARM operation: v One or more PARM operations must immediately follow a PLIST operation. v One or more PARM operations can immediately follow a CALL or CALLB operation. v When a multiple occurrence data structure is specified in the Result field of a PARM operation, all occurrences of the data structure are passed as a single field. v Factor 1 and the Result field of a PARM operation cannot contain a literal, a look-ahead field, a named constant, or a user-date reserved word. v The following rules apply to *OMIT for non-prototyped parameters: *OMIT is only allowed in PARM operations that immediately follows a CALLB operation or in a PLIST used with a CALLB. Factor 1 and Factor 2 of a PARM operation must be blank, if *OMIT is specified. *OMIT is not allowed in a PARM operation that is part of a *ENTRY PLIST. v There are other restrictions that apply when using the PARM operation code. For a detailed description of these restrictions, see the ILE RPG Reference. For examples of the PARM operation see: v Figure 47 on page 102 v Figure 42 on page 93 v Figure 133 on page 257
147
Normal End
A main procedure ends normally and control returns to the calling procedure when the LR indicator is on and the H1 through H9 indicators are not on. The LR indicator can be set on:
148
TIP If you are accustomed to ending with LR on to cause storage to be released, and you are running in a named (persistent) activation group, you may want to consider returning without an end. The reasons are: v The storage is not freed until the activation group ends so there is no storage advantage to ending with LR on. v Call performance is improved if the program is not re-initialized for each call. You would only want to do this if you did not need your program re-initialized each time.
Abnormal End
A main procedure ends abnormally and control returns to the calling procedure when one of the following occurs: v The cancel option is taken when an ILE RPG inquiry message is issued. v An ENDSR *CANCL operation in a *PSSR or INFSR error subroutine is processed. (For further information on the *CANCL return point for the *PSSR and INFSR error subroutines, see Specifying a Return Point in the ENDSR Operation on page 255). v An H1 through H9 indicator is on when a RETURN operation (with a blank factor 2) is processed. v An H1 through H9 indicator is on when last record (LR) processing occurs in the RPG cycle. When a main procedure ends abnormally, the following occurs:
Chapter 10. Calling Programs and Procedures
149
150
You access ILE bindable APIs using the same call mechanisms used by ILE RPG to call procedures, that is, the CALLP operation or the CALLB operation. If the API returns a value and you want to use it, call the API in an expression. For the information required to define a prototype for an API, see the description of the API in the CL and APIs section of the Programming category in the iSeries 400
Chapter 10. Calling Programs and Procedures
151
...
C C
where v CEExxxx is the name of the bindable API v parm1, parm2, ... parmn are omissible or required parameters passed to or returned from the called API. v feedback is an omissible feedback code that indicates the result of the bindable API. Note: Bindable APIs cannot be used if DFTACTGRP(*YES) is specified on the CRTBNDRPG command. For more information on bindable APIs, refer to the CL and APIs section of the Programming category in the iSeries 400 Information Center at this Web site http://www.ibm.com/eserver/iseries/infocenter.
152
Multithreading Considerations
Normally, running an application in multiple threads can improve the performance of the application. In the case of ILE RPG, this is not true in general. In fact, the performance of a multithreaded application could be worse than that of a single-thread version when the thread-safety is achieved by serialization of the procedures at the module level. Running ILE RPG procedures in a multithreaded environment is only recommended when required by other aspects of the application (for example, when writing a Domino exit program or when calling a short-running RPG procedure from Java). For long-running RPG programs called from Java, we recommend using a separate process for the RPG program. The THREAD(*SERIALIZE) control specification keyword can be specified to help you achieve thread safety for an ILE RPG module. Specifying THREAD(*SERIALIZE) will protect most of your variables and all your internal control structures from being accessed improperly by multiple threads. The thread safe module will be locked when a procedure in the module is entered and unlocked when no procedure in the module is still running. This serialized access, ensures that only one thread is active in any one module, within an activation group, at any one time. However, it is still up to the programmer to handle thread safety for storage that is shared across modules. This is done by adding logic in
Chapter 10. Calling Programs and Procedures
153
Multithreading Considerations
the application to synchronize access to the storage. For example, shared files, exported and imported storage, and storage accessed by the address of a parameter may be shared across modules from multiple threads. To synchronize access to this type of storage, you can do one or both of the following: v Structure the application such that the shared resources are not accessed simultaneously from multiple threads. v If you are going to access resources simultaneously from separate threads, synchronize access using facilities such as semaphores or mutexes. For more information, refer to the Multithreaded Applications document under the Programming topic at the following URL:
http://www.ibm.com/eserver/iseries/infocenter
154
Multithreading Considerations
*------------------------------------------------------------------------* .---------------. * | | * | some storage |<---------------- pointer to shared storage * | | (called MyPtr in module A) * '---------------' (saved as a static variable in module B) * Module A * Global variables in Module A D MyPtr S * D SomeStorage S 10A based(MyPtr) C eval SomeStorage = 'Init value' C callp ProcB(MyPtr) 2 C eval SomeStorage = *BLANKS 3 *------------------------------------------------------------------------* Module B * Global variables in Module B D SavedPtr S * D SomeStorage S 10A based(SavedPtr) * ProcB in module B P ProcB B export D ProcB PI D PtrParm * C eval SavedPtr = PtrParm 6 C return 7 P E * ProcB2 in module B P ProcB2 B export D ProcB2 PI D PtrParm * C if SomeStorage = 'Init value' 8 C .... C return P E Figure 73. Example of Sharing Data in a Multithreaded Environment
When ProcA calls ProcB (line 2 ), no other thread can access the storage pointed to by MyPtr, since both module A and and module B are being used by one thread. ProcB saves the pointer in module Bs static storage (line 6 ) and returns (line 7 ). Now, no thread is active in module B, so another thread is free to call module B. If another thread calls ProcB2, it is possible that the first thread could process line 3 before, at the same time, or after the second thread processes line 8 . The order of these events is not defined; the code used to test if SomeStorage = Init value could succeed one time and fail the next time. You can synchronize access to the shared data, by using logic in the program or by using synchronization techniques provided by C or by platform functions. For more details, refer to the Multithreaded Applications document under the Programming topic at the following URL:
http://www.ibm.com/eserver/iseries/infocenter
155
Multithreading Considerations
other module. This type of problem can occur even with serialization of calls to a module and is referred to as deadlock. |
thread-1 thread-2
MOD1
PROC1 CALLP PROC4 PROC2 PROC3
MOD2
| | |
This example shows that you cannot access more than one procedure in the same module at the same time using ILE RPG synchronization techniques. To avoid the problem in the above example and ensure thread safe applications, you can control the synchronization of modules using techniques provided by C or by platform functions. Any callers of PROC1 or PROC3 for each thread should do the following: 1. Restrict access to the modules for all threads except the current thread, always in the same order (MOD1 then MOD2) 2. In the current thread, call the procedures in the modules (PROC1 and PROC3) 3. Relinquish access to the modules for all threads in the reverse order of step 1 (MOD2 then MOD1). One thread would be successful in restricting access to MOD1. Since all users of MOD1 and MOD2 use the protocol of restricting access to MOD1 and MOD2 in that order, no other thread can call procedures in MOD1 or MOD2 while the first thread has restricted access to the modules. In this situation you have access to more than one procedure in the same module at the same time, but since it is only available to the current thread, it is thread safe. | This method should also be used to synchronize access to shared storage.
156
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
157
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
In object-oriented programming, a method is a programmed procedure that is defined as part of a class, which is a collection of methods and variables. Java methods can be called from your RPG program. While most Java methods are written in Java, a method can also be written in another high-level language, such as RPG. This is known as a native method. This section includes information on calling Java methods from RPG and on writing RPG native methods.
*JAVA identifies the object as a Java object. Class_name specifies the class of the object. It must be a character literal or named constant, and the class name must be fully qualified. The class name is case sensitive. For example, to declare a field that will hold an object of type BigDecimal:
D bdnum S O CLASS(*JAVA:'java.math.BigDecimal')
Note that both class names are fully qualified and that their case exactly matches that of the Java class. Fields of type O cannot be defined as subfields of data structures. It is possible to have arrays of type O fields, but pre-runtime and compile-time tables and arrays of type O are not allowed.
Both the class name and the method name must be character constants. The class name must be a fully qualified Java class name and is case sensitive. The method name must be the name of the method to be called, and is case sensitive. Use *JAVA when creating a prototype for either a method written in Java or a native method written in RPG. Use the STATIC keyword to indicate that a method is static. Java and RPG Definitions and Data Types: The data types of the parameters and the returned value of the method are specified in the same way as they are when prototyping a subprocedure, but the data types actually map to Java data types. The following table shows the mappings of ILE RPG data types to and from Java data types.
158
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
byte[]
character length > 1 (See 3.) array of character length=1 (See 4.) date time timestamp
2byte integer UCS-2 length=1 UCS-2 length>1 (See 3.) array of UCS-2 length=1 (See 4.)
4byte integer 8byte integer 4byte float 8byte float object array of equivalent type (See 4.)
Notes: 1. When a Java byte type is converted to or from a character (1A) data type, ASCII conversion occurs. When a Java byte type is converted to or from an integer (3I) data type, ASCII conversion does not occur. 2. For arrays of any type in Java, you can declare an array of the equivalent type in RPG. However, note that you cannot use an array of character length greater than 1 or UCS-2 length greater than 1 data types. 3. For UCS-2 length greater than 1 and character length greater than 1 data types, the VARYING keyword is allowed. In general, its recommended to use the VARYING keyword, since Java byte[] and char[] cannot be declared with a fixed length. 4. For RPG array data types, OPTIONS(*VARSIZE) should normally be coded for array parameters, since Java arrays cannot be declared with a fixed length. Zoned, Packed, Binary, and Unsigned data types are not available in Java. If you pass a Zoned, Packed, Binary, or Unsigned field as a parameter, the compiler will do the appropriate conversion, but this may result in truncation and/or loss of precision. When calling a method, the compiler will accept arrays as parameters only if the parameter is prototyped using the DIM keyword. If the return value or a parameter of a method is an object, you must provide the class of the object by coding the CLASS keyword on the prototype. The class name specified will be that of the object being returned or the parameter being passed. (Use the EXTPROC keyword to specify the class of the method being called.)
159
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
If the method being called is a static method, then you must specify the STATIC keyword on the prototype. If the method is a constructor, you must specify *CONSTRUCTOR as the name of the method. In Java, the following data types can only be passed by value:
boolean byte int short long float double
Parameters of these types must have the VALUE keyword specified for them on the prototype. Note that objects can only be passed by reference. The VALUE keyword cannot be specified with type O. Since arrays are seen by Java as objects, parameters mapping to arrays must also be passed by reference. This includes character and byte arrays. The CONST keyword can be used. Examples of Prototyping Java Methods: This section presents some examples of prototyping Java methods. Example 1: The Java Integer class contains a static method called toString, which accepts an int parameter, and returns a String object. It is declared in Java as follows:
static String Integer.toString(int)
The EXTPROC keyword identifies the method as a Java method. It also indicates that the method name is toString, and that it is found in class java.lang.Integer. The O in column 40 and the CLASS keyword tell the compiler that the method returns an object, and the class of that object is java.lang.String. The STATIC keyword indicates that the method is a static method, meaning that an Integer object is not required to call the method. The data type of the parameter is specified as 10I, which maps to the Java int data type. Because the parameter is an int, it must be passed by value, and the VALUE keyword is required. Example 2: The Java Integer class contains a static method called getInteger, which accepts String and Integer objects as parameters, and returns an Integer object. It is declared in Java as follows:
static Integer Integer.getInteger(String, Integer)
160
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
PR
O O
This method accepts two objects as parameters. O is coded in column 40 of the D-specification and the CLASS keyword specifies the class of each object parameter. Because both parameters are input-only, the CONST keyword is specified. Example 3: The Java Integer class contains a method called shortValue, which returns the short representation of the Integer object used to invoke the method. It is declared in Java as follows:
short shortValue()
The STATIC keyword is not specified because the method is not a static method. The method takes no parameters, so none are coded. When you call this method, you will specify the Integer instance as the first parameter. The returned value is specified as 5I, which maps to the Java short data type. Example 4: The Java Integer class contains a method called equals, which accepts an Object as parameter and returns a boolean. It is declared in Java as follows:
boolean equals(Object)
The returned value is specified as N, which maps to the Java boolean data type. Because this is not a static method, a call to this method will have two parameters with the instance parameter coded first.
161
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
the JVM for you. It is also possible to start JVM yourself using the JNI function described in Creating the Java Virtual Machine (JVM) on page 172 2. If you started the JVM or if you know that RPG started the JVM for you, you may want to destroy it when you are finished calling Java. You do this by calling the JNI function described in Destroying the Java Virtual Machine (JVM) on page 169. 3. If you are using your own classes (or any classes outside the normal java.xxx classes), be sure to have your CLASSPATH environment variable setup before you call any Java methods. When RPG starts up the JVM for you, it will add the classes in your CLASSPATH environment variable to the standard classpath, so when you use your own classes, Java will be able to find them. Set the CLASSPATH environment variable interactively like this:
===>ADDENVVAR ENVVAR(CLASSPATH) VALUE('/myclasses/:/xyzJava/classes/')
The directories must be separated by colons. 4. Normally, Java does its own garbage collection, detecting when an object is no longer needed. When you create objects by calling Java constructors from your non-native RPG procedure, Java has no way of knowing that the object can be destroyed, so it never destroys them. If you know you are not going to need an object any more, you should tell this to Java by calling the JNI function described in Telling Java you are finished with a temporary object on page 170. Note: Since Java uses threads, the THREAD(*SERIALIZE) keyword should be coded in all modules that interact with Java. See Additional RPG Coding for Using Java on page 169 for more information about the various JNI functions. Example 1 In this example, the goal is to add two BigDecimal values together. In order to do this, two BigDecimal objects must be instantiated by calling the constructor for the BigDecimal class, fields must be declared to store the BigDecimal objects, and the add() method in the BigDecimal class must be called.
162
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
* * Prototype the BigDecimal constructor that accepts a String * parameter. It returns a new BigDecimal object. * Since the string parameter is not changed by the constructor, we will * code the CONST keyword. This will make it more convenient * to call the constructor. * D bdcreate1 PR O EXTPROC(*JAVA: D 'java.math.BigDecimal': D *CONSTRUCTOR) D CLASS(*JAVA:'java.math.BigDecimal') D str O CLASS(*JAVA:'java.lang.String') D CONST * * Prototype the BigDecimal constructor that accepts a double * parameter. 8F maps to the Java double data type and so must * be passed by VALUE. It returns a BigDecimal object. * D bdcreate2 PR O EXTPROC(*JAVA: D 'java.math.BigDecimal': D *CONSTRUCTOR) D CLASS(*JAVA:'java.math.BigDecimal') D double 8F VALUE * * Define fields to store the BigDecimal objects. * D bdnum1 S O CLASS(*JAVA:'java.math.BigDecimal') D bdnum2 S O CLASS(*JAVA:'java.math.BigDecimal') * * Since one of the constructors we are using requires a String object, * we will also need to construct one of those. Prototype the String * constructor that accepts a byte array as a parameter. It returns * a String object. * D makestring PR O EXTPROC(*JAVA: D 'java.lang.String': D *CONSTRUCTOR) D CLASS(*JAVA:'java.lang.String') D bytes 30A CONST VARYING * * Define a field to store the String object. * D string S O CLASS(*JAVA:'java.lang.String') * * Prototype the BigDecimal add method. It accepts a BigDecimal object * as a parameter, and returns a BigDecimal object (the sum of the parameter * and of the BigDecimal object used to make the call). * D add PR O EXTPROC(*JAVA: D 'java.lang.BigDecimal': D 'add') D CLASS(*JAVA:'java.math.BigDecimal') D bd1 O CLASS(*JAVA:'java.math.BigDecimal') CONST * * Define a field to store the sum. * D sum S O CLASS(*JAVA:'java.math.BigDecimal') D D double S 8F INZ(1.1) D fld1 S 10A
163
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
C* C* C* C* C* C C* C* C* C* C C* C* C* C* C* C* C* C* C* C* C* C* C C* C* C* C* C* C* C* C* C* C C* C*
Call the constructor for the String class, to create a String object from fld1. Since we are calling the constructor, we do not need to pass a String object as the first parameter. EVAL string = makestring('123456789012345678901234567890')
Call the BigDecimal constructor that accepts a String parameter, using the String object we just instantiated. EVAL bdnum1 = bdcreate1(string)
Note: For the purposes of the example, the construction of the BigDecimal object above was done in two steps, but it could have been done in one step since we defined the string parameter for the first BigDecimal constructor with the CONST keyword. EVAL bdnum1 = bdcreate1( makestring('123456789012345678901234567890')) Call the BigDecimal constructor that accepts a double as a parameter. EVAL bdnum2 = bdcreate2(double)
Add the two BigDecimal objects together by calling the add method. The prototype indicates that add accepts one parameter, but since add is not a static method, we must also pass a BigDecimal object in order to make the call, and it must be passed as the first parameter. bdnum1 is the object we are using to make the call, and bdnum2 is the parameter. EVAL sum = add(bdnum1:bdnum2) sum now contains a BigDecimal object with the value bdnum1 + bdnum2.
Figure 76.
Example 2 This example shows how to perform a TRIM in Java by using the trim() method as an alternative to the ILE RPG %TRIM built-in function. The trim() method in the String class is not a static method, so a String object is needed in order to call it.
164
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
* * Define a field to store the String object we wish to trim * D str S O CLASS(*JAVA:'java.lang.String') * * Prototype the constructor for the String class. The * constructor expects a byte array. * D makestring PR O EXTPROC(*JAVA: D 'java.lang.String': D *CONSTRUCTOR) D CLASS(*JAVA:'java.lang.String') D parm 10A D * * Prototype the String method getBytes which converts a String to a byte * array. We can then store this byte array in an alpha field. * D getBytes PR 10A EXTPROC(*JAVA: D 'java.lang.String': D 'getBytes') VARYING * * Prototype the String method trim. It doesn't take any parameters, * but since it is not a static method, must be called using a String * object. * D trimstring PR O EXTPROC(*JAVA: D 'java.lang.String': D 'trim') D fld S 10A INZ(' hello ') VARYING
Trim the string by calling the String trim() method. We will reuse the str field to store the result. EVAL str = trimstring(str)
Convert the string back to a byte array and store it in fld. EVAL fld = getBytes(str)
Static methods are called in the same way, except that an object is not required to make a call. If the getBytes() method above was static, the call would look like the example below.
C EVAL fld = getBytes()
If the method does not return a value, use the CALLP operation code.
Creating Objects
In order to call a non-static method, an object is required. The class of the object must be the same as the class containing the method. You may already have an object available, but you may sometimes need to instantiate a new object. You do this by calling a class constructor. A class constructor is neither a static method nor an instance method, and therefore it does not need an instance parameter. The special method name *CONSTRUCTOR is used when prototyping a constructor. For example, class BigDecimal has a constructor that accepts a float parameter.
Chapter 11. RPG and the eBusiness World
165
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Note that the parameter must be passed by value because it maps to the Java float data type. You would call this constructor like this:
D bd D /free PR O CLASS(*JAVA: 'java.math.BigDecimal')
bd = bdcreate(5.2E9); /end-free
The class of the returned object is the same as the class of the constructor itself, so the CLASS keyword is redundant for a constructor, but it may be coded.
This will enable Java to find your native methods. Aside from adding *JAVA and the class to the EXTPROC keyword for the prototype of a native method, you write your native method like any subprocedure. Figure 79 on page 167 is an example of a Java class that calls a native method.
166
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
class MyClass { static { System.loadLibrary ("MYSRVPGM"); } native boolean checkCust (byte custName[]); void anotherMethod () { boolean found; // call the native method found = checkCust (str.getBytes()); }
D checkCust D D D custName
PR
N 100A
The native method itself is coded just like any subprocedure. Figure 81 is an example of a native method coded in RPG.
P checkCust D checkCust D custName /free chain custName return %found; /end-free P checkCust
B PI
N 100A
rec;
Java calls your service program from the default activation group. If your service program is created with activation group *CALLER, it will run in the default activation group. This can sometimes cause problems: v If you are debugging your native methods, and you want to make a change to the code, you will have to sign off and sign back on again before Java will see the new version. v If you are calling other procedures in the service program from other RPG code that is not running in the default activation group, then you will not be able to share any global variables between the ordinary procedures and the native methods. This scenario can arise if a procedure in your RPG service program sets up some global variables, and then calls a Java class which then calls a
Chapter 11. RPG and the eBusiness World
167
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
native method in that service program. Those native methods will not see the same data that the first procedure set up. If you create any Java objects in your native methods, by default they will be destroyed by Java when the native method returns. If you want the object to be available after the native method returns (for example, if you want to use it from another native method later), then you must tell Java that you want to make a global reference, by calling the JNI wrapper procedure getNewGlobalRef . When you are finished with the global reference, you will call JNI wrapper procedure freeGlobalRef, so Java can reclaim the object. See Telling Java you want an object to be permanent on page 171 and Telling Java you are finished with a permanent object on page 172 for more information about these wrapper procedures. If your RPG native method ends abnormally with an unhandled exception, the RPG compiler will throw an exception to Java. The exception is of class java.lang.Exception, and has the form RPG nnnnn, where nnnnn is the RPG status code.
try { nativeMethod (); } catch (Exception exc) { ... }
168
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
PR
100A
VARYING EXTPROC(*JAVA : 'java.lang.String' : 'getBytes') like(jint) EXTPROC(*JAVA : 'java.lang.String' : 'length') like(jstring) like(jint) VARYING
PR
S S S
100A
len = stringLength (string); data = stringBytes (string); if (len > %len(data)); error ('Actual string was too long'); endif; /end-free Figure 82. Retrieving String object length and contents from Java
You can define the returned value from the getBytes method as character data of any length, either varying or non-varying, choosing the length based on your own knowledge of the length of data in the Java String. You can also define the return value as a Date, Time or Timestamp, if you are sure that the String object will have the correct format. Alternately, you can retrieve the string value as a UCS-2 value, by calling the getChars method instead of getBytes.
169
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
/*------------------------------------------------------*/ /* destroyJVM */ /*------------------------------------------------------*/ P destroyJVM B EXPORT D destroyJVM PI N D D D D D D rc rpgRc jvm env bufLen nVMs S S S S S S N * * LIKE(jint) DIM(1) LIKE(jsize) INZ(%elem(jvm)) LIKE(jsize)
/free //---------------------------------------------------------------// See if there's a JVM started //---------------------------------------------------------------rc = JNI_GetCreatedJavaVMs (jvm : bufLen : nVMs); //---------------------------------------------------------------// If JVM is started, destroy it //---------------------------------------------------------------if (rc = 0 and nVMs > 0); JavaVM_P = jvm(1); rc = DestroyJavaVM (jvm(1)); endif; (rc = 0); return *ON; else; return *OFF; endif; /end-free P destroyJVM E if
Figure 84 on page 171 contains the sample source code for freeLocalRef.
170
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
/*------------------------------------------------------*/ /* freeLocalRef */ /*------------------------------------------------------*/ P freeLocalRef... P B EXPORT D freeLocalRef... D PI D env * VALUE D localRef O CLASS(*JAVA D : 'java.lang.Object') D VALUE /free jniEnv_P = env DeleteLocalRef (env : localRef) /end-free P freeLocalRef... P E Figure 84. Source Code for freeLocalRef
Note: You need the JNI environment pointer (described in Obtaining the JNI environment pointer on page 172 below) to call this wrapper.
/*------------------------------------------------------*/ /* getNewGlobalRef */ /*------------------------------------------------------*/ P getNewGlobalRef... P B EXPORT D getNewGlobalRef... D PI O CLASS(*JAVA D : 'java.lang.Object') D env * VALUE D localRef O CLASS(*JAVA D : 'java.lang.Object') D VALUE /free jniEnv_P = env; return NewGlobalRef (env : localRef); /end-free P getNewGlobalRef... P E Figure 85. Source Code for getNewGlobalRef
Note: You need the JNI environment pointer (described in Obtaining the JNI environment pointer on page 172 below) to call this wrapper.
Chapter 11. RPG and the eBusiness World
171
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
/*------------------------------------------------------*/ /* freeGlobalRef */ /*------------------------------------------------------*/ P freeGlobalRef... P B EXPORT D freeGlobalRef... D PI D env * VALUE D globalRef O CLASS(*JAVA D : 'java.lang.Object') D VALUE /free jniEnv_P = env; DeleteGlobalRef (env : globalRef) /end-free P freeGlobalRef... P E Figure 86. Source Code for freeGlobalRef
Note: You need the JNI environment pointer (described in Obtaining the JNI environment pointer below) to call this wrapper.
172
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
/*------------------------------------------------------*/ /* getJniEnv */ /*------------------------------------------------------*/ P getJniEnv B EXPORT D getJniEnv PI * D D D D D D D D rc rpgRc jvm env bufLen nVMs initArgs attachArgs /free //---------------------------------------------------------------// See if there's a JVM started //---------------------------------------------------------------rc = JNI_GetCreatedJavaVMs (jvm : bufLen : nVMs); //---------------------------------------------------------------// If JVM is started, just attach to it, to get the env pointer //---------------------------------------------------------------if (rc = 0 and nVMs > 0); attachArgs = *ALLX'00'; JavaVM_P = jvm(1); rc = AttachCurrentThread (jvm(1) : env : %addr(attachArgs)); //---------------------------------------------------------------// If JVM is not started, start it with the default classpath. //---------------------------------------------------------------else; initArgs = *ALLX'00'; rc = JNI_GetDefaultJavaVMInitArgs (%addr(initArgs)); if (rc = 0); rc = JNI_CreateJavaVM (jvm(1) : env : %addr(initArgs)); endif; endif; if (rc = 0); return env; else; return *NULL; endif; /end-free P getJniEnv E S S S S S S DS DS N * * LIKE(jint) DIM(1) LIKE(jsize) INZ(%elem(jvm)) LIKE(jsize) LIKEDS(JDK1_1InitArgs) LIKEDS(JDK1_1AttachArgs)
173
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
occurred after each call to a JNI function. This is done by calling the ExceptionOccurred JNI function, which returns a Java Exception object (or the Java null object which has a value of 0 in the JNI). Once you have determined that an exception has occurred, the only JNI calls you can make are ExceptionClear and ExceptionDescribe. After you have called ExceptionClear, you are free to make JNI calls again. If you make a non-exception JNI call before calling ExceptionClear, the exception will disappear, and you will not be able to get any further details. RPG always converts a JNI exception into an RPG exception (it signals one of the RNX030x messages, depending on the RPG function that was being done at the time).
Tip! You may want to include this type of exception-handling code in your versions of the JNI wrapper procedures above.
Additional Considerations
Common Runtime Errors
The compiler will not attempt to resolve classes at compile time. If a class cannot be located at run time, a runtime error will occur. It will indicate that an UnresolvedLinkException object was received from the Java environment. The compiler does no type checking of parameters at compile time. If there is a conflict between the prototype and the method being called, an error will be received at run time.
Debugging Hints
A Java object is viewed as an object reference in RPG. This object reference is an integer value, which behaves like a pointer. Normal object references are positive values, assigned in increasing order from 1. Global references, which can be created using JNI function NewGlobalRef , are negative values. These values are assigned in increasing order from the smallest negative number (-2147483647). Normally, these values are not visible within the RPG code. However, this information may be useful when debugging RPG code.
If you want to create a string with UCS-2 data or graphic data, use this code:
D newStringC D D D value PR O 32767C EXTPROC(*JAVA : 'java.lang.String' : *CONSTRUCTOR) CONST VARYING
174
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
S S S
15G 100C
like(jstring)
s s s s
/free jvalue_P = %addr(parms(1)); jvalue.i = 10; jvalue_P = %addr(parms(2)); jvalue.l = string; CallVoidMethodA (JNIEnv_P : objectId : methodId : parms); /end-free Figure 88. JNI Call in RPG
Note that the pointers JNIEnv_P and jvalue_P are defined in the JNI /COPY file.
175
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
*-----------------------------------------------------------------* This example shows how to use JNI to access the fields of a * class or an object. * * * This program creates a Rectangle object and accesses the * width and height variables directly, using JNI calls. * * In this particular case, the getWidth(), getHeight, * setWidth() and setHeight() methods could have been used * to access these fields, avoiding the use of JNI calls. *-----------------------------------------------------------------H THREAD(*SERIALIZE) /DEFINE JNI_COPY_FIELD_FUNCTIONS /COPY JNI /COPY JNIRPG_PR *-----------------------------------------------------------------* JAVA classes and methods *-----------------------------------------------------------------D Rectangle C 'java.awt.Rectangle' D NewRectangle PR O EXTPROC(*JAVA D : Rectangle D : *CONSTRUCTOR) D x 10I 0 VALUE D y 10I 0 VALUE D width 10I 0 VALUE D height 10I 0 VALUE *-----------------------------------------------------------------* Constants with ASCII representations of Java names *-----------------------------------------------------------------* One way to determine these values is to use %UCS2 to convert * a character value to UCS-2, and display the result in hex * in the debugger. * * The ASCII value is in every second byte of the UCS-2 characters. * * For example, %UCS2('abc') = X'006100620063' * -- -- -* The ASCII representation of 'abc' is X'616263' *-----------------------------------------------------------------D ASCII_I C x'49' D ASCII_x C x'78' D ASCII_y C x'79' D ASCII_width C X'7769647468' D ASCII_height C X'686569676874' * Note that this is 'java/awt/Rectangle', not 'java.awt.Rectangle' * because the JNI uses slash as a separator. D ASCII_Rectangle... D C X'6A6176612F6177742F52656D 374616E676C65' *-----------------------------------------------------------------* Cancel handling *-----------------------------------------------------------------D EnableCanHdlr PR EXTPROC('CEERTX') D Handler * CONST PROCPTR D CommArea * CONST OPTIONS(*OMIT) D Feedback 12A OPTIONS(*OMIT) D CanHdlr PR D CommArea * CONST *-----------------------------------------------------------------* Local variables and procedures *-----------------------------------------------------------------D rect s O CLASS(*JAVA : Rectangle) D x S 10I 0 D y S 10I 0 D rectClass S LIKE(jclass) D fieldId S LIKE(jfieldID) D msg S 52A D Cleanup PR
Figure 89. Using JNI to Access Fields of Java Classes and Objects (Part 1 of 3)
176
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
*-----------------------------------------------------------------* Enable the cancel handler to ensure cleanup is done *-----------------------------------------------------------------C CALLP EnableCanHdlr (%PADDR(CanHdlr) C : *OMIT : *OMIT) *-----------------------------------------------------------------* Create a new rectangle with x,y co-ordinates (5, 15), * width 100 and height 200. *-----------------------------------------------------------------C EVAL rect = NewRectangle (5 : 15 : 100 : 200) *-----------------------------------------------------------------* Prepare to call JNI functions to access the Rectangle's fields *-----------------------------------------------------------------C EVAL JNIEnv_P = getJniEnv () C EVAL rectClass = FindClass (JNIEnv_P C : ASCII_Rectangle) *-----------------------------------------------------------------* Call JNI functions to retrieve the Rectangle's width and height *-----------------------------------------------------------------C eval fieldId = GetFieldID (JNIEnv_P C : rectClass C : ASCII_width C : ASCII_I) C eval width = GetIntField (JNIEnv_P C : rect C : fieldId) C eval fieldId = GetFieldID (JNIEnv_P C : rectClass C : ASCII_height C : ASCII_I) C eval height = GetIntField (JNIEnv_P C : rect C : fieldId) C eval msg = 'The rectangle has dimensions (' C + %trim(%editc(width : '1')) C + ', ' C + %trim(%editc(height : '1')) C + ')' C msg dsply *-----------------------------------------------------------------* We do not need this Rectangle any more, so we should tell Java * that it is available to be reclaimed. *-----------------------------------------------------------------C callp DeleteLocalRef(JNIEnv_P : rect) *-----------------------------------------------------------------* Call the Cleanup procedure *-----------------------------------------------------------------C CALLP Cleanup C SETON LR Figure 89. Using JNI to Access Fields of Java Classes and Objects (Part 2 of 3)
177
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
*-----------------------------------------------------------------* Cleanup. * End the JVM *-----------------------------------------------------------------P Cleanup B C callp destroyJVM() P Cleanup E *-----------------------------------------------------------------* Cancel handler. Ends the JVM. *-----------------------------------------------------------------P CanHdlr B D CanHdlr PI D CommArea * CONST *-----------------------------------------------------------------* Abnormal call to the Cleanup procedure *-----------------------------------------------------------------C callp Cleanup() P CanHdlr E Figure 89. Using JNI to Access Fields of Java Classes and Objects (Part 3 of 3)
Calling Java Methods Using the JNI Rather than RPG *JAVA Prototypes
The first three parameters are always the same: 1. the JNI environment pointer 2. the object (for instance methods) or the class (for static methods) 3. the method The method-specific parameters are coded after these three parameters, in one of three different ways. For example, if the method does not return a value (the return type is void), CallVoidMethod: Choose this way if you are going to call the same method many times, since it makes the method very easy to call. This expects the parameters to be passed normally. To call this JNI function, an RPG programmer would copy the CallVoidMethod prototype from the JNI /COPY file, and code additional parameters. For example,
D D D D D D D D CallMyMethod env obj methodID len str PR EXTPROC(*CWIDEN : JNINativeInterface. CallVoidMethod_P) LIKE(JNIEnv_P) VALUE LIKE(jobject) VALUE LIKE(jmethodID) VALUE LIKE(jint) VALUE LIKE(jstring) CONST
... CallMyMethod (JNIEnv_P : objectId : methodId : 10 : string); Figure 90. Sample RPG Code for Calling CallVoidMethod
CallVoidMethodA: Choose this way if you do not want to create a separate prototype for
178
| | | | | | | | | | | | |
calling a method. This expects an array of jvalue structures, with each element of the array holding one parameter. Figure 88 on page 175 above is an example of this. CallVoidMethodV: Do not use this in RPG code. It expects a C construct that is extremely awkward to code in RPG. The actual function to call depends on the type of the return value. For example, if the method returns an integer, you would use CallIntMethodA. To get the class and methodID parameters for these functions, use the FindClass and GetMethodID or GetStaticMethodID. Note: When calling the JNI directly, the class names must be specified with a slash (/) rather than a period (.) as the separator. For example, use java/lang/String rather than java.lang.String.
179
180
181
182
v Equate a shorthand name to a field, expression, or debug command While debugging and testing your programs, ensure that your library list is changed to direct the programs to a test library containing test data so that any existing real data is not affected. You can prevent database files in production libraries from being modified unintentionally by using one of the following commands: v Use the Start Debug (STRDBG) command and retain the default *NO for the UPDPROD parameter v Use the Change Debug (CHGDBG) command and specify the *NO value of the UPDPROD parameter v Use the SET debug command in the Display Module Source display and specify UPDPROD NO See the chapter on debugging in ILE Concepts for more information on the ILE source debugger (including authority required to debug a program or service program and the effects of optimization levels).
183
Debug Commands
Many debug commands are available for use with the ILE source debugger. The debug commands and their parameters are entered on the debug command line displayed on the bottom of the Display Module Source and Evaluate Expression displays. These commands can be entered in uppercase, lowercase, or mixed case. Note: The debug commands entered on the debug command line are not CL commands. The debug commands are listed below. Command ATTR Description Permits you to display the attributes of a variable. The attributes are the size and type of the variable as recorded in the debug symbol table. Permits you to enter either an unconditional or conditional job breakpoint at a position in the program being tested. Use BREAK line-number WHEN expression to enter a conditional job breakpoint. Permits you to remove conditional and unconditional breakpoints, or to remove one or all active watch conditions. Allows you to display the names and definitions assigned by using the EQUATE command. It also allows you to display a different source module than the one currently shown on the Display Module Source display. The module object must exist in the current program object. Allows you to assign an expression, variable, or debug command to a name for shorthand use. Allows you to display or change the value of a variable or to display the value of expressions, records, structures, or arrays. Allows you to define the scope of variables that appear in subsequent EVAL or WATCH commands. Currently, it does not apply to ILE RPG. Allows you to change debug options, such as the ability to update production files, specify if find operations are to be case sensitive, or to enable OPM source debug support. Allows you to run one or more statements of the procedure being debugged. Permits you to enter either an unconditional or conditional breakpoint in the current thread at a position in the program being tested.
BREAK
CLEAR DISPLAY
SET
STEP TBREAK
184
The online help for the ILE source debugger describes the debug commands, explains their allowed abbreviations, and provides syntax diagrams for each command. It also provides examples in each of the ILE languages of displaying and changing variables using the source debugger. Follow these steps to access the online help information for ILE RPG: 1. Enter STRDBG library-name/program-name where program-name is any ILE program with debug data in library library-name. 2. Enter DSPMODSRC to show the source view if this screen does not appear following step 1. 3. Enter PF1 (Help) 4. Put your cursor on EVAL and press enter to bring up the EVAL command help. 5. Put your cursor on Expressions and press enter to bring up help for expressions. 6. Put your cursor on RPG language and press enter to bring up RPG language examples. 7. From the help panel which appears, you can select a number of topics pertaining to RPG, such as displaying variables, displaying table, and displaying multiple-occurrence data structures.
185
The default value for both CRTBNDRPG and CRTRPGMOD is to create a statement view. This view provides the closest level of debug support to previous releases. If you do not want debug data to be included with the module or if you want faster compilation time, specify DBGVIEW(*NONE) when the module is created. However, a formatted dump will not list the values of program variables when no debug data is available. Note also that the storage requirements for a module or program will vary somewhat depending on the type of debug data included with it. The following values for the DBGVIEW parameter are listed in increasing order based on their effect on secondary storage requirements: 1. *NONE 2. *STMT 3. *SOURCE 4. *COPY 5. *LIST 6. *ALL Once you have created a module with debug data and bound it into a program object (*PGM), you can start to debug your program. Note: An OPM program must be compiled with OPTION(*SRCDBG) or OPTION(*LSTDBG) in order to debug it using the ILE source debugger. For more information, see Starting the ILE Source Debugger on page 189 The debug views are summarized in the following table:
Table 14. Debug Views Debug View None Statement view (default) Root source view Debug Data No debug data No source displayed (use statement numbers in source section of compiler listing) Root source member information DBGVIEW Parameter Value *NONE *STMT *SOURCE
186
To create a root source view for a module DBGEX when using CRTRPGMOD, type:
CRTRPGMOD MODULE(MYLIB/DBGEX) SRCFILE(MYLIB/QRPGLESRC) TEXT('Entry module for program DEBUGEX') DBGVIEW(*SOURCE)
Specifying DBGVIEW(*SOURCE) with either create command creates a root source view for debugging module DBGEX. By default, a compiler listing with /COPY members and expanded DDS, as well as other additional information is produced.
187
Specifying DBGVIEW(*COPY) with either create command creates a root source view with /COPY members for debugging module TEST1. By default, a compiler listing is produced. The compiler listing will include /COPY members as well, since OPTION(*SHOWCPY) is a default value.
Specifying DBGVIEW(*LIST) for the DBGVIEW parameter and *EXPDDS for the OPTION parameter on either create command creates a listing view with expanded
188
By default a compiler listing and a statement view are produced. Using a compiler listing to obtain the statement numbers, you debug the program using the debug commands. If the default values for either create command have been changed, you must explicitly specify DBGVIEW(*STMT) and OUTPUT(*PRINT).
189
STRDBG Example
To start a debug session for the sample debug program DEBUGEX and a called OPM program RPGPGM, type:
STRDBG PGM(MYLIB/DEBUGEX MYLIB/RPGPGM) OPMSRC(*YES)
The Display Module Source display appears as shown in Figure 91 on page 191. DEBUGEX consists of two modules, an RPG module DBGEX and a C module cproc. See Sample Source for Debug Examples on page 229 for the source for DBGEX, cproc, and RPGPGM. If the entry module has a root source, COPY, or listing view, then the display will show the source of the entry module of the first program. In this case, the program was created using DBGVIEW(*ALL) and so the source for the main module, DBGEX, is shown.
190
*--------------------------------------------------------------* Define standalone fields for different ILE RPG data types. More... Debug . . . _________________________________________________________________ _______________________________________________________________________________ F3=End program F6=Add/Clear breakpoint F10=Step F11=Display variable F12=Resume F17=Watch variable F18=Work with watch F24=More keys
Note: Up to 20 service programs can initially be added to the debug session by using the Service Program (SRVPGM) parameter on the STRDBG command. You can also add ILE service programs to a debug session by using option 1 (Add) on the Work with Module List display (F14) or by letting the source debugger add it as part of a STEP INTO debug command.
191
The Display Module Source display appears. 2. Press F14 (Work with module list) to show the Work with Module List display as shown in Figure 92 on page 193. 3. To add service program CVTTOHEX, on the first line of the display, type: 1 (Add program), CVTTOHEX for the Program/module field, MYLIB for the Library field. Change the default program type from *PGM to *SRVPGM and press Enter. 4. Press F12 (Cancel) to return to the Display Module Source display.
192
The Display Module Source display appears. 2. Press F14 (Work with module list) to show the Work with Module List display as shown in Figure 93. 3. On this display type 4 (Remove program) on the line next to CVTHEXPGM and CVTTOHEX, and press Enter. 4. Press F12 (Cancel) to return to the Display Module Source display.
Work with Module List Type options, press enter. 1=Add program 4=Remove program 8=Work with module breakpoints Opt Program/module Library *LIBL *PGM 4 CVTHEXPGM MYLIB CVTHEXPG 4 CVTTOHEX MYLIB CVTTOHEX RPGPGM MYLIB DEBUGEX MYLIB DBGEX CPROC 5=Display module source Type *PGM *MODULE *SRVPGM *MODULE *PGM *PGM *MODULE *MODULE
System:
AS400S1
Selected
193
The source of an OPM program can be shown if the following conditions are met: 1. The OPM program was compiled with OPTION(*LSTDBG) or OPTION(*SRCDBG). (Only RPG and COBOL programs can be compiled with *LSTDBG.) 2. The ILE debug environment is set to accept OPM programs; that is the value of OPMSRC is *YES. (The system default is OPMSRC(*NO).) There are two methods to change what is shown on the Display Module Source display: v Change to a different module v Change the view of a module When you change a view, the ILE source debugger maps to equivalent positions in the view you are changing to. When you change the module, the runnable statement on the displayed view is stored in memory and is viewed when the module is displayed again. Line numbers that have breakpoints set are highlighted. When a breakpoint, step, or message causes the program to stop, and the display to be shown, the statement where the breakpoint occurred is highlighted.
The module object module-name is shown. The module object must exist in a program object that has been added to the debug session. For example, to change from the module DBGEX in Figure 91 on page 191 to the module cproc using the Display module source option, follow these steps: 1. To work with modules type DSPMODSRC, and press Enter. The Display Module Source display is shown.
194
Work with Module List Type options, press enter. 1=Add program 4=Remove program 8=Work with module breakpoints Opt Program/module Library *LIBL *PGM RPGPGM MYLIB DEBUGEX MYLIB DBGEX 5 CPROC 5=Display module source Type *PGM *PGM *MODULE *MODULE
System:
AS400S1
Selected
Bottom Debug . . . _________________________________________________________________ _______________________________________________________________________________ F3=End program F6=Add/Clear breakpoint F10=Step F11=Display variable F12=Resume F17=Watch variable F18=Work with watch F24=More keys
Program: 1 2 3 4 5 6 7 8 9 10 11 12 13
Module:
CPROC
char *c_proc(unsigned int size, char *inzval) { char *ptr; ptr = malloc(size); memset(ptr, *inzval, size ); printf("import string: %6s.\n",EXPORTFLD); return(ptr); }
195
The current view is listed at the top of the window, and the other views that are available are shown below. Each module in a program can have a different set of views available, depending on the debug options used to create it. Note: If a module is created with DBGVIEW(*ALL), the Select View window will show three views available: root source, COPY, and listing. If the module has no /COPY members, then the COPY view is identical to the root source view. 3. Type a 1 next to the listing view, and press Enter. The Display Module Source display appears showing the module with a listing view.
196
197
on the debug command line. The variable line-number is the line number in the currently displayed view of the module object on which you want to set a breakpoint. To remove an unconditional job breakpoint using the CLEAR debug command, type:
CLEAR line-number
on the debug command line. The variable line-number is the line number in the currently displayed view of the module object from which you want to remove a breakpoint. When a job breakpoint is cleared, it is also cleared for all threads.
on the debug command line where module-name is the name of the module that you want to display. 3. To set an unconditional breakpoint on the first Calculation specification, place the cursor on line 88. 4. Press F6 (Add/Clear breakpoint). If there is no breakpoint on the line 88, then an unconditional breakpoint is set on that line, as shown in Figure 97 on page 199. If there is a breakpoint on the line, it is removed. Note: Because we want the breakpoint on the first Calculation specification, we could have placed the cursor on any line before the start of the calculation specifications and the breakpoint would still have been placed on line 88, since it is the first runnable statement.
198
*--------------------------------------------------------------* Fld1a is an overlay field of Fld1. Since Fld1 is initialized More... Debug . . . _________________________________________________________________ _______________________________________________________________________________ F3=End program F6=Add/Clear breakpoint F10=Step F11=Display variable F12=Resume F17=Watch variable F18=Work with watch F24=More keys Breakpoint added to line 88.
5. After the breakpoint is set, press F3 (Exit) to leave the Display Module Source display. The breakpoint is not removed. 6. Call the program. When a breakpoint is reached, the program stops and the Display Module Source display is shown again, with the line containing the breakpoint highlighted. At this point you can step through the program or resume processing.
Note: The Thread field is displayed when the DEBUG option on the SPAWN command is greater than or equal to one. The TBREAK debug command has the same syntax as the BREAK debug command. Where the BREAK debug command sets a job breakpoint at the same position in all threads, the TBREAK debug command sets a thread breakpoint in a single thread the current thread. The current thread is the thread that is currently being debugged. Debug commands are issued to this thread. When a debug stop occurs, such as a
199
on the debug command line. The variable line-number is the line number in the currently displayed view of the module object on which you want to set a breakpoint and expression is the conditional expression that is evaluated when the breakpoint is encountered. The relational operators supported for conditional breakpoints are noted at the beginning of this section. In non-numeric conditional breakpoint expressions, the shorter expression is implicitly padded with blanks before the comparison is made. This implicit
200
on the debug command line. The variable line-number is the line number in the currently displayed view of the module object from which you want to remove a breakpoint.
TORASD80
Bottom Command ===> ________________________________________________________________________ F3=Exit F4=Prompt F5=Refresh F9=Retrieve F12=Cancel Breakpoint added to line 127.
A conditional job breakpoint is set on line 127. The expression is evaluated before the statement is run. If the result is true (in the example, if *IN02=1), the program stops, and the Display Module Source display is shown. If the result is false, the program continues to run. An existing breakpoint is always replaced by a new breakpoint entered at the same location. 5. After the breakpoint is set, press F12 (Cancel) to leave the Work with Module Breakpoints display. Press F3 (End Program) to leave the ILE source debugger. Your breakpoint is not removed. 6. Call the program. When a breakpoint is reached, the program stops, and the Display Module Source display is shown again. At this point you can step through the program or resume processing.
Chapter 12. Debugging Programs
201
A conditional job breakpoint is set on line 128. 2. After the breakpoint is set, press F3 (End Program) to leave the ILE source debugger. Your breakpoint is not removed. 3. Call the program. When a breakpoint is reached, the program stops, and the Display Module Source display is shown again.
*--------------------------------------------------------------More... Debug . . . break 128 when BigDate='1994-09-30'______________________________ _______________________________________________________________________________ F3=End program F6=Add/Clear breakpoint F10=Step F11=Display variable F12=Resume F17=Watch variable F18=Work with watch F24=More keys
Program: 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
DEBUGEX
Module:
DBGEX
*--------------------------------------------------------------* After the following SETON operation, *IN02 = '1'. *--------------------------------------------------------------C SETON C IF *IN02 C MOVE '1994-09-30' BigDate C ENDIF *--------------------------------------------------------------* Put a new value in the second cell of Arry. *--------------------------------------------------------------C MOVE 4 Arry
Figure 99. Setting a Conditional Job Breakpoint Using the BREAK Command
202
v Graphic field compared to graphic field v Graphic field compared to graphic literal v Graphic field compared to hex literal v Graphic literal v Graphic literal v Graphic literal v Hex literal v Hex literal
2 2 3 3 3 2 3
Notes: 1. Character literal is of the form 'abc'. 2. Hexadecimal literal is of the form X'hex digits'. 3. Graphic literal is of the form G'oK1K2i'. Shift-out is represented as o and shift-in is represented as i.
203
on the debug command line. The variable procedure-name is the name of the procedure in which you are setting the breakpoint. Since ILE RPG allows more than one procedure per module, the procedure-name can be either the name of the main procedure or one of the subprocedures in a module. The variable statement-number is the statement number from the compiler listing on which you want to set a breakpoint. Note: The statement number in the source listing is labeled as the Line Number when OPTION(*NOSRCSTMT) is specified, and as the Statement Number when OPTION(*SRCSTMT) is specified. For example, Figure 100 shows a sample section of a listing with OPTION(*NOSRCSTMT). Figure 101 shows the same section with OPTION(*SRCSTMT).
Line <--------------------- Source Specifications ----------------------------------------------><---- Comments ----> Src Seq Number ....1....+....2....+<-------- 26 - 35 -------->....4....+....5....+....6....+....7....+....8....+....9....+...10 Id Number S o u r c e L i s t i n g 1 C MOVE '123' BI_FLD1 000100 2 C SETON LR---000200 * * * * * E N D O F S O U R C E * * * * *
In this example, a Statement View is used to set a breakpoint for the procedure TEST. To set a breakpoint for the module with the *NOSRCSTMT listing, type:
BREAK TEST/2
To set a breakpoint for the module with the *SRCSTMT listing, type:
BREAK TEST/200
LR---- line.
Bottom Debug . . . break TEST/2_____________________________________________________ _______________________________________________________________________________ F3=End program F6=Add/Clear breakpoint F10=Step F11=Display variable F12=Resume F17=Watch variable F18=Work with watch F24=More keys Breakpoint added to statement 2 of procedure TEST.
Display Module Source Program: TEST Library: MYLIB (Source not available.)
Module:
TEST
204
Or
BREAK FmtCust/2600
B line.
Display Module Source Library: MYLIB Module: MYPGM * Begin-procedure P FmtCust B D FmtCust PI 25A * Procedure-interface (same as the prototype) D FirstName 10A D LastName 15A D ValidRec N * Calculations C IF ValidRec = '0' C RETURN %TRIMR(FirstName) + ' ' + Last C ENDIF C RETURN 'Last Customer' * End-procedure P E *MAIN PROCEDURE EXIT More... Debug . . . BREAK fmtcust/2600_______________________________________________ _______________________________________________________________________________ F3=End program F6=Add/Clear breakpoint F10=Step F11=Display variable F12=Resume F17=Watch variable F18=Work with watch F24=More keys Breakpoint added to line 34. Program: 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 MYPGM 002500 002600 002700 002800 002900 003000 003100 003200 003300 003400 003500 003600 003700 003800
Figure 103. Setting a Breakpoint using Statement Numbers and a Listing View with OPTION(*SRCSTMT)
To set a conditional job breakpoint using the BREAK debug command, type:
BREAK procedure-name/statement-number WHEN expression
on the debug command line. The variables procedure-name and statement-number are the same as for unconditional breakpoints. The variable expression is the conditional expression that is evaluated when the breakpoint is encountered. To remove an unconditional or conditional breakpoint using the CLEAR debug command, type:
CLEAR procedure-name/statement-number
205
on the debug command line. The breakpoints are removed from all of the modules bound to the program.
206
Characteristics of Watches
You should know the following characteristics about watches before working with them: v Watches are monitored system-wide, with a maximum number of 256 watches that can be active simultaneously. This number includes watches set by the system. Depending on overall system use, you may be limited in the number of watch conditions you can set at a given time. If you try to set a watch condition while the maximum number of active watches across the system is exceeded, you receive an error message and the watch condition is not set. Note: If an expression or a variable crosses a page boundary, two watches are used internally to monitor the storage locations. Therefore, the maximum number of expressions or variables that can be watched simultaneously system-wide ranges from 128 to 256. v Watch conditions can only be set when a program is stopped under debug, and the expression or variable to be watched is in scope. If this is not the case, an error message is issued when a watch is requested, indicating that the corresponding call stack entry does not exist. v Once the watch condition is set, the address of a storage location watched does not change. Therefore, if a watch is set on a temporary location, it could result in spurious watch-condition notifications. An example of this is the automatic storage of an ILE RPG subprocedure, which can be re-used after the subprocedure ends. A watch condition may be registered although the watched variable is no longer in scope. You must not assume that a variable is in scope just because a watch condition has been reported. v Two watch locations in the same job must not overlap in any way. Two watch locations in different jobs must not start at the same storage address; otherwise, overlap is allowed. If these restrictions are violated, an error message is issued. Note: Changes made to a watched storage location are ignored if they are made by a job other than the one that set the watch condition. v After the command is successfully run, your application is stopped if a program in your session changes the contents of the watched storage location, and the Display Module Source display is shown. If the program has debug data, and a source text view is available, it will be shown. The source line of the statement that was about to be run when the content change at the storage-location was detected is highlighted. A message indicates which watch condition was satisfied. If the program cannot be debugged, the text area of the display will be blank. v Eligible programs are automatically added to the debug session if they cause the watch-stop condition. v When multiple watch conditions are hit on the same program statement, only the first one will be reported. v You can set watch conditions also when you are using service jobs for debugging, that is when you debug one job from another job.
207
Address 080090506F027004
The Work with Watch display shows all watches currently active in the debug session. You can clear, and display watches from this display. When you select Option 5 Display, the Display Watch window shown below displays information about the currently active watch.
208
on the debug command line. This command requests a breakpoint to be set if the value of expression is changed from its current value. Note: expression is used to determine the address of the storage location to watch and must resolve to a location that can be assigned to, for example:
%SUBSTR(X 1 5)
The scope of the expression variables in a watch is defined by the most recently issued QUAL command. v To set a watch condition and specify a watch length, type:
WATCH expression : watch length
on a debug command line. Each watch allows you to monitor and compare a maximum of 128 bytes of contiguous storage. If the maximum length of 128 bytes is exceeded, the watch condition will not be set, and the debugger issues an error message. By default, the length of the expression type is also the length of the watch-comparison operation. The watch-length parameter overrides this default. It determines the number of bytes of an expression that should be compared to determine if a change in value has occurred. For example, if a 4-byte integer is specified as the variable, without the watch-length parameter, the comparison length is four bytes. However, if the watch-length parameter is specified, it overrides the length of the expression in determining the watch length.
Chapter 12. Debugging Programs
209
on a debug command line. This command brings up the Display Debug Watches display shown below.
Display Debug Watches ------------Job--------------MYJOBNAME1 MYUSERPRF1 123456 JOB4567890 PRF4567890 222222 JOB4567890 PRF4567890 222222 JOB PROFILE 333333 SOMEJOB SOMEPROFIL 444444 Bottom Press Enter to continue F3=Exit F5=Refresh F12=Cancel NUM 1 1 2 14 3 LENGTH 5 8 2 4 4
Note: This display does not show watch conditions set by the system.
The watch number can be obtained from the Work With Watches display. To clear all watches for your session, type:
CLEAR WATCH ALL
on a debug command line. Note: While the CLEAR PGM command removes all breakpoints in the program that contains the module being displayed, it has no effect on watches. You must explicitly use the WATCH keyword with the CLEAR command to remove watch conditions. v The CL End Debug (ENDDBG) command removes watches set in the local job or in a service job. Note: ENDDBG will be called automatically in abnormal situations to ensure that all affected watches are removed. v The initial program load (IPL) of your iSeries system removes all watch conditions system-wide.
210
on a debug line, accepting the default value for the watch-length. If the value of the variable SALARY changes subsequently, the application stops and the Display Module Source display is shown, as illustrated in Figure 107.
Display Module Source Library: MYLIB Module: PAYROLL eval cnt = 1 dow (cnt < EMPMAX) eval Pay_exmpt(cnt) = eflag(cnt) eval cnt = cnt + 1 enddo eval dow if eval eval else eval endif eval enddo index = 1 index <= cnt Pay_exmpt(index) = 1 SALARY = 40 * Pay_wage(index) numexmpt = numexmpt + 1 SALARY = Pay_hours(index)*Pay_wage(index) index = index + 1
More... Debug . . . _________________________________________________________________ _______________________________________________________________________________ F3=End program F6=Add/Clear breakpoint F10=Step F11=Display variable F12=Resume F17=Watch variable F18=Work with watch F24=More keys Watch number 1 at line 65, variable: SALARY
Program: PAYROL 52 C 53 C 54 C 55 C 56 C 57 C 58 C 59 C 60 C 61 C 62 C 63 C 64 C 65 C 66 C 67 C
v The line number of the statement where the change to the watch variable was detected is highlighted. This is typically the first executable line following the statement that changed the variable. v A message indicates that the watch condition was satisfied. Note: If a text view is not available, a blank Display Module Source display is shown, with the same message as above in the message area. The following programs cannot be added to the ILE debug environment: 1. ILE programs without debug data 2. OPM programs with non-source debug data only 3. OPM programs without debug data In the first two cases, the stopped statement number is passed. In the third case, the stopped MI instruction is passed. The information is displayed at the bottom of a blank Display Module Source display as shown below. Instead of the line number, the statement or the instruction number is given.
211
on the debug command line. The variable number-of-statements is the number of statements of the program object that you want to run in the next step before the program object is halted again. For example, if you type
STEP 5
212
on the debug command line. The variable number-of-statements is the number of statements that you want to run in the next step before processing is halted again. If this variable is omitted, the default is 1.
213
on the debug command line. The variable number-of-statements is the number of statements that you want to run in the next step before processing is halted again. If this variable is omitted, the default is 1. If one of the statements that are run contains a call statement the debugger will step into the called program or procedure. Each statement in the called program or procedure will be counted in the step. If the step ends in the called program or procedure, then the called program or procedure will be shown in the Display Module Source display. For example, if you type
STEP 5 INTO
on the debug command line, the next five statements of the program object are run. If the third statement is a CALL operation to another program object, then two statements of the calling program object are run and the first three statements of the called program object are run. In the example of DEBUGEX, if you enter STEP INTO (or press F22) while on the EVAL operation that calls the procedure c_proc, then you would step into the C module. The STEP INTO command works with the CL CALL command as well. You can take advantage of this to step through your program after calling it. After starting the source debugger, from the initial Display Module Source display, enter
STEP 1 INTO
This will set the step count to 1. Use the F12 key to return to the command line and then call the program. The program will stop at the first statement with debug data.
TIP In order to display data immediately before or after a subprocedure is run, place breakpoints on the procedure specifications that begin and end the subprocedure.
214
*--------------------------------------------------------------* Call c_proc, which imports ExportFld from the main procedure. More... Debug . . . _________________________________________________________________ _______________________________________________________________________________ F3=End program F6=Add/Clear breakpoint F10=Step F11=Display variable F12=Resume F17=Watch variable F18=Work with watch F24=More keys Breakpoint at line 102.
Program: 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
Figure 109. Display Module Source display of DBGEX Before Stepping Into RPGPGM
5. Press F22 (Step into). One statement of the program runs, and then the Display Module Source display of RPGPGM is shown, as in Figure 110 on page 216. In this case, the first runnable statement of RPGPGM is processed (line 13) and then the program stops. Note: You cannot specify the number of statements to step through when you use F22. Pressing F22 performs a single step.
215
Bottom Debug . . . _________________________________________________________________ _______________________________________________________________________________ F3=End program F6=Add/Clear breakpoint F10=Step F11=Display variable F12=Resume F17=Watch variable F18=Work with watch F24=More keys Step completed at line 13.
If the ILE source debugger is not set to accept OPM programs, or if there is no debug data available, then you will see a blank Display Module Source display with a message indicating that the source is not available. (An OPM program has debug data if it was compiled with OPTION(*SRCDBG) or OPTION(*LSTDBG).)
216
217
*--------------------------------------------------------------* Define parameters for non-prototyped call More... Debug . . . eval LastName____________________________________________________ _______________________________________________________________________________ F3=End program F6=Add/Clear breakpoint F10=Step F11=Display variable F12=Resume F17=Watch variable F18=Work with watch F24=More keys LASTNAME = 'Jones '
Program: 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
*--------------------------------------------------------------* Define prototypes for called procedures c_proc and switch *--------------------------------------------------------------D c_proc PR * EXTPROC('c_proc') D size 10U 0 VALUE D inzval 1A CONST D Switch D Parm PR 1A
Figure 113 on page 219 shows the use of the EVAL command with different types of RPG fields. The fields are based on the source in Figure 121 on page 230. Additional examples are also provided in the source debugger online help.
218
219
The variable field-name is the name of the array, the variable n is a number representing the start of the range, and the variable m is a number representing the end of the range. Figure 114 shows the use of EVAL with the array in DBGEX.
> EVAL Arry ARRY(1) = 1.23 ARRY(2) = 1.23 > EVAL Arry(2) ARRY(2) = 1.23 > EVAL Arry(1..2) ARRY(1) = 1.23 ARRY(2) = 1.23 3S 2 DIM(2) INZ(1.23) ** Display full array ** ** Display second element ** ** Display range of elements **
You can change the current element using the %INDEX built-in function. To determine the value of the table index, enter the following command:
EVAL _QRNU_TABI_name
where name represents the table name in question. Figure 115 on page 221 shows the use of EVAL with the table in DBGEX.
220
> EVAL TableA TABLEA = 'aaa' > EVAL TableA(1) TABLEA(1) = 'aaa' > EVAL TableA(2) TABLEA(2) = 'bbb' > EVAL _QRNU_TABI_TableA _QRNU_TABI_TABLEA = 1 > EVAL TableA(1..3) TABLEA(1) = 'aaa' TABLEA(2) = 'bbb' TABLEA(3) = 'ccc' > EVAL TableA=%INDEX(3) > EVAL TableA TABLEA = 'ccc'
** Specify index 1 ** ** Specify index 2 ** ** Display value of current index ** ** Specify the whole table **
For example, to display subfield NAME of qualified data structure INFO, type:
EVAL NAME OF INFO
When displaying a multiple-occurrence data structure, an EVAL on the data structure name will show the subfields using the current index. To specify a particular occurrence, specify the index in parentheses following the data structure name. For example, to display the contents of the second occurrence of DS1, type:
EVAL DS1(2)
Similarly, to view the contents of a particular occurrence of a subfield, use the index notation. To determine the value of the current index, enter the following command:
EVAL _QRNU_DSI_name
where name represents the data structure name in question. If a subfield is defined as an array overlay of another subfield, to see the contents of the overlay subfield, you can use the %INDEX built-in function to specify the occurrence, and the index notation to specify the array. An alternative way of displaying a subfield which is an array overlay is to use the following notation:
EVAL subfield-name(occurrence-index,array-index)
221
To display a data structure for which no subfields have been defined, you must use the character display function of EVAL which is discussed below.
Displaying Indicators
Indicators are defined as 1-byte character fields. Except for indicators such as *INLR, you can display indicators either as *INxx or *IN(xx). Because the system stores indicators as an array, you can display them all or some subset of them using the range notation. For example, if you enter EVAL *IN, you will get a list of indicators 01 to 99. To display indicators *IN01 to *IN06 you would enter EVAL *IN(1..6).
222
on the debug command line. The variable field-name is the name of the field that you want to display in hexadecimal format. 'x' specifies that the field is to be displayed in hexadecimal format. The variable number-of-bytes indicates the number of bytes displayed. If no length is specified after the 'x', the size of the field is used as the length. A minimum of 16 bytes is always displayed. If the length of the field is less than 16 bytes, then the remaining space is filled with zeroes until the 16 byte boundary is reached. For example, the field String is defined as six-character string. To find out the hexadecimal equivalent of the first 3 characters, you would enter:
EVAL String: x 3 Result: 00000 C1C2C3.. ........ ........ ........ - ABC.............
on the debug command line. The variable field-name is the name of the field that you want to display in character format. 'c' specifies the number of characters to display. For example, in the program DEBUGEX, data structure DS2 does not have any subfields defined. Several MOVE operations move values into the subfield. Because there are no subfields defined, you cannot display the data structure. Therefore, to view its contents you can use the character display function of EVAL.
EVAL DS2:C 20 Result: DS2:C 20 = 'aaaaaaaaaabbbbbbbbbb'
223
will show the contents of those 10 bytes. You can also show the contents in hexadecimal using:
EVAL PTR1:x 10
This would be especially useful when the data that the pointer addresses is not stored in printable form, such as packed or binary data.
224
To change the current index, you can use the %INDEX built-in function, where the index is specified in parentheses following the function name. An example of %INDEX is found in the table section of Figure 115 on page 221 and Figure 116 on page 222. Note: %INDEX will change the current index to the one specified. Therefore, any source statements which refer to the table or multiple-occurrence data structure subsequent to the EVAL statement may be operating with a different index than expected. Use the %VARS debug built-in function when the variable name conflicts with any of the debug command names. For example, EVAL %VAR(EVAL) can be used to evaluate a variable named EVAL, whereas EVAL EVAL would be a syntax error.
Chapter 12. Debugging Programs
225
on the debug command line. field-name is the name of the variable that you want to change and value is an identifier, literal, or constant value that you want to assign to variable field-name. For example,
EVAL COUNTER=3
on the message line of the Display Module Source display. Use the EVAL debug command to assign numeric, alphabetic, and alphanumeric data to fields. You can also use the %SUBSTR built-in function in the assignment expression. When you assign values to a character field, the following rules apply: v If the length of the source expression is less than the length of the target expression, then the data is left justified in the target expression and the remaining positions are filled with blanks. v If the length of the source expression is greater than the length of the target expression, then the data is left justified in the target expression and truncated to the length of the target expression. Note: Graphic fields can be assigned any of the following: v Another graphic field v A graphic literal of the form G'oK1K2i' v A hexadecimal literal of the form X'hex digits' UCS-2 fields must be changed using hexadecimal constants. For example, since %UCS2(AB) = U00410042, then to set a UCS-2 field to the UCS-2 form of AB in the debugger, you would use EVAL ucs2 = X00410042. Variable-length fields can be assigned using, for example, EVAL varfldname = abc. This sets the data part of the field to abc and the length part to 3. To set the length part without changing the data, determine the hexadecimal value of the length (for example 11 is X000B), and use EVAL %SUBSTR(varfldname 1 2) = X000B. When assigning literals to fields, the normal RPG rules apply: v Character literals should be in quotes. v Graphic literals should be specified as GoDDDDi, where o is shift-out and i is shift-in.
226
227
6 BYTES
6 BYTES
on the debug command line. shorthand-name is the name that you want to equate with a field, expression, or debug command, and definition is the field, expression, or debug command that you are equating with the name. For example, to define a shorthand name called DC which displays the contents of a field called COUNTER, type:
EQUATE DC EVAL COUNTER
228
on the debug command line. A list of the active names is shown on the Evaluate Expression display.
DBGVIEW(*ALL) was chosen in order to show the different views available. 2. To create the C module using the source in Figure 123 on page 234, type:
CRTCMOD MODULE(MYLIB/cproc) SRCFILE(MYLIB/QCLESRC) DBGVIEW(*SOURCE) TEXT('C procedure for Sample Debug Program')
229
We could have created RPGPGM to run in the OPM default activation group. However, we decided to have it run in the same activation group as DEBUGEX, and since DEBUGEX needs only a temporary activation group, *NEW was chosen for both programs.
*=================================================================* * DEBUGEX - Program designed to illustrate use of ILE source * debugger with ILE RPG source. Provides a * sample of different data types and data structures. * * Can also be used to produce sample formatted dumps. *=================================================================* *-----------------------------------------------------------------* * The DEBUG keyword enables the formatted dump facility. *-----------------------------------------------------------------* H DEBUG *-----------------------------------------------------------------* * Define standalone fields for different ILE RPG data types. *-----------------------------------------------------------------* D String S 6A INZ('ABCDEF') D Packed1D0 S 5P 2 INZ(-93.4) D ZonedD3D2 S 3S 2 INZ(-3.21) D Bin4D3 S 4B 3 INZ(-4.321) D Bin9D7 S 9B 7 INZ(98.7654321) D DBCSString S 3G INZ(G'"BBCCDD"') D UCS2String S 5C INZ(%UCS2('ucs-2')) D CharVarying S 5A INZ('abc') VARYING D Int3 S 3I 0 INZ(-128) D Int5 S 5I 0 INZ(-2046) D Int10 S 10I 0 INZ(-31904) D Int20 S 20I 0 INZ(-463972) D Unsigned3 S 3U 0 INZ(128) D Unsigned5 S 5U 0 INZ(2046) D Unsigned10 S 10U 0 INZ(31904) D Unsigned20 S 20U 0 INZ(463972) D Float4 S 4f INZ(7.2098) D Float8 S 8f INZ(-129.0978652) D DBCSString S 3G INZ(G'"BBCCDD"') Figure 121. Source for Module DBGEX (Part 1 of 4). DBGEX is the main module of the program DEBUGEX.
230
* D Spcptr S * D SpcSiz C 8 * Date, Time, Timestamp D BigDate S D INZ(D'9999-12-31') D BigTime S T INZ(T'12.00.00') D BigTstamp S Z INZ(Z'9999-12-31-12.00.00.000000') * Array D Arry S 3S 2 DIM(2) INZ(1.23) * Table D TableA S 3 DIM(3) CTDATA *-----------------------------------------------------------------* * Define different types of data structures. *-----------------------------------------------------------------* D DS1 DS OCCURS(3) D Fld1 5A INZ('ABCDE') D Fld1a 1A DIM(5) OVERLAY(Fld1) D Fld2 5B 2 INZ(123.45) * D DS2 DS 10 OCCURS(2) * D DS3 DS D Title 5A INZ('Mr. ') D LastName 10A INZ('Jones ') D FirstName 10A INZ('Fred ') D QUALDS DS QUALIFIED D Id_Num 8S 0 D Country 20A DIM(10) D LIKE_QUALDS DS LIKEDS(QUALDS) *-----------------------------------------------------------------* * Define prototypes for called procedures c_proc and switch *-----------------------------------------------------------------* D c_proc PR * EXTPROC('c_proc') D size 10U 0 VALUE D inzval 1A CONST D Switch PR D Parm 1A *-----------------------------------------------------------------* * Define parameters for non-prototyped call * PARM1 is used when calling RPGPROG program. *-----------------------------------------------------------------* D PARM1 S 4P 3 INZ(6.666) D EXPORTFLD S 6A INZ('export') EXPORT Figure 121. Source for Module DBGEX (Part 2 of 4). DBGEX is the main module of the program DEBUGEX.
231
232
Figure 121. Source for Module DBGEX (Part 4 of 4). DBGEX is the main module of the program DEBUGEX.
*=================================================================* * RPGPGM - Program called by DEBUGEX to illustrate the STEP * * functions of the ILE source debugger. * * * * This program receives a parameter InputParm from DEBUGEX, * * displays it, then returns. * *=================================================================* D InputParm S 4P 3 C *ENTRY PLIST C PARM InputParm C InputParm DSPLY C SETON LR Figure 122. Source for OPM Program RPGPGM
233
234
| | |
235
Function Check Indicates that one of the three previous exceptions occurred and was not handled. Exception messages are associated with call stack entries. Each call stack entry is in turn associated with a list of exception handlers defined for that entry. (See The Call Stack on page 127 for further discussion of a call stack.) Figure 124 on page 237 shows a call stack where an OPM program calls an ILEprogram consisting of several modules and therefore several procedures. Refer to this figure in the discussions which follow. In general, when an exception occurs, the handlers associated with the call stack entry are given a chance to handle the exception. If the exception is not handled by any of the handlers on the list then it is considered to be unhandled, at which point the following default actions are taken for the unhandled exception: 1. If the exception is a function check, the call stack entry is removed from the stack. 2. The exception is moved (percolated) to the previous call stack entry. 3. The exception handling process is restarted for this call stack entry. The action of allowing the previous call stack entry to handle an exception is referred to as percolation. Percolation continues until the exception is handled, or until the control boundary is reached. A control boundary is a call stack entry for which the immediately preceding call stack entry is in a different activation group or is an OPM program. In Figure 124 on page 237 Procedure P1 is the control boundary.
236
ILE
Pass 2
ILE
In OPM, the exception message is associated with the program which is active on the call stack. If the exception is not handled by the associated exception handlers, then a function check is sent to the same call stack entry which received the
237
238
| | |
239
TIP A *PSSR is local to the procedure in which it is coded; therefore, to have a common error routine, you can code a procedure to handle the error and call the procedure from each local *PSSR.
240
Nested Exceptions
Exceptions can be nested. A nested exception is an exception that occurs while another exception is being handled. When this happens, the processing of the first exception is temporarily suspended. Exception handling begins again with the most recently generated exception.
Unhandled Exceptions
An unhandled exception is one that has not been handled by an exception handler associated with the call stack entry that first received the exception. When an exception is unhandled, one of the following actions occurs: If the message type is a function check (CPF9999) associated with a main procedure then the RPG default handler will issue an inquiry message describing the originating condition. v If you pick the D(ump) or C(ancel) option then the procedure which first received the exception terminates and the function check is percolated to the caller. v If you pick the R(etry) or G(et Input) option then the function check is handled, exception processing ends, and the procedure resumes processing at *GETIN (when G is chosen) or at the I/O operation in which the exception occurred (when R is chosen). For example, any read operation will be retried if the read failed because of record locking. For other types of messages the exception is percolated up the call stack to the caller of the procedure. That procedure is presented with the exception and given a chance to handle it. If it does not, then the exception is percolated up the call stack until it reaches the control boundary, at which point the exception is converted to a function check, and exception handling starts over as described above.
241
| | |
The following then occurs: 1. Since there is no error indicator, active MONITOR group, or *PSSR error subroutine coded on the SUBST operation in PRC2, PRC2 cannot handle the program error, and so it is unhandled. 2. Since it is not a function check, it is percolated (passed up the call stack) to PRC1. 3. PRC1 receives (handles) the same exception message, and sets on the error indicator on the CALL operation with the side effect that PRC2 is terminated. 4. Processing then continues in PRC1 with the statement following the CALL operation. Note: The same exception handling events described would apply to a procedure call (CALLB operation) as well.
242
Percolate MCH3601
Procedure PRC2
Percolate CPF9999
Procedure PRC2
| |
The following then occurs: 1. Since there are no error handlers in PRC2, PRC2 cannot handle the function check, and so it is unhandled. 2. Since it is a function check, an inquiry message is issued describing the originating condition. 3. Depending on the response to the inquiry message, PRC2 may be terminated and the exception percolated to PRC1 (response is C) or processing may continue in PRC2 (response is G).
Optimization Considerations
While running a *FULL optimized program, the optimizer may keep frequently used values in machine registers and restore them to storage only at predefined points during normal program processing. Exception handling may break this normal processing and consequently program variables contained in registers may not be returned to their assigned storage locations.
Chapter 13. Handling Exceptions
243
244
appropriate data structure (PSDS or INFDS) is updated, and control returns to the next sequential instruction. You can then test the indicator to determine what action to take. To enable the E operation code extender handler, you specify an E (or e) with any of the operation codes in Table 16. Coding the E extender affects the value returned by the built-in functions %ERROR and %STATUS for exceptions. Before the operation begins, the value returned by these built-in functions is set to zero. If an exception occurs on the operation, the return values for these built-in functions are updated accordingly, the appropriate data structure (PSDS or INFDS) is updated, and control returns to the next sequential instruction. You can then use these built-in functions to test the returned values and determine what action to take.
Table 16. Operation Codes Allowing Extender E or an Error Indicator in Positions 73-74 ACQ (e) CALLB(d e) CHECKR (e) DELETE (e) FEOD (e) OPEN (e) READC (e) REALLOC (e) SCAN (e) SUBST (e p) WRITE (e) Notes: 1. CALLP (e m/r) is an extended Factor-2 operation code and cannot have an error indictator. However, program status and error conditions can be determined by specifying the e extender with this operation code. ADDDUR (e) CALLP (e m/r) CLOSE (e) DSPLY (e) IN (e) OUT (e) READE (e n) REL (e) SETGT (e) TEST (e d/t/z) XLATE (e p)
1
ALLOC (e) CHAIN (e n) COMMIT (e) EXFMT (e) NEXT (e) POST (e) READP (e n) RESET (e) SETLL (e) UNLOCK (e)
CALL (e) CHECK (e) DEALLOC(e/n) EXTRCT (e) OCCUR (e) READ (e n) READPE (e n) ROLBK (e) SUBDUR (e) UPDATE (e)
When you specify an error indicator or an E extender on an operation code, you can explicitly call a file error subroutine (INFSR) or a program error subroutine (*PSSR) with the EXSR operation. If either INFSR or *PSSR is explicitly called by the EXSR operation and Factor 2 of the ENDSR operation is blank or the field specified has a value of blank, control returns to the next sequential instruction following the EXSR operation. | | | | | | | | |
245
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
If a MONITOR group is nested within another MONITOR group, the innermost group is considered first when an error occurs. If that MONITOR group does not handle the error condition, the next group is considered. Level indicators can be used on the MONITOR operation, to indicate that the MONITOR group is part of total calculations. For documentation purposes, you can also specify a level indicator on an ON-ERROR or ENDMON operation but this level indicator will be ignored. Conditioning indicators can be used on the MONITOR statement. If they are not satisfied, control passes immediately to the statement following the ENDMON statement of the MONITOR group. Conditioning indicators cannot be used on ON-ERROR operations individually. If a MONITOR block contains a call to a subprocedure, and the subprocedure has an error, the subprocedures error handling will take precedence. For example, if the subprocedure has a *PSSR subroutine, it will get called. The MONITOR group containing the call will only be considered if the subprocedure fails to handle the error and the call fails with the error-in-call status of 00202. The MONITOR group does handle errors that occur in a subroutine. If the subroutine contains its own MONITOR groups, they are considered first. Branching operations are not allowed within a MONITOR block, but are allowed within an ON-ERROR block. A LEAVE or ITER operation within a MONITOR block applies to any active DO group that contains the MONITOR block. A LEAVESR or RETURN operation within a MONITOR block applies to any subroutine, subprocedure, or procedure that contains the MONITOR block. On each ON-ERROR statment, you specify which error conditions the ON-ERROR group handles. You can specify any combination of the following, separated by colons: nnnnn *PROGRAM *FILE *ALL A status code Handles all program-error status codes, from 00100 to 00999 Handles all file-error status codes, from 01000 to 09999 Handles both program-error and file-error codes, from 00100 to 09999. This is the default.
Status codes outside the range of 00100 to 09999, for example codes from 0 to 99, are not monitored for. You cannot specify these values for an ON-ERROR group. You also cannot specify any status codes that are not valid for the particular version of the compiler being used. If the same status code is covered by more than one ON-ERROR group, only the first one is used. For this reason, you should specify special values such as *ALL after the specific status codes. Any errors that occur within an ON-ERROR group are not handled by the MONITOR group. To handle errors, you can specify a MONITOR group within an ON-ERROR group.
246
C C C C C C C C C C C C C C C
* * * * * * * * * * * * *
The MONITOR block consists of the READ statement and the IF group. - The first ON-ERROR block handles status 1211 which is issued for the READ operation if the file is not open. - The second ON-ERROR block handles all other file errors. - The third ON-ERROR block handles the string-operation status code 00100 and array index status code 00121. - The fourth ON-ERROR block (which could have had a factor 2 of *ALL) handles errors not handled by the specific ON-ERROR operations. If no error occurs in the ENDIF to the ENDMON. MONITOR READ IF EVAL MONITOR block, control passes from the FILE1 NOT %EOF Line = %SUBST(Line(i) : %SCAN('***': Line(i)) + 1)
ENDIF ON-ERROR 1211 ... handle file-not-open ON-ERROR *FILE ... handle other file errors ON-ERROR 00100 : 00121 ... handle string error and array-index error ON-ERROR ... handle all other errors ENDMON
247
248
3. If an error occurs on the UPDATE operation, then control is passed to the INFSR error subroutine. 4. If the record is not found, then the product number is written to an error report.
*=================================================================* * TRNSUPDT: This program is a simple inventory update program. * * The transaction file (TRANSACT) is processed consecutively. * * The product number in the transaction is used as key to access * * the master file (PRDMAS) randomly. * * 1. If the record is found, the quantity of the inventory will * * be updated. * * 2. If the record is not found, an error will be printed on a * * report. * * 3. If the record is currently locked, the transaction will be * * written to a transaction back log file which will be * * processed later. * * 4. Any other unexpected error will cause a runtime error * * message. * *=================================================================* *-----------------------------------------------------------------* * Define the files: * * 1) PRDMAS - Product master file * * 2) TRANSACT - Transaction file * * 3) TRNBACKLG - Transaction backlog file * * 2) PRINT - Error report. * *-----------------------------------------------------------------* FPRDMAS UF E K DISK F INFSR(PrdInfsr) F INFDS(PrdInfds) FTRANSACT IP E DISK FTRNBACKLG O E DISK FPRINT O F 80 PRINTER *-----------------------------------------------------------------* * Define the file information data structure for file PRDMAS. * * The *STATUS field is used to determine what action to take. * *-----------------------------------------------------------------* D PrdInfds DS D PrdStatus *STATUS *-----------------------------------------------------------------* * List of expected exceptions. * *-----------------------------------------------------------------* D ErrRecLock C CONST(1218) Figure 128. Example of File Exception Handling (Part 1 of 2)
249
*-----------------------------------------------------------------* * Access the product master file using the transaction product * * number. * *-----------------------------------------------------------------* C TRNPRDNO CHAIN PRDREC 10 *-----------------------------------------------------------------* * If the record is found, update the quantity in the master file. * *-----------------------------------------------------------------* C IF NOT *IN10 C SUB TRNQTY PRDQTY C UPDATE PRDREC *-----------------------------------------------------------------* * If the record is not found, write to the error report * *-----------------------------------------------------------------* C ELSE C EXCEPT NOTFOUND C ENDIF C SETON LR *-----------------------------------------------------------------* * Error handling routine. * *-----------------------------------------------------------------* C PrdInfsr BEGSR *-----------------------------------------------------------------* * If the master record is currently locked, write the transaction * * record to the back log file and skip to next transaction. * *-----------------------------------------------------------------* C PrdStatus DSPLY C IF (PrdStatus = ErrRecLock) C WRITE TRNBREC C MOVE '*GETIN' ReturnPt 6 *-----------------------------------------------------------------* * If unexpected error occurs, cause inquiry message to be issued. * *-----------------------------------------------------------------* C ELSE C MOVE *BLANK ReturnPt C ENDIF C ENDSR ReturnPt *-----------------------------------------------------------------* * Error report format. * *-----------------------------------------------------------------* OPRINT E NOTFOUND O TRNPRDNO O 29 'NOT IN PRDMAS FILE' Figure 128. Example of File Exception Handling (Part 2 of 2)
When control is passed to the error subroutine, the following occurs: v If the error is due to a record lock, then the record is written to a backlog file and control returns to the main part with the next transaction (via *GETIN as the return point). v If the error is due to some other reason, then blanks are moved to ReturnPt. This will result in the RPG default handler receiving control. The recovery action at that point will depend on the nature of the error. Note that the check for a record lock error is done by matching the *STATUS subfield of the INFDS for PRDMAS against the field ErrRecLock which is defined with the value of the record lock status code. The INFSR could be extended to handle other types of I/O errors by defining other errors, checking for them, and then taking an appropriate action.
250
251
*-----------------------------------------------------------------* * Define relevant parts of program status data structure * *-----------------------------------------------------------------* D Psds SDS D Loc *ROUTINE D Err *STATUS D Parms *PARMS D Name *PROC *-----------------------------------------------------------------* * BODY OF CODE GOES HERE * An error occurs when division by zero takes place. * Control is passed to the *PSSR subroutine. *-----------------------------------------------------------------* *=================================================================* * *PSSR: Error Subroutine for the main procedure. We check for a * division by zero error, by checking if the status is * 102. If it is, we add 1 to the divisor and continue * by moving *GETIN to ReturnPt. *=================================================================* C *PSSR BEGSR C IF Err = 102 C ADD 1 Divisor C MOVE '*GETIN' ReturnPt 6 *-----------------------------------------------------------------* * An unexpected error has occurred, and so we move * *CANCL to ReturnPt to end the procedure. *-----------------------------------------------------------------* C ELSE C MOVE '*CANCL' ReturnPt C ENDIF C ENDSR ReturnPt Figure 129. Example of *PSSR Subroutine in Main Procedure
The program-status data structure is defined on the Definition specifications. The predefined subfields *STATUS, *ROUTINE, *PARMS, and *PROGRAM are specified, and names are assigned to the subfields. The *PSSR error subroutine is coded on the calculation specifications. If a program error occurs, ILE RPG passes control to the *PSSR error subroutine. The subroutine checks to determine if the exception was caused by a divide operation in which the divisor is zero. If it was, 1 is added to the divisor (Divisor), and the literal *DETC is moved to the field ReturnPt, to indicate that the program should resume processing at the beginning of the detail calculations routine If the exception was not a divide by zero, the literal *CANCL is moved into the ReturnPt field, and the procedure ends. Figure 130 on page 253 and Figure 131 on page 253 show how you would code similar program error subroutines in a subprocedure. In one example, you code a GOTO and in the other you code a RETURN operation.
252
*-----------------------------------------------------------------* * Start of subprocedure definition *-----------------------------------------------------------------* P SubProc B D SubProc PI 5P 0 ... *-----------------------------------------------------------------* * Body of code goes here including recovery code. *-----------------------------------------------------------------* C TryAgain TAG C X DIV Divisor Result C Return Result *-----------------------------------------------------------------* * An error occurs when division by zero takes place. * Control is passed to the *PSSR subroutine. *-----------------------------------------------------------------* C *PSSR BEGSR *-----------------------------------------------------------------* * If this is a divide-by-zero error, add 1 to the divisor * and try again *-----------------------------------------------------------------* C IF Err = 102 C ADD 1 Divisor C GOTO TryAgain C ENDIF *-----------------------------------------------------------------* * If control reaches ENDSR, the procedure will fail *-----------------------------------------------------------------* C ENDSR P E Figure 130. Example of Subprocedure *PSSR Subroutine with GOTO
*-----------------------------------------------------------------* * Start of subprocedure definition *-----------------------------------------------------------------* P SubProc B D SubProc PI 5P 0 ... *-----------------------------------------------------------------* * Body of code goes here including division operation. *-----------------------------------------------------------------* C X DIV Divisor Result C Return Result *-----------------------------------------------------------------* * An error occurs when division by zero takes place. * Control is passed to the *PSSR subroutine. *-----------------------------------------------------------------* C *PSSR BEGSR *-----------------------------------------------------------------* * If this is a divide-by-zero error, return 0 from the subprocedure *-----------------------------------------------------------------* C IF Err = 102 C RETURN 0 C ENDIF *-----------------------------------------------------------------* * If control reaches ENDSR, the procedure will fail *-----------------------------------------------------------------* C ENDSR P E Figure 131. Example of Subprocedure *PSSR Subroutine with RETURN
253
To create the program and start debugging it, using the source in Figure 132, type:
CRTBNDRPG PGM(MYLIB/NOLOOP) DBGVIEW(*SOURCE) STRDBG PGM(MYLIB/NOLOOP)
Set a break point on the BEGSR line of the *PSSR subroutine so you can step through the *PSSR subroutine.
254
When you call the program, the following occurs: 1. An exception occurs when the program tries to do a MOVE operation on an array using a negative index. Control is passed to the *PSSR. 2. Since this is the first time through the *PSSR, the variable In_Pssr is not already set on. To prevent a future loop, the variable In_Pssr is set on. 3. Processing continues within the *PSSR with the MOVE after the ELSE. Again, an exception occurs and so processing of the *PSSR begins anew. 4. This time through, the variable In_Pssr is already set to 1. Since this indicates that the subroutine is in a loop, the procedure is canceled by setting the ReturnPt field to *CANCL. 5. The ENDSR operation receives control, and the procedure is canceled. The approach used here to avoid looping can also be used within an INFSR error subroutine.
After the ENDSR operation of the INFSR or the *PSSR subroutine is run, the ILE RPG compiler resets the field or array element specified in Factor 2 to blanks. Because Factor 2 is set to blanks, you can specify the return point within the subroutine that is best suited for the exception that occurred. If this field contains blanks at the end of the subroutine, the ILE RPG default exception handler receives control following the running of the subroutine, unless the INFSR or the *PSSR subroutine was called by the EXSR operation. If the subroutine was called by the EXSR operation and Factor 2 of the ENDSR operation is blank, control returns to the next sequential instruction following the EXSR operation.
255
Note: You cannot specify a factor 2 entry for an ENDSR in a subprocedure. If you want to resume processing in the subprocedure, you have to use a GOTO operation to a TAG in the body of the subprocedure. Alternatively, you can code a RETURN operation in the *PSSR. The subprocedure will then return to the caller.
The example consists of two procedures: v RPGHDLR, which consists of a user-written condition handler for out-of-bound substring errors v SHOWERR, which tests the RPGHDLR procedure. While SHOWERR is designed primarily to show how RPGHDLR works, the two procedures combined are also useful for determining how ILE exception handling works. Both procedures write to QSYSPRT the actions which occur as they are processed. You might want to modify these procedures in order to simulate other aspects of ILE exception handling which you would like to explore.
256
*-----------------------------------------------------------------* * Procedure parameters * * 1. Input: Condition token structure * * 2. Input: Pointer to communication area containing * * a. A pointer to the PSDS of the procedure being handled * * b. An indicator telling whether a string error is valid * * 3. Output: Code identifying actions to be performed on the * * exception * * 4. Output: New condition if we decide to promote the * * condition. Since this handler only resumes and * * percolates, we will ignore this parameter. * *-----------------------------------------------------------------* D RPGHDLR PI D InCondTok LIKE(CondTok) D pCommArea * D Action 10I 0 D OutCondTok LIKE(CondTok) Figure 133. Source for Condition Handler for Out-of-Bounds Substring Error (Part 1 of 2)
257
DS
BASED(pCommArea)
DS
BASED(pPSDS)
10 20
*-----------------------------------------------------------------* * Point to the input condition token * *-----------------------------------------------------------------* C EVAL pCondTok = %ADDR(InCondTok) *-----------------------------------------------------------------* * If substring error, then handle else percolate. * * Note that the message number value (MsgNo) is in hex. * *-----------------------------------------------------------------* C EXCEPT C IF MsgPrefix = 'RNX' AND C MsgNo = X'0100' AND C AllowError = '1' C EXCEPT Handling C EVAL Action = Resume C ELSE C EXCEPT Perclating C EVAL Action = Percolate C ENDIF C RETURN *=================================================================* * Procedure Output * *=================================================================* OQSYSPRT E O 'HDLR: In Handler for ' O ProcName OQSYSPRT E Handling O 'HDLR: Handling...' OQSYSPRT E Perclating O 'HDLR: Percolating...' Figure 133. Source for Condition Handler for Out-of-Bounds Substring Error (Part 2 of 2)
Figure 134 on page 260 shows the source for the procedure SHOWERR, in which the condition handler RPGHDLR is registered. The procedure parameters include a procedure pointer to RPGHDLR and a pointer to the communication area which contains a pointer to the modules PSDS and an indicator telling whether the out-of-bounds string error can be ignored. In addition, it requires a definition for the error-prone array ARR1, and identification of the parameter lists used by the ILE bindable APIs CEEHDLR and CEEHDLU. The basic logic of the program is as follows:
258
259
260
261
If you want to try these procedures, follow these steps: 1. To create the procedure RPGHDLR, using the source shown in Figure 133 on page 257, type:
CRTRPGMOD MODULE(MYLIB/RPGHDLR)
2. To create the procedure SHOWERR, using the source shown in Figure 134 on page 260, type:
CRTRPGMOD MODULE(MYLIB/SHOWERR)
262
Information Center at this Web site http://www.ibm.com/eserver/iseries/infocenter. Figure 135 shows an example of enabling and coding a cancel handler for a subprocedure. (Cancel handlers can also be enabled for main procedures in the same way.)
*----------------------------------------------------------------* Define the prototype for the cancel handler. This procedure is * a local procedure. *----------------------------------------------------------------D CanHdlr PR D pMsg * *----------------------------------------------------------------* Define the prototype for a subprocedure to enable the cancel * handler. *----------------------------------------------------------------D Enabler PR *----------------------------------------------------------------* Define the prototype for a subprocedure to call Enabler *----------------------------------------------------------------D SubProc PR *----------------------------------------------------------------* Main procedure. Call SubProc three times. *----------------------------------------------------------------C CALLP SubProc C CALLP SubProc C CALLP SubProc C SETON LR *----------------------------------------------------------------* Procedure SubProc. Call Enabler. Since this call will fail, * define a local *PSSR subroutine to handle the error. *----------------------------------------------------------------P SubProc B C CALLP Enabler *----------------------------------------------------------------* The PSSR has a RETURN operation, so the call from the main * procedure to SubProc will not fail. *----------------------------------------------------------------C *PSSR BEGSR C 'Subproc PSSR'DSPLY C RETURN C ENDSR P SubProc E Figure 135. Enabling and Coding a Cancel Handler for a Subprocedure (Part 1 of 3)
263
*----------------------------------------------------------------* Procedure Enabler. This procedure enables a cancel handler, * then gets an error which causes Enabler to be canceled. *----------------------------------------------------------------P Enabler B * Local variables D Handler S * PROCPTR INZ(%PADDR('CANHDLR')) D Msg S 20A D pMsg S * INZ(%ADDR(Msg)) D Zero S 5P 0 INZ(0) D Count S 5I 0 INZ(0) STATIC D Array S 1A DIM(2) *----------------------------------------------------------------* Enable the cancel handler. When this procedure gets canceled, * procedure 'CANHDLR' will be called. *----------------------------------------------------------------C CALLB 'CEERTX' C PARM Handler C PARM pMsg C PARM *OMIT *----------------------------------------------------------------* This procedure will be called three times. The first two times * will get an error while the cancel handler is enabled. *----------------------------------------------------------------C EVAL Count = Count + 1 C SELECT C WHEN Count = 1 C EVAL Msg = 'Divide by zero' C EVAL Zero = Zero / Zero C WHEN Count = 2 C EVAL Msg = 'String error' C 'A' SCAN 'ABC':Zero Zero *----------------------------------------------------------------* On the third call, disable the cancel handler. The array index * error will cause the procedure to fail, but the handler will * not be invoked. *----------------------------------------------------------------C WHEN Count = 3 C CALLB 'CEEUTX' C PARM Handler C PARM *OMIT C EVAL Msg = 'Array index error' C EVAL Array(Zero) = 'x' C ENDSL P Enabler E Figure 135. Enabling and Coding a Cancel Handler for a Subprocedure (Part 2 of 3)
264
*----------------------------------------------------------------* Define the cancel handler. The parameter is a pointer to the * 'communication area', a message to be displayed. *----------------------------------------------------------------P CanHdlr B D CanHdlr PI D pMsg * *----------------------------------------------------------------* Define a field based on the input pointer pMsg. *----------------------------------------------------------------D Msg S 20A BASED(pMsg) *----------------------------------------------------------------* Display the message set by the procedure that enabled the * handler. *----------------------------------------------------------------C 'Cancel Hdlr 'DSPLY Msg P CanHdlr E Figure 135. Enabling and Coding a Cancel Handler for a Subprocedure (Part 3 of 3)
The following is the output from program CANHDLR. Note that the *PSSR of the procedure SubProc is called three times but the cancel handler is only called twice because it was disabled before the third error.
DSPLY DSPLY DSPLY DSPLY DSPLY Cancel Hdlr Subproc PSSR Cancel Hdlr Subproc PSSR Subproc PSSR Divide by zero String error
265
1. Ensure that the caller is in a different activation group from the ILE RPG procedure. 2. Enable an ILE condition handler in the RPG procedure. In the handler, if the message is one that you want to ignore, indicate that the message should be handled. Otherwise, indicate that it should be percolated. You could also make this handler more generic, and have it ignore all messages with a severity of 0 (information) and 1 (warning). Figure 137 shows an example of a ILE condition handler that ignores CPF4906.
*---------------------------------------------------------------* Handler definitions *---------------------------------------------------------------D Action S 10I 0 D Token DS D MsgSev 5I 0 D MsgNo 2A D 1A D Prefix 3A D 4A *---------------------------------------------------------------* Actions *---------------------------------------------------------------D Handle C 10 D Percolate C 20 *---------------------------------------------------------------* Severities *---------------------------------------------------------------D Info C 0 D Warning C 1 D Error C 2 D Severe C 3 D Critical C 4 C *ENTRY PLIST C PARM Token C PARM dummy 1 C PARM Action *---------------------------------------------------------------* If this is CPF4906, handle the notify msg, otherwise percolate *---------------------------------------------------------------C IF Prefix = 'CPF' AND C MsgNo = X'4906' C EVAL Action = Handle C ELSE C EVAL Action = Percolate C ENDIF C RETURN Figure 137. ILE Condition Handler that Ignores CPF4906
Figure 138 on page 267 shows how you would code the calculations if you wanted to ignore all status and notify messages. Escape messages and function checks have a severity of 2 (Error) or higher.
266
*---------------------------------------------------------------* Handle information or warning messages, otherwise percolate *---------------------------------------------------------------C IF MsgSev <= Warning C EVAL Action = Handle C ELSE C EVAL Action = Percolate C ENDIF C RETURN Figure 138. How to Ignore Status and Notify Messages
267
268
269
Program Status Area: Procedure Name . . . . . . . . . . . . : Program Name . . . . . . . . . . . . . : Library . . . . . . . . . . . . . . . . . : Module Name . . . . . . . . . . . . . . : Program Status . . . . . . . . . . . . . : Previous Status . . . . . . . . . . . . . : Statement in Error . . . . . . . . . . . . : RPG Routine . . . . . . . . . . . . . . : Number of Parameters . . . . . . . . . : Message Type . . . . . . . . . . . . . : Additional Message Info . . . . . . . . : Message Data . . . . . . . . . . . . . : Program signature violation. Status that caused RNX9001 . . . . . . : Last File Used . . . . . . . . . . . . . : Last File Status . . . . . . . . . . . . . : Last File Operation . . . . . . . . . . . : Last File Routine . . . . . . . . . . . . : Last File Statement . . . . . . . . . . . : Last File Record Name . . . . . . . . . : Job Name . . . . . . . . . . . . . . . . : User Name . . . . . . . . . . . . . . . : Job Number . . . . . . . . . . . . . . . : Date Entered System . . . . . . . . . . : Date Started . . . . . . . . . . . . . . . : Time Started . . . . . . . . . . . . . . . : Compile Date . . . . . . . . . . . . . . : Compile Time . . . . . . . . . . . . . . : Compiler Level . . . . . . . . . . . . . : Source File . . . . . . . . . . . . . . . : Library . . . . . . . . . . . . . . . . . : Member . . . . . . . . . . . . . . . . . :
DBGEX2 TEST MYLIB DBGEX2 .. . 00202 ..... 00000 ...... 00000088 RPGPGM MCH 4431
A B C D E F
......
MYUSERID MYUSERID .. 002273 . . 09/30/1995 *N/A* *N/A* . 123095 153438 ... 0001 QRPGLESRC MYLIB DBGEX2
Procedure Identification: the procedure name, the program and library name, and the module name.
270
Feedback Areas
271
SP QSYSPRT QSYS Q501383525 Q04079N002 QSPL 7 80 0 80 PRINTER 66 132 *N/A* 1 60 0 NO NO NO 1 NO NO Q04079N002 0 NO 1 1 *N *N '02'X '08'X 0 0 0 0 '00'X '0208'X *N 80 80 0 0 1 1 00 00 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000
00000000 00000000
* * *
* * *
This is the file feedback section of the INFDS. Only fields applicable to the file type are printed. The rest of the INFDS feedback sections are not dumped, since they are only updated if they have been declared in the program. This is the file open feedback information for the file. For a description of the fields, refer to the DB2 Universal Database for AS/400 section of the Database and File Systems category in the iSeries 400 Information Center at this Web site - http://www.ibm.com/eserver/iseries/infocenter. This is the common I/O feedback information for the file. For a description of the fields, see the above Web site.
272
Open Data Path: 0000 64800000 00001AF0 0020 00000530 00000000 0040 00008000 00000000 0060 80000000 00000000 0080 80000000 00000000 00A0 1F000000 00000000 00C0 40404040 4040D8F0 Open Feedback: 0000 E2D7D8E2 E8E2D7D9 0020 D8E2D7D3 40404040 0040 00500002 00000000 0060 00000000 00000000 0080 00000000 00001300 00A0 07100000 00000000 00C0 00450045 00450045 00E0 20000000 00000000 0100 00000000 00000000 Common I/O Feedback: 0000 00900000 00000000 0020 5CD54040 40404040 0040 00000000 00000000 0060 00000000 00000000 0080 00000000 00000000 I/O Feedback for Device: 0000 00010000 00010000 0020 0000F0F0 0001
00001B00 00000000 003AC02B 003AC005 003AA024 00000000 F4F0F7F9 E3404040 40400007 42008400 00000100 00000000 00450045 002F0030 00000000 00000000 00000000 40400000 00000000 00000000 00000000 00000000
000000B0 00000380 A00119FF CF001CB0 D0060120 00000000 D5F0F0F2 D8E2E8E2 00500000 00000000 3C000000 00000000 00450045 00040005 00000000 00000000 00000000 00500000 00000000 00000000 00000000 00000000
00000140 00000000 000006C0 00000000 01900000 E2D7D8E2 40404040 D8F5F0F1 0000D5A4 0005E000 00010001 07A10045 5CD54040 00000000 00000000 00000000 00000000 00000000 00000000 00000000
000001C6 06000000 00003033 00000000 00010000 E8E2D7D9 4040D8F0 F3F8F3F5 00100000 5CD54040 5CD54040 00450045 40404040 00000001 4040 00000000 00000000 00000000 00000000 00000000
00000280 00000000 00000000 00000000 00000050 E3404040 F4F0F7F9 F2F50000 00000008 40404040 40404040 00700045 40400208 C2200000 00000000 00000000 00000000 00000000 00000000
000002C0 00000000 00000000 00000000 00000000 D8E2E8E2 D5F0F0F2 00000000 00000000 40400001 40400000 00450045 00000000 00059A00 00000208 00000000 00000000 00000000 00000000
* * * * * * *
*SPQSYSPRT QSYS Q04079N002* *QSPL & Q501383525 * * & d Nu * * *N * * *N * * * * *N * * B * * * * **N * * * * * 0000 & * * * * * * *
The common open data path and the feedback areas associated with the file are included in the dump if you respond to an ILE RPG inquiry message with an F option. Data Information
273
L H7 '0'
M H8 '0' H9 '0' KH '0' KS '0' L8 '0' OV '0' U8 '0' 08 18 28 38 48 58 68 78 88 98 '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' 09 19 29 39 49 59 69 79 89 99 '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' 10 20 30 40 50 60 70 80 90 '0' '0' '0' '0' '0' '0' '0' '0' '0' KI '0' KT '0' L9 '0' KJ '0' KU '0'
KE '0' KP '0' L5 '0' OE '0' U5 '0' 05 15 25 35 45 55 65 75 85 95 '0' '0' '0' '0' '0' '0' '0' '0' '0' '0'
KF '0' KQ '0' L6 '0' OF '0' U6 '0' 06 16 26 36 46 56 66 76 86 96 '1' '0' '0' '0' '0' '0' '0' '0' '0' '0'
KG '0' KR '0' L7 '0' OG '0' U7 '0' 07 17 27 37 47 57 67 77 87 97 '0' '0' '0' '0' '0' '0' '0' '0' '0' '0'
VALUE 1 '00000001'X O 2 '00000002'X DIM(8) P '1' 'F1'X '0' 'F0'X '1' 'F1'X '0' 'F0'X '1' 'F1'X '0' 'F0'X '1' 'F1'X 1 '00000001'X Q DIM(8) 'AB' 'C1C2'X ' ' '4040'X '1' 'F1'X DIM(2) 1.24 'F1F2F4'X NOT ADDRESSABLE SPP:E30095A62F001208 'ABCDEF' 'C1C2C3C4C5C6'X '1994-09-30' 'F1F9F9F460F0F960F3F0'X '12.00.00' 'F1F24BF0F04BF0F0'X '9999-12-31-12.00.00.000000' 'F9F9F9F960F1F260F3F160F1F24BF0F04BF0F04BF0F0F0F0F0F0'X -4.321 'EF1F'X 98.7654321 '3ADE68B1'X ' BBCCDD ' 'C2C2C3C3C4C4'X
274
CHAR(5) CHAR(1) (1) (2) (3) (4) (5) FLD2 BIN(5,2) DS2 CHAR(1O) (1) (2) DS3 DS FIRSTNAME CHAR(10) LASTNAME CHAR(10) TITLE CHAR(5) EXPORTFLD CHAR(6) FLDNULL ZONED(3,1) FLOAT1 FLT(4) VALUE IN HEX FLOAT2 FLT(8) VALUE IN HEX INT10 INT(10) INT5 INT(5) NEG_INF FLT(8) VALUE IN HEX NOT_NUM FLT(4) VALUE IN HEX NULLPTR POINTER PACKED1D0 PACKED(5,2) PARM1 PACKED(4,3) POS_INF FLT(8) VALUE IN HEX PROCPTR POINTER SPCPTR POINTER SPCSIZ BIN(9,0) STRING CHAR(6) TABLEA CHAR(3) (1) (2) (3) UNSIGNED10 UNS(10) UNSIGNED5 UNS(5) ZONEDD3D2 ZONED(3,2) Local variables for subprocedure SWITCH: NAME ATTRIBUTES _QRNL_PSTR_PARM POINTER LOCAL CHAR(5) PARM CHAR(1) * * * * * E N D O F R P
'ABCDE' 'C1C2C3C4C5'X DIM(5) 'A' 'C1'X 'B' 'C2'X 'C' 'C3'X 'D' 'C4'X 'E' 'C5'X 123.45 '00003039'X DIM(2) S 'aaaaaaaaaa' '81818181818181818181'X 'bbbbbbbbbb' '82828282828282828282'X T 'Fred ' 'C6998584404040404040'X 'Jones ' 'D1969585A24040404040'X 'Mr. ' 'D4994B4040'X 'export' '85A7979699A3'X 24.3 'F2F4F3'X 1.234500000000E+007 U '4B3C5EA8'X 3.962745000000E+047 '49D15A640A93FCFF'X -31904 'FFFF8360'X -2046 'F802'X -HUGE_VAL V 'FFF0000000000000'X *NaN W '7FFFFFFF'X SYP:*NULL -093.40 '09340D'X 6.666 '06666F'X HUGE_VAL X '7FF0000000000000'X PRP:A00CA02EC200 Y SPP:A026FA0100C0 000000008. '00000008'X 'ABCDEF' 'C1C2C3C4C5C6'X DIM(3) 'aaa' '818181'X 'bbb' '828282'X 'ccc' '838383'X 31904 '00007CA0'X 2046 '07FE'X -3.21 'F3F2D1'X Z VALUE SYP:*NULL ' ' '0000000000'X NOT ADDRESSABLE G D U M P * * * * *
L M N
Optimization level General indicators 1-99 and their current status (1 is on, 0 is off). Note that indicators *IN02, *IN04, and *IN06 were not yet set. Beginning of user variables, listed in alphabetical order, and grouped by procedure. Data that is local to a subprocedure is stored in automatic storage and is not available unless the subprocedure is active. Note that the hexadecimal values of all variables are displayed. :nt Names longer than 131 characters, will appear in the dump listing split across multiple lines. The entire name will be printed with the characters ... at the end of
275
276
277
278
279
Note that it is the file name, not the device name (specified in positions 36 through 42) which points to the OS/400 file description that contains the specifications for the actual device. The RPG device types correspond to the above file types as follows:
Table 17. Correlation of RPG Device Types with iSeries File Types RPG Device Type DISK PRINTER WORKSTN SEQ SPECIAL iSeries File Type database, save, DDM files printer files display, ICF files tape, diskette, save, printer, database N/A
Figure 144 illustrates the association of the RPG file name FILEX, as coded in Figure 143, with a system file description for a display file.
At compilation time, certain RPG operations are valid only for a specific RPG device name. In this respect, the RPG operation is device dependent. One example of device dependency is that the EXFMT operation code is valid only for a WORKSTN device. Other operation codes are device independent, meaning that they can be used with any device type. For example, WRITE is a device-independent operation. The SEQ Device The device SEQ is an independent device type. Figure 145 on page 281 illustrates the association of the RPG file name FILEY with a system file description for a sequential device. When the program is run, the actual I/O device is specified in the description of FILEY. For example, the device might be PRINTER.
280
Although the file name and file type are coded in the RPG program, in many cases you can change the type of file or the device used in a program without changing the program. To find out how, see Overriding and Redirecting File Input and Output on page 291.
Naming Files
On the iSeries system, files are made up of members. These files are organized into libraries. The convention for naming files is library-name/file-name. In an ILE RPG program, file names are identified in positions 7 through 16 in file description specifications. File names can be up to ten characters long and must be unique. You do not qualify the file name with a library within a program. At run time, the system searches the library list associated with your job to find the file. If you wish to change the name, member, or specify a particular library, you can use a file override command. See Overriding and Redirecting File Input and Output on page 291 for more information on file overrides.
281
RPG Program-Described File (F in position 22) - The compiler does not copy in field-level description
Figure 146. Typical Relationships between an RPG Program and Files on the iSeries System
The program uses the field-level description of a file that is defined to the operating system. An externally described file is identified by an E in position 22 of the file description specifications. At compilation time, the compiler copies in the external field-level description. An externally described file (that is, a file with field-level external description) is used as a program-described file in the program. A
282
283
The RENAME keyword is generally used if the program contains two files which have the same record-format names. In Figure 147, the record format ITEMFORMAT in the externally described file ITMMSTL is renamed MSTITM for use in this program.
284
285
To assign a record-identifying indicator to a record in an externally described file, specify the record-format name in positions 7 through 16 of the input specifications and assign a valid record-identifying indicator in positions 21 and 22. A typical use of input specifications with externally described files is to assign record-identifying indicators. In this example, record-identifying indicator 01 is assigned to the record MSTRITEM and indicator 02 to the record MSTRWHSE.
To rename a field in an externally described record, specify the external name of the field, left-adjusted, in positions 21 through 30 of the field-description line. In positions 49 through 62, specify the name that is to be used in the program. In this example, the field ITEMNUMB in both records is renamed ITEM for this program.
To assign a control-level indicator to a field in an externally described record, specify the name of the field in positions 49 through 62 and specify a control-level indicator in positions 63 and 64. In this example, the ITEM field in both records MSTRITEM and MSTRWHSE is specified to be the L1 control field.
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... * IFilename++SqNORiPos1+NCCPos2+NCCPos3+NCC.................................. IMSTREC 01 1 I..............Ext-field+..................Field+++++++++L1M1..PlMnZr...... I CUSTNO M1 1 * IWKREC 02 I CUSTNO M1 I BALDUE 98 2 * Figure 151. Adding RPG Functions to an External Description
To assign a match value to a field in an externally described record, specify the record-format name in positions 7 through 16 of the record-identification line. On the field-description line specify the name of the field in positions 49 through 62 and assign a match-level value in positions 65 and 66. In this example, the CUSTNO field in both records MSTREC and WKREC is assigned the match-level value M1.
To assign a field indicator to a field in an externally described record, specify the record-format name in positions 7 through 16 of the
286
287
For an update file, all fields in the record are written to the externally described record ITMREC using the current values in the program for all fields in the record. For the creation of a new record, all fields in the record are written to the externally described record ITMREC using the current values in the program for the fields in the record.
To update a record, the fields SLSNAM and COMRAT are written to the externally described record SLSREC when indicator 30 is on. The field BONUS is written to the SLSREC record when indicators 30 and 15 are on. All other fields in the record are written with the values that were read. To create a new record, the fields SLSNAM and COMRAT are written to the externally described record SLSREC when indicator 30 is on. The field BONUS is written when indicators 30 and 15 are on. All other fields in the record are written as default values, which depend on their data type (for example: a blank for character fields; zero for numeric fields).
Level Checking
HLL programs are dependent on receiving, at run time, an externally described file whose format agrees with what was copied into the program at compilation time. For this reason, the system provides a level-check function that ensures that the format is the same. The RPG compiler always provides the information required by level checking when an externally described DISK, WORKSTN, or PRINTER file is used. The level-check function can be requested on the create, change, and override file commands. The default on the create file command is to request level checking. Level checking occurs on a record-format basis when the file is opened unless you specify LVLCHK(*NO) when you issue a file override command or create a file. If the level-check values do not match, the program is notified of the error. The RPG program then handles the OPEN error as described in Chapter 13. Handling Exceptions on page 235. The RPG program does not provide level checking for program-described files or for files using the devices SEQ or SPECIAL. For more information on how to specify level checking, refer to the DB2 Universal Database for AS/400 section of the Database and File Systems category in the iSeries 400 Information Center at this Web site http://www.ibm.com/eserver/iseries/infocenter.
288
READ, CHAIN READ, READE, CHAIN, primary and secondary file READ READP, READPE READ, READE READ EXFMT
289
UPDATE, primary and secondary file UPDATE, primary and secondary file
DELETE, primary and secondary file DELETE, primary and secondary file
290
FILEY Compile Time RPG program File name = FILEY Device = DISK Override Command: OVRDBF FILE (FILEY) TOFILE (FILEA) FILEA Execution Time File type = DEVICE Device type = DISKETTE Diskette File type = PHYSICAL
In the preceding example, the CL command OVRDBF (Override With Database File) allows the program to run with an entirely different device file than was specified at compilation time. To override a file at run time, you must make sure that record names in both files are the same. The RPG program uses the record-format name on the input/output operations, such as a READ operation where it specifies what record type is expected. Not all file redirections or overrides are valid. At run time, checking ensures that the specifications within the RPG program are valid for the file being processed. The OS/400 system allows some file redirections even if device specifics are contained in the program. For example, if the RPG device name is PRINTER, and
Copyright IBM Corp. 1994, 2001
291
292
FMT1
RPG program File name = QTAPE Format = E Device = SEQ Execution Time: No Override QTAPE File type = DEVICE Device type = TAPE
File Locking
The OS/400 system allows a lock state (exclusive, exclusive allow read, shared for update, shared no update, or shared for read) to be placed on a file used during the execution of a job. Programs within a job are not affected by file lock states. A file lock state applies only when a program in another job tries to use the file concurrently. The file lock state can be allocated with the CL command ALCOBJ (Allocate Object). For more information on allocating resources and lock states, refer to the DB2 Universal Database for AS/400 section of the Database and File Systems category in the iSeries 400 Information Center at this Web site http://www.ibm.com/eserver/iseries/infocenter. The OS/400 system places the following lock states on database files when it opens the files:
File Type Input Update Add Output Lock State Shared for read Shared for update Shared for update Shared for update
The shared-for-read lock state allows another user to open the file with a lock state of shared for read, shared for update, shared no update, or exclusive allow read, but the user cannot specify the exclusive use of the file. The shared-for-update lock state allows another user to open the file with shared-for-read or shared-for-update lock state. The RPG program places an exclusive-allow-read lock state on device files. Another user can open the file with a shared-for-read lock state. The lock state placed on the file by the RPG program can be changed if you use the Allocate Object command.
293
Record Locking
Record Locking
When a record is read by a program, it is read in one of two modes: input or update. If a program reads a record for update, a lock is placed on that record. Another program cannot read the same record for update until the first program releases that lock. If a program reads a record for input, no lock is placed on the record. A record that is locked by one program can be read for input by another program. In RPG IV programs, you use an update file to read records for update. A record read from a file with a type other than update can be read for inquiry only. By default, any record that is read from an update file will be read for update. For update files, you can specify that a record be read for input by using one of the input operations CHAIN, READ, READE, READP, or READPE and specifying an operation code extender (N) in the operation code field following the operation code name. When a record is locked by an RPG IV program, that lock remains until one of the following occurs: v the record is updated. v the record is deleted. v another record is read from the file (either for inquiry or update). v a SETLL or SETGT operation is performed against the file v an UNLOCK operation is performed against the file. v an output operation defined by an output specification with no field names included is performed against the file. Note: An output operation that adds a record to a file does not result in a record lock being released. If your program reads a record for update and that record is locked through another program in your job or through another job, your read operation will wait until the record is unlocked (except in the case of shared files, see Sharing an Open Data Path on page 295). If the wait time exceeds that specified on the WAITRCD parameter of the file, an exception occurs. If your program does not handle this exception (RNX1218) then the default error handler is given control when a record lock timeout occurs, an RNQ1218 inquiry message will be issued. One of the options listed for this message is to retry the operation on which the timeout occurred. This will cause the operation on which the timeout occurred to be re-issued, allowing the program to continue as if the record lock timeout had not occurred. Note that if the file has an INFSR specified in which an I/O operation is performed on the file before the default error handler is given control, unexpected results can occur if the input operation that is retried is a sequential operation, since the file cursor may have been modified. Note: Subprocedures do not get inquiry message, and so this situation should be handled by using an error indicator on the read operation and checking for status 1218 following the read. If no changes are required to a locked record, you can release it from its locked state, without modifying the file cursor, by using the UNLOCK operation or by processing output operations defined by output specifications with no field names included. These output operations can be processed by EXCEPT output, detail output, or total output.
294
Record Locking
(There are exceptions to these rules when operating under commitment control. See Using Commitment Control on page 323 for more information.)
295
For additional information about sharing an open data path and activation group versus job level scope, see the ILE Concepts manual.
Spooling
Spooling is a system function that puts data into a storage area to wait for processing. The iSeries system provides for the use of input and output spooling functions. Each iSeries file description contains a spool attribute that determines whether spooling is used for the file at run time. The RPG program is not aware that spooling is being used. The actual physical device from which a file is read or to which a file is written is determined by the spool reader or the spool writer. For more detailed information on spooling, refer to the DB2 Universal Database for AS/400 section of the Database and File Systems category in the iSeries 400 Information Center at this Web site http://www.ibm.com/eserver/iseries/infocenter.
Output Spooling
Output spooling is valid for batch or interactive jobs. The description of the file that is specified in the RPG program by the file name contains the specification for spooling as shown in the following diagram:
296
Spooling
Spooled File
Execution Time
Device
File override commands can be used at run time to override the spooling options specified in the file description, such as the number of copies to be printed. In addition, iSeries spooling support allows you to redirect a file after the program has run. You can direct the same printed output to a different device such as a diskette.
297
SRTSEQ/ALTSEQ
298
Database Files
Database files are objects of type *FILE on the iSeries system. They can be either physical or logical files and either externally described or program-described. You access database files by associating the file name with the device DISK in positions 36 through 42 of the file description specifications. Database files can be created by OS/400 Create File commands. For more information on describing and creating database files, refer to the DB2 Universal Database for AS/400 section of the Database and File Systems category in the iSeries 400 Information Center at this Web site http://www.ibm.com/eserver/iseries/infocenter.
299
Database Files
you to better manage your programs. The source member contains source statements that the system uses to create program objects.
Access Path
The description of an externally described file contains the access path that describes how records are to be retrieved from the file. Records can be retrieved based on an arrival sequence (non-keyed) access path or on a keyed-sequence access path. The arrival sequence access path is based on the order in which the records are stored in the file. Records are added to the file one after another. For the keyed-sequence access path, the sequence of records in the file is based on the contents of the key field that is defined in the DDS for the file. For example, in the DDS shown in Figure 156 on page 301, CUST is defined as the key field. The keyed-sequence access path is updated whenever records are added, deleted, or when the contents of a key field change.
300
contains one record format CUSREC (customer master record). The data for this file is contained in the physical file CUSMSTP, which is identified by the keyword PFILE. The UNIQUE keyword is used to indicate that duplicate key values are not allowed for this file. The CUST field is identified by a K in position 17 of the last line as the key field for this record format. The fields in this record format are listed in the order they are to appear in the record. The attributes for the fields are obtained from the physical file CUSMSTP. The physical file, in turn, refers to a field-reference file to obtain the attributes for the fields. The field-reference file is shown in Figure 157 on page 302.
301
This example of a field-reference file shows the definitions of the fields that are used by the CUSMSTL (customer master logical) file as shown in Figure 156 on page 301. The field-reference file normally contains the definitions of fields that are used by other files. The following text describes some of the entries for this field-reference file. 1 The BASDAT field is edited by the Y edit code, as indicated by the keyword EDTCDE(Y). If this field is used in an externally described output file for an ILE RPG program, the edit code used is the one specified in this field-reference file; it cannot be overridden in the ILE RPG program. If the field is used in a program-described output file for an ILE RPG program, an edit code must be specified for the field in the output specifications. The CHECK(MF) entry specifies that the field is a mandatory fill field
302
5 6 7
303
The search argument can only be a single field with attributes identical to field A because field A is the only key field common to all record types. The search argument cannot contain a floating point, variable length, or null-capable field. For an operation to a record name, the maximum number of fields that you can specify in a search argument is equal to the total number of key fields valid for that record type. If the search argument consists of one field, you can specify a literal, a field name, or a KLIST name with one KFLD. If the search argument is composed of more than one field (a composite key), you must specify a KLIST with multiple KFLDs. To process null-valued keys a KLIST must be used. The attributes of each field in the search argument must be identical to the attributes of the corresponding field in the file or record key. The attributes include the length, the data type and the number of decimal positions. The attributes are listed in the key-field-information data table of the compiler listing. See the example in Key Field Information on page 457. In all these file operations (CHAIN, DELETE, READE, READPE, SETGT, and SETLL), you can also specify a search argument that contains fewer than the total number of fields valid for the file or record. Such a search argument refers to a partial key.
304
305
Indexed File
An indexed file is a program-described DISK file whose access path is built on key values. You must create the access path for an indexed file by using data description specifications. An indexed file is identified by an I in position 35 of the file description specifications. The key fields identify the records in an indexed file. You specify the length of the key field in positions 29 through 33, the format of the key field in position 34, and the starting location of the key field in the KEYLOC keyword of the file description specifications. An indexed file can be processed sequentially by key, sequentially within limits, or randomly by key.
306
You must use data description specifications to create the access path for a program-described indexed file. In the DDS for the record format FORMATA for the logical file ORDDTLL, the field ORDER, which is five digits long, is defined as the key field, and is in packed format. The definition of ORDER as the key field establishes the keyed access for this file. Two other fields, FLDA and FLDB, describe the remaining positions in this record as character fields. The program-described input file ORDDTLL is described on the file description specifications as an indexed file. Positions 29 through 33 must specify the number of positions in the record required for the key field as defined in the DDS: three positions. The KEYLOC keyword specifies position 15 as the starting position of the key field in the record. Because the file is defined as program-described by the F in position 22, the ILE RPG compiler does not retrieve the external field-level description of the file at compilation time. Therefore, you must describe the fields in the record on the input specifications.
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ..* A..........T.Name++++++.Len++TDpB......Functions++++++++++++++++++++* A R FORMAT PFILE(ORDDTLP) A TEXT('Access Path for Indexed + A File') A FLDA 14 A ORDER 5 A ITEM 5 A FLDB 96 A K ORDER A K ITEM Figure 159. (Part 1 of 2). Using Data Description Specifications to Define the Access Path (Composite Key) for an Indexed File
In this example, the data description specifications define two key fields for the record format FORMAT in the logical file ORDDTLL. For the two fields to be used as a composite key for a program described indexed file, the key fields must be contiguous in the record. On the file description specifications, the length of the key field is defined as 10 in positions 29 through 33 (the combined number of positions required for the ORDER and ITEM fields). The starting position of the key field is described as 15
Chapter 17. Accessing Database Files
307
When the DDS specifies a composite key, you must build a search argument in the program to CHAIN to the file. (A KLIST cannot be used for a program-described file.) One way is to create a data structure (using definition specifications) with subfields equal to the key fields defined in the DDS. Then, in the calculations, set the subfields equal to the value of the key fields, and use the data-structure name as the search argument in the CHAIN operation. In this example, the MOVE operations set the subfields K1 and K2 equal to the value of ORDER and ITEM, respectively. The data-structure name (KEY) is then used as the search argument in the CHAIN operation.
Sequential File
Sequential files are files where the order of the records in the file is based on the order the records are placed in the file (that is, in arrival sequence). For example, the tenth record placed in the file occupies the tenth record position. Sequential files can be processed randomly by relative record number, consecutively, or by a record-address file. You can use either the SETLL or SETGT operation code to set limits on the file.
Limits Records
For sequential-within-limits processing, the record-address file contains limits records. A limits record contains the lowest record key and the highest record key of the records in the file to be read.
308
309
Externally Described Files With Keys Sequentially Randomly Sequential within limits (by record-address file) Without Keys Randomly/consecutively Program Described Files With Keys (indexed file) Sequentially Randomly Sequential within limits (by record-address file) Without Keys Randomly/consecutively By record-address file As record-address file (relative record numbers) As record-address limits file Blank Blank Blank Blank Blank Blank Blank A, D, G, P, T, Z, F, or Blank Blank Blank T Blank Blank Blank L A, D, G, P, T, Z, or F A, D, G, P, T, Z, or F A, D, G, P, T, Z, or F I I I Blank Blank Blank Blank Blank L K K K Blank Blank Blank
Consecutive Processing
During consecutive processing, records are read in the order they appear in the file. For output and input files that do not use random functions (such as SETLL, SETGT, CHAIN, or ADD), the ILE RPG compiler defaults to or operates as though SEQONLY(*YES) had been specified on the CL command OVRDBF (Override with Database File). (The ILE RPG compiler does not operate as though SEQONLY(*YES) had been specified for update files.) SEQONLY(*YES) allows multiple records to be placed in internal data management buffers; the records are then passed to the ILE RPG compiler one at a time on input. If, in the same job or activation group, two logical files use the same physical file, and one file is processed consecutively and one is processed for random update, a record can be updated that has already been placed in the buffer that is presented to the program. In this case, when the record is processed from the consecutive
310
Sequential-by-Key Processing
For the sequential-by-key method of processing, records are read from the file in key sequence. The sequential-by-key method of processing is valid for keyed files used as primary, secondary, or full procedural files. For output files and for input files that do not use random functions (such as SETLL, SETGT, CHAIN, or ADD) and that have only one record format, the ILE RPG compiler defaults to or operates as though SEQONLY(*YES) had been specified on the CL command OVRDBF. (The ILE RPG compiler does not operate as though SEQONLY(*YES) had been specified for update files.) SEQONLY(*YES) allows multiple records to be placed in internal data management buffers; the records are then passed to the ILE RPG compiler one at a time on input. If, in the same job, two files use the same physical file, and one file is processed sequentially and one is processed for random update, a record could be updated that has already been placed in the buffer that is presented to the program. In this case, when the record is processed from the sequential file, the record does not reflect the updated data. To prevent this problem, use the CL command OVRDBF and specify the option SEQONLY(*NO), which indicates that you do not want multiple records transferred for a sequentially processed file. For more information on sequential only processing, refer to the DB2 Universal Database for AS/400 section of the Database and File Systems category in the iSeries 400 Information Center at this Web site http://publib.boulder.ibm.com/html/as400/infocenter.html.
311
A***************************************************************** A* DESCRIPTION: This is the DDS for the physical file TRWEEK. * A* It contains one record format called RCWEEK. * A* This file contains all weekly entries made to * A* the time reporting system. * A***************************************************************** A* A R RCWEEK A ENUM 5 0 TEXT('EMPLOYEE NUMBER') A WEEKNO 2 0 TEXT('WEEK NUMBER OF CURRENT YEAR') A EHWRK 4 1 TEXT('EMPLOYEE HOURS WORKED') A K ENUM A K WEEKNO Figure 162. DDS for database file TRWEEK (physical file) A***************************************************************** A* RELATED FILES: EMPMST (Physical File) * A* TRWEEK (Physical File) * A* DESCRIPTION: This is the DDS for the logical file EMPL1. * A* It contains two record formats called * A* EMPREC and RCWEEK. * A***************************************************************** A R EMPREC PFILE(EMPMST) A K ENUM A* A R RCWEEK PFILE(TRWEEK) A K ENUM A K WEEKNO Figure 163. DDS for database file EMPL1 (logical file)
EXAMPLE PROGRAM 1 (Sequential-by-Key Using Primary File): In this example, the employee master record (EMPREC) and the weekly hours worked record (RCWEEK) are contained in the same logical file EMPL1. The EMPL1 file is defined as a primary input file and is read sequentially by key. In the data description specifications for the file, the key for the EMPREC record is defined as the ENUM (employee number) field, and the key for the RCWEEK record is defined as the ENUM field plus the WEEKNO (week number) field, which is a composite key.
312
OPRINT O O O O O O O O O O O O O O O O O O
2 1 1
40 'EMPLOYEE WEEKLY WORKING ' 52 'HOURS REPORT' 12 'EMPLOYEE: ' 32 12 'SERIAL #: ' 17 27 'DEPT: ' 30 40 'TYPE: ' 41 20 'WEEK #' 50 'HOURS WORKED' 18 45
WEEKNO EHWRK
EXAMPLE PROGRAM 2 (Sequential-by-Key Using READ): This example is the same as the previous example except that the EMPL1 file is defined as a full-procedural file, and the reading of the file is done by the READ operation code.
313
99 01
5 0 12
Since EMPL1 is defined as a full-procedural file, indicator *INLR has to be seton to terminate the program after processing the last record. EOFEND 99 TAG SETON LR
314
WEEKNO EHWRK
EXAMPLE PROGRAM 3 (Matching-Record Technique): In this example, the TRWEEK file is defined as a secondary input file. The EMPREC and RCWEEK records are processed as matching records, with the ENUM field in both records assigned the match level value of M1. Record-identifying indicators 01 and 02 are assigned to the records to control the processing for the different record types.
***************************************************************** * PROGRAM NAME: YTDRPT5 * * RELATED FILES: EMPMST (Physical File) * * TRWEEK (Physical File) * * PRINT (Printer File) * * DESCRIPTION: This program shows an example of processing * * records using the matching record method. * * This program prints out each employee's * * information, weekly worked hours and amount * * of overtime. * ***************************************************************** FPRINT O F 80 PRINTER FEMPMST IP E K DISK FTRWEEK IS E K DISK IEMPREC 01 I ENUM M1 IRCWEEK 02 I ENUM M1 Figure 166. Sequential-by-Key Processing, Example 3 (Part 1 of 2)
315
TOTOVT
Random-by-Key Processing
For the random-by-key method of processing, a search argument that identifies the key of the record to be read is specified in factor 1 of the calculation specifications for the CHAIN operation. Figure 168 on page 318 shows an example of an externally described DISK file being processed randomly by key. The specified record can be read from the file either during detail calculations or during total calculations.
316
EXAMPLE PROGRAM: In this example, the EMPMST file is defined as an Update Full-Procedural file. The update file CHANGE is to be processed by keys. The DDS for each of the externally described files (EMPMST and CHANGE) identify the ENUM field as the key field. The read/update processes are all controlled by the operations specified in the Calculation Specifications.
317
Sequential-within-Limits Processing
Sequential-within-limits processing by a record-address file is specified by an L in position 28 of the file description specifications and is valid for a file with a keyed access. You can specify sequential-within-limits processing for an input or an update file that is designated as a primary, secondary, or full-procedural file. The file can be externally described or program-described (indexed). The file should have keys in ascending sequence. To process a file sequentially within limits from a record-address file, the program reads: v A limits record from the record-address file v Records from the file being processed within limits with keys greater than or equal to the low-record key and less than or equal to the high-record key in the limits record. If the two limits supplied by the record-address file are equal, only the records with the specified key are retrieved.
318
OPRINT O O O O O O O O O
01
319
This program performs the same job as the previous program. The only difference is that the physical file EMPMST is defined as an externally described file instead of a program-described file.
***************************************************************** * PROGRAM NAME: ESWLIM2 * * RELATED FILES: EMPMST (Physical File) * * LIMITS (Physical File) * * PRINT (Printer File) * * DESCRIPTION: This program shows the processing of an * * externally described file sequentially * * within limits. * * This program prints out information for the * * employees whose employee numbers are within * * the limits given in the file LIMITS. * ***************************************************************** FLIMITS IR F 6 3 DISK RAFDATA(EMPMST) FEMPMST IP E L K DISK FPRINT O F 80 PRINTER * Input Specifications are optional for an externally described * file. Here, *IN01 is defined as the record-identifying * indicator for the record-format EMPREC to control the * processing of this record. IEMPREC 01 OPRINT O O O O O O O O O O* H 1P 1 12 22 45 56 10 35 45 55 'SERIAL #' 'NAME' 'DEPT' 'TYPE'
01
Relative-Record-Number Processing
Random input or update processing by relative record number applies to full procedural files only. The desired record is accessed by the CHAIN operation code.
320
321
I U
F F
U O O
F Blank Blank
Notes: 1. An L must be specified in position 28 to specify sequential-within-limits processing by a record-address file for an input or an update file. 2. Externally described files require a K in position 34; program-described files require an A,P,G,D,T,Z, or F in position 34 and an I in position 35. 3. An A in position 20 is not required for the initial loading of records into a new file. If A is specified in position 20, ADD must be specified on the output specifications. The file must have been created with the OS/400 CREATE FILE command. Table 22. Valid File Operations for Non-keyed Processing Methods (Sequential, Random by Relative Record Number, and Consecutive) File-Description Specifications Positions 17 I I 18 P/S P/S 20 34 Blank Blank RECNO 44-80 Calculation Specifications Positions 26-35 CLOSE, FEOD, FORCE CLOSE, FEOD, FORCE
322
A/P/G/ D/T/Z/ F/ Blank1 Blank2 A Blank Blank Blank RECNO RECNO Blank
I O O O
OPEN, CLOSE, FEOD WRITE3 (add records to a file), OPEN, CLOSE, FEOD WRITE4 (initial load of a new file), OPEN, CLOSE, FEOD WRITE (sequentially load or extend a file), OPEN, CLOSE, FEOD
Notes: 1. If position 34 is blank for a record-address-limits file, the format of the keys in the record-address file is the same as the format of the keys in the file being processed. 2. A record-address file containing relative record numbers requires a T in position 35. 3. The RECNO field that contains the relative record number must be set prior to the WRITE operation or if ADD is specified on the output specifications. 4. An A in position 20 is not required for the initial loading of the records into a new file; however, if A is specified in position 20, ADD must be specified on output specifications. The file must have been created with one of the OS/400 file creation commands.
323
324
325
326
To operate your program (named REVISE) under commitment control, you issue the commands: 1. STRCMTCTL LCKLVL(*ALL) This command starts commitment control with the highest level of locking. 2. CALL REVISE This command calls the program REVISE. 3. ENDCMTCTL This command ends commitment control and causes an implicit Roll Back operation.
327
328
DDM Files
ILE RPG programs access files on remote systems through distributed data management (DDM). DDM allows application programs on one system to use files stored on a remote system as database files. No special statements are required in ILE RPG programs to support DDM files. A DDM file is created by a user or program on a local (source) system. This file (with object type *FILE) identifies a file that is kept on a remote (target) system. The DDM file provides the information needed for a local system to locate a remote system and to access the data in the source file. For more information about using DDM and creating DDM files, refer to the DB2 Universal Database for AS/400 section of the Database and File Systems category in the iSeries 400 Information Center at this Web site http://publib.boulder.ibm.com/html/as400/infocenter.html.
In addition, if the sign of a numeric field is different from the system preferred sign, the key comparison will also differ. The first time that the key comparison is not done at the Data Management level on a pre-V3R1 DDM file during the READE or READPE operation, EQ indicator for SETLL, or during sequential-within-limits processing by a record address file, an informational message (RNI2002) will be issued.
329
DDM Files
Note: The performance of I/O operations that have the possibility of not finding a record (SETLL, CHAIN, SETGT, READE, READPE), will be slower than the pre-Version 3 Release 1.0 equivalent.
330
Tape Files
SEQ
Diskette Files
DISK
Display Files
WORKSTN
ICF Files
Allow a program on one system to communicate with a program on the same system or another system.
WORKSTN
The device file contains the file description, which identifies the device to be used; it does not contain data.
331
332
333
334
335
Total Calculations
0A
0A Print
Total Output
0A
0A Print
Overflow Printing T = Total H = Heading D = Detail E = Exception Print Print Print Print
Detail Calculations
0A
0A Print
0A
0A Print
Off
Off
Off
Off
Off
Off
Off
Off
When fetch overflow is not specified, the overflow lines print after total output. No matter when overflow occurs (OA is on), the overflow indicator OA remains on through overflow output time and is set off after heading and detail output time. When fetch overflow is specified, the overflow lines are written before the output line for which fetch overflow was specified, if the overflow indicator OA is on. When OA is set on, it remains on until after heading
336
The total lines with an F coded in position 18 can fetch the overflow routine. They only do so if overflow is sensed prior to the printing of one of these lines. Before fetch overflow is processed, a check is made to determine whether the overflow
Chapter 18. Accessing Externally Attached Devices
337
The OPM PRTCTL data structure must be defined on the Definition specifications and must contain at least the following five subfields specified in the following order:
Table 26. Layout of OPM PRTCTL Data Structure Positions 1 2 3-4 5-6 7-9 Subfield Contents A one-position character field that contains the space-before value (valid values: blank or 0-3) A one-position character field that contains the space-after value (valid values: blank or 0-3) A two-position character field that contains the skip-before value (valid values: blank, 1-99, A0-A9 for 100-109, B0-B2 for 110-112) A two-position character field that contains the skip-after value (valid values: blank, 1-99, A0-A9 for 100-109, B0-B2 for 110-112) A two-digit numeric field with zero decimal positions that contains the current line count value.
338
On the file description specifications, the PRTCTL keyword is specified for the PRINT file. The name of the associated data structure is LINE. The LINE data structure is defined on the input specifications as having only those subfields that are predefined for the PRTCTL data structure. The first four subfields in positions 1 through 12 are used to supply space and skip information that is generally specified in positions 40 through 51 of the output specifications. The PRTCTL keyword allows you to change these specifications within the program. In this example, the value in the SpAfter subfield is changed to 3 when the value in the CurLine (current line count value) subfield is equal to 10. (Assume that indicator 01 was set on as a record identifying indicator.)
339
340
A SEQ device is specified for the PAYOTIME file. When the program is run, you can use a OS/400 override command to specify the actual device (such as printer, tape, or diskette) to be associated with the file while the program is running. For example, diskette can be specified for some program runs while printer can be specified for others. The file description, pointed to by the file name, can specify the actual device, in which case an override command need not be used.
341
Status The status parameter is a one-position character field that indicates the status of the user-written routine when control is returned to the ILE RPG program. Status must contain one of the following return values when the user-written routine returns control to the ILE RPG program: Return Value Description 0 1 2 Error Normal return. The requested action was processed. The input file is at end of file, and no record has been returned. If the file is an output file, this return value is an error. The requested action was not processed; error condition exists.
The error parameter is a five-digit zoned numeric field with zero decimal positions. If the user-written routine detects an error, the error parameter contains an indication or value representing the type of error. The value is placed in the first five positions of location *RECORD in the INFDS when the status parameter contains 2. The area parameter is a character field whose length is equal to the record length associated with the SPECIAL file. This field is used to pass the record to or receive the record from the ILE RPG program.
Area
You can add additional parameters to the RPG-created parameter list. Specify the keyword PLIST(parameter list name) on the file description specifications for the SPECIAL file. See Figure 180 on page 343. Then use the PLIST operation in the calculation specifications to define the additional parameters. The user-written routine, specified by the keyword PGMNAME of the file description specifications for the SPECIAL file, must contain an entry parameter list that includes both the RPG-created parameters and the user-specified parameters. If the SPECIAL file is specified as a primary file, the user-specified parameters must be initialized before the first primary read. You can initialize these
342
343
The I/O operations for the SPECIAL device are controlled by the user-written program USERIO. The parameters specified for the programmer-defined PLIST(SPCL) are added to the end of the RPG-created parameter list for the SPECIAL device. The programmer-specified parameters can be accessed by the user ILE RPG program and the user-written routine USERIO; whereas the RPG-created parameter list can be accessed only by internal ILE RPG logic and the user-written routine.
344
345
346
This display device file contains two record formats: PROMPT and RESPONSE. 1 2 3 4 The attributes for the fields in this file are defined in the DSTREF field reference file. The OVERLAY keyword is used so that both record formats can be used on the same display. Function key 3 is associated with indicator 98, which is used by the programmer to end the program. The PUTRETAIN keyword allows the value that is entered in the ITEM field to be kept in the display. In addition, the ITEM field is defined as an input field by the I in position 38. ITEM is the only input field in these record formats. All of the other fields in the record are output fields since position 38 is blank for each of them. The ERRMSG keyword identifies the error message that is displayed if indicator 61 is set on in the program that uses this record format. The LOCK keyword prevents the work-station user from using the keyboard when the RESPONSE record format is initially-displayed. The constants such as Description, Price, and Warehouse Location describe the fields that are written out by the program. The line and position entries identify where the fields or constants are written on the display.
5 6 7 8
347
348
Using Subfiles
Subfiles can be specified in the DDS for a display-device file to allow you to handle multiple records of the same type on the display. (See Figure 183 on page 350.) A subfile is a group of records that is read from or written to a display-device file. For example, a program reads records from a database file and creates a subfile of output records. When the entire subfile has been written, the program sends the entire subfile to the display device in one write operation. The work-station user can change data or enter additional data in the subfile. The program then reads the entire subfile from the display device into the program and processes each record in the subfile individually. Records that you want to be included in a subfile are specified in the DDS for the file. The number of records that can be included in a subfile must also be specified in the DDS. One file can contain more than one subfile, and up to 12 subfiles can be active concurrently. Two subfiles can be displayed at the same time. The DDS for a subfile consists of two record formats: a subfile-record format and a subfile control-record format. The subfile-record format contains the field information that is transferred to or from the display file under control of the subfile control-record format. The subfile control-record format causes the physical read, write, or control operations of a subfile to take place. Figure 184 on page 351 shows an example of the DDS for a subfile-record format, and Figure 185 on page 352 shows an example of the DDS for a subfile control-record format. For a description of how to use subfile keywords, refer to the DB2 Universal Database for AS/400 section of the Database and File Systems category in the iSeries 400 Information Center at this Web site http://www.ibm.com/eserver/iseries/infocenter..
349
To use a subfile for a display device file in an RPG program, you must specify the SFILE keyword on a file description specification for the WORKSTN file. The format of the SFILE keyword is SFILE(record format name:RECNO field name). The WORKSTN file must be an externally-described file (E in position 22). You must specify for the SFILE keyword the name of the subfile record format (not the control-record format) and the name of the field that contains the relative record number to be used in processing the subfile. In an RPG program, relative record number processing is defined as part of the SFILE definition. The SFILE definition implies a full-procedural update file with ADD for the subfile. Therefore, the file operations that are valid for the subfile are not dependent on the definition of the main WORKSTN file. That is, the WORKSTN file can be defined as a primary file or a full-procedural file. Use the CHAIN, READC, UPDATE, or WRITE operation codes with the subfile record format to transfer data between the program and the subfile. Use the READ, WRITE, or EXFMT operation codes with the subfile control-record format to transfer data between the program and the display device or to process subfile control operations. Subfile processing follows the rules for relative-record-number processing. The RPG program places the relative-record number of any record retrieved by a READC operation into the field named in the second position of the SFILE keyword. This field is also used to specify the record number that the RPG program uses for WRITE operation to the subfile or for output operations that use ADD. The RECNO field name specified for the SFILE keyword must be defined as numeric with zero decimal positions. The field must have enough positions to contain the largest record number for the file. (See the SFLSIZ keyword in the DB2 Universal Database for AS/400 section of the Database and File Systems category in the iSeries 400 Information Center at this Web site http://www.ibm.com/eserver/iseries/infocenter.) The WRITE operation code and
350
The data description specifications (DDS) for a subfile record format describe the records in the subfile: 1 2 3 The attributes for the fields in the record format are contained in the field reference file DSTREF as specified by the REF keyword. The SFL keyword identifies the record format as a subfile. The line and position entries define the location of the fields on the display.
Use of Subfiles
Some typical ways you can make use of subfiles include: v Display only. The work-station user reviews the display. v Display with selection. The user requests more information about one of the items on the display. v Modification. The user changes one or more of the records. v Input only, with no validity checking. A subfile is used for a data entry function. v Input only, with validity checking. A subfile is used for a data entry function, but the records are checked. v Combination of tasks. A subfile can be used as a display with modification, plus the input of new records. The following figure shows an example of data description specifications for a subfile control-record format. For an example of using a subfile in an RPG program, see Search by Zip Code on page 374.
351
The subfile control-record format defines the attributes of the subfile, the search input field, constants, and function keys. The keywords you can use indicate the following: v SFLCTL names the associated subfile (SUBFIL). v SFLCLR indicates when the subfile should be cleared (when indicator 70 is off). v SFLDSPCTL indicates when to display the subfile control record (when indicator 70 is on). v SFLDSP indicates when to display the subfile (when indicator 71 is on). v SFLSIZ indicates the total number of records to be included in the subfile (15). v SFLPAG indicates the total number of records in a page (15). v ROLLUP indicates that indicator 97 is set on in the program when the user presses the Roll Up key. v HELP allows the user to press the Help key for a displayed message that describes the valid function keys. v PUTRETAIN allows the value that is entered in the SRHCOD field to be kept in the display. In addition to the control information, the subfile control-record format also defines the constants to be used as column headings for the subfile record format.
352
Output Specifications
On the output specifications, you must specify the WORKSTN file name in positions 7 through 16. The format name, which is the name of the DDS record format, is specified as a literal or named constant in positions 53 through 80 on the succeeding field description line. K1 through K10 must be specified (right-adjusted) in positions 47 through 51 on the line containing the format name. The K identifies the entry as a length rather than an end position, and the number indicates the length of the format name. For example, if the format name is CUSPMT, the entry in positions 47 through 51 is K6. (Leading zeros following the K are allowed.) The format name cannot be conditioned (indicators in positions 21 through 29 are not valid). Output fields must be located in the output record in the same order as defined in the DDS; however, the field names do not have to be the same. The end position entries for the fields refer to the end position in the output record passed from the RPG program to data management, and not to the location of the fields on the screen. To pass indicators on output, do one of the following: v Specify the keyword INDARA in the DDS for the WORKSTN file. Do not use the PASS(*NOIND) keyword on the file description specification and do not specify the indicators on the output specifications. The program and file use a separate indicator area to pass the indicators. v Specify the PASS(*NOIND) keyword on the file description specification. Specify the indicators in the output specifications as fields in the form *INxx. The indicator fields must precede other fields in the output record, and they must appear in the order specified by the WORKSTN file DDS. You can determine this order from the DDS listing.
Input Specifications
The input specifications describe the record that the RPG program receives from the display or ICF device. The WORKSTN file name must be specified in positions 7 through 16. Input fields must be located in the input record in the same sequence as defined in the DDS; however, the field names do not have to be the same. The field location entries refer to the location of the fields in the input record. To receive indicators on input, do one of the following: v Specify the keyword INDARA in the DDS for the WORKSTN file. Do not use the PASS(*NOIND) keyword on the file description specification and do not
Chapter 19. Using WORKSTN Files
353
Calculation Specifications
The operation code READ is valid for a program-described WORKSTN file that is defined as a combined, full-procedural file. See Table 29 on page 355. The file name must be specified in factor 2 for this operation. A format must exist at the device before any input operations can take place. This requirement can be satisfied on a display device by conditioning an output record with 1P or by writing the first format to the device in another program (for example, in the CL program). The EXFMT operation is not valid for a program-described WORKSTN file. You can also use the EXCEPT operation to write to a WORKSTN file.
Additional Considerations
When using a format name with a program-described WORKSTN file, you must also consider the following: v The name specified in positions 53 through 80 of the output specifications is assumed to be the name of a record format in the DDS that was used to create the file. v If a Kn specification is present for an output record, it must also be used for any other output records for that file. If a Kn specification is not used for all output records to a file, a run-time error will occur.
Input File
For an input file, the input record, which is treated by the OS/400 device support as a single input field, is initialized to blanks when the file is opened. The cursor is positioned at the beginning of the field, which is position 2 on the display.
354
Output File
For an output file, the OS/400 device support treats the output record as a string of characters to be sent to the display. Each output record is written as the next sequential record in the file; that is, each record displayed overlays the previous record displayed.
Combined File
For a combined file, the record, which is treated by the OS/400 device support as a single field, appears on the screen and is both the output record and the input record. Device support initializes the input record to blanks, and the cursor is placed in position 2. For more information on program-described-display-device files, refer to the DB2 Universal Database for AS/400 section of the Database and File Systems category in the iSeries 400 Information Center at this Web site http://www.ibm.com/eserver/iseries/infocenter.
26-35 CLOSE, ACQ, REL, NEXT, POST, FORCE WRITE1, CLOSE, ACQ, REL, NEXT, POST, FORCE READ, OPEN, CLOSE, ACQ, REL, NEXT, POST READ, WRITE1, EXFMT2, OPEN, CLOSE, ACQ, REL, NEXT, POST, UPDATE3, CHAIN3, READC3 WRITE1, OPEN, CLOSE, ACQ, REL, POST
The following further explains the EXFMT, READ, and WRITE operation codes when used to process a WORKSTN file.
EXFMT Operation
The EXFMT operation is a combination of a WRITE followed by a READ to the same record format (it corresponds to a data management WRITE-READ operation). If you define a WORKSTN file on the file description specifications as a full-procedural (F in position 18) combined file (C in position 17) that uses externally-described data (E in position 22) the EXFMT (execute format) operation code can be used to write and read from the display.
355
READ Operation
The READ operation is valid for a full-procedural combined file or a full-procedural input file that uses externally-described data or program-described data. The READ operation retrieves a record from the display. However, a format must exist at the device before any input operations can occur. This requirement can be satisfied on a display device by conditioning an output record with the 1P indicator, by writing the first format to the device from another program, or, if the read is by record-format name, by using the keyword INZRCD on the record description in the DDS.
WRITE Operation
The WRITE operation writes a new record to a display and is valid for a combined file or an output file. Output specifications and the EXCEPT operation can also be used to write to a WORKSTN file. See the ILE RPG Reference for a complete description of each of these operation codes.
Multiple-Device Files
Any RPG WORKSTN file with at least one of the keywords DEVID, SAVEIND, MAXDEV(*FILE) or SAVEDS specified on the file description specification is a multiple-device file. Through a multiple-device file, your program may access more than one device. The RPG program accesses devices through program devices, which are symbolic mechanisms for directing operations to an actual device. When you create a file (using the DDS and commands such as the create file commands), you consider such things as which device is associated with a program device, whether or not a file has a requesting program device, which record formats will be used to invite devices to respond to a READ-by-file-name operation, and how long this READ operation will wait for a response. For detailed information on the options and requirements for creating a multiple-device file, see the chapter on display files in the DB2 Universal Database for AS/400 section of the Database and File Systems category in the iSeries 400 Information Center at this Web site http://www.ibm.com/eserver/iseries/infocenter. You can also refer to information on ICF files in ICF Programming manual. With multiple-device files, you make particular use of the following operation codes: v In addition to opening a file, the OPEN operation implicitly acquires the device you specify when you create the file. v The ACQ (acquire) operation acquires any other devices for a multiple-device file. v The REL (release) operation releases a device from the file. v The WRITE operation, when used with the DDS keyword INVITE, invites a program device to respond to subsequent read-from-invited- program-devices operations. See the section on inviting a program device in ICF Programming manual. v The READ operation either processes a read-from-invited-program-devices operation or a read-from-one-program-device operation. When no NEXT operation is in effect, a program-cycle-read or READ-by-file-name operation waits for input from any of the devices that have been invited to respond (read-from-invited-program-device). Other input and output operations, including a READ-by-file-name after a NEXT operation, and a READ-by-format-name, process a read-from-one-program-device operation using
356
Multiple-Device Files
the program device indicated in a special field. (The field is named in the DEVID keyword of the file description specification lines.) This device may be the device used on the last input operation, a device you specify, or the requesting program device. See the sections on reading from invited program devices and on reading from one program device in ICF Programming manual. v The NEXT operation specifies which device is to be used in the next READ-by-file-name operation or program-cycle-read operation. v The POST operation puts information in the INFDS information data structure. The information may be about a specific device or about the file. (The POST operation is not restricted to use with multiple-device files.) See the ILE RPG Reference for details of the RPG operation codes. On the file description specification you can specify several keywords to control the processing of multiple-device files. v The MAXDEV keyword indicates whether it is a single or multiple device file. Specify MAXDEV(*FILE) to process a multiple device file with the maximum number of devices taken from the definition of the file being processed. Specify MAXDEV(*ONLY) to process only one device. v The DEVID keyword allows you to specify the name of a program device to which input and output operations are directed. When a read-from-one-program-device or WRITE operation is issued, the device used for the operation is the device specified as the parameter to the DEVID keyword. This field is initialized to blanks and is updated with the name of the device from which the last successful input operation occurred. It can also be set explicitly by moving a value to it. The ACQ operation code does not affect the value of this field. If the DEVID keyword is not specified, the input operation is performed against the device from which the last successful input operation occurred. A blank device name is used if a read operation has not yet been performed successfully from a device. When a read-from-one-program device or WRITE operation is issued with a blank device name, the RPG compiler implicitly uses the device name of the requestor device for the program. If you call an RPG program interactively and acquire an ICF device against which you want to perform one of these operations, you must explicitly move the device name of the ICF device into the field name specified with the DEVID keyword prior to performing the operation. If this is not done, the device name used will either be blank (in which case the interactive requestor device name is used), or the device name used is the one from the last successful input operation. Once you have performed an I/O operation to the ICF device, you do not need to modify the value again unless an input operation completes successfully with a different device. v The SAVEDS keyword indicates a data structure that is saved and restored for each device acquired to a file. The SAVEIND keyword indicates a set of indicators to be saved and restored for each device acquired to a file. Before an input operation, the current set of indicators and data structure are saved. After the input operation, the RPG compiler restores the indicators and data structure for the device associated with the operation. This may be a different set of indicators or data structure than was available before the input operation. v The INFDS keyword specifies the file information data structure for the WORKSTN file. The RPG *STATUS field and the major/minor return code for
357
Multiple-Device Files
the I/O operation can be accessed through this data structure. Particularly when ICF is being used, both fields are useful for detecting errors that occurred during I/O operations to multiple-device files. Note: When specifying these control options, you must code the MAXDEV option before the DEVID, SAVEIND or SAVEDS options.
358
359
360
In addition to describing the constants, fields, line numbers, and horizontal positions for the screen, the record formats also define the display attributes for these entries. Note: Normally, the field attributes are defined in a field-reference file rather than in the DDS for a file. The attributes are shown on the DDS so you can see what they are.
361
// Prototype definitions: D CustMaintain pr D SearchZip pr D SearchName pr // Field definitions: D indicators ds D exitKey D maintainKey D srchZipKey D srchCustKey
n n n n
/free // Keep looping until exit key is pressed dow '1'; // Display main menu exfmt hdrscn; // Perform requested action if exitKey; // Exit program leave; elseif maintainKey; // Maintain customer data CustMaintain(); elseif srchZipKey; // Search customer data on ZIP code SearchZip(); elseif srchCustKey; // Search customer data on customer name SearchName(); endif; enddo; *inlr = *on; /end-free
362
Note: The *FIRST option specifies that the first module in the list, CUSMAIN, is selected as the program entry procedure. 3. Call the program by entering:
CALL MYPROG
22:30:05
9/30/94
Press one of the following PF keys. F3 F5 F6 F7 End Job Maintain Customer File Search Customer by Zip Code Search Customer by Name
File Maintenance
The following illustrates a maintenance program using the WORKSTN file. It allows you to add, delete, update, and display records of the master customer file.
363
File Maintenance
The DDS for the database file used by this program describe one record format: CMLREC1. Each field in the record format is described, and the CUST field is identified as the key field for the record format.
364
File Maintenance
365
File Maintenance
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A R CSTINQ MODE 8A O 1 1 2 2 2 4 CUST NAME ADDR1 ADDR2 CITY STATE ZIP R R R R R R R O B B B B 4 6 7 8 9 TEXT('DISPLAY CUST INFO') CA12(12 'PREVIOUS SCREEN') 4DSPATR(HI) 13'MODE' DSPATR(HI) 4TIME DSPATR(HI) 28'CUSTOMER FILE MAINTENANCE' DSPATR(HI) DSPATR(RI) 70DATE EDTCDE(Y) DSPATR(HI) 14'Customer:' DSPATR(HI) DSPATR(UL) 25DSPATR(HI) 25DSPATR(CS) DSPATR(PR) 25DSPATR(CS) DSPATR(PR) 25DSPATR(CS) DSPATR(PR) 25DSPATR(CS) DSPATR(PR) 25DSPATR(CS) DSPATR(PR) 40DSPATR(CS) EDTCDE(Z) DSPATR(PR) 2'F12 Cancel' 13 TEXT('ADD CUST RECORD') CA12(12 'PREVIOUS SCREEN') 4DSPATR(HI) 13'MODE' DSPATR(HI) 4TIME DSPATR(HI) 28'CUSTOMER FILE MAINTENANCE' DSPATR(HI RI) 70DATE EDTCDE(Y) DSPATR(HI) 14'Customer:' DSPATR(HI UL) 25DSPATR(HI) 20'Name' DSPATR(HI) 25 17'Address' DSPATR(HI) 25 17'Address' DSPATR(HI) 25 20'City' DSPATR(HI) 25 19'State' DSPATR(HI) 25 36'Zip' DSPATR(HI) 40 2'F12 Cancel Addition'
04 04 04 04 04 04
B 10 B 10 23 O 23 O 1 1 2 2 2 4 4 6 6 7 7 8 8 9 9 10 10 10 10 23
8 8
R R R R R R R Y
O I I I I I I
The DDS for the MNTMENU display device file contains three record formats: HDRSCN, CSTINQ, and CSTBLD. The HDRSCN record prompts for the customer number and the mode of processing. The CSTINQ record is used for the Update,
366
File Maintenance
Delete, and Display modes. The fields are defined as output/input (B in position 38). The fields are protected when Display or Delete mode is selected (DSPATR(PR)). The CSTBLD record provides only input fields (I in position 38) for a new record. The HDRSCN record format contains the constant Customer File Maintenance. The ERRMSG keyword defines the messages to be displayed if an error occurs. The CA keywords define the function keys that can be used and associate the function keys with indicators in the RPG program.
// Field definitions: D indicators ds D exitKey D disableInput D addKey D updateKey D deleteKey D displayKey D prevKey D custExists D custNotFound // Key list definitions: C C CSTKEY KLIST KFLD CUST n n n n n n n n n overlay(indicators:3) overlay(indicators:4) overlay(indicators:5) overlay(indicators:6) overlay(indicators:7) overlay(indicators:8) overlay(indicators:12) overlay(indicators:51) overlay(indicators:52)
367
File Maintenance
//***************************************************************** // MAINLINE * //***************************************************************** /free mode = 'DISPLAY'; exfmt hdrscn; // Loop until exit key is pressed dow not exitKey; exsr SetMaintenanceMode; if cust <> 0; if mode = 'ADD'; exsr AddSub; elseif mode = 'UPDATE'; exsr UpdateSub; elseif mode = 'DELETE'; exsr DeleteSub; elseif mode = 'DISPLAY'; exsr InquirySub; endif; endif; exfmt hdrscn; custExists = *off; CustNotFound = *off; enddo; *inlr = *on; Figure 192. Source for module CUSMNT (Part 2 of 5) // turn off error messages
368
File Maintenance
//**************************************************************** // SUBROUTINE - AddSub * // PURPOSE - Add new customer to file * //**************************************************************** begsr AddSub; // Is customer number already in file? chain CstKey cmlrec1; if %found(cusmstl1); // Customer number is already being used custExists = *on; leavesr; endif; // Initialize new customer data custExists = *off; // turn off error messages CustNotFound = *off; name = *blank; addr1 = *blank; addr2 = *blank; city = *blank; state = *blank; zip = 0; // Prompt for updated data for this customer record exfmt cstbld; // If OK, add customer to the customer file if not *in12; write cmlrec1; endif; endsr; // end of subroutine AddSub
//**************************************************************** // SUBROUTINE - UpdateSub * // PURPOSE - Update customer master record * //**************************************************************** begsr UpdateSub; // Lookup customer number chain cstkey cmlrec1; if not %found(cusmstl1); // Customer is not found in file custNotFound = *on; leavesr; endif; // Display information for this customer disableInput = *off; exfmt cstinq; if not prevKey; // Update information in file update cmlrec1; else; // If we don't want to update, at least unlock // the record. unlock cusmstl1; endif; endsr; // end of subroutine UpdateSub; Figure 192. Source for module CUSMNT (Part 3 of 5)
369
File Maintenance
//**************************************************************** // SUBROUTINE - DeleteSub * // PURPOSE - Delete customer master record * //**************************************************************** begsr DeleteSub; // Lookup customer number chain cstkey cmlrec1; if not %found(cusmstl1); // Customer is not found in file custNotFound = *on; leavesr; endif; // Display information for this customer disableInput = *on; exfmt cstinq; if not prevKey; // Delete customer record delete cmlrec1; else; // If we don't want to delete, at least unlock // the record. unlock cusmstl1; endif; endsr; // end of subroutine DeleteSub
//**************************************************************** // SUBROUTINE - InquirySub * // PURPOSE - Display customer master record * //**************************************************************** begsr InquirySub; // Lookup customer number chain(n) cstkey cmlrec1; // don't lock record if not %found(cusmstl1); // Customer is not found in file custNotFound = *on; leavesr; endif; // Display information for this customer disableInput = *on; exfmt cstinq; endsr; // end of subroutine InquirySub; Figure 192. Source for module CUSMNT (Part 4 of 5)
370
File Maintenance
//**************************************************************** // SUBROUTINE - SetMaintenanceMode * // PURPOSE - Set maintenance mode * //**************************************************************** begsr SetMaintenanceMode; if addKey; mode = 'ADD'; elseif updateKey; mode = 'UPDATE'; elseif deleteKey; mode = 'DELETE'; elseif displayKey; mode = 'DISPLAY'; endif; endsr; // end of subroutine SetMaintenanceMode /end-free Figure 192. Source for module CUSMNT (Part 5 of 5)
This program maintains a customer master file for additions, changes, and deletions. The program can also be used for inquiry. The program first sets the default (display) mode of processing and displays the customer maintenance prompt screen. The workstation user can press F3, which turns on indicator 03, to request end of job. Otherwise, to work with customer information, the user enters a customer number and presses Enter. The user can change the mode of processing by pressing F5 (ADD), F6 (UPDATE), F7 (DELETE), or F8 (DISPLAY). To add a new record to the file, the program uses the customer number as the search argument to chain to the master file. If the record does not exist in the file, the program displays the CSTBLD screen to allow the user to enter a new customer record. If the record is already in the file, an error message is displayed. The user can press F12, which sets on indicator 12, to cancel the add operation and release the record. Otherwise, to proceed with the add operation, the user enters information for the new customer record in the input fields and writes the new record to the master file. To update, delete, or display an existing record, the program uses the customer number as the search argument to chain to the master file. If a record for that customer exists in the file, the program displays the customer file inquiry screen CSTINQ. If the record is not in the file, an error message is displayed. If the mode of processing is display or delete, the input fields are protected from modification. Otherwise, to proceed with the customer record, the user can enter new information in the customer record input fields. The user can press F12, which sets on indicator 12, to cancel the update or delete operation, and release the record. Display mode automatically releases the record when Enter is pressed. In Figure 193 on page 372, the workstation user responds to the prompt by entering customer number 00007 to display the customer record.
371
File Maintenance
DISPLAY MODE 22:30:21 CUSTOMER FILE MAINTENANCE 9/30/94
00007
F3 End Job
F5 Add
F6 Update
F7 Delete
F8 Display
Because the customer record for customer number 00007 exists in the Master File, the data is displayed as show in Figure 194.
DISPLAY MODE 22:31:06 CUSTOMER FILE MAINTENANCE Customer: 00007 Mikhail Yuri 1001 Bay Street Suite 1702 Livonia MI 11201
9/30/94
The workstation user responds to the add prompt by entering a new customer number as shown in Figure 195 on page 373.
372
File Maintenance
ADD MODE 22:31:43 CUSTOMER FILE MAINTENANCE 9/30/94
00012
F3 End Job
F5 Add
F6 Update
F7 Delete
F8 Display
CUSTOMER FILE MAINTENANCE Customer: 00012 Name Address Address City State JUDAH GOULD 2074 BATHURST AVENUE YORKTOWN NY Zip 70068
9/30/94
The workstation user responds to the delete prompt by entering a customer number as shown in Figure 197 on page 374.
373
File Maintenance
DELETE MODE 22:32:55 CUSTOMER FILE MAINTENANCE 9/30/94
00011
F3 End Job
F5 Add
F6 Update
F7 Delete
F8 Display
The workstation user responds to the update prompt by entering a customer number as shown in Figure 198.
UPDATE MODE 22:33:17
9/30/94
00010
F3 End Job
F5 Add
F6 Update
F7 Delete
F8 Display
374
The DDS for the database file used by this program describe one record format: CMLREC2. The logical file CUSMSTL2 keyed by zip code is based on the physical file CUSMST, as indicated by the PFILE keyword. The record format created by the logical file will include only those fields specified in the logical file DDS. All other fields will be excluded.
375
376
377
zip
378
379
//**************************************************************** // SUBROUTINE - FillSubfile * // PURPOSE - Fill subfile with customer records matching * // specified zip code. * //**************************************************************** begsr FillSubfile; // Loop through all customer records with specified zip code recnum = 0; dou %eof(szipmenu); // Read next record with specified zip code reade zip cmlrec2; if %eof(cusmstl2); // If no more records, we're done leavesr; endif; // Add information about this record to the subfile recnum = recnum + 1; write subfile; enddo; endsr; // end of subroutine FillSubfile;
//**************************************************************** // SUBROUTINE - ClearSubfile * // PURPOSE - Clear subfile records * //**************************************************************** begsr ClearSubfile; sflClear = *on; write subctl; sflClear = *off; endsr; // end of subroutine ClearSubfile
380
381
ENTER - Continue
F3 - End Job
9/30/94
ENTER - Continue
F3 - End Job
382
The DDS for the database file used in this program defines one record format named CUSREC and identifies the NAME field as the key fields.
383
384
SRCNAM
R CUSDSP CUST NAME ADDR1 ADDR2 CITY STATE ZIP ARBAL 5S 0O 20A 20A 20A 20A 2A O O O O O
5S 0O 10Y 2O
The DDS for the SNAMMENU display device file contains seven record formats: HEAD, FOOT1, FOOT2, PROMPT, SUBFILE, SUBCTL, and CUSDSP. The PROMPT record format requests the user to enter a zip code and search name. If no entry is made, the display starts at the beginning of the file. The user can press F3, which sets on indicator 03, to end the program. The SUBFILE record format must be defined immediately preceding the subfile-control record format SUBCTL. The subfile-record format defined with the keyword SFL, describes each field in the record, and specifies the location where the first record is to appear on the display (here, on line 9).
385
386
srcnam name
387
//***************************************************************** // SUBROUTINE - ProcessSubfile * // PURPOSE - Process subfile and display * //***************************************************************** begsr ProcessSubfile; // Keep looping while roll up key is pressed dou not rollupKey; // Do we have more information to add to subfile? if not %eof(cusmstl3); // Clear and fill subfile with customer data exsr ClearSubfile; exsr FillSubfile; endif; // Write out subfile and wait for response write foot2; exfmt subctl; enddo; endsr; // end of subroutine ProcessSubfile
388
//**************************************************************** // SUBROUTINE - ClearSubfile * // PURPOSE - Clear subfile records * //**************************************************************** begsr ClearSubfile; sflClear = *on; write subctl; sflClear = *off; endsr; // end of subroutine ClearSubfile
389
The file description specifications identify the disk file to be searched and the display device file to be used (SNAMMENU). The SFILE keyword for the WORKSTN file identifies the record format (SUBFILE) to be used as a subfile. The relative-record-number field (RECNUM) specifies which record within the subfile is being accessed. The program displays the PROMPT record format and waits for the workstation users response. F3 sets on indicator 03, which controls the end of the program. The name (NAME) is used as the key to position the CUSMSTL3 file by the SETLL operation. Notice that the record format name CUSREC is used in the SETLL operation instead of the file name CUSMSTL3. The SFLPRC subroutine handles the processing for the subfile: clearing, filling, and displaying. The subfile is prepared for additional requests in subroutine SFLCLR. If indicator 55 is on, no action occurs on the display, but the main storage area for the subfile records is cleared. The SFLFIL routine fills the subfile with records. A record is read from the CUSMSTL3 file, the record count (RECNUM) is incremented, and the record is written to the subfile. This subroutine is repeated until either the subfile is full (indicator 21 on the WRITE operation) or end of file occurs on the CUSMSTL3 file (indicator 71 on the READ operation). When the subfile is full or end of file occurs, the subfile is written to the display by the EXFMT operation by the subfile-control record control format. The user reviews the display and decides: v To end the program by pressing F3. v To restart the subfile by pressing F4. The PROMPT record format is not displayed, and the subfile is displayed starting over with the same name.
390
9/30/94
ENTER - Continue
F3 - End Job
The user requests more information by entering an X as shown in Figure 208 on page 392.
391
ENTER - Continue
F3 - End Job
F4 - Restart Name
The detailed information for the customer selected is shown in Figure 209 . At this point the user selects the appropriate function key to continue or end the inquiry.
23:39:48
9/30/94
00012 JUDAH GOULD 2074 BATHURST AVENUE YORKTOWN NY Zip Code 70068 .00
A/R Balance
ENTER - Continue
F3 - End Job
F4 - Restart Name
Figure 209. Customer Search and Inquiry by Name detailed information screen
392
Part 5. Appendixes
393
394
Appendix A. Behavioral Differences Between OPM RPG/400 and ILE RPG for AS/400
The following lists note differences in the behavior of the OPM RPG/400 compiler and ILE RPG.
Compiling
1. If you specify CVTOPT(*NONE) in OPM RPG, all externally described fields that are of a type or with attributes not supported by RPG will be ignored. If you specify CVTOPT(*NONE) in ILE RPG, all externally described fields will be brought into the program with the same type as specified in the external description. 2. In RPG IV there is no dependency between DATEDIT and DECEDIT in the control specification. 3. Regarding the ILE RPG create commands (CRTBNDRPG and CRTRPGMOD): v The IGNDECERR parameter on the CRTRPGPGM command has been replaced by the FIXNBR parameter on the ILE RPG create commands. IGNDECDTA ignores any decimal data errors and continues with the next machine instruction. In some cases, this can cause fields to be updated with incorrect and sometimes unpredictable values. FIXNBR corrects the data in a predictable manner before it is used. v There is a new parameter, TRUNCNBR, for controlling whether numeric overflow is allowed. v There are no auto report features or commands in RPG IV. v You cannot request an MI listing from the compiler. 4. In a compiler listing, line numbers start at 1 and increment by 1 for each line of source or generated specifications, when the default OPTION(*NOSRCSTMT) is specified. If OPTION(*SRCSTMT) is specified, sequence numbers are printed instead of line numbers. Source IDs are numeric, that is, there are no more AA000100 line numbers for /COPY members or expanded DDS. 5. RPG IV requires that all compiler directives appear before compile-time data, including /TITLE. When RPG IV encounters a /TITLE directive, it will treat it as data. (RPG III treats /TITLE specifications as compiler directives anywhere in the source.) The Conversion Aid will remove any /TITLE specifications it encounters in compile-time data. 6. ILE RPG is more rigorous in detecting field overlap in data structures. For some calculation operations involving overlapping operands, ILE RPG issues a message while the OPM compiler does not. 7. In ILE RPG the word NOT cannot be used as a variable name. NOT is a special word that is used as an operator in expressions. 8. At compile time, the source is read using the CCSID of the main source file, while for OPM RPG, the source is read using the CCSID of the job.
Running
1. The FREE operation is not supported by RPG IV.
395
396
| | | | | | | | | | | |
I/O
1. In ILE RPG you can read a record in a file opened for update, and created or overridden with SHARE(*YES), and then update this locked record in another program that has opened the same file for update. 2. You cannot modify the MR indicator using the MOVE or SETON operations. (RPG III only prevents using SETON with MR.) 3. The File Type entry on the File specification no longer dictates the type of I/O operations that must be present in the calculation specifications. For example, in RPG III, if you define a file as an update file, then you must have an UPDAT operation later in the program. This is no longer true in RPG IV. However, your file definition still must be consistent with the I/O operations present in the program. So if you have an UPDATE operation in your source, the file must be defined as an update file. 4. ILE RPG will allow record blocking even if the COMMIT keyword is specified on the file description specification. 5. In RPG IV, a file opened for update will also be opened as delete capable. You do not need any DELETE operations to make it delete capable. 6. In RPG IV, you do not have to code an actual number for the number of devices that will be used by a multiple-device file. If you specify MAXDEV(*FILE) on a file description specification, then the number of save areas created for SAVEDS and SAVEIND is based on the number of devices that your file can handle. (The SAVEDS, SAVEIND, and MAXDEV keywords on an RPG IV file description specification correspond to the SAVDS, IND, and NUM options on a RPG III file description specification continuation line, respectively.)
Appendix A. Behavioral Differences Between OPM RPG/400 and ILE RPG for AS/400
397
398
399
400
Conversion Overview
You convert source programs to the RPG IV source format by calling the Conversion Aid through the CL command Convert RPG Source (CVTRPGSRC). The Conversion Aid converts: v A single member v All members in a source physical file v All members with a common member-name prefix in the same file To minimize the likelihood of there being conversion problems, you can optionally have the /COPY members included in the converted source code. For convenience in reading the code, you can also optionally include specification templates in the converted source code. The Conversion Aid converts each source member on a line-by-line basis. After each member conversion, it updates a log file on the status of the conversion if you specified a log file on the command. You can also obtain a conversion report that includes information such as conversion errors, /COPY statements, CALL operations, and conversion status. The Conversion Aid assumes that your source code is free of any compilation errors. If this is the case, then it will successfully convert most of your source code. In some cases, there may be a small amount of code that you may have to convert manually. Some of these cases are identified by the Conversion Aid. Others are not detected until you attempt to compile the converted source. To see which ones the Conversion Aid can identify, you can run the Conversion Aid using the unconverted member as input, and specify a conversion report but no output member. For information on the types of coding that cannot be converted, see Resolving Conversion Problems on page 419.
File Considerations
The Conversion Aid operates on file members. This section presents information on different aspects of files that must be taken into consideration when using the Conversion Aid.
401
Conversion Overview
If the source member type is 'blank', then the Conversion Aid will assume it has a member type of RPG. If the source member type is blank for an auto report source member, then you should assign the correct source member type (RPT or RPT38) to the member before converting it. If you do, then the Conversion Aid will automatically expand the auto report source member so that it can be converted properly. The expansion is necessary since ILE RPG does not support auto report source members. For more information on converting auto report source members, see Converting Auto Report Source Members on page 411.
Minimum Record Length (92 characters) Recommended Record Length (112 characters)
If the converted source file has a record length less than 92 characters then an error message will be issued and the conversion will stop. This is because the record length is not long enough to contain the 80 characters allowed for source code and so some code is likely to be lost.
402
Conversion Overview
The name of the converted source member(s) depends on whether you are converting one or several members. If you are converting one member, the default is to give the converted source member the same name as the unconverted member. You can, of course, specify a different name for the output member. If you are converting all source members in a file, or a group of them using a generic name, then the members will automatically be given the same name as the unconverted source members. Note that specifying the file, library and member name for the converted output is optional. If you do not specify any of these names, the converted output will be placed in the file QRPGLESRC and have a member name the same as the unconverted member name. (The library list will be searched for the file QRPGLESRC.)
You must have object management, operational and add authority to the log file that is accessed by the Conversion Aid. For information on using the log file see Using the Log File on page 417.
403
Conversion Overview
v The Conversion Aid does not support converting RPG II source programs to the RPG IV source format. However, you can use the RPG II to RPG III Conversion Aid first and then the RPG III to RPG IV Conversion Aid. v The Conversion Aid does not re-engineer source code, except where required (for example, the number of conditioning indicators.) v The Conversion Aid does not create files. The log file and the output file must exist prior to running it.
404
The syntax for the CVTRPGSRC command is shown below. Job: B,I Pgm: B,I REXX: B,I Exec
source-file-name )
CVTRPGSRC FROMFILE (
FROMMBR (
TOFILE (
QRPGLESRC source-file-name
405
EXPCPY (
*NO *YES
CVTRPT (
*YES *NO
SECLVL (
*NO *YES
INSRTPL (
*NO *YES
LOGFILE (
QRNCVTLG log-file-name
LOGMBR (
The parameters and their possible values follow the syntax diagram. If you need prompting, type CVTRPGSRC and press F4. The CVTRPGSRC screen appears, lists the parameters, and supplies default values. For a description of a parameter on the display, place your cursor on the parameter and press F1. Extended help for all of the parameters is available by pressing F1 on any parameter and then pressing F2. FROMFILE Specifies the name of the source file that contains the RPG III or RPG source code to be converted and the library where the source file is stored. This is a required parameter; there is no default file name. source-file-name Enter the name of the source file that contains the source member(s) to be converted. *LIBL The system searches the library list to find the library where the source file is stored. *CURLIB The current library is used to find the source file. If you have not specified a current library, then the library QGPL is used.
406
407
408
This will result in the conversion of the specified source member. The output will be placed in the file QRPGLESRC in whichever library in the library list contains this file. The /COPY members will not be expanded, no specification templates will be inserted, and the conversion report will be produced. The log file QRNCVTLG will be updated. Note: The files QRPGLESRC and QRNCVTLG must already exist.
409
This command converts all of the source members in library OLDRPG in the source physical file QRPGSRC. The new members are created in library NEWRPG in the source physical file QRPGLESRC. If you prefer to keep all source (DDS source, RPG source, etc.) in the same file, you can still convert the RPG source members in one step, by specifying FROMMBR(*ALL). The Conversion Aid will only convert members with a valid RPG type (see Table 31 on page 402).
This command converts all of the source members in library OLDRPG in the source physical file QRPGSRC. The new members are created in library NEWRPG in the source physical file QRPGLESRC.
The TOMBR parameter should be specified as *FROMMBR. However, since this is the default, you do not need to specify it unless the default value has been changed. The CVTRPT parameter should be specified as *YES this is also the default. If it is not, then the conversion will stop immediately.
410
411
412
** 123 ** 456
413
Note the following about the converted source: v The new specification types are H (control), F (file), D (definition), I (input), C (calculation), and O (output); they must be entered in this order. The converted source contains specification templates for the new types, since INSRTPL(*YES) was specified on CVTRPGSRC. v The control, file, and definition specifications are keyword-oriented. See lines 2, 4 - 7, and 9 - 16. v The ILE member has a new specification type, definition. It is used to define standalone fields, arrays and named constants as well as data structures. In this example, ARR2 is defined as a standalone array (Line 9) Data structure DS1 is defined as a data structure with two subfields FIELD1 and ARR1 (Lines 11 - 14) Constant CONST1 is defined as a constant (Line 16) The input (I) specifications are now used only to define records and fields of a file. See Lines 19 - 20. v The extension (E) specifications have been eliminated. Arrays and tables are now defined using definition specifications. v Record address file (RAF) entries on extension specifications have been replaced by the keyword RAFDATA on the File Description specification.
414
415
The source section includes lines that have informational, warning, or error messages associated with them. These lines have an asterisk (*) in column 1 for ease of browsing in SEU. The message summary contains all three message types. Two informational messages which may be of particular interest are: v RNM0508 flags /COPY statements v RNM0511 flags CALL operations All /COPY members in an program must be converted in order for the corresponding ILE RPG program to compile without errors. Similarly, you may want to convert all members related by CALL at the same time. Use this part of the report to assist you in identifying these members. Figure 214 shows the source section for the sample conversion.
5769RG1 V4R4M0 990521 From file . . . . . To file. . . . . . . Log file . . . . . . Sequence Number 000002 *RNM0511 000003 *RNM0508 000004 *RNM0506 RN IBM ILE RPG AS400S01 12/30/99 20:41:35 Page 2 . . . . . . : MYLIB/QRPGSRC(REPORT) . . . . . . : MYLIB/QRPGLESRC(REPORT) . . . . . . : *NONE C o n v e r s i o n R e p o r t <----------------------- Source Specifications ---------------------------><-------------- Comments --------------> Page ....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+...10....+...11....+...12 Line C CALL PROG1 00 CALL operation code found. C/COPY COPYCODE 00 /COPY compiler directive found. C FREE PROG2 30 FREE operation code is not supported in RPG IV. E N D O F S O U R C E * * * * *
* * * * *
The message summary of the listing shows you the different messages that were issued. If you specify SECLVL(*YES), second-level messages will appear in the message summary. Figure 215 on page 417 shows the messages section for the sample conversion, including second-level messages.
416
The final summary of the listing provides message and record statistics. A final status message is also placed in the job log. Figure 216 shows the messages section for the sample conversion.
F i n a l S u m m a r y Message Totals: Information (00) . . . . . . . : 2 Warning (10) . . . . . . . : 0 Severe Error (30+) . . . . . . : 1 --------------------------------- ------Total . . . . . . . . . . . . . : 3 Source Totals: Original Records Read . . . . . . : 3 Converted Records Written . . . . : 4 Highest Severity Message Issued . : 30 * * * * * E N D O F F I N A L S U M M A R Y * * * * * * * * * * E N D O F C O N V E R S I O N * * * * *
417
418
Figure 217. DDS for model log file QARNCVTLG in library QRPGLE
419
Merging Problems
Because of differences between the RPG III and RPG IV languages, the Conversion Aid must reorder certain source statements. An example of this reordering is shown in Example of Source Conversion on page 412 for the RPG III source member TEST1. If you compare the placement of the data structure DS1 in Figure 211 on page 413 and in Figure 212 on page 414, you can see that the data structure DS1 was moved so that it precedes the record format FORMAT1. Now suppose that the RPG III member TEST1 was split into two members, TEST2 and COPYDS1, where the data structure DS1 and the named constant CONST1 are in a copy member COPYDS1. This copy member is included in source TEST2.
420
** 123 ** 456
Figure 218. RPG III Source for TEST2 I* DATA STRUCTURE COMMENT IDS1 DS I I* NAMED CONSTANT COMMENT I 'XYZ' I Figure 219. RPG III Source for COPYDS1
1 C 4
In this situation, the Conversion Aid would convert both member TEST2 and the copy member COPYDS1 correctly. However, when the copy member is included at compile time, it will be inserted below FORMAT1, because this is where the /COPY directive is located. As a result, all source lines in the copy member COPYDS1 will get a source record is out of sequence error. In RPG IV, definition specifications must precede input specifications. Note that the Conversion Aid could not move the /COPY directive above FORMAT1 because the contents of /COPY member are unknown. There are two methods of correcting this type of problem: 1. Use the EXPCPY(*YES) option of the CVTRPGSRC command to include all /COPY members in the converted RPG IV source member. This approach is easy and will work most of the time. However, including the /COPY members in each source member reduces the maintainability of your application. 2. Manually correct the code after conversion using the information in the ILE RPG compiler listing and the ILE RPG Reference. Other examples of this type of problem include: v Line Specifications and Record Address Files In RPG III the line counter specification and the Record Address File of the extension specification are changed to keywords (RAFDATA, FORMLEN, and
421
Context-Sensitive Problems
In RPG III, there are occasions when it is impossible to determine the type of specifications in a /COPY member without the context of the surrounding specifications of the primary source member. There are two instances of this problem: v In data structure subfields or program-described file fields
I* I* I* I* I* I* I I If the RPG III source member contains only the source statements describing fields FIELD1 and FIELD2 below, the Conversion Aid is unsure how to convert them. These statements may be data structure fields (which are converted to definition specifications) or program-described file fields (which are converted to input specifications). 1 3 FIELD1 4 6 FIELD2
Figure 220. RPG III /COPY file with input fields only
v In renaming an externally described data structure field or an externally described file field
I* I* I* I* I* I* I* I If the RPG III source member contains only the source statement describing field CHAR below, the Conversion Aid is unsure how to convert it. This statement may be a rename of an externally described data structure field which is converted to a definition specification) or a rename of an externally described file field) (which is converted to an input specification). CHARACTER CHAR
In the above two instances, a data structure is assumed and definition specifications are produced. A block of comments containing the input specification code is also produced. For example, the Conversion Aid will convert the source in Figure 220 to the code shown in Figure 222 on page 423. If Input specification code
422
Remember that you have two ways of correcting these types of problems. Either use the EXPCPY(*YES) option of the CVTRPGSRC command, or manually correct the code after conversion.
A A A
10 10
423
Figure 224. RPG III source using external data structure with array
S E DS DSPLY SETON
DIM(10) EXTNAME(EXTREC) LR
Figure 225. RPG IV source with two definitions for the array D DSONE D ARRAY C CHAR C E DS E DSPLY SETON EXTNAME(EXTREC) DIM(10) LR
Figure 226. Corrected RPG IV source with a single definition for the array
IDSONE I I I C C
CHAR CHAR LR
Figure 227. RPG III source with renamed and initialized external subfield D DSONE D CHAR D CHAR C CHAR C E DS E E DSPLY SETON EXTNAME(EXTREC) EXTFLD(CHARACTER) INZ('XYZ') LR
Figure 228. RPG IV source with two definitions for renamed subfield D DSONE D CHAR C CHAR C E DS E DSPLY SETON EXTNAME(EXTREC) EXTFLD(CHARACTER) INZ('XYZ') LR
424
Run-time Differences
If you have prerun-time arrays that overlap in data structures, the order of loading these arrays at run time may be different in RPG III and in RPG IV. This difference in order can cause the data in the overlapping section to differ. The order in which the arrays are loaded is the order in which they are encountered in the source. This order may have changed when the arrays were been merged with the subfields during conversion. In general, you should avoid situations where an application consists of OPM and ILE programs that are split across the OPM default activation group and a named activation group. When spilt across these two activation groups, you are mixing OPM behavior with ILE behavior and your results may be hard to predict. Refer to Chapter 3. Program Creation Strategies on page 23 or ILE Concepts for further information.
425
426
Using CL Commands
Control Language (CL) commands, parameters, and keywords can be entered in either uppercase or lowercase characters. In the syntax diagram they are shown in uppercase (for example, PARAMETER, PREDEFINED-VALUE). Variables appear in lowercase italic letters (for example, user-defined-value). Variables are user-defined names or values.
Read the syntax diagram from left to right, and from top to bottom, following the path of the line. The The symbol indicates the beginning of the syntax diagram. symbol indicates the end of the syntax diagram.
The symbol indicates that the statement syntax is continued on the next line. The symbol indicates that a statement is continued from the previous line. The () symbol indicates that the parameter or value must be entered in parentheses. Required parameters appear on the base line and must be entered. Optional parameters appear below the base line and do not need to be entered. In the following sample, you must enter REQUIRED-PARAMETER and a value for it, but you do not need to enter OPTIONAL-PARAMETER or a value for it.
REQUIRED-PARAMETER ( PREDEFINED-VALUE user-defined-value )
427
Default values appear above the base line and do not need to be entered. They are used when you do not specify a parameter. In the following sample, you can enter DEFAULT-VALUE, OTHER-PREDEFINED-VALUE, or nothing. If you enter nothing, DEFAULT-VALUE is assumed.
PARAMETER ( DEFAULT-VALUE OTHER-PREDEFINED-VALUE )
Optional values are indicated by a blank line. The blank line indicates that a value from the first group (OPTIONAL-VALUE1, OPTIONAL-VALUE2, user-defined-value) does not need to be entered. For example, based on the syntax below, you could enter KEYWORD(REQUIRED-VALUE).
PARAMETER ( OPTIONAL-VALUE1 OPTIONAL-VALUE2 user-defined-value REQUIRED-VALUE )
Repeated values can be specified for some parameters. The comma (,) in the following sample indicates that each user-defined-value must be separated by a comma.
, KEYWORD ( user-defined-value )
CRTBNDRPG Command
The Create Bound RPG (CRTBNDRPG) command performs the combined tasks of the Create RPG Module (CRTRPGMOD) and Create Program (CRTPGM) commands by creating a temporary module object from the source code, and then creating the program object. Once the program object is created, CRTBNDRPG deletes the module object it created. The entire syntax diagram for the CRTBNDRPG command is shown below. Job: B,I Pgm: B,I REXX: B,I
*CURLIB/ library-name/
Exec
*CTLSPEC program-name
CRTBNDRPG PGM (
428
CRTBNDRPG Command
SRCFILE ( *LIBL/ *CURLIB/ library-name/ QRPGLESRC source-file-name )
GENLVL
10 severity-level-value
TEXT
DFTACTGRP
*YES *NO
OPTION
OPTION Details
DBGVIEW
OUTPUT
*PRINT *NONE
OPTIMIZE
INDENT
*NONE character-value
CVTOPT
SRTSEQ
sort-table-name
LANGID
REPLACE
*YES *NO
USRPRF
*USER *OWNER
AUT
429
CRTBNDRPG Command
*YES *NO *NONE *ZONED *INPUTPACKED
TRUNCNBR (
FIXNBR (
TGTRLS (
ALWNULL (
BNDDIR (
ACTGRP (
ENBPFRCOL (
DEFINE (
*NONE condition-name
PRFDTA (
*NOCOL *COL
LICOPT ( options )
OPTION Details:
*XREF *NOXREF *GEN *NOGEN *NOSECLVL *SECLVL *SHOWCPY *NOSHOWCPY *EXPDDS *NOEXPDDS
430
CRTBNDRPG Command
*EXT *NOEXT *NOSHOWSKP *SHOWSKP *NOSRCSTMT *SRCSTMT *DEBUGIO *NODEBUGIO *NOEVENTF *EVENTF
431
CRTBNDRPG Command
library-name Enter the name of the library where the source file is stored. SRCMBR Specifies the name of the member of the source file that contains the ILE RPG source program to be compiled. *PGM Use the name specified by the PGM parameter as the source file member name. The compiled program object will have the same name as the source file member. If no program name is specified by the PGM parameter, the command uses the first member created in or added to the source file as the source member name. source-file-member-name Enter the name of the member that contains the ILE RPG source program. GENLVL Controls the creation of the program object. The program object is created if all errors encountered during compilation have a severity level less than or equal to the generation severity level specified. 10 A program object will not be generated if you have messages with a severity-level greater than 10. severity-level-value Enter a number, 0 through 20 inclusive. For errors greater than severity 20, the program object will not be generated. TEXT Allows you to enter text that briefly describes the program and its function. The text appears whenever program information is displayed. *SRCMBRTXT The text of the source member is used. *BLANK No text appears. description Enter the text that briefly describes the function of the source specifications. The text can be a maximum of 50 characters and must be enclosed in apostrophes. The apostrophes are not part of the 50-character string. Apostrophes are not required if you are entering the text on the prompt screen. DFTACTGRP Specifies whether the created program is intended to always run in the default activation group. *YES When this program is called it will always run in the default activation group. The default activation group is the activation group where all original program model (OPM) programs are run. Specifying DFTACTGRP(*YES) allows ILE RPG programs to behave like OPM programs in the areas of override scoping, open scoping, and RCLRSC. ILE static binding is not available when a program is created with DFTACTGRP(*YES). This means that you cannot use the BNDDIR or ACTGRP parameters when creating this program. In addition, any call operation in your source must call a program and not a procedure.
432
CRTBNDRPG Command
DFTACTGRP(*YES) is useful when attempting to move an application on a program-by-program basis to ILE RPG. *NO The program is associated with the activation group specified by the ACTGRP parameter. Static binding is allowed when *NO is specified. If ACTGRP(*CALLER) is specified and this program is called by a program running in the default activation group, then this program will behave according to ILE semantics in the areas of file sharing, file scoping and RCLRSC. DFTACTGRP(*NO) is useful when you intend to take advantage of ILE concepts; for example, running in a named activation group or binding to a service program. OPTION Specifies the options to use when the source member is compiled. You can specify any or all of the options in any order. Separate the options with one or more blank spaces. If an option is specified more than once, the last one is used. *XREF Produces a cross-reference listing (when appropriate) for the source member. *NOXREF A cross-reference listing is not produced. *GEN Create a program object if the highest severity level returned by the compiler does not exceed the severity specified in the GENLVL option. *NOGEN Do not create a program object. *NOSECLVL Do not print second-level message text on the line following the first-level message text. *SECLVL Print second-level message text on the line following the first-level message text in the Message Summary section. *SHOWCPY Show source records of members included by the /COPY compiler directive. *NOSHOWCPY Do not show source records of members included by the /COPY compiler directive. *EXPDDS Show the expansion of externally described files in the listing and display key field information. *NOEXPDDS Do not show the expansion of externally described files in the listing or display key field information. *EXT Show the list of external procedures and fields referenced during the compile on the listing.
Appendix C. The Create Commands
433
CRTBNDRPG Command
*NOEXT Do not show the list of external procedures and fields referenced during the compilation on the listing. *NOSHOWSKP Do not show ignored statements in the source part of the listing. The compiler ignores statements as a result of /IF, /ELSEIF or /ELSE directives. *SHOWSKP Show all statements in the source part of the listing, regardless of whether or not the compiler has skipped them. *NOSRCSTMT Line Numbers in the listing are assigned sequentially; these numbers are used when debugging using statement numbers. Line Numbers are shown on the left-most column of the listing. The source IDs and SEU Sequence Numbers are shown on the two right-most columns of the listing. *SRCSTMT Statement numbers for debugging are generated using SEU sequence numbers and source IDs as follows:
Statement_Number = source_ID * 1000000 + source_SEU_sequence_number
SEU Sequence Numbers are shown on the left-most column of the listing. Statement Numbers are shown on the right-most column of the listing; these numbers are used when debugging using statement numbers. Note: When OPTION(*SRCSTMT) is specified, all sequence numbers in the source files must contain valid numeric values. If there are duplicate sequence numbers in the same source file, the behavior of the debugger may be unpredictable and statement numbers for diagnostic messages or cross reference entries may not be meaningful. *DEBUGIO Generate breakpoints for all input and output specifications. *NODEBUGIO Do not generate breakpoints for input and output specifications. *NOEVENTF Do not create an Event File for use by CoOperative Development Environment/400 (CODE/400). CODE/400 uses this file to provide error feedback integrated with the CODE/400 editor. An Event File is normally created when you create a module or program from within CODE/400. *EVENTF Create an Event File for use by CoOperative Development Environment/400 (CODE/400). The Event File is created as a member in file EVFEVENT in the library where the created module or program object is to be stored. If the file EVFEVENT does not exist it is automatically created. The Event File member name is the same as the name of the object being created. CODE/400 uses this file to provide error feedback integrated with the CODE/400 editor. An Event File is normally created when you create a module or program from within CODE/400.
434
CRTBNDRPG Command
DBGVIEW Specifies which level of debugging is available for the compiled program object, and which source views are available for source-level debugging. *STMT Allows the program object to be debugged using the Line Numbers or Statement Numbers of the compiler listing. Line Numbers are shown on the left-most column of the source section of the compiler listing when OPTION(*NOSRCSTMT) is specified. Statement Numbers are shown on the right-most column of the source section of the compiler listing when OPTION(*SRCSTMT) is specified. *SOURCE Generates the source view for debugging the compiled program object. This view is not available if the root source member is a DDM file. Also, if changes are made to any source members after the compile and before attempting to debug the program, the views for those source members may not be usable. *LIST Generates the listing view for debugging the compiled program object. The information contained in the listing view is dependent on whether *SHOWCPY, *EXPDDS, and *SRCSTMT are specified for the OPTION parameter. Note: The listing view will not show any indentation that you may have requested using the Indent option. *COPY Generates the source and copy views for debugging the compiled program object. The source view for this option is the same source view generated for the *SOURCE option. The copy view is a debug view which has all the /COPY source members included. These views will not be available if the root source member is a DDM file. Also, if changes are made to any source members after the compile and before attempting to debug the program, the views for those source members may not be usable. *ALL Generates the listing, source and copy views for debugging the compiled program object. The information contained in the listing view is dependent on whether *SHOWCPY, *EXPDDS, and *SRCSTMT are specified for the OPTION parameter. *NONE Disables all of the debug options for debugging the compiled program object. OUTPUT Specifies if a compiler listing is generated. *PRINT Produces a compiler listing, consisting of the ILE RPG program source and all compile-time messages. The information contained in the listing is dependent on whether *XREF, *SECLVL, *SHOWCPY, *EXPDDS, *EXT, *SHOWSKP, and *SRCSTMT are specified for the OPTION parameter. *NONE Do not generate the compiler listing. OPTIMIZE Specifies the level of optimization, if any, of the program.
Appendix C. The Create Commands
435
CRTBNDRPG Command
*NONE Generated code is not optimized. This is the fastest in terms of translation time. It allows you to display and modify variables while in debug mode. *BASIC Some optimization is performed on the generated code. This allows user variables to be displayed but not modified while the program is in debug mode. *FULL Optimization which generates the most efficient code. Translation time is the longest. In debug mode, user variables may not be modified but may be displayed although the presented values may not be current values. INDENT Specifies whether structured operations should be indented in the source listing for enhanced readability. Also specifies the characters that are used to mark the structured operation clauses. Note: Any indentation that you request here will not be reflected in the listing debug view that is created when you specify DBGVIEW(*LIST). *NONE Structured operations will not be indented in the source listing. character-value The source listing is indented for structured operation clauses. Alignment of statements and clauses are marked using the characters you choose. You can choose any character string up to 2 characters in length. If you want to use a blank in your character string, you must enclose the string in single quotation marks. Note: The indentation may not appear as expected if there are errors in the program. CVTOPT Specifies how the ILE RPG compiler handles date, time, timestamp, graphic data types, and variable-length data types which are retrieved from externally described database files. *NONE Ignores variable-length database data types and use the native RPG date, time, timestamp and graphic data types. *DATETIME Specifies that date, time, and timestamp database data types are to be declared as fixed-length character fields. *GRAPHIC Specifies that double-byte character set (DBCS) graphic data types are to be declared as fixed-length character fields. *VARCHAR Specifies that variable-length character data types are to be declared as fixed-length character fields. *VARGRAPHIC Specifies that variable-length double-byte character set (DBCS) graphic data types are to be declared as fixed-length character fields.
436
CRTBNDRPG Command
SRTSEQ Specifies the sort sequence table that is to be used in the ILE RPG source program. *HEX No sort sequence table is used. *JOB Use the SRTSEQ value for the job when the *PGM is created. *JOBRUN Use the SRTSEQ value for the job when the *PGM is run. *LANGIDUNQ Use a unique-weight table. This special value is used in conjunction with the LANGID parameter to determine the proper sort sequence table. *LANGIDSHR Use a shared-weight table. This special value is used in conjunction with the LANGID parameter to determine the proper sort sequence table. sort-table-name Enter the qualified name of the sort sequence table to be used with the program. *LIBL The system searches the library list to find the library where the sort sequence table is stored. *CURLIB The current library is used to find the sort sequence table. If you have not specified a current library, QGPL is used. library-name Enter the name of the library where the sort sequence table is stored. | | | If you want to use the SRTSEQ and LANGID parameters to determine the alternate collating sequence, you must also specify ALTSEQ(*EXT) on the control specification. LANGID Specifies the language identifier to be used when the sort sequence is *LANGIDUNQ and *LANGIDSHR. The LANGID parameter is used in conjunction with the SRTSEQ parameter to select the sort sequence table. *JOBRUN Use the LANGID value associated with the job when the RPG program is executed. *JOB Use the LANGID value associated with the job when the RPG program is created. language-identifier Use the language identifier specified. (For example, FRA for French and DEU for German.) REPLACE Specifies if a new program is created when a program of the same name already exists in the specified (or implied) library. The intermediate module created during the processing of the CRTBNDRPG command are not subject to
437
CRTBNDRPG Command
the REPLACE specifications, and have an implied REPLACE(*NO) against the QTEMP library. The intermediate modules is deleted once the CRTBNDRPG command has completed processing. *YES A new program is created in the specified library. The existing program of the same name in the specified library is moved to library QRPLOBJ. *NO A new program is not created if a program of the same name already exists in the specified library. The existing program is not replaced, a message is displayed, and compilation stops. USRPRF Specifies the user profile that will run the created program object. The profile of the program owner or the program user is used to run the program and to control which objects can be used by the program (including the authority the program has for each object). This parameter is not updated if the program already exists. To change its value, you must delete the program and recompile using the new value (or, if the constituent *MODULE objects exist, you may choose to invoke the CRTPGM command). *USER The program runs under the user profile of the programs user. *OWNER The program runs under the user profile of both the programs user and owner. The collective set of object authority in both user profiles are used to find and access objects while the program is running. Any objects created during the program are owned by the programs user. AUT Specifies the authority given to users who do not have specific authority to the object, who are not on the authorization list, and whose user group has no specific authority to the object. The authority can be altered for all users or for specified users after the program is created with the CL commands Grant Object Authority (GRTOBJAUT) or Revoke Object Authority (RVKOBJAUT). For further information on these commands, see the CL and APIs section of the Programming category in the iSeries 400 Information Center at this Web site http://www.ibm.com/eserver/iseries/infocenter. *LIBCRTAUT The public authority for the object is taken from the CRTAUT keyword of the target library (the library that contains the object). The value is determined when the object is created. If the CRTAUT value for the library changes after the create, the new value will not affect any existing objects. *ALL Authority for all operations on the program object, except those limited to the owner or controlled by authorization list management authority. The user can control the program objects existence, specify this security for it, change it, and perform basic functions on it, but cannot transfer its ownership. *CHANGE Provides all data authority and the authority to perform all operations on the program object except those limited to the owner or controlled by object authority and object management authority. The user can change the object and perform basic functions on it.
438
CRTBNDRPG Command
*USE Provides object operational authority and read authority; that is, authority for basic operations on the program object. The user is prevented from changing the object. *EXCLUDE The user is prevented from accessing the object. authorization-list name Enter the name of an authorization list of users and authorities to which the program is added. The program object will be secured by this authorization list, and the public authority for the program object will be set to *AUTL. The authorization list must exist on the system when the CRTBNDRPG command is issued. Note: Use the AUT parameter to reflect the security requirements of your system. The security facilities available are described in detail in the iSeries Security Reference manual. TRUNCNBR Specifies if the truncated value is moved to the result field or an error is generated when numeric overflow occurs while running the program. Note: The TRUNCNBR option does not apply to calculations performed within expressions. (Expressions are found in the Extended-Factor 2 field.) If overflow occurs for these calculations, an error will always occur. In addition, overflow is always signalled for any operation where the value that is assigned to an integer or unsigned field is out of range. *YES Ignore numeric overflow and move the truncated value to the result field. *NO When numeric overflow is detected, a run time error is generated with error code RNX0103. FIXNBR Specifies whether decimal data that is not valid is fixed by the compiler. *NONE Indicates that decimal data that is not valid will result in decimal data errors during run time if used. *ZONED Zoned-decimal data that is not valid will be fixed by the compiler on the conversion to packed data. Blanks in numeric fields will be treated as zeroes. Each decimal digit will be checked for validity. If a decimal digit is not valid, it is replaced with zero. If a sign is not valid, the sign will be forced to a positive sign code of hex F. If the sign is valid, it will be changed to either a positive sign hex F or a negative sign hex D, as appropriate. If the resulting packed data is not valid, it will not be fixed. *INPUTPACKED Indicates that if packed decimal data that is not valid is encountered while processing input specifications, the internal variable will be set to zero. TGTRLS Specifies the release level of the operating system on which you intend to use the object being created. In the examples given for the *CURRENT and *PRV values, and when specifying the target-release value, the format VxRxMx is
439
CRTBNDRPG Command
used to specify the release, where Vx is the version, Rx is the release, and Mx is the modification level. For example, V2R3M0 is version 2, release 3, modification level 0. Valid values for this parameter change every release. The possible values are: *CURRENT The object is to be used on the release of the operating system currently running on your system. For example, if V2R3M5 is running on the system, *CURRENT means that you intend to use the object on a system with V2R3M5 installed. You can also use the object on a system with any subsequent release of the operating system installed. Note: If V2R3M5 is running on the system, and the object is to be used on a system with V2R3M0 installed, specify TGTRLS(V2R3M0), not TGTRLS(*CURRENT). *PRV The object is to be used on the previous release with modification level 0 of the operating system. For example, if V2R3M5 is running on your system, *PRV means you intend to use the object on a system with V2R2M0 installed. You can also use the object on a system with any subsequent release of the operating system installed. target-release Specify the release in the format VxRxMx. You can use the object on a system with the specified release or with any subsequent release of the operating system installed. Valid values depend on the current version, release, and modification level, and they change with each new release. If you specify a target-release that is earlier than the earliest release level supported by this command, an error message is sent indicating the earliest supported release. Note: The current version of the command may support options that are not available in previous releases of the command. If the command is used to create objects that are to be used on a previous release, it will be processed by the compiler appropriate to that release, and any unsupported options will not be recognized. The compiler will not necessarily issue any warnings regarding options that it is unable to process. ALWNULL Specifies how the ILE RPG module will be allowed to use records containing null-capable fields from externally described database files. *NO Specifies that the ILE RPG module will not process records with null-value fields from externally-described files. If you attempt to retrieve a record containing null values, no data in the record is accessible to the ILE RPG module and a data-mapping error occurs. *INPUTONLY Specifies that the ILE RPG module can successfully read records with null-capable fields containing null values from externally-described input-only database files. When a record containing null values is retrieved, no data-mapping errors occur and the database default values are placed into any fields that contain null values. The module cannot do any of the following: v use null-capable key fields
440
CRTBNDRPG Command
v create or update records containing null-capable fields v determine whether a null-capable field is actually null while the module is running v set a null-capable field to be null. *USRCTL Specifies that the ILE RPG module can read, write, and update records with null values from externally-described database files. Records with null keys can be retrieved using keyed operations. The module can determine whether a null-capable field is actually null, and it can set a null-capable field to be null for output or update. The programmer is responsible for ensuring that fields containing null values are used correctly within the module. *YES Same as *INPUTONLY. BNDDIR Specifies the list of binding directories that are used in symbol resolution. *NONE No binding directory is specified. binding-directory-name Specify the name of the binding directory used in symbol resolution. The directory name can be qualified with one of the following library values: *LIBL The system searches the library list to find the library where the binding directory is stored. *CURLIB The current library for the job is searched. If no library is specified as the current library for the job, library QGPL is used. *USRLIBL Only the libraries in the user portion of the jobs library list are searched. library-name Specify the name of the library to be searched. ACTGRP Specifies the activation group this program is associated with when it is called. QILE When this program is called, it is activated into the named activation group QILE. *NEW When this program is called, it is activated into a new activation group. *CALLER When this program is called, it is activated into the callers activation group. activation-group-name Specify the name of the activation group to be used when this program is called. ENBPFRCOL Specifies whether performance collection is enabled.
Appendix C. The Create Commands
441
CRTBNDRPG Command
*PEP Performance statistics are gathered on the entry and exit of the program entry procedure only. This applies to the actual program-entry procedure for a program, not to the main procedure of the modules within the program. This is the default. *NEW When this program is called, it is activated into a new activation group. *ENTRYEXIT Performance statistics are gathered on the entry and exit of all procedures of the program. *FULL Performance statistics are gathered on entry and exit of all procedures. Also, statistics are gathered before and after each call to an external procedure. DEFINE Specifies condition names that are defined before the compilation begins. Using the parameter DEFINE(condition-name) is equivalent to coding the /DEFINE condition-name directive on the first line of the source file. *NONE No condition names are defined. This is the default. condition-name Up to 32 condition names can be specified. Each name can be up to 50 characters long. The condition names will be considered to be defined at the start of compilation. PRFDTA Specifies the program profiling data attribute for the program. Program profiling is an advanced optimization technique used to reorder procedures and code within the procedures based on statistical data (profiling data). *NOCOL This program is not enabled to collect profiling data. This is the default. *COL The program is enabled to collect profiling data. *COL can be specified only when the optimization level of the module is *FULL, and when compiling with a target release of *CURRENT. | | | | | LICOPT Specifies one or more Licensed Internal Code compile-time options. This parameter allows individual compile-time options to be selected, and is intended for the advanced programmer who understands the potential benefits and drawbacks of each selected type of compiler option.
CRTRPGMOD Command
The Create RPG Module (CRTRPGMOD) command compiles ILE RPG source code to create a module object (*MODULE). The entire syntax diagram for the CRTRPGMOD command is shown below. Job: B,I Pgm: B,I REXX: B,I
*CURLIB/ library-name/
Exec
*CTLSPEC module-name
CRTRPGMOD MODULE (
442
CRTRPGMOD Command
SRCFILE ( *LIBL/ *CURLIB/ library-name/ QRPGLESRC source-file-name )
GENLVL
10 severity-level-value
TEXT
OPTION
OPTION Details
DBGVIEW
OUTPUT
*PRINT *NONE
OPTIMIZE
INDENT
*NONE character-value
CVTOPT
SRTSEQ
sort-table-name
LANGID
REPLACE
*YES *NO
AUT
TRUNCNBR
*YES *NO
443
CRTRPGMOD Command
FIXNBR ( *NONE *ZONED *INPUTPACKED )
TGTRLS (
ALWNULL (
BNDDIR (
ENBPFRCOL (
DEFINE (
*NONE condition-name
PRFDTA (
*NOCOL *COL
LICOPT ( options )
OPTION Details:
*XREF *NOXREF *EXT *NOEXT *GEN *NOGEN *NOSHOWSKP *SHOWSKP *NOSECLVL *SECLVL *NOSRCSTMT *SRCSTMT *SHOWCPY *NOSHOWCPY *DEBUGIO *NODEBUGIO *EXPDDS *NOEXPDDS *NOEVENTF *EVENTF
444
CRTRPGMOD Command
programs. (When looking at the CRTBNDRPG descriptions, keep in mind that CRTRPGMOD does not have the following parameters: ACTGRP, DFTACTGRP, USRPRF.) A description of CRTRPGMOD is also available online. Enter the command name on a command line, press PF4 (Prompt) and then press PF1 (Help) for any parameter you want information on.
445
CRTRPGMOD Command
446
447
Compiler Listings
Table 33. Sections of the Compiler Listing (continued) Listing Section1 Binding section
3
OPTION2
Description Errors (if any) which occur during binding phase for CRTBNDRPG command
Notes: 1. The information contained in the listing section is dependent on whether *SRCSTMT or *NOSRCSTMT is specified for the OPTION parameter. For details on how this information changes, see *NOSRCSTMT Source Heading on page 454 and *SRCSTMT Source Heading on page 454. *SRCSTMT allows you to request that the compiler use SEU sequence numbers and source IDs when generating statement numbers for debugging. Otherwise, statement numbers are associated with the Line Numbers of the listing and the numbers are assigned sequentially. 2. The OPTION column indicates what value to specify on the OPTION parameter to obtain this information. A blank entry means that the information will always appear if OUTPUT(*PRINT) is specified. 3. The sections containing the code generation errors and binding errors appear only if there are errors. There is no option to suppress these sections.
Prologue
The prologue section summarizes the command parameters and their values as they were processed by the CL command analyzer. If *CURLIB or *LIBL was specified, the actual library name is listed. Also indicated in the prologue is the effect of overrides. Figure 230 on page 449 illustrates how to interpret the Prologue section of the listing for the program MYSRC, which was compiled using the CRTBNDRPG command.
448
Compiler Listings
5769RG1 V4R4M0 990521 RN Command . . . . . . . . . Issued by . . . . . . . Program . . . . . . . . . Library . . . . . . . . Text 'description' . . . . Source Member . . . . . . Source File . . . . . . . Library . . . . . . . . CCSID . . . . . . . . . Text 'description' . . . . Last Change . . . . . . . Generation severity level Default activation group . Compiler options . . . . . Debugging views . . . . . Output . . . . . . . . . . Optimization level . . . . Source listing indentation Type conversion options . Sort sequence . . . . . . Language identifier . . . Replace program . . . . . User profile . . . . . . . Authority . . . . . . . . Truncate numeric . . . . . Fix numeric . . . . . . . Target release . . . . . . Allow null values . . . . Binding directory . . . . Library . . . . . . . . Activation group . . . . . Define condition names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . IBM ILE RPG MYLIB/MYSRC 1a . : CRTBNDRPG . : MYUSERID . : MYSRC 2 . : MYLIB . : Text specified on the Command . : MYSRC 3 . : QRPGLESRC 4 . : MYLIB . : 37 . : Text specified on the Source Member . : 98/07/27 12:50:13 . : 10 . : *NO . : *XREF *GEN *SECLVL *SHOWCPY *EXPDDS *EXT *SHOWSKP *NOSRCSTMT *DEBUGIO *NOEVENTF . : *ALL . : *PRINT . : *NONE . : '| ' 6 . : *NONE . : *HEX . : *JOBRUN . : *YES . : *USER . : *LIBCRTAUT . : *YES . : *ZONED *INPUTPACKED . : *CURRENT . : *NO . : BNDDIRA BNDDIRB . : CMDLIBA CMDLIBB . : CMDACTGRP . : ABC 7 DEF . : *PEP . : *NOCOL AS400S01 98/07/27 12:58:46 Page 1
1 Page Heading The page heading information includes the product information line and the text supplied by a /TITLE directive. Customizing a Compiler Listing on page 66 describes how you can customize the page heading and spacing in a compiler listing. 2 Module or Program The name of the created module object (if using CRTRPGMOD) or the name of the created program object (if using CRTBNDRPG) 3 Source member The name of the source member from which the source records were retrieved (this can be different from 2 if you used command overrides). 4 Source The name of the file actually used to supply the source records. If the file is overridden, the name of the overriding source is used. 5 Compiler options The compiler options in effect at the time of compilation, as specified on either the CRTRPGMOD command or the CRTBNDRPG command. 6 Indentation Mark The character used to mark structured operations in the source section of the listing. 7 Define condition names Specifies the condition names that take effect before the source is read.
Source Section
The source section shows records that comprise the ILE RPG source specifications. The root source member records are always shown. If OPTION(*EXPDDS) is also
Appendix D. Compiler Listings
449
Compiler Listings
specified, then the source section shows records generated from externally described files, and marks them with a = in the column beside the line number. These records are not shown if *NOEXPDDS is specified. If OPTION(*SHOWCPY) is specified, then it also shows the records from /COPY members specified in the source, and marks them with a + in the column beside the line number. These records are not shown if *NOSHOWCPY is specified. The source section also shows the conditional compilation process. All lines with /IF, /ELSEIF, /ELSE and /ENDIF directives and source lines selected by the /IF groups are printed and given a listing line number. If OPTION(*SHOWSKP) is specified, it shows all statements that have been excluded by the /IF, /ELSEIF, and /ELSE directives, and marks them with a ------- in the column beside the statement. Line numbers in the listing are not incremented for excluded lines. All skipped statements are printed exactly as specified, but are not interpreted in any way. For example, an excluded statement with an /EJECT directive does not cause a page break. Similarly, /SPACE, /TITLE, /COPY and /EOF compiler directives are ignored if they are encountered in excluded lines. These statements are not shown if the default OPTION(*NOSHOWSKP) is specified; instead a message is printed giving the number of lines excluded. The source section identifies any syntax errors in the source, and includes a match-field table, when appropriate. If OPTION(*NOSRCSTMT) is specified, line numbers are printed sequentially on the left side of the listing to reflect the compiled source line numbers. Source IDs and SEU sequence numbers are printed on the right side of the listing to identify the source members and records respectively. For example, Figure 231 shows a section of the listing with a /COPY statement in line 35. In the root source member, the next line is a DOWEQ operation. In the listing, however, the DOWEQ operation is on line 39. The three intervening lines shown in the listing are from the /COPY source member.
Line Number 34 35 <--------------------- Source Specifications ----------------------------------------------><---- Comments ----> Src Seq ....1....+....2....+<-------- 26 - 35 -------->....4....+....5....+....6....+....7....+....8....+....9....+...10 Id Number C MOVE '123' BI_FLD1 001500 C/COPY MYCPY 971104 001600 *--------------------------------------------------------------------------------------------* * RPG member name . . . . . : MYCPY * 5 * External name . . . . . . : RPGGUIDE/QRPGLESRC(MYCPY) * 5 * Last change . . . . . . . : 98/07/24 16:20:04 * 5 * Text 'description' . . . . : Text on copy member * 5 *--------------------------------------------------------------------------------------------* 36+C Blue(1) DSPLY 5000100 37+C Green(4) DSPLY 5000200 38+C Red(2) DSPLY 5000300 39 C *in20 doweq *OFF 001700
If OPTION(*SRCSTMT) is specified, sequence numbers are printed on the left side of the listing to reflect the SEU sequence numbers. Statement numbers are printed on the right side of the listing. The statement number information is identical to the source ID and SEU sequence number information. For example, Figure 232 on page 451 shows a section of the listing that has a /COPY statement with sequence number 001600. The next line in the root source member is the same as the line with the next sequence number in the listing: sequence number 001700. The three intervening lines are assigned the SEU sequence numbers from the /COPY source member. The corresponding statement numbers are genereated from source IDs and SEU sequence numbers of the root and /COPY source members.
450
Compiler Listings
Seq Number 001500 001600 <--------------------- Source Specifications ----------------------------------------------><---- Comments ----> Statement ....1....+....2....+<-------- 26 - 35 -------->....4....+....5....+....6....+....7....+....8....+....9....+...10 Number C MOVE '123' BI_FLD1 001500 C/COPY MYCPY 971104 001600 *--------------------------------------------------------------------------------------------* * RPG member name . . . . . : MYCPY * 5 * External name . . . . . . : RPGGUIDE/QRPGLESRC(MYCPY) * 5 * Last change . . . . . . . : 98/07/24 16:20:04 * 5 * Text 'description' . . . . : Text on copy member * 5 *--------------------------------------------------------------------------------------------* 000100+C Blue(1) DSPLY 5000100 000200+C Green(4) DSPLY 5000200 000300+C Red(2) DSPLY 5000300 001700 C *in20 doweq *OFF 001700
Figure 233 on page 452 shows the entire source section for MYSRC with OPTION(*NOSRCSTMT) specified.
451
Compiler Listings
5769RG1 V4R4M0 990521 RN IBM ILE RPG MYLIB/MYSRC AS400S01 98/07/28 14:21:00 1a Line <---------------------- Source Specifications ----------------------------><---- Comments ----> Do Page Number ....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+...10 Num Line S o u r c e L i s t i n g 1 H DFTACTGRP(*NO) ACTGRP('Srcactgrp') CCSID(*GRAPH:*SRC) 2 H OPTION(*NODEBUGIO) 3 H BNDDIR('SRCLIB1/BNDDIR1' : 'SRCLIB2/BNDDIR2' : '"ext.nam"') 4 H ALTSEQ(*SRC) 5 H FIXNBR(*ZONED) 6 H TEXT('Text specified on the Control Specification') *--------------------------------------------------------------------* 2 * Compiler Options in Effect: * *--------------------------------------------------------------------* * Text 'description' . . . . . . . : * * Text specified on the Control Specification * * Generation severity level . . . : 10 * * Default activation group . . . . : *NO * * Compiler options . . . . . . . . : *XREF *GEN * * *SECLVL *SHOWCPY * * *EXPDDS *EXT * * *SHOWSKP *NOSRCSTMT * * *NODEBUGIO *NOEVENTF * * Optimization level . . . . . . . : *NONE * * Source listing indentation . . . : '| ' * * Type conversion options . . . . : *NONE * * Sort sequence . . . . . . . . . : *HEX * * Language identifier . . . . . . : *JOBRUN * * User profile . . . . . . . . . . : *USER * * Authority . . . . . . . . . . . : *LIBCRTAUT * * Truncate numeric . . . . . . . . : *YES * * Fix numeric . . . . . . . . . . : *ZONED *INPUTPACKED * * Allow null values . . . . . . . : *NO * * Binding directory from Command . : BNDDIRA BNDDIRB * * Library . . . . . . . . . . . : CMDLIBA CMDLIBB * * Binding directory from Source . : BNDDIR1 BNDDIR2 * * Library . . . . . . . . . . . : SRCLIB1 SRCLIB2 * * "ext.nam" * * *LIBL * * Activation group . . . . . . . . : Srcactgrp * * Enable performance collection . : *PEP * * Profiling data . . . . . . . . . : *NOCOL * *--------------------------------------------------------------------* 7 FInFile IF E DISK *--------------------------------------------------------------------------------------------* 3 * RPG name External name * * File name. . . . . . . . . : INFILE MYLIB/INFILE * * Record format(s) . . . . . : INREC INREC * *--------------------------------------------------------------------------------------------* 8 FKEYL6 IF E K DISK *--------------------------------------------------------------------------------------------* * RPG name External name * * File name. . . . . . . . . : KEYL6 MYLIB/KEYL6 * * Record format(s) . . . . . : REC1 REC1 * * REC2 REC2 * *--------------------------------------------------------------------------------------------* 9 FOutfile O E DISK *--------------------------------------------------------------------------------------------* * RPG name External name * * File name. . . . . . . . . : OUTFILE MYLIB/OUTFILE * * Record format(s) . . . . . : OUTREC OUTREC * *--------------------------------------------------------------------------------------------* 10 D Blue S 4 DIM(5) CTDATA PERRCD(1) 11 D Green S 2 DIM(5) ALT(Blue) 12 D Red S 4 DIM(2) CTDATA PERRCD(1) 13 D DSEXT1 E DS 100 PREFIX(BI_) INZ(*EXTDFT) 14 D FLD3 E INZ('111') Page 2
Change Src Seq Date Id Number 980727 980727 971104 971104 980728 971104 000100 000200 000300 000400 000500 000600
971104
000700
971104
000800
971104
000900
452
Compiler Listings
*--------------------------------------------------------------------------------------------* * Data structure . . . . . . : DSEXT1 * * Prefix . . . . . . . . . . : BI_ : 0 * * External format . . . . . : REC1 : MYLIB/DSEXT1 * * Format text . . . . . . . : Record format description * *--------------------------------------------------------------------------------------------* 4 1 1 1 1 1 1
5 15=D BI_FLD1 5A EXTFLD (FLD1) FLD1 description 1000001 16=D INZ (*BLANK) 1000002 17=D BI_FLD2 10A EXTFLD (FLD2) FLD2 description 1000003 18=D INZ (*BLANK) 1000004 19=D BI_FLD3 18A EXTFLD (FLD3) FLD3 description 1000005 20=D INZ ('111') 1000006 21=IINREC 2000001 *--------------------------------------------------------------------------------------------* 2 * RPG record format . . . . : INREC * 2 * External format . . . . . : INREC : MYLIB/INFILE * 2 *--------------------------------------------------------------------------------------------* 2 22=I A 1 25 FLDA 2000002 23=I A 26 90 FLDB 2000003 24=I 13488 *VAR C 91 112 UCS2FLD 2000004 25=IREC1 3000001 *--------------------------------------------------------------------------------------------* 3 * RPG record format . . . . : REC1 * 3 * External format . . . . . : REC1 : MYLIB/KEYL6 * 3 *--------------------------------------------------------------------------------------------* 3 26=I *ISO-D 1 10 FLD12 3000002 27=I A 11 13 FLD13 3000003 28=I A 14 17 FLD14 3000004 29=I A 18 22 FLD15 3000005 30=I 13488 C 23 32 FLDC 3000006 31=I 13488 *VAR C 33 44 FLDCV 3000007 32=I 835 G 45 54 FLDG 3000008 33=IREC2 4000001 *--------------------------------------------------------------------------------------------* 4 * RPG record format . . . . : REC2 * 4 * External format . . . . . : REC2 : MYLIB/KEYL6 * 4 *--------------------------------------------------------------------------------------------* 4 34=I *ISO-D 1 10 FLD22 4000002 35=I A 11 13 FLD23 4000003 36=I A 14 17 FLD24 4000004 37=I A 18 22 FLD25 4000005 Line <--------------------- Source Specifications ----------------------------------------------><---- Comments ----> Src Seq Number ....1....+....2....+<-------- 26 - 35 -------->....4....+....5....+....6....+....7....+....8....+....9....+...10 Id Number 38 C MOVE '123' BI_FLD1 001500 39 C/COPY MYCPY 971104 001600 *--------------------------------------------------------------------------------------------* 6 * RPG member name . . . . . : MYCPY * 5 * External name . . . . . . : MYLIB/QRPGLESRC(MYCPY) * 5 * Last change . . . . . . . : 98/07/24 16:20:04 * 5 * Text 'description' . . . . : Text specified on Copy Member * 5 *--------------------------------------------------------------------------------------------* 7 40+C Blue(1) DSPLY 5000100 41+C Green(4) DSPLY 5000200 42+C Red(2) DSPLY 5000300 8 43 C *in20 doweq *OFF 001700 44 C | READ InRec ----20 001800 45 C | if NOT *in20 001900 46 C FLDA | | DSPLY 002000 47 C | endif 002100 48 C enddo 002200 49 C write outrec 002300 9 50 C SETON LR---002400 47 C/DEFINE ABC 971104 002500 51 C/IF DEFINED(ABC) 971104 002600 52 C MOVEL 'x' Y 10 002700 54 C MOVEL 'x' Z 10 002800 55 C/ELSE 971104 002900 10 ------ C MOVEL ' ' Y 10 971104 003000 ------ C MOVEL ' ' Z 10 971104 003100 56 C/ENDIF 971104 003200
453
Compiler Listings
Line <---------------------- Source Specifications ----------------------------><---- Comments ----> Do Page Change Src Seq Number ....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+...10 Num Line Date Id Number 57=OOUTREC 6000001 *--------------------------------------------------------------------------------------------* 6 * RPG record format . . . . : OUTREC * 6 * External format . . . . . : OUTREC : MYLIB/OUTFILE * 6 *--------------------------------------------------------------------------------------------* 6 58=O FLDY 100A CHAR 100 6000002 59=O FLDZ 132A CHAR 32 6000003 60=O GRAPHFLD 156G GRPH 12 835 6000004 * * * * * E N D O F S O U R C E * * * * *
1a *NOSRCSTMT Source Heading The source heading shown in the above example was generated with OPTION(*NOSRCSTMT) specified. Line Number Starts at 1 and increments by 1 for each source or generated record. Use this number when debugging using statement numbers. Ruler Line This line adjusts when indentation is specified. Do Number Identifies the level of the structured operations. This number will not appear if indentation is requested. Page Line Shows the first 5 columns of the source record. Source Id Identifies the source (either /COPY or DDS) of the record. For /COPY members, it can be used to obtain the external member name from the /COPY member table. Sequence Number (on right side of listing) Shows the SEU sequence number of the record from a member in a source physical file. Shows an incremental number for records from a /COPY member or records generated from DDS. 1b *SRCSTMT Source Heading When OPTION(*SRCSTMT) is specified, the source heading changes to: The Ruler Line, Do Number, and Page Line remain unchanged.
1b Seq <---------------------- Source Specifications ----------------------------><---- Comments ----> Do Page Change Statement Number ....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+...10 Num Line Date Number
Sequence Number (on left side of listing) Shows the SEU sequence number of the record from a member in a source physical file. Shows an incremental number for records from a /COPY member or records generated from DDS. Statement Number Shows the statement number generated from the source ID number and the SEU sequence number as follows:
stmt_num = source_ID * 1000000 + source_SEU_sequence_number
Use this number when debugging using statement numbers. 2 Compiler Options in Effect Identifies the compiler options in effect. Displayed when compile-option keywords are specified on the control specification.
454
Compiler Listings
3 File/Record Information Identifies the externally described file and the records it contains. 4 DDS Information Identifies from which externally described file the field information is extracted. Shows the prefix value, if specified. Shows the format record text if specified in the DDS. 5 Generated Specifications Shows the specifications generated from the DDS, indicated by = beside the Line Number. Shows up to 50 characters of field text if it is specified in the DDS. Shows the initial value as specified by the INZ keyword on the definition specification. If INZ(*EXTDFT) is specified for externally described data structure subfields, the DDS default value is displayed. Default values that are too long to fit on one line are truncated and suffixed with '...'. 6 /COPY Member Information Identifies which /COPY member is used. Shows the member text, if any. Shows the date and time of the last change to the member. 7 /COPY Member Records Shows the records from the /COPY member, indicated by a + beside the Line Number. 8 Indentation Shows how structured operations appear when you request that they be marked. 9 Indicator Usage Shows position of unused indicators, when an indicator is used. 10 OPTION(*SHOWSKP) Usage Shows two statements excluded by an /IF directive, indicated by a ------- beside the statements. If the OPTION(*NOSHOWSKP) was specified these two statements would be replaced by: LINES EXCLUDED: 2.
A d d i t i o n a l D i a g n o s t i c M e s s a g e s Sv Number Seq Message text 00 8 000800 Record-Format REC1 not used for input or output. 00 8 000800 Record-Format REC2 not used for input or output. 00 60 000004 RPG handles blocking for file INFILE. INFDS is updated only when blocks of data are transferred. *RNF7086 00 60 000004 RPG handles blocking for file OUTFILE. INFDS is updated only when blocks of data are transferred. * * * * * E N D O F A D D I T I O N A L D I A G N O S T I C M E S S A G E S Msg id *RNF7066 *RNF7066 *RNF7086
* * * * *
If OPTION(*SRCSTMT) is specified, the messages will have only the statement number shown. Figure 235 on page 456 shows an example.
455
Compiler Listings
A d d i t i o n a l D i a g n o s t i c M e s s a g e s Sv Statement Message text 00 000800 Record-Format REC1 not used for input or output. 00 000800 Record-Format REC2 not used for input or output. 00 6000004 RPG handles blocking for file INFILE. INFDS is updated only when blocks of data are transferred. *RNF7086 00 6000004 RPG handles blocking for file OUTFILE. INFDS is updated only when blocks of data are transferred. * * * * * E N D O F A D D I T I O N A L D I A G N O S T I C M E S S A G E S Msg id *RNF7066 *RNF7066 *RNF7086
* * * * *
B U F F E R
P O S I T I O N
* * * *
Compile-Time Data
The Compile-Time Data section includes information on ALTSEQ or NLSS tables, and on tables and arrays. In this example, there is an alternate collating sequence and two arrays, as shown in Figure 238 on page 457.
456
Compiler Listings
C o m p i l e T i m e D a t a 61 ** *--------------------------------------------------------------------* * Alternate Collating Sequence Table Data: * *--------------------------------------------------------------------* 62 ALTSEQ 1122ACAB4B7C36F83A657D73 Line <---------------------- Data Records --------------------------------------------------------------> Number ....+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+...10 *--------------------------------------------------------------------* * Alternate Collating Sequence Table: * * Number of characters with an altered sequence . . . . . . : 6 1 * * 2 0_ 1_ 2_ 3_ 4_ 5_ 6_ 7_ 8_ 9_ A_ B_ C_ D_ E_ F_ * * _0 . . . . . . . . . . . . . . . . _0 * * _1 . 22 3 . . . . . . . . . . . . . _1 * * _2 . . . . . . . . . . . . . . . . _2 * * _3 . . . . . . . . . . . . . . . . _3 * * _4 . . . . . . . . . . . . . . . . _4 * * _5 . . . . . . . . . . . . . . . . _5 * * _6 . . . F8 . . . . . . . . . . . . _6 * * _7 . . . . . . . . . . . . . . . . _7 * * _8 . . . . . . . . . . . . . . . . _8 * * _9 . . . . . . . . . . . . . . . . _9 * * _A . . . 65 . . . . . . . . . . . . _A * * _B . . . . 7C . . . . . . . . . . . _B * * _C . . . . . . . . . . AB . . . . . _C * * _D . . . . . . . 73 . . . . . . . . _D * * _E . . . . . . . . . . . . . . . . _E * * _F . . . . . . . . . . . . . . . . _F * * 0_ 1_ 2_ 3_ 4_ 5_ 6_ 7_ 8_ 9_ A_ B_ C_ D_ E_ F_ * *--------------------------------------------------------------------* 63 ** *--------------------------------------------------------------------* * Array . . . : BLUE 4 Alternating Array . . . . : GREEN * *--------------------------------------------------------------------* 64 1234ZZ 65 ABCDYY 66 5432XX 67 EDCBWW 68 ABCDEF 69 ** *--------------------------------------------------------------------* * Array . . . : RED * *--------------------------------------------------------------------* 70 3861 71 TJKL * * * * * E N D O F C O M P I L E T I M E D A T A * * * * * 971104 003300
971104
003500
971104 971104
00420 00430
1 Total Number of Characters Altered Shows the number of characters whose sort sequence has been altered. 2 Character to be Altered The rows and columns of the table together identify the characters to be altered. For example, the new value for character 3A is 65, found in column 3_ and row _A. 3 Alternate Sequence The new hexadecimal sort value of the selected character. 4 Array/Table information Identifies the name of the array or table for which the compiler is expecting data. The name of the alternate array is also shown, if it is defined.
457
Compiler Listings
K e y F i e l d I n f o r m a t i o n File Internal External Record field name field name Attributes 2 KEYL6 Common Keys: DATE *ISO- 10 CHAR 3 REC1 FLD12 DATE *ISO- 10 FLD13 CHAR 3 FLD15 CHAR 5 FLDC UCS2 5 13488 FLDCV VUC2 5 13488 FLDG GRPH 5 835 REC2 FLD22 DATE *ISO- 10 FLD23 CHAR 3 * * * * * E N D O F K E Y F I E L D I N F O R M A T I O N
* * * * *
Cross-Reference Table
The Cross-Reference table contains at least three lists: v files and records v global fields v indicators In addition, it contains the local fields that are used by each subprocedure. Use this table to check where files, fields and indicators are used within the module/program. Note that the informational message RNF7031, which is issued when an identifier is not referenced, will only appear in the cross-reference section of the listing and in the message summary. It does not appear in the source section of the listing. Names longer than 122 characters, will appear in the cross-reference section of the listing split across multiple lines. The entire name will be printed with the characters ... at the end of the lines. If the final portion of the name is longer than 17 characters, the attributes and line numbers will be listed starting on the following line. Figure 240 on page 459 shows an example for the module TRANSRPT, which has two subprocedures. In this example, the Cross-Reference table shows the line numbers for each reference. If you specify OPTION(*SRCSTMT) instead of OPTION(*NOSRCSTMT), the statement numbers will be displayed for each reference and the cross reference listing can extend beyond the first 80 columns of the listing.
458
Compiler Listings
C r o s s R e f e r e n c e File and Record References: File Device References (D=Defined) Record CUSTFILE DISK 8D CUSTREC 0 44 *RNF7031 CUSTRPT DISK 9D ARREARS 0 60 79 Global Field References: Field Attributes References (D=Defined M=Modified) *INZSR BEGSR 63D AMOUNT P(10,2) 56M 83 95 CITY A(20) 53D 132 CURDATE D(10*ISO-) 42D 64M 92 CUSTNAME A(20) 50D 122 CUSTNUM P(5,0) 49D 124 DUEDATE A(10) 57M 84 91 EXTREMELY_LONG_PROCEDURE_NAME_THAT_REQUIRES_MORE_THAN_ONE_LINE_IN_THE_CROSS_REFERENCE_EVEN_THOUGH_THE_ENTIRE_LINE_UP_TO_... COLUMN_132_IS_USED_TO_PRINT_THE_NAME... I(5,0) 9D PROTOTYPE FMTCUST PROTOTYPE 35D 59 113 114 134 INARREARS A(1) 30D 58 85 86 PROTOTYPE 101 LONG_FLOAT F(8) 7D 11M 12M NUMTOCHAR A(31) 22D 124 130 PROTOTYPE RPTADDR A(100) 59 82 RPTNAME C(100) 59 81 CCSID(13488) RPTNUM P(5,0) 80 SHORT_FLOAT F(4) 8D 10M *RNF7031 STATE A(2) 54D STREETNAME A(20) 52D 131 STREETNUM P(5,0) 51D 130 THIS_NAME_IS_NOT_QUITE_SO_LONG... A(5) 7D UDATE S(6,0) 64 *RNF7031 ZIP P(5,0) 55D INARREARS Field References: Field Attributes References (D=Defined M=Modified) DAYSLATE I(10,0) 88D 92M 94 DATEDUE D(10*ISO-) 89D 91M 92 FMTCUST Field References: Field Attributes References (D=Defined M=Modified) NAME A(100) 115D 122M BASED(_QRNL_PST+) ADDRESS A(100) 116D 130M BASED(_QRNL_PST+) Indicator References: Indicator References (D=Defined M=Modified) *RNF7031 01 44D * * * * * E N D O F C R O S S R E F E R E N C E * * * * *
459
Compiler Listings
E x t e r n a l R e f Statically bound procedures: Procedure PROTOTYPED PADDR_PROC CALLB_PROC Imported fields: Field Attributes IMPORT_FLD P(5,0) Exported fields: Field Attributes EXPORT_ARR(2) A(5) * * * * * E N D O F E X T E R N A L e r e n c e s References 2 4 6 Defined 3 Defined 2 R E F E R E N C E S 2
* * * * *
Message Summary
The message summary contains totals by severity of the errors that occurred. If OPTION(*SECLVL) is specified, it also provides second-level message text. Figure 242 shows an example.
M e s s a g e S u m m a r y Msg id Sv Number Message text *RNF7031 00 16 The name or indicator is not referenced. Cause . . . . . : The field, subfield, TAG, data structure, PLIST, KLIST, subroutine, indicator, or prototype is defined in the program, but not referenced. Recovery . . . : Reference the item, or remove it from the program. Compile again. *RNF7066 00 2 Record-Format name of Externally-Described file is not used. Cause . . . . . : There is a Record-Format name for an Externally-Described File that is not used on a valid input or output operation. Recovery . . . : Use the Record-Format name of the Externally-Described File for input or output, or specify the name as a parameter for keyword IGNORE. Compile again. *RNF7086 00 2 RPG handles blocking for the file. INFDS is updated only when blocks of data are transferred. Cause . . . . . : RPG specifies MLTRCD(*YES) in the UFCB (User-File-Control Block). Records are passed between RPG and data management in blocks. Positions 241 through the end of the INFDS (File-Information-Data Structure) are updated only when a block of records is read or written. Recovery . . . : If this information is needed after each read or write of a record, specify the OVRDBF command for the file with SEQONLY(*NO). * * * * * E N D O F M E S S A G E S U M M A R Y * * * * *
Final Summary
The final summary section provides final message statistics and source statistics. It also specifies the status of the compilation. Figure 243 shows an example.
F i n a l S u m m a r y Message Totals: Information (00) . . . . . . . : 20 Warning (10) . . . . . . . : 0 Error (20) . . . . . . . : 0 Severe Error (30+) . . . . . . : 0 --------------------------------- ------Total . . . . . . . . . . . . . : 20 Source Totals: Records . . . . . . . . . . . . : 71 Specifications . . . . . . . . : 55 Data records . . . . . . . . . : 8 Comments . . . . . . . . . . . : 0 * * * * * E N D O F F I N A L S U M M A R Y * * * * * Program MYSRC placed in library MYLIB. 00 highest severity. Created on 98/07/28 at 14:21:03. * * * * * E N D O F C O M P I L A T I O N * * * * *
460
Compiler Listings
461
462
Notices
This information was developed for products and services offered in the U.S.A. IBM may not offer the products, services, or features discussed in this document in other countries. Consult your local IBM representative for information on the products and services currently available in your area. Any reference to an IBM product, program, or service is not intended to state or imply that only that IBM product, program, or service may be used. Any functionally equivalent product, program, or service that does not infringe any IBM intellectual property right may be used instead. However, it is the users responsibility to evaluate and verify the operation of any non-IBM product, program, or service. IBM may have patents or pending patent applications covering subject matter described in this document. The furnishing of this document does not give you any license to these patents. You can send license inquiries, in writing, to: IBM Director of Licensing IBM Corporation North Castle Drive Armonk, NY 10504-1785 U.S.A. The following paragraph does not apply to the United Kingdom or any other country where such provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS PUBLICATION AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of express or implied warranties in certain transactions, therefore, this statement may not apply to you. This information could include technical inaccuracies or typographical errors. Changes are periodically made to the information herein; these changes will be incorporated in new editions of the publication. IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this publication at any time without notice. Any references in this information to non-IBM Web sites are provided for convenience only and do not in any manner serve as an endorsement of those Web sites. The materials at those Web sites are not part of the materials for this IBM product and use of those Web sites is at your own risk. IBM may use or distribute any of the information you supply in any way it believes appropriate without incurring any obligation to you. Licensees of this program who wish to have information about it for the purpose of enabling: (i) the exchange of information between independently created programs and other programs (including this one) and (ii) the mutual use of the information which has been exchanged, should contact: IBM Canada Ltd. Department 071 1150 Eglinton Avenue East
Copyright IBM Corp. 1994, 2001
463
North York, Ontario M3C 1H7 Canada Such information may be available, subject to appropriate terms and conditions, including in some cases, payment of a fee. The licensed program described in this information and all licensed material available for it are provided by IBM under terms of the IBM Customer Agreement, IBM International Program License Agreement, or any equivalent agreement between us. This information contains examples of data and reports used in daily business operations. To illustrate them as completely as possible, the examples include the names of individuals, companies, brands, and products. All of these names are fictitious and any similarity to the names and addresses used by an actual business enterprise is entirely coincidental. COPYRIGHT LICENSE: This information contains sample application programs in source language, which illustrates programming techniques on various operating platforms. You may copy, modify, and distribute these sample programs in any form without payment to IBM, for the purposes of developing, using, marketing or distributing application programs conforming to the application programming interface for the operating platform for which the sample programs are written. These examples have not been thoroughly tested under all conditions. IBM, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs. You may copy, modify, and distribute these sample programs in any form without payment to IBM for the purposes of developing, using, marketing, or distributing application programs conforming to IBMs application programming interfaces.
464
GDDM iSeries
WebSphere
Domino is a trademark of the Lotus Development Corporation in the United States, or other countries, or both. Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both. Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the United States and/or other countries. UNIX is a registered trademark in the United States and/or other countries licensed exclusively through X/Open Company Limited. Other company, product, and service names may be the trademarks or service marks of others. Registered trademarks and unregistered trademarks are denoted by respectively.
and
Notices
465
466
Bibliography
For additional information about topics related to ILE RPG programming on the iSeries system, refer to the following IBM iSeries publications: v ADTS/400: Application Development Manager Users Guide, SC09-2133-02, describes creating and managing projects defined for the Application Development Manager feature as well as using the program to develop applications. v ADTS/400: Programming Development Manager, SC09-1771-00, provides information about using the Programming Development Manager (PDM) to work with lists of libraries, objects, members, and user-defined options to easily do such operations as copy, delete, and rename. Contains activities and reference material to help the user learn PDM. The most commonly used operations and function keys are explained in detail using examples. v ADTS for AS/400: Source Entry Utility, SC09-2605-00, provides information about using the Application Development ToolSet Source Entry Utility (SEU) to create and edit source members. The manual explains how to start and end an SEU session and how to use the many features of this full-screen text editor. The manual contains examples to help both new and experienced users accomplish various editing tasks, from the simplest line commands to using pre-defined prompts for high-level languages and data formats. v Application Display Programming, SC41-5715-00, provides information about: Using DDS to create and maintain displays for applications; Creating and working with display files on the system; Creating online help information; Using UIM to define panels and dialogs for an application; Using panel groups, records, or documents v Backup and Recovery, SC41-5304-05, provides information about setting up and managing the following: Journaling, access path protection, and commitment control User auxiliary storage pools (ASPs) Disk protection (device parity, mirrored, and checksum) Provides performance information about backup media and save/restore operations. Also includes advanced backup and recovery topics, such as using save-while-active support, saving and restoring to a different release, and programming tips and techniques. v CL Programming, SC41-5721-04, provides a wide-ranging discussion of iSeries programming topics including a general discussion on objects and libraries, CL programming, controlling flow and communicating between programs, working with objects in CL programs, and creating CL programs. Other topics include predefined and impromptu messages and message handling, defining and creating user-defined commands and menus, application testing, including debug mode, breakpoints, traces, and display functions. v Communications Management, SC41-5406-02, provides information about work management in a communications environment, communications status, tracing and diagnosing communications problems, error handling and recovery, performance, and specific line speed and subsystem storage information. v GDDM Programming Guide, SC41-0536-00, provides information about using OS/400 graphical data display manager (GDDM) to write graphics application programs. Includes many example programs and information to help users understand how the product fits into data processing systems. v GDDM Reference, SC41-3718-00, provides information about using OS/400 graphical data display manager (GDDM) to write graphics application programs. This manual provides detailed descriptions of all graphics routines available in GDDM. Also provides information about high-level language interfaces to GDDM. v ICF Programming, SC41-5442-00, provides information needed to write application programs that use iSeries communications and the OS/400 intersystem communications function (OS/400-ICF). Also contains information on data description specifications
467
(DDS) keywords, system-supplied formats, return codes, file transfer support, and program examples. v IDDU Use, SC41-5704-00, describes how to use the iSeries interactive data definition utility (IDDU) to describe data dictionaries, files, and records to the system. Includes: An introduction to computer file and data definition concepts An introduction to the use of IDDU to describe the data used in queries and documents Representative tasks related to creating, maintaining, and using data dictionaries, files, record formats, and fields Advanced information about using IDDU to work with files created on other systems and information about error recovery and problem prevention. v ILE C/C++ Programmers Guide, SC09-2712-02, provides information on how to develop applications using the ILE C language. It includes information about creating, running and debugging programs. It also includes programming considerations for interlanguage program and procedure calls, locales, handling exceptions, database, externally described and device files. Some performance tips are also described. An appendix includes information on migrating source code from EPM C/400 or System C/400 to ILE C. v ILE COBOL Programmers Guide, SC09-2540-02, provides information about how to write, compile, bind, run, debug, and maintain ILE COBOL programs on the iSeries system. It provides programming information on how to call other ILE COBOL and non-ILE COBOL programs, share data with other programs, use pointers, and handle exceptions. It also describes how to perform input/output operations on externally attached devices, database files, display files, and ICF files. v ILE Concepts, SC41-5606-05, explains concepts and terminology pertaining to the Integrated Language Environment (ILE) architecture of the OS/400 licensed program. Topics covered include creating modules, binding, running programs, debugging programs, and handling exceptions. v ILE RPG Reference, SC09-2508-03, provides information about the ILE RPG programming language. This manual describes, position by position and keyword by keyword, the valid entries for all RPG IV specifications, and
provides a detailed description of all the operation codes and built-in functions. This manual also contains information on the RPG logic cycle, arrays and tables, editing functions, and indicators. v ILE RPG Reference Summary, SX09-1315-02, provides information about the RPG III and RPG IV programming language. This manual contains tables and lists for all specifications and operations in both languages. A key is provided to map RPG III specifications and operations to RPG IV specifications and operations. v Printer Device Programming, SC41-5713-04, provides information to help you understand and control printing. Provides specific information on printing elements and concepts of the iSeries system, printer file and print spooling support for printing operations, and printer connectivity. Includes considerations for using personal computers, other printing functions such as Business Graphics Utility (BGU), advanced function printing (AFP), and examples of working with the iSeries system printing elements such as how to move spooled output files from one output queue to a different output queue. Also includes an appendix of control language (CL) commands used to manage printing workload. Fonts available for use with the iSeries system are also provided. Font substitution tables provide a cross-reference of substituted fonts if attached printers do not support application-specified fonts. v iSeries Security Reference, SC41-5302-04, tells how system security support can be used to protect the system and the data from being used by people who do not have the proper authorization, protect the data from intentional or unintentional damage or destruction, keep security information up-to-date, and set up security on the system. v Software Installation, SC41-5120-05, provides step-by-step procedures for initial installation, installing licensed programs, program temporary fixes (PTFs), and secondary languages from IBM. This manual is also for users who already have an iSeries system with an installed release and want to install a new release. v System Operation, SC41-4203-00, provides information about handling messages, working with jobs and printer output, devices communications, working with support functions, cleaning up your system, and so on.
468
v Tape and Diskette Device Programming, SC41-5716-01, provides information to help users develop and support programs that use tape and diskette drives for I/O. Includes information on device files and descriptions for tape and diskette devices. | | | | | | | | v Who Knew You Could Do That with RPG IV? A Sorcerers Guide to System Access and More provides hints and tips for iSeries system programmers who want to take full advantage of RPG IV and the Integrated Language Environment (ILE). It is available from the IBM Redbooks Web Site:
http://www.redbooks.ibm.com/
Bibliography
469
470
B
behavior of bound ILE RPG modules 79 behavioral differences between OPM RPG/400 and ILE RPG 395 bibliography 467 bindable APIs calling conventions 151 CEE4ABN 151 CEECRHP (Create Heap) 20, 118 CEECZST (Reallocate Storage) 20 CEEDSHP (Discard Heap) 20, 118 CEEFRST (Free Storage) 20 CEEGTST (Get Heap Storage) 20, 118 CEEHDLR (Register ILE Condition Handler) 256 CEEHDLU (Unregister ILE Condition Handler) 256 CEERTX (Register Call Stack Entry Termination User Exit Procedure) 262 CEETREC 151 CEETSTA (Check for Omitted Argument) 136 CEEUTX (Call Stack Entry Termination User Exit Procedure) 262 Create Heap (CEECRHP) 20, 118 description 151 Discard Heap (CEEDSHP) 20, 118 Free Storage (CEEFRST) 20 Get Descriptive Information About a String Argument (CEESGI) 136 Get Heap Storage (CEEGTST) 20, 118 overview 20 passing operational descriptors to 135 Reallocate Storage (CEECZST) 20 Retrieve Operational Descriptor Information (CEEDOD) 136 returning from a procedure 151 sample coding 151 binder language example 95 reasons for using 89 binder listing as maintenance resource 84 basic 98 creating 84 determining exports in service program 89 sections of 84 binding after modifying a module 84 definition 79 modules into a program 79 service program to a program 96 binding errors in compiler listing 461 binding multiple modules 82
Numerics
01-99 indicators displaying while debugging 222 in a sample formatted dump 275
A
abnormal program/procedure end 149 access path example of 306 for externally described DISK file 300 for indexed file 306 ACTGRP parameter CRTBNDRPG command 60, 441 CRTPGM command 81 specifying 108 using 62 Copyright IBM Corp. 1994, 2001
471
blocking/unblocking records 305 BNDDIR parameter on CRTBNDRPG CRTBNDRPG command 60, 441 CRTRPGMOD command 74 static binding 62 BREAK debug command definition 184 example 202 using 198, 200, 204 breakpoints conditional setting and removing for job 200 setting and removing for thread 205 removing all 206 setting and removing 196 setting using statement numbers 203 testing 197 unconditional setting and removing for job 197 setting and removing for thread 199 browsing a compiler listing using SEU 69 built-in functions %ADDR 136
C
calculation specifications general description 3 program-described WORKSTN file 354 CALL (call a program) operation code in a conversion report 416 using 145 CALL CL command example passing parameters 102 passing parameters 101 running a program 101 call operations calling programs 145 DSPPGMREF 146 fixed-form call 145 free-form call 131 query names of called procedures 146 special routines 153 using 131 call stack 127, 236 Call Stack Entry Termination User Exit Procedure (CEEUTX) 262 CALLB (call a bound procedure) operation code calling programs 145 using 145 calling Java from RPG 161 RPG from Java 166 calling a graphics routine 152 calling programs/procedures abnormal program/procedure end 149 call stack 127 calling bindable APIs 151 calling graphics 152 calling procedures 126
calling programs/procedures (continued) calling programs 126 calling special routines 153 fixed-form call 145 free-form call 131 interlanguage calls 143 normal program/procedure end 148 overview 125 parameter passing methods 132 recursive calls 127 returning from a called program or procedure 148 returning values 131 returning without ending 150 static calls 126 using the CALL operation 145 using the CALLB operation 145 within ILE 19 CALLP (call a prototyped program or procedure) operation code using 131 cancel handler 235 CEERTX (Register Call Stack Entry Termination User Exit Procedure) 262 CEEUTX (Call Stack Entry Termination User Exit Procedure) 262 example 263 using 262 CCSIDs indicated in compiler listing 452 CEE4ABN 151 CEECRHP (Create Heap) bindable API 20, 118 CEECZST (Reallocate Storage) bindable API 20 CEEDOD (Retrieve Operational Descriptor Information) 92 example 136 operational descriptors 136 CEEDSHP (Discard Heap) bindable API 20, 118 CEEFRST (Free Storage) bindable API 20 CEEGTST (Get Heap Storage) bindable API 20, 118 CEEHDLR (Register ILE Condition Handler) 256 CEEHDLU (Unregister ILE Condition Handler) 256 CEERTX (Register Call Stack Entry Termination User Exit Procedure) 262 CEESGI (Get Descriptive Information About a String Argument) 136 CEETREC 151 CEETSTA (Check for Omitted Argument) 136 CEEUTX (Call Stack Entry Termination User Exit Procedure) 262 Change Module (CHGMOD) command 86 removing observability 86 Change Program (CHGPGM) command optimization parameters 86 removing observability 86
Change Service Program (CHGSRVPGM) command 97 changing a module 84 changing a program 84 changing a service program 91 changing field values while debugging 226 changing optimization level of a program or module 85 changing the debug view of a module 195 character format character CCSID indicated in compiler listing 452 displaying while debugging 223 Check for Omitted Argument (CEETSTA) 136 checking, level 288 checking for the number of passed parameters 137 CL commands Add Program (ADDPGM) 192 additional service program commands 91 ADDRPLYE 106 authority ix CALL 101 Change Module (CHGMOD) 86 CHGPGM 86 commonly used commands 12 CRTPGM command 81 CRTRPGMOD 74 CVTRPGSRC 405 Display Module Source (DSPMODSRC) 191, 192, 193, 194 DSPMOD 146 DSPPGMREF 146 End Debug (ENDDBG) 189 module-related 79 MONMSG 265 program-related 83 RCLACTGR 108 RCLRSC 110 reading syntax diagrams 427 Remove Program (RMVPGM) 192 Start Debug (STRDBG) 189, 191 UPDPGM 85 using 427 WRKRPLYE 107 clear command 348 CLEAR debug command definition 184 removing all 206 using 198, 201, 205 code conversion constraints 419 code generation errors in compiler listing 461 combined file 355 command attention (CA) keys 346 command definition 106 command function (CF) keys 346 COMMIT (commit) operation code commitment control 326 system considerations 326 with multiple devices 326 commitment control 323 COMMIT operation 326
472
commitment control 323 (continued) conditional 328 example 327 in program cycle 328 locks 324 scoping 325 specifying files 326 starting and ending 324 communication accessing other programs and systems 345 compatibility differences between OPM RPG/400 and ILE RPG 395 compilation errors, correcting 68 compile time array or table section in compiler listing 456 compiler directives changing a listing heading 66 compiler listing additional diagnostic messages 69 browsing using SEU 69 coordinating listing options with debug view options 70 correcting compilation errors 68 correcting run-time errors 70 default information 65 in-line diagnostic messages 68 indenting structured operations 67 obtaining 65 reading 447 sample listing 448 sections of 65, 448 specifying the format of 66 using 65 using as documentation 70 compiling creating modules 73 differences between ILE RPG and OPM RPG/400 395 in ILE 17 using CRTBNDRPG command 59 compressing an object 87 condition handler 235 example 256 overview 256 percolate an exception 257 recursive calls 256 registering 256 conditional breakpoint definition 196 setting 201 setting and removing for job 200 setting and removing for thread 205 using statement numbers 203 conditional commitment control, specifying 328 conditioning output overflow indicators 333 consecutive processing 310 control boundary 236 control break example 334 control language (CL) program as module in ILE program 27 commands used with ILE RPG 12 commonly used commands 12 in OPM-compatible application 23
control-record format, subfile 349 control specification keywords compile-option keywords compiler listing example 448 control specifications conversion considerations 404 example 7 general description 3 conversion, analyzing 415 conversion reports obtaining 411 sections of 415 using 415 converting to RPG IV analyzing your conversion 415 constraints 403 conversion problems 419 converting 404 converting all file members 410 converting auto report source members 411 converting some file members 410 converting source from a data file 412 converting source members with embedded SQL 412 CVTRPGSRC command 405 example 412 file and member names 402 file considerations 401 file record length 402 log file 403 obtaining conversion reports 411 overview 401 performing a trial conversion 410 requirements 403 using a conversion error report 415 using the log file 417 valid source member types 402 CoOperative Development Environment/400 (CODE/400) description 14 event file 434 coordinating listing options with debug view options 70 correcting compilation errors 68 correcting run-time errors 70 Create Bound RPG Program (CRTBNDRPG) command and ILE 18 coordinating listing options with debug view 70 creating programs 59 default parameter values 60 examples OPM-compatible program 63 program for source debugging 61 program with static binding 62 parameter description 431 parameters grouped by function 60 program creation strategy 23, 25 RETURNCODE data area 71 syntax diagram 428 using 59 Create Heap (CEECRHP) bindable API 20, 118
Create Program (CRTPGM) command 27 and ILE 18 creating a program 73 examples 96 binding multiple modules 82 parameters 82 system actions 82 using 81 Create RPG Module (CRTRPGMOD) command and ILE 18 default values of parameters 74 defaults 75 examples 95, 96 parameter description 444 parameter grouping by function 74 program creation strategy 27 syntax diagram 442 using 74 Create Service Program (CRTSRVPGM) command and ILE 18 example 95 parameters 90 creating a binder listing 84 creating a debug view COPY 187 listing 188 root source 187 statement 189 creating a library 53 creating a module general discussion 73 using CRTRPGMOD 74 using CRTRPGMOD defaults 75 creating a program with the CRTBNDRPG command 59 creating a source physical file 53 creating programs coding considerations 47 examples of 61, 62, 63, 82 OPM-compatible creating 23 strategy to avoid 31 strategies for 23 CRTPGM command 81 ILE application using CRTRPGMOD 27 OPM-compatible 23 strategy to avoid 31 using CRTBNDRPG 25 using CRTRPGMOD and CRTPGM 73 using the one-step process 59 creating service programs about 89 strategies 89 cross-reference listing 458 CRTRPTPGM (create auto report program) command converting auto report members 411 CVTOPT parameter CRTBNDRPG command 60, 436 CRTRPGMOD command 74 Index
473
CVTRPGSRC (Convert RPG Source) command default parameter values 405 example 410 parameter description 406 syntax diagram 405 using the command defaults 409 CVTRPT parameter 408, 411, 415 cycle, program commitment control 328 fetch overflow logic 335 general description 4 last cycle 5 cycle-free module 75
debug data (continued) none 186 removing from a module 86 debug view changing while debugging 195 COPY source 187 default 189 definition 186 listing 188 root source 187 statement 189 debugging adding an object to a session 192 built-in functions %ADDR 224 %INDEX 224 %SUBSTR 224 %VARS 224 changing values using %SUBSTR 226 examples 225 general discussion 224 changing field values 226 changing modules while debugging 194 coordinating with listing options 70 creating a program for debugging 61 differences between ILE RPG and OPM RPG/400 396 displaying attributes of 227 displaying data addressed by pointers 224 displaying data and expressions 217 displaying fields as hexadecimal values 223 displaying fields in character format 223 displaying fields in UCS-2 format 224 displaying fields in variable-length format 224 displaying indicators 222 displaying multiple-occurrence data structures 221 displaying the contents of a table 220 displaying the contents of an array 220 general discussion 183 National Language Support 229 NLSS considerations 202 obtaining a formatted dump 269 OPM program limit in debug session 192 optimization effects 85, 184 overview 20 preparing a program 186 removing an object from a session 192, 193 rules for assigning values using EVAL 226 setting and removing breakpoints 196 setting debug options 191 setting watch conditions 206 starting the source debugger 189 stepping through 212 unexpected results 219
D
data areas RETURNCODE 71 data file, converting source from 412 data management operations 289 data structures multiple-occurrence displaying while debugging 221 subfields conversion problems 423 displaying while debugging 221 using EVAL debug command 221 database data updating while debugging 191 database file data file 299 field level description 299 general discussion 299 physical and logical files 299 record level description 299 source member 299 DB2 for AS/400 SQL entering SQL statements 57 DBCS in RPG IV character fields 399 NLSS debug considerations 202 DBGVIEW parameter coordinating with listing options 70 CRTBNDRPG command 60, 435 CRTRPGMOD command 74 preparing a program for debugging 186 using 61 values for viewing source 194 DEALLOC (free storage) operation code 111 debug commands ATTR 227 CLEAR 198 DISPLAY 194 EQUATE 228 equating with a name while debugging 228 EVAL 217, 226 general discussion 184 STEP 212 STEP INTO 213 STEP OVER 213 WATCH 206 debug data creating 186 effect on object size 186
debugging (continued) updating production files 191 viewing shorthand names 229 viewing source 194 decimal positions input specifications program-described WORKSTN file 353 with external descriptions 285 decompressing an object 87 default activation group 23, 31, 109 running in 109 default exception handler, RPG 238 default heap 111 DEFINE parameter CRTBNDRPG command 60, 442 CRTRPGMOD command 74 definition specifications general description 3 deleting an activation group 109 description of parameters CRTBNDRPG command 431 CRTRPGMOD command 444 CVTRPGSRC command 406 descriptors, operational definition 135 example 92 DETAIL parameter creating a binder listing 84 DETC 255 detecting errors in a program 183 DETL 255 device files device dependence 279 device independence 279 DISK files 299 general discussion 331 multiple-device 356 PRINTER files 331 SEQ files 340 workstation files 345 device name, function of 280 devices WORKSTN 345 DFTACTGRP parameter on CRTBNDRPG CRTBNDRPG command 60 description 432 running in OPM default 109 using 59, 62, 63 diagnosing errors in a program 183 differences between OPM and ILE RPG behavioral differences 395 exception handling 240 different views of a module 195 Discard Heap (CEEDSHP) bindable API 20, 118 DISK file externally described access path 300 as program-described 282 examples 301 general description 300 record format specifications 300 file operation codes allowed for keyed processing methods 322
474
DISK file (continued) for non-keyed processing methods 322 general description 299 processing methods consecutive processing 310 overview 309 random-by-key processing 317 relative-record-number processing 320 sequential-by-key processing 311 sequential-within-limits processing 318 program-described indexed file 306 processing 309 record-address file 308 sequential file 308 record-format specifications 300 DISPLAY debug command definition 184 using 194 viewing shorthand names 229 Display Module (DSPMOD) command 146 Display Module Source (DSPMODSRC) command 191, 192, 193, 194 Display Program (DSPPGM) command determining optimization level 86 Display Program References (DSPPGMREF) command 146 Display Service Program (DSPSRVPGM) command 89 displaying attributes of a field 227 displaying data and expressions while debugging 217 distributed data management (DDM) files 329 documentation of programs 70 double byte character set in RPG IV character fields 399 NLSS debug considerations 202 dump, formatted 269 DUMP (program dump) operation code obtaining a formatted dump 269 using 269 dynamic array allocating storage during run-time 117 dynamic calls 19, 126 dynamic storage 111
E
edit source (STRSEU) command 54 eliminating errors in a program 183 ENBPFRCOL parameter CRTBNDRPG command 60, 441 CRTRPGMOD command 74 End Debug (ENDDBG) command 189 ending a program or procedure abnormal end 149 after system call 107 normal end 148 return overview 148 returning without ending 150 using bindable APIs 151 ending commitment control 324
ENDSR (end of subroutine) operation code specifying a return point 255 ENTMOD parameter 81 entry module 28, 81 EQUATE debug command definition 184 example 228 using 228 equating a name with a field, expression, or command 228 error indicators specifying 244 error subroutines avoiding a loop 254 for file errors 248 program 251 using 247 errors correcting compilation 68 correcting run-time 70 file 238 program 238 escape messages definition 236 unhandled 241 EVAL debug command changing values 226 contents of a table 220 contents of an array 220 definition 184 displaying data structures 221 example 218, 227 in character format 223 in UCS-2 format 224 in variable-length format 224 indicators 222 rules for assigning values 226 using 217 event file for CODE/400 434 examples compiling binding multiple modules 82 OPM-compatible program 63 program for source debugging 61 program with static binding 62 sample binder listing 98 service program 91 converting to RPG IV all members in a file 410 performing a trial conversion 410 sample conversion 412 some members in a file 410 debugging adding a service program to a session 192 changing field values 227 changing the debug view of a module 195 displaying attributes of a field 227 displaying data addressed by pointers 224 displaying fields as hexadecimal values 223 displaying fields in character format 223
examples (continued) debugging (continued) displaying fields in UCS-2 format 224 displaying fields in variable-length format 224 displaying indicators 222 displaying multiple-occurrence data structures 221 displaying the contents of a table 220 displaying the contents of an array 220 removing programs from a session 193 setting a conditional breakpoint 201 setting an unconditional breakpoint 198 setting debug options 191 source for debug examples 229 using %SUBSTR to display field values 225 viewing a different module in a debug session 194 handling exceptions *PSSR error subroutine 251 avoiding a loop in an error subroutine 254 cancel handler 262 file error subroutine 248 unhandled escape message 241 unhandled function check 242 using a cancel handler 263 using a condition handler 256 I/O data maintenance 363 inquiry by zip code and search on name 382 inquiry program 360 subfile processing 374 interactive application 359 managing your own heap 117 module with multiple procedures 43 passing parameters using the CL CALL command 102 program/procedure call checking number of passed parameters 138 using omitted parameters 92 sample ILE RPG program 6 subprocedures 38 creating a NOMAIN module 75 exception monitoring during run time 107 nested, 241 exception/error handling *PSSR error subroutine 251 avoiding a loop 254 cancel handler 262 condition handler 256 differences between ILE RPG and OPM RPG/400 240, 396 error/exception subroutine overview 247 error indicators 244 Index
475
exception/error handling (continued) file error/exception (INFSR) subroutine 248 general considerations 240 JAVA exceptions 173 MONITOR group 245 NOOPT keyword 243 optimization considerations 243 overview 235 percolation 236 RPG-specific 238 specifying a return point 255 types of 235 unhandled 241 using E extender 244 exception handler priority of 241 RPG-specific 238, 244 exception messages percolation 236 types of 236 unexpectedly handled by CL MONMSG 265 unhandled 241 EXFMT (write/then read format) operation code 355 EXPCPY parameter 408 EXPORT keyword duplicate names 82 expressions returning values 131 extension specifications conversion problems 414, 421 external-references list in compiler listing 459 externally described file access path 300 adding to external description 283 advantages 279 as program-described 282 as WORKSTN file 345, 348 definition 281 file description specifications for 283 output specifications for 287 overriding 285 physical and logical files 299 record format specifications 300 renaming field names 284 renaming record format 283 specifications 283
F
fetch overflow general description 335 logic 335 field changing the value while debugging 226 displaying attributes of while debugging 227 displaying while debugging as hexadecimal values 223 in character format 223 in UCS-2 format 224 in variable-length format 224 using EVAL 217
field (continued) equating with a name while debugging 228 maintaining current values while debugging 184 field-reference file, example of 301 file device dependence 279 device independence 279 differences between ILE RPG and OPM RPG/400 397 DISK 299 externally described 279 externally described disk 300 general considerations 279 indexed 306 locking 293 name externally described 279 override 285 program-described 289 naming conventions 281 open options 295 override 285 PRINTER 331 processing charts sequential file 341 SPECIAL file 343 WORKSTN file 356 program described 279, 289 redirection 280 SEQ 308, 340 sharing 295 valid keys 303 WORKSTN 345 file description specifications commitment control 326 for externally described files 283 general description 3 file exception/error subroutine (INFSR) description 248 example 248 specifications for 248 file exception/errors definition 238 example 248 using an INFSR subroutine 248 file information data structure example 248 using in an error subroutine 248 file locking 293 file operations allowed with DISK file 322 allowed with PRINTER file 331 allowed with sequential file 341 allowed with SPECIAL file 343 allowed with WORKSTN file 355 file overrides 285 example 292 general discussion 291, 321 indicated in compiler listing 449 file record length, conversion considerations 402 file sharing 295 final summary in compiler listing 460 FIND debug command 185
FIXNBR parameter CRTBNDRPG command 60, 439 CRTRPGMOD command 74 flowchart fetch-overflow logic 335 format name 353 format of compiler listing, specifying 66 formatted dump 269 FREE (deactivate a program) operation code 419 Free Storage (CEEFRST) bindable API 20 freeing resources of ILE programs 110 FROMFILE parameter 406 FROMMBR parameter 407, 410 function check definition 236 unhandled 242 function keys indicators 347 with WORKSTN file 347
G
GDDM 152 GENLVL parameter CRTBNDRPG command 60, 432 CRTRPGMOD command 74 Get Descriptive Information About a String Argument (CEESGI) 136 Get Heap Storage (CEEGTST) bindable API 20, 118 graphic format graphic CCSID indicated in compiler listing 452 NLSS debug considerations 202 rules for assigning values using EVAL 226 graphic support 152 Graphical Data Display Manager(GDDM) 152
H
halt (H1-H9) indicators used to end a program/procedure 148, 149, 150 handling exceptions/errors *PSSR error subroutine 251 avoiding a loop 254 cancel handler 262 condition handler 256 differences between ILE RPG and OPM RPG/400 240, 396 error/exception subroutine overview 247 error indicators 244 file error/exception (INFSR) subroutine 248 general considerations 240 NOOPT keyword 243 optimization considerations 243 overview 235 percolation 236 RPG-specific 238 specifying a return point 255 types of 235
476
handling exceptions/errors (continued) unhandled 241 using E extender 244 heap default heap 111 definition 111 example 117 help command key 348 hexadecimal values, displaying while debugging 223 home command key 348
I
I/O differences between ILE RPG and OPM RPG/400 397 ICF communications file 345 identifying an activation group 108 IGNORE keyword 284 ignoring record format 284 ILE C as ILE language 17 in advanced application 30 in mixed-language application 29 parameter passing method 143 source for module in debug example 233 ILE CL as ILE language 17 as module in ILE program 27 calling ILE RPG program 28 calling RPG program 25 in advanced application 30 in mixed-language application 29 parameter passing method 143 unexpectedly handling status and notify exceptions 265 ILE COBOL as ILE language 17 parameter passing method 143 ILE RPG behavior of bound modules 79 behavioral differences between OPM RPG/400 395 converting to 401 data management operations 289 device types supported 331 exception handling overview 238 logic chart 4 overview of RPG IV language 3 sample program 6 ILE source debugger debug commands 184 description 183 starting 189 include source view, creating 187 INDENT parameter 188 CRTBNDRPG command 60, 436 CRTRPGMOD command 74 indenting structured operations in the compiler listing 67 indexed file access path 306 general description 306 valid search arguments 306 indicators as error indicators 244 displaying while debugging 222
indicators (continued) error 244 function key (KA-KN, KP-KY) with WORKSTN file 347 halt (H1-H9) used to end a program/procedure 148, 149, 150 last record (LR) general description 5 used to end a program/procedure 148, 149, 150 overflow examples 335 fetch overflow logic 335 general description 331 presence or absence of 333 relation to program cycle 335 setting of 335 with PRINTER file 331 return (RT) used to end a program/procedure 148, 149, 150 using 5 input file 354 input record unblocking 305 input specifications general description 3 inquiry messages list of 106 replying to 106 inserting specification templates 412 INSRTPL parameter 408, 412 integer format TRUNCNBR parameter 439 Integrated Language Environment (ILE) effect on OPM-compatible program 24 program using CRTBNDRPG 26 ending an ILE program 107 family of ILE compilers 17 interlanguage calling considerations 144 interlanguage calls 143 internal structure of program 80 overview 17 program call 19 program creation 17 program creation strategies 23, 25, 27 program management 19 interlanguage calls 143 Intersystem Communications Function (ICF) 345
K
key composite 304 for a record or a file 303 partial 304 key field information in compiler listing 457 keyed processing access path 300 indexed file 306 record-address limits file 308 sequential-within-limits 318 keyed-sequence access path 300 keywords *OMIT 137 DDS 299 EXPORT 82 for continuation line 299 CLEAR 348 HELP 348 HOME 348 PRINT 348 ROLLDOWN 348 ROLLUP 348 for display device file CLEAR 348 HELP 348 HOME 348 PRINT 348 ROLLDOWN 348 ROLLUP 348 NOOPT 85, 243
L
LANGID parameter CRTBNDRPG command 60, 437 CRTRPGMOD command 74 languages, ILE 17 last record (LR) indicator used to end a program/procedure 148, 149, 150 length of record in a file, conversion considerations 402 level checking 288 library, creating 53 LICOPT parameter CRTBNDRPG command 442 limits records 301 listing, binder as maintenance resource 84 basic 98 creating 84 determining exports in service program 89 sections of 84 listing, compiler additional diagnostic messages 69 browsing using SEU 69 coordinating listing options with debug view options 70 correcting compilation errors 68 correcting run-time errors 70 default information 65 in-line diagnostic messages 68 indenting structured operations 67 Index
J
Java 169 calling Java from RPG 161 calling RPG from Java 166 native methods 166 Java methods 161 Java Virtual Machine (JVM) 169 JNI functions, wrappers for 169
477
listing, compiler (continued) obtaining 65 reading 447 sample listing 448 sections of 65, 448 specifying the format of 66 using 65 using as documentation 70 listing view, creating 188 local variable in formatted dump 276 locking file 293 read without locking 294 record locking wait time 294 retry on timeout 294 standalone 294 under commitment control 324 UNLOCK 294 log file about 403 DDS for 417 using 417 LOGFILE parameter 409 logical file general 299 multi-format 299 LOGMBR parameter 409 long names in compiler listing 458 loop, avoiding in an error subroutine 254
M
main procedure coding considerations 47 overview 33 returning from 148 scope of files 79 maintaining OPM compatibility 63, 109 managing activation groups 107 managing dynamically-allocated storage 111 managing programs 19 managing run-time storage 111 managing the default heap using RPG operations 111 manual code conversion 419 MCH3601 397 memory management operations %ALLOC built-in function 111 %REALLOC built-in function 111 ALLOC (allocate storage) operation code 111 DEALLOC (free storage) operation code 111 REALLOC (reallocate storage with new length) operation code 111 message summary in compiler listing 460 messages additional diagnostic 69 exception example 241 types of 236 unhandled 241 in-line diagnostic 68
messages (continued) inquiry replying to 106 migrating to ILE RPG 401 modifying a module 84 module about 73 behavior of bound ILE RPG 79 binding into a program 79 binding multiple 82 changing optimization level 85 changing while debugging 194 creating 73 creating a NOMAIN module 75 CRTRPGMOD command 74 determining the entry module 81 different debug views 195 effect of debug data on size 186 information in dump listing 269 modifying and rebinding 84 overview of multiple-procedure module 33 preparing for debugging 186 reducing size 87 related CL commands 79 relationship to program 80 removing observability 86 replacing in a program 85 viewing source while debugging 194 module creation general discussion 73 using CRTRPGMOD 74 using CRTRPGMOD defaults 75 module observability 86 MODULE parameter 81 CRTBNDRPG command 431 CRTRPGMOD command 74 MONITOR group 245 MQSeries 157 multiple-device file WORKSTN 356 multiple devices attached to application program 326
O
observability 86 obtaining a compiler listing 65 obtaining conversion reports 411 OFL 255 omitted parameters 136 *OMIT 137 ON-ERROR group 245 one-step process of program creation 59 online information for create commands 431 for ILE source debugger 185 open data path sharing 295 operation codes 355 allowed with DISK file 322 allowed with PRINTER file 331 allowed with sequential file 340 allowed with SPECIAL file 343 allowing E extender 245 allowing error indicators 245 general discussion 6 operational descriptors definition 135 example 92 OPM compatibility, maintaining 63, 109 OPM default activation group 23, 31 running in 109 optimization definition 85 effect on fields when debugging 184 exception handling considerations 243 level of changing an objects 85 checking 86 OPTIMIZE parameter CRTBNDRPG command 60, 435 CRTRPGMOD command 74 OPTION parameter coordinating listing and debug view options 188 coordinating with debug view options 70 CRTBNDRPG command 60, 433 CRTRPGMOD command 74 using 65, 70 OPTIONS keyword *NOPASS 137 *OMIT 137 order of evaluation on prototyped call 143 output specifications program-described WORKSTN file 353 output buffer positions, in compiler listing 456 output file 355 OUTPUT parameter CRTBNDRPG command 60, 435 CRTRPGMOD command 74 using 65 output record blocking 305 output specifications example 8
N
named activation group 108 National Language Support (NLS) of source debugger 229 nested exceptions 241 no debug data 186 NOMAIN module coding considerations 47 creating 75 nonkeyed processing 321 NOOPT keyword and handling exceptions 243 maintaining current values while debugging 184 program optimization level 85 normal program/procedure end 148 NOT Behavioral difference between ILE RPG and RPG/400 395 null value support displaying null-capable fields 224
478
output specifications (continued) general description 3 program-described WORKSTN file 353 with external descriptions 287 output spooling 296 overflow indicators 333 page 332 overflow indicators conditioning output 333 examples 335 fetch-overflow logic 335 general description 333 presence or absence of 333 relation to program cycle 335 setting of 335 with PRINTER file 331 overrides, file 285 example 292 general discussion 291, 321 indicated in compiler listing 449 overriding external description 285
P
page headings 66 page number, in PRINTER file 332 page overflow, in PRINTER file 332 parameter descriptions CRTBNDRPG command 431 CRTRPGMOD command 444 CVTRPGSRC command 406 parameter list created by PARM 148 identifying 129 rules for specifying 147 parameter table CRTBNDRPG command 60 CRTRPGMOD command 74 CVTRPGSRC command 405 parameters checking number passed 137 match data type requirements 135 omitted 136 operational descriptors 135 passing 129 passing using the CL CALL command 101 specifying 146 PARM (identify parameters) operation code 102 *OMIT 136, 137 rules for specifying 147 using 146 partial key 304 parts of an ILE RPG program 6 passing parameters by read-only reference 134 by reference 132, 133 by value 133 checking number passed 137 example 102 match data type requirements 135 omitted parameters 136 operational descriptors 135 overview 129 passing less data 142
passing parameters (continued) passing methods for ILE languages 143 using PARM 146 using PLIST 147 using the CL CALL command 101 percolate an exception using a condition handler 257 percolation of an exception 236 performance considerations subroutines vs. subprocedures 92 performance tips call for LR-on 396 program call 149 performing a quick conversion 409 performing a trial conversion 410 PGM parameter CRTBNDRPG command 60 physical file 299 PLIST (identify a parameter list) operation code 102 *ENTRY PLIST 148 using 147 pointers in teraspace memory 145 PREFIX keyword 284 preparing a program for debugging 186 Presentation Graphics Routines (PGR) 152 preventing printing over perforation 335 PRFDTA parameter CRTBNDRPG command 60, 442 CRTRPGMOD command 74 removing observability 86 print command key 348 PRINTER file access current line value 338 fetch-overflow logic 335 file operation codes allowed 331 maximum number of files allowed in program 331 modify forms control 338 overflow indicators 331 page overflow 332 PRTCTL (printer control) 338 procedure abnormal ending 149 calling 125 dump information 269 normal ending 148 passing parameters 129 procedure pointer call 126 returning from 148 returning without ending 150 static procedure call 126 stepping over 213 procedure pointer calls 126 processing methods consecutive 310 for DISK file 309 nonkeyed 321 random-by-key 316 relative-record-number 320 sequential-by-key 311 sequential only 311, 321 sequential-within-limits 318 WORKSTN file 348, 355
program abnormal ending 149 advanced ILE 30 binding modules 79 calling 125, 126 calling using expressions 131 calling using the CALL operation 145 calling using the CALLP operation 131 changing 84 changing optimization level 85 changing while debugging 194 different debug views 195 effect of debug data on size 186 ending 107 entering source 53 entering SQL statements 57 example 6 freeing resources 110 internal structure 80 mixed-language 29 multiple-module general creation strategy 27 normal ending 148 OPM-compatible creation method 23 effect of ILE 24 example 23 program creation strategy 23, 31 passing parameters 129 preparing for debugging 186 program entry procedure 79 reducing size 87 related CL commands 83 removing observability 86 returning from 148 returning without ending 150 running 101 running from a menu-driven application 103 running in the OPM default activation group 109 running using a user-created command 106 setting watch conditions 206 single-language 28 effect of ILE 26 stepping into 213 stepping over 213 stepping through 212 updating 85 viewing source while debugging 194 program activation 107 program creation coding considerations 47 examples of 61, 62, 63, 82 OPM-compatible creating 23 strategy to avoid 31 strategies for 23 CRTPGM command 81 ILE application using CRTRPGMOD 27 OPM-compatible 23 strategy to avoid 31 using CRTBNDRPG 25 Index
479
program creation (continued) using CRTRPGMOD and CRTPGM 73 using the one-step process 59 program cycle commitment control 328 fetch overflow logic 335 general description 4 last cycle 5 program-described file as DISK file 306 as WORKSTN file 352, 353, 354 definition 281 physical and logical files 299 valid search arguments 306 program entry procedure (PEP) and the call stack 127 definition 79 determining 81 program exception/error subroutine description 251 example 251 program exception/errors avoiding a loop 254 definition 238 example 251, 256 using a *PSSR subroutine 251 program management 19 program name *FROMMBR parameter 408 program/procedure call abnormal program/procedure end 149 call stack 127 calling bindable APIs 151 calling graphics 152 calling procedures 126 calling programs 126 calling special routines 153 fixed-form call 145 free-form call 131 interlanguage calls 143 normal program/procedure end 148 overview 125 parameter passing methods 132 recursive calls 127 returning from a called program or procedure 148 returning values 131 returning without ending 150 static calls 126 using the CALL operation 145 using the CALLB operation 145 within ILE 19 program/procedure end abnormal end 149 after system call 107 normal end 148 return overview 148 returning without ending 150 using bindable APIs 151 program status data structure example 146, 251 using in an error subroutine 251 programming tips creating NOMAIN module 90 setting subprocedure breakpoints 214
prologue section of compiler listing 448 prototype description 34 using 130 prototyped call order of evaluation of parameters 143 prototyped program or procedure prototyped call 34 prototyping, Java methods 158 PRTCTL (printer control) example 339 general information 338
Q
QUAL debug command definition 184 ILE RPG 226 querying names of called programs/procedures 146
R
random-by-key processing example 317 general discussion 316 reading a record 356 reading next record with WORKSTN subfile 351 REALLOC (reallocate storage with new length) operation code 111 Reallocate Storage (CEECZST) bindable API 20 rebinding 84 Reclaim Activation Group (RCLACTGRP) command deleting activation groups 109 named activation groups 108 Reclaim Resources (RCLRSC) command ILE program 26 OPM-compatible program 24 to free storage 110 RECNO keyword with relative-record-number processing 320 record limits 308 locking 294 releasing 294 valid keys 303 record address file conversion problems 414, 421 relative-record number 308 sequential-within-limits 308 with limits records 308 with relative record numbers 308 record format for a subfile 349 ignoring 284 renaming 283 specifications for externally described file 300 record length of files, conversion considerations 402 record locking 294 recursion calling condition handlers 256
recursion (continued) recursive calls 48, 127 redirection, file definition 280 general description 280 reducing object size 87, 186 Register Call Stack Entry Termination User Exit Procedure(CEERTX) 262 Register ILE Condition Handler (CEEHDLR) API 256 relative-record number 309 relative-record-number processing 320 releasing a locked record 294 removing breakpoints about 196 all 206 conditional job breakpoints 200 conditional thread breakpoints 205 unconditional job breakpoints 197 unconditional thread breakpoints 199 using statement numbers 203 removing objects from a debug session 192 removing observability 86 RENAME keyword 283 renaming field names 284 renaming fields 284 renaming record-format names 283 REPLACE parameter CRTBNDRPG command 60, 437 CRTRPGMOD command 74 replacing modules in a program 85 reply list of messages adding to 106 changing 107 replying to run-time inquiry messages 106 requirements of Conversion Aid 403 reserved words *CANCL 255 *DETC 255 *DETL 255 *GETIN 255 *OFL 255 *TOTC 255 *TOTL 255 resulting indicators (01-99, H1-H9, OA-OG, OV, L1-L9, LR, U1-U8, KA-KN, KP-KY, RT) as error indicators 244 resume point 255 Retrieve Operational Descriptor Information (CEEDOD) 92 example 136 operational descriptors 136 retry on a record lock timeout 294 RETURN (return to caller) operation code returning without ending 150 role in abnormal end 149 role in normal end 148 return (RT) indicator used to end a program/procedure 148, 149, 150 return points, specifying in ENDSR 255 return status parameter 342 return value returning using expressions 131
480
RETURNCODE data area 71 returning from a called main procedure 148 returning from a called procedure 148 returning from a main procedure 148 returning from a subprocedure 150 returning using ILE bindable APIs 151 returning without ending 150 rolldown command key 348 rollup command key 348 root source view, creating 187 RPG IV behavioral differences between RPG III 395 converting to 23, 25, 401 overview 3 unsupported RPG III features 420 run-time array allocating storage during run-time 117 run-time errors, correcting with a compiler listing 70 run-time inquiry messages, replying to 106 run-time storage, managing 111 running a program differences between ILE RPG and OPM RPG/400 395 from a menu-driven application 103 in the OPM default activation group 109 overview 101 using a user-created command 106 using the CL CALL command 101
S
scope of files 79 screen design aid (SDA) 104 search argument externally described file description 303 referencing a partial key 304 valid 303 program-described file 306 SECLVL parameter 408 SEQ file example 341 file operation codes allowed 341 general description 340 processing chart 341 restrictions 340 variable-length 340 sequence checking on input specifications 289 sequential-by-key processing examples 311 general discussion 311 sequential file 308 sequential-only processing 310, 311 sequential-within-limits processing examples 319 general discussion 318 service program adding to a debug session 192 binder language 95
service program (continued) binding with CRTBNDRPG 62 changing 91 creating 89 example 91 in advanced application 30 reasons for using 89 reclaiming resources 110 related CL commands 91 sample binder listing 98 strategies for creating 89 updating 97 service program creation about 89 strategies 89 SET debug command definition 184 SETLL exception MCH3601 397 setting breakpoints about 196 conditional job breakpoints 200 conditional thread breakpoints 205 example 198, 201 unconditional job breakpoints 197 unconditional thread breakpoints 199 using statement numbers 203 setting debug options 191 sharing an open data path for a file 295 sort sequence affect of SRTSEQ parameter 297 ALTSEQ table in compiler listing 456 debug considerations 202 source debugging adding an object to a session 192 built-in functions %ADDR 224 %INDEX 224 %SUBSTR 224 %VARS 224 changing values using %SUBSTR 226 examples 225 general discussion 224 changing field values 226 changing modules while debugging 194 coordinating with listing options 70 creating a program for debugging 61 differences between ILE RPG and OPM RPG/400 396 displaying attributes of 227 displaying data addressed by pointers 224 displaying data and expressions 217 displaying fields as hexadecimal values 223 displaying fields in character format 223 displaying fields in UCS-2 format 224 displaying fields in variable-length format 224 displaying indicators 222 displaying multiple-occurrence data structures 221 displaying the contents of a table 220
source debugging (continued) displaying the contents of an array 220 general discussion 183 National Language Support 229 NLSS considerations 202 obtaining a formatted dump 269 OPM program limit in debug session 192 optimization effects 85, 184 overview 20 preparing a program 186 removing an object from a session 192, 193 rules for assigning values using EVAL 226 setting and removing breakpoints 196 setting debug options 191 setting watch conditions 206 starting the source debugger 189 stepping through 212 unexpected results 219 updating production files 191 viewing shorthand names 229 viewing source 194 source entry utility (SEU) 53 browsing a compiler listing 69 entering source 54 source from a data file, converting 412 source member types, conversion of 402 source physical file, creating 53 source program converting all members 410 converting auto report source members 411 converting some members 410 converting to ILE RPG 404 entering into system 53 entering SQL statements 57 file and member names when converting 402 record length of when converting 402 source member types when converting 402 source section of compiler listing 449 special command keys 348 SPECIAL file deleting records from 343 general discussion 341, 343 valid file operations 343 special routines, calling 153 specification templates, inserting 412 specifications description of 3 externally described file 283 file description 283 order 3 record format 300 types 3 specifying a return point 255 specifying an activation group 108 specifying error indicators 244 specifying the format of compiler listing 66 spooling 296 Index
481
SRCFILE parameter CRTBNDRPG command 60, 431 CRTRPGMOD command 74 SRCMBR parameter CRTBNDRPG command 60, 432 CRTRPGMOD command 74 SRTSEQ parameter affect on key comparisons 297 CRTBNDRPG command 60, 437 CRTRPGMOD command 74 debug considerations 202 stack, call 127, 236 Start Debug (STRDBG) command 189 Update Production files (UPDPROD) parameter 191 starting commitment control 324 starting the ILE source debugger 189 statement view creating 189 using for debug 203 static calls 19, 126 static procedure call 126 status codes data management errors 398 STEP debug command definition 184 into 213 over 213 stepping while debugging into a program or procedure 213 over a program or procedure 213 through a program 212 storage management allocating during run-time 117 dynamic storage 111 managing run-time 111 strategies for creating ILE programs 23 STRSEU (edit source) command 54 structured operations indenting 67 subfields for file information data structure 271, 273 for program status data structure 270 for PRTCTL 338 subfiles control-record format 349 descriptions 349 examples 351 file operation codes allowed with 350 general description 349, 350 record format 349 uses of 351 subprocedures coding considerations 48 debugging 216 example 9 information in compiler listing 459 local data in dump listing 276 logic flow 5 overview 33 returning from 150 scope of files 79 stepping into 213 stepping over 213 SUBR23R3 (message retrieval) 153
SUBR40R3 (manipulating Double Byte Characters variables) 153 SUBR41R3 (manipulating Double Byte Characters variables) 153 subroutines avoiding a loop 254 calling SUBR routines 153 error 247 file error (INFSR) 248 program error (*PSSR) 251 substring of character or graphic literal ILE debug built-in %SUBSTR 225 summary tables file operation codes allowed with DISK 321 PRINTER 331 sequential 341 SPECIAL 343 WORKSTN 355 sequential file processing 341 SPECIAL file processing 343 syntax diagrams CRTBNDRPG command 428 CRTRPGMOD command 442 CVTRPGSRC command 405 interpreting 427 system functions spooling 296 system reply list adding to 106 changing 107
trial conversion, performing TRUNCNBR parameter CRTBNDRPG command CRTRPGMOD command two-step process of program types of exception handlers
U
UCS-2 format displaying while debugging 224 UCS-2 CCSID indicated in compiler listing 452 unblocking/blocking records 305 unconditional breakpoint definition 196 setting 198 setting and removing for job 197 setting and removing for thread 199 using statement numbers 203 unhandled escape message 241 unhandled exceptions 241 unhandled function check 242 Unregister ILE Condition Handler (CEEHDLU) API 256 unsigned integer format TRUNCNBR parameter 439 Update Program (UPDPGM) command using 85 updating a service program 97 user-created command, running an RPG program 106 user entry procedure (UEP) and the call stack 127 role in program 80 USRPRF parameter on CRTBNDRPG CRTBNDRPG command 60, 438
T
table displaying while debugging 220 table of parameters CRTBNDRPG command 60 CRTRPGMOD command 74 CVTRPGSRC command 405 tape file 308 TBREAK debug command definition 184 using 199, 205 templates, inserting specification 412 teraspace memory 145 test library, using 191 testing breakpoints 197 TEXT parameter CRTBNDRPG command 60, 432 CRTRPGMOD command 74 TGTRLS parameter CRTBNDRPG command 60, 439 CRTRPGMOD command 74 THREAD debug command definition 185 using 199 threaded applications coding considerations 153 debugging 196 locking and unlocking procedures 155 overview 21 TOFILE parameter 407, 410 TOMBR parameter 408, 410 TOTC 255 TOTL 255
V
valid file operations SPECIAL file 343 valid keys for file 303 for records 303 variable-length format displaying while debugging 224 variable-length records 340 view, debug changing while debugging 195 COPY source 187 default 189 definition 186 listing 188 root source 187 statement 189 viewing source while debugging 194 VisualAge RPG 14
W
WATCH debug command definition 185 example 211 setting conditions 206 Work with Reply List Entry (WRKRPLYE) command changing a system reply list 107
482
WORKSTN file definition 345 examples 359 externally described processing 348 externally-described 345 file operation codes allowed with 355 function key indicators with 347 multiple-device 356 processing 355 program-described calculation specifications 354 combined file 355 considerations 354 general 352 input file 354 input specifications 353 output file 355 output specifications 353 with format name 353 without format name 354 sample data maintenance program 363 sample inquiry and search program 382 sample inquiry program 360 sample subfile processing program 374 subfiles control-record format 349 examples 351 for display-device file 349 record format 349 uses of 351 using 345
X
XML 157
Index
483
484
Printed in U.S.A.
SC09-2507-03