Previous Topic: Control OperationsNext Topic: Work Field Parameters


Control Operations

Purpose

Control the flow of processing.

Syntax

►►─┬─ PERFORM sequence ───────────────────────────────────────────────┬───────►◄
   ├─ RETURN ─────────────────────────────────────────────────────────┤
   ├─ CALL ─┬─ USnn ────┬─┬─────────────────────────────────────────┬─┤
   │        └─ DB-EXIT ─┘ │     ┌─────────────────────────────┐     │ │
   │                      └─ ( ─▼─┬─ literal ───────────────┬─┴─ ) ─┘ │
   │                              └─ field-name-expression ─┘         │
   │                  ┌─────────────┐                                 │
   └─┬─ PICK ───┬─ ( ─▼─ edit-line ─┴─ ) ─────────────────────────────┘
     ├─ UNPICK ─┤
     ├─ TAKE ───┤
     ├─ RELS ───┤
     └─ DROP ───┘

Syntax Rules

PERFORM

Passes processing control to a process parameter of the same type; for example, from one type 7 parameter to another or from one type 8 parameter to another.

sequence

The sequence number of the process parameter that receives processing control. The process parameter that receives processing control must have the sequence number coded in columns 5 through 7.

PERFORM instructions cannot be nested; that is, a PERFORM statement cannot appear within another PERFORM statement. All CA Culprit procedure statements other than PERFORM, however, can appear within code accessed by a PERFORM instruction.

RETURN

Returns processing control to the process statement that immediately follows the statement containing the PERFORM instruction. RETURN executes only if the procedure code is accessed with a PERFORM statement.

CALL

Indicates that processing control is passed to a user-coded or CA-supplied procedure module.

CALL instructions must be coded only on type 7 process parameters.

Note: For more information on coding CALL statements and syntax for individual procedure modules, see the CA Culprit for CA IDMS User Modules Guide.

USnn

Identifies the name of the external procedure module that is to receive processing control. Nn must be a 2-digit number in the range 00 through 99.

literal/field-name-expression

Indicates one or more literals, input fields, or work fields whose values serve as arguments for the procedure module identified by USnn. Syntax and syntax rules for coding field-name-expression appear under User-Defined Variables. These literals or field values are moved to ARGn fields, which communicate with the procedure module.

Note: For more information on coding arguments for individual procedure modules, see the CA Culprit for CA IDMS User Modules Guide.

A maximum of nine arguments can be specified. These arguments must be specified in sequence; that is, ARG1 corresponds to the first literal or field in the list, ARG2 corresponds to the second argument in the list, and so forth.

Arguments cannot be omitted; for example, if a procedure module requires only the first and third arguments, a dummy value must be specified for the second argument. A blank can serve as a dummy value for alphanumeric arguments; a zero can serve as a dummy value for numeric arguments.

PICK/UNPICK/TAKE/RELS/DROP ( edit-line )

Specifies edit line selection/deselection operations as described below. These operations allow the user to specify which edit lines to print. When these instructions appear on a type 7 process parameter, detail lines are selected; when these instructions appear on a type 8 process parameter, total lines are selected.

PICK

Selects edit lines for extracting or printing. These lines are not output, however, until a TAKE or RELS instruction is executed. Multiple PICK statements can execute before the selected lines are output.

UNPICK

Deselects edit lines for extracting or printing. Edit lines not specified on an UNPICK instruction are selected for output; the selected lines are not extracted or output until a TAKE or RELS instruction executes.

TAKE

Immediately extracts or outputs the selected edit lines, and stops processing for the current buffer or control break. Any remaining procedure code defined for the report does not execute.

An implicit TAKE instruction executes at the end of type 7 and 8 procedure logic thereby causing all selected edit lines to be extracted or output. If no explicit selection or deselection has occurred, all edit lines are output.

RELS

Immediately extracts or outputs the selected edit lines and continues processing for the current buffer or control break. Processing continues with the procedure statement that immediately follows the RELS instruction. Any number of RELS instructions can be issued for each buffer or control break by each report.

Note: The selected/deselected status is not reset following a RELS instruction, since the current buffer or control break continues to be processed. PICK or UNPICK instructions are needed to ensure that the necessary lines are selected for any subsequent TAKE or RELS instructions, unless the TAKE and RELS instructions specify edit lines to be selected.

DROP

Indicates that processing control for the current buffer or control break is complete for the report associated with this parameter. Any remaining procedure logic defined for this report is not executed; the code is not accessed again until the next buffer or control break is processed.

Once a DROP executes, no additional edit lines are extracted or output for the current buffer or control break for this report. Information extracted or output previous to a DROP instruction is unaffected.

edit-line

Identifies an edit line or a list of edit lines to be selected or deselected. Edit-line is a number in the range 1 through 8 that refers to the value coded in position 5 on a type 5 or a type 6 edit parameter.

If a list of edit line numbers is specified, the list must be enclosed in parentheses; each value in the list must be separated by a comma or a space.

An edit line specification is required for PICK and UNPICK instructions; it is optional for TAKE, RELS, and DROP instructions. If no edit lines are specified on a TAKE or RELS instruction, all lines selected by PICK or UNPICK instructions are extracted or output; if no edit lines are explicitly selected or deselected, all edit lines are extracted or output when a TAKE or RELS instruction executes.

Note: TAKE, RELS, and DROP are optional actions that can be performed as the result of a conditional operation discussed earlier in this chapter. However, when used in this context, edit lines cannot be specified for selection or deselection.

Examples

Sample process parameters are shown and described below.

Example 1: Arithmetic Operation—Simple

017     PREVIOUS-BALANCE + DEPOSITS CURRENT-BALANCE

For each record processed for Report 01, the value in DEPOSITS is added to the value in PREVIOUS-BALANCE; the sum is stored in the work field CURRENT-BALANCE. The values of PREVIOUS-BALANCE, DEPOSITS, and CURRENT-BALANCE for each input buffer processed are available for output on detail lines.

Example 2: Arithmetic Operation—Compound

028010 COMPUTE (REVENUE - COST) / COUNT AVE-PROFIT

This procedure statement executes in the output phase; because a sequence number is specified, the statement can be the object of a branch. Internally, the COMPUTE statement is processed as shown:

028   REVENUE  -  COST      WORK*01
028   WORK*01  /  COUNT     AVE-PROFIT

The difference in total revenue and total cost is divided by COUNT, which signifies the number of records processed by Report 02. The result of this computation is stored in the work field, AVE-PROFIT. The total values of REVENUE, COST, and COUNT and the calculated value of AVE-PROFIT can be output on total lines each time a control break executes and at the end of the output phase.

Example 3: Conditional Operation—Simple

227     CRED-LIMIT GT 500.00 TAKE

When the value of CRED-LIMIT is greater than $500.00 dollars, any remaining type 7 procedure logic for Report 22 is bypassed and the current buffer is extracted. If the comparison is false, the next type 7 process statement is processed.

An alternative method for coding this procedure logic appears below:

22I   CRED-LIMIT LE 500.00 DROP
22I   TAKE

Example 4: Conditional Operation—Compound

 467030 IF DAY.INDX NE ('MON' 'WED' 'FRI')
*       OR INIT EQ ('A' TO 'L') DROP

Two comparisons are specified in this compound test statement. An occurrence of the multiply-occurring field DAY is compared to a list of alphanumeric literals for a NE (not equal) condition. INIT is compared to a range of alphanumeric values for an equal condition. If one of these tests is true, DROP executes; that is, a DROP is performed when either the value of DAY.INDX does not equal MON, WED, or FRI or the value of INIT is in the range 'A' through 'L', inclusive. An input buffer that is not dropped continues processing in the 7 logic of Report 46.

Example 5: Conditional Operation—EOF

8951*010 TOTAL-BAL
897010  EOF EQ TAKE
897020  COMPUTE CURR-BAL + TOTAL-BAL  TOTAL-BAL
897030  DROP

An end-of-file condition is tested for each record processed. When end-of-file is reached, the type 7 procedure logic is entered one more time. Since the first type 7 statement specifies a TAKE action, any remaining type 7 process statements are not executed. If the EOF test were coded after the COMPUTE and DROP statements, the detail line for the report would not be extracted since the DROP action would occur before the EOF statement.

The code in this example achieves the same result as a totals-only report that contains no procedure logic, as shown below:

89       OUT T
8951*010  CURR-BAL    $CURR-BAL REPLACES TOTAL-BAL

Example 6: Conditional Operation—EOF

Sample code containing multiple EOF tests follows:

027    IF EOF EQ 200
 .
 .          ◄- Processing logic for input records
 .
027200      ◄- Processing logic for input records and EOF
 .
 .
 .
027    IF EOF EQ DROP
 .
 .          ◄- Processing logic for input records
 .

When the end of the file is reached, the type 7 code is entered one last time. The first type 7 statement passes processing control to the process statement with sequence number 200. The statements coded between sequence number 200 and the second EOF test execute.

Example 7: Conditional Operation—LEVL

01SORT DIVISION,-,DEPARTMENT,0,TITLE,EMP-LNAME
128    IF LEVL EQ 2 100
128    IF LEVL EQ 3 200
128    MOVE 'DEPARTMENT TOTALS' TO LABEL
128    TAKE
128100 MOVE 'DIVISION TOTALS' TO LABEL
128    TAKE
128200 MOVE 'COMPANY TOTALS' TO LABEL

This type 8 process parameter tests the level of the control break during break processing. Level 1 refers to the control break associated with DEPARTMENT on the SORT parameter; level 2 refers to the control break associated with DIVISION. The value of LEVL at grand totals time is one more than the number of control breaks specified on the SORT parameter. In this example, the value of LEVL is 3.

Depending on the level of the control break, the literal DEPARTMENT TOTALS, DIVISION TOTALS, or COMPANY TOTALS moves to LABEL. When TAKE executes, the total lines are output and processing for the current control break stops. A TAKE automatically executes after the last procedure statement, so an explicit statement is not coded after sequence number 200.

Example 8: Conditional Operation—Branch

627    B 300

Processing control passes unconditionally to the type 7 process parameter with a sequence number of 300.

Example 9: Conditional Operation—Branch

2541*001 ACCOUNT-NUM
257010   B HEAD

In this example, ACCOUNT-NUM is referenced on a type 4 edit parameter, but not on a SORT parameter for Report 25. Therefore, it is necessary to code a B HEAD statement so that values of ACCOUNT-NUM can appear as report headers.

Example 10: Assignment Operation—MOVE

437    MOVE 'AMT NOW DUE' TO DISPLAY-MESSAGE

In this example of a MOVE operation, the literal 'AMT NOW DUE' is moved to a work field, DISPLAY-MESSAGE. If the length of DISPLAY-MESSAGE is smaller than the length of the literal, the excess characters in the literal truncate on the right; when this happens, CA Culprit issues a W-level message in the Input Parameter Listing.

In the example presented below, DISPLAY-MESSAGE is set to blanks, by coding a single blank in the MOVE operation. Since the field being moved is smaller than the result field, the rightmost characters of DISPLAY-MESSAGE are padded with blanks.

437    MOVE ' ' TO DISPLAY-MESSAGE

Example 11: Assignment Operation—MOVE

548010 IF LEVL NE 2 070
548020 MOVE 0 TO PAGE

The system-maintained work field PAGE is reset to 0 when the current control break is 2. Because the value of PAGE increases by 1 before printing, the next page appears in the title as PAGE 1. When the control break does not equal 2, processing control passes to the type 8 process parameter that has a sequence number of 070.

Example 12: Assignment Operation—MOVE

0151*020 PRINT-NUM
017      MOVE NUMERIC-WORK-FLD.2 TO PRINT-NUM

The second occurrence of a multiply-occurring work field, NUMERIC-WORK-FLD, is moved to another work field, PRINT-NUM, for output during input processing. To perform this operation, PRINT-NUM must be defined as numeric.

Example 13: Assignment Operation—CONVERT

670  WORK-FIELD
677     CONVERT '     128' TO WORK-FIELD

The alphanumeric literal (space)(space)(space)(space)(space)128 is converted to the numeric value 00000128 (space represents blanks); this value is placed in a numeric work field, WORK-FIELD.

Example 14: Assignment Operation—CONVERT

020 WORK-DP2  DP=2  ALPHA-WORK '12345.67'
027    CONVERT ALPHA-WORK TO WORK-DP2

In this example, the alphanumeric and numeric work fields both contain two decimal positions. The CONVERT statement assigns WORK-DP2 the numeric equivalent of the alphanumeric literal.

If ALPHA-WORK had a value with three decimal positions, for example: 12345.678, the numeric value assigned to WORK-DP2 would be rounded to two decimal positions: 12345.68.

Example 15: Control Operation—PERFORM/RETURN

337010 IF BALANCE LE 200 860
337020 PERFORM 810
         -                  ◄- More procedure logic
         -
337    TAKE
337810 BALANCE + TOT-BAL TOT-BAL
337    COUNT + 1 COUNT
337    RETURN
337860 MOVE LOW-BAL-MESSAGE TO MESSAGE

In the sample code above, processing control is passed to the process parameter that has sequence number 810 when the input buffer value for BALANCE is greater than 200. TOT-BAL and COUNT are incremented, and processing control returns to the process statement that follows the PERFORM statement. A TAKE instruction selects the record for printing and bypasses remaining process code.

If BALANCE is less than or equal to 200, a message is transferred to a work field referenced on a type 5 edit parameter. An implicit TAKE at the end of type 7 logic selects the record for printing.

Example 16: Control Operation—CALL

997    CALL US11 (JUL-DATE, GREG-DATE)

This CALL statement invokes a CA-supplied procedure module, CULLUS11 (Julian Date Conversion). (See CA Culprit for CA IDMS User Modules Guide for details on coding this procedure module.) Two arguments are passed to the procedure module: JUL-DATE corresponds to ARG1; GREG-DATE corresponds to ARG2.

Internally, CA Culprit processes the CALL statement shown above as follows:

997   MOVE  JUL-DATE  ARG1
997   MOVE  GREG-DATE ARG2
997   B     US11

Example 17: Control Operation—PICK/TAKE

6651*010 'BALANCE'
6651*020 POSITIVE-BALANCE
6651*030 ACCOUNT-NUM
6652*010 'NEGATIVE BALANCE'
6652*020 NEGATIVE-BALANCE
6652*030 ACCOUNT-NUM
6653*030 NUM-TRANSACTIONS
667    PICK 3
667    IF AMOUNT LT 0  040
667    MOVE AMOUNT TO POSITIVE-BALANCE
667    TAKE 1
667040 MOVE AMOUNT TO NEGATIVE-BALANCE
667    TAKE 2

In this example, detail line 3 is always selected to be extracted, as specified by the PICK statement. It is extracted, however, as a result of a subsequent TAKE statement. Detail line 1 is extracted when the value of AMOUNT is greater than or equal to 0; detail line 2 is extracted when the value of AMOUNT is less than 0.

Example 18: Control Operation—TAKE

2261*0100'DIVISION TOTAL'
2261*040 TOTAL-SALARIES
2262*010 'NUMBER OF EMPLOYEES'
2262*040 COUNT
2263*040 ANNUAL-EMP-SALARY
2264*040 STATUS
228    IF LEVL NE 1  070
228    TAKE (3 4)
228070 TAKE (1 2)

Edit lines 1 and 2 are selected when the control break is not 1; edit lines 3 and 4 are selected when the control break is 1. When a new control break executes, the status of all type 6 edit parameters is set to deselect because line selection specifications are coded on type 8 process parameters.

Example 19: Control Operation—RELS/TAKE

017    COMPUTE BAL-DUE  -  PAYMENT  BAL-DUE
017    RELS (1,2,4)
017    IF BAL-DUE GT 0 DROP
017    TAKE 3      $THIS LINE FLAGS ZERO/NEGATIVE BALANCES

After the arithmetic process statement executes, edit lines 1, 2, and 4 are extracted to the extracted items and statistics file. If a positive balance remains due, processing ends for this record. If a negative or zero balance remains due, edit line 3 is extracted also.

Internally, the RELS statement is processed as shown below:

017    PICK (1 2 4)     $SELECT LINES 1 2 and 4
017    RELS             $PRINT LINES 1 2 and 4
017    UNPICK (1 2 4)   $DESELECT LINES 1 2 and 4

The RELS statement resets the select/deselect status of edit lines 1, 2, and 4; edit line 3 must be explicitly selected in the TAKE statement in order to print. When a RELS immediately follows a PICK, the user must explicitly deselect lines coded on the PICK instruction, as appropriate.

Example 20: Control Operation— DROP

347010 IF SEX EQ 'F' DROP
347020 IF AGE LE 65  DROP
    -
    -                     ◄-  More procedure logic

Records of all males over the age of 65 are selected for processing in report 34. All other records are dropped.