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:
- Initialization (Level 4 - Company/Bank G/L Break):
-
At the company or bank G/L level (
L4indicator), the program initializes key variables:- Retrieves the current system date and time using the
TIMEoperation, storing it inTIMDAT(12 digits). - Extracts the time portion into
TIME(6 digits) and the date portion intoDATE(6 digits). - Converts the date to a year-month-day format (
DATYMD) by multiplyingDATEby10000.01to adjust for century handling. - Sets the century prefix (
20for 2000s) intoDATE8(8-digit date field, e.g.,20YYMMDD) and movesDATYMDintoDATE8. - Initializes the page number (
PAGE) to 0. - Sets a separator line (
SEP) to'* 'for report formatting. - Chains to the
APCONTfile using the company number (CDCONO) to retrieve company details (e.g.,ACNAMEfor company name). - Initializes debit (
L4DR) and credit (L4CR) totals to 0 for journal balancing.
- Retrieves the current system date and time using the
-
Period/Year Validation:
-
Checks if the year/period field (
CDYYPD) is non-zero (N99).- If non-zero, sets indicators
98and99to enable printing of the period/year (CDPD,CDPDYY) in the report header.
- If non-zero, sets indicators
-
Record Processing Loop:
-
Processes each record in the
APCDJRfile (primary input, indicator01):- Identifies the transaction type (
CDCORD): - If
CDCORD = 'D', sets indicator30(debit transaction). - Identifies the journal entry type (
CDTYPE): - If
CDTYPE = 'AP ', sets indicator20to indicate an A/P transaction that requires summarization. - Converts the check date (
CDCKDT) to an 8-digit format (CYMD, e.g.,20YYMMDD): - Multiplies
CDCKDTby10000.01to getYMD(6 digits). - Extracts the year (
YY) and compares it toY2KCMP(company century threshold, e.g.,80). - If
YY >= Y2KCMP, usesY2KCEN(e.g.,19or20) as the century (CN). - If
YY < Y2KCMP, incrementsY2KCENby 1 (e.g.,20becomes21). - Combines
CNandYMDintoCYMDfor reporting. - Accumulates the transaction amount (
CDAMT) intoL1AMT(level 1 amount) for summarization.
- Identifies the transaction type (
-
Journal Entry Processing (JRNL Subroutine):
-
The
JRNLsubroutine is called for each non-summarized record (N20) and for summarized A/P records at the level 1 break (L1and20):- Increments a journal reference number (
JRREF#) for each entry. - Sets the credit/debit code (
CORD) based onCDCORD: - If
L1AMTis negative (10set), reverses the sign ofL1AMTand adjustsCORD:- If
30(debit), setsCORD = 'C'(credit). - If not
30, setsCORD = 'D'(debit).
- If
- Accumulates amounts:
- If
CORD = 'D'(debit,11set), addsL1AMTtoL4DR(debit total). - If
CORD ≠ 'D'(credit,N11), addsL1AMTtoL4CR(credit total). - Moves
L1AMTtoJRAMT(journal amount) and resetsL1AMTto 0.
- Increments a journal reference number (
-
Output to TEMGEN (General Ledger File):
- For non-summarized records (
N20):- Writes a detailed journal entry to
TEMGENwith: - 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).
- Writes a detailed journal entry to
-
For summarized A/P records (
L1and20):- Writes a summarized journal entry to
TEMGENwith: - 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).
- Writes a summarized journal entry to
-
Output to Cash Disbursements Journal Report (APPRINT):
- At the company level (
L4):- Prints report headers with:
- Company name (
ACNAME). - Page number (
PAGE). - Date (
DATE, formatted asMMDDYY). - Wire transfer description (
WIREDS, e.g.,'WT*** WIRE TRANSFER ***'). - Title
'CASH DISBURSEMENTS JOURNAL'. - Time (
TIME, formatted asHH.MM.SS). - Journal number (
CDJRNL). - Check date (
CDCKDTY). - Period/year (
CDPD,CDPDYY) if98is set. - Column headings for journal reference, check number, description, vendor name, and debit/credit amounts with G/L numbers.
- For each non-summarized record (
01andN20):- 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.
- For summarized A/P records (
L1and20):- 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.
-
At the end of the company level (
L4, total timeT 2):- Prints journal totals with:
'JOURNAL TOTALS'.- Total debits (
L4DR) and credits (L4CR).
-
Completion:
- Processes all
APCDJRrecords, writing toTEMGENandAPPRINTas needed. - 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:
- Transaction Type Handling:
- Processes journal entries based on
CDCORD:'D': Debit transaction (30set).- Other values (e.g.,
'C'): Credit transaction.
-
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').
- Negative debit becomes credit (
-
A/P Summarization:
-
Summarizes A/P transactions (
CDTYPE = 'AP ',20set) at the level 1 break (L1), consolidating multiple A/P entries into a single journal entry with the description'-SUMMARIZED A/P '. -
Journal Balancing:
- Accumulates debit (
L4DR) and credit (L4CR) totals at the company level (L4) to ensure journal entries balance. -
Prints totals in the report to verify debit and credit amounts.
-
Date Handling:
- Uses century-aware date processing:
- Compares the year (
YY) fromCDCKDTtoY2KCMP(company century threshold). - Assigns the century (
Y2KCENorY2KCEN + 1) to createCYMD(e.g.,20YYMMDD).
- Compares the year (
-
Includes both raw (
YMD) and century-adjusted (CYMD) dates inTEMGENoutput. -
Period/Year Reporting:
-
If the year/period (
CDYYPD) is non-zero, includes the period (CDPD) and year (CDPDYY) in the report header (e.g.,'PERIOD XX-XX'). -
General Ledger Integration:
- Writes journal entries to
TEMGENfor integration with the general ledger system, including both detailed and summarized entries. -
Uses a consistent format with record type
'A'(active), company number, G/L number, journal number, reference number, and amount. -
Report Formatting:
- Generates a formatted Cash Disbursements Journal (
APPRINT) with headers, detail lines, and totals. - Includes debit and credit columns with G/L numbers for clarity.
-
Supports wire transfer descriptions (
WIREDS) for context. -
File Access:
APCDJRis processed sequentially as the primary input file (IP).APCONTis accessed randomly (IC, keyed) for company details.TEMGENis an output file for general ledger entries.AP255Sis 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:
- APCDJR (IP, 128 bytes, keyed,
DISK): - Primary input file, contains sorted cash disbursements journal entries from the main OCL process (sorted by
#GSORTinAP250.ocl36.txt). -
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).
-
AP255S (IR, 3 bytes, keyed,
EDISK): - Internal table file, likely used for temporary storage or control data during processing.
-
Associated with
APCDJRvia theEspecification (E AP255S APCDJR). -
APCONT (IC, 256 bytes, keyed,
DISK): - Control file, accessed randomly to retrieve company details.
-
Fields include:
ACNAME: Company name (positions 4-33).
-
TEMGEN (O, 128 bytes,
DISK): - Output file for general ledger entries.
-
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 (
CDDESCor'-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).
- Record type (
-
APPRINT (O, 132 bytes,
PRINTER): - Output file for the Cash Disbursements Journal report.
-
Includes headers, detail lines, summarized A/P entries, and journal totals.
-
UDS (User Data Structure):
- Provides additional fields:
WIREDS: Wire transfer description (positions 200-220, e.g.,'WT*** WIRE TRANSFER ***').Y2KCEN: Century indicator (positions 509-510, e.g.,19or20).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 (
L4break). - Processes
APCDJRrecords, 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!