BB929 RPGLE
The BB929
RPGLE program is part of the Billing and Invoicing system and is designed for CSR (Customer Service Representative) ID Entry Maintenance and Inquiry. It is called by the main program BB929P
to handle the creation, modification, or inquiry of individual CSR records. Below, I will explain the process steps, outline the business rules, list the tables used, and identify any external programs called.
Process Steps of the RPGLE Program (BB929
)¶
The program is an interactive workstation-based application that uses a display file (bb929d
) to present a single record format (FMT01
) for maintaining or inquiring CSR ID records. It operates in either maintenance (MNT
) or inquiry (INQ
) mode, allowing users to create or update CSR records or view them without modification. Below is a step-by-step explanation of its process flow, based on the mainline logic and subroutines:
- Program Initialization (
*inzsr
Subroutine): - Parameter Reception: The program receives five parameters:
p$co
: Company number (input).p$crid
: CSR ID (input).p$mode
(3 characters): Run mode (MNT
for maintenance,INQ
for inquiry).p$fgrp
(1 character): File group (Z
orG
) for database overrides.p$flag
(1 character): Return flag (output, set to1
on successful update/create).
- Field Initialization:
- Moves input parameters
p$co
andp$crid
to display file fieldsf$co
andf$crid
. - Initializes output parameters (
o$co
,o$crid
,o$mode
,o$fgrp
,o$flag
) to blanks or zeros. - Sets up message handling fields (
dspmsg
,m@pgmq
,m@key
). - Defines key list
klcsr
for accessing thebbcsr
file usingf$co
andf$crid
. - Initializes flags (
fmtagn
,delagn
,winagn
) to*OFF
.
- Moves input parameters
-
Commented Test Code: Includes commented-out code for testing with hardcoded values (e.g.,
p$mode = 'MNT'
). -
Open Database Tables (
opntbl
Subroutine): - File Overrides: Based on
p$fgrp
(Z
orG
), applies database overrides using theQCMDEXC
API to redirect file access to the appropriate library (gbbcsr
orzbcsr
forbbcsr
,gbicont
orzbicont
forbicont
). - File Opening: Opens two files:
bbcsr
(update/add, keyed access).bicont
(input-only, keyed access).
-
Company Validation: Chains to
bicont
usingf$co
to validate the company number (no specific error handling is implemented here). -
Retrieve Data (
rtvdta
Subroutine): - Record Retrieval: Chains to
bbcsr
using the key listklcsr
(f$co
,f$crid
) to check if the record exists.- If
*IN99
is*ON
(record not found), clears thebbcsrpf
record format and setsw$exists
to*OFF
. - If
*IN99
is*OFF
(record found), setsw$exists
to*ON
.
- If
-
Header and Protection Setup:
- If
p$mode
isMNT
, sets*IN70
to*OFF
(no global protection) and sets the headerc$hdr1
to "CSR Id Entry Maintenance". - If
p$mode
isINQ
, sets*IN70
to*ON
(global protection) and setsc$hdr1
to "CSR Id Inquiry".
- If
-
Process Panel Formats (
srfmt
Subroutine): - Clear Screen: Writes the
clrscr
format to clear the display. - Initialize Format: Calls
f01mov
to initialize fields for theFMT01
format and setsw$fmt
toFMT01
. -
Main Loop (
fmtagn
):- Display Messages: If
dspmsg
is*ON
, callswrtmsg
to display the message subfile; otherwise, writesclrscr
. - Clear Format Change Indicator: Sets
*IN19
to*OFF
. - Display Format:
- If
w$fmt
isFMT01
, callsf01pro
to set protection indicators and executesexfmt fmt01
to display the format and accept user input. - If
w$fmt
is notFMT01
, defaults to processingFMT01
(note:FMT02
is commented out, indicating it may not be used). - Clear Error Indicators: Resets indicators
*IN50
to*IN69
to zero. - Clear Cursor Position: Clears
row
andcol
. - Clear Messages: If
dspmsg
is*ON
, callsclrmsg
to clear the message subfile. - Process Format Input: If the current format is
FMT01
, callsf01sr
to process user input. - The loop continues until
fmtagn
is*OFF
.
- Display Messages: If
-
Process Format (
f01sr
Subroutine): -
Handle User Input:
- F04 (Field Prompting): Calls
prompt
to handle field prompting. - F10 (Position Cursor Home): Clears
row
andcol
to reposition the cursor. - F12 (Exit): Sets
fmtagn
to*OFF
to exit the loop. - Inquiry Mode: If
p$mode
isINQ
, callsf01nxt
to determine the next format (which terminates the loop since*IN19
is*OFF
). - Enter Key:
- Calls
f01edt
to validate input fields. - If no errors (
*IN50
is*OFF
) and inMNT
mode, callsupddbf
to update the database. - Calls
f01nxt
to determine the next format (terminates the loop if*IN19
is*OFF
).
- F04 (Field Prompting): Calls
-
Determine Next Format (
f01nxt
Subroutine): - If
*IN19
is*OFF
, setsfmtagn
to*OFF
to exit the main loop. -
(Note: Code for
FMT02
is commented out, suggesting onlyFMT01
is used.) -
Edit Format Input (
f01edt
Subroutine): - Validate CSR Name: If
crcrnm
(CSR name) is blank, sets errorERR0012
, sets*IN50
and*IN51
to*ON
, and callsaddmsg
. - Validate Email Address: If
cremal
(email address) is blank, sets errorERR0012
, sets*IN50
and*IN52
to*ON
, and callsaddmsg
. -
Inquiry Mode: If
p$mode
isINQ
, clears error indicators (*IN50
to*IN69
) and clears messages usingclrmsg
. -
Initialize Format Field Values (
f01mov
Subroutine): - Calls
f01edt
to validate fields. -
If errors exist (
*IN50
is*ON
), clears error indicators and messages. -
Format Protection Schemes (
f01pro
Subroutine): - Clears protection indicators
*IN70
to*IN74
to0
. - If
p$mode
is notMNT
(i.e.,INQ
), sets*IN70
to*IN73
to1
for global input protection. -
If in
MNT
mode and the record exists (w$exists
is*ON
), sets*IN71
to*ON
to protect key fields (f$co
,f$crid
). -
Update Database (
upddbf
Subroutine):- Saves the current
wkds01
(external data structure forbbcsr
) tosvds
. - Chains to
bbcsr
usingklcsr
: - If the record exists (
*IN80
is*OFF
):- If
svds
differs fromwkds01
(indicating changes), restoressvds
towkds01
, updates thebbcsrpf
record, and setsp$flag
to1
. - If no changes, forces end-of-data (
feod
) onbbcsr
.
- If
- If the record does not exist (
*IN80
is*ON
):- Clears
bbcsrpf
, restoressvds
towkds01
, setscrco
(company),crcrid
(CSR ID), andcrdel
toA
(active), writes the new record, and setsp$flag
to1
.
- Clears
- Saves the current
-
Field Prompting (
prompt
Subroutine):- Calculates cursor position (
row
,col
) usingcsrloc
. - Checks the current format (
rcdnam
=FMT01
) but has no specific logic implemented (likely a placeholder for field-specific prompting). - Sets
*IN19
to*ON
to indicate a panel format change.
- Calculates cursor position (
-
Message Handling (
addmsg
,wrtmsg
,clrmsg
Subroutines):- Add Message (
addmsg
): - Sets
dspmsg
to*ON
. - Calculates the length of
m@data
and sends a message to the program message queue usingQMHSNDPM
. - Clears message data fields.
- Write Message Subfile (
wrtmsg
): - Sets
*IN49
to*ON
and writes themsgctl
format to display messages. - Clear Message Subfile (
clrmsg
): - Sets
dspmsg
to*OFF
. - Saves and restores
rcdnam
andpagrrn
. - Clears messages using
QMHRMVPM
.
- Add Message (
-
Program Termination:
- Closes all files.
- Sets
*INLR
to*ON
and returns.
Business Rules¶
The BB929
program enforces the following business rules for managing CSR ID records:
- Operational Modes:
- Maintenance Mode (
MNT
): Allows creation and updating of CSR records. Key fields (f$co
,f$crid
) are protected if the record already exists (w$exists
is*ON
). Input validation is performed, and the database is updated if no errors occur. -
Inquiry Mode (
INQ
): Displays CSR records in read-only mode, with all input fields protected (*IN70
to*IN73
set to1
). No database updates are performed. -
Input Validation:
- CSR Name (
crcrnm
): Must not be blank; otherwise, errorERR0012
is displayed, and*IN51
is set. - Email Address (
cremal
): Must not be blank; otherwise, errorERR0012
is displayed, and*IN52
is set. -
In inquiry mode, validation errors are cleared, and no updates are attempted.
-
Database Operations:
- Create Record: If the record does not exist (
*IN80
is*ON
), a new record is written tobbcsr
withcrdel
set toA
(active). - Update Record: If the record exists and changes are detected (
svds
differs fromwkds01
), the record is updated. - No Changes: If no changes are detected, the file is set to end-of-data (
feod
). -
Success Flag: Sets
p$flag
to1
on successful create or update. -
Field Protection:
- In maintenance mode, key fields (
f$co
,f$crid
) are protected for existing records to prevent modification. -
In inquiry mode, all input fields are protected to prevent any changes.
-
File Overrides:
-
The program uses the
p$fgrp
parameter to determine the file library (Z
orG
) and applies overrides to accessgbbcsr
orzbcsr
forbbcsr
, andgbicont
orzbicont
forbicont
. -
User Interface:
- Displays a single format (
FMT01
) for entering or viewing CSR data. - Supports function keys:
- F04: Initiates field prompting (logic not fully implemented).
- F10: Repositions the cursor to the home position.
- F12: Exits the program.
-
Provides message feedback for validation errors and successful operations.
-
Message Handling:
- Uses the
GSMSGF
message file in*LIBL
for error messages (e.g.,ERR0012
for blank fields). - Displays messages in a message subfile (
msgctl
) and clears them as needed.
Tables (Files) Used¶
The program uses the following files:
1. bb929d:
- Type: Workstation file (display file).
- Usage: Contains the FMT01
format (and possibly FMT02
, commented out) for user interaction, along with a message subfile (msgctl
) and clear screen format (clrscr
).
- Handler: PROFOUNDUI(HANDLER)
for Profound UI integration.
2. bbcsr:
- Type: Physical file (update/add, keyed access).
- Usage: Stores CSR records, used for creating, updating, and retrieving records. Accessed using the key list klcsr
(f$co
, f$crid
).
- Override: Redirected to gbbcsr
or zbcsr
based on p$fgrp
.
3. bicont:
- Type: Physical file (input-only, keyed access).
- Usage: Used to validate the company number (f$co
).
- Override: Redirected to gbicont
or zbicont
based on p$fgrp
.
External Programs Called¶
The program calls the following external programs (all IBM i APIs):
1. QCMDEXC:
- Purpose: Executes file override commands to redirect bbcsr
and bicont
to the appropriate library.
- Parameters:
- dbov##
(80 characters, override command).
- dbol##
(15.5, command length).
2. QMHSNDPM:
- Purpose: Sends messages (e.g., error ERR0012
) to the program message queue for display in the message subfile.
- Parameters: Message ID, message file, message data, data length, message type, program queue, stack counter, message key, error code.
3. QMHRMVPM:
- Purpose: Clears messages from the program message queue.
- Parameters: Program queue, stack counter, message key, remove option, error code.
Summary¶
The BB929
RPGLE program, called by BB929P
, is responsible for the maintenance and inquiry of individual CSR ID records in the Billing and Invoicing system. It operates in MNT
or INQ
mode, allowing users to create or update CSR records (with validation for non-blank name and email fields) or view them in read-only mode. The program uses a single display format (FMT01
) with Profound UI integration, enforces field protection based on mode and record existence, and updates the bbcsr
file accordingly. It validates the company number against bicont
and uses file overrides to access the correct library (Z
or G
). The program relies on IBM i APIs (QCMDEXC
, QMHSNDPM
, QMHRMVPM
) for file overrides and message handling, and interacts with three files: bb929d
(display), bbcsr
(CSR data), and bicont
(company validation).