BB170 RPG36
Process Steps of the RPG Program (BB170.rpg36.txt)¶
The RPG program BB170 is designed for the IBM System/36 environment and is called by the BB170 OCL procedure (distinct from this program despite sharing the name) as part of an order management system. Its primary function is to create new order records by copying an existing order into a transaction file (BBTRAN) and related supplemental files (BBOTHS, BBOTDS, BBOTA, SHIPTOO) for a specified number of copies, as requested by the user (via KYCPYS). The program processes the source order from BBORDR, retrieves the next available order number from BICONT, and generates new records with updated order numbers. It operates within the standard RPG cycle, using conditional logic to handle multiple file outputs. Below is a step-by-step breakdown of the process:
- Initialization (Mainline Calculations):
- Clear fields: BLNK15 (15 bytes), BLNK7 (7 bytes), ZERO6 (6-digit numeric), ZERO8 (8-digit numeric) to blanks or zeros.
- Capture system time (TIME to TIMDAT, 12 digits) and extract SYTIME (HHMMSS) and SYDATE (MMDDYY).
- Convert SYDATE to century-year-month-day format (DATYMD = SYDATE * 10000.01, e.g., 081325 for 08/13/25).
-
Set DATE8 (8-digit, CCYYMMDD) by prefixing '20' (for 21st century) and appending DATYMD.
-
Process BBORDR Records (Primary Input):
- Read records sequentially from BBORDR (primary file, IP, 512-byte records, 11-byte alphanumeric key, indexed) using input specification NS 01.
- Extract fields like BODEL (delete flag), BOCO (company), BORDNO (order number), BORSEQ (sequence), BOCUST (customer), BOSHIP (ship-to), and others (e.g., dates, freight codes, lock status).
-
For each record, check if BORDNO (order number) matches KYORD# (input order number from local data area, offset 143-148).
-
Create New Orders (DO Loops for Each File):
- The program uses a series of DO loops (indicators 01-10) to process different files, each checking if the source order number (BORDNO, BHRDNO, BTORDN, BAORDN, CSORDN) matches KYORD#. If not, it branches to the END tag, skipping processing for that record.
- Get Next Order Number (Indicator 01):
- Chain to BICONT (control file, update-capable) using BOCO (company number).
- If found (49 off), set NEWORD (new order number) to BCORDN (next order number from BICONT).
- Increment BCORDN to NXTORD and update BICONT (EXCPT COUPD) to store the next available order number.
- Build a composite key (KEY, 21 bytes) by combining BOCO and BORDNO, padded as needed.
- Write a new BBTRAN record (EXCPT ADD1) with NEWORD, SYDATE, DATE8, and default values (e.g., zeros for dates, 'X' at 476).
- Increment KYCNT (copy counter, offset 140-141) to track copies made.
- BBOTHS (Indicator 07):
- If BHRDNO (order number from BBORHS) matches KYORD#, write a new BBOTHS record (EXCPT ADDTH) with NEWORD.
- BBOTDS (Indicator 08):
- If BTORDN (order number from BBORDS) matches KYORD#, write a new BBOTDS record (EXCPT ADDTD) with NEWORD.
- BBOTA (Indicator 09):
- If BAORDN (order number from BBORA) matches KYORD#, write a new BBOTA record (EXCPT ADDTA) with NEWORD.
- SHIPTOO (Indicator 10):
- If CSDEL='O' (ship-to record active), CSSHIP=999 (special ship-to flag), and CSORDN matches KYORD#, write a new SHIPTOO record (EXCPT ADDSHP) with NEWORD.
-
Other Files (Indicators 02-06):
- Similar logic for ADD2 to ADD6 (BBTRAN), writing additional records with NEWORD, likely for different record types or segments (REC021-REC062).
-
Output to Files:
- BICONT (EXCPT COUPD): Updates NXTORD (next order number) at position 39.
- BBTRAN (EXCPT ADD1-ADD6): Writes new order records with fields like NEWORD (new order number, position 9), SYDATE (order date, 39), DATE8 (CCYYMMDD, 322), and default values (e.g., 'X' at 476, zeros for dates).
- BBOTHS (EXCPT ADDTH): Writes header supplemental records with NEWORD.
- BBOTDS (EXCPT ADDTD): Writes detail supplemental records with NEWORD.
- BBOTA (EXCPT ADDTA): Writes auxiliary records with NEWORD.
-
SHIPTOO (EXCPT ADDSHP): Writes ship-to records with NEWORD and multiple record segments (REC1-REC8).
-
Program Cycle:
- The RPG cycle processes BBORDR records sequentially.
- For each matching record (BORDNO=KYORD#), it creates new records in the target files up to the number of copies requested (tracked via KYCNT, compared to KYCPYS in the OCL).
- The program ends when all BBORDR records are processed or the required copies are created.
Business Rules¶
- Order Copying:
- Creates new orders by copying an existing order (KYORD#) into BBTRAN and supplemental files (BBOTHS, BBOTDS, BBOTA, SHIPTOO).
- The number of copies is controlled by KYCPYS (local data area, offset 150-151).
- Each new order gets a unique order number (NEWORD) from BICONT’s BCORDN, incremented after each use.
- Order Number Management:
- BICONT tracks the next order number (BCORDN) per company (BOCO), ensuring unique order numbers.
- Updates BCORDN after each copy to prevent reuse.
- File-Specific Processing:
- BBTRAN: Primary transaction file for new orders, with standardized fields (e.g., SYDATE, DATE8, default zeros).
- BBOTHS, BBOTDS, BBOTA: Supplemental files for headers, details, and auxiliary data, using NEWORD to link to the new order.
- SHIPTOO: Copies ship-to records only when CSDEL='O' and CSSHIP=999, ensuring valid ship-to data.
- Data Integrity:
- Matches records using BOCO (company) and BORDNO (order number) to ensure correct source data.
- Uses composite keys (e.g., KEY, TCOORD) for precise record creation.
- Sets default values (e.g., 'X' at 476, zeros for dates) to initialize new records.
- Date Handling:
- Uses system date (SYDATE, MMDDYY) and converts to CCYYMMDD (DATE8) for consistency.
- Ensures order entry date (position 39, 322) reflects the current date.
- Loop Control:
- The OCL checks KYCNT (copies made) against KYCPYS (copies requested) to control the number of iterations.
Tables Used¶
- BBORDR:
- Primary input file, 512-byte records, 11-byte alphanumeric key, indexed (11AI).
- Contains source order header records.
- Fields: BODEL (delete), BOCO (company), BORDNO (order number), BORSEQ (sequence), BOCUST (customer), BOSHIP (ship-to), and many others (e.g., dates, freight codes, lock status).
- BICONT:
- Update-capable file, 256-byte records, 2-byte alphanumeric key, indexed (02AI).
- Stores control data, including BCORDN (next order number).
- Fields: BCORDN (34-39), company-related fields (e.g., BCCO, BCNAME, BCAGPW).
- BBORHS:
- Input sequential file, 512-byte records, 21-byte alphanumeric key, externally described (EXTK).
- Likely historical order headers.
- BBORDS:
- Input sequential file, 512-byte records, 24-byte alphanumeric key, externally described (EXTK).
- Likely order details.
- BBORA:
- Input sequential file, 512-byte records, 26-byte alphanumeric key, externally described (EXTK).
- Likely archive or auxiliary order data.
- SHIPTO:
- Input sequential file, 2048-byte records, 11-byte alphanumeric key, indexed (11AI).
- Contains ship-to address data.
- BBOTHS:
- Output file, 512-byte records, 21-byte alphanumeric key, externally described (EXTK).
- Stores new header supplemental records.
- BBOTDS:
- Output file, 512-byte records, 24-byte alphanumeric key, externally described (EXTK).
- Stores new detail supplemental records.
- BBOTA:
- Output file, 512-byte records, 26-byte alphanumeric key, externally described (EXTK).
- Stores new auxiliary records.
- BBTRAN:
- Output file, 512-byte records, 11-byte alphanumeric key, indexed (11AI).
- Stores new order transaction records.
- SHIPTOO:
- Output file, 2048-byte records, 11-byte alphanumeric key, indexed (11AI).
- Stores new ship-to records.
External Programs Called¶
- None. BB170 is self-contained, with no direct calls to other programs. It relies on file I/O and exception outputs (COUPD, ADD1-ADD6, ADDTH, ADDTD, ADDTA, ADDSHP) to create new records.
The program is a critical component of the order copying process, generating new order records in multiple files while maintaining unique order numbers and data consistency, as controlled by the BB170 OCL procedure.