View previous topic :: View next topic
|
Author |
Message |
gragha
New User
Joined: 25 Jul 2006 Posts: 23
|
|
|
|
Can we unstring an input record into a group variable.
Say I want to unstring "HDR~1234567~00001~20061228~104555
this into
05 HEADER-REC.
10 RECORD-TYPE PIC X(03).
10 IDENTIFIER PIC X(07)
JUSTIFIED RIGHT.
10 FILE-SEQ-NO PIC 9(05).
10 DATE PIC X(08).
10 TIME PIC X(08).
Instead of unstringing them into indvidual variables , Can I unstring into the group variable HEADER-REC.
I tried doing this and it correctly moves it into only RECORD-TYPE whereas the rest of the variables do not have any value at all.
Am I missing something. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Please post your UNSTRING code. |
|
Back to top |
|
|
gragha
New User
Joined: 25 Jul 2006 Posts: 23
|
|
|
|
Hi,
Please find it below. It doesnot work when I give it like this.
Code: |
UNSTRING INPUT-FILE-REC
DELIMITED BY '~'
INTO HEADER-REC
END-UNSTRING |
It works when I give it like this.
Code: |
UNSTRING INPUT-FILE-REC
DELIMITED BY '~'
INTO RECORD-TYPE
IDENTIFIER
FILE-SEQ-NO
DATE
TIME
END-UNSTRING. |
|
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Shouldn't you be STRINGing instead? |
|
Back to top |
|
|
gragha
New User
Joined: 25 Jul 2006 Posts: 23
|
|
|
|
Why should I be stringing ?
I want the fields from the Input file be separated and moved into the corresponding individual variables. I am sure that unstringing should be used. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
you are right, I need a new pair of glasses...
When the unstring hits the first delimiter, it stops, thinking it is done....
You could code a repeating unstring keeping track of the position but that is a lot more work than the multi-element unstring you posted.... |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Something like this should work
Code: |
move 1 to ptr.
move space to overf-flag.
perform until overf-flag = 'O'
unstring input-file-rec
delimited by '~'
into header-rec
with pointer ptr
on overflow
move 'O' to overf-flag
end-unstring
end-perform |
but if anything changes, it will skew everything following.... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
The reason this did not do what you want is that the UNSTRING doesn't care whether the 'into' field is group or elementary.
What the original code told the UNSTRING was to copy data from the input to HEADER-REC and quit when the first delimiter was reached.
In your second UNSTRING, you could change RECORD-TYPE to HEADER-REC and the code would still work.
I'd recommend using your second format where all of the fields are named at the elementary level. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hi Bill,
In your example, what will prevent the recursive UNSTRINGs from starting at the beginning of HEADER-REC?
I'm fightin' dain brammage today. . . . |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Hi Dick,
When pointer is specified (it must be initialized prior), (IIRC) it starts at the sum of the into (sorta) plus the pointer....after the first pass, pointer contains the count of the characters it unstrung and literally points to the next starting place...maybe init to zero, I'm fightin' dain brammage today too..... Dang, I'm going to have to look it up.....
Never-the-less, in the past I have used string and unstring with pointers and counts from several areas to several areas at the same time, kind of like an air traffic controller's nightmare - but beautiful when it works right....
Bill |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hi Bill,
Not sure if i remember this correctly, but i thought POINTER in an UNSTRING statement refered to the sending field and POINTER in a STRING statement referred to the receiving field.
I too will have to check.
d |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Yes, correct, but that is the point, the repeated unstring starts off where it left off.... continuing along the string to be unstrunged.. ....
That's all he needed, was to continue where he left off, but I do agree with your earlier observation, and I quote,"I'd recommend using your second format where all of the fields are named at the elementary level".
Bill |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hmmm. . . .
My dain brammage is worsening
I believe it WILL continue where it left off in the input string, but what will maintain the position in the output field? Will it not start over at the beginning of the output during each iteration? We've declared an input pointer, but i'm missing the output placeholder.
d |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Are you baiting me.... ..Well (I think you win)..
Code: |
move 0/1? to tly.
move 0/1? to ptr.
move space to overf-flag.
perform until overf-flag = 'O'
unstring input-file-rec
delimited by '~'
into header-rec (tly:length of header-rec) - tly(?)
with pointer ptr
tallying in tly
on overflow
move 'O' to overf-flag
end-unstring
end-perform |
Dang you are a cruel taskmaster...
Like I said earlier,
Quote: |
kind of like an air traffic controller's nightmare - but beautiful when it works right.... |
Bill |
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
Hi Gragha...
One novice advice in the ballcourt of MF Giants... You can also use Reference Modification, IF you have char length fixed coming in fields among delimiter "~"...
Leave air a little clear for nature |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Actually, Gragha posted what is a very good solution. It is readable and maintainable!
The rest was just havin' fun. |
|
Back to top |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
Hi gragha !
As yourself found out, it only works by specifying the receivings fileds and not using a group variable. This a simple rule & a fact !!!
A string or unstring is nothing more than a set of move commands.
For the other String/Unstring experts above a little enhancement:
You can also transfer the delimiter into a special field and do a count on them. Then the whole command becomes a very highly qualified look.
Anyway if it's useful or not.
unstring send-field delimited by "/" or "$"
into
field-01 delimiter in del-01 count in cnt-01
field-02 delimiter in del-02 count in cnt-02
end-unstring
Regards, UmeySan |
|
Back to top |
|
|
|