AR810U RPGLE
The provided RPGLE program, AR810U.rpgle, is an AR (Accounts Receivable) Invoice Inquiry program written in free-format RPGLE for an IBM i system. It displays invoice details for a given company and customer in a subfile (a scrolling list on a workstation display). Below is an explanation of the process steps, followed by the external programs called and the tables (files) used.
Process Steps of the AR810U Program¶
- Program Initialization (OneTime Subroutine):
- Check Genie Environment: The program calls
GSGENIE2Cto determine if it’s running in the Genie environment (a web-based interface). Ifgenievaris not 'YES', the program terminates immediately. - Set Default Company: Retrieves the default company (
gxcono) from theGSCONTfile. If found and non-zero, sets the company code (cco) and positions the cursor on the customer field (*in11 = *ON). Otherwise, positions the cursor on the company field (*in11 = *OFF). -
Set Default Open Invoices: Sets the
cOPENflag to 'O' to display only open invoices by default. -
Main Processing Loop:
- The program enters a
DoW(Do While) loop that continues until theEXITindicator is turned on (e.g., user presses a function key to exit). - Clear Subfile: Initializes the subfile control indicators (
SFLDSP,SFLCLR), clears subfile variables (MORE,sftermI,sfamt,invdatI,invdt8I), and writes the subfile control record (SFLCTL1) to clear the subfile. -
Check Subfile Display: If the subfile is ready to display (
SFLDSP = *On), the program proceeds to retrieve company and customer data. -
Retrieve Company and Customer Data (GetCo Subroutine):
- Retrieve AR Control Data: Reads the
ARCONTfile using the company code (cco). If not found, initializes aging bucket limits (aclmt1,aclmt2,aclmt3,aclmt4) to zero. - Set Aging Bucket Headings: Defines aging bucket descriptions (
xAGE1toxAGE5) based on the AR control limits (aclmt1toaclmt4). For example:xAGE1 = 'CURRENT'xAGE2 = ' 1 - ' + aclmt1- Assigns these to subfile fields (
cage1tocage5).
-
Retrieve Customer Master: Reads the
ARCUSTfile using the company (cco) and customer (ccust) keys. If not found, sets customer details (e.g.,arname,aradr1, etc.) to indicate "Customer Master not found" or blanks. -
Load Subfile (Main Loop):
- Read AR Detail Records: Sets the lower limit (
SetLL) on theARDETLfile using company (cco) and customer (ccust) keys, then reads records in aDoWloop usingReadE. - Filter Records:
- Skips deleted (
adDEL = 'D') or inactive (adDEL = 'I') records. - Skips open payment (
ADTYPE = 'P') or adjustment (ADTYPE = 'J') records whencOPEN = 'O'. - Skips fully paid invoices (
ADTYPE = 'I'andADPART + ADPAY = ADAMT) whencOPEN = 'O'.
- Skips deleted (
- Populate Subfile (SFfill Subroutine): For valid records, fills subfile fields:
- Convert Dates: Converts transaction (
adtym8) and due dates (addud8) fromYYYYMMDDtoMM/DD/YYYYformat for display (trdat,dudat). - Handle Record Types:
- Invoice ('I'):
- Sets
sftype = ' INVOICE'andsftypeI = '1'. - Calculates open amount (
sfamt = adamt - adpart - adpay) ifcOPEN = 'O', else usesadamt. - Retrieves terms description from
GSTABLusing the terms code (adterm). If not found, uses the terms code as the description. - Sets invoice date (
invdat,invdatI) totrdat.
- Sets
- Adjustment ('J'):
- Sets
sftype = 'ADJUST '. - Uses
adamtassfamt. - Calls
GetDaysto calculate days between transaction and due dates.
- Sets
- Payment ('P'):
- Sets
sftype = 'PAYMENT'. - Uses
adamtassfamt. - Calls
GetDaysto calculate days.
- Sets
- Aging Description: Assigns the aging bucket description (
sfage) based on theadagevalue (1 to 5, mapping tocage1tocage5).
- Convert Dates: Converts transaction (
-
Write Subfile Record: Increments the relative record number (
RRN) and writes the subfile record (SFL1). IfRRNexceeds 9990, setsMOREto indicate not all records are displayed and exits the loop. -
Display Subfile:
-
Sets
SFLDSP = *Onand executesExFmtto display the subfile control record (SFLCTL1) on the workstation screen, allowing user interaction (e.g., scrolling, selecting records, or exiting). -
Repeat or Exit:
- After displaying the subfile, the program loops back to check if
EXITis turned on. If not, it repeats the process (e.g., clears subfile, reloads data if user changes input). IfEXITis on, the program sets*InLr = *Onand terminates.
External Programs Called¶
- GSGENIE2C:
- Purpose: Checks if the program is running in the Genie environment by setting the
genievarvariable to 'YES' or 'NO'. -
Parameters:
genievar(char(3)): Output parameter indicating Genie environment status.
-
GSDTCLC2:
- Purpose: Calculates the difference in days between two dates.
- Parameters:
p#dat1(Packed(8:0)): First date inCCYYMMDDformat.p#dat2(Packed(8:0)): Second date inCCYYMMDDformat.p#fmt(char(1)): Format of difference ('D' for days).p#diff(Packed(10:2)): Output for the calculated difference.p#err(char(1)): Error flag.
Tables (Files) Used¶
- AR810UD:
- Type: Workstation file (display file).
- Usage: External (
*Ext), handled by Profound UI (PROFOUNDUI(HANDLER)). -
Description: Contains the subfile (
SFL1) and control record (SFLCTL1) for displaying invoice inquiry data on the screen. -
ARDETL:
- Type: Disk file (database file).
- Usage: Input, keyed.
-
Description: Stores AR transaction details (e.g., invoices, payments, adjustments). Keyed by company (
cco) and customer (ccust). Fields includeadDEL,ADTYPE,ADPART,ADPAY,ADAMT,adtym8,addud8,adage,adterm. -
GSCONT:
- Type: Disk file.
- Usage: Input, keyed.
-
Description: Stores general system control data, including the default company code (
gxcono). Keyed bygskey. -
ARCONT:
- Type: Disk file.
- Usage: Input, keyed.
-
Description: Stores AR control data, including aging bucket limits (
aclmt1,aclmt2,aclmt3,aclmt4). Keyed by company (cco). -
ARCUST:
- Type: Disk file.
- Usage: Input, keyed.
-
Description: Stores customer master data (e.g., name, address). Keyed by company (
cco) and customer (ccust). Fields includearname,aradr1,aradr2,aradr3,aradr4,arzip5. -
GSTABL:
- Type: Disk file.
- Usage: Input, keyed.
- Description: Stores general system table data, including terms descriptions (
TBDESC). Keyed by a composite key (ARTERM+ terms code).
Summary¶
The AR810U program is designed to display AR invoice details for a specific company and customer in a subfile, filtering out deleted records and optionally showing only open invoices. It retrieves data from multiple files, calculates aging buckets, and formats dates for display. The program interacts with the user through a workstation display and terminates when the user exits. It relies on two external programs (GSGENIE2C and GSDTCLC2) for environment checks and date calculations, and uses five database files (ARDETL, GSCONT, ARCONT, ARCUST, GSTABL) for data retrieval, along with the AR810UD display file for user interaction.