Read 4 byte field in Variable Block File



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Read 4 byte field in Variable Block File

Postby priyanshu90 » Wed Jul 11, 2012 11:06 pm

For a variable block file we have first four bytes for the Record length. How can we move that 4 byte field in a variable in our program?
priyanshu90
 
Posts: 4
Joined: Fri Dec 16, 2011 5:59 pm
Has thanked: 1 time
Been thanked: 0 time

Re: Read 4 byte field in Variable Block File

Postby Robert Sample » Wed Jul 11, 2012 11:40 pm

The FIRST question is, why would you want to do that?

Second, the record descripter word (RDW) is not part of a COBOL program as it is controlled by the operating system.

Thrid, you can get the record length by using the RECORD VARYING clause in the FD description for the file, which gives you the same thing as if you accessed the RDW.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Read 4 byte field in Variable Block File

Postby dick scherrer » Thu Jul 12, 2012 12:02 am

Hello and welcome to the forum,

What you are tryiing to do probably should not be done. . .

If you explain why you believe this is needed, someone may have a suggestion.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Read 4 byte field in Variable Block File

Postby priyanshu90 » Thu Jul 12, 2012 12:49 am

dick scherrer wrote:Hello and welcome to the forum,

What you are tryiing to do probably should not be done. . .

If you explain why you believe this is needed, someone may have a suggestion.

Normally for a variable block file there is always a field in the copybook for that file which has the length stored for each record. However in this case the field is blank and does not contain any value..This is why i need to use those 4 bytes
priyanshu90
 
Posts: 4
Joined: Fri Dec 16, 2011 5:59 pm
Has thanked: 1 time
Been thanked: 0 time

Re: Read 4 byte field in Variable Block File

Postby Akatsukami » Thu Jul 12, 2012 1:07 am

priyanshu90 wrote:
dick scherrer wrote:Hello and welcome to the forum,

What you are tryiing to do probably should not be done. . .

If you explain why you believe this is needed, someone may have a suggestion.

Normally for a variable block file there is always a field in the copybook for that file which has the length stored for each record. However in this case the field is blank and does not contain any value..This is why i need to use those 4 bytes

Note that this is a case where obsessing on the wrong question leads to the wrong answer being given. As Mr. Sample writes:
you can get the record length by using the RECORD VARYING clause in the FD description for the file, which gives you the same thing as if you accessed the RDW
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Read 4 byte field in Variable Block File

Postby Anuj Dhawan » Thu Jul 12, 2012 9:30 am

As an Application Programmer, you never need to bother about the contents of RDW. By any chance are you talking about to determine the "length of contents" in some COBOL variable read in to from a VB file?
Anuj
Anuj Dhawan
 
Posts: 273
Joined: Mon Feb 25, 2008 3:53 am
Location: Mumbai, India
Has thanked: 6 times
Been thanked: 4 times

Re: Read 4 byte field in Variable Block File

Postby priyanshu90 » Thu Jul 12, 2012 2:49 pm

Anuj Dhawan wrote:As an Application Programmer, you never need to bother about the contents of RDW. By any chance are you talking about to determine the "length of contents" in some COBOL variable read in to from a VB file?


Yes I am
priyanshu90
 
Posts: 4
Joined: Fri Dec 16, 2011 5:59 pm
Has thanked: 1 time
Been thanked: 0 time

Re: Read 4 byte field in Variable Block File

Postby Robert Sample » Thu Jul 12, 2012 4:50 pm

If used on an input file, the RECORD VARYING clause sets the variable to the length of each record when a READ is done. If used on an output file, you must set the length before doing the WRITE.

In other words, you do not need to access the RDW since the RECORD VARYING clause gives you the exact same data in a COBOL way.

These users thanked the author Robert Sample for the post:
priyanshu90 (Thu Jul 12, 2012 7:16 pm)
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Read 4 byte field in Variable Block File

Postby Anuj Dhawan » Thu Jul 12, 2012 6:14 pm

I'm bit confused now and afraid if OP is talking about this: :?

01  TEXT1           PIC X(40) VALUE 'THIS IS THE STRING'.


INSPECT FUNCTION REVERSE(TEXT1) TALLYING L FOR LEADING SPACES
COMPUTE L = LENGTH OF TEXT1 - L
Anuj
Anuj Dhawan
 
Posts: 273
Joined: Mon Feb 25, 2008 3:53 am
Location: Mumbai, India
Has thanked: 6 times
Been thanked: 4 times

Re: Read 4 byte field in Variable Block File

Postby priyanshu90 » Thu Jul 12, 2012 7:17 pm

The RECORD VARYING CLAUSE gave me the desired result..Thanks Guys :)
priyanshu90
 
Posts: 4
Joined: Fri Dec 16, 2011 5:59 pm
Has thanked: 1 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post