Skip to content

AP255 RPG

The provided RPG program, AP255.rpg36.txt, is executed by the main OCL program (AP250.ocl36.txt) within an IBM System/36 or AS/400 Accounts Payable (A/P) system. Its primary purpose is to generate a Cash Disbursements Journal and summarize A/P transactions, producing a report and updating a general ledger file. Below, I will explain the process steps, business rules, tables (files) used, and external programs called based on the RPG code.


Process Steps of the AP255 RPG Program

The AP255 RPG program processes sorted cash disbursements journal records from APCDJR, summarizes A/P transactions, and generates a formatted report (APPRINT) while updating a temporary general ledger file (TEMGEN). Here is a detailed breakdown of the process steps:

  1. Initialization (Level 4 - Company/Bank G/L Break):
  2. At the company or bank G/L level (L4 indicator), the program initializes key variables:

    • Retrieves the current system date and time using the TIME operation, storing it in TIMDAT (12 digits).
    • Extracts the time portion into TIME (6 digits) and the date portion into DATE (6 digits).
    • Converts the date to a year-month-day format (DATYMD) by multiplying DATE by 10000.01 to adjust for century handling.
    • Sets the century prefix (20 for 2000s) into DATE8 (8-digit date field, e.g., 20YYMMDD) and moves DATYMD into DATE8.
    • Initializes the page number (PAGE) to 0.
    • Sets a separator line (SEP) to '* ' for report formatting.
    • Chains to the APCONT file using the company number (CDCONO) to retrieve company details (e.g., ACNAME for company name).
    • Initializes debit (L4DR) and credit (L4CR) totals to 0 for journal balancing.
  3. Period/Year Validation:

  4. Checks if the year/period field (CDYYPD) is non-zero (N99).

    • If non-zero, sets indicators 98 and 99 to enable printing of the period/year (CDPD, CDPDYY) in the report header.
  5. Record Processing Loop:

  6. Processes each record in the APCDJR file (primary input, indicator 01):

    • Identifies the transaction type (CDCORD):
    • If CDCORD = 'D', sets indicator 30 (debit transaction).
    • Identifies the journal entry type (CDTYPE):
    • If CDTYPE = 'AP ', sets indicator 20 to indicate an A/P transaction that requires summarization.
    • Converts the check date (CDCKDT) to an 8-digit format (CYMD, e.g., 20YYMMDD):
    • Multiplies CDCKDT by 10000.01 to get YMD (6 digits).
    • Extracts the year (YY) and compares it to Y2KCMP (company century threshold, e.g., 80).
    • If YY >= Y2KCMP, uses Y2KCEN (e.g., 19 or 20) as the century (CN).
    • If YY < Y2KCMP, increments Y2KCEN by 1 (e.g., 20 becomes 21).
    • Combines CN and YMD into CYMD for reporting.
    • Accumulates the transaction amount (CDAMT) into L1AMT (level 1 amount) for summarization.
  7. Journal Entry Processing (JRNL Subroutine):

  8. The JRNL subroutine is called for each non-summarized record (N20) and for summarized A/P records at the level 1 break (L1 and 20):

    • Increments a journal reference number (JRREF#) for each entry.
    • Sets the credit/debit code (CORD) based on CDCORD:
    • If L1AMT is negative (10 set), reverses the sign of L1AMT and adjusts CORD:
      • If 30 (debit), sets CORD = 'C' (credit).
      • If not 30, sets CORD = 'D' (debit).
    • Accumulates amounts:
    • If CORD = 'D' (debit, 11 set), adds L1AMT to L4DR (debit total).
    • If CORD ≠ 'D' (credit, N11), adds L1AMT to L4CR (credit total).
    • Moves L1AMT to JRAMT (journal amount) and resets L1AMT to 0.
  9. Output to TEMGEN (General Ledger File):

  10. For non-summarized records (N20):
    • Writes a detailed journal entry to TEMGEN with:
    • Record type 'A' (active).
    • Company number (CDCONO).
    • G/L number (CDGLNO).
    • Journal number (CDJRNL).
    • Reference number (JRREF#).
    • Credit/debit code (CORD).
    • Check number (CDCHEK).
    • Description (CDDESC).
    • Date (YMD).
    • Amount (JRAMT, packed).
    • Vendor name (CDNAME).
    • Century-adjusted date (CYMD).
  11. For summarized A/P records (L1 and 20):

    • Writes a summarized journal entry to TEMGEN with:
    • Record type 'A'.
    • Company number (CDCONO).
    • G/L number (CDGLNO).
    • Journal number (CDJRNL).
    • Reference number (JRREF#).
    • Credit/debit code (CORD).
    • Check date (CDCKDT).
    • Fixed description '-SUMMARIZED A/P '.
    • Date (YMD).
    • Amount (JRAMT, packed).
    • Century-adjusted date (CYMD).
  12. Output to Cash Disbursements Journal Report (APPRINT):

  13. At the company level (L4):
    • Prints report headers with:
    • Company name (ACNAME).
    • Page number (PAGE).
    • Date (DATE, formatted as MMDDYY).
    • Wire transfer description (WIREDS, e.g., 'WT*** WIRE TRANSFER ***').
    • Title 'CASH DISBURSEMENTS JOURNAL'.
    • Time (TIME, formatted as HH.MM.SS).
    • Journal number (CDJRNL).
    • Check date (CDCKDTY).
    • Period/year (CDPD, CDPDYY) if 98 is set.
    • Column headings for journal reference, check number, description, vendor name, and debit/credit amounts with G/L numbers.
  14. For each non-summarized record (01 and N20):
    • Prints detail lines with:
    • Journal number (CDJRNL).
    • Reference number (JRREF#).
    • Check number (CDCHEK).
    • Description (CDDESC).
    • Vendor name (CDNAME).
    • G/L number (CDGLNO) and amount (JRAMT) in debit (11) or credit (N11) columns.
  15. For summarized A/P records (L1 and 20):
    • Prints summarized lines with:
    • Journal number (CDJRNL).
    • Reference number (JRREF#).
    • Check date (CDCKDTY).
    • Fixed description '-SUMMARIZED A/P '.
    • G/L number (CDGLNO) and amount (JRAMT) in debit (11) or credit (N11) columns.
  16. At the end of the company level (L4, total time T 2):

    • Prints journal totals with:
    • 'JOURNAL TOTALS'.
    • Total debits (L4DR) and credits (L4CR).
  17. Completion:

  18. Processes all APCDJR records, writing to TEMGEN and APPRINT as needed.
  19. Terminates, returning control to the main OCL program (AP250.ocl36.txt).

Business Rules

The program enforces the following business rules based on its logic and context within the A/P system:

  1. Transaction Type Handling:
  2. Processes journal entries based on CDCORD:
    • 'D': Debit transaction (30 set).
    • Other values (e.g., 'C'): Credit transaction.
  3. Adjusts negative amounts by reversing the sign and switching the credit/debit code (CORD):

    • Negative debit becomes credit (CORD = 'C').
    • Negative credit becomes debit (CORD = 'D').
  4. A/P Summarization:

  5. Summarizes A/P transactions (CDTYPE = 'AP ', 20 set) at the level 1 break (L1), consolidating multiple A/P entries into a single journal entry with the description '-SUMMARIZED A/P '.

  6. Journal Balancing:

  7. Accumulates debit (L4DR) and credit (L4CR) totals at the company level (L4) to ensure journal entries balance.
  8. Prints totals in the report to verify debit and credit amounts.

  9. Date Handling:

  10. Uses century-aware date processing:
    • Compares the year (YY) from CDCKDT to Y2KCMP (company century threshold).
    • Assigns the century (Y2KCEN or Y2KCEN + 1) to create CYMD (e.g., 20YYMMDD).
  11. Includes both raw (YMD) and century-adjusted (CYMD) dates in TEMGEN output.

  12. Period/Year Reporting:

  13. If the year/period (CDYYPD) is non-zero, includes the period (CDPD) and year (CDPDYY) in the report header (e.g., 'PERIOD XX-XX').

  14. General Ledger Integration:

  15. Writes journal entries to TEMGEN for integration with the general ledger system, including both detailed and summarized entries.
  16. Uses a consistent format with record type 'A' (active), company number, G/L number, journal number, reference number, and amount.

  17. Report Formatting:

  18. Generates a formatted Cash Disbursements Journal (APPRINT) with headers, detail lines, and totals.
  19. Includes debit and credit columns with G/L numbers for clarity.
  20. Supports wire transfer descriptions (WIREDS) for context.

  21. File Access:

  22. APCDJR is processed sequentially as the primary input file (IP).
  23. APCONT is accessed randomly (IC, keyed) for company details.
  24. TEMGEN is an output file for general ledger entries.
  25. AP255S is a table file, likely used for temporary storage or control data.

Tables (Files) Used

The program uses the following files, as defined in the File Specification (F-spec) section:

  1. APCDJR (IP, 128 bytes, keyed, DISK):
  2. Primary input file, contains sorted cash disbursements journal entries from the main OCL process (sorted by #GSORT in AP250.ocl36.txt).
  3. Fields include:

    • CDDEL: Deletion flag (position 1, 'D' for delete).
    • CDCONO: Company number (positions 2-3, L4).
    • CDJRNL: Journal number (positions 4-7).
    • CDCORD: Credit/debit code (position 12, L3, e.g., 'C', 'D').
    • CDGLNO: G/L number (positions 13-20, L1).
    • CDCHEK: Check number (positions 21-26).
    • CDDESC: Description (positions 27-50).
    • CDCKDT: Check date (positions 51-56).
    • CDAMT: Amount (packed, positions 57-62).
    • CDNAME: Vendor name (positions 63-92).
    • CDSEQ#: Sequence number (positions 97-105).
    • CDTYPE: Transaction type (positions 106-115, L2, e.g., 'AP ', 'CASH ', 'DISC ').
    • CDYYPD: Year/period (positions 116-119).
    • CDPDYY: Year (positions 116-117).
    • CDPD: Period (positions 118-119).
  4. AP255S (IR, 3 bytes, keyed, EDISK):

  5. Internal table file, likely used for temporary storage or control data during processing.
  6. Associated with APCDJR via the E specification (E AP255S APCDJR).

  7. APCONT (IC, 256 bytes, keyed, DISK):

  8. Control file, accessed randomly to retrieve company details.
  9. Fields include:

    • ACNAME: Company name (positions 4-33).
  10. TEMGEN (O, 128 bytes, DISK):

  11. Output file for general ledger entries.
  12. Fields include:

    • Record type ('A', position 1).
    • Company number (CDCONO, positions 2-3).
    • G/L number (CDGLNO, positions 4-11).
    • Journal number (CDJRNL, positions 12-15).
    • Reference number (JRREF#, positions 16-19).
    • Credit/debit code (CORD, position 20).
    • Check number (CDCHEK) or check date (CDCKDT) for summarized entries.
    • Description (CDDESC or '-SUMMARIZED A/P ', positions 27-50).
    • Date (YMD, positions 51-56).
    • Amount (JRAMT, packed, positions 57-62).
    • Vendor name (CDNAME, positions 63-92).
    • Century-adjusted date (CYMD, positions 93-100).
  13. APPRINT (O, 132 bytes, PRINTER):

  14. Output file for the Cash Disbursements Journal report.
  15. Includes headers, detail lines, summarized A/P entries, and journal totals.

  16. UDS (User Data Structure):

  17. Provides additional fields:
    • WIREDS: Wire transfer description (positions 200-220, e.g., 'WT*** WIRE TRANSFER ***').
    • Y2KCEN: Century indicator (positions 509-510, e.g., 19 or 20).
    • Y2KCMP: Company century threshold (positions 511-512, e.g., 80).

External Programs Called

The AP255 RPG program does not call any external programs. It is self-contained, using the JRNL subroutine to handle journal entry processing. The program is invoked by the main OCL program (AP250.ocl36.txt) after sorting data with #GSORT.


Summary

The AP255 RPG program is a critical component of the A/P system, responsible for generating the Cash Disbursements Journal and preparing general ledger entries. Its key functions are:

  • Process Steps:
  • Initializes company-level data and report headers (L4 break).
  • Processes APCDJR records, handling debit/credit codes and summarizing A/P transactions.
  • Converts dates to century-aware format.
  • Writes detailed and summarized journal entries to TEMGEN.
  • Generates a formatted Cash Disbursements Journal report (APPRINT) with headers, details, and totals.

  • Business Rules:

  • Handles debit ('D') and credit ('C') transactions, adjusting negative amounts.
  • Summarizes A/P transactions (CDTYPE = 'AP ') into a single entry.
  • Maintains journal balance with debit (L4DR) and credit (L4CR) totals.
  • Supports century-aware date processing.
  • Includes period/year in the report if applicable.
  • Writes standardized general ledger entries to TEMGEN.

  • Tables Used:

  • APCDJR: Primary input, cash disbursements journal entries.
  • AP255S: Internal table file.
  • APCONT: Company control file.
  • TEMGEN: General ledger output file.
  • APPRINT: Cash Disbursements Journal report.
  • UDS: User Data Structure for additional fields.

  • External Programs Called: None.

The program integrates with the broader A/P process by processing sorted journal entries from AP250 and preparing data for general ledger integration. If you need further details or analysis (e.g., specific report formats or TEMGEN integration), please let me know!