Skip to content

AR135 RPGLE

Process Steps of the AR135 RPG Program

The AR135 RPG program is an interactive screen-based application for entering and managing Accounts Receivable (AR) cash receipts, specifically tailored for Electronic Funds Transfer (EFT) draft automation. It uses a workstation file (AR135FM) for user interaction across multiple screens (S1, S2, S3, S4) and processes data against various database files. The program supports entry mode (add new records) and update mode (edit existing records), with validation, cross-referencing, and totals calculation.

The code is a mix of original System/36-style RPG and converted ILE RPGLE (via TARGET/400 tool, dated 09/23/23), using fixed-format with modern enhancements like EVAL and EXSR. Here's a step-by-step breakdown of the main process flow, based on the program's structure:

  1. Program Initialization (*INZSR Subroutine):
  2. Clears key fields: Company (CO), Customer (CUST), Invoice (INV#), and Customer Address (AXCUST).
  3. Sets up initial state for entry, ensuring blanks or zeros for new transactions.

  4. Read Workstation Input (Main Loop):

  5. Checks the control field (QSCTL): If blank, sets it to 'R' (read mode) and turns on indicator *IN09 (initial display).
  6. Reads the appropriate screen based on indicators:
    • *IN81: Reads AR135S1 (header/search screen).
    • *IN82: Reads AR135S2 (detail entry screen).
    • *IN83: Reads AR135S3 (totals screen).
    • *IN84: Reads AR135S4 (cross-reference/address screen).
  7. If last record (LR), returns to caller.
  8. Resets error indicators (*IN90, *IN91) and screen indicators (*IN81-*IN84).
  9. Clears display fields like company name (COMP NM), customer name (CUSTNM), descriptions, and messages.

  10. Handle Function Keys and Mode Switches:

  11. Exit (F3, *IN03): Switches to update mode (*IN11 on, *IN10 off) and redisplays S1.
  12. Initial Entry (F9, *IN09): Sets company from DSCSCO (default company), switches to update mode, and redisplays S1.
  13. Update Mode Toggle (F4, *INKA): Switches from entry to update mode and redisplays S1.
  14. Totals Calculation (F11, *INKB): Calls TOTALS subroutine to compute totals, then redisplays S3.
  15. Exit Program (F23, *INKG): Sets *INLR = *ON to end the program.
  16. Read Transaction (F12, *INKJ): Calls RDTRAN subroutine to read from CRTRAN, then switches to entry mode and displays S2.
  17. Add New (F24, *INKK): Resets sequence to 0, switches to update mode, and displays S1.

  18. Screen S1 Processing (Enter on S1, *IN01 and *IN11):

  19. Calls S1 subroutine to validate and process header data (company, customer, invoice, etc.).
  20. If successful, redisplays S1.

  21. Screen S2 Processing (Enter on S2, *IN02 and *IN10 for Add):

  22. Calls S2ADD subroutine to add a new transaction record to CRTRAN.
  23. Writes the record using EADD (effective add with key) or E (update).

  24. Screen S2 Update (Enter on S2, *IN02 and *IN11 for Update):

  25. Calls S2UPD subroutine to update an existing transaction in CRTRAN.

  26. Cross-Reference/Address Processing (S4, *IN84):

  27. Calls CSR (Cross-Reference Subroutine) to build address lines from customer data.
  28. Calls S4 subroutine to handle customer search and validation.
  29. If search yields no results, displays error and allows re-entry.

  30. Date Validation (DTEDIT Subroutine):

  31. Validates input date (DATE) in MMDDYY format.
  32. Breaks down into month/day/year, checks for valid month (1-12), day (accounting for leap years using Y2K logic).
  33. Handles leap year: Divides year by 4 (or by 400 for century years using Y2KCMP and Y2KCEN).
  34. Sets *IN79 on error; otherwise, proceeds.

  35. Transaction Read (RDTRAN Subroutine):

  36. Reads from CRTRAN using key (company, customer, sequence).
  37. Handles duplicate keys by redefining fields as alphanumeric for comparison.
  38. Loads data into screen fields.

  39. Output and Display:

    • Displays screens with messages (e.g., "Sequence Not Found", "Invalid Date").
    • S3 shows running totals (TOTAMT, TOTDIS, TOTMIS).
    • S4 populates address lines (CSAR array).
  40. End of Program:

    • On *INLR, returns control to the calling OCL program.

The program loops through reads and writes until exit, with subroutines handling most logic for modularity.


Business Rules

The program enforces several business rules for data integrity, validation, and EFT/cash receipts processing. These are derived from field validations, indicators, and subroutines:

  1. Mode Switching:
  2. Starts in entry mode (*IN10 on) for adding new receipts; toggles to update mode (*IN11 on) via F3/F4/F9/F24.
  3. Prevents adding if sequence exists (error: "Seq No Is Already Used, CMD 10 To Add").

  4. Key Field Validation:

  5. Company (CO): Must be valid (error if invalid: "Invalid Company Number").
  6. Customer (CUST): Must exist in ARCUST/ARCUSTX; cross-references name/abbreviation (error: "Invalid Customer Number", "Name Search Data - Not Found").
  7. Invoice (INV#): Cannot be blank for non-misc cash (error: "Invoice Number May Not Be Blank").
  8. Sequence (SEQ): Auto-increments; cannot reuse existing (checks CRTRAN for duplicates).

  9. Transaction Rules:

  10. Type (TYPE): 'P' for cash receipts/misc cash; misc cash cannot have discount (DISC > 0 triggers error: "Misc Cash cannot have Discount Amount").
  11. Amount (AMT): Must be > 0 (error: "Invalid Amount, Must Not Be = To Zero").
  12. Discount (DISC): Valid only for non-misc; links to discount G/L (GLDI).
  13. G/L Accounts: Debit (GLDR), Credit (GLCR), Discount (GLDI) must exist in GLMAST (errors for invalid accounts).
  14. Intercompany: Credit/Debit companies (COCR, CODR) must be valid.
  15. Notification of Difference (NOD): Must be blank or 'Y' (error otherwise).

  16. Date Handling:

  17. Transaction Date (DATE), Due Date (DUDT): MMDDYY format; validated for month/day/leap year (using Y2K century/month params).
  18. Error on invalid dates (e.g., Feb 30, non-leap Feb 29).

  19. Customer and Address:

  20. Searches ARCUSTX by name abbreviation; builds 11-line address array (CSAR).
  21. Salesman (SLSM) from ARCUST.
  22. Terms (TERM) and due date from ARDETL.

  23. Financial Rules:

  24. Totals: Calculates total amount (TOTAMT), discount (TOTDIS), misc (TOTMIS) from detail lines.
  25. AR Detail Update: Applies payments to ARDETL (partial ADPART, current month ADPAY).
  26. Deletion: Marks records with 'D' in ATDEL; prevents processing deleted sequences (error: "This Sequence Was Previously Deleted" or "Record Marked For Deletion").

  27. Error Handling and Messages:

  28. Uses 28 predefined messages (e.g., "Press Enter To Add/Update", "Record Activated").
  29. Displays on screens; requires user acknowledgment.

  30. EFT-Specific:

  31. Designed for EFT draft automation (per comments); handles individual entries with intercompany transfers and G/L postings.

These rules ensure accurate AR postings, prevent duplicates/errors, and comply with financial standards.


Tables/Files Used

The program uses the following physical and logical files (all IBM i-style DDS definitions, with keys and usage):

File Name Type Record Length Key Location Usage/Description
AR135FM Display File (CF) 900 N/A Workstation SFL for screens S1-S4 (header, detail, totals, address).
CRTRAN Update File (UF A) 256 2 (Company, Customer, Invoice?) EFT transaction workfile; stores receipts (amount, disc, type, date, G/L, desc).
CRTRANR Input File (IF) 256 2 Reference transaction file (for reads/comparisons; includes old seq, misc amounts).
ARCUST Input File (IF) 384 2 Customer master; name, salesman (ARSLS#).
ARCUSTX Input File (IF) 384 1 Customer index/extension; address lines (AXADR1/2), name abbr (CXNM).
ARCONT Input File (IF) 256 2 AR control; company name (ACNAME), G/L accounts (AR ACARGL, disc ACDSGL, cash ACCSGL).
GLMAST Input File (IF) 256 2 G/L master; account descriptions (GLDESC).
ARDETL Input File (IF) 128 2 AR detail; amounts (ADAMT, partial ADPART, paid ADPAY), due date (ADDUDT), terms (ADTERM), no diff (ADNOD).

Files use packed decimals (P) for amounts, zoned for dates/numbers. All are keyed for efficient access; shared in OCL caller.


External Programs Called

The RPG program AR135 does not explicitly call any other external programs or procedures via CALL or similar statements. All processing is internal via subroutines (EXSR): - S1, S2ADD, S2UPD, CSR, S4, DTEDIT, RDTRAN, TOTALS, *INZSR.

It is invoked by the OCL program (AR135.ocl36.txt via LOAD AR135 and RUN), which handles file opens and environment setup. No outbound calls; returns control on *INLR.