AR9009 RPG36
The provided document is an RPG/36 program named AR9009.rpg36.txt
, called from the main OCL script AR900.ocl36.txt
to verify whether a customer has activity (e.g., invoices or sales) before allowing deletion in the Customer Master File Maintenance process (AR900
) on an IBM midrange system (likely System/36 or AS/400, now IBM i). Below, I explain the process steps, business rules, tables used, and external programs called by this RPG program.
Process Steps of the RPG Program¶
The AR9009
program checks for customer activity in specific files to determine if a customer can be deleted. It is invoked from AR900
to ensure that customers with active records (e.g., open invoices or sales) are not deleted. The program processes input parameters, checks multiple files for matching records, and returns a flag indicating whether activity was found.
- Program Entry and Parameter Handling:
- Purpose: Receives input parameters to identify the customer and control the verification process.
-
Steps:
- Defines a parameter list (
*ENTRY PLIST
) with: ARKEY
(8 bytes): Key combining company and customer number (e.g.,COCUST
).BCINST
(1 byte): Billing instruction code, used to determine if sales files should be checked.FOUND
(1 byte): Output parameter set to indicate whether activity was found ('A'
for invoices,'S'
for sales, or blank if no activity).- Calls the
EACH
subroutine to perform the activity check. - Sets the Last Record indicator (
LR
) and exits via theOUT
tag.
- Defines a parameter list (
-
EACH Subroutine:
- Purpose: Checks for customer activity in invoice and sales files.
- Steps:
- Invoice File Check (
CRDETX
): - Moves
ARKEY
to a 23-byte key (KEY21
) for positioning inCRDETX
(invoice detail file). - Uses
SETLL
to position the file pointer at the first record matchingKEY21
. - Reads
CRDETX
records in a loop (RDAGN
tag) until end-of-file (indicator10
). - For each record:
- Skips deleted records (
ADDEL = 'D'
). - Compares the record’s key (
ARDKEY
) withARKEY
. If they match and the record is not deleted, setsFOUND = 'A'
(indicating the customer has invoices) and exits toENDDEL
.
- Skips deleted records (
- Sales File Checks (Conditional on
BCINST = '5'
): - If
BCINST = '5'
, checks multiple sales files for activity:SA5FIXD
andSA5FIXM
(fixed sales data, perLT02
).SA5BCXD
andSA5BCXM
(billing-related sales data, perJB03
).SA5DBXD
andSA5DBXM
(distribution-related sales data, perJB03
).SA5COXD
andSA5COXM
(customer order-related sales data, perJB03
).
- For each file:
- Moves
ARKEY
to a 39-byte key (SAKEY
) for positioning. - Uses
SETLL
to position the file pointer. - Reads the file and checks if the record’s key (
SACOCU
) matchesARKEY
. - If a match is found, sets
FOUND = 'S'
(indicating the customer has sales activity) and exits toENDDEL
.
- Moves
- Termination:
- If no activity is found,
FOUND
remains blank. - Exits via
ENDDEL
, closes files, and terminates the program.
- Invoice File Check (
Business Rules¶
The program enforces the following business rules to ensure accurate verification of customer activity before deletion:
- Invoice Activity Check:
- A customer cannot be deleted if they have active (non-deleted,
ADDEL ≠ 'D'
) invoices inCRDETX
. -
If a matching invoice record is found,
FOUND
is set to'A'
, signaling that deletion is not allowed. -
Sales Activity Check:
- Sales activity is checked only if the billing instruction code (
BCINST
) is'5'
. - The program checks multiple sales files (
SA5FIXD
,SA5FIXM
,SA5BCXD
,SA5BCXM
,SA5DBXD
,SA5DBXM
,SA5COXD
,SA5COXM
) for records matching the customer key (SACOCU = ARKEY
). -
If a matching record is found in any of these files,
FOUND
is set to'S'
, indicating that deletion is not allowed due to sales activity. -
Key Matching:
- The customer key (
ARKEY
) combines company and customer number and is used to match records in both invoice and sales files. -
Only non-deleted invoice records (
ADDEL ≠ 'D'
) are considered for activity checks. -
Sequential File Checking:
- The program checks
CRDETX
first for invoices. If no activity is found, it proceeds to check sales files (ifBCINST = '5'
). -
Sales files are checked in pairs (e.g.,
SA5FIXD
andSA5FIXM
), reflecting different data structures or indexes (perLT02
andJB03
revisions). -
Output:
- The
FOUND
parameter is set to:'A'
if invoice activity is found.'S'
if sales activity is found.- Blank if no activity is found, indicating the customer may be eligible for deletion.
Tables (Files) Used¶
The program uses the following files, as defined in the File Specification (F
) section:
- CRDETX (
IF
, Input, 128 bytes, Key at position 2, Logical File): - Invoice detail file used to check for customer invoices.
-
Fields:
ADDEL
(1 byte): Delete code (D
for deleted).ARDKEY
(8 bytes): Key combining company and customer number.
-
SA5FIXD (
IF
, Input, 1024 bytes, Key at position 2, Logical File, perLT02
): - Sales file (fixed data, detail) for checking customer sales activity.
-
Field:
SACOCU
(8 bytes): Key combining company and customer number. -
SA5FIXM (
IF
, Input, 1024 bytes, Key at position 2, Logical File, perLT02
): - Sales file (fixed data, master) for checking customer sales activity.
-
Field:
SACOCU
(8 bytes): Key combining company and customer number. -
SA5BCXD (
IF
, Input, 1024 bytes, Key at position 2, Logical File, perJB03
): - Billing-related sales file (detail) for checking customer sales activity.
-
Field:
SACOCU
(8 bytes): Key combining company and customer number. -
SA5BCXM (
IF
, Input, 1024 bytes, Key at position 2, Logical File, perJB03
): - Billing-related sales file (master) for checking customer sales activity.
-
Field:
SACOCU
(8 bytes): Key combining company and customer number. -
SA5DBXD (
IF
, Input, 1024 bytes, Key at position 2, Logical File, perJB03
): - Distribution-related sales file (detail) for checking customer sales activity.
-
Field:
SACOCU
(8 bytes): Key combining company and customer number. -
SA5DBXM (
IF
, Input, 1024 bytes, Key at position 2, Logical File, perJB03
): - Distribution-related sales file (master) for checking customer sales activity.
-
Field:
SACOCU
(8 bytes): Key combining company and customer number. -
SA5COXD (
IF
, Input, 1024 bytes, Key at position 2, Logical File, perJB03
): - Customer order-related sales file (detail) for checking customer sales activity.
-
Field:
SACOCU
(8 bytes): Key combining company and customer number. -
SA5COXM (
IF
, Input, 1024 bytes, Key at position 2, Logical File, perJB03
): - Customer order-related sales file (master) for checking customer sales activity.
- Field:
SACOCU
(8 bytes): Key combining company and customer number.
External Programs Called¶
The AR9009
program does not call any external programs. It performs direct file operations on CRDETX
and the sales files (SA5FIXD
, SA5FIXM
, SA5BCXD
, SA5BCXM
, SA5DBXD
, SA5DBXM
, SA5COXD
, SA5COXM
) to check for customer activity.
Summary¶
- Process Steps: Receives parameters (
ARKEY
,BCINST
,FOUND
), checksCRDETX
for invoice activity, and, ifBCINST = '5'
, checks multiple sales files (SA5FIXD
,SA5FIXM
,SA5BCXD
,SA5BCXM
,SA5DBXD
,SA5DBXM
,SA5COXD
,SA5COXM
) for sales activity. SetsFOUND
to'A'
(invoices),'S'
(sales), or blank (no activity). - Business Rules: Prevents deletion if the customer has active invoices or sales (when
BCINST = '5'
); skips deleted invoice records; checks multiple sales files for comprehensive activity verification. - Tables Used:
CRDETX
(invoices),SA5FIXD
,SA5FIXM
,SA5BCXD
,SA5BCXM
,SA5DBXD
,SA5DBXM
,SA5COXD
,SA5COXM
(sales data). - External Programs Called: None.
This RPG/36 program is a critical validation step in the customer deletion process, ensuring that customers with active invoices or sales are not deleted, maintaining data integrity in the customer master maintenance system. If you need further details on specific logic or file structures, let me know!