Presentation is loading. Please wait.

Presentation is loading. Please wait.

Agenda Collating sequence / Sorting data

Similar presentations


Presentation on theme: "Agenda Collating sequence / Sorting data"— Presentation transcript:

1 Agenda Collating sequence / Sorting data
Selection (Logic) Infinite Loops n!!Not me! Case statements Iteration Manipulating / selecting data in variables STRISDB also see handout

2 Sorting on the AS/400 EBCDIC Sort
(Collating sequence) 1. Blanks 2. Special Characters 3. Lower Case Letters 4. Upper Case Letters 5. Numbers

3 Selection

4 Selection Condition? Statement2 Statement1

5 Relational Operators

6 Selection IF Condition THEN Statement(s) ELSE END-IF

7 If-Then-Else A = 10 B = 20 If A > B THEN MOVE B TO A ELSE
MOVE A TO B.

8 If-Then-Else A = 10 B = 20 If (A > B) THEN MOVE B TO A.

9 If-Then-Else NESTED A = 10 B = 20 C = 30 D = 40 If A < B THEN
IF A > C THEN MOVE A TO C ELSE MOVE C TO A ENDIF MOVE A TO B END-IF.

10 IF-THEN-ELSE Statements
IF MARKS >= 80 THEN MOVE ‘A’ TO GRADE ELSE IF MARKS >= 70 THEN MOVE ‘B’ TO GRADE IF MARKS >= 60 THEN MOVE ‘C’ TO GRADE IF MARKS >= 55 THEN MOVE ‘D’ TO GRADE MOVE ‘F’ TO GRADE END-IF ENDIF.

11 Condition Names - 88’s Used with Code Fields
Eg. ARE-THERE-MORE-RECORDS Eg. FINAL-GRADE Eg. Indicators

12 Condition Names 01 ARE-THERE-MORE-RECORDS PIC X(3) VALUE ‘YES’.
88 THERE-ARE-MORE-RECORDS VALUE ‘YES’. 88 END-OF-FILE VALUE ‘NO’. IF THERE-ARE-MORE-RECORDS READ EMPLOYEE-FILE. IF END-OF-FILE PERFORM TERMINATION-RTN.

13 Set Verb Used to initialize fields to a Condition-Name.
01 ARE-THERE-MORE-RECORDS PIC X(3). 88 THERE-ARE-MORE-RECORDS VALUE ‘YES’. 88 END-OF-FILE VALUE ‘NO’. SET END-OF-FILE TO TRUE.

14 Conditions Cont’d 01 WORK-DAYS PIC X(3). 88 MONDAY VALUE ‘MON’.
88 TUESDAY VALUE ‘TUE’. 88 WEDNESDAY VALUE ‘WED’. 88 THURSDAY VALUE ‘THU’ 88 FRIDAY VALUE ‘FRI’. SET MONDAY TO TRUE. IF FRIDAY DISPLAY ‘GO HOME EARLY’.

15 Conditions Cont’d 01 FALL-MONTHS PIC X(3). 88 SEPTEMBER VALUE ‘SEP’.
88 OCTOBER VALUE ‘OCT’. 88 NOVEMBER VALUE ‘NOV’. 88 DECEMBER VALUE ‘DEC’. IF OCTOBER DISPLAY ‘HAPPY HALLOWEEN!!’ SET DECEMBER TO TRUE.

16 Option Indicators and Conditions
01 WS-indicators. 05 IN90 INDICATOR 90 PIC 1. 88 display-message value B’1’. 88 dont-display-message value B’0’. Set display-message to true. Set dont-display-message to true. If display-message If don’t-display-message If not display-message

17 Response Indicators and Conditions
01 WS-Control. 05 ws-function-key pic x(2). 88 F3 value ’03’ 88 F12 value ’12’. 88 Enter value ’00’ 05 ws-device-name pic x(10). 05 ws-record-format pic x(10). If F3 If not F3

18 Selection Statements

19 Sign Test A = 10 B = -10 If A IS NEGATIVE IF A IS POSITIVE
MOVE B TO A MOVE B TO A ELSE ELSE MOVE A TO B MOVE A TO B.

20 Sign Test A = 10 B = -10 If A IS NEGATIVE IF A IS POSITIVE
MOVE B TO A MOVE B TO A ELSE ELSE MOVE A TO B MOVE A TO B.

21 Numeric Test A = 10 B = -10 If A IS NUMERIC ADD A TO B.

22 Alphabetic Test C = ‘CJ’ D = ‘Christy’ If C is ALPHABETIC THEN
MOVE C TO OLDER-SISTER ELSE MOVE D TO OLDER-SISTER END-IF

23 Alphabetic-Upper Test
C = ‘CJ’ D = ‘Christy’ If C is ALPHABETIC-UPPER THEN MOVE C TO OLDER-SISTER ELSE MOVE D TO OLDER-SISTER END-IF

24 Alphabetic-Lower Test
C = ‘CJ’ D = ‘Christy’ If D is ALPHABETIC-LOWER THEN MOVE D TO OLDER-SISTER ELSE MOVE C TO OLDER-SISTER END-IF

25 AND

26 OR

27 AND/OR Order of Operations
Brackets First ANDs (From Left to Right) ORs (From Left to Right)

28 ANDs/ORs A = 10 B = -10 C = 20 If (A<B) OR (B<C) AND (A<C) THEN MOVE A TO C ELSE MOVE A TO B END-IF

29 Replacing nested IF’s with
Case Statements Replacing nested IF’s with “CASE” statements

30 IF-THEN-ELSE Statements
IF MARKS >= 80 THEN MOVE ‘A’ TO GRADE ELSE IF MARKS >= 70 THEN MOVE ‘B’ TO GRADE IF MARKS >= 60 THEN MOVE ‘C’ TO GRADE IF MARKS >= 55 THEN MOVE ‘D’ TO GRADE MOVE ‘F’ TO GRADE END-IF ENDIF.

31 CASE Statements EVALUATE TRUE WHEN MARKS >= 80 MOVE ‘A’ TO GRADE
WHEN MARKS >= 70 AND MARKS < 80 MOVE ‘B’ TO GRADE WHEN MARKS >= 60 AND MARKS < MOVE ‘C’ TO GRADE WHEN MARKS >= 55 AND MARKS < MOVE ‘D’ TO GRADE WHEN OTHER MOVE ‘F’ TO GRADE END-EVALUATE.

32 CASE Statements EVALUATE GRADE WHEN ‘A’ DISPLAY ‘WONDERFUL!!!!’
WHEN ‘B’ DISPLAY ‘GREAT!!!’ WHEN ‘C’ DISPLAY ‘NEED ANY HELP?’ WHEN ‘D’ DISPLAY ‘COME AND SEE ME!’ WHEN ‘F’ DISPLAY ‘SEE YOU NEXT SEMESTER’ [WHEN OTHER DISPLAY ‘WE HAVE A PROBLEM!’] END-EVALUATE.

33 Problem FILENAME is a 10 character field in the file, FILELIST.
FILELIST is a Physical file that contains a record for each of the physical files in QGPL. You are required to write a COBOL program that prints all of the files listed in FILELIST. What COBOL statement would list all of the Files in QGPL that start with ‘CHAP’?

34 Iteration Looping / repetition

35 Perform Statement COBOL’s version of the execute sub-routine command.
Works as follows: Goto the start of a paragraph. Repeat in sequence, all of the statements in the paragraph as many times as required. UNTIL Clause Return to the calling statement.

36 PERFORM STATEMENT Basic Format: PERFORM paragraph-name. ====
Perform executes a group of statements within the paragraph ‘paragraph-name’ Then, control comes back to the next statement following the perform

37 Basic PERFORM READ Emp-File PERFORM DSP-Rtn STOP RUN DSP-RTN
move emp-in to emp-out. write dsp-record format is ‘SCREEN’. read dsp-file record.

38 PERFORM STATEMENT PERFORM HEADER-LINE =======================
PROCEDURE DIVISION. 00-MAIN. OPEN INPUT PAYROLL-FILE OUTPUT PRINT-FILE. READ PAYROLL-FILE AT END MOVE 'N' TO EOF-FLAG END-READ. PERFORM HEADER-LINE PERFORM PROCESS-RECORDS UNTIL EOF-FLAG = 'N'. ======================= HEADER-LINE. MOVE HEADING-LINE TO PRINT-LINE. WRITE PRINT-LINE.

39 Iteration Statement to Use?
Perform Until Tests for the condition first Statements are executed only if the condition is true Perform With Test After tests for the condition last Statements are always executed at least once

40 PERFORM Until PERFORM paragraph-name UNTIL Condition

41 PERFORM Until Condition Met? YES NO Execute Program Statements

42 PERFORM….UNTIL STATEMENT
PROCEDURE DIVISION. 00-MAIN. : PERFORM PROCESS-RECORDS UNTIL EOF-FLAG = 'N'. ======================= PROCESS-RECORDS. MOVE EMP-NAME TO DET-NAME MOVE EMP-HOURS TO DET-HOURS COMPUTE DET-PAY = EMP-HOURS * EMP-RATE MOVE DETAIL-LINE TO PRINT-LINE WRITE PRINT-LINE READ PAYROLL-FILE AT END MOVE 'N' TO EOF-FLAG END-READ.

43 PERFORM Until READ Emp-File AT END Move ‘YES’ TO EOF.
PERFORM Dsp-Rtn UNTIL EOF = ‘Y’ STOP RUN DSP-RTN move emp-in to emp-out. write dsp-record format is ‘SCREEN’. read dsp-file RECORD. read emp-file at end move ‘YES’ to EOF.

44 Iteration Statement to Use?
Perform X Times Use this when you know the number of times the paragraph(s) are to be executed.

45 PERFORM X Times PERFORM (paragraph-name) THROUGH/THRU (paragraph-name)
(integer/variable) TIMES

46 PERFORM X Times Number of Times Met? YES NO Execute Program Statements

47 PERFORM X Times READ Emp-File AT END Move ‘YES’ TO EOF.
PERFORM Dsp-Rtn 5 TIMES STOP RUN DSP-RTN move emp-in to emp-out. write dsp-record format is ‘SCREEN’. read dsp-file record.

48 PERFORM With Test After
PERFORM (paragraph-name) THROUGH/THRU (paragraph-name) WITH TEST AFTER UNTIL Condition

49 PERFORM With Test After
Execute Program Statements Condition Met? YES NO

50 PERFORM With Test After
READ Emp-File AT END Move ‘YES’ TO EOF. PERFORM Dsp-Rtn WITH TEST AFTER UNTIL EOF = ‘Y’ STOP RUN DSP-RTN move emp-in to emp-out. write dsp-record format is ‘SCREEN’. read dsp-file record. read emp-file AT END MOVE ‘YES’ TO EOF.

51 PERFORMs within PERFORMs
READ Emp-File AT END Move ‘YES’ TO EOF. PERFORM DSP-Rtn UNTIL 5 TIMES STOP RUN DSP-RTN MOVE EMP-IN TO EMP-OUT. PERFORM Write-Rtn

52 Moving Data & Text Manipulation
Chapter 6 Moving Data & Text Manipulation

53 Fun with Functions ILEFUNCT

54 System Date Function current-date Function convert-date-time

55 Display file ‘Both’ Fields
Input and Output buffers REDEFINES clause Different data specifications for same memory location Screens with both fields need an input and an output buffer.

56 Used to Concatenate character strings together.
STRING Statement Used to Concatenate character strings together.

57 STRING Statement STRING
Variable/Constant DELIMITED BY {Variable/Constant/SIZE) INTO variable END-STRING

58 STRING Statement Rules
DELIMITED BY required Receiving field must be an elementary data (not a group item) element with no editing symbols All literals must be alphanumeric String moves data from left-right but does not pad with blanks

59 STRING Statement STRING first-name DELIMITED BY ‘ ‘
last-name DELIMITED BY ‘ ‘ INTO full-name END-STRING first-name last-name full-name ‘Cindy‘ ‘Laurin-Moogk’

60 STRING Statement ‘Cindy ‘ ‘Laurin-Moogk ‘
STRING first-name DELIMITED BY ‘ ‘ ‘ ‘ DELIMITED BY SIZE last-name DELIMITED BY ‘ ‘ INTO full-name END-STRING first-name last-name full-name ‘Cindy ‘ ‘Laurin-Moogk ‘

61 STRING Statement MOVE ‘XXXXXXXXXXXXXXXXXXXXXXXX’ TO full-name.
STRING first-name DELIMITED BY ‘ ‘ ‘ ‘ DELIMITED BY SIZE last-name DELIMITED BY ‘ ‘ INTO full-name END-STRING first-name last-name full-name ‘Cindy ‘ ‘Laurin-Moogk ‘ ‘Cindy Laurin-MoogkXXXXX’

62 We can concatenate strings together using the String Verb.
Wouldn’t it be nice if we could parse a string into other strings?

63 UNSTRING Verb!! UNSTRING Variable DELIMITED BY Variable/Constant/SIZE
INTO variable1 variable2 variable3 END-UNSTRING

64 UNSTRING 01 Name-In-Pieces. 05 Last-Name PIC X(16).
05 First-Name PIC X(10). 05 Middle-Initial PIC X. 01 Entire-Name PIC X(31) VALUE ‘Cindy M Laurin-Moogk’. UNSTRING Entire-Name DELIMITED BY ‘ ‘ INTO First-Name Middle-Initial Last-Name.

65 UNSTRING 01 Name-In-Pieces. 05 Last-Name PIC X(16).
05 First-Name PIC X(10). 05 Middle-Initial PIC X. 01 Entire-Name PIC X(31) VALUE ‘Eddie Laurin’. UNSTRING Entire-Name DELIMITED BY ‘ ‘ INTO First-Name Middle-Initial Last-Name.

66 UNSTRING 01 Name-In-Pieces. 05 Last-Name PIC X(16).
05 First-Name PIC X(10). 05 Middle-Initial PIC X. 01 Entire-Name PIC X(31) VALUE ‘Cindy M Laurin Moogk’ UNSTRING Entire-Name DELIMITED BY ‘ ‘ INTO First-Name Middle-Initial Last-Name.

67 Next Class Work on Assignment 1 Do your readings per the text book.
Due end of this week!!!!!! Do your readings per the text book.


Download ppt "Agenda Collating sequence / Sorting data"

Similar presentations


Ads by Google