Skip to content

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:

  1. Initialization (Level 2 - L2):
  2. At the start of processing for each company (ATCO, Level 2 control break), the program:
    • Captures the current date and time using TIME and MOVELTIMDAT operations, storing them in TIMDAT, TIME, and DATE.
    • Resets the page number (PAGE) to zero.
    • Chains to the ARCONT file using ATCO to retrieve company details (e.g., ACNAME). If not found, sets indicator 99.
  3. Prints report headers, including company name, date, time, and column headings for the transaction edit report.

  4. Read and Process Transactions:

  5. Reads records from the sorted input file AR111S (300 bytes, 3-byte key).
  6. For each transaction record in ARTRAN (matched with AR111S via E AR111S ARTRAN), performs validations and calculations.
  7. If the record is marked as deleted (ATDEL = 'D'), it skips further processing.

  8. Validation Subroutines:

  9. Customer Validation:
    • Chains to ARCUST using the customer key (ATCOCU, company + customer number). If not found, sets indicator 21 and marks an error (*in29).
    • Compares salesman number (ATSLS) with the customer’s salesman (ARSLS#). If different, sets indicator 63.
  10. 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 against GLMAST. If the account is not found, deleted (GLDEL = 'D'), or inactive (GLDEL = 'I'), sets indicator 22 and marks an error (*in29).
    • Compares ATGLCR with the sales G/L account (ACSLGL) from ARCONT. If equal, sets indicator 60.
  11. 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 against GLMAST. If not found, deleted, or inactive, sets indicator 22 and marks an error (*in29).
    • Compares ATGLDR with the A/R G/L account (ACARGL) from ARCONT. If equal, sets indicator 61.
  12. 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 indicator 26 and marks an error (*in29).
  13. 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 indicators 27 and 29 (duplicate invoice error).
    • For adjustments (ATTYPE = 'J'), if the invoice does not exist, sets indicator 30 (invoice not found warning).
    • Validates transaction type. If not I or J, sets indicators 25 and 29 (invalid type error).
    • Checks if the transaction amount (ATAMT) is zero, setting indicator 73.
  14. Transaction Processing:

  15. 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.
  16. Adjustment Processing (ATTYPE = 'J'):
    • Validates that the type is J. If not I or J, sets error indicators 25 and 29 and skips to END.
  17. Updates the ARTRAN file with an error flag ('E') if any validation errors occur (*in29), otherwise clears the flag.

  18. Totals Calculation:

  19. 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).
  20. Adds transaction amount (ATAMT) to total A/R (TOTAR).
  21. Accumulates net change to A/R (NETCHG) by adding ATAMT.

  22. Report Generation:

  23. 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, or CREDIT), description (ATDESC), reference invoice (ATRFIV), G/L debit/credit accounts, terms, due date, and salesman.
  24. 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".
  25. 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).
  26. End of Processing:

  27. Updates the ARTRAN file with validated records, marking errors where applicable.
  28. Closes files and terminates.

Business Rules

The program enforces the following business rules for A/R transaction editing:

  1. Customer Validation:
  2. Customer number (ATCUST) combined with company (ATCO) must exist in ARCUST. If not, an error is reported.
  3. Salesman number (ATSLS) is compared with the customer’s salesman (ARSLS#) for consistency.

  4. G/L Account Validation:

  5. Credit G/L account (ATGLCR) and debit G/L account (ATGLDR) must exist in GLMAST and not be deleted (GLDEL = 'D') or inactive (GLDEL = 'I'). Invalid accounts trigger an error.
  6. 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.

  7. Terms Code Validation:

  8. Terms code (ATTERM) must exist in GSTABL under the ARTERM key. Invalid terms trigger an error.

  9. Transaction Type:

  10. Transaction type (ATTYPE) must be I (invoice) or J (adjustment). Invalid types trigger an error.
  11. Invoices require a non-zero amount (ATAMT).

  12. Invoice Validation:

  13. For invoices (I), the invoice must not already exist in ARDETL (duplicate check). If it exists and the amount is non-zero, an error is reported.
  14. For adjustments (J), the referenced invoice must exist in ARDETL. If not, a warning is issued.

  15. Error Handling:

  16. Errors (e.g., invalid customer, G/L account, terms, or duplicate invoice) set indicator 29, mark the ARTRAN record with 'E', and print an error message.
  17. Warnings (e.g., invoice not found for adjustments) are printed but do not mark the record as an error.

  18. Totals:

  19. Tracks total invoices (TOTINV), total A/R transactions (TOTAR), and net change to A/R (NETCHG).
  20. Prior and current month balances are calculated for A/R detail records.

  21. Reporting:

  22. Produces a detailed report with headers, transaction details, errors/warnings, and final totals.
  23. Errors and warnings are clearly marked with **** and descriptive messages.

Tables (Files) Used

The program interacts with the following files:

  1. AR111S (Input File, IR):
  2. Sorted A/R transaction file (300 bytes, 3-byte key).
  3. Provides input transactions for validation.

  4. ARTRAN (Update File, UP):

  5. A/R transaction file (256 bytes, 5-byte key at position 2).
  6. Stores transaction details (e.g., ATCO, ATCUST, ATINV#, ATAMT, ATDATE).
  7. Updated with error flags ('E') for invalid records.

  8. ARCUST (Input File, IC):

  9. Customer master file (384 bytes, 8-byte key at position 2).
  10. Contains customer data (e.g., ARNAME, ARSLS#, ARTERM).

  11. ARDETL (Input File, IC):

  12. A/R detail file (128 bytes, 18-byte key at position 2).
  13. Stores detailed A/R records (e.g., ADAMT, ADDUDT, ADTERM, ADINV#).

  14. GLMAST (Input File, IC):

  15. General ledger master file (256 bytes, 11-byte key at position 2).
  16. Contains G/L account details (e.g., GLDEL).

  17. ARCONT (Input File, IC):

  18. A/R control file (256 bytes, 2-byte key at position 2).
  19. Stores company details (e.g., ACNAME, ACARGL, ACSLGL, ACCSGL).

  20. GSTABL (Input File, IC):

  21. General system table (256 bytes, 12-byte key at position 2).
  22. Contains terms data (e.g., TERMSD).

  23. PRINT (Output File, O):

  24. Printer file (164 bytes).
  25. 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.