How To Read Cobol Data Files Average ratng: 3,8/5 5709reviews
How To Read Cobol Data FilesSee More On Stackoverflow

I need to read MS Cobol 2.0 data files in Delphi over a LAN. While I can easily read Line Sequential Files, I also have to read Sequential files and I just do not.

Cobol File Read Example - Example of opening and reading file with Cobol Cobol Example - Opening and Reading Files. Community Help: Cobol File Read Example - Example of opening and reading file with Cobol This cobol example will show the basics for reading a file. It shows how to open the file, define the file, and read the file. It also shows the cobol variables and how they are defined, but of course some things are left out like how you want to loop through to read all the input data, etc., and of course you will want to close the file when done. This example will use cobol to open and read a variable length file that has 4000 bytes per row max.

It also shows how to check the open and read to make sure it was successfull. In your I/O section: INPUT-OUTPUT SECTION. SELECT FILE-IN ASSIGN TO FILE-NAME-IN FILE STATUS IS WS-STATUS-IN.

In your data division: DATA DIVISION. FILE SECTION.

FD FILE-IN RECORDING MODE IS V. 01 SAMPLE-INPUT-PROF PIC X(4000). In working storage, define: 05 WS-STATUS-IN PIC 9(02) VALUE ZERO. In your cobol code: OPEN INPUT SAMPLE-FILE IF WS-STATUS-IN = 0 (You will loop through the reads) READ FILE-IN INTO WS-I-REC AT END (Do something like close the file when done) END-READ EVALUATE WS-STATUS-IN (Do something with various conditions) END-EVALUATE ELSE (Do something if you had an open error) END-IF.

To read the COBOL-genned file, you'll need to know: First, you'll need the record layout (copybook) for the file. A COBOL record layout will look something like this: 01 PATIENT-TREATMENTS. 05 PATIENT-NAME PIC X(30). 05 PATIENT-SS-NUMBER PIC 9(9). 05 NUMBER-OF-TREATMENTS PIC 99 COMP-3.

05 TREATMENT-HISTORY OCCURS 0 TO 50 TIMES DEPENDING ON NUMBER-OF-TREATMENTS INDEXED BY TREATMENT-POINTER. 10 TREATMENT-DATE.

15 TREATMENT-DAY PIC 99. 15 TREATMENT-MONTH PIC 99.

15 TREATMENT-YEAR PIC 9(4). 10 TREATING-PHYSICIAN PIC X(30). C Program To Print World Map. 10 TREATMENT-CODE PIC 99. You'll also need a copy of IBM's Principles of Operation (S/360, S370, z/OS, doesn't really matter for our purposes). Latest is available from IBM at • (but you'll need an IBM account.

• An older edition is available, gratis, at Chapters 8 (Decimal Instructions) and 9 (Floating Point Overview and Support Instructions) are the interesting bits for our purposes. Without that, you're pretty much lost. Then, you need to understand COBOL data types. For instance: • PIC defines an alphameric formatted field (PIC 9(4), for example is 4 decimal digits, that might be filled with for space characters if missing). Pic 999V99 is 5 decimal digits, with an implied decimal point. So-on and so forthe.

• BINARY is [usually] a signed fixed point binary integer. Usual sizes are halfword (2 octets) and fullword (4 octets). • COMP-1 is single precision floating point. • COMP-2 is double precision floating point.

If the datasource is an IBM mainframe, COMP-1 and COMP-2 likely won't be IEE floating point: it will be IBM's. You'll need something like the S/370 Principles of Operation to help you understand it. • COMP-3 is 'packed decimal', of varying lengths. Packed decimal is a compact way of representing a decimal number. The declaration will look something like this: PIC S9999V99 COMP-3.

This says that is it signed, consists of 6 decimal digits with an implied decimal point. Packed decimal represents each decimal digit as a nibble of an octet (hex values 0-9). The high-order digit is the upper nibble of the leftmost octet. The low nibble of the rightmost octet is a hex value A-F representing the sign. So the above PIC clause will require ceil( (6+1)/2 ) or 4 octets. The value -345.67, as represented by the above PIC clause will look like 0x0034567D. The actual sign value may vary (the default is C/positive, D/negative, but A, C, E and F are treated as positive, while only B and D are treated as negative).