Reputation: 1
I am looking for PHP code that can convert an EBCDIC binary file in to ASCII. This EBCDIC file also has some packed data fields, the code should be able to unpack these fields as well, and present them in a readable format.
EBCDIC files follow the CP037 format.
The file has the following definition. As you can see below the first compressed value starts after the 7th char and is 18 char long.
******************************************************************
* COBOL DECLARATION FOR TABLE CUST_BILL *
******************************************************************
01 DCL-CUST-BILL.
10 FILLER PIC X(05).
10 TB01196-BL-TYP-CD PIC X(2).
10 TB01196-INVOICE-NO PIC S9(18) COMP.
10 TB01196-CUST-ID-NO PIC S9(9) COMP.
10 TB01196-ACCT-NO PIC S9(9) COMP.
10 TB01196-BL-CYC-NO PIC X(2).
10 TB01196-CYC-MTH-YR PIC X(6).
10 TB01196-JOB-ITERATION-NO PIC S9(4) COMP.
10 TB01196-BL-DISC-APLIED-PCT PIC S9(5)V9(2) COMP-3.
10 TB01196-BL-PREV-INV-RM-AMT PIC S9(9)V9(2) COMP-3.
10 TB01196-BL-PMT-MADE-AMT PIC S9(9)V9(2) COMP-3.
10 TB01196-BL-TOT-CUR-CHG PIC S9(9)V9(2) COMP-3.
10 TB01196-BL-TOT-REMIT-AMT PIC S9(9)V9(2) COMP-3.
10 TB01196-BL-PEND-IND PIC X(1).
10 TB01196-BL-FED-EX-TX PIC S9(7)V9(2) COMP-3.
10 TB01196-BL-ST-LCL-SLS-TX PIC S9(7)V9(2) COMP-3.
10 TB01196-BL-OTH-TX PIC S9(7)V9(2) COMP-3.
10 TB01196-BAL-FORWARD-AMT PIC S9(9)V9(2) COMP-3.
10 TB01196-BL-PRINTED-IND PIC X(1).
10 TB01196-DB-USERID PIC X(8).
10 TB01196-DB-TMSTAMP PIC X(26).
10 CUST-ACCT-INT-SRVC-CHG PIC S9(7)V99 COMP-3.
******************************************************************
* THE NUMBER OF COLUMNS DESCRIBED BY THIS DECLARATION IS 20 *
******************************************************************
This is represantation of the EBCIDIC:
This is the converted ASCII format which I'm trying to achieve:
Upvotes: 0
Views: 443
Reputation: 71
In general you can decode/unpack in PHP using the unpack function, though my experience is that it's quite time consuming to get it right; https://www.php.net/manual/en/function.unpack.php
This question has some answers (in particular sharing the code for EBCDIC to ASCII) which you may find a useful starting point: php - convert ebcdic to ascii
Upvotes: 0