Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to convert text to hexadecimal format.
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
vardhan0007

New User


Joined: 05 Jun 2006
Posts: 51
Location: Bangalore,India

PostPosted: Wed May 05, 2010 4:39 pm    Post subject: How to convert text to hexadecimal format.
Reply with quote

Hi,

I have a rquirement to convert text to hexadecimal format.
I will be recieving around 1000 bytes o f text from front end (may be from windows text box) i need to convert the text in to hexadecimal format. Please anyone let me know whether there is any function in cobol will do this.

input text : abcdefghijklmnhguookansjdkaks

01 ws-input-text pic x(1000) values spaces.

Move input-text to ws-input-text.


Now i need convert the data which is in ws-input-text to hexadecimal and move it to another file.

Thanks,
Harsha
Back to top
View user's profile Send private message

expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Wed May 05, 2010 4:47 pm    Post subject:
Reply with quote

Ok, you've got me. Why does it need to be represented in 'X format. Why do you want to double the number of bytes used to store the data again.

Methinks a little more explanation would be nice.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed May 05, 2010 4:47 pm    Post subject:
Reply with quote

Quote:
convert the text in to hexadecimal format


no such thing as hexadecimal format.

now, do you mean that you want to display in two bytes,
the hex representation of 1 byte?

e.g.: 'A' >> 'C1'

or are you talking about converting ansii to ebcdic?

you need to clarify your requirement - using acceptable IT terms,
before anyone can provide you with ideas on how to accomplish your task.
Back to top
View user's profile Send private message
vardhan0007

New User


Joined: 05 Jun 2006
Posts: 51
Location: Bangalore,India

PostPosted: Wed May 05, 2010 5:09 pm    Post subject:
Reply with quote

Actually my requirement is.... I am recieving 1000 bytes of text from front end appplication as below.
1)asdaskldjaskldjaskjdaslfjljflasdhfhafhljsfhkjsfhlafkasfhsdkjf
sdfkhaskfjhalshdfjsdhfhlafjladsfhkjdshafkdlashfkjsdh
dasfkhadskfhldahfladsfsdjafhsdafhld
sadkfhdsafhjasdfkjdsfl

2)lsdhfdsfyuidhuiaseyrefuioerfefrefhsdhfu435927894fewjfioedfcsdjlf
ilwerufwy5rtifcjwerioy3948rweruihw489rfhl
weirfwe8ry.askldfhsafhjks.

I want trace the enterkey. Meaning when the user ahs pressed enter key. In text which is comming to cobol code i can its comming as some special charector. I did a hex on and observed that "0A" is in that.
So what i need to do is i need replace that special charector to the word 2B.

Please let me know if you require mor info.

Thanks,
Harsha
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed May 05, 2010 5:14 pm    Post subject:
Reply with quote

Why not just search the input for X'0A' and replace it with X'2B'?
Back to top
View user's profile Send private message
vardhan0007

New User


Joined: 05 Jun 2006
Posts: 51
Location: Bangalore,India

PostPosted: Wed May 05, 2010 5:18 pm    Post subject:
Reply with quote

Can I directly inspect the 1000 byte field(chare field) for X'0A' and replace with X'2B'

If yes, again I am putting a hex value X'2B' but I need to put 2B (char)
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed May 05, 2010 7:43 pm    Post subject: Reply to: Ho to convert text to hexadecimal format.
Reply with quote

This will convert the hex-values in a 1000-byte area (on the fly) to their 2-byte equivilent in a 2000-byte area, one byte at a time. You can probably experiment and convert 8-bytes to 16-bytes at a time, but that's up to you -

Code:

           03  WS-FWORD            PIC  9(08)      COMP.
           03  FILLER              REDEFINES WS-FWORD.
               05  FILLER          PIC  X(02).
               05  WS-HWORD        PIC  9(04)      COMP.
           03  WS-PACKED           PIC  9(01)V9    COMP-3.
           03  WS-PACKED-X         REDEFINES WS-PACKED
                                   PIC  X(02).
           03  WS-DISPLAY          PIC  9(02)V9.
           03  WS-DISPLAY-X        REDEFINES WS-DISPLAY
                                   PIC  X(03).
           03  WS-1000-BYTE-REC.
               05  WS-1000-BYTE-TBL
                                   OCCURS 1000 TIMES
                                   INDEXED BY X-WS-1000, X-WS-1000-MAX
                                   PIC  X(01).
           03  WS-2000-BYTE-REC.
               05  WS-2000-BYTE-TBL
                                   OCCURS 1000 TIMES
                                   INDEXED BY X-WS-2000, X-WS-2000-MAX
                                   PIC  X(02).
      *
           MOVE LENGTH OF WS-1000-BYTE-REC
                                       TO WS-FWORD.
           SET  X-WS-1000-MAX          TO WS-HWORD.
           MOVE LENGTH OF WS-2000-BYTE-REC
                                       TO WS-FWORD.
           SET  X-WS-2000-MAX          TO WS-HWORD.
           SET  X-WS-1000              TO 1.
           SET  X-WS-2000              TO 1.
           MOVE ZERO                   TO WS-PACKED.
      *
           PERFORM UNTIL X-WS-1000 > X-WS-1000-MAX
               MOVE WS-1000-BYTE-TBL (X-WS-1000)
                                       TO WS-PACKED-X (1:1)
               MOVE WS-PACKED          TO WS-DISPLAY
               MOVE WS-DISPLAY-X       TO WS-2000-BYTE-TBL (X-WS-2000)
               SET  X-WS-1000          UP BY 1
               SET  X-WS-2000          UP BY 1
           END-PERFORM.
      *
           INSPECT WS-2000-BYTE-REC    CONVERTING X'FAFBFCFDFEFF'
                                       TO 'ABCDEF'.

So (for example), if the 1000-byte area had equaled all SPACES (X'40'), the 2000-byte area now contains all C'40' (X'F4F0').

HTH....

Bill
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1219
Location: Israel

PostPosted: Wed May 05, 2010 8:28 pm    Post subject: Reply to: Ho to convert text to hexadecimal format.
Reply with quote

Please vardhan0007, you need to relax first.
Take a deep breath, gather your thoughts, then talk to us again.

The beginning is easy to understand:
You have a cobol program. I guess you are writing it.
This program receives as input a 1000 bytes long string.
This string contains some text, and each time the user hit the enter key there is a X'0A' (line feed) in the text.

Now things get a bit messy and you have to explain exactly what you need to do (not what you want).

Replace this X'0A' by X'2B' ? (if yes, why ?)
Replace it by C'2B' ? (if yes, why ?)
Maybe you need to split the big string into smaller lines ?
Back to top
View user's profile Send private message
vardhan0007

New User


Joined: 05 Jun 2006
Posts: 51
Location: Bangalore,India

PostPosted: Thu May 06, 2010 1:25 am    Post subject:
Reply with quote

Hi Marso,

Actually as i said in my previous posts, my cobol program is recieving test from user interface where the user will enter the text in a text box.

And cobol program is taking that data and insert into a table. Again the data will be taken from table into a flat file and will run perl script on to format the data in to paragraphs.

Now the problem is while posting the data into table its not catering for "enter key" meaning when user hit the enter while entering the data into text box if s/he hit the enter for a new line that hit we are not posting it into data base(though we are blindly moving entire 1000 bytes to data base) but when see the data which is comming from text box I can a special charector in it (so i did a hex on on the data and i found enter key is interpreted as "0A").

Now wat i need to do is, trace the enter key and replace the enter key with any readable character (can be anyhting like A,B,C,etc..) so that in perl script we can recognize that replaced letter and format the text as user entered.

Hope now you understand my requirement.

Thanks,
Harsha
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Thu May 06, 2010 1:35 am    Post subject:
Reply with quote

Hello,

When the data is read from the database, where will it be shown (on a mainframe terminal or some web page or . . .)? Depending on the presentation code, the x'0A' may be ok. . .

If you want to use some value and then have perl deal with it, you could convert the x'0A' to x'EE' and let the perl act on the x'EE'. If this would work, i'm not sure why the perl code cannot simply look for the x'0A'.

Obviously, there is something i am missing. . . icon_confused.gif
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Thu May 06, 2010 1:38 am    Post subject:
Reply with quote

If x'0A' is the only character you need to find/change then it would be easiest ( and fastest) to just

INSPECT 1000-BYTE-FIELD CONVERTING X'0A' TO X'??'

where '??' is the hex representation of what you want to replace x'0A' with.
Back to top
View user's profile Send private message
vardhan0007

New User


Joined: 05 Jun 2006
Posts: 51
Location: Bangalore,India

PostPosted: Thu May 06, 2010 1:48 am    Post subject:
Reply with quote

Hi D.sh,

Actually cobol program is posting the data into a table and again another program is unloading the data into a flat file where I am seing the data in a continuous line ( This file i have seen in some unix platform not in mainframe) so now the probelm is when iam seeing the file in unix i cant see any special charecter in the place of enter hence perl is unable do anything. If I can differntiate enter with any word or letter (lets say replacing X'0A' with some ## then perl script can identify ## and put the rest of data in a new line.
And I dont know when I can inspect the incoming data for X'0A' and replace with ## or to any other readable format direclty. Please advice.

Hi Ronald,

Please confirm whether I can directly inspect the 1000 byte field as u said in ur post and replace with some word which I like.

Thanks in advacne.
Harsha
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Thu May 06, 2010 2:00 am    Post subject:
Reply with quote

About the INSPECT statement, Enterprise COBOL for z/OS V4.2 Language Reference wrote:
Code:
    ___ Format 2: INSPECT statement with REPLACING phrase ____________________________________________
   |                                                                                                  |
   | >>__INSPECT__identifier-1__REPLACING___________________________________________________________> |
   |                                                                                                  |
   |    <___________________________________________________________________________________          |
   |                                         <__________________                            |         |
   | >____ _CHARACTERS BY__ _identifier-5_ ____ ______________ _|_________________________ _|______>< |
   |      |                |_literal-3____|    |_| phrase 1 |_|                           |           |
   |      |              <______________________________________________________________  |           |
   |      |                                                        <__________________  | |           |
   |      |_ _ALL_____ ____ _identifier-3_ __BY__ _identifier-5_ ____ ______________ _|_|_|           |
   |        |_LEADING_|    |_literal-1____|      |_literal-3____|    |_| phrase 1 |_|                 |
   |        |_FIRST___|                                                                               |
   |                                                                                                  |
   | phrase 1:                                                                                        |
   | |__ _BEFORE_ __ _________ __ _identifier-4_ ___________________________________________________| |
   |    |_AFTER__|  |_INITIAL_|  |_literal-2____|                                                     |
   |                                                                                                  |
   |__________________________________________________________________________________________________|
Back to top
View user's profile Send private message
vardhan0007

New User


Joined: 05 Jun 2006
Posts: 51
Location: Bangalore,India

PostPosted: Thu May 06, 2010 2:05 am    Post subject:
Reply with quote

Hi CICS guy,

I am aware of the syntax of INSPECT my question is if inspect X'0A' and replace it with for example x'AA' which is 170 ...then i insert the same to databse. Now can I be able to see that 170 in the data which i inserted into database?

Thanks for your reply above.

Thanks,
Harsha
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu May 06, 2010 2:25 am    Post subject: Reply to: How to convert text to hexadecimal format.
Reply with quote

So, you want each hex-byte in the 1000-byte area converted to 3-bytes display-numeric? This would mean that you need a 3000-byte output area, not a 2000-byte area.

For example, if a byte from the 1000-byte input-area contains X'40' then its equivalent in the 3000-byte output-area would contain a display-numeric 064. I thought you wanted to convert (and I'll use a X'40' again) to a 2-Byte C'40'? If you want to use a 2000-byte area and store each byte as its 3-byte display-numeric decimal equivalent, as soon as the input byte-value exceeds X'63', you're out of luck.

Please correct me if I'm wrong or explain this just a little bit better, because it seems there are many folks scratching their heads, including me.

Bill
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Thu May 06, 2010 2:50 am    Post subject:
Reply with quote

In this instance, you can use either

INSPECT 1000-BYTES REPLACING ALL X'0A' BY X'AA'

or

INSPECT 1000-BYTES CONVERTING X'0A' TO X'AA'

Both constructs result in the exact same machine code - namely a series of TRanslate instructions.

However, neither construct will permit you to replace a CHARACTER ( 1 byte ) with a WORD ( more than 1 byte ).

While the CONVERTING construct only works on individual bytes ( though it can convert many byte values to other byte values ), the REPLACING construct can also be used to replace a multi-byte string with another equal length string.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Thu May 06, 2010 5:10 am    Post subject:
Reply with quote

vardhan0007 wrote:
Hi Marso,

Actually as i said in my previous posts, my cobol program is recieving test from user interface where the user will enter the text in a text box.

And cobol program is taking that data and insert into a table. Again the data will be taken from table into a flat file and will run perl script on to format the data in to paragraphs.

Now the problem is while posting the data into table its not catering for "enter key" meaning when user hit the enter while entering the data into text box if s/he hit the enter for a new line that hit we are not posting it into data base(though we are blindly moving entire 1000 bytes to data base) but when see the data which is comming from text box I can a special charector in it (so i did a hex on on the data and i found enter key is interpreted as "0A").

Now wat i need to do is, trace the enter key and replace the enter key with any readable character (can be anyhting like A,B,C,etc..) so that in perl script we can recognize that replaced letter and format the text as user entered.

Hope now you understand my requirement.

Thanks,
Harsha


What if the characters you are using to replace the x'0A' already exist in the data? Can't the perl script recognize a x'0A'?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Thu May 06, 2010 5:47 am    Post subject:
Reply with quote

"enter" keeps getting used but X'0A' is actually an LF (linefeed) character. Some 3270 emulators map the PC enter key to a newline (LF) character -- but calling it an enter doesn't make it one; it is still a linefeed character. The Perl script should be changing X'0A' to '\n'.
Back to top
View user's profile Send private message
vardhan0007

New User


Joined: 05 Jun 2006
Posts: 51
Location: Bangalore,India

PostPosted: Thu May 06, 2010 6:51 am    Post subject:
Reply with quote

Hi Bill,

Forget about converting to hex. What I need to do is trce the in the incoming text when the enter key was pressed, meaning while entering the text in text box user might have used enter key for a new line so i need to capture that key stroke and change that incoming junkh value to any readable value and insert into table.
I see the which is comming is like dot/bullet mark (".") so i did a hexon and seenthat value is nothing but 0A.

Thanks,
Harsha
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Thu May 06, 2010 8:23 am    Post subject:
Reply with quote

Hello,

Yes, the x'0A' is exactly correct. . . And on the mainframe this is a non-printable character so the dot is displayed on the terminal. This does not mean there is anything wrong with the character, only that it will not "print" on the 3270 screen.

What is not yet clear (at least to me) is why you believe you need to change it to something else. . .
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts Convert +9999999999999.99 to S9(12)V9(3) vnktrrd DFSORT/ICETOOL 8 Thu Nov 17, 2016 8:15 pm
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
No new posts convert PD to ZD ram_vizag DFSORT/ICETOOL 5 Sat Nov 05, 2016 3:06 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us