AR111 RPG36
The provided document, AR111.rpg36.txt
, is an RPG II program for the IBM System/36 environment, called from the main OCL program (AR101.ocl36.txt
) to edit and validate Accounts Receivable (A/R) transactions. It processes sorted transactions from the AR111S
file, validates them against various master files, and produces a printed report detailing the results, including errors and totals. Below, I will explain the process steps, business rules, tables (files) used, and any external programs called.
Process Steps of the AR111 RPG Program¶
The AR111
program validates A/R transactions (invoices and adjustments) and generates a report to highlight valid transactions, errors, and totals. It operates in a batch mode, reading from the sorted transaction file AR111S
and updating the ARTRAN
file. Here’s a step-by-step breakdown of the process:
- Initialization (Level 2 - L2):
- At the start of processing for each company (
ATCO
, Level 2 control break), the program:- Captures the current date and time using
TIME
andMOVELTIMDAT
operations, storing them inTIMDAT
,TIME
, andDATE
. - Resets the page number (
PAGE
) to zero. - Chains to the
ARCONT
file usingATCO
to retrieve company details (e.g.,ACNAME
). If not found, sets indicator99
.
- Captures the current date and time using
-
Prints report headers, including company name, date, time, and column headings for the transaction edit report.
-
Read and Process Transactions:
- Reads records from the sorted input file
AR111S
(300 bytes, 3-byte key). - For each transaction record in
ARTRAN
(matched withAR111S
viaE AR111S ARTRAN
), performs validations and calculations. -
If the record is marked as deleted (
ATDEL = 'D'
), it skips further processing. -
Validation Subroutines:
- Customer Validation:
- Chains to
ARCUST
using the customer key (ATCOCU
, company + customer number). If not found, sets indicator21
and marks an error (*in29
). - Compares salesman number (
ATSLS
) with the customer’s salesman (ARSLS#
). If different, sets indicator63
.
- Chains to
- Credit G/L Account Validation:
- If the credit G/L account (
ATGLCR
) is non-zero, constructs a G/L key (ATGL
) using the credit company (ATCOCR
) and account number. - Calls the
GETGL
subroutine to validate againstGLMAST
. If the account is not found, deleted (GLDEL = 'D'
), or inactive (GLDEL = 'I'
), sets indicator22
and marks an error (*in29
). - Compares
ATGLCR
with the sales G/L account (ACSLGL
) fromARCONT
. If equal, sets indicator60
.
- If the credit G/L account (
- Debit G/L Account Validation:
- If the debit G/L account (
ATGLDR
) is non-zero, constructs a G/L key using the debit company (ATCODR
) and account number. - Calls
GETGL
to validate againstGLMAST
. If not found, deleted, or inactive, sets indicator22
and marks an error (*in29
). - Compares
ATGLDR
with the A/R G/L account (ACARGL
) fromARCONT
. If equal, sets indicator61
.
- If the debit G/L account (
- Terms Code Validation:
- If the terms code (
ATTERM
) is non-zero, constructs a key (TRMKEY
) using'ARTERM'
and the terms code. - Chains to
GSTABL
. If not found, sets indicator26
and marks an error (*in29
).
- If the terms code (
-
Invoice/Adjustment Validation:
- Builds an A/R detail key (
KEY18
) using company, customer, invoice number (ATINV#
), and type ('I00'
for invoices). - Chains to
ARDETL
. If found, calculates the invoice date (INVDAT
) and checks the transaction type: - For invoices (
ATTYPE = 'I'
), if the invoice exists and the amount is non-zero, sets indicators27
and29
(duplicate invoice error). - For adjustments (
ATTYPE = 'J'
), if the invoice does not exist, sets indicator30
(invoice not found warning). - Validates transaction type. If not
I
orJ
, sets indicators25
and29
(invalid type error). - Checks if the transaction amount (
ATAMT
) is zero, setting indicator73
.
- Builds an A/R detail key (
-
Transaction Processing:
- Invoice Processing (
ATTYPE = 'I'
):- If the transaction is an invoice and no errors exist (
*in27
off), processes it as valid. - If errors exist, skips to the
END
tag.
- If the transaction is an invoice and no errors exist (
- Adjustment Processing (
ATTYPE = 'J'
):- Validates that the type is
J
. If notI
orJ
, sets error indicators25
and29
and skips toEND
.
- Validates that the type is
-
Updates the
ARTRAN
file with an error flag ('E'
) if any validation errors occur (*in29
), otherwise clears the flag. -
Totals Calculation:
- For A/R detail records (
*in34
on):- Calculates prior month balance (
ADAMT - ADPART
). - Calculates current month balance (
ARLEFT = ADAMT - ADPAY
). - Adds
ARLEFT
to total invoices (TOTINV
).
- Calculates prior month balance (
- Adds transaction amount (
ATAMT
) to total A/R (TOTAR
). -
Accumulates net change to A/R (
NETCHG
) by addingATAMT
. -
Report Generation:
- Prints transaction details for each record, including:
- Sequence number (
ATKEY
), customer number (ATCUST
), customer name (ARNAME
), invoice number (ATINV#
), invoice amount (ARLEFT
), invoice date (INVDAT
), transaction amount (ATAMT
), transaction date (ATDATE
), type (INVOICE
,ADJUST
, orCREDIT
), description (ATDESC
), reference invoice (ATRFIV
), G/L debit/credit accounts, terms, due date, and salesman.
- Sequence number (
- Prints error messages for specific conditions:
- Customer not found (
*in21
): "CUSTOMER REC. NOT FOUND". - G/L account not found/deleted/inactive (
*in22
): "GL ACCOUNT NOT FOUND". - Duplicate invoice (
*in27
): "DUPLICATE INVOICE". - Invoice not found for adjustment (
*in30
): "INVOICE REC. NOT FOUND". - Invalid transaction type (
*in25
): "INVALID TRANS TYPE". - Invalid terms code (
*in26
): "INVALID TERMS CODE".
- Customer not found (
-
At the end of processing (
LR
indicator), prints totals:- Total invoices (
TOTINV
) for invoices only (*in33
off). - Total A/R transactions (
TOTAR
). - Net change to A/R (
NETCHG
).
- Total invoices (
-
End of Processing:
- Updates the
ARTRAN
file with validated records, marking errors where applicable. - Closes files and terminates.
Business Rules¶
The program enforces the following business rules for A/R transaction editing:
- Customer Validation:
- Customer number (
ATCUST
) combined with company (ATCO
) must exist inARCUST
. If not, an error is reported. -
Salesman number (
ATSLS
) is compared with the customer’s salesman (ARSLS#
) for consistency. -
G/L Account Validation:
- Credit G/L account (
ATGLCR
) and debit G/L account (ATGLDR
) must exist inGLMAST
and not be deleted (GLDEL = 'D'
) or inactive (GLDEL = 'I'
). Invalid accounts trigger an error. -
Credit account is compared with the sales G/L account (
ACSLGL
), and debit account with the A/R G/L account (ACARGL
) for default validation. -
Terms Code Validation:
-
Terms code (
ATTERM
) must exist inGSTABL
under theARTERM
key. Invalid terms trigger an error. -
Transaction Type:
- Transaction type (
ATTYPE
) must beI
(invoice) orJ
(adjustment). Invalid types trigger an error. -
Invoices require a non-zero amount (
ATAMT
). -
Invoice Validation:
- For invoices (
I
), the invoice must not already exist inARDETL
(duplicate check). If it exists and the amount is non-zero, an error is reported. -
For adjustments (
J
), the referenced invoice must exist inARDETL
. If not, a warning is issued. -
Error Handling:
- Errors (e.g., invalid customer, G/L account, terms, or duplicate invoice) set indicator
29
, mark theARTRAN
record with'E'
, and print an error message. -
Warnings (e.g., invoice not found for adjustments) are printed but do not mark the record as an error.
-
Totals:
- Tracks total invoices (
TOTINV
), total A/R transactions (TOTAR
), and net change to A/R (NETCHG
). -
Prior and current month balances are calculated for A/R detail records.
-
Reporting:
- Produces a detailed report with headers, transaction details, errors/warnings, and final totals.
- Errors and warnings are clearly marked with
****
and descriptive messages.
Tables (Files) Used¶
The program interacts with the following files:
- AR111S (Input File,
IR
): - Sorted A/R transaction file (300 bytes, 3-byte key).
-
Provides input transactions for validation.
-
ARTRAN (Update File,
UP
): - A/R transaction file (256 bytes, 5-byte key at position 2).
- Stores transaction details (e.g.,
ATCO
,ATCUST
,ATINV#
,ATAMT
,ATDATE
). -
Updated with error flags (
'E'
) for invalid records. -
ARCUST (Input File,
IC
): - Customer master file (384 bytes, 8-byte key at position 2).
-
Contains customer data (e.g.,
ARNAME
,ARSLS#
,ARTERM
). -
ARDETL (Input File,
IC
): - A/R detail file (128 bytes, 18-byte key at position 2).
-
Stores detailed A/R records (e.g.,
ADAMT
,ADDUDT
,ADTERM
,ADINV#
). -
GLMAST (Input File,
IC
): - General ledger master file (256 bytes, 11-byte key at position 2).
-
Contains G/L account details (e.g.,
GLDEL
). -
ARCONT (Input File,
IC
): - A/R control file (256 bytes, 2-byte key at position 2).
-
Stores company details (e.g.,
ACNAME
,ACARGL
,ACSLGL
,ACCSGL
). -
GSTABL (Input File,
IC
): - General system table (256 bytes, 12-byte key at position 2).
-
Contains terms data (e.g.,
TERMSD
). -
PRINT (Output File,
O
): - Printer file (164 bytes).
- Generates the transaction edit report.
External Programs Called¶
The AR111
RPG program does not explicitly call any external programs. All processing is handled within the program, primarily through the GETGL
subroutine for G/L account validation.
Summary¶
The AR111
RPG program, called from the main OCL program, validates sorted A/R transactions from AR111S
, ensuring compliance with business rules for customers, G/L accounts, terms, and invoice/adjustment data. It updates the ARTRAN
file with error flags for invalid records and produces a detailed printed report listing transactions, errors, warnings, and totals. The program uses eight files (AR111S
, ARTRAN
, ARCUST
, ARDETL
, GLMAST
, ARCONT
, GSTABL
, PRINT
) and relies on the GETGL
subroutine for G/L validation. No external programs are called, and the program enforces strict validation to maintain A/R data integrity.