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

Unstring variable length record


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

New User


Joined: 25 Jan 2011
Posts: 10
Location: Kolkata(India)

PostPosted: Thu Sep 15, 2011 11:41 am
Reply with quote

In my input record the fields are separated by pipe (“|”) and the record ended with NULL character.
As follows --

‘JOHN|SMITH|HR|ACTIVE|……|………………….’

My requirement is to get all fields in output variables and separated way like this
JOHN
SMITH
HR
ACTIVE

…….

……..

……..

But in my program I only get JOHN and also so many times

Thanks!
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Sep 15, 2011 11:48 am
Reply with quote

Quote:
But in my program I only get JOHN and also so many times

that' s sad ... to hear that Your program is not working
we all hope that You will be able to fix it soon so that You will get the expected results
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Sep 15, 2011 11:48 am
Reply with quote

your third instruction is the problem.

and there is no such thing as a null character.

though there exsists a null status of a db2 column.
Back to top
View user's profile Send private message
pawasthi

New User


Joined: 08 Mar 2010
Posts: 15
Location: India

PostPosted: Thu Sep 15, 2011 11:49 am
Reply with quote

Quote:
But in my program I only get JOHN and also so many times



what you have done to solve this issue please clarify this..?
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Sep 15, 2011 11:53 am
Reply with quote

icon_redface.gif I forgot to add the usual and expected comment

to make the most out of the questions You ask and to forecast the comments You might receive
it would be wise for You to read and meditate on
how to ask questions the smart way
here catb.org/~esr/faqs/smart-questions.html
or .. for a more PC language
here support.microsoft.com/kb/555375
Back to top
View user's profile Send private message
Manas Mazumder

New User


Joined: 25 Jan 2011
Posts: 10
Location: Kolkata(India)

PostPosted: Thu Sep 15, 2011 12:27 pm
Reply with quote

Thanks for quick replying,

The input record is a simple string.

the below code I've used
Code:

WORKING-STORAGE SECTION.
01 OUT-REC.
          02 VAR1 PIC X(100) OCCURS 10 TIMES.
.........
.......
PROCEDURE DIVISION
           PERFORM VARYING I FROM 1 BY 1 UNTIL I>10
           UNSTRING INPUT-RECORD
               DELIMITED BY "|"
               INTO VAR1(I)
           DISPLAY 'VAR1: ' VAR1(I).
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Sep 15, 2011 12:35 pm
Reply with quote

why not review Yourself the UNSTRING ... DELIMITED information in the manuals ?
link to the cobol manuals at the top of the page
or even google for examples ?

Quote:
But in my program I only get JOHN and also so many times

because that' s what You are telling UNSTRING to do icon_cool.gif
Back to top
View user's profile Send private message
Manas Mazumder

New User


Joined: 25 Jan 2011
Posts: 10
Location: Kolkata(India)

PostPosted: Thu Sep 15, 2011 12:45 pm
Reply with quote

Thnx enrico,

I'm very sorry to say that u already posted 3 times all r not useful for my live project, i want an idea .....please give chance others
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Sep 15, 2011 12:49 pm
Reply with quote

Follow what enrico is saying.

You are "unstringing" the first field from your pipe-delimited data EACH TIME IN YOUR LOOP.

Look at the manuals. Get rid of the PERFORM.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Sep 15, 2011 12:56 pm
Reply with quote

Quote:
I'm very sorry to say that u already posted 3 times all r not useful for my live project,


if You want good answers provide good question
all you posted was just useless gibberish!

You should feel sorry for Your incompetence rather than for telling me how I should reply
and pleas stop using the idiotic sms chat speak

Quote:
i want an idea
read the effing manual about proper use of cobol constructs

a forum is not a place to have Your job done, but a place to get advice
so the proper approach is not to wait for the correct program snippets, but to read the manuals

the error was a stupid one due to Your laziness in looking at the manuals or searching for example

all this whether You like or not
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Sep 15, 2011 1:02 pm
Reply with quote

Manas Mazumder wrote:
Thnx enrico,

I'm very sorry to say that u already posted 3 times all r not useful for my live project, i want an idea .....please give chance others


sorry, have not idea what the above gibberish means.
if you want to communicate in a professional forum,
write like a professional.

after looking at your code,
suggest you do the following:
Code:

UNSTRING <source-string>
              delimited by '|'
    INTO VAR(1)
        ,VAR(2)
        ,VAR(3)
        ,VAR(4)
        ,VAR(5)
        ,VAR(6)
        ,VAR(7)
        ,VAR(8)
        ,VAR(9)
        ,VAR(10)
END-UNSTRING


I am giving you the answer,
so that you can avoid making any more really, really, stupid comments
and get yourself banned from this website.

your grasp of cobol equals your ability to communicate.

and counting the PROCEDURE DIVISION statement as 1,
I was correct when I said your 3 statement was incorrect.

now apologize to enrico.
had you more professionalism
and fewer personal problems,
you could have found the solution yourself.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Sep 15, 2011 1:12 pm
Reply with quote

Thanks Dick !
I do not really care about getting apologies

I do not remember the name of the personality who
when blamed for his sloppy dressing habits replied
well ...
people who know me, they know me and do not care
people who do not know me, they do not know me and I do not care

what I really like in these forums is the opportunities You get to
refurbish sarcasm, anecdotics, and word playi icon_biggrin.gif
icon_redface.gif and naturally IT skills

but sometime I really wonder
from the TS profile
Occupation: Software Professional
Mainframe Skills: JCL,COBOL,DB2 & CICS
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Sep 15, 2011 3:25 pm
Reply with quote

Study what Dick has posted and keep this link handy: UNSTRING Statement Example and try again.


Once I interview a person, Enrico, with loads of IBM DB2 Certifications on his resume, I asked him, "How would you get the number of rows in a DB2 table? Use any tool you know of, don't think about CPU usage - just answer it."

He started chanting something in-his-mouth, after a while he realized that I'm still in the room and waiting for his answer (more than 5 mnutes it was), he said we need to write a program from scrathc for it! icon_neutral.gif

Me: How about using QMF, SPUFI; writing a SELECT COUNT... kind of query.

There was a long silence for a while, which ended up with next question from me and no answer for the previous one.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Thu Sep 15, 2011 3:34 pm
Reply with quote

Anuj,

Enrico explained it a lot of times. Stupid questions will not get answers icon_eek.gif
Back to top
View user's profile Send private message
Manas Mazumder

New User


Joined: 25 Jan 2011
Posts: 10
Location: Kolkata(India)

PostPosted: Tue Sep 20, 2011 11:02 am
Reply with quote

Sorry to all & thanks for your valuable replying, Below is the code which I have tried to achieve my requirement------

Code:
WORKING-STORAGE SECTION.
       01 WHOLE-RECORD              PIC X(1000).
       01 NAMEX      PIC 9.
       01 POS        PIC 9(4) COMP.
       01 OUT-REC.
               02 VAR1 PIC X(100).
               02 OUT-DATA OCCURS 100 PIC X(30).
       01 OUT-POOS            PIC 9999.
       01 I                   PIC 9999.
       PROCEDURE DIVISION.
      *     DISPLAY SPACES AT 0101.
           MOVE  1  TO POS.
           MOVE 'FIRST_NAME|MIDDLE_NAME|LAST_NAME|AGE|DEPT
      -           '|SEX|NATIONALITY|SALARY|CONTAC_No|'
                 TO WHOLE-RECORD.
           MOVE 1 TO NAMEX.
           MOVE 0 TO OUT-POOS
           PERFORM 001-PARA UNTIL NAMEX = 0
           PERFORM PRT-PARA VARYING I FROM 1 BY 1 UNTIL I > OUT-POOS.
           STOP RUN.
       PRT-PARA.
           DISPLAY OUT-DATA(I).
       001-PARA.
           MOVE 0 TO NAMEX
           UNSTRING WHOLE-RECORD
               DELIMITED BY "|"
               INTO VAR1
           WITH POINTER  POS  ON OVERFLOW
           MOVE 1 TO NAMEX.
           IF NAMEX = 1
                   ADD 1 TO OUT-POOS
                   MOVE VAR1 TO OUT-DATA(OUT-POOS)
                   DISPLAY 'VAR1: '  VAR1.

OUTPUT--

Code:
VAR1: FIRST_NAME

VAR1: MIDDLE_NAME

VAR1: LAST_NAME

VAR1: AGE

VAR1: DEPT

VAR1: SEX

VAR1: NATIONALITY

VAR1: SALARY

VAR1: CONTAC_No

FIRST_NAME
MIDDLE_NAME
LAST_NAME
AGE
DEPT
SEX
NATIONALITY
SALARY
CONTAC_No


with regards,
Manas Mazumder
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Sep 20, 2011 2:35 pm
Reply with quote

An interesting approach.

Why do you want to do UNSTRING 9 times, when you only really need to do it once?

Even in a little mock-up program, why are I and OUT-POOS (no, I'm not going to comment on that) DISPLAY NUMERIC not COMP/BINARY/COMP-5? Even NAMEX would help. What about some 88's to make things clearer?

You originally mentioned a "NULL" delimeter for the end of the record, you haven't taken care of that yet. Is there always a "trailing" "pipe" before the end of the record, else you are in danger of losing your last field.

What if there is a "missing" field, what are you going to get in your output?
ie 'FIRST_NAME||LAST_NAME|'.
Back to top
View user's profile Send private message
Manas Mazumder

New User


Joined: 25 Jan 2011
Posts: 10
Location: Kolkata(India)

PostPosted: Tue Sep 20, 2011 3:39 pm
Reply with quote

Thanks Mr. Bill for your replying, actually when I studied on current requirement noticed that the input string was ended with pipe (|) not with NULL Character. sorry for that.

And I study on your queries and get back to you soon.

But at least my problem is now solved thanks all of you for giving your valuable time for that.


With regards,

Manas Mazumder
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Sep 20, 2011 3:53 pm
Reply with quote

Code:
UNSTRING <source-string>
              delimited by '|'
    INTO VAR(1)
        ,VAR(2)
        ,VAR(3)
        ,VAR(4)
        ,VAR(5)
        ,VAR(6)
        ,VAR(7)
        ,VAR(8)
        ,VAR(9)
END-UNSTRING


dbz already showed you something like the above. Did you try it?

You need to be aware that UNSTRING stops "moving" data into the destination when the "substring" ends. Try you test with a third set of data which are shorter than the first, as well as with the second set of data missing the middle-name. That is all three at the same time, not one at a time.

You should also check whether your data is messed up, so in the UNSTRING do the count and check for the overflow, and do something rational if there are too few or two many fields. This may never happen, but if you code for it ahead of time you will be saved if it does happen.
Back to top
View user's profile Send private message
Manas Mazumder

New User


Joined: 25 Jan 2011
Posts: 10
Location: Kolkata(India)

PostPosted: Tue Sep 20, 2011 4:29 pm
Reply with quote

Thnx Bill,
Actually in my case my approach is to separate variables from unknown length of string which delimited by pipe. I don't know it is 9 times or 5 times or so many. So I have to need catch each variable and print them by or through a variable.

So in my program we are increasing the length like this way -

'|SEX|NATIONALITY|SALARY|CONTAC_No| ' ----- my existing input

NEW--- '|SEX|NATIONALITY|SALARY|CONTAC_No|ADDRESS1| ADDRESS2|----

If this way string length may be increased then no effect on this program and it gives output like previously posted.


Thnx
Manas
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Sep 20, 2011 4:34 pm
Reply with quote

i have my way of doing it,
i want to use a loop,
i have to use a loop -
it is a requirement
i know it is the right way,
do not try to confuse me with facts!
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Sep 20, 2011 4:45 pm
Reply with quote

Well, it would have been nice to know that up front.

What exactly are you trying to do in your program? I don't understand from what you have said so far why you don't know how many fields you have. In your latest example you have limited both the string size and the number of fields. How does that work with what you are now saying?

From what you have said up to this point, I'd not use UNSTRING, but tell us what you are really trying to do (forget the programming-speak, tell us in words).
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Sep 20, 2011 5:04 pm
Reply with quote

TS would prefer to loop thru UNSTRING and STRING statements,
than to do one UNSTRING
loop thru the populated,
finding the unpopulated,
populating the the unpopulated with the new stuff to be appended
and then do one STRING.

another example of a solution looking for a problem.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Wed Sep 21, 2011 1:36 pm
Reply with quote

Morning Guy's !

I would think, unstring with the use of pointers and count would easily solve the problem of separating the data in the whole input record.

This handling should nicely be packaged in a loop over the record until max-recsize is reached, or something like this.

To handle the number of bunstringed data, plse use the tallying option.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Sep 22, 2011 3:51 pm
Reply with quote

Manas Mazumder wrote:
[...]
Code:
WORKING-STORAGE SECTION.
       01 WHOLE-RECORD              PIC X(1000).
       01 NAMEX      PIC 9.
       01 POS        PIC 9(4) COMP.
       01 OUT-REC.
               02 VAR1 PIC X(100).
               02 OUT-DATA OCCURS 100 PIC X(30).
       01 OUT-POOS            PIC 9999.
       01 I                   PIC 9999.
       PROCEDURE DIVISION.
      *     DISPLAY SPACES AT 0101.
           MOVE  1  TO POS.
           MOVE 'FIRST_NAME|MIDDLE_NAME|LAST_NAME|AGE|DEPT
      -           '|SEX|NATIONALITY|SALARY|CONTAC_No|'
                 TO WHOLE-RECORD.
           MOVE 1 TO NAMEX.
           MOVE 0 TO OUT-POOS
           PERFORM 001-PARA UNTIL NAMEX = 0
           PERFORM PRT-PARA VARYING I FROM 1 BY 1 UNTIL I > OUT-POOS.
           STOP RUN.
       PRT-PARA.
           DISPLAY OUT-DATA(I).
       001-PARA.
           MOVE 0 TO NAMEX
           UNSTRING WHOLE-RECORD
               DELIMITED BY "|"
               INTO VAR1
           WITH POINTER  POS  ON OVERFLOW
           MOVE 1 TO NAMEX.
           IF NAMEX = 1
                   ADD 1 TO OUT-POOS
                   MOVE VAR1 TO OUT-DATA(OUT-POOS)
                   DISPLAY 'VAR1: '  VAR1.

[...]


Manas,

You have got yourself to a solution. If you do want to continue that way, pay close attention to what UmeySan has said (Hi UmeySan!). That means doing everything properly. If you only have a table which can store 30 items, make sure you don't exceed 30 and start stamping on the rest of your program. If you are unstrining to 100 bytes, don't then chop them down to 30 unthinglingly. Why use a numeric for your flag? PIC X, and arrange it so you don't have to set it to an illogical value just to get into your perform. Etc.

One problem that you may face is the "trailing" "pipe". It is unusual in a delimeted record to have a trailing delimeter. There is a danger that someone "fixes" this without telling you. If you are going to rely on a trailing delimeter, you are going to have to check that you actually have one! (This is the same for any condition in any program that you rely on).

Also, with the trailing pipe, if there is the "null" that you originally mentioned, your final field (which you have not emulated in your test), will consist of the "null".

Although there is a certain "neatness" to the correct implementation of your approach, I still prefer the "use UNSTRING once" approach. It does look uglier, but that is the fault of the syntax.

INSPECT TALLYING can tell you how many delimiters you have. Get the input file sorted out. UNSTRING all at once, and deal with the field starting with a null, like checking it is the last, etc.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Sep 22, 2011 4:09 pm
Reply with quote

just a side note:
get into the habit of always using GOBACK instead of STOP RUN.

you will avoid to problem of RUN-UNIT Termination from a sub-module.
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 Goto page 1, 2  Next

 


Similar Topics
Topic Forum Replies
No new posts Store the data for fixed length COBOL Programming 1
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
Search our Forums:

Back to Top