Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 101 String Processing Operations on numeric edited fields i.e., view the PIC as a string of characters –Reference modification read/write substrings.

Similar presentations


Presentation on theme: "Lecture 101 String Processing Operations on numeric edited fields i.e., view the PIC as a string of characters –Reference modification read/write substrings."— Presentation transcript:

1 lecture 101 String Processing Operations on numeric edited fields i.e., view the PIC as a string of characters –Reference modification read/write substrings –INSPECT replacing, converting, and counting substrings –STRING join substrings –UNSTRING split substrings

2 lecture 102 Reference Modification (1) Access substrings within a field Format –identifier (offset from left : length) MOVE “*” TO WORK-FIELD (20:1). MOVE SSN (4:2) TO USER-PASSWD (3:2). Omit length to default to the string end MOVE ZIP-CODE TO ADDRESS (15:). Table subscript comes before reference modification TABLE-ITEM (20) (5:1)

3 lecture 103 Reference Modification (2) 05 TELEPHONE-NUMPIC X(10) VALUE ‘6145551212’ 01 EDITED-PHONE-NUM. 05 FILLERPIC X VALUE ‘(‘. 05 AREA-CODEPIC X(3). 05 FILLERPIC X VALUE ‘)’. 05 FILLERPIC X VALUE ‘ ‘. 05 EXCHANGEPIC X(3). 05 FILLERPIC X VALUE ‘-’. 05 DIGITSPIC X(4). … MOVE TELEPHONE-NUM (1:3) TO AREA-CODE. MOVE TELEPHONE-NUM (4:3) TO EXCHANGE. MOVE TELEPHONE-NUM (7:4) TO DIGITS.  EDITED-PHONE-NUM = “(614) 555-1212”

4 lecture 104 Utility String Operations Invoke with the statement FUNCTION –NUMVAL – string (‘+’, ‘-’) to number –NUMVAL-C – string (‘$’, ‘,’) to number –LOWER-CASE –UPPER-CASE –LENGTH –REVERSE

5 lecture 105 INSPECT Operation (1) REPLACING clause INSPECT ident-1 REPLACING {ALL/LEADING/FIRST ident-2/lit-1 BY ident-3/lit-2 {BEFORE/AFTER ident-4/lit-3}} –ALL - replace all occurrences –LEADING – replace occurrences from start –FIRST – replace just first occurrence

6 lecture 106 INSPECT Operation (2) 01 SSNUMPIC X(9) 01 SSN-OUTPIC XXXBXXBXXXX … MOVE SSNUM TO SSN-OUT. INSPECT SSN-OUT REPLACING ALL ‘ ‘ BY ‘-’. ------------------------------------------------------------------------------------------ INSPECT WORK-FIELD REPLACING ALL “A” BY “a” BEFORE “.” FIRST “B” BY “b” ALL “C” BY “c” AFTER “.”. WORK-FIELD : “BACK.BACK”  “baCK.BAcK”

7 lecture 107 INSPECT Operation (3) CONVERTING clause INSPECT ident-1 CONVERTING ident-2/lit-1 TO ident-3/lit-2 {BEFORE/AFTER ident-4/lit-3} INSPECT WORK-FIELD CONVERTING “*” TO “0” WORK-FIELD : “**123.56*”  “00123.560” TALLYING clause INSPECT ident-1 TALLYING ident-2 FOR { CHARACTERS/ALL/LEADING ident-3/lit-1 {BEFORE/AFTER ident-4/lit-2}} INSPECT WORK-FIELD TALLYING COUNT-1 FOR ALL “*” BEFORE “.” COUNT-2 FOR CHARACTERS AFTER “.”. WORK-FIELD : “***12.**”  COUNT-1 = 3, COUNT-2 = 2

8 lecture 108 STRING Concatenate substrings into a string STRING {ident-1/lit-1 DELIMITED BY ident-2/lit-2/SIZE} INTO ident-3 WITH POINTER ident-4.

9 lecture 109 05 NAME-IN-PIECES. 10 LAST-NAMEPIC X(16). 10 FIRST-NAMEPIC X(10). 10 MIDDLE-INITIALPIC X. 05 ENTIRE-NAMEPIC X(29). SMITH LAST-NAME H MIDDLE-INITIAL JOHN FIRST-NAME ENTIRE-NAME Before Execution

10 lecture 1010 JOHN (1) ENTIRE-NAME JOHN (b) (2) ENTIRE-NAME Execution Steps JOHN (b) H (3) ENTIRE-NAME JOHN (b) H (4) ENTIRE-NAME JOHN (b) H SMITH (5) ENTIRE-NAME MOVE SPACES TO ENTIRE-NAME. STRING FIRST-NAME DELIMITED BY SPACE ‘ ‘ DELIMITED BY SIZE MIDDLE-INITIAL DELIMITED BY SPACE ‘ ‘ DELIMITED BY SIZE LAST-NAME DELIMITED BY SPACE INTO ENTIRE-NAME

11 lecture 1011 UNSTRING Split a string into substrings UNSTRING ident-1 { DELIMITED BY {ALL} ident-2/lit-1} INTO ident-list WITH POINTER ident-3

12 lecture 1012 05 NAME-IN-PIECES. 10 LAST-NAMEPIC X(16). 10 FIRST-NAMEPIC X(10). 10 MIDDLE-INITIALPIC X. 05 ENTIRE-NAMEPIC X(31). LAST-NAME MIDDLE-INITIAL FIRST-NAME Before Execution JOHN (b) H SMITH ENTIRE-NAME MOVE SPACES TO NAME-IN-PIECES. UNSTRING ENTIRE-NAME DELIMITED BY ‘ ‘ INTO FIRST-NAME MIDDLE-INITIAL LAST-NAME.

13 lecture 1013 JOHN (b) H SMITH (1) ENTIRE-NAME JOHN (b) H SMITH (1) ENTIRE-NAME JOHN H SMITH FIRST-NAMELAST-NAMEMIDDLE-INITIAL

14 lecture 1014 Subprograms What is a subprogram? –cobol code in different file(s) –pre-compiled –call from within your program Why? –fast linking with your program –shared by many applications –basis for libraries of useful code

15 lecture 1015 Subprogram Format A subprogram is the same as a program except : –extra program division called LINKAGE SECTION. –PROCEDURE DIVISION has a USING clause –EXIT PROGRAM instead of STOP RUN. … LINKAGE SECTION. … Data definitions for fields coming from the calling program … … PROCEDURE DIVISON USING ident-1 … … EXIT PROGRAM.

16 lecture 1016 Calling the Subprogram CALL “subprogram-name” USING ident-1 … In the subprogram, the fields in the LINKAGE SECTION must match the list in the USING clause of the PROCEDURE DIVISION The lists in both USING clauses of CALL and the PROCEDURE DIVISON must match See the book for an example


Download ppt "Lecture 101 String Processing Operations on numeric edited fields i.e., view the PIC as a string of characters –Reference modification read/write substrings."

Similar presentations


Ads by Google