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 (
L4
indicator), the program initializes key variables:- Retrieves the current system date and time using the
TIME
operation, 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 multiplyingDATE
by10000.01
to adjust for century handling. - Sets the century prefix (
20
for 2000s) intoDATE8
(8-digit date field, e.g.,20YYMMDD
) and movesDATYMD
intoDATE8
. - 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.
- 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
98
and99
to 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
APCDJR
file (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 indicator20
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
by10000.01
to getYMD
(6 digits). - Extracts the year (
YY
) and compares it toY2KCMP
(company century threshold, e.g.,80
). - If
YY >= Y2KCMP
, usesY2KCEN
(e.g.,19
or20
) as the century (CN
). - If
YY < Y2KCMP
, incrementsY2KCEN
by 1 (e.g.,20
becomes21
). - Combines
CN
andYMD
intoCYMD
for reporting. - Accumulates the transaction amount (
CDAMT
) intoL1AMT
(level 1 amount) for summarization.
- Identifies the transaction type (
-
Journal Entry Processing (JRNL Subroutine):
-
The
JRNL
subroutine is called for each non-summarized record (N20
) and for summarized A/P records at the level 1 break (L1
and20
):- Increments a journal reference number (
JRREF#
) for each entry. - Sets the credit/debit code (
CORD
) based onCDCORD
: - If
L1AMT
is negative (10
set), reverses the sign ofL1AMT
and adjustsCORD
:- If
30
(debit), setsCORD = 'C'
(credit). - If not
30
, setsCORD = 'D'
(debit).
- If
- Accumulates amounts:
- If
CORD = 'D'
(debit,11
set), addsL1AMT
toL4DR
(debit total). - If
CORD ≠ 'D'
(credit,N11
), addsL1AMT
toL4CR
(credit total). - Moves
L1AMT
toJRAMT
(journal amount) and resetsL1AMT
to 0.
- Increments a journal reference number (
-
Output to TEMGEN (General Ledger File):
- 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
).
- Writes a detailed journal entry to
-
For summarized A/P records (
L1
and20
):- 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
).
- 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
) if98
is set. - Column headings for journal reference, check number, description, vendor name, and debit/credit amounts with G/L numbers.
- For each non-summarized record (
01
andN20
):- 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 (
L1
and20
):- 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
APCDJR
records, writing toTEMGEN
andAPPRINT
as 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 (30
set).- 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 '
,20
set) 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
) fromCDCKDT
toY2KCMP
(company century threshold). - Assigns the century (
Y2KCEN
orY2KCEN + 1
) to createCYMD
(e.g.,20YYMMDD
).
- Compares the year (
-
Includes both raw (
YMD
) and century-adjusted (CYMD
) dates inTEMGEN
output. -
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
TEMGEN
for 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:
APCDJR
is processed sequentially as the primary input file (IP
).APCONT
is accessed randomly (IC
, keyed) for company details.TEMGEN
is an output file for general ledger entries.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:
- APCDJR (IP, 128 bytes, keyed,
DISK
): - Primary input file, contains sorted cash disbursements journal entries from the main OCL process (sorted by
#GSORT
inAP250.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
APCDJR
via theE
specification (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 (
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).
- 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.,19
or20
).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!