Download presentation
Presentation is loading. Please wait.
Published byTracey Holt Modified over 9 years ago
1
Lesson 6
2
05 NUMERIC-FIELDPIC 9(5). 05 ALPHANUMERIC-FIELDPIC X(5).... IF NUMERIC-FIELD = 10...(valid entry) IF NUMERIC-FIELD = ‘10’... (invalid entry) IF ALPHANUMERIC-FIELD = 10(invalid entry) IF ALPHANUMERIC-FIELD = ‘10’(valid entry) The Relational Condition (a) Syntax (b) Examples IS [NOT] GREATER THAN IS [NOT] > IS [NOT] LESS THAN identifier-1IS [NOT] = IS [NOT] LESS THAN OR EQUAL TO IS [NOT] <=
3
CONDITION? STATEMENT2 STATEMENT1 STATEMENT3 CONDITION? STATEMENT1 STATEMENT2 The IF Statement (a) With ELSE Option (b) Without ELSE Option FALSE TRUE
4
The ELSE Clause/II A=B MOVE ZERO TO C MOVE 1 TO C WRITE DETAIL-LINE MOVE ZERO TO D MOVE 1 TO D FALSETRUE IF A = B MOVE 1 TO C MOVE 1 TO D ELSE MOVE ZERO TO C MOVE ZERO TO D END-IF. WRITE DETAIL-LINE. (a) IF/ELSE Flowchart(b) COBOL Code
5
Nested IF Statements/II C>D? ADD 1 TO Y ADD 1 TO X A>B? FALSE TRUE IF A > B IF C > D ADD 1 TO X ELSE NEXT SENTENCE ELSE ADD 1 TO Y. IF A > B IF C > D ADD 1 TO X END-IF ELSE ADD 1 TO Y END-IF (b) NEXT SENTENCE (COBOL-74) (c) Scope Terminators (COBOL-85) (a) Flowchart
6
IBM COBOL Reference Manual: ‘The presence of one or more IF statements within the initial IF statement constitutes a "nested IF statement." Nesting statements is much like specifying subordinate arithmetic expressions enclosed in parentheses and combined in larger arithmetic expressions.’ Nested IF’s
7
IF A = B NEXT SENTENCE ELSE PERFORM D0-ARITHMETIC-CALCULATIONS END-IF. IF condition A = B is true then NEXT SENTENCE is executed and the ELSE phrase is ignored, and control passes to the statement following the END-IF.
8
The Class Test NUMERIC ALPHABETIC IF identifier IS [NOT]ALPHABETIC-UPPER ALPHABETIC-LOWER (a) Syntax 05 NUMERIC-FIELDPIC 9(5). 05 ALPHABETIC-FIELDPIC X(5).... IF NUMERIC-FIELD IS NUMERIC PERFORM D0-ARITHMETIC-CALCULATIONS END-IF. IF NUMERIC-FIELD IS NOT NUMERIC DISPLAY ‘ERROR - NUMERIC FIELD CONTAINS INVALID DATA’ END-IF. IF ALPHABETIC-FIELD IS ALPHABETIC DISPLAY ‘ALPHABETIC FIELD CONTAINS UPPER AND/OR LOWER CASE LETTERS’ END-IF. IF ALPHABETIC-FIELD IS NOTALPHABETIC DISPLAY ‘ERROR - ALPHABETIC FIELD CONTAINS NON-ALPHABETIC DATA’ END-IF. (b) Examples
9
The SignTest identifierPOSITIVE IF arithmetic expression IS [NOT]NEGATIVE ZERO (a) Syntax IF NET-PAY IS NOT POSITIVE PERFORM TOO-MUCH-TAXES END-IF. IF CHECK-BALANCE IS NEGATIVE PERFORM OVERDRAWN END-IF. (b) Examples
10
Condition Names (88-level entries) (a) Syntax 05 YEAR-CODEPIC 9. 88 FRESHMANVALUE 1. 88 SOPHOMOREVALUE 2. 88 JUNIORVALUE 3. 88 SENIORVALUE 4. 88 GRAD-STUDENTVALUES ARE 5 THRU 8. 88 UNDER-CLASSMANVALUES ARE 1, 2 88 UPPER-CLASSMANVALUES ARE 3, 4. 88 VALID-CODESVALUES ARE 1 THRU 8. IF FRESHMAN PERFORM WELCOME-NEW-STUDENTS END-IF IF VALID-CODES PERFORM PROCESS-STUDENT-RECORD ELSE DISPLAY ‘INCOMING YEAR CODE IS IN ERROR’ END-IF. (b) Examples VALUE ISTHROUGH 88 data-name VALUES AREliteral-1 THRU literal-2...
11
Level 88 Identifies any condition-name entry that is associated with a particular value of a conditional variable. Check sample code (program CPCH13B)
12
The ACCEPT Statement WORKING-STORAGE SECTION. 01 EMPLOYEE-RECORD... 05 EMP-DATE-OF-BIRTH. 10 EMP-BIRTH-MONTHPIC 99. 10 EMP-BIRTH-YEARPIC 99. 01 EMPLOYEE-AGEPIC 99V99. 01 DATE-WORK-AREA. 05 TODAYS-YEARPIC 99. 05 TODAYS-MONTHPIC 99. 05 TODAYS-DAYPIC 99... PROCEDURE DIVISION... ACCEPT DATE-WORK-AREA FROM DATE... COMPUTE EMPLOYEE-AGE = TODAYS-YEAR - EMP-BIRTH-YEAR + (TODAYS-MONTH - EMP-BIRTH-MONTH) / 12.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.