Skip to content

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:

  1. Program Initialization and Parameter Definition
  2. 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.
  3. Parameter List (*ENTRY PLIST):
    • Accepts KYGRAV, KYLBS, and KYGAL as parameters. KYFACT is commented out (per change log JB01), indicating it is no longer used in the new formula.
  4. Purpose: Initializes variables and sets up the parameter interface for communication with the calling program (IN873).

  5. Main Logic (*ENTRY)

  6. 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 the LBGL11 subroutine.
    • If KYGAL is non-zero (and KYLBS is zero), it performs a gallons-to-pounds conversion by calling the GLLB11 subroutine.
  7. If neither condition is met (both KYLBS and KYGAL are zero), no conversion is performed.
  8. The program includes a legacy branch (IFNE 1) that calls the CALC subroutine (old formula), but this is effectively bypassed as the condition 1 IFNE 1 is always false.
  9. Purpose: Directs the program flow based on whether pounds or gallons are provided as input.

  10. Pounds-to-Gallons Conversion (LBGL11 Subroutine)

  11. 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
  12. The result (w@gal) is moved to KYGAL for return to the calling program.
  13. Purpose: Converts pounds to net gallons using the API gravity-based formula.

  14. Gallons-to-Pounds Conversion (GLLB11 Subroutine)

  15. 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
  16. The result (w@lbs) is moved to KYLBS for return to the calling program.
  17. Purpose: Converts gallons to pounds using the API gravity-based formula.

  18. Legacy Formula (CALC Subroutine)

  19. 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
  20. This subroutine is not executed in the current program flow (due to the IFNE 1 condition being false) but is retained for legacy compatibility.
  21. Purpose: Previously used to calculate a conversion factor (KYFACT) for pounds-to-gallons conversion.

  22. Program Termination

  23. Sets the LR (Last Record) indicator to signal the end of processing.
  24. Returns control to the calling program (IN873) with updated KYLBS or KYGAL values.
  25. Purpose: Ensures proper program completion and result return.

Business Rules

The program enforces the following business rules, derived from the code and comments:

  1. Input Exclusivity:
  2. 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).

  3. API Gravity Requirement:

  4. The conversion requires a valid API gravity (KYGRAV), provided by the calling program. The program does not validate KYGRAV but assumes it is non-negative and appropriate for the formula.

  5. Standardized Formula:

  6. 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
  7. The constants 999.01599999999996 and 119.8 are part of the API-standard formula, likely accounting for density adjustments and unit conversions (e.g., for petroleum products).

  8. Direct Calculation:

  9. Unlike the old formula (in CALC), which calculated a factor (KYFACT), the new formula (per JB01) directly calculates the output (gallons or pounds) and returns it via KYGAL or KYLBS.

  10. No File Access:

  11. 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 the CALC 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, and 119.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 uses 999.01599999999996 and 119.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, or KYGAL.
  • The exact rationale for the constants 999.01599999999996 and 119.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, call LBGL11 to convert pounds to gallons.
  • If KYLBS is zero and KYGAL is non-zero, call GLLB11 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
  • Return results via KYGAL or KYLBS.
  • 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 unused CALC).

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.