2. SYNC Clause
05 DATA-ONE PIC X(6).
05 DATA-TWO PIC 9(6) COMP SYNC.
05 DATA-THREE PIC S9(4)V99 COMP-3.
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).
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
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.
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 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
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
IF Condition-3 THEN
IF statement within the IF statement called as nested IF statement.
20. Simple EVALUATE Statement
DISPLAY 'Alphabetic filed'
DISPLAY 'Numeric filed'
DISPLAY 'Alpha numeric filed'
DISPLAY 'Invalid indicator value'
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
MOVE 0 TO WS-RATE-OF-INT
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 " "
23. UNSTRING Statement
DELIMITED BY " "
INTO FIRST-NAME LAST-NAME.
24. INSPECT Statement with TALLYING option
INSPECT WS-STRING TALLYING WS-COUNT FOR CHARACTER.
INSPECT WS-STRING TALLYING WS-COUNT FOR ALL 'E'.
25. INSPECT Statement with REPLACING option
INSPECT WS-STRING REPLACING ALL 'E' BY 'I'.
26. Reference Modification in MOVE Statement
MOVE WS-FULL-NAME(1:3) TO WS-NAME
MOVE WS-PHONE TO WS-COUNTRY-CODE(1:3)