Day 4
You can specify whether or not some conditions are enabled or disabled. If
a condition is enabled, the raising of the condition executes an action. If a
condition is disabled, the raising of the condition does not execute an action.
Enabling and disabling can be specified for the eligible conditions by a
condition prefix. For example:
The conditions that are always enabled unless they are explicitly disabled by
condition prefixes are:
CONVERSION
FIXEDOVERFLOW
OVERFLOW
UNDERFLOW
ZERODIVIDE
NOFIXEDOVERFLOW
NOOVERFLOW
NOUNDERFLOW
NOZERODIVIDE
The conditions that are always disabled unless they are enabled by a
condition prefix are:
SIZE
SUBSCRIPTRANGE
STRINGRANGE
STRINGSIZE
NOSUBSCRIPTRANGE
NOSTRINGRANGE
NOSTRINGSIZE
All other conditions are always enabled and cannot be disabled. These
conditions are:
AREA KEY
ATTENTION
NAME
CONDITION
RECORD
ENDFILE
TRANSMIT
ENDPAGE
UNDEFINEDFILE
ERROR
PENDING
FINISH
Conditions that are detected by the compiler while compiling your program
are diagnosed and do not raise the condition when the program is executed.
The scope of a condition prefix (the part of the program throughout which it
applies) is the statement or block to which the prefix is attached. The prefix
does not necessarily apply to any procedures or ON-units that can be
invoked in the execution of the statement.
A condition prefix attached to a PROCEDURE or BEGIN statement applies
to all the statements up to and including the corresponding END statement.
This includes other PROCEDURE or BEGIN statements nested within that
block.
The scope of a condition prefix applied to a DO or SELECT statement is
limited to execution of the statement itself; it does not apply to execution of
the entire group.
SNAP Is optional Specifies that when the enabled condition is raised, a list
is printed of all the blocks and ON-units active in the current task at the time
the condition is raised. The action of the SNAP option precedes the action
of the ON-unit.
SYSTEM Specifies that the implicit action is taken. The implicit action is not
the same for every condition, although for most conditions a message is
printed and the ERROR condition is raised
The effect of a null statement ON-unit is to execute normal return from the
condition. Use of the null ON-unit is not the same as disabling, for two
reasons:
A null ON-unit can be specified for any condition, but not all conditions
can be disabled.
Disabling a condition, if possible, can save time by avoiding any
checking for this condition. (If a null ON-unit is specified, the system
must still check for the raising of the condition).
ON ERROR BEGIN;
ON ERROR SYSTEM;
.
.
.
END;
An ON statement that specifies a file variable refers to the file constant that
is the current value of the variable when the ON-unit is established.
Example 1:
DCL F FILE,
G FILE VARIABLE;
G = F;
L1: ON ENDFILE(G);
L2: ON ENDFILE(F);
The statements labeled L1 and L2 are equivalent.
Example 2:
An ENDFILE condition raised during the first READ statement causes the
ON-unit to be entered, since the ON-unit refers to file FC1. If the condition is
raised in the second READ statement, however, the ON-unit is not entered,
since this READ refers to file FC2.
Example 3:
E: PROCEDURE;
An end-of-file encountered for F1 in
DECLARE F1 FILE; E1 causes the ON-unit for F2 in E1 to
ON ENDFILE (F1) GOTO L1; be entered. If the ON-unit in E1 was
CALL E1 (F1); not specified, an ENDFILE condition
. encountered for either F1 or F2 would
. cause entry to the ON-unit for F1 in E.
.
E1: PROCEDURE (F2);
DECLARE F2 FILE;
ON ENDFILE (F2) GO TO L2;
READ FILE (F1);
READ FILE (F2);
END E1;
Example 4:
REVERT condition;
SIGNAL condition;
Conditions
CONVERSION
Abbreviation CONV
The SIZE computational condition is raised only when high-order (that is,
leftmost) significant binary or decimal digits are lost in an attempted
assignment to a variable or an intermediate result or in an input/output
operation. This loss can result from a conversion involving different data
types, different bases, different scales, or different precisions.
The size condition is not enabled unless it appears in a condition prefix.
The SIZE condition differs from the FIXEDOVERFLOW condition in that,
whereas FIXEDOVERFLOW is raised when the size of a calculated fixed-
point value exceeds the maximum allowed by the implementation, SIZE is
raised when the size of the value being assigned to a data item exceeds the
declared (or default) size of the data item. SIZE can be raised on
assignment of a value regardless of whether or not FIXEDOVERFLOW was
raised in the calculation of that value.
SIZE
FIXEDOVERFLOW
FOFL
UNDERFLOW
UFL
OVERFLOW
OFL
ZERODIVIDE
ZDIV
ENDFILE (file-reference)
PENDING
The value of the ONKEY built-in function when the PENDING condition is
raised is a null string.
ENDPAGE (file-reference)
RECORD (file-reference)
KEY (file-reference)
TRANSMIT (file-reference)
MAME (file-reference)
Implicit Action: The incorrect data field is ignored, a message is printed, and
execution of the GET statement continues.
Status: NAME is always enabled.
Normal Return: The execution of the GET statement continues with the next
name in the stream.
Condition Code: 10
UNDEFINABLE (file-reference)
UNDF
STRINGSIZE
STRZ
Result: After the condition action, the truncated string is assigned to its
target string. The right-hand characters, bits, or graphics of the source string
are truncated so that the target string can accommodate the source string.
Implicit Action: A message is printed and processing continues. However, if
error messages and program output are using the same output stream, the
output is unpredictable because no synchronization between them is
provided.
Status: STRINGSIZE is disabled by default and within the scope of a
NOSTRINGSIZE condition prefix. It is enabled only within the range of a
STRINGSIZE condition prefix.
Normal Return: Execution continues from the point at which the condition
was raised.
Condition Codes: 150 151
STRINGRANGE
STRG
SUBSCRIPTRANGE
SUBRG
Result: When SUBSCRIPTRANGE has been raised, the value of the invalid
subscript is undefined, and, hence, the reference is also undefined.
Implicit Action: A message is printed and the ERROR condition is raised.
Status: SUBSCRIPTRANGE is disabled by default and within the scope of a
NOSUBSCRIPTRANGE condition prefix. It is enabled only within the scope
of a SUBSCRIPTRANGE condition prefix.
Normal Return: Normal return from a SUBSCRIPTRANGE ON-unit raises
the ERROR condition.
Condition Codes: 520 521
ERROR
Implicit Action:
The ATTENTION condition is raised when the user signals attention at the
terminal during interactive processing. Raising the condition causes an
ATTENTION ON-unit to be entered. The condition can also be raised by a
SIGNAL ATTENTION statement in batch or conversational processing.
ATTENTION
ATTN
CONDITION
COND
Stream-oriented data transmission uses only one input statement, GET, and
one output statement, PUT. The FORMAT statement specifies the format of
data values being transmitted and is used only for edit-directed data
transmission.
The variables or pseudovariables to which data values are assigned, and
the expressions from which they are transmitted, are generally specified in a
data-specification with each GET or PUT statement. The statements can
also include options that specify the origin or destination of the data values
or indicate where they appear in the stream relative to the preceding data
values.
Only sequential files can be processed with the GET and PUT statements.
The keywords can appear in any order. The data specification must
Syntax
Syntax
The FORMAT statement specifies a format list that can be used by edit-
directed data transmission statements to control the format of the data being
transmitted.
FILE
COPY
SKIP
PAGE
LINE
STRING
The FILE option specifies the file upon which the operation takes place. It
must be a STREAM file.
If neither the FILE option nor the STRING option appears in a GET
statement, the input file SYSIN is the default.
If neither option appears in a PUT statement, the output file SYSPRINT is
the default.
The COPY option specifies that the source data stream is written on the
specified STREAM OUTPUT file without alteration. If no file reference is
given, the default is the output file SYSPRINT. Each new record in the input
stream starts a new record on the COPY file. For example:
GET FILE(SYSIN) DATA(A,B,C) COPY(DPL);
Not only transmits the values assigned to A, B, and C in the input stream to
the variables with these names, but also writes them exactly as they appear
in the input stream, on the file DPL. If they are written by default on the
SYSPRINT file, they appear in data-directed format. Data values that are
skipped on input, and not transmitted to internal variables, copy intact into
the output stream.
The SKIP option specifies a new current line (or record) within the data set.
The expression is evaluated and converted to an integer value, n. The data
set is positioned to the start of the nth line (record) relative to the current line
(record). If expression is not specified, the default is SKIP(1). The SKIP
option takes effect before the transmission of values defined by the data
specification (if any).
For example: PUT LIST(X,Y,Z) SKIP(3); prints the values of the variables X,
Y, and Z on the output file SYSPRINT commencing on the third line after the
current line. For output non-PRINT files and input files, if the expression in
the SKIP option is less than or equal to zero, a value of 1 is used. For output
PRINT files, if n is less than or equal to zero, the positioning is to the start of
the current line.
The PAGE option can be specified only for output PRINT files. It defines a
new current page within the data set. If PAGE and LINE appear in the same
PUT statement, the PAGE option is applied first. The PAGE option takes
effect before the transmission of any values defined by the data
specification (if any). When a PAGE format item is encountered, a new page
is defined.
The page remains current until the execution of a PUT statement with the
PAGE option, until a PAGE format item is encountered, or until the
ENDPAGE condition is raised, which can result in the definition of a new
page. A new current page implies line one.
The LINE option can be specified only for output PRINT files. The LINE
option defines a new current line for the data set.
The expression is evaluated and converted to an integer value, n. The new
current line is the nth line of the current page. If at least n lines have already
been written on the current page or if n exceeds the limits set by the
PAGESIZE option of the OPEN statement, the ENDPAGE condition is
raised. If n is less than or equal to zero, a value of 1 is used. If n specifies
the current line, ENDPAGE is raised except when the file is positioned on
column 1. In this case, the effect is as for a SKIP(0) option.
The LINE option takes effect before the transmission of any values defined
by the data specification (if any). If both the PAGE option and the LINE
option appear in the same statement, the PAGE option is applied first.
For example: PUT FILE(LIST) DATA(P,Q,R) LINE(34) PAGE; prints the
values of the variables P, Q, and R in data-directed format on a new page,
commencing at line 34.
The STRING option in GET and PUT statements transmits data between
main storage locations rather than between the main and auxiliary storage
facilities. DBCS data items cannot be used with the STRING option.
The GET statement with the STRING option specifies that data values
assigned to the data list items are obtained from the expression, after
conversion to character string. Each GET operation using this option always
begins at the leftmost character position of the string. If the number of
characters in this string is less than the total number of characters specified
by the data specification, the ERROR condition is raised.
In the STRING option of a PUT statement, the character reference cannot
be the STRING pseudovariable.
The PUT statement with the STRING option specifies that values of the data
list items are to be assigned to the specified character variable or
pseudovariable. The PUT operation begins assigning values at the leftmost
character position of the string, after appropriate conversions are performed.
Blanks and delimiters are inserted as usual. If the string is not long enough
to accommodate the data, the ERROR condition is raised.
The NAME condition is not raised for a GET DATA statement with the
STRING option. Instead, the ERROR condition is raised for situations that
raise the NAME condition for a GET DATA statement with the FILE option.
The STRING option is most useful with edit-directed transmission. The
COLUMN control format option cannot be used with the STRING option.
The STRING option allows data gathering or scattering operations
performed with a single statement, and it allows stream-oriented processing
of character strings that are transmitted by record-oriented statements.
Example 1:
READ FILE (INPUTR) INTO (TEMP);
GET STRING(TEMP) EDIT (CODE) (F(1));
IF CODE = 1 THEN
GET STRING (TEMP) EDIT (X,Y,Z) (X(1), 3 F(10,4));
The READ statement reads a record from the input file INPUTR. The first
GET statement uses the STRING option to extract the code from the first
byte of the record and assigns it to CODE. If the code is 1, the second GET
statement uses the STRING option to assign the values in the record to X,Y,
and Z. The second GET statement specifies that the first character in the
string TEMP is ignored (the X(1) format item in the format list). The
character that is ignored in the second GET statement is the same
character that is assigned to CODE by the first GET statement.
Example 2
PUT STRING (RECORD) EDIT
(NAME) (X(1), A(12))
(PAY#) (X(10), A(7))
(HOURS*RATE) (X(10), P'$999V.99');
WRITE FILE (OUTPRT) FROM (RECORD);
The PUT statement specifies, by the X(1) spacing format item, that the first
character assigned to the character variable is to be a single blank, which is
the ANS vertical carriage positioning character that specifies a single space
before printing. Following that, the values of the variables NAME and PAY#
and of the expression HOURS*RATE are assigned. The WRITE statement
specifies that record transmission is used to write the record into the file
OUTPRT.
Example
GET LIST (N,(X(I) DO I=1 TO N),J,K, SUBSTR (NAME, J,K));
When this statement is executed, values are transmitted and assigned in the
following order:
A new value is assigned to N.
Elements are assigned to the array X as specified in the repetitive-specification
in the order X(1),X(2),...X(N), with the new value of N specifying the number of
assigned items.
A new value is assigned to J.
A new value is assigned to K.
A substring of length K is assigned to the string variable NAME, beginning at the
Jth character.
DATA (data-list)
Syntax
Example:
GET EDIT (NAME, DATA, SALARY)(A(N), X(2), A(6), F(6,2));
This example specifies that the first N characters in the stream are treated
as a character string and assigned to NAME. The next 2 characters are
skipped. The next 6 are assigned to DATA in character format. The next 6
characters are considered an optionally signed decimal fixed-point constant
and assigned to SALARY.
Example:
PUT EDIT('INVENTORY='||INUM,INVCODE)(A,F(5));
Example
PUT EDIT ('QUARTERLY STATEMENT')(PAGE, LINE(2),A(19))
(ACCT#, BOUGHT, SOLD, PAYMENT, BALANCE)
(SKIP(3), A(6), COLUMN(14), F(7,2), COLUMN(30), F(7,2),
COLUMN(45), F(7,2), COLUMN(60), F(7,2));
Picture Formats
X
Any character of the 256 possible bit combinations represented by the 8-
bit byte.
A
Any alphabetic character, #, @, $, or blank.
9
Any digit, or blank. (Note that the 9 picture specification character in
numeric character specifications is different in that the corresponding
character can only be a digit).
Valid Values
DECLARE PART# PICTURE 'AAA99X'; ‘ABC12M’
PUT EDIT (PART#) (P'AAA99X'); ‘bbb09/’
‘XYZb13’
The picture characters comma (,), point (.), slash (/), and blank (B) cause
the specified character to be inserted into the associated position of the
numeric character data. They do not indicate digit or character positions, but
are inserted between digits or characters. Each does, however, actually
represent a character position in the character value, whether or not the
character is suppressed. The comma, point, and slash are conditional
insertion characters and can be suppressed within a sequence of zero
suppression characters. The blank (B) is an unconditional insertion
character; it always specifies that a blank appears in the associated
position.