Convert Character Field EBCDIC to ASCII or ASCII to EBCDIC

 

I had some spare time, so I started converting some old BASIC programs for manipulating AWS tape image files to COBOL.  The first thing I needed was a way to convert the data on the tape image files from EBCDIC to ASCII (and will also need ASCII to EBCDIC in the next program I will tackle), so I created this brief program to handle that.  It has been a long time since I used multiple entry points into a program (something like the late 1970's or early 1980's if I remember correctly).  Since I didn't want to have two source programs and would need the encoding tables for both programs if I did, I elected to put two entry points in the program so a single source program will provide both functions.

To install the source programs (the subprogram and a test program), and compile them, create a simple test EBCDIC file and test the program, execute the bash script:  downloads/AtoEtoA.setup  [md5: f3840a5c94871fe8e125d99c171fb412].  Right click and save the script in the location where you want the source program to reside, then execute it.  It will create two files containing the source programs, call the GnuCOBOL compiler to compile them into the run unit for the test, create a simple EBCDIC file to test with, and then execute the test program.  The GnuCOBOL compiler must be installed prior to executing the bash script.  

It was a bit difficult to devise a test program to show the use of this subprogram, as typical use would be to convert character encoding of a field inside of another program.  I decided the simplest way to achieve that was to use the iconv program to create a file containing the testSubs.cbl source in EBCDIC.

Output from the script:

jay@Phoenix ~ $ ./AtoEtoA.setup 
******************************************************************
      * Author: Jay Moseley
      * Date: November 10, 2019
      * Purpose: Testing various subroutines.
      ******************************************************************
       IDENTIFICATION DIVISION.

       PROGRAM-ID. testSubs.
       ENVIRONMENT DIVISION.

       CONFIGURATION SECTION.
       REPOSITORY.
           FUNCTION ALL INTRINSIC.

       INPUT-OUTPUT SECTION.
       FILE-CONTROL.

           SELECT SAMPLE-INPUT-FILE
               ORGANIZATION IS LINE SEQUENTIAL
               ASSIGN TO 'sample.ebcdic.txt'.

       DATA DIVISION.

       FILE SECTION.

       FD  SAMPLE-INPUT-FILE
           DATA RECORD IS SAMPLE-INPUT-RECORD.
       01  SAMPLE-INPUT-RECORD         PIC X(3000).

       WORKING-STORAGE SECTION.

       01  INPUT-SEQUENCE              PIC 9(6) VALUE 0.
       01  END-OF-INPUT-SWITCH         PIC X VALUE 'N'.
           88  END-OF-INPUT                  VALUE 'Y'.
           88  NOT-END-OF-INPUT              VALUE 'N'.

       PROCEDURE DIVISION.

       MAIN-PROCEDURE.

           OPEN INPUT SAMPLE-INPUT-FILE.

           PERFORM UNTIL END-OF-INPUT

             READ SAMPLE-INPUT-FILE
               AT END
                 SET END-OF-INPUT TO TRUE
               NOT AT END
                 ADD 1 TO INPUT-SEQUENCE
                 CALL 'TOASCII' USING SAMPLE-INPUT-RECORD (1:1595)
                 DISPLAY TRIM(SAMPLE-INPUT-RECORD)
             END-READ
           END-PERFORM.

           CLOSE SAMPLE-INPUT-FILE.

           GOBACK.

       END PROGRAM testSubs.


jay@Phoenix ~ $ 

This page was last updated on July 21, 2020.