Operation Definitions (Cont) [ HP RPG/iX Reference Manual ] MPE/iX 5.0 Documentation
HP RPG/iX Reference Manual
Operation Definitions (Cont)
DOUxx
This structured programming operation (DO Until) performs the block of
operations (Do Block) immediately following it until Factor 1 and Factor
2 meet the criteria specified by xx. The Do Block is performed at least
once.
Table 8-9. DOUxx Operations
--------------------------------------------------------------------------------------------
| | |
| Enter this operation: | To perform the Do Block until Factor 1 is: |
| | |
--------------------------------------------------------------------------------------------
| | |
| DOUEQ | Equal to Factor 2. |
| | |
| DOUGE | Greater than or equal to Factor 2. |
| | |
| DOUGT | Greater than Factor 2. |
| | |
| DOULE | Less than or equal to Factor 2. |
| | |
| DOULT | Less than Factor 2. |
| | |
| DOUNE | Not equal to Factor 2. |
| | |
--------------------------------------------------------------------------------------------
End the operations in a Do Block with an END operation. Do not split a
Do Block between detail, total, or subroutine operations. You may branch
into or out of a Do Block, but be sure that you understand what the
results will be. Do Blocks can be nested; that is, a Do Block can be
contained within another Do Block as shown below (the maximum number of
levels of nesting is 100).
Begin Level 1 DO Block IFEQ (If equal then do)
.
.
ELSE (Else do)
.
.
Begin Level 2 DO Block DOULT (Do until less than)
.
.
Begin Level 3 DO Block DOWNE (Do while not equal)
.
.
End Level 3 DO Block END
End Level 2 DO Block END
End Level 1 DO Block END
To conditionally execute the DOUxx operation, enter one or more
indicators in the Indicators Field (columns 9-17). You can prematurely
end execution of a Do Block by entering one or more indicators in the
Indicators Field of the END operation. When the indicator conditions are
no longer satisfied, control skips to the operation following END.
You can enter a field name or a literal in the Factor 1 and Factor 2
Fields. Numeric fields are aligned by decimal point before they are
compared. Shorter fields are padded with zeros (to the left and right)
to make them the same size. Blanks in numeric fields are treated as
zeros. The maximum numeric field length is 15 digits. Alphanumeric
fields are aligned starting with their high-order (leftmost) characters.
Shorter fields are padded with blanks (on the right) to make them the
same size. If you specified an alternate collating sequence, it is used.
You can compare a numeric field to an alphanumeric field. The numeric
field is temporarily converted to alphanumeric format and the two fields
are compared as if they both were alphanumeric. The numeric field is not
aligned by decimal point before the compare.
Negative signs are ignored. For example, the number -123.45 becomes
"12345". To avoid problems when comparing the numeric field, make sure
it does not have decimal places, is the same length and is not negative.
When you compare a numeric field to an alphanumeric field, you see this
compiler message:
9016I NUMERIC FIELD TEMPORARILY CONVERTED TO ALPHANUMERIC FOR
ALPHANUMERIC COMPARE
Do not use the Result Field or the Resulting Indicators Field (columns
54-59).
Example
Figure 8-17 shows how to use the DOUxx operation. The DOULT operation in
line 1 is executed if indicator 21 is OFF. The operations between lines 1
and 2 are executed until the X element of TBL is less than zero or until
indicator 44 is turned OFF (see line 2). In these cases, execution
resumes with the operation following line 2.
___________________________________________________________________________________
| |
| 1 2 3 4 5 6 7 |
| 678901234567890123456789012345678901234567890123456789012345678901234|
| _______________________________________________________ |
| |
| 1 C N21 TBL,X DOULTO |
| C MOVEANAME,X CHAR |
| C Z-ADD1 Y |
| C . |
| C . |
| 2 C 44 END |
| |
| |
| |
___________________________________________________________________________________
Figure 8-17. Using the DOULT Operation
DOWxx
This structured programming operation (DO While) performs the block of
operations (Do Block) immediately following it as long as Factor 1 and
Factor 2 meet the criteria specified by xx.
Table 8-10. DOWxx Operations
--------------------------------------------------------------------------------------------
| | |
| Enter this operation: | To perform the Do Block while Factor 1 is: |
| | |
--------------------------------------------------------------------------------------------
| | |
| DOWEQ | Equal to Factor 2. |
| | |
| DOWGE | Greater than or equal to Factor 2. |
| | |
| DOWGT | Greater than Factor 2. |
| | |
| DOWLE | Less than or equal to Factor 2. |
| | |
| DOWLT | Less than Factor 2. |
| | |
| DOWNE | Not equal to Factor 2. |
| | |
--------------------------------------------------------------------------------------------
End the Do Block of operations with an END operation or an ELSE if the IF
operation is also used. (See the DOUxx operation for a description of Do
Blocks.) Do not split a Do Block between detail, total, or subroutine
operations. You may branch into or out of a Do Block, but be sure that
you understand what the results will be. Do Blocks can be nested; that
is, a Do Block can be contained within another Do Block as shown below
(the maximum number of levels of nesting is 100).
To conditionally execute the DOWxx operation, enter one or more
indicators in the Indicators Field (columns 9-17). You can prematurely
end execution of a Do Block by entering one or more indicators in the
Indicators Field of the END operation. When the indicator conditions are
no longer satisfied, control skips to the operation following END.
You can enter a field name or a literal in the Factor 1 and Factor 2
Fields. Numeric fields are aligned by decimal point before they are
compared. Shorter fields are padded with zeros (to the left and right)
to make them the same size. Blanks in numeric fields are treated as
zeros. The maximum numeric field length is 15 digits. Alphanumeric
fields are aligned starting with their high-order (leftmost) characters.
Shorter fields are padded with blanks (on the right) to make them the
same size. If you specified an alternate collating sequence, it is used.
You can compare a numeric field to an alphanumeric field. The numeric
field is temporarily converted to alphanumeric format and the two fields
are compared as if they both were alphanumeric. The numeric field is not
aligned by decimal point before the compare. Negative signs are ignored.
For example, the number -123.45
becomes "12345". To avoid problems when comparing the numeric field,
make sure it does not have decimal places, is the same length and is not
negative. When you compare a numeric field to an alphanumeric field, you
see this compiler message:
9016I NUMERIC FIELD TEMPORARILY CONVERTED TO ALPHANUMERIC FOR
ALPHANUMERIC COMPARE
Do not use the Result Field or the Resulting Indicators Field (columns
54-59).
Example
Figure 8-18 shows how to use the DOWxx operation. The DOWNE operation in
line 1 executes the operations between it and the END operation (line 2)
as long as the Y element of the array CHAR is not equal to blanks.
___________________________________________________________________________________
| |
| 1 2 3 4 5 6 7 |
| 678901234567890123456789012345678901234567890123456789012345678901234|
| _______________________________________________________ |
| |
| 1 C CHAR,Y DOWNE" " |
| C . |
| C . |
| 2 C END |
| |
| |
| |
___________________________________________________________________________________
Figure 8-18. Using the DOWNE Operation
DSPLM
This display operation displays messages on the terminal from a User
Message Catalog. You can also use it to display a field on the terminal
and accept changes to it from the user. If you enable the function keys
(f1 through f8) using the SET operation, DSPLM automatically turns the
function key indicators ON or OFF when the user presses the function keys
on the keyboard.
When you run a program containing DSPLM from a job file, data is read and
displayed using the system console. When running in session mode, DSPLM
uses the user terminal.
Use the Factor 1 and Result Fields in one of the two ways shown below.
These fields determine how DSPLM works.
* To display a message from the User Message Catalog (only), enter
the identification number of the message in the Factor 1 Field.
* To display a message from the User Message Catalog and to display
a field in the program, enter the identification number of the
message in the Factor 1 Field and the field name in the Result
Field. The user at the terminal can update the Result Field data
and also use the function keys.
When DSPLM is executed for method 2 above, the Factor 1 Field is
displayed on one line and the Result Field on the next. RPG pauses to
let the user update the data displayed for the Result Field. To change
the field, the user enters new data directly underneath the displayed
data, then presses RETURN . If there are no changes to the field, the
user types an asterisk (*) followed by RETURN or presses RETURN by
itself. If the field is displayed on the operator's console, the
operator must respond using the REPLY console command (see the MPE/iX
Commands Reference Manual). The operator does not have to enter leading
zeros for numeric fields or trailing blanks for alphanumeric fields. RPG
automatically aligns the fields and pads them with these characters. For
the user or operator to use the function keys, you must have enabled them
previously using the SET operation.
When entering the Factor 1 Field, specify the identification number of
the message in the User Message Catalog. Ensure that the actual message
text does not exceed 249 characters. (See the MSG operation for more
information about message identification numbers.)
You may enter the name of the file in the Factor 2 Field, although it is
not used. It is provided for compatibility with other implementations of
RPG.
When you use the Result Field, enter a field name into it. If the field
is alphanumeric, the maximum number of characters it can contain is 256.
If it is numeric, the maximum number of digits is 15. If you're using
the system console, the field must not exceed 31 characters for input and
56 characters for output. If you're using a user terminal, the field
must not exceed the terminal record length defined at system
configuration. You can enter indicators in the Resulting Indicators
Field (columns 54-59). They are turned ON or OFF according to the final
contents of the Result Field.
You can use the Header Specification to alter the way data is displayed
on the terminal and read from it. The DSPLY Options Field (column 48)
lets you suppress the display of "DSPLY". It also lets you determine
whether the user updates the Result Field on the same line where it is
displayed, or on the next line.
Example
The code in figure 8-20 displays instructions to a user on how to use the
function keys to print reports. The instructions come from a User
Message Catalog and are displayed by the DSPLM operations starting in
line 1. (Figure 8-19 lists the messages in the User Message Catalog that
are used for this example.) The example also shows SETON operations
(starting at line 3) which use the function key indicators turned ON by
the DSPLM operations.
_____________________________________________________________________
| |
| $SET 1 |
| 0001Product Sales Analysis - F1 for Current Month Detail |
| 0002 - F2 for Current Month Summary|
| 0003 - F3 for Year-to-date Detail |
| 0004 - F4 for Year-to-date Summary |
| 0005 - F5 for Comparative Detail |
| 0006 - F6 for Comparative Summary |
| 0007 - F7 for Month-end Processing |
| 0008 - F8 for Year-end Processing |
| 0009Use the function keys to select the report to print |
| |
| |
| |
_____________________________________________________________________
Figure 8-19. Sample Message Set in a User Message Catalog File
___________________________________________________________________________________
| |
| 1 2 3 4 5 6 7 |
| 678901234567890123456789012345678901234567890123456789012345678901234|
| _______________________________________________________ |
| |
| E KEYLBL 1 8 16 FUNC KEY LABELS |
| |
| C SETOF U1U2U3 |
| C SETOF U4U5U6 |
| C SETOF U7U8 |
| 1 C "01:1" DSPLM |
| C "02:1" DSPLM |
| C "03:1" DSPLM |
| C "04:1" DSPLM |
| C "05:1" DSPLM |
| C "06:1" DSPLM |
| C "07:1" DSPLM |
| C "08:1" DSPLM |
| C KEYLBL SET f@ |
| 2 C "09:1" DSPLM KEYIN 2 |
| C . |
| C . |
| C . |
| 3 C F1 SETON U1 |
| C F2 SETON U2 |
| C F3 SETON U3 |
| C F4 SETON U4 |
| C F5 SETON U5 |
| C F6 SETON U6 |
| C F7 SETON U7 |
| C F8 SETON U8 |
| C SETON LR |
| |
| |
___________________________________________________________________________________
Figure 8-20. Using the DSPLM Operation
DSPLY
This display operation displays data on the terminal and reads data from
it. You can also use DSPLY to turn the function key indicators ON or OFF
when the user presses the function keys on the keyboard.
When running in batch mode, DSPLY uses the system console. When running
in session mode, it uses the user terminal.
Use the Factor 1 and Result Fields in one of three ways shown below.
These fields determine how DSPLY works.
* To display a single data field on the terminal, enter the name of
the field, literal, array element, or table to display in the
Factor 1 Field.
* To display a data field on the terminal and allow the user to
update it, enter the field name in the Result Field and leave the
Factor 1 Field blank. If you have already enabled one or more
function keys using the SET operation, the function key indicators
are automatically turned ON or OFF according to the function keys
that the user presses.
* To display two data fields and allow one of them to be updated by
the user, enter both the Factor 1 and Result Fields. If you have
already enabled the functions keys using the SET operation, the
function key indicators are automatically turned ON or OFF
depending on the function keys that the user presses.
When DSPLY is executed for methods 2 and 3 above, the Factor 1 Field (if
used) is displayed on one line and the Result Field on the next line.
RPG pauses to let the user update the data displayed for the Result
Field. To change the field, the user enters new data directly underneath
the displayed data, then presses RETURN . If there are no changes to the
field, the user types an asterisk (*) followed by RETURN or presses
RETURN by itself. If the field is displayed on the operator's console,
the operator must respond using the REPLY console command (see the MPE/iX
Commands Reference Manual). The user does not have to enter leading
zeros for numeric fields or trailing blanks for alphanumeric fields. RPG
automatically aligns the fields and pads them with these characters.[REV
BEG] You can also use the function keys if you have previously enabled
them with the SET operation. Specify a result field at least two
characters long if you use function keys.[REV END]
When entering the Factor 1 Field, specify the name of a field, literal,
array element, or table to display. If you enter a table name, the
element found by the last LOKUP operation is displayed.[REV BEG] If an
array is named in the DS line of an Input Specification, and the array is
named in factor 1 without an index, the entire array is displayed, within
limits.[REV END] The data in Factor 1 cannot exceed 249 characters.
(Seven characters of this are used for the word DSPLY plus two blanks.)
If the data exceeds the terminal line length, it is displayed on
successive lines. (Data displayed on the system console is limited to 56
characters per line.)
You may enter the name of the file in the Factor 2 Field although it is
not used. It is provided for compatibility with other implementations of
RPG.
When you use the Result Field, enter a field name in it. If the field is
alphanumeric, the maximum number of characters it can contain is 256. If
it is numeric, the maximum number of digits is 15. If you're using the
system console, the field must not exceed 56 characters. If you're using
a user terminal, the field must not exceed the terminal record length
defined at system configuration. You can enter indicators in the
Resulting Indicators Field (columns 54-59). They are turned ON or OFF
according to the final contents of the Result Field.
You can use the Header Specification to alter the way data is displayed
on the terminal and read from it. The DSPLY Options Field (column 48)
lets you suppress the display of "DSPLY". It also lets you determine
whether the user updates the Result Field on the same line where it is
displayed, or on the next line.
Example
Figure 8-21 illustrates the three ways to use DSPLY. The first line (line
1) displays the contents of the field MESSAGE. If MESSAGE contains the
characters RE-RUN PROGRAM WITH FILE 2, the following line appears on the
terminal:
DSPLY RE-RUN PROGRAM WITH FILE 2
Line 2 shows how to display the contents of the field FIELD1 and allow
the user to change it. If FIELD1 contains 0023, it is displayed as
follows (RPG displays the field, then pauses for user input):
0023
If the operator enters 43 and presses RETURN , 43 is placed in FIELD1,
and RPG continues with the next operation.
Line 3 shows how to display two fields and accept changes for the second
one. The fields FIELD2 and FIELD3 are displayed on separate lines. If
FIELD2 contains ENTER NEW ID NO; PRESENT NO IS and FIELD3 contains 32,
these lines are displayed on the terminal (RPG displays the fields, then
pauses for user input):
DSPLY ENTER NEW ID NO; PRESENT NO IS
32
If the operator enters 5, and presses RETURN , 5 is placed in FIELD3 and
RPG continues with the next operation.
___________________________________________________________________________________
| |
| 1 2 3 4 5 6 7 |
| 678901234567890123456789012345678901234567890123456789012345678901234|
| _______________________________________________________ |
| |
| 1 C MESSAGE DSPLY |
| C . |
| C . |
| 2 C DSPLY FIELD1 |
| C . |
| C . |
| 3 C FIELD2 DSPLY FIELD3 |
| |
| |
___________________________________________________________________________________
Figure 8-21. Using the DSPLY Operation
ELSE
This structured programming operation is used with the IF operation. It
marks the beginning of the operations that are performed when the
comparison criteria of the IF test are not met.
Enter ELSE in the Operation Field and leave all other fields on the
specification blank.
Example
Figure 8-22 shows how to use the ELSE operation. The operation in line 2
is executed when the field CODE is equal to zero (line 1). If CODE is
not equal to zero the lines between ELSE (line 3) and END (line 4) are
executed.
___________________________________________________________________________________
| |
| 1 2 3 4 5 6 7 |
| 678901234567890123456789012345678901234567890123456789012345678901234|
| _______________________________________________________ |
| |
| 1 C CODE IFEQ O |
| 2 C MOVE CODE CODE2 |
| 3 C ELSE |
| C SUB SHIFT CODE2 2121 |
| C N21 Z-ADDO X |
| C . |
| C . |
| 4 C END |
| |
| |
___________________________________________________________________________________
Figure 8-22. Using the ELSE Operation
END
This structured programming operation marks the end of a Do Block of
operations. (See the IFxx or DOUxx operations for examples of Do
Blocks.) When used with IFxx, ELSE and CASxx, it terminates execution of
the Do Block. When used with the DO, DOUxx, or DOWxx operations, it
transfers control to the beginning of the Do Block.
You can prematurely end execution of a Do Block by entering one or more
indicators in the Indicators Field (columns 9-17) of the END operation.
When the indicator conditions are no longer satisfied, control skips to
the operation following END.
[REV BEG]
When using the END operation with the DO operation, enter a numeric value
in Factor 2 to specify the loop increment. If no value is specified, the
default increment is 1. You cannot specify an increment for the IF,
CASxx, DOUxx, and DOWxx operations.[REV END]
Example
Figure 8-23 shows how to use the END operation with CASxx operations.
The END operation (line 2) follows the last line in the CASxx group,
which starts with line 1.
___________________________________________________________________________________
| |
| 1 2 3 4 5 6 7 |
| 678901234567890123456789012345678901234567890123456789012345678901234|
| _______________________________________________________ |
| |
| C SELECT TAG |
| 1 C N20 CODE CASEQ21 SUB21 |
| C 20 CODE2 CASGE5 SUB5X |
| C CAS |
| 2 C END |
| |
| |
| |
___________________________________________________________________________________
Figure 8-23. Using the END Operation
ENDSR
This internal subroutine operation ends an internal subroutine (see
figures 8-7 and 8-26). Execution continues in the main program
immediately after the EXSR operation that called the subroutine. If you
want to branch to ENDSR within the subroutine (do not branch to it from
outside the subroutine), enter a label in the Factor 1 Field. The label
can be the same as a field name.
Do not use the Factor 2 and Result Fields and do not enter indicators in
the Indicators Field (columns 9-17). Enter just one ENDSR operation per
subroutine.
EXCPT
This file operation lets you produce output during detail and total
calculations. This output is in addition to the records that are
normally written at detail time and total time. (Normally, the number of
records defined in the Output Specifications are written during each
program cycle.) For example, you may want several copies of a form that
contains the same heading information.
To condition this operation, enter indicators in the Control Level
(columns 7-8) and the Indicators Field (columns 9-17). You can further
condition or limit the lines that are written by entering a file name in
the Factor 2 Field (see the section which follows titled "Conditioning by
File Name") or by entering an EXCPT Name in the Result Field (see the
section which follows titled "Conditioning by EXCPT Name"). Leave the
other fields on the specification blank.
When you use EXCPT, you must also enter an E into the Type Field (column
15) of the Output Specification that defines the record you want to
write. Because the record lines that are written are exceptions to the
normal program cycle, they are called exception lines. EXCPT writes all
exception lines whose conditioning indicators, file name and EXCPT Name
conditions are satisfied. When the exception lines are written,
execution resumes with the operation following EXCPT.
Example
Figure 8-24 shows how to use the EXCPT operation to print several copies
of a mailing address label. The CUST record beginning in line 1 contains
the mailing address of a company's customers. When a name matches the
name in the NAMEA field (line 2), indicator 50 is turned ON. If indicator
05 is ON, the EXCPT operation in line 3 is executed. It causes the
mailing address label (exception lines) defined by MAILER (line 4) to be
printed. Since EXCPT is included in a loop that prints five mailing
labels for the customer, exception output is performed five times.
___________________________________________________________________________________
| |
| 1 2 3 4 5 6 7 |
| 678901234567890123456789012345678901234567890123456789012345678901234|
| _______________________________________________________ |
| |
| 1 ICUST AA |
| I 1 20 NAME |
| I 21 30 STREET |
| I 31 40 CITY |
| I 41 45 STATE |
| I 46 50 ZIP |
| |
| C . |
| C . |
| 2 C NAMEA COMP NAME 50 |
| C REPEAT TAG |
| 3 C 50 EXCPT |
| C 50 1 ADD COUNT COUNT 10 |
| C 50 COUNT COMP 5 60 |
| C 60 GOTO REPEAT |
| C RES1 ADD RES2 RES3 52 |
| C . |
| C . |
| |
| 4 OMAILER E |
| O NAME 20 |
| O STREET 30 |
| O CITY 40 |
| O STATE 45 |
| O ZIP 50 |
| |
| |
___________________________________________________________________________________
Figure 8-24. Using the EXCPT Operation
Conditioning by File Name
You can write exception lines for a particular file (only) by entering
the name of the file in the Factor 2 Field. The exception lines that are
written for the file must also satisfy the conditioning indicators and
the EXCPT Name conditions.
See figure 8-25 for an example of how to condition by file name.
Conditioning by EXCPT Name
You can write exception lines for a certain record in a file by entering
the EXCPT Name for the record in the Result Field. (Note that some
implementations of RPG use the Factor 2 Field instead of the Result
Field.) Define the record you want to write and enter the EXCPT Name in
the Field Name Field (columns 32-37) of that Output Specification.
When you enter an EXCPT Name, follow the naming conventions for field
names. Do not use an existing array, data structure, field, file label,
subroutine, or table name. You can enter the same EXCPT Name for more
than one record. The maximum number of EXCPT Names that you can use in a
program is 245.
When EXCPT is executed, the exception lines are written only if the
conditioning indicators are satisfied and if the record belongs to the
file named in the Factor 2 Field (if Factor 2 is used).
Example
Figure 8-25 shows how to use file and EXCPT Names to write additional
records to the output files LIST and OUTFILE. The EXCPT operation in line
1 writes the output record containing GROUP1 in columns 32-37 (line 4).
The EXCPT operation in line 2 writes the output record containing GROUP2
in columns 32-37 (line 5). The EXCPT operation in line 3 writes the
output record containing GROUP5 in columns 32-37 (line 6) of the file
OUTFILE. In addition, only those exception lines in GROUP5 are written
when indicator 81 is ON (and they are conditioned by 81).
________________________________________________________________________________
| |
| 1 2 3 4 5 6 7 |
| 678901234567890123456789012345678901234567890123456789012345678901234|
| _______________________________________________________ |
| |
| 1 C EXCPT GROUP1 |
| C . |
| C . |
| 2 C EXCPT GROUP2 |
| C . |
| C . |
| 3 C EXCPTOUTFILE GROUP5 |
| |
| 4 OLIST E 3 GROUP1 |
| O . |
| O . |
| 5 O E 1 GROUP2 |
| O . |
| O . |
| 6 OOUTFILE E 2 81 GROUP5 |
| |
| |
________________________________________________________________________________
Figure 8-25. Using the EXCPT Operation with File and EXCPT Names
MPE/iX 5.0 Documentation