Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Unstringing into a group variable COBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Unstringing into a group variable COBOL
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

Site Director


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

PostPosted: Thu Jan 04, 2007 11:11 pm    Post subject:
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    Post subject: Re: Unstringing into a group variable COBOL
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: 3158
Location: Tucson AZ

PostPosted: Thu Jan 04, 2007 11:21 pm    Post subject:
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    Post subject: Re: Unstringing into a group variable COBOL
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: 3158
Location: Tucson AZ

PostPosted: Thu Jan 04, 2007 11:36 pm    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Thu Jan 04, 2007 11:46 pm    Post subject:
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

Site Director


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

PostPosted: Fri Jan 05, 2007 12:07 am    Post subject:
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

Site Director


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

PostPosted: Fri Jan 05, 2007 12:15 am    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Fri Jan 05, 2007 3:13 am    Post subject:
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

Site Director


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

PostPosted: Fri Jan 05, 2007 4:02 am    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Fri Jan 05, 2007 4:29 am    Post subject:
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

Site Director


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

PostPosted: Fri Jan 05, 2007 4:44 am    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Fri Jan 05, 2007 5:11 am    Post subject:
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: 1452
Location: Chicago, IL

PostPosted: Fri Jan 05, 2007 6:22 am    Post subject: Re: Unstringing into a group variable COBOL
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

Site Director


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

PostPosted: Fri Jan 05, 2007 6:34 am    Post subject:
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: 755
Location: Germany

PostPosted: Fri Jan 05, 2007 4:27 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts find RACF group for access to spooled... jzhardy JCL & VSAM 1 Mon May 08, 2017 11:46 am
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us