RAMESH KRISHNA REDDY mainframe discussion forum - cobol, db2,cics,jcl,file-aid,changeman,interview questions
Online Tutorials   | PREV  | TOP  | NEXT



Author : Kishore B.



STRING The STRING verb concatenates the partial or complete contents of two or more strings or literals into one single data item. Below example illustrates how the string is used. String Example: 01 WS-DATA-ITEM1 PIC X(10) “THIS IS ”. 01 WS-DATA-ITEM2 PIC X(20) “STRING FIRST”. STRING WS-DATA-ITEM1 DELIMITED BY SIZE. WS-DATA-ITEM2 DELIMITED BY SPACES ‘ EXAMPLE. ‘ DELIMITED BY SIZE INTO WS-DESTINATION This example will concatenate the strings WS-DATA-ITEM1 and WS-DATA-ITEM2 into WS-DESTINATION. In above example WS-DATA-ITEM1 is delimited by size,so complete string content will be moved to destination string(WS-DESTINATION). WS-DATA-ITEM2 is delimited by SPACES, partial content (characters up to first space) will be moved. And complete literal (i.e. ‘ EXAMPLE. ‘) will be moved. Now WS-DESTINATION will contain “THIS IS STRING EXAMPLE”. cobol string delimited by size space syntax WITH POINTER is optional, value associated with it (Pointer-integer) determines the starting character position for insertion into the destination string, and pointer-integer must be an integer item. ON OVERFLOW is optional, this clause specifies what needs to be done when overflow condition occurred. Overflow condition occurs in following conditions. The pointer- integer is not pointing to a character position within the destination string when the STRING executes. i.e.less than 1 or exceeding the length of destination string. If all source strings together are not accommodated in destination string then overflow occurs. DELIMITED BY phrase specifies the content of source string to be transferred. DELIMITED BY [SPACES, Data item or literal] -> Transfers the data till sepcificed delimeter found DELIMITED BY SIZE, Transfers complete string. Data movement from a particular source string ends when either; 1. The end of the source string is reached 2. The end of the destination string is reached 3. The delimiter is detected. The STRING statement ends when either; 1. All the source strings have been processed. 2. The destination string is full. 3. The pointer points outside the string. STRING Example: 01 WS-DATA-ITEM1 PIC X(20) VALUE “THIS STATEMENT”. 01 WS-DATA-ITEM2 PIC X(20) VALUE “IS EXAMPLE #2 AND”. 01 WS-DATA-ITEM3 PIC X(25) VALUE “FOR STRING CONCATENATION”. 01 WS-POINTER PIC 9(02) VALUE 3. 01 WS-DESTINATION PIC X(35). STRING WS-DATA-ITEM 1 DELIMITED BY SPACES SPACE DELIMITED BY SIZE WS-DATA-ITEM 2 DELIMITED BY ‘#’ SPACE DELIMITED BY SIZE WS-DATA-ITEM 3 DELIMITED BY SIZE INTO WS-DESTINATION WITH POINTER WS-POINTER ON OVERFLOW DISPLAY “Overflow condition occurred” END-STRING In Above example result will be transfered into destination string from 3rd character position (WITH POINTER option). WS-DATA-ITEM1 is delimited by spaces, so characters up to first space (i.e. “THIS”) will be inserted into WS-DESTINATION, starting from 3 character position (WS-POINTER value is 3). After all data transfer, WS-POINTER will be 7 (next insertion position). WS-DATA-ITEM2 is delimited by delimiter ‘#’, so characters will be moved to destination string till it encounters delimiter ‘#’ (i.e. ‘IS EXAMPLE ’). WS-POINTER will be 18. WS-DATA-ITEM3 is delimited by SIZE, so all characters will be moved to desti- nation string. WS-POINTER will be 36. WS-POINTER is exceeding length of destination string (35), overflow condition is satisfied, so DISPLAY statement will be executed Difference between DELIMITED BY SIZE and DELIMITED BY SPACE DELIMITED BY SIZE will add whole of the source string to destination string. DELIMITED BY SPACE will add part of source string until first space encountered. For example Input string contains value - “This is Example string” If you want full string in the output field, use BY SIZE option as shown below. DELIMITED BY SIZE -> “This is Example String” If you want only first word from the sentence, use BY SPACE option as shown below. DELIMITED BY SPACE -> “This”



Previous chapter in COBOL tutorial Starting of COBOL tutorial Next chapter in COBOL tutorial

Visit COBOL books section in this site for good books

Home | Donations | Online Tutorials | Books | Entertainment | Contactme | privacy |  sql tutorial | jcl interview questions | JCL Tutorial | JCL Tutorial - chapter1 | JCL Tutorial - chapter2 | JCL Tutorial - chapter3 | JCL Tutorial - chapter4 | JCL Tutorial - chapter5 | JCL Tutorial - chapter6 | JCL Tutorial - chapter7 | JCL Tutorial - chapter8 | JCL Tutorial - chapter9 | JCL Tutorial - chapter10 | JCL Tutorial - chapter11