Quantcast
Channel: IBM Mainframe Computers Forums
Viewing all articles
Browse latest Browse all 9405

COBOL Programming :: RE: Unstring list of values into an array.

$
0
0
Author: Roshnii
Posted: Wed Jun 29, 2016 7:07 pm (GMT 5.5)

Hi All,

Thanks for the suggestions.

I used reference modification to get the values to an array as suggested by Robert as UNSTRING does not really work to get values in a loop in a array.

Following is what I used.

Code:

    05  WS-VALUE.                               
         10  WS-NAME1                  PIC  X(08).   
         10  WS-NAME2                  PIC  X(08).
         10  WS-Y-FLAG                 PIC  X(01).
         10  WS-N-FLAG                 PIC  X(20).
         10  WS-CUST-STRING            PIC  X(200).

                   
      05  WS-CUST-TBL.   
            15 WS-CUST-ARRAY OCCURS 1 TO 40 TIMES.
                     DEPENDING ON WS-LMT.
               20 WS-CUST         PIC X(08).

      UNSTRING WS-VARIABLE DELIMITED BY '#'   
          INTO WS-NAME1,
               WS-NAME2,
               WS-Y-FLAG,
               WS-N-FLAG,
               WS-CUST-STRING
      END-UNSTRING

      ADD  +1           TO SUB-X
      ADD  +1           TO SUB-Y
      ADD  +1           TO SUB-Z


      PERFORM VARYING SUB-X FROM 1 BY 1
      UNTIL WS-TRNSFR-CUST-VAR(SUB-X:1) = SPACES OR SUB-X > WS-LMT

        IF WS-CUST-STRING(SUBX:1)  = '#'
           MOVE WS-STORE-VAR TO WS-CUST(SUB-Y)       
           MOVE SPACES       TO WS-STORE-VAR
           ADD  +1           TO SUB-Y
           MOVE +1           TO SUB-Z

         ELSE
       
           MOVE WS-CUST-STRING(SUBX:1)
             TO WS-STORE-VAR(SUB-Z:1)
           ADD +1 TO WS-SUB-Z
     
         END-IF
      END-PERFORM   

_________________
Roshnii


Viewing all articles
Browse latest Browse all 9405

Trending Articles