BB9531 RPG36
The provided document, BB9531.rpg36.txt
, is an RPG (Report Program Generator) program written for an IBM System/36 or AS/400 environment. It is called by the OCL program BB953.ocl36.txt
and serves as a preprocessing step for generating a rack price list. The program processes records from the rack price master file (BBPRCE
), validates them against user-specified criteria, and writes selected records to a temporary output file (BB9531
) for further processing. Below, I will explain the process steps, business rules, tables (files) used, and any external programs called.
Process Steps of the RPG Program¶
The BB9531
RPG program preprocesses data from the rack price master file (BBPRCE
) to create a temporary file (BB9531
) that contains filtered and enriched records for the rack price list. It validates records based on company, date range, and division, and retrieves product descriptions from the GSPROD
file (replacing GSTABL
per modification JK01
). Here’s a detailed breakdown of the process steps:
- Header and File Definitions:
- H-Spec: The header specification (
H P064
) identifies the program asBB9531
with a program identifierP064
. - File Definitions (F-Specs):
BBPRCE
: Primary input file (128 bytes, indexed with 27 keys, disk-based), containing rack price data.GSTABL
: Input file (256 bytes, indexed with 12 keys), originally used for product lookups but replaced byGSPROD
for product codes perJK01
.GSPROD
: Input file (512 bytes, indexed with 6 keys), added perJK01
for product data lookups.BB9531
: Output file (169 bytes, disk-based), used to store processed records for the rack price list.
- Array Definitions (E-Specs):
RKPR
: Array of 5 elements (9 bytes, 4 decimals) for rack prices.RKQT
: Array of 5 elements (7 bytes, 0 decimals) for quantity levels.HLPR
: Array of 5 elements (9 bytes, 4 decimals) for holding current rack prices.HLQT
: Array of 5 elements (7 bytes, 0 decimals) for holding current quantity levels.PRPR
: Array of 5 elements (9 bytes, 4 decimals) for previous prices (not used in output but defined).
-
Input Specifications (I-Specs):
BBPRCE
: Defines fields likeRKDEL
(delete flag),RKCONO
(company),RKLOC
(location),RKPROD
(product code),RKCNTR
(container),RKUNMS
(unit of measure),RKDATE
(date, CYMD format),RKTIME
(time, HHMM),RKPR,1-5
(rack prices),RKQT
(quantity levels),RKRKRQ
(rack required flag, added perJB03
), andRKINAC
(inactive flag, added perJB03
).GSTABL
: Defines fields likeTBDEL
(delete flag),TBTYPE
(table type),TBCODE
(table code),TBPROD
(product code),TBDESC
(description),TBPRCL
(product class code),TBABDS
(short description), andTBCSRT
(inventory company sort).GSPROD
: Defines fields likeTPDEL
(delete flag),TPDESC
(description),TPDES1
(complete description),TPPRGP
(product group code),TPPRCL
(product class code),TPABDS
(short description), andTPFLCD
(added perJK01
).- Data Structures (DS): Define
PRCEKY
(price key),CUPROD
,CUCNTR
,CUUNMS
,XXULO
,XXCYMD
,XXHHMM
,$CYMD
,$CN
,$YMD
for date and key manipulations. - User Data Structure (UDS): Defines fields like
KYCO
(company prompt),KYDIV
(division),KYDTSL
(date selection),KYFRDT
(from date),KYTODT
(to date),KYDVNO
(division number),Y2KCEN
(century, 19), andY2KCMP
(comparison year, 80).
-
Initialization and Date Processing (Lines
0053-0287
): -
Indicator
09
Check:- If indicator
09
is off (initial run), the program calculates date-related variables: - Today’s Date:
- Computes
KYDAT8
(8-digit date, CCYYMMDD) usingUDATE
(system date) andY2KCEN
(century, 19 or 20 based onUYEAR
vs.Y2KCMP
).
- Computes
- Date 30 Days Ago:
- Converts
KYDAT8
to$CYMD
and extracts$YMD
(YYMMDD). - Calls
@GTOJ
subroutine to convert to Julian date (G$JD
). - Subtracts 31 days (
SUB 31 G$JD
). - Calls
@JTOG
subroutine to convert back to Gregorian date ($MDY
). - Stores result in
DT3AGO
(8-digit date, CCYYMMDD).
- Converts
- Date Range Validation:
- If
KYDTSL
is not'ALL'
(specific date range selected): - Converts
KYFRDT
andKYTODT
toFRDYMD
andTODYMD
(6-digit YYMMDD). - Adjusts for century: if year > 80, uses 1900s (
FRDAT8
,TODAT8
start with19
); otherwise, uses 2000s (20
).
- If
- Sets indicator
09
to prevent reprocessing date calculations.
- If indicator
-
Record Filtering (Lines
0054-0062
): - Deleted Records:
- If
RKDEL = 'D'
(delete flag), skips the record by jumping toEND
(line0056
).
- If
-
Company Validation:
- If
RKCONO
(company number) does not matchKYCO
(user-specified company), skips the record by jumping toEND
(line0061
).
- If
-
Date Range Filtering (Lines
0059-0062
): - If
KYDTSL = 'ALL'
:- Proceeds to
NEXT
tag, processing all records regardless of date.
- Proceeds to
-
If
KYDTSL
is not'ALL'
:- Compares
RKDATE
(record date, CYMD) toFRDAT8
(from date) andTODAT8
(to date). - If
RKDATE < FRDAT8
orRKDATE > TODAT8
, setsWRITIT = 'N'
(do not write) and jumps toEND
. - Otherwise, proceeds to processing.
- Compares
-
Main Processing Loop (Lines
0065-0101
): - Initialization:
- Clears arrays
HLQT
(quantity),HLPR
(price), and fieldsHLRKRQ
(rack required),HLINAC
(inactive),PRPR
(previous price), andWRITIT
(write flag, set to blank).
- Clears arrays
- Product Description Lookup:
- Builds a key (
TBLKY6
/KLPROD
) usingRKCONO
(company) andRKPROD
(product code). - Chains to
GSPROD
(replacingGSTABL
perJK01
) usingKLPROD
to retrieve product data (indicator92
). - If not found (
92
on), clears description fields (TPDES1
,TPABDS
,TPPRGP
,DES1CP
,ABDSCP
). - If found (
N92
), movesTPDES1
toDES1CP
(complete description, 20 bytes) andTPABDS
toABDSCP
(short description, 10 bytes).
- Builds a key (
- Product Class Lookup:
- If product found (
N65
), retrievesTPPRCL
(product class code) and chains toGSTABL
usingPRCLKY
(built fromRKCONO
andTPPRCL
) to getTBCSRT
(inventory company sort, stored asDIV
). - If product class not found (
65
on),DIV
remains unchanged.
- If product found (
- Division Validation (per
JB04
):- If
KYDIV ≠ 'B'
(not both divisions), comparesDIV
(fromTBCSRT
) toKYDVNO
(division number from user input). - If they don’t match, sets
WRITIT = 'N'
and jumps toEND
.
- If
-
Price and Quantity Comparison:
- Compares current record’s prices (
RKPR,1-5
), quantities (RKQT
), rack required (RKRKRQ
), and inactive (RKINAC
) flags to previous values (HLPR
,HLQT
,HLRKRQ
,HLINAC
). - If any differ (indicator
10
on), updates hold arrays (HLPR
,HLQT
,HLRKRQ
,HLINAC
) with current values. - Sets
WRITIT = 'Y'
to indicate the record should be written.
- Compares current record’s prices (
-
Write Output (Lines
0106-0108
): - If
WRITIT = 'Y'
and levelL1
(primary input cycle), writes a record toBB9531
using theADD951
exception output. -
Fields written include:
RKCONO
(company, pos 1-2)RKLOC
(location, pos 3-5)TPPRGP
(product group code, pos 6-7, perJK01
)RKPROD
(product code, pos 8-11)RKCNTR
(container, pos 12-14)RKUNMS
(unit of measure, pos 15-17)HLQT
(quantity levels, pos 18-52)HLPR
(prices, pos 53-82, packed)PRPR
(previous prices, pos 83-112, packed, unused)DES1CP
(complete description, pos 113-132)ABDSCP
(short description, pos 133-142)RKDATE
(date, pos 143-150)RKTIME
(time, pos 151-154)RKMINQ
(minimum quantity, pos 155-161)DIV
(division fromTBCSRT
, pos 162-164)PRCL
(product class code, pos 165-167)HLRKRQ
(rack required, pos 168, perJB03
)HLINAC
(inactive flag, pos 169, perJB03
)
-
Date Conversion Subroutines:
- @GTOJ (Lines
0320-0384
):- Converts Gregorian date (
$MDY
, YYMMDD) to Julian date (G$JD
). - Handles century calculation using
Y2KCEN
andUYEAR
. - Computes Julian days based on year, month, and day, accounting for leap years.
- Determines the day of the week (
G$JW
).
- Converts Gregorian date (
-
@JTOG (Lines
0388-0438
):- Converts Julian date (
G$JD
) back to Gregorian date ($MDY
, YYMMDD). - Calculates year, month, and day, adjusting for century and leap years.
- Converts Julian date (
-
Termination:
- The program ends at the
END
tag (line0102
) after processing each input record or skipping invalid ones.
Business Rules¶
The BB9531
program enforces the following business rules for preprocessing the rack price list:
- Record Deletion:
-
Skips records marked as deleted (
RKDEL = 'D'
). -
Company Selection:
-
Processes only records where the company number (
RKCONO
) matches the user-specified company (KYCO
). -
Date Range Filtering:
- If
KYDTSL = 'ALL'
, includes all records regardless of date. - If
KYDTSL ≠ 'ALL'
, includes only records whereRKDATE
(CYMD format) falls betweenFRDAT8
(from date) andTODAT8
(to date). -
Converts user-specified dates (
KYFRDT
,KYTODT
) to 8-digit CCYYMMDD format, handling century (19xx or 20xx) based on year comparison withY2KCMP
(80). -
Division Validation:
- If
KYDIV ≠ 'B'
(not both divisions), ensures the record’s division (DIV
, derived fromTBCSRT
inGSTABL
) matches the user-specified division number (KYDVNO
). -
Records with mismatched divisions are excluded (
WRITIT = 'N'
). -
Product Lookup:
- Retrieves product details from
GSPROD
(replacingGSTABL
perJK01
) using a key built fromRKCONO
andRKPROD
. - If not found, clears description fields (
DES1CP
,ABDSCP
,TPPRGP
). -
If found, populates
DES1CP
(complete description),ABDSCP
(short description), andTPPRCL
(product class code). -
Product Class Lookup:
- If product found, uses
TPPRCL
to chain toGSTABL
for product class details, retrievingTBCSRT
(division sort code) intoDIV
. -
If product class not found, no division is set, but processing continues.
-
Price and Quantity Tracking:
- Compares current record’s prices (
RKPR,1-5
), quantities (RKQT
), rack required (RKRKRQ
), and inactive (RKINAC
) flags to previous values (HLPR
,HLQT
,HLRKRQ
,HLINAC
). -
If any differ, updates the hold arrays and sets
WRITIT = 'Y'
to write the record. -
Output Record:
-
Writes records to
BB9531
only ifWRITIT = 'Y'
, including company, location, product group, product code, container, unit of measure, quantities, prices, descriptions, date, time, minimum quantity, division, product class, and rack/inactive flags. -
Date Handling:
- Calculates today’s date (
KYDAT8
) and a date 30 days prior (DT3AGO
) for potential filtering. - Handles century transitions for date conversions (1900s vs. 2000s).
Tables (Files) Used¶
The RPG program uses the following files (tables):
1. BBPRCE: Primary input file containing rack price data (e.g., RKCONO
, RKLOC
, RKPROD
, RKCNTR
, RKUNMS
, RKDATE
, RKTIME
, RKPR
, RKQT
, RKRKRQ
, RKINAC
).
2. GSTABL: Input file for product class lookups (e.g., TBPRCL
, TBCSRT
), used to retrieve division sort code.
3. GSPROD: Input file for product lookups (e.g., TPDES1
, TPABDS
, TPPRGP
, TPPRCL
, TPFLCD
), added per JK01
to replace GSTABL
for product codes.
4. BB9531: Output file containing processed records for the rack price list (169 bytes, including fields like RKCONO
, RKLOC
, TPPRGP
, RKPROD
, DES1CP
, ABDSCP
, etc.).
External Programs Called¶
No external programs are explicitly called within the BB9531
RPG program. It operates independently, processing input from BBPRCE
, performing lookups in GSTABL
and GSPROD
, and writing to BB9531
. The program is invoked by the OCL program BB953.ocl36.txt
, and its output is used by subsequent programs (BB9534
, #GSORT
, BB953
).
Summary¶
The BB9531
RPG program preprocesses rack price data by:
- Calculating date ranges and handling century transitions.
- Filtering BBPRCE
records based on company (KYCO
), deletion status (RKDEL
), date range (KYDTSL
, KYFRDT
, KYTODT
), and division (KYDIV
, KYDVNO
).
- Retrieving product descriptions and product class data from GSPROD
and GSTABL
.
- Comparing prices, quantities, and flags to track changes and decide which records to write.
- Writing valid records to BB9531
with enriched data for further processing.
Tables (Files) Used:
- BBPRCE
- GSTABL
- GSPROD
- BB9531
External Programs Called: - None
This program ensures that only relevant, validated records are included in the temporary file BB9531
, setting the stage for subsequent sorting and report generation in the rack price list workflow.