AP251 RPG
The provided RPG program, AP251.rpg36.txt
, is executed by the OCL program AP251.ocl36.txt
, which itself is called from the main OCL program AP250.ocl36.txt
within an IBM System/36 or AS/400 Accounts Payable (A/P) system. The purpose of AP251
is to update a commission table (APTORCY
) with payment information from the payment file (APPAY
). 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 AP251 RPG Program¶
The AP251
RPG program processes payment records from the APPAY
file and updates corresponding records in the APTORCY
commission table. Here is a detailed breakdown of the process steps:
- Initialization (ONETIM Subroutine):
-
The program starts by checking indicator
09
. If09
is off (N09
), it executes theONETIM
subroutine:- 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
). - Moves
DATYMD
intoDATE8
for consistent date formatting. - Sets indicator
09
on to prevent re-execution ofONETIM
.
- Retrieves the current system date and time using the
-
Main Processing Loop (EACH01 Subroutine):
-
For each record in the
APPAY
file (processed with indicator01
), theEACH01
subroutine is executed:- Builds a key (
KEY27
, 27 characters) for chaining to theAPTORCY
file: - Copies the company number (
CONO
, positions 2-3) into the first part ofKEY27
. - Copies the vendor number (
VEND
, positions 4-8) intoKEY25
. - Copies the invoice description (
OPIN20
, positions 35-54) intoKEY20
. - Combines
KEY20
andKEY25
intoKEY27
for the full key. - Chains to the
APTORCY
file usingKEY27
to locate the corresponding commission record. - If a matching record is found (
N99
, i.e., not indicator99
set): - Converts the check date (
AXCKDT
) to an 8-digit format (AXYMD8
, e.g.,20YYMMDD
) by multiplying by10000.01
and prefixing with the century (20
). - Stores the gross amount (
OPGRAM
) in a temporary field (AMT92
, 9.2 format). - Writes an exception record to
APTORCY
using theUPDATE
exception (see Output Specification below). - If no matching record is found (
99
set), the record is skipped.
- Builds a key (
-
Update Commission Table:
-
The
UPDATE
exception in the Output Specification (OAPTORCY E UPDATE
) updates theAPTORCY
file with:- Invoice number (
OPINV#
, positions 207-226 fromAPPAY
) toATINV
(positions 84-103). - Gross amount (
AMT92
, derived fromOPGRAM
) toATAPMT
(positions 104-108, packed). - Status (
ATSTAT
) set to'P'
(paid, position 109). - Check number (
ATCHK#
, positions 110-115, likely populated fromOPCKNO
inAPPAY
).
- Invoice number (
-
Completion:
- The program processes all
APPAY
records sequentially, updating matchingAPTORCY
records. - Once all records are processed, the program terminates, and control returns to the calling OCL program (
AP251.ocl36.txt
).
Business Rules¶
The RPG program enforces the following business rules based on its logic and context within the A/P system:
- Commission Record Matching:
- Matches payment records from
APPAY
to commission records inAPTORCY
using a composite key (KEY27
) built from:- Company number (
CONO
). - Vendor number (
VEND
). - Invoice description (
OPIN20
, likely a truncated or formatted invoice number).
- Company number (
-
Only updates
APTORCY
records that match the key; unmatched records are skipped. -
Payment Status Update:
- Sets the commission record status (
ATSTAT
) to'P'
(paid) when a payment is applied. - Records the payment amount (
OPGRAM
fromAPPAY
) inATAPMT
and the check number (OPCKNO
) inATCHK#
. -
Includes the invoice number (
OPINV#
) to link the payment to the commission record. -
Date Handling:
- Uses century-aware date processing (prefixes
20
for 2000s) to format the check date (AXCKDT
) intoAXYMD8
for consistency. -
Relies on
Y2KCEN
(century field, set to19
or20
) from the User Data Structure (UDS) for date calculations. -
File Access:
APPAY
is processed sequentially as the primary input file (IP
), ensuring all payment records are read.-
APTORCY
is a keyed update file (UF
,EXTK
for external key), allowing random access and updates based on the composite key. -
No Error Output:
-
The program does not generate error reports or logs for unmatched records (
99
set). It silently skips them, assuming they are not relevant to the commission table. -
Integration with A/P Process:
- The program assumes
APPAY
contains valid payment data from the A/P check register process (AP250
). - Updates to
APTORCY
are part of the broader A/P workflow, ensuring commission records reflect payments made to vendors or agents.
Tables (Files) Used¶
The program uses the following files, as defined in the File Specification (F-spec) section:
- APPAY (IP, 384 bytes, keyed,
DISK
): - Primary input file, temporary payment file created by the main OCL program (
AP250.ocl36.txt
). -
Contains payment details, including:
CONO
: Company number (positions 2-3).VEND
: Vendor number (positions 4-8).OPGRAM
: Gross amount (packed, positions 18-23).OPDISC
: Discount (packed, positions 24-28).OPPPTD
: Partial paid to date (packed, positions 29-34).OPCKNO
: Check number (positions 91-96).OPPAID
: Payment status (position 97, e.g.,'P'
for prepaid).OPLPAM
: This payment amount (packed, positions 161-166).OPDSTK
: Discount already taken (packed, positions 167-171).OPSORN
: Sales order number (positions 281-286).OPINV#
: Invoice number (positions 207-226).OPIN20
: Invoice description (positions 35-54).AXCKDT
: Check date (positions 434-439, from UDS).
-
APTORCY (UF, 211 bytes, keyed,
EXTK
,DISK
): - Update file, commission master file.
-
Contains commission-related data, including:
ATDEL
: Deletion flag (position 1).ATCO
: Company number (positions 2-3).ATCUST
: Customer number (positions 4-9).ATORD#
: Order number (positions 10-15).ATSRN#
: Serial number (positions 16-18).ATINV#
: Invoice number (positions 19-25).ATIVAM
: Invoice amount (packed, positions 26-30).ATINV8
: Invoice date (positions 31-38).ATSHD8
: Shipping date (positions 39-46).ATPROD
: Product code (positions 47-50).ATUM
: Unit of measure (positions 51-53).ATAMT
: Amount (packed, positions 54-56).ATPCT
: Percentage (packed, positions 57-58).ATVEND
: Vendor number (positions 59-63).ATHAND
: Handling code (positions 64-83).ATINV
: Invoice number (positions 84-103, updated).ATAPMT
: Payment amount (packed, positions 104-108, updated).ATSTAT
: Status (position 109, updated to'P'
).ATCHK#
: Check number (positions 110-115, updated).
-
UDS (User Data Structure):
- Provides additional fields, including:
AXCKDT
: Check date (positions 434-439).Y2KCEN
: Century indicator (positions 509-510, e.g.,19
or20
).Y2KCMP
: Company-related century field (positions 511-512).
External Programs Called¶
The AP251
RPG program does not call any external programs. It is self-contained, using two subroutines (ONETIM
for initialization and EACH01
for processing) to handle all logic. The program is invoked by the AP251.ocl36.txt
OCL script, which loads and runs it as part of the A/P process.
Summary¶
The AP251
RPG program is a focused component of the A/P system, designed to update the commission table (APTORCY
) with payment data from the APPAY
file. Its key functions are:
- Process Steps:
- Initializes date and time fields (
ONETIM
subroutine). - Processes each
APPAY
record, matches it toAPTORCY
using a composite key (company, vendor, invoice description), and updates commission records with payment details (invoice number, amount, status, check number). -
Writes updated records to
APTORCY
. -
Business Rules:
- Matches payments to commission records using company number, vendor number, and invoice description.
- Updates commission records with payment status (
'P'
), amount, and check number. - Handles century-aware date formatting for check dates.
- Skips unmatched records without generating errors.
-
Operates in a shared access environment for concurrent processing.
-
Tables Used:
APPAY
: Temporary payment file (input).APTORCY
: Commission master file (update).-
UDS
: User Data Structure for date and century fields. -
External Programs Called: None.
The program integrates with the broader A/P process by processing payment data generated by AP250
and updating the commission table to reflect payments made to vendors or agents. If you have additional details (e.g., the structure of APTORCY
or specific commission logic), I can provide further analysis. Please let me know if you need clarification or more details!