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
 

 

Unstring variable length record
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Manas Mazumder

New User


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

PostPosted: Thu Sep 15, 2011 11:41 am    Post subject: Unstring variable length record
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Thu Sep 15, 2011 11:48 am    Post subject: Reply to: Unstring variable length record
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    Post subject:
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    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Thu Sep 15, 2011 11:53 am    Post subject: Reply to: Unstring variable length record
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 http://catb.org/~esr/faqs/smart-questions.html
or .. for a more PC language
here http://support.microsoft.com/kb/555375
Back to top
View user's profile Send private message
Manas Mazumder

New User


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

PostPosted: Thu Sep 15, 2011 12:27 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Thu Sep 15, 2011 12:35 pm    Post subject: Reply to: Unstring variable length record
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: 11
Location: Kolkata(India)

PostPosted: Thu Sep 15, 2011 12:45 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Thu Sep 15, 2011 12:49 pm    Post subject: Reply to: Unstring variable length record
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Thu Sep 15, 2011 12:56 pm    Post subject: Reply to: Unstring variable length record
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    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Thu Sep 15, 2011 1:12 pm    Post subject: Reply to: Unstring variable length record
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

Senior Member


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

PostPosted: Thu Sep 15, 2011 3:25 pm    Post subject:
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: 2422
Location: Netherlands, Amstelveen

PostPosted: Thu Sep 15, 2011 3:34 pm    Post subject:
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: 11
Location: Kolkata(India)

PostPosted: Tue Sep 20, 2011 11:02 am    Post subject: Reply to: Unstring variable length record
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Tue Sep 20, 2011 2:35 pm    Post subject: Reply to: Unstring variable length record
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: 11
Location: Kolkata(India)

PostPosted: Tue Sep 20, 2011 3:39 pm    Post subject: Reply to: Unstring variable length record
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Tue Sep 20, 2011 3:53 pm    Post subject: Reply to: Unstring variable length record
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: 11
Location: Kolkata(India)

PostPosted: Tue Sep 20, 2011 4:29 pm    Post subject:
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    Post subject:
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
No new posts Joinkeys operation when key1 and key2... Susanta DFSORT/ICETOOL 5 Wed Nov 02, 2016 5:35 pm
No new posts sort with previous record anatol DFSORT/ICETOOL 9 Thu Oct 06, 2016 2:36 am
No new posts Get Record count in summary record fo... Atul Banke DFSORT/ICETOOL 21 Fri Sep 23, 2016 4:17 pm


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