BB943P RPGLE
The RPG program BB943P.rpgle
is an IBM i (AS/400) program designed for "Work With Customer Sales Agreements." It provides an interactive interface using a display file with subfiles to manage customer sales agreement records. The program supports maintenance and inquiry modes, allowing users to view, add, copy, delete, or display sales agreement records. Below, I will explain the process steps, business rules, tables used, and external programs called, based on the provided RPG source code.
Process Steps of the RPG Program¶
The BB943P
program follows a structured flow typical of RPG interactive applications on IBM i, using a display file with a subfile to present and manage data. Here are the key process steps:
- Initialization (
*inzsr
Subroutine): - Parameters: The program receives two input parameters:
p$mode
(3 characters): Determines the run mode, either 'MNT' (maintenance) or 'INQ' (inquiry).p$fgrp
(1 character): Specifies the file group ('G' or 'Z'), which determines the database files to use via overrides.
- File Overrides: Based on
p$fgrp
, the program applies database file overrides (ovg
for 'G' orovz
for 'Z') to point to the appropriate files (e.g.,garcust
orzarcust
). - File Opens: Opens all required database files (
arcust
,bicont
,bicuag
,gscntr1
,gsprod
,gstabl
,inloc
,shipto
,bicuax
,bicua10
) withUSROPN
to control file access. -
Variable Initialization: Sets up work fields, subfile control fields, and message handling fields. Initializes the current date and time for use in processing.
-
Open Database Tables (
opntbl
Subroutine): - Executes the
QCMDEXC
API to apply file overrides based onp$fgrp
. -
Opens all input files for reading, ensuring the program can access customer, sales agreement, and related data.
-
Process Subfile (
srsfl1
Subroutine): - Clear Message Subfile: Calls
clrmsg
to clear any existing messages in the message subfile. - Initialize Subfile: Sets the subfile mode to 'folded' (
sfmod1 = '1'
,*in45 = *on
) for the initial load and initializes control fields (e.g.,c1cono
to 10). - Set Filters: Initializes the expired entries filter (
w$expd = *off
,F8=Incl Del
) and the ascending/descending sort order (f13sel = 'D'
,F13=Descend
). - Global Protection: Sets
*in70
(global protect) based onp$mode
. In 'INQ' mode, fields are protected (*in70 = *on
); in 'MNT' mode, fields are editable (*in70 = *off
). - Position File: Calls
sf1rep
to position the file cursor based on user input or defaults. -
Main Loop:
- Displays the command line and message subfile.
- Checks for existing subfile records to enable/disable display (
*in41
). - Sets folded/unfolded mode for the subfile (
*in45
). - Displays the subfile control record (
sflctl1
) usingEXFMT
. - Processes user input (function keys, cursor location, and subfile records).
-
Handle User Input:
-
Function Keys:
- F03 (Exit): Exits the program by setting
sf1agn = *off
. - F04 (Prompt): Calls
prompt
to allow field-specific prompting (e.g., customer, ship-to, location). - F05 (Refresh): Triggers a subfile refresh by setting
repsfl = *on
. - F08 (Toggle Expired Entries): Toggles the
w$expd
flag to include/exclude expired entries and updates the subfile. - F09 (History Inquiry): Calls
histinq
to invokeGB730P
for customer history inquiry. - F13 (Toggle Ascend/Descend): Toggles the sort order (
f13sel
between 'A' and 'D') and refreshes the subfile. - PAGEDN (Page Down): Calls
sf1lod
to load additional subfile records. - ENTER: Validates the password (
validatepw
) and processes subfile records (sf1prc
). - F06 (Add): Validates the password and calls
sf1add
to add a new record. - F10 (Position Cursor): Clears cursor position to focus on the control record.
- Control Field Changes: If control fields (e.g.,
c1cono
,c1cust
) change, repositions the subfile viasf1rep
.
- F03 (Exit): Exits the program by setting
-
Process Subfile Records (
sf1prc
Subroutine): - Reads changed subfile records (
readc sfl1
) and processes them viasf1chg
. -
Handles options selected in the subfile (e.g., 2=Change, 3=Copy, 4=Delete, 5=Display).
-
Process Subfile Options (
sf1chg
Subroutine): - Option 2 (Change): If in 'MNT' mode and the record is not deleted, calls
sf1s02
to modify the record. - Option 3 (Copy): If in 'MNT' mode and not deleted, calls
sf1s03
to copy the record. - Option 4 (Delete): If in 'MNT' mode, calls
sf1s04
to delete the record. - Option 5 (Display): Calls
sf1s05
to display the record details. -
Updates the subfile record after processing.
-
Reposition Subfile (
sf1rep
Subroutine): - Clears the subfile (
sf1clr
). - Validates control field input (
sf1cte
). - Positions the file cursor based on sort order (
f13sel
) and user input (e.g.,c1cono
,c1cust
,c1cntr
). -
Loads the subfile (
sf1lod
). -
Edit Control Fields (
sf1cte
Subroutine): - Validates the company (
c1cono
) and customer (c1cust
) fields againstbicont
andarcust
files. -
Sets error messages if validation fails (e.g.,
ERR0010
for invalid company). -
Subfile Option Processing:
- Copy (
sf1s03
): CallsBB943
to copy a record, passing parameters like company, status, and sequence number. Displays success (ERR0000
,com(04)
) or failure (com(09)
) messages. - Delete (
sf1s04
): CallsBB944
to mark a record as deleted ('D') or reactivated ('A'), displaying appropriate messages (com(05)
orcom(06)
). - Display (
sf1s05
): CallsBB943
in 'INQ' mode to display record details. -
History Inquiry (
histinq
): CallsGB730P
with customer history parameters. -
Message Handling:
- Add Message (
addmsg
): Sends messages to the program message queue usingQMHSNDPM
. - Write Message (
wrtmsg
): Writes messages to the message subfile. - Clear Message (
clrmsg
): Clears the message subfile usingQMHRMVPM
.
- Add Message (
-
Program Termination:
- Closes all files (
close *all
). - Sets
*inlr = *on
and returns.
- Closes all files (
Business Rules¶
The program enforces several business rules to ensure proper management of customer sales agreements:
- Mode-Based Access Control:
- In 'MNT' mode, users can add, change, copy, or delete records (
*in70 = *off
for editable fields). -
In 'INQ' mode, fields are protected (
*in70 = *on
), allowing only viewing. -
Validation of Input:
- Company (
c1cono
) and customer (c1cust
) must exist inbicont
andarcust
files, respectively, or an error (ERR0010
) is displayed. -
Ship-to codes require a valid customer code (
com(01)
). -
Password Validation:
- For add or copy operations, a password (
c1agpw
) is required unless blank, in which case it defaults to 'N' (w$validpw
). -
The password is validated via
validatepw
and passed to called programs. -
Expired Records Filter:
- Users can toggle inclusion/exclusion of expired records using F8 (
w$expd
andfky
labels). -
Expired records are filtered based on the
w$expd
flag during subfile loading. -
Sort Order:
-
Users can toggle ascending (
f13sel = 'A'
) or descending (f13sel = 'D'
) sort order using F13, affecting how records are loaded into the subfile. -
Record Status:
- Deleted records (
s1del = 'D'
) cannot be modified (com(08)
). -
Copy operations check for expired records and display a message if applicable (
com(11)
). -
Partial PO Data Entry:
-
As of revision
jk06
(08/31/18), the program supports partial purchase order (PO) data entry for scanning purposes. -
Container Type Restriction:
-
As of revision
jb07
(07/22/24), users cannot enter container types in sales agreements, restricting input flexibility. -
Subfile Options:
- Option 2 (Change): Allowed in 'MNT' mode for non-deleted records.
- Option 3 (Copy): Copies a record to a new sequence number, with success or failure messages.
- Option 4 (Delete): Marks records as deleted ('D') or reactivated ('A').
-
Option 5 (Display): Displays record details in inquiry mode.
-
Error and Success Messages:
- Messages are displayed for actions like record creation (
com(02)
), change (com(03)
), copy (com(04)
), deletion (com(05)
), reactivation (com(06)
), or errors (e.g.,com(09)
,com(11)
).
- Messages are displayed for actions like record creation (
Tables Used¶
The program uses the following database files, with overrides applied based on p$fgrp
('G' or 'Z'):
- arcust: Customer master file, containing customer details (e.g., customer ID, name).
- bicont: Company master file, containing company details.
- bicuag: Sales agreement file, primary file for customer sales agreements.
- gscntr1: Container file (replaced
gscntr
per revisionjk05
), with an alpha key. - gsprod: Product file, containing product details.
- gstabl: Table file, likely for reference data (e.g., container types).
- inloc: Location file, containing location details.
- shipto: Ship-to file, containing ship-to addresses.
- bicuax: Renamed sales agreement file (record format
bicuagp1
), used for specific key access. - bicua10: Renamed sales agreement file (record format
bicuagp2
), used for alternate key access (per revisionjk02
).
The overrides (ovg
and ovz
) map these files to specific libraries (e.g., garcust
or zarcust
), ensuring the correct dataset is used based on the file group.
External Programs Called¶
The program calls the following external programs:
- QCMDEXC: System API to execute file override commands.
- QMHSNDPM: System API to send messages to the program message queue.
- QMHRMVPM: System API to remove messages from the message queue.
- BB943: Called for copy (option 3) and display (option 5) operations, passing parameters like company, status, sequence number, and mode ('MNT' or 'INQ').
- BB944: Called for delete (option 4) operations, handling record deletion or reactivation.
- GB730P: Called for history inquiry (F9), passing customer history parameters.
- LARCUST: Called for customer field prompting (F4 on
C1CUST
), returning a selected customer. - LCSTSHP: Called for ship-to field prompting (F4 on
C1SHIP
), returning customer and ship-to codes. - LINLOC: Called for location field prompting (F4 on
C1LOC
), returning a selected location. - LGSCNCD: Called for container field prompting (F4 on
C1CNTR
), returning a container code. - LGSPROD: Called for product field prompting (F4 on
C1PRCD
), returning a product code.
Note: A commented-out call to BB947
suggests it was previously used for copy operations but has been replaced by BB943
.
Summary¶
- Process Steps: The program initializes parameters and files, opens database tables, displays a subfile for user interaction, processes function keys (F3, F4, F5, F8, F9, F13, etc.), validates input, and handles subfile options (change, copy, delete, display). It uses message subfiles for feedback and closes files upon termination.
- Business Rules: Enforces mode-based access ('MNT' vs. 'INQ'), validates company/customer input, requires passwords for certain actions, supports expired record filtering, toggles sort order, restricts container type entry, and provides feedback via messages.
- Tables Used:
arcust
,bicont
,bicuag
,gscntr1
,gsprod
,gstabl
,inloc
,shipto
,bicuax
,bicua10
. - External Programs Called:
QCMDEXC
,QMHSNDPM
,QMHRMVPM
,BB943
,BB944
,GB730P
,LARCUST
,LCSTSHP
,LINLOC
,LGSCNCD
,LGSPROD
.
If you need a deeper analysis of specific subroutines, file structures, or called programs (e.g., BB943
or BB944
), please provide their source code or additional details. Alternatively, I can perform a DeepSearch for related information if you enable that mode. Let me know how to proceed!