BB517 RPG36
The RPG program BB517.rpg36.txt is part of the invoice posting workflow in an IBM System/36 or AS/400 environment, likely called by an OCL program related to BB600P.ocl36.txt. Its primary function is to process EDI (Electronic Data Interchange) records from a temporary file (EDIOTH) and either add them to a permanent invoice header file (EDIINVH) or copy duplicate records to a duplicate invoice header file (EDIDPIH) while logging duplicates to a printer file (PRINTER). Below is a detailed explanation of the process steps, business rules, tables used, and external programs called.
Process Steps of the BB517 RPG Program¶
The BB517 program reads records from the EDIOTH file, checks for their existence in the EDIINVH file, and either adds new records to EDIINVH or handles duplicates by writing them to EDIDPIH and logging them to PRINTER. It operates using the RPG cycle for sequential processing.
Process Steps:¶
- File Initialization:
- The program opens four files:
EDIOTH: Secondary input file (IS), containing temporary EDI invoice header records (762 bytes per record).EDIINVH: Update-capable file (UC) with an 18-byte alternate index (AI), used to store permanent EDI invoice header records (762 bytes per record).EDIDPIH: Output file (O) with add capability (A), used to store duplicate EDI invoice header records (762 bytes per record).PRINTER: Output file (O), a printer file (132 bytes per record) for logging duplicate records.
-
All disk files are fixed-length (762 bytes, except
PRINTERat 132 bytes). -
Record Processing:
- The program reads each record from
EDIOTHsequentially using the RPG cycle (NS 01for non-sequential input, processed as a secondary file). - For each record, the program extracts the key field (
EIKEY, positions 1–18), which includes:EIDCTY(Document Type, positions 1–3)EIINV#(Invoice Number, positions 4–10)EIRECT(Record Type, positions 11–12)EISEQ#(Sequence Number, positions 13–15)EIKEY3(Rest of Key, positions 16–18)
-
The program performs a
CHAINoperation onEDIINVHusingEIKEYto check if a record with the same key already exists (sets indicator99if not found). -
Add New Record:
- If the record is not found in
EDIINVH(99is on), the program executes theADDRECexception output (EXCPTADDREC). - The
OEDIINVH EADD ADDRECspecification writes the entire 762-byte record toEDIINVH, split into three fields for output:REC1(positions 1–256)REC2(positions 257–512)REC3(positions 513–762)
-
This adds the new EDI invoice header record to the permanent file.
-
Handle Duplicate Record:
- If the record is found in
EDIINVH(99is off), the program executes theDUPRECexception output (EXCPTDUPREC). - The
OEDIDPIH EADD DUPRECspecification writes the duplicate record toEDIDPIH, using the same fields (REC1,REC2,REC3) as above. - The
OPRINTER E DUPRECspecification writes a log entry to thePRINTERfile, including:EIKEY(positions 1–18, output up to position 25)- The literal
'RECORD ALREADY EXISTS'(output at position 50)
-
This logs the duplicate record for reporting purposes.
-
Cycle Completion:
- The RPG cycle processes all records in
EDIOTHuntil the end of the file is reached. - Once all records are processed, the program terminates, closing all files.
Business Rules¶
- Duplicate Record Detection:
- The program checks for duplicate records in
EDIINVHusing the 18-byte key (EIKEY), which uniquely identifies each EDI invoice header record based on document type, invoice number, record type, sequence number, and additional key fields. -
If a record with the same key exists, it is considered a duplicate.
-
Record Handling:
- New records (non-duplicates) are added to the permanent
EDIINVHfile for storage and future processing. - Duplicate records are copied to the
EDIDPIHfile to segregate them from the main file, preserving the original data for auditing or troubleshooting. -
Duplicates are logged to the
PRINTERfile with the key and a message indicating they already exist, providing a record for review. -
No Data Modification:
- The program does not modify the content of the records; it performs a direct copy of the 762-byte record from
EDIOTHto eitherEDIINVHorEDIDPIH. -
The record structure includes detailed fields (e.g., customer number, ship-to, invoice date, quantity, price), but these are not validated or altered.
-
Purpose for EDI Processing:
-
The program supports the EDI workflow by ensuring that temporary EDI invoice header records are either stored permanently or flagged as duplicates, maintaining data integrity for transmission to a third-party EDI service provider (e.g., Kleinschmidt, as referenced in related programs).
-
No Error Handling:
- The program does not include explicit error handling for file access, key validation, or I/O errors. It assumes that
EDIOTHcontains valid records,EDIINVHandEDIDPIHare accessible for writing, andPRINTERcan log output.
Tables (Files) Used¶
- EDIOTH:
- Description: Temporary EDI invoice header file.
- Attributes: 762 bytes per record, secondary input file (
IS), disk-based. - Fields Used:
EIKEY(18 bytes, positions 1–18): Composite key including:EIDCTY(3 bytes, positions 1–3): Document Type.EIINV#(7 bytes, positions 4–10): Invoice Number.EIRECT(2 bytes, positions 11–12): Record Type.EISEQ#(3 bytes, positions 13–15): Sequence Number.EIKEY3(3 bytes, positions 16–18): Rest of Key.EICUST(6 bytes, positions 19–24): Customer Number.EISHIP(3 bytes, positions 25–27): Ship-to Number.EISYD8(8 bytes, positions 28–35): System Date.EIIND8(8 bytes, positions 36–43): Invoice Date.EICP08(8 bytes, positions 44–51): Customer PO Date.EICPO#(14 bytes, positions 52–65): Customer PO Number.EIBOLC(3 bytes, positions 66–68): BOL Code.EIBOL#(16 bytes, positions 69–84): BOL Number.EINAME(60 bytes, positions 85–144): Name.EIADD1(60 bytes, positions 145–204): Address Line 1.EICITY(30 bytes, positions 205–234): City.EISTAT(2 bytes, positions 235–236): State.EIZIPC(15 bytes, positions 237–251): Zipcode.EIQTY(4 bytes, positions 252–255, packed): Quantity.EIUM(3 bytes, positions 256–258): Unit of Measure.EIPRCE(4 bytes, positions 259–262, packed): Price.EIVPID(20 bytes, positions 263–282): Vendor Product ID.EIPROD(13 bytes, positions 283–295): Product ID.EIFIL1(1 byte, position 296): Filler 1.EILPRC(5 bytes, positions 297–301, packed): Line Price Total.EIIDSC(86 bytes, positions 302–387): Item Description.EIIAMT(5 bytes, positions 388–392, packed): Invoice Amount.EIITOT(5 bytes, positions 393–397, packed): Invoice Total.EIADCT(9 bytes, positions 398–406): Additional Charge Type.EIADCA(5 bytes, positions 407–411, packed): Additional Charge Amount.EIFIL2(189 bytes, positions 412–600): Filler 2.EISEND(128 bytes, positions 601–728): Field for Resend.EIRED8(8 bytes, positions 729–736): Resend Date.EIRET8(6 bytes, positions 737–742): Resend Time.EIFIL3(20 bytes, positions 743–762): Filler 3.REC1(256 bytes, positions 1–256): First segment of the record.REC2(256 bytes, positions 257–512): Second segment of the record.REC3(250 bytes, positions 513–762): Third segment of the record.
- Purpose: Contains temporary EDI invoice header data to be processed.
-
Usage: Read sequentially to check for duplicates and copy to
EDIINVHorEDIDPIH. -
EDIINVH:
- Description: Permanent EDI invoice header file.
- Attributes: 762 bytes per record, update-capable (
UC) with an 18-byte alternate index (AI), disk-based, add capability (A). - Fields Used: Same as
EDIOTH(copied directly viaREC1,REC2,REC3). - Purpose: Stores unique EDI invoice header records for permanent storage and further processing.
-
Usage: Checked for duplicates using
EIKEYand updated with new records viaADDREC. -
EDIDPIH:
- Description: Duplicate EDI invoice header file.
- Attributes: 762 bytes per record, output file (
O) with add capability (A), disk-based. - Fields Used: Same as
EDIOTH(copied directly viaREC1,REC2,REC3). - Purpose: Stores duplicate EDI invoice header records for auditing or troubleshooting.
-
Usage: Receives duplicate records via
DUPREC. -
PRINTER:
- Description: Printer output file for logging duplicates.
- Attributes: 132 bytes per record, output file (
O), printer-based. - Fields Used:
EIKEY(18 bytes, output up to position 25): Record key.- Literal
'RECORD ALREADY EXISTS'(output at position 50): Error message.
- Purpose: Logs duplicate records for reporting and review.
- Usage: Receives output for duplicate records via
DUPREC.
External Programs Called¶
The BB517 RPG program does not explicitly call any external programs. It is a self-contained program that processes EDI records from EDIOTH and writes to EDIINVH, EDIDPIH, and PRINTER.
Summary¶
The BB517 RPG program, likely called by an OCL program in the BB600P.ocl36.txt workflow, processes temporary EDI invoice header records by:
- Reading each record from EDIOTH and checking for duplicates in EDIINVH using the 18-byte key (EIKEY).
- Adding new records to EDIINVH.
- Copying duplicate records to EDIDPIH and logging them to PRINTER with a message.
- Terminating after processing all records.
Tables Used: EDIOTH (temporary EDI input), EDIINVH (permanent EDI invoice header), EDIDPIH (duplicate EDI invoice header), PRINTER (duplicate record log).
External Programs Called: None.
This program ensures that EDI invoice header data is stored permanently, with duplicates segregated and logged, supporting the EDI workflow for transmission to a third-party service like Kleinschmidt.