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

How to convert text to hexadecimal format.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 8797
Location: Welsh Wales

PostPosted: Wed May 05, 2010 4:47 pm
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
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
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
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed May 05, 2010 7:43 pm
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: 1353
Location: Israel

PostPosted: Wed May 05, 2010 8:28 pm
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
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

Moderator Emeritus


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

PostPosted: Thu May 06, 2010 1:35 am
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
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
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: 2146
Location: At my coffee table

PostPosted: Thu May 06, 2010 2:00 am
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu May 06, 2010 2:25 am
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
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu May 06, 2010 5:47 am
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
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

Moderator Emeritus


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

PostPosted: Thu May 06, 2010 8:23 am
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
vardhan0007

New User


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

PostPosted: Thu May 06, 2010 10:50 am
Reply with quote

Hi D.sch,

I am changing because while posting the entire data into a table that enter key not getting posted into table. So if can replace X'0A' with some other value and post it to table perl will recognize.

-Harsha
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 May 06, 2010 8:00 pm
Reply with quote

Hello,

Why can the perl script not detect and act on the x'0A' (which is octal "012")?
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 8:43 pm
Reply with quote

vardhan0007 wrote:
Hi D.sch,

I am changing because while posting the entire data into a table that enter key not getting posted into table.
-Harsha


Why is it not getting posted to the table?
Back to top
View user's profile Send private message
vardhan0007

New User


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

PostPosted: Fri May 07, 2010 10:19 am
Reply with quote

Hi D.sch,

The text is being inserted into a table and again from table we are writing into a falt file and in file if see there is not enter key trapped hence perl is unable act on enter key.

Hi Crag,

The table is a oracle table I am not sure why its unable to show us the enter key in the text.

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

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Fri May 07, 2010 12:00 pm
Reply with quote

Sorry to say you have kept confusing everybody with your replies.
If you want to replace one character by another one character, that is one thing.
If you want to replace one character by a word (2 or 3 characters), that is another thing.

vardhan0007 wrote:
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.


If you don't believe the expert advice, then you have 2 choices:
1. Try by yourself.
2. Go to another Forum.

Now, about which character to use:
Stop using strange values, like X'2B' or X'AA', which are not displayable.
Stop using standard characters, like C'2B', which could be misunderstood as part of the text.
Use only '|'. This is the best option, as it is sometimes used as a separator.

Code:
INSPECT YOUR-VAR REPLACING ALL X'0A' BY '|'


The correct answer has already been provided. This should be the last reply in this thread.
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 Goto page 1, 2  Next

 


Similar Topics
Topic Forum Replies
No new posts Populate last day of the Month in MMD... SYNCSORT 2
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts InfoSphere OPTIM CSV ouput vs DSNTIUA... IBM Tools 3
Search our Forums:

Back to Top