Setting up the initial COBOL program

First, we will create a sample program to work with. We will base this on the pets sample program included with the product.

mkdir fileshare
cd fileshare
cp $GENESIS_HOME/sample/mfdbc/code/pets.cbl fspets.cbl

Edit the file fspets.cbl and modify the SELECT statement:

SELECT pets-file
ASSIGN TO "fspets"
ORGANIZATION IS INDEXED
ACCESS IS DYNAMIC
RECORD KEY IS patient-id
FILE STATUS IS pets-file-status.

Now compile the program. Note that the program contains the $SET CREATEXFD directive. This directive instructs the checker to generate a new XFD file called fspets.xfd that maps the COBOL field names to a database’s column based format.

cob fspets.cbl anim nognt ;
cobrun fspets

We now have a new data file called fspets populated with data. Next we will write a simple COBOL program to read the information.

cp fspets.cbl rfspets00.cbl

Modify the procedure division to be as follows:

PROCEDURE DIVISION.
MAIN-LOGIC.

open input pets-file.

read pets-file next record.
perform until pets-file-status not = "00"
display patient-id," ",patient-name

read pets-file next record
end-perform.
display "Final file status: ",pets-file-status.

close pets-file.

Exit Program.
Stop Run.

Now compile and run this program to verify that you can read the file locally from the same directory:

cob rfspets00.cbl anim nognt ;
cobrun rfspets00