Skip to content

AR105 RPG36

The AR105.rpg36.txt program is an RPG II program (with System/36 syntax) designed for editing and validating payment statement entries in an accounts receivable (AR) system. It is invoked by the AR105.ocl36 OCL script, which prepares the environment by ensuring input files (CRWKGG, CRCKGG) are present and creating the output transaction file (CRPSGG). The program processes payment and unapplied cash transactions from payment statements entered via AR050, validates them against master files, and generates transaction records for further processing by AR110 (for payments) and AR111 (for adjustments, though adjustments are disabled per AR050.rpgle notes). Below, I outline the process steps, business rules, tables (files) used, and external programs called, based on the provided code and context from related documents.

Process Steps of the AR105 RPG Program

  1. Initialization (ONCE Block):
  2. Condition: Executes only once (ONCE IFEQ 0, lines 0062–0067).
  3. Actions:
    • Initializes fields: SEQ (sequence number), ZERO7 (7-digit zero), ZERO9 (9-digit zero), Z8 (8-digit zero), Z7 (7-digit zero) to zero.
    • Increments ONCE to 1 to prevent re-execution.
  4. Purpose: Sets up counters and default values for transaction processing.

  5. Read Check File (CRCHKS):

  6. Reads CRCHKS (check work file, primary input, IP) sequentially, processing each check record (CRDEL, CRCO, CRCUST, CRCKNO, CRCKAM, CRDSAM, CRPYDT, CRAPPL, CRGRSS, CRFCAM, CRPYD8).
  7. Uses level break L2 on company number (CRCO) to group checks by company.

  8. Validate Company:

  9. Chains to ARCONT using CRCO (line 0069).
  10. If not found (*in90 = *on), skips further processing for the check.
  11. Retrieves company data: name (ACNAME), AR GL (ACARGL), discount GL (ACDSGL), cash GL (ACCSGL), finance GL (ACFNGL).

  12. Process Invoices for Each Check (L1 Loop):

  13. Loop Control: For each check (L1 on CRCUST, customer number), processes related invoices from CRWORK (line 0071).
  14. Initialize Unapplied Amount: Sets L2UNAP (unapplied amount for company) to zero (line 0072).
  15. Customer Validation:
    • Constructs CUSTKY (company + customer) from AWCO and AWCUST (lines 0073–0074).
    • Chains to ARCUST using CUSTKY (line 0075).
    • If found (*in93 = *off), retrieves salesman number (ARSLS) into SLS (line 0076).
  16. Read Invoice Records:

    • Chains to CRWORK using CRCOCS (company + customer) to find matching invoices (line 0080).
    • For each invoice (AWDEL, AWCO, AWCUST, AWDUDT, AWINV#, AWAMDU, AWAMPD, AWPAID, AWPDDT, AWCKAM, AWDSAM, AWCKNO, AWGLNO, AWDUD8, AWPDD8, AWNOD):
    • Verifies check number match (AWCKNO = CRCKNO, line 0081).
    • Checks payment code (AWPAID = 'P', line 0082) for payment transactions (adjustments 'J' are disabled per AR050).
  17. Invoice Validation:

  18. Chains to ARDETL using AWCOCS and AWINV# (line 0084).
  19. If found (*in91 = *off), retrieves invoice details: salesman (ADSLS), due date (ADDUDT), terms (ADTERM).
  20. If invoice is deleted or not found, marks the transaction with an error ('E' in position 54 of CRTRAN, line 0088).

  21. GL Account Assignment:

  22. Credit GL:
    • If override GL (AWGLNO) is non-zero, uses it (CRGL = AWGLNO, lines 0179–0180).
    • Otherwise, defaults to local data area credit GL (LDCRGL, line 0182).
  23. Debit GL: Uses local data area debit GL (LDDRGL, line 0185).
  24. Discount GL: Uses ACDSGL from ARCONT (implied, line 0222).

  25. Generate Payment Transaction (ARPAY):

  26. For valid invoices with AWPAID = 'P':

    • Sets transaction type (TYPE = 'P', implied).
    • Increments sequence number (SEQ += 10, line 0188).
    • Sets payment amount (PAY$ = AWAMPD, line 0189).
    • Writes to CRTRAN using ARPAY exception (lines 0204–0227):
    • Fields: 'A' (active), SEQ, AWCO, AWCUST, AWINV#, PAY$, DSAM (discount), TYPE, AWPDDT, CRGL, DRGL, AWCKNO, DUDT, TERM, SLS, ZERO9, AWCO, DISCGL, AWCO, AWCO, AWPDD8, AWDUD8, AWNOD.
  27. Handle Unapplied Cash (ARUNAP):

  28. If unapplied amount exists (L2UNAP > 0, line 0198):

    • Increments SEQ (line 0199).
    • Writes to CRTRAN using ARUNAP exception (lines 0228–0250):
    • Fields: 'A', SEQ, CRCO, CRCUST, '9999999' (dummy invoice), L2UNAP, ZERO7, 'P', CRPYDT, ACARGL, ACCSGL, CRCKNO, CRPYDT, TERM, SLS, ZERO9, CRCO, Z8, CRCO, CRCO, CRPYD8, CRPYD8, ' '.
    • Represents cash not applied to specific invoices.
  29. Handle Finance Charges (UPDFC):

  30. If foreign currency amount exists (CRFCAM > 0, line 0164):

    • Writes to CRTRAN using UPDFC exception (lines 0252–0276):
    • Fields: 'A', SEQ, CRCO, CRCUST, Z7 (zero invoice), CRFCAM, ZERO7, 'P', CRPYDT, ACFNGL, ACCSGL, 'FIN CHG', ' ', CRCUST, CRPYDT, TERM, SLS, ZERO9, CRCO, Z8, CRCO, CRCO, CRPYD8, CRPYD8, ' '.
    • Records finance charges separately.
  31. Loop and Termination:

    • Continues processing invoices (GOTO AGAIN, line 0194) until all records for the check are processed (ENDDET, line 0196).
    • At customer or company break (L1, L2), processes unapplied amounts if any.
    • Terminates after all checks are processed, closing files.

Business Rules

  1. Transaction Validation:
  2. Checks must exist in CRCHKS and not be deleted (CRDEL <> 'D').
  3. Invoices must exist in ARDETL and not be deleted (ADDEL <> 'D'); otherwise, transactions are marked with 'E' in CRTRAN.
  4. Customers must exist in ARCUST (via CUSTKY).

  5. Payment Processing:

  6. Only processes payment transactions (AWPAID = 'P'). Adjustments ('J') are disabled per AR050.rpgle (March 2024 note).
  7. Payment amount (AWAMPD) must match invoice data; discount (AWDSAM) is validated against ARDETL.
  8. Notification of difference (AWNOD) must be 'Y' or blank.

  9. Unapplied Cash:

  10. If check amount (CRCKAM) exceeds applied amounts (AWAMPD), the remainder (L2UNAP) is recorded as unapplied cash with a dummy invoice number ('9999999').
  11. Uses default GL accounts (ACARGL, ACCSGL) for unapplied transactions.

  12. Finance Charges:

  13. Foreign currency amounts (CRFCAM) are recorded as separate transactions with finance GL (ACFNGL) and description 'FIN CHG'.

  14. GL Account Assignment:

  15. Override GL (AWGLNO) takes precedence; otherwise, defaults to LDCRGL (credit) and LDDRGL (debit) from the local data area.
  16. Discount GL uses ACDSGL from ARCONT.

  17. Sequence Numbering:

  18. Transactions are assigned unique sequence numbers (SEQ), incremented by 10 for each record.

  19. Atrium Compatibility:

  20. Uses GG suffix for files (CRWKGG, CRCKGG, CRPSGG) per JB01 (11/28/23) for Atrium environment.

  21. Multi-User Support:

  22. Master files (ARCONT, ARDETL, ARCUST) are shared (DISP-SHR in OCL), allowing concurrent access.

Tables (Files) Used

  1. CRCHKS:
  2. Type: Input primary file (IP), disk-based.
  3. Record Length: 96 bytes.
  4. Key: 14-byte key (positions 2-15, likely company + customer + check).
  5. Usage: Check data (e.g., CRCO, CRCUST, CRCKNO, CRCKAM, CRDSAM, CRPYDT).

  6. CRWORK:

  7. Type: Input file (IF), disk-based.
  8. Record Length: 96 bytes.
  9. Key: 21-byte logical key (company + customer + invoice).
  10. Usage: Invoice data (e.g., AWCO, AWCUST, AWINV#, AWAMPD, AWDSAM, AWCKNO, AWNOD).

  11. ARCONT:

  12. Type: Input file (IC), disk-based.
  13. Record Length: 256 bytes.
  14. Key: 2-byte company key.
  15. Usage: Company data and default GL accounts (ACNAME, ACARGL, ACCSGL, ACDSGL, ACFNGL).

  16. ARDETL:

  17. Type: Input file (IC), disk-based.
  18. Record Length: 128 bytes.
  19. Key: 18-byte key (company + customer + invoice).
  20. Usage: Validates invoice details (e.g., ADSLS, ADDUDT, ADTERM).

  21. CRTRAN:

  22. Type: Output file (O), disk-based.
  23. Record Length: 2560 bytes (likely a typo; should be 256 bytes per OCL).
  24. Key: 5-byte sequence key.
  25. Usage: Stores validated transactions (ARPAY, ARUNAP, UPDFC).

  26. ARCUST:

  27. Type: Input file (IC), disk-based.
  28. Record Length: 384 bytes.
  29. Key: 8-byte customer key.
  30. Usage: Validates customer data (e.g., ARSLS, ARTERM).

External Programs Called

The AR105 program does not explicitly call external programs within the provided code. It operates as a standalone validation program, relying on the AR105.ocl36 script for environment setup (e.g., GSY2K, #GSORT). The output file CRTRAN (CRPSGG) is processed by subsequent programs (AR110, AR111) as defined in the OCL script, but no direct calls are made from AR105.

Summary

The AR105 program validates payment statement entries from AR050 by: - Processing checks (CRCHKS) and invoices (CRWORK), validating against ARCUST, ARDETL, and ARCONT. - Generating payment (ARPAY), unapplied cash (ARUNAP), and finance charge (UPDFC) transactions in CRTRAN. - Assigning GL accounts (override or default) and handling notifications of difference (AWNOD). - Supporting Atrium with GG suffixes and multi-user access via shared files.

It enforces strict validation rules, ensures unapplied cash and finance charges are recorded, and prepares transactions for further validation by AR110 and AR111. The program integrates seamlessly with the OCL workflow, focusing on data integrity before posting.