MBBQTY RPGLE
The MBBQTY.rpgle.txt is an RPG program (converted to RPGLE, as noted in JB15) called from the BB502.ocl36.txt OCL program and referenced in BB502.rpg36.txt as a replacement for BB5009 (JB12). It is a utility module designed to convert order quantities to pounds, gallons, and shipping weight for use in shipment processing. Below, I’ll 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 MBBQTY program converts an order’s container quantity (CTQT) into pounds (NETLBS), gross gallons (GGAL), net gallons (NGAL), and shipping weight (SHPLBS) based on the unit of measure (UM), product (PROD), container (CNTR), and other parameters. It uses conversion factors from files and formulas to ensure accurate calculations. Here’s a step-by-step breakdown of the process:
- Program Initialization:
- The program defines input files (
BICONT,GSPROD,GSCTUM,GSUMCV,GSCTWT) for retrieving product, container, and conversion data. - A parameter data structure (
QTPARM) is defined to handle input and output:- Input Fields: Company (
CO), product (PROD), container (CNTR, alphanumeric per JB09), unit of measure (UM), container quantity (CTQT, sometimes output), tare weight (TARE), gross weight (GVWT), car capacity (CACA), outage (OUTA), carrier code (CACD), fluid code (FLCD), temperature (TEMP), gravity (GRAV), volume correction factor (VCF). - Output Fields: Shipped quantity (
SQTY), gross gallons (GGAL), net gallons (NGAL), temperature correction factor (T6DFAC), net pounds (NETLBS), shipping pounds (SHPLBS), error code (ERR).
- Input Fields: Company (
-
Additional data structures (
KYGRAV,KYFACT,P@LBS,P@GAL) are used for conversion calculations, andT6DTEM,T6DGRA,T6DVCFstore temperature and gravity data. -
Retrieve Company Data (
BICONT): - The program chains to the
BICONTfile using the company number (CO) to verify the company record. -
If the record is not found or marked as deleted (
BCDEL = 'D'), it sets the outage percentage (BCIOPE) to zero and sets indicator49. -
Retrieve Product Data (
GSPROD): - It constructs a key (
HLD6) by combiningCOandPRODand chains to theGSPRODfile to retrieve product details (e.g., standard API gravityTPGRAV, fluid codeTPFLCD, VCF codeTPVCF). -
If the record is not found or deleted (
TPDEL = 'D'), it setsTPFLCD,TPGRAV, andTPVCFto blank/zero and sets an error code (ERR = 'E', JB13). -
Populate Missing Input Fields:
-
If input fields
FLCD,GRAV, orVCFare blank/zero, they are populated from theGSPRODrecord (TPFLCD,TPGRAV,TPVCF). -
Unit of Measure Conversion:
-
The program handles conversions based on the unit of measure (
UM):- Kilograms (KG, JB10):
- Converts
SQTY(in kilograms) to pounds (NETLBS) using the formula:SQTY * 2.20462. - Calls
MINLBGL1to convert pounds to net gallons (NGAL) usingGRAV. - Calculates gross gallons (
GGAL) by dividingNGALby the temperature correction factor (T6DFAC). - Liters (LI, JB11):
- Converts
SQTYto net gallons:SQTY / 3.78541. - Calls
MINLBGL1to convert net gallons to pounds (NETLBS). - Calculates gross gallons:
NGAL / T6DFAC. - Milliliters (ML, JB11):
- Converts
SQTYto net gallons:SQTY / 3785.41. - Calls
MINLBGL1to convert net gallons to pounds. - Calculates gross gallons:
NGAL / T6DFAC. - Ounces (OZ, JB11):
- Converts
SQTYto net gallons:SQTY / 128. - Calls
MINLBGL1to convert net gallons to pounds. - Calculates gross gallons:
NGAL / T6DFAC. - Pounds (LBS):
- Sets
NETLBStoSQTY. - Calls
MINLBGL1to convert pounds to net gallons (NGAL). - Calculates gross gallons:
NGAL / T6DFAC. - Gallons (GAL):
- Sets
GGALtoSQTY. - Calculates net gallons:
GGAL * T6DFAC. - If the GL code (
GLCD) is'G', setsSQTYtoGGAL; otherwise, setsSQTYtoNGAL. - Calls
MINLBGL1to convert net gallons to pounds (NETLBS). - Other Units (e.g., non-LBS, GAL, ECH, JB07, JB14):
- Chains to
GSCTWTusing a key (WTKEY) combiningCO,PROD, andCNTRto get gallons per container (WTGAL, expanded to 12.7 digits in JB16). - If found and not deleted (
WTDEL ≠ 'D' or 'I'), calculates gross gallons:CTQT * WTGALand net gallons:GGAL * T6DFAC. - If no
GSCTWTrecord, chains toGSUMCVusing a key (UCKEY) combiningCO,PROD,UM, and'GAL'to get a conversion factor (UCCVFA). - If no
GSUMCVrecord, setsUCOPERto'M'andUCCVFAto 1 (JB01), and setsERR = 'E'(JB13). - Applies conversion:
SQTY * UCCVFA(ifUCOPER = 'M') orSQTY / UCCVFA(ifUCOPER = 'D') to getNGAL. - Calculates gross gallons:
NGAL / T6DFAC. - Calls
MINLBGL1to convert net gallons to pounds (NETLBS).
-
Shipping Weight Calculation (JB02, JB05):
- Chains to
GSCTWTto retrieve gross weight (WTGROS, including packaging). - If found and not deleted, calculates shipping weight:
CTQT * WTGROS. -
If no
GSCTWTrecord:- For
UM = 'LBS', setsSHPLBStoNETLBS. - For
UM = 'GAL'or other units, setsSHPLBStoNETLBS.
- For
-
Program Termination:
- The program jumps to the
ENDQTYtag and ends, returning the updatedQTPARMdata structure withSQTY,GGAL,NGAL,NETLBS,SHPLBS, andERRto the calling program.
Business Rules¶
The program enforces the following business rules, based on the code and change history:
- Unit of Measure Conversions:
- Supports conversions for
KG,LI,ML,OZ,LBS,GAL, and other units (ECH, etc.) using specific formulas or conversion factors fromGSUMCVandGSCTWT(JB10, JB11). - For
KG, converts to pounds using a fixed factor (2.20462) before converting to gallons (JB10). - For
LI,ML,OZ, uses fixed factors (3.78541,3785.41,128) to convert to gallons, avoiding user-entered factors (JB11). -
For other units, prefers
GSCTWTfor gallons per container (WTGAL) if available; otherwise, usesGSUMCVor defaults to a factor of 1 (JB01, JB14). -
Gross vs. Net Gallons (JB03, JB06):
- Gross gallons (
GGAL) are calculated from net gallons (NGAL) by dividing by the temperature correction factor (T6DFAC). - For
LBS, converts to net gallons first, then to gross gallons. -
For non-
LBS/GALunits, prefers converting to gallons before pounds if possible; otherwise, converts to pounds first (JB06). -
Shipping Weight Calculation (JB02, JB05):
- Uses
GSCTWTfor shipping weight (SHPLBS) if available, as it includes packaging weight. -
Falls back to
NETLBSforLBS,GAL, or other units if noGSCTWTrecord exists. -
Error Handling (JB13):
-
Sets an error code (
ERR = 'E') if no valid record is found inGSPRODorGSUMCV, indicating a conversion failure. -
Rounding (JB12):
-
Applies rounding to certain unit of measure conversions to ensure accuracy.
-
Container Code (JB09):
-
The container code (
CNTR) is alphanumeric, allowing flexibility in container identification. -
Gallons Precision (JB16):
-
The
WTGALfield inGSCTWTwas expanded from 8.2 to 12.7 digits for higher precision in gallon calculations. -
Fallback for Missing Data:
- If
FLCD,GRAV, orVCFare missing, they are populated fromGSPRODto ensure valid conversions. - If no conversion factor is found in
GSUMCV, a default factor of 1 is used (JB01).
Tables (Files) Used¶
The program uses the following input files, as defined in the F (File) specifications:
- BICONT: Container master file (256 bytes, indexed, read-only, key length 2). Contains outage percentage (
BCIOPE). - GSPROD: Product master file (512 bytes, indexed, read-only, key length 8). Contains product details (
TPGRAV,TPFLCD,TPVCF). - GSCTUM: Unit of measure file (64 bytes, indexed, read-only, key length 12). Contains issue unit of measure (
CUIUM,CUHAZM). - GSUMCV: Unit conversion file (64 bytes, indexed, read-only, key length 12). Contains conversion factors (
UCCVFA,UCOPER). - GSCTWT: Container weight file (64 bytes, indexed, read-only, key length 9). Contains gross weight (
WTGROS) and gallons per container (WTGAL).
External Programs Called¶
The program calls one external program:
- MINLBGL1 (JB04, JB05, JB11):
- A utility program that converts between pounds and gallons based on gravity (
KYGRAV) and other parameters. - Input parameters:
KYGRAV(gravity),P@LBS(pounds),P@GAL(gallons). - Output: Updated
P@LBSorP@GALbased on the conversion direction. - Replaces
MINLBGLto directly calculate gallons or pounds instead of returning a factor (JB04).
Summary¶
The MBBQTY RPGLE program is a utility called from BB502 (and potentially other programs like BB113) to convert order quantities (CTQT) to pounds (NETLBS), gross gallons (GGAL), net gallons (NGAL), and shipping weight (SHPLBS). It uses product, container, and conversion data from five files (BICONT, GSPROD, GSCTUM, GSUMCV, GSCTWT) and applies specific formulas for units like KG, LI, ML, OZ, LBS, and GAL. It enforces business rules for accurate conversions, error handling, and fallback logic, calling MINLBGL1 for pound-to-gallon conversions. The program ensures precision (e.g., JB16) and avoids user errors in conversion factors (JB10, JB11).
If you need further details on specific calculations, validations, or related content (e.g., analysis of X posts or web searches), let me know!