Variable Length Files- Fujitsu 5.0 
Author Message
 Variable Length Files- Fujitsu 5.0

I have some old programs that were used on MVS which need to be
adapted to Fujitsu Cobol 5.0 on the PC.  My problem is variable length
files that do not specify the length within the file.  The data file
contains two formats - A and B.  Format A had a record length of 500
which is followed by 1 to 99 format B records that have a length of
125.  These repeat.  The data is sequential (no delimiters).

Using the programs with the following two samples results in an
invalid delimiter error (inv-delmtr) when I compile the program.
Sample 1.
       FILE-CONTROL.
           SELECT INFILE ASSIGN TO FILEIN.
       DATA DIVISION.
       FILE SECTION.
       FD  INFILE
           BLOCK CONTAINS 0 RECORDS
           RECORDING MODE IS V
           LABEL RECORDS ARE STANDARD.
       01  IN-RECORD.
           05  FILE-KEY
               10 FLD001-IN         PIC X(06).
               10 FLD002-IN         PIC X(05).
               10 FLD003-IN         PIC X(05).
               10 FLD004-IN         PIC X(10).
           05  FORMAT-IN            PIC X(001).
           05  FILLER               PIC X(473).  

       01  HISTORY-FMTA-RECORD      PIC X(500).  
       01  HISTORY-FMTB-RECORD      PIC X(125).

Sample 2.
       FILE-CONTROL.
            SELECT  INFILE ASSIGN TO FILEIN.
       DATA DIVISION.
       FILE SECTION.
       FD  INFILE
           BLOCK CONTAINS 0 RECORDS
           RECORDING MODE IS V
           RECORD CONTAINS 125 TO 500 CHARACTERS
           LABEL RECORDS ARE STANDARD
           DATA RECORDS ARE IN-RECORD
                            HISTORY-FMTA-RECORD
                            HISTORY-FMTB-RECORD.

Read Section (same one used in both of above samples).

           250-READ SECTION.
           READ INFILE
               AT END MOVE 'YES' TO EOF-SW
               GO TO 250-EXIT.
           ADD 1 TO REC-READ-CTR.

           IF FORMAT-IN = 'A'
               MOVE HISTORY-FMTA-RECORD TO WS-FMTA-RECORD
               GO TO 250-EXIT.

           IF FORMAT-IN = 'B'
               MOVE HISTORY-FMTB-RECORD TO WS-FMTB-RECORD
           ELSE
               ADD 1 TO FORMAT-ERR-CTR.

Does anyone have an example of how these should be rewritten.  

Thanks
BJ



Sat, 10 Sep 2005 07:52:15 GMT  
 Variable Length Files- Fujitsu 5.0

Quote:

> Sample 2.
>        FILE-CONTROL.
>             SELECT  INFILE ASSIGN TO FILEIN.
>        DATA DIVISION.
>        FILE SECTION.
>        FD  INFILE
>            BLOCK CONTAINS 0 RECORDS
>            RECORDING MODE IS V
>            RECORD CONTAINS 125 TO 500 CHARACTERS
>            LABEL RECORDS ARE STANDARD
>            DATA RECORDS ARE IN-RECORD
>                             HISTORY-FMTA-RECORD
>                             HISTORY-FMTB-RECORD.

        FD  INFILE
            RECORD VARYING 125 TO 500.


Sat, 10 Sep 2005 20:47:52 GMT  
 Variable Length Files- Fujitsu 5.0


Quote:
> I have some old programs that were used on MVS which need to be
> adapted to Fujitsu Cobol 5.0 on the PC.  My problem is variable length
> files that do not specify the length within the file.  The data file
> contains two formats - A and B.  Format A had a record length of 500
> which is followed by 1 to 99 format B records that have a length of
> 125.  These repeat.  The data is sequential (no delimiters).

> Using the programs with the following two samples results in an
> invalid delimiter error (inv-delmtr) when I compile the program.
> Sample 1.
>        FILE-CONTROL.
>            SELECT INFILE ASSIGN TO FILEIN.
>        DATA DIVISION.
>        FILE SECTION.
>        FD  INFILE
>            BLOCK CONTAINS 0 RECORDS
>            RECORDING MODE IS V
>            LABEL RECORDS ARE STANDARD.
>        01  IN-RECORD.
>            05  FILE-KEY
>                10 FLD001-IN         PIC X(06).
>                10 FLD002-IN         PIC X(05).
>                10 FLD003-IN         PIC X(05).
>                10 FLD004-IN         PIC X(10).
>            05  FORMAT-IN            PIC X(001).
>            05  FILLER               PIC X(473).

>        01  HISTORY-FMTA-RECORD      PIC X(500).
>        01  HISTORY-FMTB-RECORD      PIC X(125).

> Sample 2.
>        FILE-CONTROL.
>             SELECT  INFILE ASSIGN TO FILEIN.
>        DATA DIVISION.
>        FILE SECTION.
>        FD  INFILE
>            BLOCK CONTAINS 0 RECORDS
>            RECORDING MODE IS V
>            RECORD CONTAINS 125 TO 500 CHARACTERS
>            LABEL RECORDS ARE STANDARD
>            DATA RECORDS ARE IN-RECORD
>                             HISTORY-FMTA-RECORD
>                             HISTORY-FMTB-RECORD.

> Read Section (same one used in both of above samples).

>            250-READ SECTION.
>            READ INFILE
>                AT END MOVE 'YES' TO EOF-SW
>                GO TO 250-EXIT.
>            ADD 1 TO REC-READ-CTR.

>            IF FORMAT-IN = 'A'
>                MOVE HISTORY-FMTA-RECORD TO WS-FMTA-RECORD
>                GO TO 250-EXIT.

>            IF FORMAT-IN = 'B'
>                MOVE HISTORY-FMTB-RECORD TO WS-FMTB-RECORD
>            ELSE
>                ADD 1 TO FORMAT-ERR-CTR.

> Does anyone have an example of how these should be rewritten.

First principles:

1. Your input file can't be #2 because Fujitsu's Variable Length files have
length descriptors on the front of each record (which your records don't).
Therefore, any attempt to use RECORDING MODE V is doomed.

2. Remember, in COBOL, one reads FILES. The sequential READ statement
accepts incoming data until a delimiter is hit OR the requested number of
bytes has been transferred.

3. Absent a delimiter, for the record pointer to point to the second record,
the first read operation must know the length of the first record and the
first read operation must know this length before starting the read.

4. In your #1, the first read operation transfers 500 bytes (the maximum
record length defined in the FD) and the record pointer for the next read is
sitting at byte 501. OK so far. Read #2 also transfers 500 bytes, but you
only want 125. Too bad. The record pointer is pointing to byte 1001 in
anticipation of read #3 - and you can't move the pointer back. Your trick of
moving 125 bytes out of the FD is useless; the compiler won't move the
residual 375 up to the front of the buffer.

5. Assuming the first record in the file is a type "A" record (you know its
length), you can set the length to read. If, after getting the "A" record,
you can figure out how many type "B" records follow, you're golden. Here's
how:

01  IN-REC.
    02  FILLER OCCURS 1 TO 500 DEPENDING ON LEN PIC X.

*>Get an "A"
PERFORM UNTIL EOF
  MOVE 500 TO LEN
  READ IN-FILE
  MOVE IN-REC TO WS-HEADER
  *> Somehow deduce number of "B" records following
  PERFORM VARYING RECNO FROM 1 BY 1 UNTIL RECNO > NUM2DO
      MOVE 125 TO LEN
      READ IN-FILE
      MOVE IN-REC TO WS-DETAIL
      END-PERFORM
  END-PERFORM.

Without knowing how many "B" records follow each "A" record, you're pretty
much screwed.

Fortunately, there's an alternative: The CBL file routines.

Email me at jerry at-sign bisusa.com and I'll forward the source on some
subprograms to do what you need.



Sat, 10 Sep 2005 11:40:49 GMT  
 Variable Length Files- Fujitsu 5.0

Quote:
> I have some old programs that were used on MVS which need to be
> adapted to Fujitsu Cobol 5.0 on the PC.  My problem is variable length
> files that do not specify the length within the file.  The data file
> contains two formats - A and B.  Format A had a record length of 500
> which is followed by 1 to 99 format B records that have a length of
> 125.  These repeat.  The data is sequential (no delimiters).

Are you trying to read an existing file, or you trying to change some
programs to use data files as you describe ?

If an existing file is just a block of 500 bytes followed by a
variable number of 125 byte records followd by another 500 byte record
then there is a problem and you can't define an FD that will usefully
describe this.

Because 500 is a multiple of 125 then it should be possible to read a
fixed record size of 125 bytes and build the 500 byte records in
memory from 4 reads.

For this define the file with just a single record of 125 bytes and
_no_ clause in the FD.  This will treat the data file as fixed chunks
125 bytes long (no headers, no delimiters).

Read the file, when you identity that a record is a 500 byte one do 3
more reads moving these 4 to W-S area.

If you are trying to emulate an existing program and the file will be
written by a Fujitsu program then use RECORD VARYING 125 TO 500 as a
clause on the FD (none other required).  Write appropriate record
descriptions and ensure that the type can be identified when it is
read.

The file will be written with headers that specify the length, but
this is not available in the program.

A READ AT END will read the variable record file and set the record
area to the appropriate data.  Identify the record to know which
record area data items to use.



Sat, 10 Sep 2005 14:35:21 GMT  
 Variable Length Files- Fujitsu 5.0

Quote:
> 5. Assuming the first record in the file is a type "A" record (you know its
> length), you can set the length to read. If, after getting the "A" record,
> you can figure out how many type "B" records follow, you're golden. Here's
> how:

> 01  IN-REC.
>     02  FILLER OCCURS 1 TO 500 DEPENDING ON LEN PIC X.

If he is trying to read an existing file with 500 bytes then 125 bytes
then 125 etc then this cannot work.

Fujitsu will read this as if it is a variable format sequential file
that has record headers that includes the length.



Sat, 10 Sep 2005 14:46:14 GMT  
 Variable Length Files- Fujitsu 5.0

Quote:

>I have some old programs that were used on MVS which need to be
>adapted to Fujitsu Cobol 5.0 on the PC.  My problem is variable length
>files that do not specify the length within the file.

They DO specify the length within the file, on both mainframe and Fujitsu. On
the mainframe, there is a binary word in front of each record called the RSW
(Record Status Word). Fujitsu has something comparable. You are not aware it's
there because it doesn't appear in the COBOL record layout. It is created behind
the scenes when you do a WRITE.

Your question asks about READ, but the answer lies in WRITE. Before you can READ
the variable length records in Fujitsu, you most have WRITTEN them in Fujitsu.
You didn't say how the file was created.

Are you getting a compile or an execution error? I sounds like execution.



Sat, 10 Sep 2005 18:14:44 GMT  
 Variable Length Files- Fujitsu 5.0

Quote:
Wagner) writes:
>Your question asks about READ, but the answer lies in WRITE. Before you can
>READ
>the variable length records in Fujitsu, you most have WRITTEN them in
>Fujitsu.
>You didn't say how the file was created.

>Are you getting a compile or an execution error? I sounds like execution.

If it was not written by Fujitsu, then it will not likely be read by fujitsu.
I tried migrating variable length files from the Host to the PC and it
definitely
did not work very nicely at all.
You just about have to flatten out the records on the host to a common length,
get it FTP'ed in BINARY to prevent loss of packed fields then re-process
reading the
EBCDIC file into the PC ASCII variable length file.
At least that is the long way around the horse that I had to exercise.


Mon, 12 Sep 2005 06:29:27 GMT  
 Variable Length Files- Fujitsu 5.0

Quote:


>Wagner) writes:

>>Your question asks about READ, but the answer lies in WRITE. Before you can
>>READ
>>the variable length records in Fujitsu, you most have WRITTEN them in
>>Fujitsu.
>>You didn't say how the file was created.

>>Are you getting a compile or an execution error? I sounds like execution.

>If it was not written by Fujitsu, then it will not likely be read by fujitsu.
>I tried migrating variable length files from the Host to the PC and it
>definitely
>did not work very nicely at all.
>You just about have to flatten out the records on the host to a common length,
>get it FTP'ed in BINARY to prevent loss of packed fields then re-process
>reading the
>EBCDIC file into the PC ASCII variable length file.
>At least that is the long way around the horse that I had to exercise.

I suggested that as the tedious approach. There _are_ tools which can do the
transfer in one step, but most people don't have them. This why we recommend
formatting all files in display, without comp-3 or binary. Because it makes
transfer to another platform so much easier.

Have you learned your lesson? Are your PC files display?

Robert



Mon, 12 Sep 2005 11:23:51 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Processing variable length/variable data files

2. How to access files with variable length records?

3. How to access files with variable length records?

4. Processing Variable Length Files

5. More on reading variable length files

6. How to read variable length files

7. Accessing variable-length records files in C-ISAM standard

8. Variable length files

9. Getting true length of a variable length record - IBM Mainframe

10. Finding Variable-Length Record Length

11. Problem when formating a variable delimited file to fixed length

12. processing variable length records in text file

 

 
Powered by phpBB® Forum Software