Posted: Mon Sep 03, 2012 3:55 am Post subject: Program using String & Unstring
I have coded a program by using string & unstring. Please see below.
01 NAME PIC X(20) VALUE 'TENDULKAR,SACHIN'.
01 FNAME PIC X(20).
01 LNAME PIC X(20).
01 EXTNAME PIC X(20).
UNSTRING NAME DELIMITED BY ',' INTO LNAME, FNAME
STRING FNAME DELIMITED BY SPACE ' ' LNAME DELIMITED
BY SIZE INTO EXTNAME
for the above program, I am getting the correct output see below
maybe change ,, to something else and use a different UNSTRING delimiter.
that's your solution.
and if you are going to say "provide me the solution"
then I am going to say, "provide me with your paycheck". _________________ Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
You haven't supplied enough information to be certain:
If the third cannot exist, then DELIMITED BY ALL "," with DELIMITER IN fieldname. fieldname would need to be the length of the maximum number of repeating commas possibile.
Sub-define fieldname such that bytes two to end have a name.
Specify three fields in your STRING by including the sub-defined name in the middle.
If the third can exist, use UNSTRING with COUNT IN, but only specifying one destination field, the first.
Then, use a second UNSTRING with WITH POINTER but specifying no delimiter to get the second field, with a potential leading/embedded character the same value as your delimiter in the first UNSTRING now being of no significance.
Don't use TALLYING to adjust the value from the COUNT IN as you always know the value to adjust it by - although think about what to do if the field is already space, which you aren't doing at the moment.
Put these values as well into your program, at the same time, after your existing test data and run your original.
This field intentionally left blank [that means just all blanks, not the text]
Here's my first suggestion. Turns out not to work. The DELIMITER IN is only to distinguish between multiple different delimiters, not to do that and show how many delimiter characters have been processed when ALL has been used. There doesn't seem a direct way to do that.
I do it a different way when the data is more complex than easily allows UNSTRING'/STRING to work with. This is just on the edge. It will work in all cases.
dbz's suggestion will work, as long as the chosen replacement for "," cannot appear naturally in the field.
INSPECT field REPLACING FIRST COMMA BY new-delimiter : UNSTRING using the new delimeter.
Usually when you are UNSTRINGing, you have text data, so no problem with finding something unused to make the delimiter. I think this is the neatest solution, as many will be unfamiliar with COUNT IN and WITH POINTER (not to be confused with the other sort of POINTERs, you see?) and don't know where/how to read the manual.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum