UNSTRING into unknown number of tokens.



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

UNSTRING into unknown number of tokens.

Postby vinodj » Tue Jan 24, 2012 3:28 pm

Hello,

I did UNSTRING of a source dataset like this : UNSTRING source_dsn delimited by "." INTO Q1, Q2, Q3

But now I want to UNSTRING it into unknown number of qualifiers. For that I declared an array (occurs 15 times) and did UNSTRING like this :

perform varying i from 1 by 1 until i<=15
UNSTRING source_dsn delimited by "." INTO Q(i)

But this will always give me the first qualifier, could somebody suggest me an approach as to how it could it be done?

Regards,
Vinod
vinodj
 
Posts: 29
Joined: Wed Nov 23, 2011 6:16 pm
Has thanked: 0 time
Been thanked: 0 time

Re: UNSTRING into unknown number of tokens.

Postby BillyBoyo » Tue Jan 24, 2012 3:38 pm

I assume that you mean the problem is that each UNSTRING in the loop is picking up the same piece of information, the first one.

Look up UNSTRING in the manuals, and consider especially POINTER. This should get you what you want, for the loop,

I'm not convinced there is a benefit to doing it that way over coding out UNSTRING with 15 values. One UNSTRING against an "average" of seven-and-a-half UNSTRINGs. TALLYING will give you number of fields populated.

Remember to initialise all receiving fields for the UNSTRING, else you'll get data left over from the previous UNSTRING (in your loop, you want the data left over for the POINTER in each iteration, but you must initialise to zero before entering the loop).
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post