Skip to main content

I have below scenario. 

Input File <<input_file.txt>>

0005abcde                                                                ====> Record1

0020abcdefghijklmnopqrst                                   =====> Record2

Each record has 2 part:

Part#1          4 digit records length (ex: 0005)

Part#2        Actual Data (ex: abcde)

How the FD section should be defined in such case ?



------------------------------
Swapnil Gupta
Senior Application Developer
Pharmacy Data Management, Inc.
Youngstown US
------------------------------

I have below scenario. 

Input File <<input_file.txt>>

0005abcde                                                                ====> Record1

0020abcdefghijklmnopqrst                                   =====> Record2

Each record has 2 part:

Part#1          4 digit records length (ex: 0005)

Part#2        Actual Data (ex: abcde)

How the FD section should be defined in such case ?



------------------------------
Swapnil Gupta
Senior Application Developer
Pharmacy Data Management, Inc.
Youngstown US
------------------------------

Swapnil,

Assuming that this is a standard text file, with end-of-line/CR between text records, then nothing really special is needed.

01  my-record.
    02  my-count         pic 9999.
    02  my-data.
        03  pic x occurs 1 to 500 depending on my-count.

I this is not a standard text file, then it gets a bit more complicated...



------------------------------
Tom Morrison
Consultant
Simpsonville US
------------------------------

Swapnil,

Assuming that this is a standard text file, with end-of-line/CR between text records, then nothing really special is needed.

01  my-record.
    02  my-count         pic 9999.
    02  my-data.
        03  pic x occurs 1 to 500 depending on my-count.

I this is not a standard text file, then it gets a bit more complicated...



------------------------------
Tom Morrison
Consultant
Simpsonville US
------------------------------

Thanks Tom.. I have LF at the end of the record... I tried but getting 3906 while opening the file.

 FD INPUTFILE.
          01 IN-REC.
              05 IN-REC-LEN                  PIC 9(4).
              05 IN-REC-DATA.
                 10 FILLER                   PIC X
                    OCCURS 1 TO 500 DEPENDING ON IN-REC-LEN.



------------------------------
Swapnil Gupta
Senior Application Developer
Pharmacy Data Management, Inc.
Youngstown US
------------------------------

Thanks Tom.. I have LF at the end of the record... I tried but getting 3906 while opening the file.

 FD INPUTFILE.
          01 IN-REC.
              05 IN-REC-LEN                  PIC 9(4).
              05 IN-REC-DATA.
                 10 FILLER                   PIC X
                    OCCURS 1 TO 500 DEPENDING ON IN-REC-LEN.



------------------------------
Swapnil Gupta
Senior Application Developer
Pharmacy Data Management, Inc.
Youngstown US
------------------------------

In the ENVIRONMENT DIVISION/INPUT-OUTPUT SECTION/FILE-CONTROL:

Make sure that the ORGANIZATION clause states:
    ORGANIZATION LINE SEQUENTIAL

Depending on your compiler's configuration, if you omit the word LINE the organization is probably defaulting to BINARY SEQUENTIAL, which causes the mismatch indicated by error 39,06.



------------------------------
Tom Morrison
Consultant
Simpsonville US
------------------------------

In the ENVIRONMENT DIVISION/INPUT-OUTPUT SECTION/FILE-CONTROL:

Make sure that the ORGANIZATION clause states:
    ORGANIZATION LINE SEQUENTIAL

Depending on your compiler's configuration, if you omit the word LINE the organization is probably defaulting to BINARY SEQUENTIAL, which causes the mismatch indicated by error 39,06.



------------------------------
Tom Morrison
Consultant
Simpsonville US
------------------------------

Thanks Tom. I tried. It worked fine.



------------------------------
Swapnil Gupta
Senior Application Developer
Pharmacy Data Management, Inc.
Youngstown US
------------------------------

Thanks Tom. I tried. It worked fine.



------------------------------
Swapnil Gupta
Senior Application Developer
Pharmacy Data Management, Inc.
Youngstown US
------------------------------

Hi Tom,

I have a follow-up question regarding this. Suppose I want to write multiple records to the file without trailing white space. For example, I have the following two records:

0005abcde                         => Record 1  
0020abcdefghijklmnopqrst         => Record 2


Each record consists of two parts:
Part 1: A 4-digit record length (e.g., 0005)
Part 2: The actual data (e.g., abcde)

How should the FD (File Description) section and the SELECT clause be defined in this case to handle such records?



------------------------------
Swapnil Gupta
Senior Application Developer
Pharmacy Data Management, Inc.
Youngstown US
------------------------------

Hi Tom,

I have a follow-up question regarding this. Suppose I want to write multiple records to the file without trailing white space. For example, I have the following two records:

0005abcde                         => Record 1  
0020abcdefghijklmnopqrst         => Record 2


Each record consists of two parts:
Part 1: A 4-digit record length (e.g., 0005)
Part 2: The actual data (e.g., abcde)

How should the FD (File Description) section and the SELECT clause be defined in this case to handle such records?



------------------------------
Swapnil Gupta
Senior Application Developer
Pharmacy Data Management, Inc.
Youngstown US
------------------------------

Swapnil, 

Same thing if these are text records delimited with standard text file delimiters for the platform (*nix vs. Windows).  



------------------------------
Tom Morrison
Consultant
Simpsonville US
------------------------------