Getting true length of a variable length record - IBM Mainframe 
Author Message
 Getting true length of a variable length record - IBM Mainframe

Old IBM Mainframe COBOL programs that wanted the true record length of a
Variable Length record would play games with a subscript, reducing it to
-4, so that they could access the record descriptor word (RDW).

With new features of the 1985 ANSI COBOL standard, and IBM language
extensions in COBOL for OS/390 & VM, is it possible to get the actual
record size?  Should I keep playing the "trick" to get true record
length?

My program's FD has records described as "very short" (about 40 bytes),
and "very long" (about 1639 bytes), so the program knows that the file
contains variable length records.  There are 40+ record types coming in,
all in this range.  Right now, the program is acting as if one of
"intermediate length" record types is "very long", so it is wasting time
moving bytes that it doesn't have to.  I used LENGTH OF to acquire a
length, but this is just the described length of the "very long" record,
not the actual size.

The records do not have a "number of occurs" that would allow me to
compute actual sizes for different record types.  Because I am new to
the input data & program, I do not know whether a given record type
always has the same record length, although I suspect it does.
Thanks,
Colin



Mon, 01 Mar 2004 02:26:04 GMT  
 Getting true length of a variable length record - IBM Mainframe

Quote:

> Old IBM Mainframe COBOL programs that wanted the true record length of a
> Variable Length record would play games with a subscript, reducing it to
> -4, so that they could access the record descriptor word (RDW).

> With new features of the 1985 ANSI COBOL standard, and IBM language
> extensions in COBOL for OS/390 & VM, is it possible to get the actual
> record size?  Should I keep playing the "trick" to get true record
> length?

> My program's FD has records described as "very short" (about 40 bytes),
> and "very long" (about 1639 bytes), so the program knows that the file
> contains variable length records.  There are 40+ record types coming in,
> all in this range.  Right now, the program is acting as if one of
> "intermediate length" record types is "very long", so it is wasting time
> moving bytes that it doesn't have to.  I used LENGTH OF to acquire a
> length, but this is just the described length of the "very long" record,
> not the actual size.

> The records do not have a "number of occurs" that would allow me to
> compute actual sizes for different record types.  Because I am new to
> the input data & program, I do not know whether a given record type
> always has the same record length, although I suspect it does.
> Thanks,
> Colin

Not a solution to above problem but that 'LENGTH" thing has always been one
of my disappointments. You specify a field pic x(80) and can use (depending
upon compiler), MOVE LENGTH OF or COMPUTE FUNCTION LENGTH - both giving you
"80".

If ONLY I was able  to put "Hello World" into pic x(80) and the MOVE ACTUAL
or FUNCTION ACTUAL LENGTH  returned "11" - now wouldn't that be nice.

Bill, Chuck  or Stephen - any chance with this one ? (I am of course
thinking about COBOL 2005 not 2002 <G>).

Jimmy, Calgary AB



Mon, 01 Mar 2004 03:18:03 GMT  
 Getting true length of a variable length record - IBM Mainframe


Quote:
> Old IBM Mainframe COBOL programs that wanted the true record length of a
> Variable Length record would play games with a subscript, reducing it to
> -4, so that they could access the record descriptor word (RDW).

I just so happen to need to get a variable length with a project I'm working
on. What's this "trick" you mentioned?

--
Gonzo  -  yes, the one with the curly nose...



Mon, 01 Mar 2004 04:11:20 GMT  
 Getting true length of a variable length record - IBM Mainframe


Quote:

> If ONLY I was able  to put "Hello World" into pic x(80) and the MOVE
ACTUAL
> or FUNCTION ACTUAL LENGTH  returned "11" - now wouldn't that be nice.

No, it wouldn't be nice because the 'actual length' of a PIC X(80) field is
eighty (80).

Perhaps you meant you'd like something  like FUNCTION
LENGTH-WITHOUT-TRAILING-BLANKS?

MCM



Mon, 01 Mar 2004 04:47:15 GMT  
 Getting true length of a variable length record - IBM Mainframe
Unlike pre-85 Standard COBOL's, there is a fully SUPPORTED and documented
way of getting the "actual" length of any variable length record that is
read in any CONFORMING '85 Standard compiler.

If in your FD you use the

  RECORD VARYING IN SIZE FROM m TO N
     DEPENDING ON WS-ITEM

where WS-ITEM is an unsigned integer data item defined in your
working-storage section.

PLEASE NOTE WELL: this is RECORD VARYING IN SIZE and it *replaces* the older
RECORD CONTAINS clause.

If you use this format, the WS-ITEM will include the record size of each
record - after it is read.  This technique is also useful in doing WRITEs -
but in that case, you put the value into the WS-ITEM before you do the
WRITE.

See:
 http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/IGYLR205/5.2.5.3

for complete details

Note: This method (unlike the subscript by -4) works even if files are above
the line and the FD doesn't point to the "real" buffer.

--
Bill Klein
 wmklein <at> ix.netcom.com

Quote:
> Old IBM Mainframe COBOL programs that wanted the true record length of a
> Variable Length record would play games with a subscript, reducing it to
> -4, so that they could access the record descriptor word (RDW).

> With new features of the 1985 ANSI COBOL standard, and IBM language
> extensions in COBOL for OS/390 & VM, is it possible to get the actual
> record size?  Should I keep playing the "trick" to get true record
> length?

> My program's FD has records described as "very short" (about 40 bytes),
> and "very long" (about 1639 bytes), so the program knows that the file
> contains variable length records.  There are 40+ record types coming in,
> all in this range.  Right now, the program is acting as if one of
> "intermediate length" record types is "very long", so it is wasting time
> moving bytes that it doesn't have to.  I used LENGTH OF to acquire a
> length, but this is just the described length of the "very long" record,
> not the actual size.

> The records do not have a "number of occurs" that would allow me to
> compute actual sizes for different record types.  Because I am new to
> the input data & program, I do not know whether a given record type
> always has the same record length, although I suspect it does.
> Thanks,
> Colin



Mon, 01 Mar 2004 05:11:59 GMT  
 Getting true length of a variable length record - IBM Mainframe
Generally, the FD contains one record description of the form:
01  V-TYPE-REC.
  05 V-CHAR PIC X OCCURS 1 TO 1639 DEPENDING NO-OF-BYTES INDEXED V-X.
The Working-Storage contains:
01  NO-OF-BYTES BINARY PIC S9(4) VALUE +1639.
01  REC-LENGTH BINARY PIC S9(4).
01  REC-X        REDEFINES
    REC-LENGTH.
 05 REC-LENGTH-1 PIC X.
 05 REC-LENGTH-2 PIC X.
The Procedure Division has a READ, followed by some code like:
SET V-X     TO  1
SET V-X     DOWN BY  4
MOVE V-CHAR (V-X)  TO  REC-LENGTH-1
MOVE V-CHAR (V-X + 1)  TO  REC-LENGTH-2
Executing this code allows you to pick up the 16 bits in the RDW that contain
the actual record length (including the RDW itself, which COBOL adjusts for when
managing the records).  For this example, if I had a maximum length record,
REC-LENGTH would have a value of +1643, meaning that there were 1639 data bytes
in the record.

I believe that with 1985 COBOL, you could use reference modification, and code
MOVE START-REC-1(VAR-POS:2) TO REC-X
but that isn't what is in most old programs.

Once you have this actual length, you probably will want to subtract 4 from it.
Colin



Mon, 01 Mar 2004 05:16:00 GMT  
 Getting true length of a variable length record - IBM Mainframe
I made the change to my program, and now, I'm seeing most records are 361, with
a few 566, and one at 1141.  Before, I was treating each record as if it were
1613.  Has to be a performance improvement in there somewhere!
Thanks again,
Colin


Mon, 01 Mar 2004 05:59:36 GMT  
 Getting true length of a variable length record - IBM Mainframe
In your FD specify :

RECORD IS VARYING IN SIZE FROM 40 TO 1639 CHARACTERS DEPENDING ON
WS-RECORD-LGTH.

In WORKING-STORAGE specify :

03  WS-RECORD-LGTH PIC  9(09) BINARY VALUE ZERO.

After the completion of the "READ" the field (data-name) WS-RECORD-LGTH will
contain the length of the record just read. By specifying a fullword, you
won't run the risk of high-order truncation, due to the TRUNC compiler
option. But, then again, you could specify PACKED-DECIMAL or DISPLAY, which
is your own preference, but is much less efficient than BINARY. Just make
sure that your picture clause can hold (at a minimum) 5-digits. With BINARY,
whether it's PIC 9(05) through PIC 9(09), it still occupies 4 bytes. This is
why (IMHO) it's pointless to define anything other than a 9(09) definition
for BINARY (4 bytes).

If you're going to "WRITE" a record, populate the field with the desired
record length value prior to the actual write.

Regardless of the data-type of the DEPENDING ON data-name integer, it must
be defined as unsigned.

This facility was introduced with COBOL2 and has carried forward into later
releases of COBOL.

HTH....

Bill


Quote:
> Old IBM Mainframe COBOL programs that wanted the true record length of a
> Variable Length record would play games with a subscript, reducing it to
> -4, so that they could access the record descriptor word (RDW).

> With new features of the 1985 ANSI COBOL standard, and IBM language
> extensions in COBOL for OS/390 & VM, is it possible to get the actual
> record size?  Should I keep playing the "trick" to get true record
> length?

> My program's FD has records described as "very short" (about 40 bytes),
> and "very long" (about 1639 bytes), so the program knows that the file
> contains variable length records.  There are 40+ record types coming in,
> all in this range.  Right now, the program is acting as if one of
> "intermediate length" record types is "very long", so it is wasting time
> moving bytes that it doesn't have to.  I used LENGTH OF to acquire a
> length, but this is just the described length of the "very long" record,
> not the actual size.

> The records do not have a "number of occurs" that would allow me to
> compute actual sizes for different record types.  Because I am new to
> the input data & program, I do not know whether a given record type
> always has the same record length, although I suspect it does.
> Thanks,
> Colin



Mon, 01 Mar 2004 06:07:00 GMT  
 Getting true length of a variable length record - IBM Mainframe

writes:

Quote:

>My program's FD has records described as "very short" (about 40 bytes),
>and "very long" (about 1639 bytes), so the program knows that the file
>contains variable length records.  There are 40+ record types coming in,
>all in this range.  Right now, the program is acting as if one of
>"intermediate length" record types is "very long", so it is wasting time
>moving bytes that it doesn't have to.  I used LENGTH OF to acquire a
>length, but this is just the described length of the "very long" record,
>not the actual size.

If you use the format of
    RECORD VARYING IN SIZE FROM x TO y
          DEPENDING ON WS-RECD-LEN
in the FD , then each read will be filled with the Actual record length.
You might be able to do some edits on the read process to compare/report
the RecordType/RecordLength of all records processed.

Build a table to identify RecordType/RecordLength/Count
for each variation of RecordType/RecordLength encountered.

Do you have any system utilities that might be able to produce
an occurrence analysis of your file?
This might help isolate what record type is causing the overlength
 processing.



Mon, 01 Mar 2004 06:05:51 GMT  
 
 [ 23 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Finding Variable-Length Record Length

2. processing variable length records in text file

3. Import dos file variable record length

4. Variable record length input.

5. Variable Length Records

6. Variable Length records in VS/Cobol II rel 3.0

7. Best way to handle variable length fields within records

8. Reading variable-length records from a file

9. records containing variable length arrays [long]

10. Memory representation of variable length record components

11. How to access files with variable length records?

12. How to access files with variable length records?

 

 
Powered by phpBB® Forum Software