Control Statements (P-Z)

Review the following control statements.
view
Review the following control statements.
2
PRINT Control Statement
The PRINT control statement writes data to the print file.
Syntax
PRINT [
expression-1 
[
expression-2
]]  [COL(
expression
)] [SKIP(
expression
)][PAGE]
where:
  • expression-1
    Specifies an expression that determines the data to place in the print record.
  • expression-2
    Specifies an expression that determines the data to use as subheadings for expression-1.
    If expression-2 contains a comma (for example, 'REPORT,IDENTIFIER'), the data is split at that point and written on separate heading lines. The heading data is aligned to the same position as expression-1.
  • COL(
    expression
    )
    Specifies an expression that determines the position on the output record that expression-1 is written.
    A value of 1 represents the first print position (character after the carriage control character). If this value is less than the current column position, the current print record is written to the print file, and expression-1 is placed in the new print record.
    If COL is specified without an expression, the data is positioned directly after the previous print data.
    If COL(expression) is omitted, expression-1 is positioned one character from the previous print data.
  • SKIP(
    expression
    )
    Specifies an expression that determines the number of lines to skip before printing the next print record.
    This specification causes the current print record to be written to the print file and the column position to reset to the first column. If SKIP is specified without an expression, one line is skipped.
  • PAGE
    Specifies that the next print record is printed at the top of a new page.
    This specification also causes the current print record to be written to the print file and the column position to reset to the first column.
Note:
 If both PAGE and SKIP(
expression
) are specified, SKIP(
expression
) is ignored.
The data from each PRINT control statement is queued up contiguously in the print record. The print record is written under the following conditions:
  • Statement processing has completed processing for a given database record, and the next PRINT control statement does not specify the COL operand.
  • The COL operand is specified with a value less than the current column position.
  • The print record size is exceeded.
  • The PRINT control statement directs the print record to be written (SKIP or PAGE is specified).
Examples
To cause a control break (skip to the top of a new page) when job name changes, enter the following:
/IF JOBNAME ¬= PREV(JOBNAME) /       PRINT PAGE /END
To print the tape data set name in column 3 after skipping two lines, enter the following:
/PRINT TAPEDSN COL(3) SKIP(2)
To print SYSOUT ID, generation number, sequence number, archival date, archival time, lines, and pages, enter the following statements:
/PRINT ID  'ID'                             /PRINT EDIT(GEN,'ZZZZ9') '  Gen'            /PRINT EDIT(SEQ,'ZZZZ9') '  Seq'            /PRINT ARCHDATE 'Arc Date'                  /PRINT ARCHTIME 'Arc Time'                  /PRINT EDIT(LINES,'ZZZZZZZZ9') '    Lines' /PRINT EDIT(PAGES,’ZZZZZZZ9’) '   Pages'
To print a descriptive title preceding the field being printed, specify:
/PRINT 'CLASS='||CLASS
The same data can be printed using separate statements as follows:
/PRINT 'CLASS=' /PRINT CLASS COL
RELEASE Control Statement
The RELEASE control statement signals the construction and release of a sort record to the sort. The data released to the sort depends on the current values of database fields and defined fields. The RELEASE control statement is only allowed in logic before the sorting (statements preceding the SORT control statement).
The RELEASE control statement helps reduce the number of records that are released to the sort and to allow sorting of iterative fields, such as TEXT (report text line), INST (report instruction line), BINST (bundle instruction line), and A (distribution address line).
If the logic before the sorting drops through to the SORT control statement, an implied release is assumed.
Note:
 When coding the RELEASE control statement, avoid the release of identical information.
Syntax
RELEASE
Example
The following example restricts the sort selection to production jobs by interrogating the first four positions of the programmer name.
/DO FOREVER /   IF SUBSTR(PGMRNAME,1,4) = 'PROD' /      RELEASE /   END /NEXT RECORD /END /SORT ID /PRINT ID /PRINT ARCHDATE /PRINT ARCHTIME /PRINT PGMRNAME /END
The previous example shows the use of the RELEASE control statement. In most cases, complex logic as in that example is not needed. Selection of production jobs that start with PROD can be performed much easier using the SELECT control statement as follows.
/SELECT SUBSTR(PGMRNAME,1,4) = 'PROD' /SORT ID /PRINT ID /PRINT ARCHDATE /PRINT ARCHTIME /PRINT PGMRNAME /END
SELECT Control Statement
The SELECT control statement restricts statement processing to certain database records. The placement of the SELECT control statement is crucial, because it is interrogated at its relative position in the control statement flow. Typically, the SELECT control statement is placed at the beginning of the control statement flow or after the SORT control statement. Only one SELECT control statement is allowed, and it cannot be embedded in an IF or DO control statement.
Syntax
SELECT 
condition
where 
condition
 specifies the condition that is checked to determine which records to select from the database.
Example
To only select the job names that end with P1, specify the following:
/SELECT SUBSTR(JOBNAME,7,2) = 'P1'
SET Control Statement
The SET control statement sets a define field to a specific value.
Syntax
SET field=
expression-1
where 
expression-1 s
pecifies an expression that determines the data or value to place in the defined field.
Example
To set field ZIPCODE to positions 1 - 10 of address line 4, enter the following:
/DEFINE ZIPCODE CHAR(10) /SET ZIPCODE = ADDRESS2
Similarly, if ZIPCODE was in columns 21 - 30 of address line 3, you would extract this information as follows:
/DEFINE ZIPCODE CHAR(10) /SET ZIPCODE = SUBSTR(ADDRESS3,21,10)
SORT Control Statement
The SORT control statement orders information that is eventually written to the print and output files. Capabilities are provided to sort up to 15 fields in ascending or descending sequence.
Syntax
SORT
 field
[
-seq
][,
field
[-
seq
]] , …]
where:
  • field
    Specifies the name of the field to sort.
    This field can be a database field, a defined field, or a reserved field.
  • -seq
    Specifies the sequence for sorting the field.
    The sequence A is used for sorting in ascending sequence; the sequence D is used for sorting in descending sequence. If omitted, the field is sorted in ascending sequence.
The SORT control statement cannot be embedded in IF or DO control statements. Statements supplied before the SORT control statement are considered statements that are executed before the sort record is released to the sort. Statements following the SORT control statement are statements that are executed after the sort record is returned from the sort.
Example
To sort job name and SYSOUT ID in ascending sequence for a cross reference report, enter the following:
/SORT JOBNAME, ID
The same sort criteria can be given by specifying the sort sequence:
/SORT JOBNAME-A, ID-A
To print SYSOUT information sorted by page count from the largest to the smallest, specify the following:
/SORT PAGES-D, ID-A /PRINT ID  'ID'                             /PRINT EDIT(GEN,'ZZZZ9') '  Gen'            /PRINT EDIT(SEQ,'ZZZZ9') '  Seq'            /PRINT ARCHDATE 'Arc Date'                  /PRINT ARCHTIME 'Arc Time'                  /PRINT EDIT(LINES,'ZZZZZZZZ9') '    Lines' /PRINT EDIT(PAGES,’ZZZZZZZ9’) '   Pages'
STOP Control Statement
The STOP control statement signals the end of a processing phase and the start of the next processing phase, if applicable. The processing phases (in order) are:
  1. Non-sort logic or logic before the sorting (statements preceding the SORT control statement)
  2. End-of-data logic (ON control statement) for non-sort or pre-sort logic
  3. Post-sort logic (statements following the SORT control statement)
  4. End-of-data logic (ON control statement) for post-sort logic
The pre-sort and post-sort designations are not applicable if sorting is not requested (no SORT control statement).
Syntax
STOP
Example
The following example concludes processing when the first digit of JOB is greater than or equal to "B":
/IF SUBSTR(JOBNAME,1,1) GE 'B' /         STOP /END /PRINT JOBNAME
THEN Control Statement
The THEN control statement is used with the IF control statement to specify the statements that are executed when a true condition is determined for the IF control statement. The THEN control statement does not have to be specified. If the THEN control statement is specified, it can be specified at the end of the IF control statement specification or as a separate statement.
Syntax
THEN
If the THEN control statement is specified as a separated statement, this control statement must directly follow the corresponding IF control statement.
TITLE Control Statement
The TITLE control statement defines a report title for the printed report.
Syntax
TITLE
 expression-1
where 
expression-1
 specifies the expression whose data is used for the report title. This data is printed on the second line of the printed report and centered between the margins.
The TITLE control statement does not cause the report to eject to the top of a new page. The data for the TITLE control statement is saved and printed with each subsequent page. To force a page break, use the PRINT control statement (for example, PRINT PAGE). This PRINT control statement is specified before the TITLE control statement to help ensure that the current report record is written. If the TITLE control statement is not supplied, a report title of 'GENERAL REPORT WRITER UTILITY' is used.
Example
To set a report title of REPORT ATTRIBUTES, enter:
TITLE 'REPORT ATTRIBUTES'
To include the report identifier with a title, similar to the previous example, enter:
TITLE 'REPORT ATTRIBUTES FOR' ||ID