2. SYNC Clause
01 MY-DATA.
05 DATA-ONE PIC X(6).
05 DATA-TWO PIC 9(6) COMP SYNC.
05 DATA-THREE PIC S9(4)V99 COMP-3.
3. Redefines
01 WS-DATE PIC 9(06).
01 WS-REDEF-DATE REDEFINES WS-DATE.
05 WS-YEAR PIC 9(02).
05 WS-MONTH PIC 9(02).
05 WS-DAY PIC 9(02).
4. Renames
01 WS-REPSONSE.
05 WS-CHAR143 PIC X(03).
05 WS-CHAR4 PIC X(04).
66 ADD-REPSONSE RENAMES WS-CHAR143.
5. Condition Name
01 GENDER PIC X.
88 MALE VALUE ‘1’
88 FEMALE VALUE ‘2’ ‘3’.
11. CORRESPONDING (CORR) phrase
05 WS-FIELD-1.
10 WS-FIELD-A PIC S9(3).
10 WS-FIELD-B PIC +99.9.
10 WS-FIELD-C PIC X(4).
10 WS-FIELD-D REDEFINES WS-FIELD-C PIC 9(4).
10 WS-FIELD-E USAGE COMP-1.
10 WS-FIELD-F USAGE INDEX.
05 WS-FIELD-2.
10 WS-FIELD-A PIC 99.
10 WS-FIELD-B PIC +9V9.
10 WS-FIELD-C PIC A(4).
10 WS-FIELD-D PIC 9(4).
10 WS-FIELD-E PIC 9(9) USAGE COMP.
10 WS-FIELD-F USAGE INDEX.
If ADD CORR WS-FIELD-2 TO WS-FIELD-1 is specified, WS-FIELD-A and WS-FIELD-A, WS-FIELD-B and WS-FIELD-B, and WS-FIELD-E
and WS-FIELD-E are considered to be corresponding and are added together. WS-FIELD-C and WS-FIELD-C are not included
because they are not numeric. WS-FIELD-D and WS-FIELD-D are not included because WS-FIELD-D includes a REDEFINES clause
in its data description. WS-FIELD-F and WS-FIELD-F are not included because they are index data items.
13. PERFORM PARA-NAME-1 THRU PARA-NAME-2 Statement
PERFORM PARA-NAME-1 THRU PARA-NAME-2
PARA-NAME-1, PARA-NAME-2 are paragraph names. Execution of PERFORM statement causes control transfers
to the first statement of PARA-NAME-1. control executes all the statements from the first statement
of PARA-NAME-1 to last statement of PARA-NAME-2 and the control return to the next executable statement
of PERFORM statement. if there are any other paragraphs between PARA-NAME-1 and PARA-NAME-2, all those
statements are included for execution.
14. PERFORM Statement with TIMES phrase
PERFORM PARA-NAME-1 THRU PARA-NAME-2 5 TIMES.
All the statements in the scope of PARA-NAME-1 thru PARA-NAME-2 are get executed 5 times. Control then
passes to the next executable statement following PERFORM statement.
15. PERFORM Statement with UNTIL phrase
PERFORM PARA-NAME-1 VARIYING WS-A FROM 1 BY 1 UNTIL WS-A > 5
All statements in PARA-NAME-1 are executed till the codition associated with UNTIL
becomes true. For first iteration WS-A contains the value of 1 ( as it is specified after FROM ),
for second iteration WS-A value increase by 1 ( as it is specified after BY keyword) and condition
will be tested, if it false statements in PARA-NAME-1 will get executed and control come back to PERFORM,
Now WS-A value increased again by 1 and condition will be tested, if it is false, statements in
PARA-NAME-1 will get executed again. This loop continues till the condition becomes true.
16. PERFORM Statement with VARYING, AFTER phrases
PERFORM PARA-NAME-1 VARIYING WS-A FROM 1 BY 1 UNTIL WS-A > 10
AFTER WS-B FROM 1 BY 1 UNTIL WS-B > 5
In this example, in addition to WS-A, WS-B value also get changed.
For every valid value in WS-A, WS-B value start from 1 till WS-B > 5 becomes true.
PERFORM statement execution ends only when WS-A > 10 becomes true.
17. Conditional Statement - Simple IF
IF Condition
{Statement Block}
[END-IF].
If the condition is true, then it will execute the set of statements written in the IF block. If condition is not satisfied, the control will transfer to the next statements after the IF statement terminated.
END-IF is the scope terminator, which is optional in the program. The period (.) can be defined at the last statement of IF block.
If we didn't specify the period, then scope terminator END-IF is mandatory.
18. Conditional Statement - IF ELSE
IF Condition-1
{Statement-Block-1}
[ELSE]
{Statement-Block-2}
[END-IF].
In IF-ELSE, the block of statements will be executed if the specified condition is true. If the condition is false, the other set of statements will be executed, and those set will be under the ELSE block.
19. Conditional Statement - Nested IF
IF Condition-1 THEN
IF Condition-2 THEN
Statements-block-1
[ELSE
Statements-block-2
END-IF]
[ELSE
IF Condition-3 THEN
Statements-block-3
[ELSE
Statements-block-4
END-IF]
END-IF.]
IF statement within the IF statement called as nested IF statement.
20. Simple EVALUATE Statement
EVALUATE WS-DATA-TYPE-IND
WHEN 'A'
DISPLAY 'Alphabetic filed'
WHEN '1'
DISPLAY 'Numeric filed'
WHEN 'X'
DISPLAY 'Alpha numeric filed'
WHEN OTHER
DISPLAY 'Invalid indicator value'
END-EVALUATE
This example evaluates WS-DATA-TYPE-IND, if WS-DATA-TYPE-IND is 'A' displays
'Alphabetic field', if WS-DATA-TYPE-IND is '1' displays 'Numeric
filed', if WS-DATA-TYPE-IND is 'X' displays 'Alpha numeric filed'. If
WS-DATA-TYPE-IND is not 'A' or '1' or 'X' then it displays 'Invalid indicator value'.
21. Evaluate Statement with ALSO
EVALUATE TRUE ALSO WS-GENDER ALSO WS-AGE
WHEN WS-SALARY >= 1000 AND < 50000 ALSO 'M' ALSO 25 THRU 50
MOVE 0.5 TO WS-RATE-OF-INT
WHEN WS-SALARY >= 1000 AND < 50000 ALSO 'F' ALSO 25 THRU 60
MOVE 0.25 TO WS-RATE-OF-INT
WHEN OTHER
MOVE 0 TO WS-RATE-OF-INT
END-EVALUATE.
This example is an example of decision table, calculates tax rate based on
income, age and sex. First WHEN clause will satisfy if condition on income
(>= 1000 and < 50000) is true, gender is 'M' and age is in range of 25 to
50, if it is true, then MOVE statement after first when will get executed,
and control come out of EVALUATE.
If first WHEN condition becomes false, then control goes to second WHEN condition and check the condition, whether that is true or false, if it is true,
it will execute MOVE statement after the second WHEN condition. if second WHEN
condition is false, then control will go to the MOVE statement coded after WHEN
OTHER, here it wont check for true or false.
22. STRING Statement
STRING FIRST-NAME DELIMITED BY " "
" " DELIMITED BY SIZE
LAST-NAME DELIMITED BY " "
INTO FULL-NAME.
Field Name | Value |
FIRST-NAME | ABDUL |
LAST-NAME | KALAM |
FULL-NAME | ABDUL KALAM |
23. UNSTRING Statement
UNSTRING FULL-NAME
DELIMITED BY " "
INTO FIRST-NAME LAST-NAME.
Field Name | Value |
FULL-NAME | ABDUL KALAM |
FIRST-NAME | ABDUL |
LAST-NAME | KALAM |
24. INSPECT Statement with TALLYING option
INSPECT WS-STRING TALLYING WS-COUNT FOR CHARACTER.
Field Name | Value |
WS-STRING | JOEBIDEN |
WS-COUNT | 8 |
INSPECT WS-STRING TALLYING WS-COUNT FOR ALL 'E'.
Field Name | Value |
WS-STRING | JOE BIDEN |
WS-COUNT | 2 |
25. INSPECT Statement with REPLACING option
INSPECT WS-STRING REPLACING ALL 'E' BY 'I'.
Field Name | Value |
WS-STRING | JOE BIDEN |
WS-COUNT | JOI BIDIN |
26. Reference Modification in MOVE Statement
MOVE WS-FULL-NAME(1:3) TO WS-NAME
Field Name | Value |
WS-FULL-NAME | JOE BIDEN |
WS-NAME | JOE |
MOVE WS-PHONE TO WS-COUNTRY-CODE(1:3)
Field Name | Value |
WS-PHONE | +1-9876543210 |
WS-COUNTRY-CODE | +1- |