MINLBGL1
The provided RPGLE program (MINLBGL1.rpgle.txt
) is a module called by the IN873
RPG program, which itself is executed by the IN873.ocl36.txt
OCL procedure in an IBM System/36 or AS/400 environment. The MINLBGL1
program is designed to convert between pounds and net gallons using API gravity, supporting both pounds-to-gallons and gallons-to-pounds conversions. Below, I will explain the process steps, business rules, tables (files) used, and external programs called, based on the provided RPGLE source code and its context within the IN873
program.
Process Steps of the RPG Program¶
The MINLBGL1
program is a non-standalone module that performs conversions between pounds and net gallons based on API gravity. It accepts parameters from the calling program (IN873
), processes the conversion using a standardized formula, and returns the results. Here are the detailed process steps:
- Program Initialization and Parameter Definition
- Data Definitions:
KYGRAV
(3.1 numeric): API gravity, provided by the calling program.KYFACT
(7.3 numeric): Conversion factor (density in lb/gal), unused in the new formula but defined for compatibility with the old formula.KYLBS
(7.0 numeric): Input pounds (for pounds-to-gallons) or output pounds (for gallons-to-pounds).KYGAL
(7.0 numeric): Output gallons (for pounds-to-gallons) or input gallons (for gallons-to-pounds).w@wrk1
(12.10 numeric): Work field for calculating specific gravity.w@wrk2
(15.10 numeric): Work field for intermediate calculations.w@LBS
(15.0 numeric): Work field for calculated pounds.w@GAL
(15.0 numeric): Work field for calculated gallons.
- Parameter List (
*ENTRY PLIST
):- Accepts
KYGRAV
,KYLBS
, andKYGAL
as parameters.KYFACT
is commented out (per change logJB01
), indicating it is no longer used in the new formula.
- Accepts
-
Purpose: Initializes variables and sets up the parameter interface for communication with the calling program (
IN873
). -
Main Logic (
*ENTRY
) - The program checks the input parameters to determine the conversion direction:
- If
KYLBS
is non-zero, it performs a pounds-to-gallons conversion by calling theLBGL11
subroutine. - If
KYGAL
is non-zero (andKYLBS
is zero), it performs a gallons-to-pounds conversion by calling theGLLB11
subroutine.
- If
- If neither condition is met (both
KYLBS
andKYGAL
are zero), no conversion is performed. - The program includes a legacy branch (
IFNE 1
) that calls theCALC
subroutine (old formula), but this is effectively bypassed as the condition1 IFNE 1
is always false. -
Purpose: Directs the program flow based on whether pounds or gallons are provided as input.
-
Pounds-to-Gallons Conversion (
LBGL11
Subroutine) - Formula (as documented in the code):
1
Net Gallons = (Pounds / ((141.5 / (131.5 + API Gravity)) * 999.01599999999996)) * 119.8
- Step 1: Calculate specific gravity:
w@wrk1 = 141.5 / (131.5 + KYGRAV)
- Step 2: Calculate intermediate factor:
w@wrk2 = w@wrk1 * 999.01599999999996
- Step 3: Calculate gallons:
w@gal = KYLBS / w@wrk2 * 119.8
- Step 1: Calculate specific gravity:
- The result (
w@gal
) is moved toKYGAL
for return to the calling program. -
Purpose: Converts pounds to net gallons using the API gravity-based formula.
-
Gallons-to-Pounds Conversion (
GLLB11
Subroutine) - Formula (as documented in the code):
1
Pounds = (Gallons * ((141.5 / (131.5 + API Gravity)) * 999.01599999999996)) / 119.8
- Step 1: Calculate specific gravity:
w@wrk1 = 141.5 / (131.5 + KYGRAV)
- Step 2: Calculate intermediate factor:
w@wrk2 = w@wrk1 * 999.01599999999996
- Step 3: Calculate pounds:
w@lbs = KYGAL * w@wrk2 / 119.8
- Step 1: Calculate specific gravity:
- The result (
w@lbs
) is moved toKYLBS
for return to the calling program. -
Purpose: Converts gallons to pounds using the API gravity-based formula.
-
Legacy Formula (
CALC
Subroutine) - Formula (as documented in the code):
1
Net Gallons = Pounds / ((141.5 / (131.5 + API Gravity)) * 8.337193)
- Calculates specific gravity:
WRK62 = 131.5 + KYGRAV
- Calculates density:
WRK73 = 141.5 / WRK62
- Calculates factor:
KYFACT = WRK73 * 8.337193
- Calculates specific gravity:
- This subroutine is not executed in the current program flow (due to the
IFNE 1
condition being false) but is retained for legacy compatibility. -
Purpose: Previously used to calculate a conversion factor (
KYFACT
) for pounds-to-gallons conversion. -
Program Termination
- Sets the
LR
(Last Record) indicator to signal the end of processing. - Returns control to the calling program (
IN873
) with updatedKYLBS
orKYGAL
values. - Purpose: Ensures proper program completion and result return.
Business Rules¶
The program enforces the following business rules, derived from the code and comments:
- Input Exclusivity:
-
The program expects either pounds (
KYLBS
) or gallons (KYGAL
) as input, but not both. It checks which is non-zero to determine the conversion direction (pounds-to-gallons or gallons-to-pounds). -
API Gravity Requirement:
-
The conversion requires a valid API gravity (
KYGRAV
), provided by the calling program. The program does not validateKYGRAV
but assumes it is non-negative and appropriate for the formula. -
Standardized Formula:
- The program uses an API-standard formula (per change log
JB01
, 10/27/2011) for conversions:- Specific gravity =
141.5 / (131.5 + API Gravity)
- Pounds-to-gallons:
(Pounds / (Specific Gravity * 999.01599999999996)) * 119.8
- Gallons-to-pounds:
(Gallons * (Specific Gravity * 999.01599999999996)) / 119.8
- Specific gravity =
-
The constants
999.01599999999996
and119.8
are part of the API-standard formula, likely accounting for density adjustments and unit conversions (e.g., for petroleum products). -
Direct Calculation:
-
Unlike the old formula (in
CALC
), which calculated a factor (KYFACT
), the new formula (perJB01
) directly calculates the output (gallons or pounds) and returns it viaKYGAL
orKYLBS
. -
No File Access:
- The program relies entirely on parameters passed from the calling program and does not access any files or tables, ensuring it is a lightweight calculation module.
Tables Used¶
The MINLBGL1
program does not use any files or tables directly. It operates solely on the parameters passed to it (KYGRAV
, KYLBS
, KYGAL
) and internal work fields (w@wrk1
, w@wrk2
, w@LBS
, w@GAL
). No disk files or database tables are defined or accessed in the program.
External Programs Called¶
The MINLBGL1
program does not call any external programs or subroutines beyond its own internal subroutines (LBGL11
, GLLB11
, and CALC
). It is a self-contained module designed to perform calculations and return results to the calling program (IN873
).
Additional Notes¶
- Change Log Insights:
JB01
(10/27/2011): Revised the program to use a new API-standard formula, replacing the old formula in theCALC
subroutine. Added support for bidirectional conversion (pounds-to-gallons and gallons-to-pounds) and direct calculation of output values instead of a factor.- Formula Context:
- The formulas are based on API gravity, commonly used in the petroleum industry to calculate the density of liquids relative to water. The constants
141.5
,131.5
,999.01599999999996
, and119.8
are specific to the API standard for converting between pounds and net gallons, likely for petroleum or similar liquids. - The old formula used a factor of
8.337193
(density of water in lb/gal), while the new formula uses999.01599999999996
and119.8
, suggesting a more precise or industry-specific adjustment (possibly for a specific type of liquid). - Program Context:
- The program is called by
IN873
and other programs (e.g.,BB110
, as noted in the comments) that require pounds-to-gallons conversions. - The use of
/FREE
and/END-FREE
indicates a mix of fixed-format RPG II and free-format RPGLE, suggesting a transition to a more modern RPG syntax on the System/36 or AS/400. - Limitations:
- The program assumes valid input parameters and does not include error checking for invalid or negative
KYGRAV
,KYLBS
, orKYGAL
. - The exact rationale for the constants
999.01599999999996
and119.8
is not explained in the code, but they are likely industry-specific (e.g., for petroleum density calculations). - The
CALC
subroutine is retained but unused, indicating legacy code that may be removed in future updates.
Summary¶
- Process Steps:
- Initialize parameters (
KYGRAV
,KYLBS
,KYGAL
) and work fields. - Check if
KYLBS
is non-zero; if so, callLBGL11
to convert pounds to gallons. - If
KYLBS
is zero andKYGAL
is non-zero, callGLLB11
to convert gallons to pounds. - Perform calculations using the API-standard formula:
- Specific gravity =
141.5 / (131.5 + KYGRAV)
- Pounds-to-gallons:
(KYLBS / (specific gravity * 999.01599999999996)) * 119.8
- Gallons-to-pounds:
(KYGAL * (specific gravity * 999.01599999999996)) / 119.8
- Specific gravity =
- Return results via
KYGAL
orKYLBS
. -
Set
LR
indicator and return to the calling program. -
Business Rules:
- Convert pounds to gallons or gallons to pounds based on non-zero input.
- Use API gravity to calculate specific gravity and apply the API-standard formula.
- Directly calculate output values (gallons or pounds) rather than a factor.
-
Do not access files or tables; rely on parameters from the calling program.
-
Tables Used: None (no files or database tables are accessed).
-
External Programs Called: None (only internal subroutines
LBGL11
,GLLB11
, and unusedCALC
).
If you have additional details, such as the context of other calling programs (e.g., BB110
) or specific industry standards for the API gravity formula, I can provide further analysis.