IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Unstringing into a group variable COBOL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
gragha

New User


Joined: 25 Jul 2006
Posts: 23

PostPosted: Thu Jan 04, 2007 10:44 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Jan 04, 2007 11:11 pm
Reply with quote

Hello,

Please post your UNSTRING code.
Back to top
View user's profile Send private message
gragha

New User


Joined: 25 Jul 2006
Posts: 23

PostPosted: Thu Jan 04, 2007 11:15 pm
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Jan 04, 2007 11:21 pm
Reply with quote

Shouldn't you be STRINGing instead?
Back to top
View user's profile Send private message
gragha

New User


Joined: 25 Jul 2006
Posts: 23

PostPosted: Thu Jan 04, 2007 11:24 pm
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Jan 04, 2007 11:36 pm
Reply with quote

you are right, I need a new pair of glasses... icon_redface.gif
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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Jan 04, 2007 11:46 pm
Reply with quote

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.... icon_eek.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jan 05, 2007 12:07 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jan 05, 2007 12:15 am
Reply with quote

Hi Bill,

In your example, what will prevent the recursive UNSTRINGs from starting at the beginning of HEADER-REC? icon_confused.gif

I'm fightin' dain brammage today. . . .
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Jan 05, 2007 3:13 am
Reply with quote

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..... icon_question.gif Dang, I'm going to have to look it up..... icon_cry.gif

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.... icon_lol.gif

Bill
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jan 05, 2007 4:02 am
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Jan 05, 2007 4:29 am
Reply with quote

Yes, correct, but that is the point, the repeated unstring starts off where it left off.... continuing along the string to be unstrunged.. icon_lol.gif ....
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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jan 05, 2007 4:44 am
Reply with quote

Hmmm. . . .

My dain brammage is worsening icon_biggrin.gif

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. icon_confused.gif

d
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Jan 05, 2007 5:11 am
Reply with quote

Are you baiting me.... icon_eek.gif ..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
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Fri Jan 05, 2007 6:22 am
Reply with quote

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 icon_biggrin.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jan 05, 2007 6:34 am
Reply with quote

Hello,

Actually, Gragha posted what is a very good solution. It is readable and maintainable!

The rest was just havin' fun.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Fri Jan 05, 2007 4:27 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top