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
 

 

LENGTH OF function and Perform varying

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
atanwc

New User


Joined: 26 Jul 2006
Posts: 24

PostPosted: Wed Jul 26, 2006 7:03 am    Post subject: LENGTH OF function and Perform varying
Reply with quote

My program reads IMS, when it comes back with data(segment), I need to determine the length of the return data because they are variable. I used

01 IMS-OUTPUT-AREA.
05 FILLER pic X(1000).
01 WS-LENGTH pic 9(9) comp.


MOVE LENGTH OF IMS-OUTPUT-AREA TO WS-LENGTH
MOVE IMS-OUTPUT-AREA (1:WS-LENGTH) to WS-OUTPUT

So I can output a variable length.

BUT I just found out the 'LENGTH OF' statement or the WS-LENGTH always retures ''1000' instead of 10, 200 and so on. 1000 was defined in Working Storage.

So what is the LENGTH OF function is? How do I not to use array/ PERFORM to count?
Back to top
View user's profile Send private message

giri_82

New User


Joined: 19 Jul 2006
Posts: 6

PostPosted: Wed Jul 26, 2006 11:36 am    Post subject:
Reply with quote

Hi,
The 'Length of' Function always gives the length of the data in the variable only.

But I think here, you are having a 'FILLER' of Size 1000 in the sub group level of IMS-OUTPUT-AREA.That is why 'Length of' function is returning the length as 1000.

Try using


01 IMS-OUTPUT-AREA PIC X(1000).


OR


01 IMS-OUTPUT-AREA.

05 WS-FILL PIC X(1000).

If you are declaring as specified above and using the LENGTH OF function I think you will get the Desired result.


Correct me if I am wrong


Regards,

Giri
Back to top
View user's profile Send private message
atanwc

New User


Joined: 26 Jul 2006
Posts: 24

PostPosted: Wed Jul 26, 2006 5:40 pm    Post subject:
Reply with quote

Thanks Giri!

I had tried the 01 IMS-OUTPUT-AREA PIC X(1000) but it worked the same, return 1000.
I will tried WS-FILL PIC X(1000) today and let you know tonight.
Thanks for your help!

atanwc
Back to top
View user's profile Send private message
atanwc

New User


Joined: 26 Jul 2006
Posts: 24

PostPosted: Wed Jul 26, 2006 6:47 pm    Post subject: Re: Can LENGTH OF function replace perform varying in counti
Reply with quote

Gili, here is the test and it is not working.

05 WS-DB-CALL-IO-AREA.
10 WS-ROOT-SEGMENT-LENGTH PIC S9(4) COMP VALUE +0.
10 WS-FILLER PIC X(998) VALUE SPACES.
05 FILLER REDEFINES WS-DB-CALL-IO-AREA.
10 WS-CALL-CHAR PIC X OCCURS 1000 TIMES
INDEXED BY WS-CALL-PNT.


==========================================
MOVE LENGTH OF WS-DB-CALL-IO-AREA
TO WS-SEG2-LEN
DISPLAY 'HERE ' LENGTH OF WS-DB-CALL-IO-AREA
DISPLAY 'HERE1 ' WS-SEG2-LEN

The display is 1000
Back to top
View user's profile Send private message
atanwc

New User


Joined: 26 Jul 2006
Posts: 24

PostPosted: Wed Jul 26, 2006 7:01 pm    Post subject:
Reply with quote

Also tried this
05 WS-SEG2-LEN USAGE IS BINARY, PIC 9(9) VALUE 0.

05 WS-DB-CALL-IO-AREA1.
10 WS-FILLER1 PIC X(1000).

MOVE WS-DB-CALL-IO-AREA TO WS-DB-CALL-IO-AREA1
MOVE LENGTH OF WS-DB-CALL-IO-AREA
TO WS-SEG2-LEN
DISPLAY 'HERE ' LENGTH OF WS-DB-CALL-IO-AREA1


Result: Dsiplay 1000
Back to top
View user's profile Send private message
atanwc

New User


Joined: 26 Jul 2006
Posts: 24

PostPosted: Wed Jul 26, 2006 7:12 pm    Post subject:
Reply with quote

Try this
01 WS-DB-CALL-IO-AREA1.
10 WS-FILLER1 PIC X(1000).

Also display 1000

need help!
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed Jul 26, 2006 10:43 pm    Post subject: Re: Can LENGTH OF function replace perform varying in counti
Reply with quote

There are two issues here. I'll handle them seperatly.

First.
The "LENGTH OF" will NOT give you the length of the data within a field. It will only give you the field length. If you need the length of actual data within the field you will have to search the field from the back to the front, one char at a time until you reach a significant char (The end of the data). When you can know how long the data is within the field.


Second.
Using "LENGTH OF", or searching the data to determine the length of data just read is not the way to do it. Read the following link that talks about reading variable length data.

Reading Variable Length Records

Use Format 3. After your read, Data-Name-1 will contain the length of data just read

Dave
Back to top
View user's profile Send private message
IQofaGerbil

Active User


Joined: 05 May 2006
Posts: 183
Location: Scotland

PostPosted: Thu Jul 27, 2006 12:08 am    Post subject: Re: Can LENGTH OF function replace perform varying in counti
Reply with quote

If your data has a unique delimiter at the end (say a space) then you could use the following to count the data before that character

eg
01 CTR-1 PIC S9(5).

UNSTRING IMS-OUTPUT-AREA
DELIMITED BY SPACE
INTO WS-XYZ COUNT IN CTR-1

then CTR-1 will contain the total number of characters up to the first space.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu Jul 27, 2006 4:07 am    Post subject:
Reply with quote

This should work (haven't tested it):

INSPECT FUNCTION REVERSE(TEXT1) TALLYING L FOR LEADING SPACES
COMPUTE L = LENGTH OF TEXT1 - L

P.S. IQ - Your solution works well for strings w/no imbedded spaces. Otherwise there can be problems.
Back to top
View user's profile Send private message
atanwc

New User


Joined: 26 Jul 2006
Posts: 24

PostPosted: Thu Jul 27, 2006 6:51 am    Post subject:
Reply with quote

Thanks for all your time! But
1) My record is not input from file, it is from read database(IMS). So I cannot use depend on like reading a variable length rec.
2) My task was suppose to replace a perform varying to increase performance. So I cannot perform an array.
3) The record may contains a lot of spaces in the middle of the record because some fields from database may not contain data. So IQofaGerbil I believe I may not be able to use unstring
4) I will try mmwife method INSPECT FUNCTION REVERSE(TEXT1) TALLYING L FOR LEADING SPACES
COMPUTE L = LENGTH OF TEXT1 - L
Thanks!
5) DavidatK, thanks for your info
But I read the IBM site, there is an example
Move Customer-name To Customer-record(1:Function Length(Customer-name))
The website is
http://publib.boulder.ibm.com/infocenter/pdthelp/v1r1/index.jsp?topic=/com.i
It is very similar with my case. So the Function Length should return either 1 to 40 or it should not be always 40 bytes if it defines as 40 bytes. So it made myself to believe 'Length of' can work. What do you think?

Thanks all for your time!
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 Count the length of the record & ... sreekusr DFSORT/ICETOOL 4 Thu Mar 23, 2017 7:52 pm
No new posts Writing on to GSAM variable length rohanthengal JCL & VSAM 6 Fri Mar 03, 2017 7:46 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 6 Sun Nov 06, 2016 8:11 pm


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