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

Count the length of the data in a group variable.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
bijal.awhad

New User


Joined: 19 Mar 2008
Posts: 51
Location: Pune

PostPosted: Wed Jul 22, 2009 3:22 pm
Reply with quote

Varialbe is defined as below

01 WK-INPUT-REC.
05 WK-IN-ONE PIC X (18).
05 WK-IN-TWO PIC X (03).
05 WK-IN-THREE PIC X (07).
05 WK-IN-FOUR PIC X (15).
05 WK-IN-COUNT PIC 9 (04).
05 WK-IN-TABLE OCCURS 2000 TIMES INDEXED BY IX-IN.
10 WK-IN-NO.
15 WK-IN-ORD. PIC X (08).
15 WK-IN-CODE PIC XX.


WK-IN-TABLE can either have 1 to 2000 occurences of WK-IN-NO.The occurence of WK-IN-TABLE is equal to WK-IN-COUNT. So if WK-IN-COUNT is 10 then WK-IN-TABLE will occur 10 times.

How i can calculate length of the data in WK-INPUT-REC?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Jul 22, 2009 4:52 pm
Reply with quote

05 WK-IN-TABLE OCCURS 2000 TIMES INDEXED BY IX-IN

needs to be an ODO.

without the ODO, WK-INPUT-REC will always be a fixed length record.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Wed Jul 22, 2009 4:55 pm
Reply with quote

Why bother to calculate at all? Recompile with the MAP option turned on and let COBOL do the work for you.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Jul 22, 2009 4:56 pm
Reply with quote

compute len-of-input-rec = LENGTH(WK-INPUT-REC) - LENGTH(WK-IN-TABLE) + (WS-IN-COUNT * length(ws-in-no))
end-compute
Back to top
View user's profile Send private message
Dsingh29

Active User


Joined: 16 Dec 2008
Posts: 132
Location: IBM

PostPosted: Wed Jul 22, 2009 5:09 pm
Reply with quote

Hi,

May be we would be able to help more if you can tell for what purpose you require the length..(like if you need it for computing the starting position of the subsequent variables, etc.). Try with FileAid, if you have that tool, it will count this for you.

Dave
Back to top
View user's profile Send private message
bijal.awhad

New User


Joined: 19 Mar 2008
Posts: 51
Location: Pune

PostPosted: Wed Jul 22, 2009 6:44 pm
Reply with quote

Dsingh29 wrote:
Hi,

May be we would be able to help more if you can tell for what purpose you require the length..(like if you need it for computing the starting position of the subsequent variables, etc.). Try with FileAid, if you have that tool, it will count this for you.

Dave



We are getting WK-INPUT-REC from interfacing application.We have to calculate the length of the record for its correctness. This check is part of validation.

Regards
Bijal
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


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

PostPosted: Wed Jul 22, 2009 7:11 pm
Reply with quote

With this definition
Code:
05 WK-IN-TABLE OCCURS 2000 TIMES INDEXED BY IX-IN.
10 WK-IN-NO.
15 WK-IN-ORD. PIC X (08).
15 WK-IN-CODE PIC XX.
this
Quote:
WK-IN-TABLE can either have 1 to 2000 occurences of WK-IN-NO.The occurence of WK-IN-TABLE is equal to WK-IN-COUNT. So if WK-IN-COUNT is 10 then WK-IN-TABLE will occur 10 times
is not predictable

Above table definition should use "depending on" clause to meet what you said
Code:
05 WK-IN-TABLE OCCURS 2000 TIMES  DEPENDING ON WK-IN-COUNT INDEXED BY IX-IN.
10 WK-IN-NO.
15 WK-IN-ORD. PIC X (08).
15 WK-IN-CODE PIC XX.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Wed Jul 22, 2009 7:17 pm
Reply with quote

Okay, why not add the length of WS-IN-ONE, WS-IN-TWO, WS-IN-THREE, WS-IN-FOUR, WS-IN-COUNT and 10 times WS-IN-COUNT? If you do not know how long the individual fields are, you really need to go to the COBOL Language Reference manual (link at the top of the page) and spend some serious time reading about COBOL variables so you can figure out these lengths.

And what happens if you calculate a length of 137? How can you use it? What kind of validation does this give you since the interfacing application could be sending you the entire 20,037 bytes every time -- which may say the data in the first 137 bytes is okay and the rest of it is garbage.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Jul 22, 2009 9:53 pm
Reply with quote

I am bored, so I will repeat my earlier entry:
Code:

COMPUTE LEN-OF-INPUT-REC =   FUNCTION LENGTH(WK-INPUT-REC)
                           - FUNCTION LENGTH(WK-IN-TABLE)
                           + (WS-IN-COUNT * FUNCTION LENGTH(WS-IN-NO))
END-COMPUTE
Back to top
View user's profile Send private message
bijal.awhad

New User


Joined: 19 Mar 2008
Posts: 51
Location: Pune

PostPosted: Wed Jul 22, 2009 11:19 pm
Reply with quote

Robert Sample wrote:
Okay, why not add the length of WS-IN-ONE, WS-IN-TWO, WS-IN-THREE, WS-IN-FOUR, WS-IN-COUNT and 10 times WS-IN-COUNT? If you do not know how long the individual fields are, you really need to go to the COBOL Language Reference manual (link at the top of the page) and spend some serious time reading about COBOL variables so you can figure out these lengths.

And what happens if you calculate a length of 137? How can you use it? What kind of validation does this give you since the interfacing application could be sending you the entire 20,037 bytes every time -- which may say the data in the first 137 bytes is okay and the rest of it is garbage.


Interfacing application will be sending maximum length of 20047. Not every time they will be sending entire 20047 bytes. First 47 bytes will always come but next bytes depends on count.

As you told add length of one,two,three,four,count and 10 times count.This is one of the way to do it.

Regards
Bijal
Back to top
View user's profile Send private message
bijal.awhad

New User


Joined: 19 Mar 2008
Posts: 51
Location: Pune

PostPosted: Wed Jul 22, 2009 11:28 pm
Reply with quote

dbzTHEdinosauer wrote:
I am bored, so I will repeat my earlier entry:
Code:

COMPUTE LEN-OF-INPUT-REC =   FUNCTION LENGTH(WK-INPUT-REC)
                           - FUNCTION LENGTH(WK-IN-TABLE)
                           + (WS-IN-COUNT * FUNCTION LENGTH(WS-IN-NO))
END-COMPUTE



Let's say WS-IN-COUNT is 100.Then length of the data in WK-IN-TABLE will be (100 * 10) 1000.Hence total length of WK-INPUT-REC is
(18+3+7+15+4+1000) = 1047


As per your compute

LEN-OF-INPUT-REC = 20047 - 20000 + (100 * 10)
= 20047 - 21000
= -943
But actual length is 1047.

Regards
Bijal
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


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

PostPosted: Wed Jul 22, 2009 11:51 pm
Reply with quote

bijal.awhad wrote:
As per your compute

LEN-OF-INPUT-REC = 20047 - 20000 + (100 * 10)
= 20047 - 21000
= -943
But actual length is 1047.
Which school you are from?

LEN-OF-INPUT-REC = 20047 - 20000 + (100 * 10)
= 21047 - 20000
= 1047
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Jul 22, 2009 11:53 pm
Reply with quote

Subtraction and Addition are done left to right unless there are parenthese.

Your calculations are based on

FUNCTION LENGTH(WK-INPUT-REC)
- (FUNCTION LENGTH(WK-IN-TABLE)+ (WS-IN-COUNT * FUNCTION LENGTH(WS-IN-NO)))

Which is not the way the statement is coded!
Back to top
View user's profile Send private message
bijal.awhad

New User


Joined: 19 Mar 2008
Posts: 51
Location: Pune

PostPosted: Thu Jul 23, 2009 10:53 am
Reply with quote

Craq Giegerich wrote:
Subtraction and Addition are done left to right unless there are parenthese.

Your calculations are based on

FUNCTION LENGTH(WK-INPUT-REC)
- (FUNCTION LENGTH(WK-IN-TABLE)+ (WS-IN-COUNT * FUNCTION LENGTH(WS-IN-NO)))

Which is not the way the statement is coded!


Anuj Dhawan & Craq Giegerich

You both are correct. I just forgot basic BODMAS rule. icon_redface.gif

I thank all the people who posted reply.

Regards
Bijal
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


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

PostPosted: Thu Jul 23, 2009 11:04 am
Reply with quote

Not to worry -- once in a while we all overlook small things...

Hopefully you get a logic to start with.

Have a good one, icon_smile.gif
Back to top
View user's profile Send private message
manojkumar.sesuraj

New User


Joined: 15 Apr 2009
Posts: 43
Location: Mumbai

PostPosted: Fri Jul 24, 2009 3:14 pm
Reply with quote

If you have File Aid tool, then go to =H;8 (For some systems =F;8) used to View Record Layout - Dataset Specification. There you can find the length of all fields you defined. icon_cool.gif
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


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

PostPosted: Fri Jul 24, 2009 3:29 pm
Reply with quote

Yes, File-Aid will tell the length of the COBOL fields of interest. But, if you read through the thread, you'll find this:
Quote:
We are getting WK-INPUT-REC from interfacing application.We have to calculate the length of the record for its correctness. This check is part of validation.
so file-aid is not an opition here, as been discarded earlier also.

And, not to sound argumetive, but those options of File-Aid would differ from shop to shop. For my shop it's F;Fa;8.
Back to top
View user's profile Send private message
manojkumar.sesuraj

New User


Joined: 15 Apr 2009
Posts: 43
Location: Mumbai

PostPosted: Fri Jul 24, 2009 3:49 pm
Reply with quote

Thanks Anuj... I need to read the entire thread icon_sad.gif
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


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

PostPosted: Fri Jul 24, 2009 6:07 pm
Reply with quote

Quote:
icon_sad.gif
oh...don't get this disappointed...
Quote:
I need to read the entire thread
Yeah, usually I read through them unless I'm an active particiapnt in the thread.

And I read through some of them them because some threads I found quite knowledgable and I can select few of them to add into "Set a bookmark for this topic" icon_smile.gif
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 db2 vs static data COBOL Programming 1
No new posts REXX/CMS How to place command console... CLIST & REXX 4
No new posts External data queue (changes?) CLIST & REXX 0
No new posts Pull data using date difference betwe... DB2 6
No new posts fast data scrambling PL/I & Assembler 10
Search our Forums:

Back to Top