Download presentation
Presentation is loading. Please wait.
Published bySybil Fletcher Modified over 9 years ago
1
Figure 9.9Duplicate Data Names 01 STUDENT-RECORD. 05 STUDENT-NAMEPIC X(20). 05 SOCIAL-SECURITY-NUMPIC 9(9). 05 STUDENT-ADDRESS. 10 STREETPIC X(15). 10 CITY-STATEPIC X(15). 05 ZIP-CODEPIC X(5). 05 CREDITSPIC 9(3). 05 MAJORPIC X(10). 05 FILLERPIC X(3).... 01 PRINT-LINE. 05 STUDENT-NAMEPIC X(20). 05 FILLERPIC XX. 05 CREDITSPIC 9(3). 05 FILLERPIC XX. 05 TUITIONPIC $$,$$9.99. 05 FILLERPIC XX. 05 STUDENT-ADDRESS. 10 STREETPIC X(15). 10 CITY-STATEPIC X(15). 10 ZIP-CODEPIC X(5). 05 FILLERPIC XX. 05 SOCIAL-SECURITY-NUMPIC 999B99B9999. 05 FILLERPIC X(47). (a) Duplicate Data Names
2
Figure 9.9Duplicate Data Names MOVE CORRESPONDING STUDENT-RECORD TO PRINT-LINE (b) MOVE CORRESPONDING Statement MOVE STUDENT-NAME OF STUDENT-RECORD TO STUDENT-NAME OF PRINT-LINE. MOVE SOCIAL-SECURITY-NUM OF STUDENT-RECORD TO SOCIAL-SECURITY-NUM OF PRINT-LINE. MOVE STREET OF STUDENT-RECORD TO STREET OF PRINT-LINE. MOVE CITY-STATE OF STUDENT-RECORD TO CITY-STATE OF PRINT-LINE. MOVE CREDITS OF STUDENT-RECORD TO CREDITS OF PRINT-LINE. (c) Equivalent MOVE Statements
3
CONDITION? A A TRUE FALSE (a) DO WHILE Construct(b) DO UNTIL Construct The Iteration Structure
4
The PERFORM Verb Structured Programming uses iteration as an integral part of its main constructs. In COBOL the PERFORM statement handles all the different iterations. We will discuss the different variations of the Perform. But first, how do we define a paragraph
5
Paragraph Scope The scope of ‘100-INITIALIZATION-RTN’ is delimited by the occurrence of the paragraph name ‘200-PROCESS-SCREEN-RECORD-RTN’. Paragraph Scope The scope of ‘100-INITIALIZATION-RTN’ is delimited by the occurrence of the paragraph name ‘200-PROCESS-SCREEN-RECORD-RTN’.
6
PERFORM statement formats Basic PERFORM PERFORM... TIMES phrase. PERFORM... UNTIL phrase. PERFORM...VARYING phrase..
7
PERFORM variation examples PERFORM 1000-INITIALIZATION-RTN (THRU 100-EXIT). PERFORM 420-PRINT-RTN 2 TIMES. PERFORM 2000-PROCESS-SCREEN-RECORD-RTN UNTIL WS-FUNCTION-KEY-03. PERFORM 300-PRINT-RTN VARYING SUB FROM 1 BY 1 UNTIL SUB > 12 PERFORM UNTIL END-OF-FILE-SWITCH = 'YES’... END-PERFORM.
8
The Basic Peform This is the only type of PERFORM that is not an iteration construct. It instructs the computer to transfer control to an out-of-line block of code. When the end of the block is reached, control reverts to the statement (not the sentence) immediately following the PERFORM. 1stProc and EndProc are the names of Paragraphs or Sections. The PERFORM..THRU instructs the computer to treat the Paragraphs or Sections from 1stProc TO EndProc as a single block of code.
9
Keep them in line when possible The out-of-line Perform The in-line Perform Avoid GO TOs
10
READ INPUT-FILE AT END MOVE ‘NO’ TO DATA-REMAINS-SWITCH. PERFORM PROCESS-RECORDS UNTIL DATA-REMAINS-SWITCH = ‘NO’. PROCESS-RECORDS.... READ INPUT-FILE AT END MOVE ‘NO’ TO DATA-REMAINS-SWITCH. (a) Priming Read PERFORM UNTIL DATA-REMAINS-SWITCH = ‘NO’ READ INPUT-FILE AT END MOVE ‘NO’ TO DATA-REMAINS-SWITCH NOT AT END... END-READ END-PERFORM. (b) False Condition Branch with In-Line Perform Procedure Division statements to process the current record Figure 9.2Structure of a COBOL Program
11
EVALUATE Statement In many cases nested IF statements can be replaced by an EVALUATE statement. The EVALUATE statement evaluates multiple conditions and a particular action is taken depending on the results of these evaluations. Implements the Case Structure
12
IF Syntax. Simple Conditions –Relation Conditions –Class Conditions –Sign Conditions Complex Conditions Condition Names Simple Conditions –Relation Conditions –Class Conditions –Sign Conditions Complex Conditions Condition Names C ONDITION T YPES
13
The Evaluate statement EVALUATE TRUE WHEN STU-CREDITS <= 1ST-CREDIT-LIMIT MOVE 1ST-ACTIVITY-FEE TO IND-ACTIVITY-FEE WHEN STU-CREDITS > 1ST-CREDIT-LIMIT AND STU-CREDITS <= 2ND-CREDIT-LIMIT MOVE 2ND-ACTIVITY-FEE TO IND-ACTIVITY-FEE WHEN STU-CREDITS > 2ND-CREDIT-LIMIT MOVE 3RD-ACTIVITY-FEE TO IND-ACTIVITY-FEE WHEN OTHER DISPLAY 'INVALID CREDITS FOR: ' STU-NAME END-EVALUATE.
14
Check pgm Tuition5
15
EVALUATE MENU-INPUT WHEN "0" PERFORM INIT-PROC WHEN "1" THRU "9" PERFORM PROCESS-PROC WHEN "R" PERFORM READ-PARMS WHEN "X" PERFORM CLEANUP-PROC WHEN OTHER PERFORM ERROR-PROC END-EVALUATE. Equivalent Nested If’s IF (MENU-INPUT = "0") THEN PERFORM INIT-PROC ELSE IF (MENU-INPUT ° "1") AND (MENU-INPUT ° "9") THEN PERFORM PROCESS-PROC ELSE IF (MENU-INPUT = "R") THEN PERFORM READ-PARMS ELSE IF (MENU-INPUT = "X") THEN PERFORM CLEANUP-PROC ELSE PERFORM ERROR-PROC END-IF END-IF.
16
Why all these varieties? Did you hear about the Law of the Hammer If the only tool you have is a hammer you will always try pounding as the best and only solution
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.