Sunday, November 20, 2011

UNSTRING


UNSTRING command is used to split one string to many strings.
Syntax:
         UNSTRING  identifier-1
         [DELIMITED BY (ALL/) identifier2/literal1 [,OR (ALL/) (identifier-3/literal-2),..]]
         INTO identifier-4 [,DELIMITER IN identifier-5, COUNT IN identifier-6]
          [,identifier-7 [,DELIMITER IN identifier-8, COUNT IN identifier-9]

01 WS-DATA PIC X(12) VALUE ‘10/200/300/1’.
UNSTRING WS-DATA DELIMITED BY ‘/’
         INTO WS-FLD1 DELIMITER IN WS-D1 COUNT IN WS-C1      
                 WS-FLD2 DELIMITER IN WS-D2 COUNT IN WS-C2      
                 WS-FLD3 DELIMITER IN WS-D3 COUNT IN WS-C3
END-UNSTRING.
Result:
WS-FLD1 = 10 WS-FLD2 =200 WS-FLD3=300
WS-C1 = 2 WS-C2=3 WS-C3=3 WS-D1 = ‘/’ WS-D2=’/’ WS-D3 ‘/’
ON OVERFLOW can be coded with STRING and UNSTRING. If there is STRING truncation then the imperative statements followed ON OVERFLOW will be executed.

No comments:

Post a Comment