How to convert between EBCDIC and UNICODE and also EBCDIC and ASCII character sets in Cobol programs?

Document ID : KB000051584
Last Modified Date : 14/02/2018
Show Technical Document Details

Description

Using a COBOL program as a TCPIP client or Server between IDMS on the mainframe and some other platform that supports UNICODE or ASCII may require the COBOL program to be able to convert between EBCDIC and UNICODE and also between EBCDIC and ASCII.

Solution

This conversion between these character sets can be done in COBOL but an easier solution is to call an Assembler routine from COBOL to do this conversion. Save the CODECONV attachment which is the Assembled object to your PC and upload it to the mainframe with LRECL=80 in binary mode with CRLF not selected.

Use the link JCL below to link the CODECONV object. Assign the physical sequential dataset containing the OBJECT to the CONVOBJ DD.

//LINKSTEP EXEC  PGM=IEWL,                                        
//   PARM='LET,MAP,LIST,NCAL,SIZE=(524288,65536),RENT,REUS,REFR'  
//SYSLMOD   DD DSN=IDMS.LOADLIB,DISP=SHR               
//CONVOBJ   DD DSN=CODECONV.OBJECT,DISP=SHR                              
//SYSPRINT  DD SYSOUT=*                                           
//SYSLIN    DD   *                                                
 INCLUDE CONVOBJ                                       
 ENTRY   CODECONV                                                  
 NAME    CODECONV(R)                                              
/* 

Define this program to the SYSGEN using the following program statement then generate it:

ADD PROGRAM CODECONV                 
         CONCURRENT                       
         NODYNAMIC                        
         DUMP THRESHOLD IS 0              
         ENABLED                          
         ERROR THRESHOLD IS 5             
         ISA SIZE IS 0                    
         LANGUAGE IS ASSEMBLER            
         MPMODE IS SYSTEM                 
         NOMAINLINE                       
         MULTIPLE ENCLAVE IS ON           
         NEW COPY IS ENABLED              
         OVERLAYABLE                      
         PROGRAM                          
         PROTECT                          
         REENTRANT                        
         RESIDENT                         
         REUSABLE                         
         SAVEAREA                         
         .                               

This utility takes four parameters.


Length: A PIC 9(8) COMP field which is the number of bytes to be converted.

Type of conversion: A PIC X(2) field which indicates the type of conversion, that is, EA for EBCDIC to ASCII, AE for ASCII to EBCDIC, EU for EBCDIC to Unicode and UE for Unicode to EBCDIC.


Input field: A PIC X(N) field that contains to input of length N. This field can contain EBCDIC, ASCII or Unicode.


Output field: A PIC X(N)field for the converted output.

The length should not exceed the size of the input or output fields.

The call from COBOL to this program can be dynamic or static. The example of the code below is for a dynamic call which does not require the program to be linked with the user COBOL program that could be used as a client or server. Example: 01 SUBROUTINE-NAME PIC X(8) VALUE 'CODECONV'.

         01 CTRLSIZE        PIC 9(8) COMP.
         01 CTRLTYPE        PIC X(2). 
         01 INPUT-FIELD     PIC X(80). 
         01 OUTPUT-FIELD    PIC X(80).
 
               MOVE 80   TO CTRLSIZE.
               MOVE 'EU' TO CTRLTYPE.
               CALL SUBROUTINE-NAME USING CTRLSIZE,
                                          CTRLTYPE,
                                          INPUT-FIELD,
                                          OUTPUT-FIELD.

IDMSIN01 can also be called to convert between ASCII and EBCDIC. It does not support conversion between UNICODE and EBCDIC. Refer to the Callable Services Guide 3.4.1 for an example of COBOL calling IDMSIN01.

File Attachments:
TEC522052.zip