The provided RPGLE programs, BB931
and MGSTABL
, form a call stack where BB931
is the main program for managing flat freight codes, and MGSTABL
is a utility program for table value lookups, specifically for selecting valid units of measure. Below, I’ll identify the use cases implemented by this call stack and then provide a function requirement document for one of the use cases, reimagined as a non-interactive function that processes inputs directly.
List of Use Cases Implemented in the Call Stack¶
The call stack (BB931
calling MGSTABL
) supports the following use cases, derived from the functionality of BB931
and its interaction with MGSTABL
. Each use case represents a distinct user goal within the flat freight code maintenance/inquiry system.
- Inquire Flat Freight Codes:
- Description: Allows users to view existing flat freight codes for a specific company and optionally filter by freight code without modifying data.
-
Details:
- Run mode:
INQ
(Inquiry). - Displays a subfile of freight code records from
BBFRTB
(orBBFRTBRD
for reading) based on company code (c1cono
) and optional freight code (c1frcd
). - Users can reposition the subfile using control fields and navigate pages with the Page Down key.
- Fields are protected (
*IN71 = *ON
) to prevent modifications. - No database updates are performed.
- Run mode:
-
Maintain Flat Freight Codes (Add):
- Description: Enables users to add new flat freight codes to the database.
-
Details:
- Run mode:
MNT
(Maintenance), Entry mode (s1updt = *OFF
). - Users enter a new freight code (
s1frcd
), rate (s1rate
), freight label (s1frlb
), unit of measure (s1frum
), and unit of measure rate (s1frpu
) in the subfile. - Validates that the freight code does not already exist in
BBFRTB
. - Validates company code (
c1cono
) againstBICONT
and unit of measure (s1frum
) againstGSTABL
(viaMGSTABL
). - Writes a new record to
BBFRTB
with the provided values.
- Run mode:
-
Maintain Flat Freight Codes (Update):
- Description: Allows users to update existing flat freight codes.
-
Details:
- Run mode:
MNT
, Update mode (s1updt = *ON
). - Users modify non-key fields (
s1rate
,s1frlb
,s1frum
,s1frpu
) for existing freight codes in the subfile. - Validates company code and unit of measure as above.
- Updates the corresponding record in
BBFRTB
.
- Run mode:
-
Delete Flat Freight Codes:
- Description: Permits users to delete existing flat freight codes.
-
Details:
- Run mode:
MNT
. - Users select a record with F23, confirm deletion in a window (
sfldel1
), and press F23 again to delete. - Deletes the record from
BBFRTB
if it exists and clears the subfile record.
- Run mode:
-
Look Up Unit of Measure:
- Description: Provides a lookup interface to select a valid unit of measure code from
GSTABL
, used byBB931
fors1frum
. - Details:
- Called by
BB931
when F04 is pressed for theS1FRUM
field. - Displays a subfile of
GSTABL
records filtered by table type (p$type
, e.g.,BIUNMS
) and optional search string (c$srch
). - Users select a record (option
1
), and the selected code (tbcode
) is returned toBB931
asp$code
. - Validates the table type against
GSTABL
and filters descriptions if a search string is provided.
- Called by
Function Requirement Document: Add/Update Flat Freight Code Function¶
Function Name: AddUpdateFlatFreightCode
Purpose: To add a new flat freight code or update an existing one in the database based on provided inputs, ensuring data integrity through validation against company and unit of measure tables.
Inputs:
- Company Code (companyCode
): Numeric, 2 digits, required. Identifies the company.
- Freight Code (freightCode
): Character, length as defined in BBFRTB
, required. Unique identifier for the freight code.
- Freight Rate (freightRate
): Numeric, as defined in BBFRTB
, optional. The flat freight rate.
- Freight Label (freightLabel
): Numeric, as defined in BBFRTB
, optional. Additional identifier or label.
- Unit of Measure (unitOfMeasure
): Character, as defined in GSTABL
, optional. The unit of measure code.
- Unit of Measure Rate (unitOfMeasureRate
): Numeric, as defined in BBFRTB
, optional. Rate associated with the unit of measure.
- Mode (mode
): Character, 3 characters, required. Either ADD
(add new record) or UPD
(update existing record).
- File Group (fileGroup
): Character, 1 character, required. Either G
(use GBBFRTB
, GBICONT
, GGSTABL
) or Z
(use ZBBFRTB
, ZBICONT
, ZGSTABL
).
Outputs:
- Success Flag (success
): Boolean. Indicates whether the operation was successful.
- Error Message (errorMessage
): Character, 80 characters. Contains error details if the operation fails.
- Company Name (companyName
): Character, as defined in BICONT
. Name of the validated company.
- Unit of Measure Description (unitOfMeasureDesc
): Character, as defined in GSTABL
. Description of the validated unit of measure.
Process Steps:
1. Apply File Overrides:
- Based on fileGroup
, apply database overrides to use the correct files (G
or Z
group).
- Example: For G
, override BICONT
to GBICONT
, GSTABL
to GGSTABL
, BBFRTB
to GBBFRTB
.
- Validate Company Code:
- Query
BICONT
withcompanyCode
. - If not found or zero, return
success = false
,errorMessage = "Invalid company code"
. -
Retrieve
companyName
fromBICONT
. -
Validate Unit of Measure:
- If
unitOfMeasure
is provided, queryGSTABL
withtableType = 'BIUNMS'
andtableCode = unitOfMeasure
. - If not found, return
success = false
,errorMessage = "Invalid unit of measure"
. - Retrieve
unitOfMeasureDesc
fromGSTABL
. -
If
unitOfMeasure
is provided,unitOfMeasureRate
must be non-zero, and vice versa. If inconsistent, returnsuccess = false
,errorMessage = "Must provide both unit of measure and rate or neither"
. -
Validate Input Data:
- Ensure at least one of
freightRate
,freightLabel
,unitOfMeasure
, orunitOfMeasureRate
is provided. -
If all are blank/zero, return
success = false
,errorMessage = "Must provide at least one value"
. -
Check Freight Code Existence:
- For
mode = ADD
, queryBBFRTB
withcompanyCode
andfreightCode
.- If found, return
success = false
,errorMessage = "Freight code already exists"
.
- If found, return
-
For
mode = UPD
, queryBBFRTB
withcompanyCode
andfreightCode
.- If not found, return
success = false
,errorMessage = "Freight code does not exist"
.
- If not found, return
-
Perform Database Operation:
- For
mode = ADD
:- Create a new record in
BBFRTB
withcompanyCode
,freightCode
,freightRate
,freightLabel
,unitOfMeasure
, andunitOfMeasureRate
.
- Create a new record in
- For
mode = UPD
:- Update the existing record in
BBFRTB
with the provided non-key fields (freightRate
,freightLabel
,unitOfMeasure
,unitOfMeasureRate
).
- Update the existing record in
-
Commit the operation.
-
Return Results:
- Set
success = true
, clearerrorMessage
, and returncompanyName
andunitOfMeasureDesc
if validations and operations succeed. - Otherwise, return
success = false
with the appropriateerrorMessage
.
Business Rules:
1. Company Code Validation: Must exist in BICONT
. Zero or invalid codes are rejected.
2. Unit of Measure Consistency: If a unit of measure is provided, its rate must be non-zero, and vice versa.
3. Non-Empty Input: At least one non-key field (freightRate
, freightLabel
, unitOfMeasure
, unitOfMeasureRate
) must be provided.
4. Unique Freight Code: In ADD
mode, the freight code must not already exist for the given company.
5. Existing Freight Code: In UPD
mode, the freight code must exist for the given company.
6. File Group Selection: The correct file group (G
or Z
) must be specified to access the appropriate database files.
7. Data Integrity: Only non-key fields can be updated in UPD
mode; key fields (companyCode
, freightCode
) are protected.
Calculations:
- No complex calculations are performed. The function moves input values directly to the database fields after validation.
- The unit of measure description is retrieved from GSTABL
but involves no computation.
Dependencies:
- Files: BICONT
(company validation), GSTABL
(unit of measure validation), BBFRTB
(freight code storage).
- External Program: None required, as the function performs direct database operations.
Error Handling: - Returns specific error messages for invalid company code, unit of measure, inconsistent unit of measure/rate, missing values, or freight code existence issues. - Ensures database operations are only performed if all validations pass.
Notes:
- This function replaces the interactive subfile processing in BB931
and the unit of measure lookup in MGSTABL
with direct input validation and database operations.
- Assumes the database files are accessible with the correct overrides applied based on fileGroup
.
Function Requirement Document: AddUpdateFlatFreightCode¶
Purpose¶
Add or update a flat freight code in the database, ensuring data integrity through validation against company and unit of measure tables.
Inputs¶
- companyCode: Numeric, 2 digits, required. Company identifier.
- freightCode: Character, per
BBFRTB
, required. Unique freight code. - freightRate: Numeric, per
BBFRTB
, optional. Flat freight rate. - freightLabel: Numeric, per
BBFRTB
, optional. Freight label. - unitOfMeasure: Character, per
GSTABL
, optional. Unit of measure code. - unitOfMeasureRate: Numeric, per
BBFRTB
, optional. Unit of measure rate. - mode: Character, 3 chars, required.
ADD
orUPD
. - fileGroup: Character, 1 char, required.
G
orZ
for file selection.
Outputs¶
- success: Boolean. Operation success status.
- errorMessage: Character, 80 chars. Error details if failed.
- companyName: Character, per
BICONT
. Validated company name. - unitOfMeasureDesc: Character, per
GSTABL
. Unit of measure description.
Process Steps¶
- Apply File Overrides: Use
fileGroup
to override toG
(GBICONT
,GGSTABL
,GBBFRTB
) orZ
(ZBICONT
,ZGSTABL
,ZBBFRTB
) files. - Validate Company Code: Query
BICONT
withcompanyCode
. If invalid or zero, returnsuccess = false
,errorMessage = "Invalid company code"
. SetcompanyName
. - Validate Unit of Measure: If
unitOfMeasure
provided, queryGSTABL
withtableType = 'BIUNMS'
. If invalid, returnsuccess = false
,errorMessage = "Invalid unit of measure"
. SetunitOfMeasureDesc
. EnsureunitOfMeasure
andunitOfMeasureRate
are both provided or neither. - Validate Input Data: Ensure at least one of
freightRate
,freightLabel
,unitOfMeasure
, orunitOfMeasureRate
is non-blank/zero. If not, returnsuccess = false
,errorMessage = "Must provide at least one value"
. - Check Freight Code Existence:
ADD
: IfcompanyCode
andfreightCode
exist inBBFRTB
, returnsuccess = false
,errorMessage = "Freight code already exists"
.UPD
: If not found, returnsuccess = false
,errorMessage = "Freight code does not exist"
.- Perform Database Operation:
ADD
: Write new record toBBFRTB
with input values.UPD
: Update existing record’s non-key fields inBBFRTB
.- Return Results: Set
success = true
, clearerrorMessage
, returncompanyName
andunitOfMeasureDesc
if successful.
Business Rules¶
- Company Code: Must exist in
BICONT
. - Unit of Measure: If provided, must exist in
GSTABL
withtableType = 'BIUNMS'
, andunitOfMeasureRate
must be non-zero (and vice versa). - Non-Empty Input: At least one non-key field must be provided.
- Unique Freight Code: Must not exist for
ADD
, must exist forUPD
. - File Group:
G
orZ
determines database files. - Data Integrity: Key fields (
companyCode
,freightCode
) are protected inUPD
.
Calculations¶
- No calculations; input values are moved to database fields after validation.
- Retrieves
companyName
andunitOfMeasureDesc
from respective files.
Dependencies¶
- Files:
BICONT
,GSTABL
,BBFRTB
. - External Programs: None.
Error Handling¶
- Returns specific messages for invalid company code, unit of measure, inconsistent unit of measure/rate, missing values, or freight code issues.
- Database operations only proceed if validations pass.