IN873 RPG36
The provided RPG II program (IN873.rpg36.txt
) is executed by the OCL procedure (IN873.ocl36.txt
) in an IBM System/36 environment. It is designed to convert between pounds and net gallons for inventory or production purposes, using data from input files and user interaction via workstation screens. Below, I will explain the process steps, business rules, tables (files) used, and external programs called, based on the RPG source code and the context provided by the OCL script.
Process Steps of the RPG Program¶
The IN873
RPG program is an interactive program that uses two screen formats (IN873S1
and IN873S2
) to collect user input and display results. It processes data from the INCONT
and GSPROD
files to perform conversions between pounds and gallons, using product-specific gravity or density values. The program follows a structured flow with subroutines to handle screen navigation, data validation, and calculations. Here are the detailed process steps:
- Program Initialization
- File Setup: The program defines three files:
SCREEN
: A workstation file (display file) for user interaction, with a size of 1000 bytes.INCONT
: An indexed input file (512 bytes, 2-byte key, alternate index) for inventory control data.GSPROD
: An indexed input file (512 bytes, 6-byte key, alternate index) for product master data, replacing the previously usedGSTABL
file (per change logJK01
).
- Data Structures:
- Defines
MSG
array for error messages (5 messages, 35 characters each). - Defines
@INFDS
for screen status information (e.g.,@VKEY
for function key status).
- Defines
-
Initial Screen Preparation:
- The program starts by checking if the screen format ID (
@SFID
) is blank, indicating the first execution. - If blank, the
$SBLK
subroutine is called to initialize screen fields and display the first screen (IN873S1
).
- The program starts by checking if the screen format ID (
-
Main Processing Loop (
@SFNEX DOWNE 'EJ'
) - The program enters a loop that continues until the user presses a key to exit (
@SFNEX = 'EJ'
). - Based on the screen format ID (
@SFID
), it calls subroutines to handle different screens:- If
@SFID
is blank, call$SBLK
(initial blank screen). - If
@SFID
isS1
, call$S1
(first screen processing). - If
@SFID
isS2
, call$S2
(second screen processing).
- If
- After processing the appropriate subroutine, the
$XCPT
subroutine displays the next screen. -
The program reads the
SCREEN
file to capture user input, setting theLR
(Last Record) indicator on subsequent reads after the first. -
Blank Screen Processing (
$SBLK
) - Initializes screen fields:
- Clears
KCO
(company number),KPROD
(product code),KGRAV
(specific gravity),KLBS
(pounds),KGAL
(gallons),KFACT
(factor),OLBS
(output pounds),OGAL
(output gallons), andPRDS
(product description). - Hardcodes the company number (
KCO
) to 10.
- Clears
- Sets the next screen format to
S1
(@SFNEX = 'S1'
). -
Calls
$S1ENT
to validate the company number and prepare the first screen (IN873S1
). -
Screen 1 Processing (
$S1
) - Handles the first screen (
IN873S1
), which prompts the user to enter or confirm the company number (KCO
). - Based on the function key pressed (
@VKEY
):- If
Enter
(key 0), calls$S1ENT
to validate the company number. - If command key 2, calls
$S1CK
to process command key actions (e.g., exit).
- If
- Subroutine
$S1ENT
:- Validates the company number (
KCO
) by performing aCHAIN
operation on theINCONT
file. - If the company number is invalid (indicator 90 set), displays error message "INVALID COMPANY NO" (
MSG,1
). - If valid, sets indicators 03 and 04 (likely for screen formatting) and sets the next screen to
S2
(@SFNEX = 'S2'
).
- Validates the company number (
-
Subroutine
$S1CK
:- If the user presses command key
KG
(likely F3 or an exit key), sets@SFNEX
toEJ
to exit the program.
- If the user presses command key
-
Screen 2 Processing (
$S2
) - Handles the second screen (
IN873S2
), where the user enters the product code (KPROD
), specific gravity (KGRAV
), and either pounds (KLBS
) or gallons (KGAL
) to convert. - Based on the function key pressed (
@VKEY
):- If
Enter
(key 0), calls$S2ENT
to validate input and perform the conversion. - If command key 2, calls
$S2CK
to process command key actions.
- If
- Subroutine
$S2ENT
:- Validation:
- Checks if both
KLBS
andKGAL
are non-zero. If so, sets error indicator 90 and displays "ENTER EITHER POUNDS OR GALLONS" (MSG,4
), then skips to the end. - Validates the product code (
KPROD
) by constructing a 6-byte key (GSKEY6 = KCO + KPROD
) and performing aCHAIN
on theGSPROD
file. - If the product code is invalid (indicator 96 set), displays "INVALID PRODUCT CODE" (
MSG,2
). - Retrieves the product description (
TPDESC
) fromGSPROD
and moves it toPRDS
for display. - Specific Gravity Handling:
- If the user-entered specific gravity (
KGRAV
) is zero, retrieves the gravity from theGSPROD
file (TPGRAV
) (per change logJB01
). - Conversion Calculation:
- Calls the external program
MINLBGL1
to perform the conversion. - If
KLBS
is non-zero (pounds to gallons):- Passes
KGRAV
(specific gravity),KLBS
(input pounds), andP@GAL
(output gallons, initialized to zero). MINLBGL1
calculates the gallons (P@GAL
) and returns updated pounds (P@LBS
).- Moves results to
OLBS
(output pounds) andOGAL
(output gallons).
- Passes
- If
KGAL
is non-zero (gallons to pounds, per change logJB02
):- Passes
KGRAV
,P@LBS
(output pounds, initialized to zero), andKGAL
(input gallons). MINLBGL1
calculates the pounds (P@LBS
) and returns updated gallons (P@GAL
).- Moves results to
OLBS
andOGAL
.
- Passes
- If errors occur (indicator 90 set), sets indicator 03 and skips to the end.
- If successful, clears indicator 03 for normal display.
-
Subroutine
$S2CK
:- If command key
KA
(likely F12 or back) is pressed, clearsKPROD
,KGRAV
,KLBS
,KFACT
,OGAL
, sets indicators 03 and 04, and returns to screenS1
. - If command key
KG
is pressed, sets@SFNEX
toEJ
to exit the program.
- If command key
-
Screen Display (
$XCPT
) - Increments a counter (
@CCNT
) to track screen displays. - Displays the appropriate screen based on
@SFNEX
:- If
@SFNEX = 'S1'
, outputs theIN873S1
screen format withKCO
andMSG1
. - If
@SFNEX = 'S2'
, outputs theIN873S2
screen format withKCO
,KPROD
,KGRAV
,KLBS
,KGAL
,OLBS
,OGAL
,MSG1
, andPRDS
.
- If
-
Calls
CLRIND
to reset error indicators and clear the message field (MSG1
). -
Indicator Reset (
CLRIND
) - Clears error indicator 90 and cursor indicators (51-57).
-
Clears the message field (
MSG1
) to prepare for the next screen display. -
Program Termination
- The program exits when
@SFNEX = 'EJ'
, typically triggered by the user pressing an exit key (e.g., F3 viaKG
). - The
LR
indicator is set after the first screen read, ensuring proper file handling and program termination.
Business Rules¶
The program enforces the following business rules, derived from the code and comments:
- Company Number Validation:
- The company number (
KCO
) is hardcoded to 10 but validated against theINCONT
file. -
If invalid, displays "INVALID COMPANY NO" and prevents further processing until corrected.
-
Product Code Validation:
- The product code (
KPROD
) is validated against theGSPROD
file using a composite key (GSKEY6 = KCO + KPROD
). -
If invalid, displays "INVALID PRODUCT CODE" and prevents conversion.
-
Input Exclusivity:
- Users must enter either pounds (
KLBS
) or gallons (KGAL
), but not both (per change logJB02
). -
If both are entered, displays "ENTER EITHER POUNDS OR GALLONS" and skips calculation.
-
Specific Gravity Handling:
- If the user-entered specific gravity (
KGRAV
) is zero, the program retrieves the gravity from theGSPROD
file (TPGRAV
) (per change logJB01
). -
The gravity is used in the conversion calculation by the external program
MINLBGL1
. -
Conversion Logic:
- The program supports bidirectional conversion (pounds to gallons or gallons to pounds, per change log
JB02
). - The external program
MINLBGL1
performs the actual conversion, using the specific gravity (KGRAV
) and either pounds (KLBS
) or gallons (KGAL
) as input. -
Results are stored in
OLBS
(output pounds) andOGAL
(output gallons) for display. -
Screen Navigation:
- The program uses two screens:
IN873S1
: For entering/validating the company number.IN873S2
: For entering product code, specific gravity, and quantity (pounds or gallons), and displaying results.
-
Users can return to
IN873S1
using command keyKA
(e.g., F12) or exit usingKG
(e.g., F3). -
Error Handling:
- Displays specific error messages for invalid company number, invalid product code, or incorrect input (both pounds and gallons entered).
- Uses indicators (e.g., 90, 03, 04) to control error display and screen formatting.
Tables Used¶
In the System/36 context, "tables" typically refer to files or data structures used by the program. The RPG program uses the following files, which serve as data sources:
- INCONT:
- Description: Inventory control file, used to validate the company number (
KCO
). - Fields Used:
ICINUM
(positions 35-37): Inventory unit/measure.ICTKRD
(position 91): Daily tank reading flag (e.g., '', Q, H).
- Access: Indexed file with a 2-byte key, read via
CHAIN
to validateKCO
. -
Purpose: Ensures the company number is valid before proceeding to product and quantity input.
-
GSPROD:
- Description: Product master file, replacing the previous
GSTABL
file (per change logJK01
). Contains product-specific data. - Fields Used:
TPDEL
(position 1): Likely a deletion flag or status.TPDESC
(positions 14-43): Product description, displayed on the screen.TPPRCL
(positions 127-129): Likely a product class or code.TPGRAV
(positions 132-134.1): Specific gravity, used for conversion ifKGRAV
is zero.TPVCFC
(positions 250-251): Likely a volume correction factor, though not used in the provided code.
- Access: Indexed file with a 6-byte key (
GSKEY6
), read viaCHAIN
to validateKPROD
and retrieveTPGRAV
andTPDESC
. - Purpose: Provides product-specific data, including gravity and description, for conversion and display.
No additional arrays or internal tables (e.g., RPG E
specification arrays beyond MSG
) are defined in the program.
External Programs Called¶
The program calls one external program:
- MINLBGL1:
- Description: Called to perform the conversion between pounds and gallons (per change log
JB02
). This program replaced an earlierMINLBGL
module and directly calculates gallons or pounds rather than returning a factor. - Parameters:
KYGRAV
(3.1 numeric): Specific gravity, passed as input.P@LBS
(7.0 numeric): Pounds, passed as input (for pounds-to-gallons) or output (for gallons-to-pounds).P@GAL
(7.0 numeric): Gallons, passed as output (for pounds-to-gallons) or input (for gallons-to-pounds).
- Purpose: Performs the mathematical conversion using the specific gravity and input quantity, returning the converted value.
- Change Log Reference:
JB02
(10/27/2011) notes thatMINLBGL1
includes a corrected formula and supports bidirectional conversion.
Additional Notes¶
- Change Log Insights:
JB01
(06/08/2011): Added logic to retrieve specific gravity fromGSTABL
(nowGSPROD
) if the user-enteredKGRAV
is zero.JB02
(10/27/2011): Updated to callMINLBGL1
instead ofMINLBGL
, added gallons-to-pounds conversion, and modified the program to calculate results directly.JK01
(08/15/2014): ReplacedGSTABL
withGSPROD
for product data access.- System/36 Context: The program uses RPG II syntax and conventions typical of the IBM System/36, with flat files (
INCONT
,GSPROD
) and a workstation file (SCREEN
) for user interaction. - Limitations: Without the source code for
MINLBGL1
, the exact conversion formula (e.g., pounds = gallons × specific gravity × 8.34 for water-based calculations) is not visible. The program assumesMINLBGL1
handles the calculation correctly. - Error Messages: The program defines four error messages:
- "INVALID COMPANY NO" (MSG,1)
- "INVALID PRODUCT CODE" (MSG,2)
- "VCF MUST BE IN GSTABL - INVCF TYPE" (MSG,3, not used in the code)
- "ENTER EITHER POUNDS OR GALLONS" (MSG,4)
Summary¶
- Process Steps:
- Initialize files, data structures, and screen fields.
- Enter a loop to process screens until exit (
@SFNEX = 'EJ'
). - Display and process
IN873S1
to validate the company number. - Display and process
IN873S2
to validate product code and perform conversion. - Call
MINLBGL1
for conversion calculations (pounds to gallons or gallons to pounds). - Display results or errors and handle navigation (back to
S1
or exit). -
Terminate when the user exits.
-
Business Rules:
- Validate company number against
INCONT
. - Validate product code against
GSPROD
. - Allow only one input (pounds or gallons).
- Use product-specific gravity from
GSPROD
if user input is zero. - Perform bidirectional conversion using
MINLBGL1
. -
Support navigation between screens and program exit.
-
Tables Used:
INCONT
: Inventory control file for company validation.-
GSPROD
: Product master file for product data and specific gravity. -
External Programs Called:
MINLBGL1
: Performs the pounds-to-gallons or gallons-to-pounds conversion.
If you have additional details, such as the source code for MINLBGL1
or the screen format definitions (IN873S1
, IN873S2
), I can provide further analysis of the conversion logic or screen layouts.