IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Built-in function to convert Char to EBCDIC


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
trbala

New User


Joined: 29 Oct 2008
Posts: 2
Location: Chennai

PostPosted: Thu Oct 30, 2008 12:05 pm
Reply with quote

There is any buil-in function in VS COBOL II to convert chanracter to EBCDIC?. if so, please help me with peace of sample code or function.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Oct 30, 2008 12:20 pm
Reply with quote

Quote:
chanracter to EBCDIC
Shuold I read as ASCII to EBCDIC ?
Back to top
View user's profile Send private message
trbala

New User


Joined: 29 Oct 2008
Posts: 2
Location: Chennai

PostPosted: Thu Oct 30, 2008 12:29 pm
Reply with quote

No, it should be read as Char to EBCDIC.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Oct 30, 2008 12:56 pm
Reply with quote

Quote:

No, it should be read as Char to EBCDIC


with the exception of db2 columns in unicode, everything on IBM Mainframes is in EBCDIC.

suggest you do some reading about your environment.

if you have more questions, post them.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Oct 30, 2008 7:32 pm
Reply with quote

Hello,

Quote:
No, it should be read as Char to EBCDIC.
Please post some of your non-ebcdic chars in hex.
Back to top
View user's profile Send private message
Bob Ream

New User


Joined: 05 Nov 2008
Posts: 7
Location: RI

PostPosted: Thu Nov 06, 2008 10:01 pm
Reply with quote

Funny you should ask this question as I have recently an opportunity to do just that. There are 2 tables you need to put in your program and one line of code.

Code:
 
      *****************************************************************     
      * The following tables are used by the INSPECT statement to do  *
      * the conversion betweeen EBCDIC and ASCII.                     *
      * inspect FIELD-NAME converting EBCDIC-INFO to ASCII-INFO       *
      * inspect FIELD-NAME converting ASCII-INFO  to EBCDIC-INFO      *
      *                                                               *
      * The tables may also be used to convert between lower and      *
      * upper case.         *                                         *
      * inspect FIELD-NAME converting EBCDIC-LOWER to EBCDIC-UPPER    *
      * inspect FIELD-NAME converting ASCII-LOWER  to ASCII-UPPER     *
      *****************************************************************
      *                                                               
      *>   ------------------------------------------------------------
      *>   **  The EBCDIC Table ...                                   
      *>   **  01                             A B C D E F G H I       
      *>   **  02                             J K L M N O P Q R       
      *>   **  03                             S T U V W X Y Z         
      *>   **  04                             a b c d e f g h i       
      *>   **  05                             j k l m n o p q r       
      *>   **  06                             s t u v w x y z         
      *>   **  07                             0 1 2 3 4 5 6 7 8 9     
      *>   **  08                         space . < ( + | & ! $ *     
      *>   **  09                             ) ; - / , % _ > ? `     
      *>   **  10  7D/7F Single/Double quote  : # @7D =7F  { }     
      *>   **  11                             \ ~                        
       01  EBCDIC-DATA.                                               
           05  EBCDIC-UPPER-CASE-DATA.                               
               10  filler  pic X(9)  value X'C1C2C3C4C5C6C7C8C9'.     
               10  filler  pic X(9)  value X'D1D2D3D4D5D6D7D8D9'.     
               10  filler  pic X(8)  value X'E2E3E4E5E6E7E8E9'.       
           05  EBCDIC-UPPER          redefines EBCDIC-UPPER-CASE-DATA
                                     pic X(26).                       
           05  EBCDIC-LOWER-CASE-DATA.                               
               10  filler  pic X(9)  value X'818283848586878889'.     
               10  filler  pic X(9)  value X'919293949596979899'.     
               10  filler  pic X(8)  value X'A2A3A4A5A6A7A8A9'.       
           05  EBCDIC-LOWER          redefines EBCDIC-LOWER-CASE-DATA
                                     pic X(26).                       
           05  EBCDIC-DIGITS.                                         
               10  filler  pic X(10) value X'F0F1F2F3F4F5F6F7F8F9'.
          05  EBCDIC-SPECIAL.                                     
              10  filler  pic X(10) value X'404B4C4D4E4F505A5B5C'.
              10  filler  pic X(10) value X'5D5E60616B6C6D6E6F79'.
              10  filler  pic X(10) value X'7A7B7C7D7E7FADBDC0D0'.
              10  filler  pic X(3)  value X'E0A1B0'.               
      01  EBCDIC-INFO     redefines EBCDIC-DATA pic X(95).         
      01  EBCDIC-TABLE    redefines EBCDIC-DATA.                   
          05  EBCDIC-BYTE pic X     occurs 95 times.               
     *                                                             
     *>   ---------------------------------------------------------
     *>   **  The ASCII Table ...                                 
     *>   **  01                             A B C D E F G H I     
     *>   **  02                             J K L M N O P Q R     
     *>   **  03                             S T U V W X Y Z       
     *>   **  04                             a b c d e f g h i     
     *>   **  05                             j k l m n o p q r     
     *>   **  06                             s t u v w x y z       
     *>   **  07                             0 1 2 3 4 5 6 7 8 9   
     *>   **  08                         space . < ( + | & ! $ *   
    *>   **  09                             ) ; - / , % _ > ? `     
    *>   **  10  27/22 Single/Double quote  : # @27 =22           { }     
    *>   **  11                             \ ~                        
     01  ASCII-DATA.                                               
         05  ASCII-UPPER-CASE-DATA.                                 
             10  filler  pic X(9)  value X'414243444546474849'.     
             10  filler  pic X(9)  value X'4A4B4C4D4E4F505152'.     
             10  filler  pic X(8)  value X'535455565758595A'.       
         05  ASCII-UPPER           redefines ASCII-UPPER-CASE-DATA 
                                   pic X(26).                       
         05  ASCII-LOWER-CASE-DATA.                                 
             10  filler  pic X(9)  value X'616263646566676869'.     
             10  filler  pic X(9)  value X'6A6B6C6D6E6F707172'.     
             10  filler  pic X(8)  value X'737475767778797A'.       
         05  ASCII-LOWER           redefines ASCII-LOWER-CASE-DATA 
                                   pic X(26).                       
         05  ASCII-DIGITS.                                         
             10  filler  pic X(10) value X'30313233343536373839'.   
         05  ASCII-SPECIAL.                                         
            10  filler  pic X(10) value X'202E3C282B7C2621242A'.
            10  filler  pic X(10) value X'293B2D2F2C255F3E3F79'.
            10  filler  pic X(10) value X'3A2340273D225B5D7B7D'.
            10  filler  pic X(3)  value X'5C7E5E'.               
    01  ASCII-INFO      redefines ASCII-DATA pic X(95).         
    01  ASCII-TABLE     redefines ASCII-DATA.                   
        05  ASCII-BYTE  pic X     occurs 95 times.         


The WS-POS-6501-ENCRIP-DATA is the output field. The actual convert code would be:

Code:
 C000-CONVERT-ASCII SECTION.                                     
*>   MOVE ALL X'20' to SYSUT2-RECORD.                             
     MOVE ALL X'20' to WS-POS-6501-ENCRIP-DATA.                   
*>   TransLATE...                                                 
*>   MOVE SYSUT1-RECORD(00001:00080) to SYSUT2-RECORD(00001:00080)
     MOVE WS-POS-IN-REC TO WS-POS-IN-REC-6501                     
     INSPECT WS-POS-6501-ENCRIP-DATA(00001:00080)                 
         CONVERTING ASCII-INFO TO EBCDIC-INFO.             

I have used this and it does work.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Nov 07, 2008 1:52 am
Reply with quote

Hi Bob,

Thanks for the translator code icon_smile.gif

We're still waiting for trbala to post some of the troublesome non-ebcdic characters. . .

d
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Nov 07, 2008 2:19 am
Reply with quote

I might be picky icon_biggrin.gif but I feel that the approach is a bit approximate...
or the requirement is a bit generic

the approach shown would work for printable

a truly foolproof approach would be to use a table for all the ascii symbols

two tables really....
a standard ASCII with 128 chars
an extended ASCII with 256 chars

maybe two more for checking...
whose content be a simple flag byte to tell if the translation is possible
carry on the translation raising a condition error whenever a char cannot be translated

the same approach for the other way around

but thats a personal opinion, or the way I would specify the requirement
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Calling an Open C library function in... CICS 1
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts DATE2 function SYNCSORT 15
Search our Forums:

Back to Top