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



DRONA SERIES
COBOL STUDY MATERIAL


UNSTRING

Author : Kishore B.



   
 

UNSTRING 




UNSTRING The UNSTRING verb is used to divide a string into sub-strings The UNSTRING copies characters from the source string, to the destination strings, until a delimiter encountered that terminates data transfer. When data transfer ends for a particular destination string, the next destination string will become the receiving area. The following example shows how UNSTRING is used. Example: UNSTRING ‘userid@company.com’ DELIMITED BY ‘@’ OR ‘.’ INTO WS-USER-ID WS-COMPANY WS-DOMAIN END-NSTRING In this example unstrings the literal ‘userid@company.com’ into different strings WS-USER-ID, WS-COMPANY and WS-DOMAIN based on delimiters (i.e. ‘@’ and ‘.’). Characters from source string (i.e. ‘userid@company.com’) until delimiter ‘@’ will be moved to WS-USER-ID, after that characters until delimiter ‘.’ will be moved to WS-COMPANY, remaining characters in source string will be moved to WS-DOMAIN. cobol unstring delimited by tallying Delimiter - Character or set of characters in the source string that terminates data transfer to a particular string. We can specify one or more delimiters if anyone delimiter encountered in source string, the data will be transferred to next destination string. Hold-delimiter – Holds the delimiter that caused the termination of data transfer to associated destination string. Char-counter – Holds the no of characters transferred into associated destination string. Pointer-integer – Points to the position in the source string from which the next character will be taken. Destination-counter – Holds the count of no of destination strings affected by UNSTRING verb. - If the DELIMITED BY phrase is not used, then DELIMITER IN and COUNT IN phrases must not be specified. - When the ALL phrase is used, contiguous delimiters are treated as one delimiter. If the ALL is not used, contiguous delimiters will act as separate delimiters and result in spaces being sent to some of the destination strings. Example -1: UNSTRING source-string DELIMITED BY ‘/’ INTO destination-string1 Destination-string2 Destination-string3 END-UNSTRING Input: Source-string = “19/11/2010” Output: Destination-string1 –> “19” Destination-string2 -> “11” Destination-String3 -> “2010” Above UNSTRING example moves source data into destination delimited by / accordingly. Example -2 : UNSTRING source-string DELIMITED BY ‘/’ OR ‘#’ OR ALL SPACES INTO destination-string1 DELIMITER IN hold-delimiter1 COUNT IN char-counter1 destination-string2 DELIMITER IN hold-delimiter2 COUNT IN char-counter2 destination-string3 DELIMITER IN hold-delimiter3 COUNT IN char-counter3 destination-string4 DELIMITER IN hold-delimiter4 COUNT IN char-counter4 WITH POINTER pointer-integer TALLYING IN destination-count ON OVERFLOW DISPLAY “Overflow occurred” NOT ON OVERFLOW DISPLAY “No overflow” END-UNSTRING Input: Source-string = “+TODAYSDATEIS 19//11-2010” Pointer-integer = 02 Output: Once the above statement executed destination variables hold these values. Destination-string1 -> “TODAYSDATEIS” Destination-string2 -> "19” Destination-string3 -> (Spaces) Destination-string4 -> "11-2010” Unstring will start from position 2 in source-string because of value in WITH POINTER option.
    

NEXT CHAPTER TOPIC : COBOL


                                   



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