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

LENGTH OF function and Perform varying


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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
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
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
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
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
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
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 VB to VB copy - Full length reached SYNCSORT 8
Search our Forums:

Back to Top