AP125P RPGLE
The AP125P.rpgle program is an RPGLE program running on an IBM AS/400 (iSeries) system, designed for "Freight Invoice Import Selection" as part of an Accounts Payable (A/P) process. It is called from the AP125.ocl36.txt OCL script and facilitates the selection and management of freight invoices for batch processing. Below, I will explain the process steps, business rules, tables used, and external programs called, based on the provided source code.
Process Steps of the AP125P Program¶
The program is structured to manage a subfile (SFL) interface for selecting freight invoices, allowing users to add or remove invoices from a batch, validate inputs, and create batches for further processing. The main process steps are:
- Initialization (
*inzsrSubroutine): - Parameters: Receives input parameters:
a$co: Company code (2 digits).p$inty: Invoice type filter (Pfor paper,Nfor non-paper).p$mode: Run mode (MNTfor maintenance, otherwise inquiry).p$fgrp: File group (GorZ, determining which library files to use).
- Initializes work fields, subfile control fields (e.g.,
rrn1,pagsz1), and key lists for file access. -
Sets up message handling and default headers/comments.
-
Open Database Tables (
opntblSubroutine): - Overrides database files based on the
p$fgrpparameter (GorZ) usingQCMDEXCto execute override commands (e.g.,ovrdbfforapcont,frbinh, etc.). -
Opens input files (
apcont,frbinh,frcinh,frcfbh,bbcaid,frcinhj4) and the add/update file (ap125pw). -
Create or Clear Work File (
crtwrkfSubroutine): - Calls the external program
AP125PCto create or clear the work fileap125pw. - Overrides the
ap125pwfile toqtemp/ap125pwwithshare(*no). -
Opens the
ap125pwfile for add/update operations. -
Process Subfile (
srsfl1Subroutine): - Clear Message Subfile: Clears any existing messages (
clrmsg) and writes initial messages (wrtmsg). - Initialize Subfile: Sets the subfile mode to folded (
sfmod1 = '1',*in45 = *on) and initializes control fields (e.g.,c1cofroma$co,c1modetoAll). - Global Protection: Sets
*in70based onp$mode(*offforMNT,*onfor inquiry mode, protecting fields in inquiry mode). - Position File: Calls
sf1repto position the file and load the subfile. -
Main Loop:
- Displays the subfile control (
sflctl1) and command line (sflcmd1). - Checks for subfile records to enable display (
*in41). - Handles user inputs (function keys and Enter):
- F03 (Exit): Checks for pending selections in
ap125pw. If present, displays a confirmation window (f03wdw) viasf1f03. Exits if confirmed. - F04 (Field Prompting): Calls
promptto handle field prompting (e.g., forc1caidusingLBBCAID). - F05 (All/Review Toggle): Toggles between
AllandReviewmodes, updatingc1modeand repositioning the subfile. - F06 (Create Batch and Exit): Displays a confirmation window (
f06wdw) viasf1crtbatand creates a batch by callingcrtbat. - F22 (Add All): Adds all displayed invoices to the batch via
sf1prcall. - F23 (Remove All): Removes all displayed invoices from the batch via
sf1prcall. - Page Down: Loads additional subfile records (
sf1lod). - Enter: Processes subfile changes (
sf1prc). - Positioning: Repositions the subfile if
c1caid,c1fmdy, orc1tmdychange (sf1rep). - F10: Moves the cursor to the control record.
- Displays the subfile control (
-
Process Subfile on Enter (
sf1prcSubroutine): - Reads changed subfile records (
readc sfl1) and processes options (sf1chg). - Handles options:
- Option 1 (Add): Adds the invoice to the batch (
sf1s01) if inMNTmode. - Option 4 (Remove): Removes the invoice from the batch (
sf1s04) if inMNTmode.
- Option 1 (Add): Adds the invoice to the batch (
-
Updates subfile fields and colors (
sf1fmt,sf1col) and writes the updated record. -
Reposition Subfile (
sf1repSubroutine): - Clears the subfile (
sf1clr) and resets the relative record number (rrn1). - Validates control fields (
sf1cte) and positions the file (frcinhj4) usingsetll. -
Loads subfile records (
sf1lod) and retains control field values for repositioning. -
Edit Subfile Control Input (
sf1cteSubroutine): - Validates:
- Company (
c1co): Chains toapcontto verify the company code and retrieve the company name (c1conm). - Carrier ID (
c1caid): Chains tobbcaidto verify the carrier ID and retrieve the carrier name (c1crnm). If blank, sets to*All. - From/To Invoice Dates (
c1fmdy,c1tmdy): CallsGSDTEDITto validate dates and convert toc1fdat/c1tdat. Errors trigger messages (ERR0020).
- Company (
-
Adds error messages to the message subfile if validation fails.
-
Load Subfile Records (
sf1lodSubroutine): - Reads records from
frcinhj4(replacingfrcinh4) for the specified company (c1co). - Retrieves the order ship date (
boshd8) fromfrbinh(replacing invoice date per revisiondc01). - Applies filters (
sf1fltr) and skips records that don’t match criteria. - Formats (
sf1fmt) and color-codes (sf1col) subfile lines, then writes them to the subfile. -
Sets
s1nosflrecsif no records are found. -
Apply Filters (
sf1fltrSubroutine): - Filters records based on:
- Approval status (
fralst ≠ 'Y'orfrapst ≠ 'N'). - Invoice type (
frintymust matchp$inty). - Non-zero invoice amount (
s1inam ≠ 0, per revisionjb03). - Carrier ID (
c1caidmust matchfrcaidif specified).
- Approval status (
-
Sets
s1fltrto*onto skip records that fail filters. -
Format Subfile Line (
sf1fmtSubroutine):- Populates subfile fields (
s1caid,s1cain,s1inty,s1rdno,s1srn,s1inam,s1smdy) fromfrcinhj4orfrbinh. - Adjusts invoice amount (
s1inam = frinam - frfboa, per revisionjb02). - Checks if the record is already in
ap125pwand setss1flagto'*'if present.
- Populates subfile fields (
-
Color Coding (
sf1colSubroutine):- Placeholder for color-coding subfile records (currently empty but reserved for visual indicators).
-
Add Invoice to Batch (
sf1s01Subroutine):- Chains to
ap125pwto check if the record exists. - If not, writes a new record with company, carrier ID, invoice number, record type (
s1rcd), and reference number (s1rdno). - Updates the total invoice amount (
c1inam).
- Chains to
-
Remove Invoice from Batch (
sf1s04Subroutine):- Chains to
ap125pwto locate the record. - If found, deletes it and subtracts the invoice amount from
c1inam.
- Chains to
-
Process All Records (
sf1prcallandsf1prcall2Subroutines):- Displays a window (
addwdwfor adding,rmvwdwfor removing) and processes all displayed records. - Iterates through
frcinhj4, applies filters, and callssf1s01(add) orsf1s04(remove) based onw$add.
- Displays a window (
-
Create Batch (
crtbatSubroutine):- Reads
ap125pwrecords and chains tofrcinhorfrcfbhbased onw1rcd. - For approved (
fralst = 'Y',frapst = 'N') records, callsAP125with parameters (o$co,o$caid,o$cain,o$rcd,o$rdno) to create the batch.
- Reads
-
Field Prompting (
promptSubroutine):- For the
C1CAIDfield, callsLBBCAIDto prompt for a carrier ID, passingc1co,c1caid, andp$fgrp.
- For the
-
Message Handling (
addmsg,wrtmsg,clrmsgSubroutines):addmsg: Sends error messages (e.g.,ERR0010,ERR0020) to the program message queue usingQMHSNDPM.wrtmsg: Displays the message subfile (msgctl).clrmsg: Clears the message subfile usingQMHRMVPM.
-
Program Termination:
- Closes all files and sets
*inlr = *onto end the program.
- Closes all files and sets
Business Rules¶
The program enforces the following business rules:
1. Invoice Filtering:
- Only approved invoices (fralst = 'Y', frapst = 'N') are eligible for selection.
- Invoices must match the specified invoice type (p$inty, P or N).
- Invoices with zero amounts are excluded (revision jb03).
- Carrier ID (c1caid) must match if specified, otherwise all carriers are included.
- Invoice Amount Adjustment:
-
The displayed invoice amount (
s1inam) is calculated asfrinam - frfboa(Freight Balancing Order Override Total, revisionjb02). -
Date Usage:
-
Uses the order ship date (
boshd8fromfrbinh) instead of the invoice date (frindt, revisiondc01) for filtering and display. -
Batch Processing:
- Invoices are added to or removed from
ap125pwbased on user selections (options 1 or 4, or F22/F23). -
Batch creation (
crtbat) only processes approved invoices with valid status codes. -
Mode-Based Access:
- In
MNTmode, users can add/remove invoices and create batches. -
In inquiry mode, fields are protected (
*in70 = *on), preventing modifications. -
Validation:
- Company code (
c1co) must exist inapcont. - Carrier ID (
c1caid) must exist inbbcaid(revisionjk01). -
Dates (
c1fmdy,c1tmdy) must be valid, checked viaGSDTEDIT. -
Subfile Behavior:
- Supports
All(all eligible invoices) andReview(only invoices inap125pw) modes. - Displays a "No Records Found" message if no invoices meet the criteria.
Tables (Files) Used¶
- Display File:
-
ap125pd: Display file with subfilesfl1, used for the user interface. -
Input Files:
apcont: Accounts Payable control file (company data).frbinh: Freight Out Balancing Customer Invoice Header (for order ship date).frcinh: Freight Invoice Header.frcfbh: Freight Billed Balance Header (revisionjb02).bbcaid: Carrier ID table (replacinggstabl, revisionjk01).-
frcinhj4: Multi-file logical file combiningfrcinhandfrcfbh(replacingfrcinh4, revisionjb02). -
Add/Update File:
ap125pw: Work file inqtempfor storing selected invoices.
External Programs Called¶
- AP125PC:
-
Called in
crtwrkfto create or clear theap125pwwork file. -
GSDTEDIT:
-
Called in
sf1cteto validate and convert dates (c1fmdy,c1tmdy). -
AP125:
-
Called in
crtbatto create the invoice batch, passing company, carrier ID, invoice number, record type, and reference number. -
LBBCAID:
-
Called in
promptto provide carrier ID prompting, replacingLGSTABL(revisionjk01). -
QCMDEXC:
-
System program to execute override commands (
ovrdbf) inopntblandcrtwrkf. -
QMHSNDPM:
-
System program to send error messages to the program message queue in
addmsg. -
QMHRMVPM:
- System program to clear the message subfile in
clrmsg.
Summary¶
The AP125P program is a user-interactive RPGLE program for selecting freight invoices for batch processing. It uses a subfile interface to display invoices from frcinhj4, allows users to add/remove invoices to/from ap125pw, and creates batches via AP125. Key features include filtering by approval status, invoice type, and non-zero amounts, using order ship dates, and supporting maintenance/inquiry modes. The program integrates with multiple files and external programs to validate data and manage the batch process.
If you need further details or clarification on specific subroutines, business rules, or file structures, please let me know!