Domanda

How in Cobol do I break a literal apart on each line to write back to the screen or a file?

Code:

   05 CONSTPARM             PIC X(78) VALUE             
   'SW89JSXX PROV RANGE 01: XXXXXXX THRU XXXXXXX   ' 
   -      'TAXONOMY: XXXXXXXXXX'.                           
È stato utile?

Soluzione

We don't have actual strings in COBOL. Fields are just as long as they are defined as.

However, if you want to "break something", we have a verb called UNSTRING:

UNSTRING CONSTPARM INTO xxxx DELIMITED BY ALL SPACE
                        yyyy DELIMITED BY ALL SPACE
                        zzzz DELIMITED BY ALL SPACE
                        lackofforethought DELIMITED BY ALL SPACE
                        etc

You have to name the fields you want to receive the data.

If using the same UNSTRING more than once, before doing the UNSTRING set all the target fields to initial values. Otherwise can get data "left over" from the previous use of that UNSTRING.

For a full explanation, consult your manual. Enterprise COBOL Language Reference. UNSTRING is very powerful, and has lots of options.

To put a field together (or to wrap a Christmas present) use STRING.

Altri suggerimenti

Have you tried reference modification? Reference modification resembles the use of substringing from many other languages. It can be used to select segments of another data item by providing a place to start from and the number of characters to bring back. The referenced field remains unchanged.

05 CONSTPARM             PIC X(78) VALUE             
'SW89JSXX PROV RANGE 01: XXXXXXX THRU XXXXXXX   ' 
-      'TAXONOMY: XXXXXXXXXX'.                   
05 WS-FIRST-FOUR         PIC X(5).
05 WS-RANGE              PIC X(5).

MOVE CONSTPARM(1:4)  TO WS-FIRST-FOUR.    
MOVE CONSTPARM(15:5) TO WS-RANGE.

DISPLAY 'WS-FIRST-FOUR = ' WS-FIRST-FOUR.    
DISPLAY 'WS-RANGE = ' WS-RANGE.

Your value in WS-FIRST-FOUR would be 'SW89' and your value in WS-RANGE would be 'RANGE'.

For another example and more details, you can visit this helpful guide: http://www.fluffycat.com/COBOL/Reference-Modification/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top