IDENTIFICATION DIVISION.
PROGRAM-ID. cobol_Tutorial1.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT CUSTMAST-FILE
ASSIGN TO "CUSTMAST"
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS cm_custnumb
FILE STATUS IS st.
DATA DIVISION.
FILE SECTION.
FD CUSTMAST-FILE
RECORD CONTAINS 16 TO 1024 CHARACTERS.
01 CUSTMAST-RECORD.
03 cm_custnumb PIC X(4).
03 cm_custzipc PIC X(9).
03 cm_custstat PIC X(2).
03 cm_custrtng PIC X(1).
XFD VAR-LENGTH
03 cm_custname PIC X(47).
XFD VAR-LENGTH
03 cm_custaddr PIC X(47).
XFD VAR-LENGTH
03 cm_custcity PIC X(47).
WORKING-STORAGE SECTION.
77 st PIC X(2).
PROCEDURE DIVISION.
DECLARATIVES.
CUSTMAST-ERROR SECTION.
USE AFTER STANDARD ERROR PROCEDURE ON CUSTMAST-FILE.
CUSTMAST-ERR.
if file does not exist
if st = "35"
create table
perform Create_CustomerMaster_Table
open table
open i-o CUSTMAST-FILE
else
perform Handle_Error
end-if.
CUSTMAST-ERR-EXIT.
exit.
end declaratives.
main.
perform Init.
perform Define.
perform Manage.
perform Done.
display "Press <ENTER> key to exit . . .".
accept omitted end-accept.
stop run.
Init.
display "INIT".
no specific action is required to connect
Define.
display "DEFINE".
create table
perform Create_CustomerMaster_Table
open table
open i-o CUSTMAST-FILE.
Manage.
display "MANAGE".
populate the table with data
perform Add-Records.
display contents of table
perform Display_Records.
delete any existing records
perform Delete_Records.
Done.
display "DONE".
close CUSTMAST-FILE.
Create_CustomerMaster_Table.
display " Create table..."
create table
open output CUSTMAST-FILE
close CUSTMAST-FILE.
Delete_Records.
display " Delete records..."
move low-values to cm_custnumb
start CUSTMAST-FILE key not less cm_custnumb
perform until st not = "00"
read CUSTMAST-FILE next
at end
exit perform
not at end
delete CUSTMAST-FILE
end-read
end-perform.
Add_Records.
display " Add records..."
move "1000" to cm_custnumb.
move "92867" to cm_custzipc.
move "CA" to cm_custstat.
move "1" to cm_custrtng.
move "Bryan Williams" to cm_custname.
move "2999 Regency" to cm_custaddr.
move "Orange" to cm_custcity.
write CUSTMAST-RECORD.
move "1001" to cm_custnumb.
move "61434" to cm_custzipc.
move "CT" to cm_custstat.
move "1" to cm_custrtng.
move "Michael Jordan" to cm_custname.
move "13 Main" to cm_custaddr.
move "Harford" to cm_custcity.
write CUSTMAST-RECORD.
move "1002" to cm_custnumb.
move "73677" to cm_custzipc.
move "GA" to cm_custstat.
move "1" to cm_custrtng.
move "Joshua Brown" to cm_custname.
move "4356 Cambridge" to cm_custaddr.
move "Atlanta" to cm_custcity.
write CUSTMAST-RECORD.
move "1003" to cm_custnumb.
move "10034" to cm_custzipc.
move "MO" to cm_custstat.
move "1" to cm_custrtng.
move "Keyon Dooling" to cm_custname.
move "19771 Park Avenue" to cm_custaddr.
move "Columbia" to cm_custcity.
write CUSTMAST-RECORD.
Display_Records.
display " Display records..."
move low-values to cm_custnumb
start CUSTMAST-FILE key not less cm_custnumb
perform until st not = "00"
read CUSTMAST-FILE next
at end
exit perform
not at end
display " " with no advancing
display cm_custnumb " " with no advancing
display cm_custname
end-read
end-perform.
Handle_Error.
display "ERROR: [" st "]"
display "*** Execution aborted ***"
display "Press <ENTER> key to exit..."
accept omitted end-accept
stop run.