AP1012 RPG
The AP1012.rpg program is an RPG III program running on an IBM AS/400 (iSeries) system, designed to create detail lines for accounts payable (A/P) voucher entries in the APTRAN file by prorating freight charges based on sales detail or miscellaneous records. It is called from the AP125.rpg program (which is invoked by the AP125.ocl36.txt OCL script) and processes data from sales files (SA5FIUD, SA5FIUM, SA5MOUD, SA5MOUM) to allocate freight amounts. Below, I detail the process steps, business rules, tables used, and external programs called, based on the provided source code.
Process Steps of the AP1012 Program¶
The program calculates freight amounts for A/P voucher detail lines by prorating the total freight amount (FRTTOT) across sales detail or miscellaneous records, based on gallons or miscellaneous amounts. It handles both detail (SA5FIUD, SA5MOUD) and miscellaneous (SA5FIUM, SA5MOUM) records, with adjustments for invoice dates and product codes.
- Initialization:
- Parameters: Receives a
SALESdata structure with:SACO: Company number (2 digits).SAORD: Order number (6 digits).SASRN#: Shipping reference number (3 digits).SASEQ: Sequence number (3 digits).FRTTOT: Total freight to allocate (7.2 digits).VEND: Vendor number (5 digits).ENTNUM: A/P entry number (5 digits).EXGL: Expense G/L (8 digits).DSPC: Discount percentage (4.3 digits, perMG03).CMPDT8: Comparison date (invoice date minus one year, perJB06).S@FIMO: File indicator (FforSA5FI,MforSA5MO, perJB06).S@DM: Detail/misc indicator (Dfor detail,Mfor misc, perJB06).
- Initializes fields (
ZERO6,ZERO7,ZERO9,ZERO11) to zero. -
If
S@FIMOis blank, callsGETS@to determine the appropriate file (SA5FIorSA5MO) and record type (DorM). -
Subroutine GETS@ (Determine File and Record Type):
- If
SAORDandSASRN#are non-zero, constructs a key (SAIUKY) usingSACO,SAORD, andSASRN#. - Checks files in order:
SA5FIUD: If a valid record is found withS5SHD8 >= CMPDT8, setsS@FIMO = 'F',S@DM = 'D'.SA5MOUD: If found, setsS@FIMO = 'M',S@DM = 'D'.SA5FIUM: If found, setsS@FIMO = 'F',S@DM = 'M'.SA5MOUM: If found, setsS@FIMO = 'M',S@DM = 'M'.
-
Stops when a valid record is found (
SA5FND). -
Calculate Total Gallons (Detail Records):
- Constructs a key (
SAKEY) usingSACO,SAORD, andSASRN#. - Sets the lower limit for
SA5FIUDorSA5MOUDbased onS@FIMO. - Reads through
SA5FIUD(ifS@FIMO ≠ 'M') orSA5MOUD(ifS@FIMO = 'M'). - For matching records (
S5CO# = SACO,S5ORD# = SAORD,S5SRN# = SASRN#,S5SHD8 >= CMPDT8):- Adds
S5NGAL(net gallons) toTTLQTY. - Increments
COUNT1(number of detail lines).
- Adds
-
If
TTLQTYandCOUNT1are zero, skips to miscellaneous record processing (SKIP3). -
Prorate Freight for Detail Records:
- Resets
SAKEYto "000" and re-readsSA5FIUDorSA5MOUD. - For each matching record:
- Calculates the percentage (
PCTHLD = S5NGAL / TTLQTY) ifTTLQTYis non-zero. - Computes freight amount (
AMT,Y = PCTHLD * FRTTOT). - Stores in
AMTITMandLINAMT. - Increments
COUNT2(line counter) and array indexY.
- Calculates the percentage (
- For the last record (
COUNT2 = COUNT1):- Calculates total computed amount (
CLCAMT= sum ofAMT). - Adjusts
AMTITMandLINAMT: - If
FRTTOT = CLCAMT, no adjustment. - If
FRTTOT > CLCAMT, adds difference (DIFF1) toAMTITM. - If
FRTTOT < CLCAMT, subtracts difference (DIFF2) fromAMTITM.
- Calculates total computed amount (
-
Calls
GOODto write the detail line toAPTRAN. -
Subroutine MFRTO (Miscellaneous Freight Total):
-
For invoices with only miscellaneous records (no detail lines, per
JB08):- Reads
SA5FIUMorSA5MOUMbased onS@FIMO. - For matching records (
SMCO# = SACO,SMORD# = SAORD,SMSRN# = SASRN#,SMMSTY = 'F',SMGLNO ≠ 0,SMSHD8 >= CMPDT8): - Adds
SMMAMTtoTTLMFT(total miscellaneous freight). - Increments
COUNTM(miscellaneous line count).
- Reads
-
Prorate Freight for Miscellaneous Records:
-
If no detail records were found (
TTLQTY = 0,COUNT1 = 0):- Reads
SA5FIUMorSA5MOUMbased onS@FIMO. - For matching records (
SMCO# = SACO,SMORD# = SAORD,SMSRN# = SASRN#,SMMSTY = 'F',SMGLNO ≠ 0,SMSHD8 >= CMPDT8): - Calculates miscellaneous amount (
CLCAMT = SMMAMT * SMMQTY). - For non-last records (
COUNT3 < COUNTM):- Computes percentage (
PCTHLD = CLCAMT / TTLMFT). - Calculates freight amount (
FRTAMT = FRTTOT * PCTHLD). - Adds
FRTAMTtoCLCTOT(running total).
- Computes percentage (
- For the last record:
- Sets
FRTAMT = FRTTOT - CLCTOTto ensure total matchesFRTTOT.
- Sets
- Calls
GETFRTto write the miscellaneous detail line toAPTRAN.
- Reads
-
Subroutine GOOD (Write Detail Line for Detail Records):
- Retrieves freight G/L (
FEGL):- If product code (
S5PROD) contains an alpha character (perJB02), chains toGSCTUMusingS5CO#,S5PROD,S5CNTR, andS5UMto getCUFEGL. - Otherwise, chains to
GSTABL(tableCNTRPF) usingS5TANKto getTBFEG4, appendingS5PROD. - If still zero, chains to
BICONTto get defaultBCFRGL.
- If product code (
- Constructs
APKEYusingS5CO#andCOUNT2. - Chains to
APTRANto check for an existing record. - Sets description (
DDES = 'XXXXXXXXX XXXX XXX FRTCHG'). -
Writes (
ADDT) or updates (UPDT) the detail line withLINAMT,FEGL,DSPC, etc. -
Subroutine GETFRT (Write Detail Line for Miscellaneous Records):
- Sets freight G/L (
FEGL = SMGLNO). - Constructs
APKEYusingSMCO#andCOUNT3. - Chains to
APTRANto check for an existing record. - Sets description (
DDES = 'MISC CHARGE'). -
Writes (
ADDTM) or updates (UPDTM) the detail line withFRTAMT,FEGL,DSPC, etc. -
Program Termination:
- Sets
*INLR = *ONto end the program.
Business Rules¶
- Freight Proration:
- For detail records (
SA5FIUDorSA5MOUD), prorates freight (FRTTOT) based on net gallons (S5NGAL / TTLQTY). - For miscellaneous records (
SA5FIUMorSA5MOUM), prorates freight based on miscellaneous amount (SMMAMT * SMMQTY / TTLMFT, perJB08). -
Ensures the sum of prorated amounts equals
FRTTOTby adjusting the last record. -
File Selection:
- Uses
S@FIMO(FforSA5FI,MforSA5MO) andS@DM(Dfor detail,Mfor misc) to determine the correct file (SA5FIUD,SA5MOUD,SA5FIUM,SA5MOUM). -
If
S@FIMOis blank,GETS@determines the file by checking for valid records (perJB07). -
Date Restriction:
-
Only processes records with a ship date (
S5SHD8orSMSHD8) within one year of the invoice date (CMPDT8, perJB06). -
G/L Account Determination:
- For detail records with alpha product codes, retrieves freight G/L (
CUFEGL) fromGSCTUM(perJB02). - For numeric product codes, uses
TBFEG4fromGSTABL(tableCNTRPF) withS5PRODappended. -
Defaults to
BCFRGLfromBICONTif no G/L is found. -
Miscellaneous Records:
- Only processes miscellaneous records with
SMMSTY = 'F'(freight) and non-zeroSMGLNO(perMG05,JB08). -
Handles invoices with only miscellaneous lines (no detail records, per
JB08). -
Discount Application:
-
Applies discount percentage (
DSPC) from theSALESdata structure to detail lines (perMG03). -
Detail Line Creation:
- Creates
APTRANdetail lines with fields likeFEGL,LINAMT(orFRTAMT),DSPC, and default values (e.g.,CLCD = 'C',POSQ = '000'). - Uses fixed descriptions:
XXXXXXXXX XXXX XXX FRTCHGfor detail records,MISC CHARGEfor miscellaneous records.
Tables (Files) Used¶
- Update Files:
-
APTRAN: Accounts Payable transaction file (404 bytes, keyed by company and entry number). -
Input Files:
SA5FIUD: Sales detail file (1024 bytes, keyed by company, customer, order, ship to, SRN).SA5FIUM: Sales miscellaneous file (1024 bytes, keyed by company, customer, order, SRN).SA5MOUD: Move detail file (1024 bytes, keyed by company, customer, order, ship to, SRN, perJB06).SA5MOUM: Move miscellaneous file (1024 bytes, keyed by company, customer, order, SRN, perJB06).GSTABL: General table file (256 bytes, keyed by table typeCNTRPFfor freight G/L).BICONT: Billing control file (256 bytes, keyed by company for default freight G/L).GSCTUM: Customer table file (64 bytes, keyed by company, product code, container code, unit of measure, perJB02).
External Programs Called¶
- None. The program does not call any external programs.
Summary¶
The AP1012.rpg program creates A/P voucher detail lines in APTRAN by prorating freight charges (FRTTOT) across sales detail (SA5FIUD, SA5MOUD) or miscellaneous (SA5FIUM, SA5MOUM) records. It calculates freight amounts based on gallons for detail records or miscellaneous amounts for misc records, ensuring the total matches FRTTOT. It retrieves freight G/L accounts from GSCTUM, GSTABL, or BICONT, applies discounts, and restricts records to within one year of the invoice date. The program handles invoices with only miscellaneous lines and writes detail lines with appropriate descriptions.
If you need further details or clarification on specific subroutines, business rules, or file structures, please let me know!