View previous topic :: View next topic
|
Author |
Message |
bijal.awhad
New User
Joined: 19 Mar 2008 Posts: 51 Location: Pune
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Why bother to calculate at all? Recompile with the MAP option turned on and let COBOL do the work for you. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Dsingh29
Active User
Joined: 16 Dec 2008 Posts: 132 Location: IBM
|
|
|
|
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 |
|
|
bijal.awhad
New User
Joined: 19 Mar 2008 Posts: 51 Location: Pune
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
bijal.awhad
New User
Joined: 19 Mar 2008 Posts: 51 Location: Pune
|
|
|
|
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 |
|
|
bijal.awhad
New User
Joined: 19 Mar 2008 Posts: 51 Location: Pune
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
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 |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
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 |
|
|
bijal.awhad
New User
Joined: 19 Mar 2008 Posts: 51 Location: Pune
|
|
|
|
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.
I thank all the people who posted reply.
Regards
Bijal |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
Not to worry -- once in a while we all overlook small things...
Hopefully you get a logic to start with.
Have a good one, |
|
Back to top |
|
|
manojkumar.sesuraj
New User
Joined: 15 Apr 2009 Posts: 43 Location: Mumbai
|
|
|
|
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. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
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 |
|
|
manojkumar.sesuraj
New User
Joined: 15 Apr 2009 Posts: 43 Location: Mumbai
|
|
|
|
Thanks Anuj... I need to read the entire thread |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
Quote: |
|
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" |
|
Back to top |
|
|
|