CUSMNT: RPG Source
//****************************************************************
// PROGRAM NAME: CUSMNT *
// RELATED FILES: CUSMSTL1 (LF) *
// MNTMENU (DSPF) *
// DESCRIPTION: This program shows a customer master *
// maintenance program using a workstn file. *
// This program allows the user to add, update, *
// delete and display customer records. *
// PF3 is used to quit the program. *
//****************************************************************
Fcusmstl1 uf a e k disk
Fmntmenu cf e workstn indds(indicators)
// Field definitions:
D indicators ds
D exitKey n overlay(indicators:3)
D disableInput n overlay(indicators:4)
D addKey n overlay(indicators:5)
D updateKey n overlay(indicators:6)
D deleteKey n overlay(indicators:7)
D displayKey n overlay(indicators:8)
D prevKey n overlay(indicators:12)
D custExists n overlay(indicators:51)
D custNotFound n overlay(indicators:52)
// Key list definitions:
C CSTKEY KLIST
C KFLD CUST
//*****************************************************************
// MAINLINE *
//*****************************************************************
/free
mode = 'DISPLAY';
exfmt hdrscn;
// Loop until exit key is pressed
dow not exitKey;
exsr SetMaintenanceMode;
if cust <> 0;
if mode = 'ADD';
exsr AddSub;
elseif mode = 'UPDATE';
exsr UpdateSub;
elseif mode = 'DELETE';
exsr DeleteSub;
elseif mode = 'DISPLAY';
exsr InquirySub;
endif;
endif;
exfmt hdrscn;
custExists = *off; // turn off error messages
CustNotFound = *off;
enddo;
*inlr = *on;
//****************************************************************
// SUBROUTINE - AddSub *
// PURPOSE - Add new customer to file *
//****************************************************************
begsr AddSub;
// Is customer number already in file?
chain CstKey cmlrec1;
if %found(cusmstl1);
// Customer number is already being used
custExists = *on;
leavesr;
endif;
// Initialize new customer data
custExists = *off; // turn off error messages
CustNotFound = *off;
name = *blank;
addr1 = *blank;
addr2 = *blank;
city = *blank;
state = *blank;
zip = 0;
// Prompt for updated data for this customer record
exfmt cstbld;
// If OK, add customer to the customer file
if not *in12;
write cmlrec1;
endif;
endsr; // end of subroutine AddSub
//****************************************************************
// SUBROUTINE - UpdateSub *
// PURPOSE - Update customer master record *
//****************************************************************
begsr UpdateSub;
// Lookup customer number
chain cstkey cmlrec1;
if not %found(cusmstl1);
// Customer is not found in file
custNotFound = *on;
leavesr;
endif;
// Display information for this customer
disableInput = *off;
exfmt cstinq;
if not prevKey;
// Update information in file
update cmlrec1;
else;
// If we don't want to update, at least unlock
// the record.
unlock cusmstl1;
endif;
endsr; // end of subroutine UpdateSub;
//****************************************************************
// SUBROUTINE - DeleteSub *
// PURPOSE - Delete customer master record *
//****************************************************************
begsr DeleteSub;
// Lookup customer number
chain cstkey cmlrec1;
if not %found(cusmstl1);
// Customer is not found in file
custNotFound = *on;
leavesr;
endif;
// Display information for this customer
disableInput = *on;
exfmt cstinq;
if not prevKey;
// Delete customer record
delete cmlrec1;
else;
// If we don't want to delete, at least unlock
// the record.
unlock cusmstl1;
endif;
endsr; // end of subroutine DeleteSub
//****************************************************************
// SUBROUTINE - InquirySub *
// PURPOSE - Display customer master record *
//****************************************************************
begsr InquirySub;
// Lookup customer number
chain(n) cstkey cmlrec1; // don't lock record
if not %found(cusmstl1);
// Customer is not found in file
custNotFound = *on;
leavesr;
endif;
// Display information for this customer
disableInput = *on;
exfmt cstinq;
endsr; // end of subroutine InquirySub;
//****************************************************************
// SUBROUTINE - SetMaintenanceMode *
// PURPOSE - Set maintenance mode *
//****************************************************************
begsr SetMaintenanceMode;
if addKey;
mode = 'ADD';
elseif updateKey;
mode = 'UPDATE';
elseif deleteKey;
mode = 'DELETE';
elseif displayKey;
mode = 'DISPLAY';
endif;
endsr; // end of subroutine SetMaintenanceMode
/end-free
This program maintains a customer master file for additions, changes, and deletions. The program can also be used for inquiry.
The program first sets the default (display) mode of processing and displays the customer maintenance prompt screen. The workstation user can press F3, which turns on indicator 03, to request end of job. Otherwise, to work with customer information, the user enters a customer number and presses Enter. The user can change the mode of processing by pressing F5 (ADD), F6 (UPDATE), F7 (DELETE), or F8 (DISPLAY).
To add a new record to the file, the program uses the customer number as the search argument to chain to the master file. If the record does not exist in the file, the program displays the CSTBLD screen to allow the user to enter a new customer record. If the record is already in the file, an error message is displayed. The user can press F12, which sets on indicator 12, to cancel the add operation and release the record. Otherwise, to proceed with the add operation, the user enters information for the new customer record in the input fields and writes the new record to the master file.
To update, delete, or display an existing record, the program uses the customer number as the search argument to chain to the master file. If a record for that customer exists in the file, the program displays the customer file inquiry screen CSTINQ. If the record is not in the file, an error message is displayed. If the mode of processing is display or delete, the input fields are protected from modification. Otherwise, to proceed with the customer record, the user can enter new information in the customer record input fields. The user can press F12, which sets on indicator 12, to cancel the update or delete operation, and release the record. Display mode automatically releases the record when Enter is pressed.
In Figure 2, the workstation user responds to the prompt by entering customer number 00007 to display the customer record.
DISPLAY MODE
22:30:21 CUSTOMER FILE MAINTENANCE 9/30/94
00007 <--Enter Customer Number
F3 End Job F5 Add F6 Update F7 Delete F8 Display
Because the customer record for customer number 00007 exists in the Master File, the data is displayed as show in Figure 3.
DISPLAY MODE
22:31:06 CUSTOMER FILE MAINTENANCE 9/30/94
Customer: 00007
Mikhail Yuri
1001 Bay Street
Suite 1702
Livonia
MI 11201
F12 Cancel DISPLAY
The workstation user responds to the add prompt by entering a new customer number as shown in Figure 4.
ADD MODE
22:31:43 CUSTOMER FILE MAINTENANCE 9/30/94
00012 <--Enter Customer Number
F3 End Job F5 Add F6 Update F7 Delete F8 Display
In Figure 5 a new customer is added to the Customer Master File.
ADD MODE
22:32:04 CUSTOMER FILE MAINTENANCE 9/30/94
Customer: 00012
Name JUDAH GOULD
Address 2074 BATHURST AVENUE
Address
City YORKTOWN
State NY Zip 70068
F12 Cancel Addition
The workstation user responds to the delete prompt by entering a customer number as shown in Figure 6.
DELETE MODE
22:32:55 CUSTOMER FILE MAINTENANCE 9/30/94
00011 <--Enter Customer Number
F3 End Job F5 Add F6 Update F7 Delete F8 Display
The workstation user responds to the update prompt by entering a customer number as shown in Figure 7.
UPDATE MODE
22:33:17 CUSTOMER FILE MAINTENANCE 9/30/94
00010 <--Enter Customer Number
F3 End Job F5 Add F6 Update F7 Delete F8 Display