How to write a HEX string into a file as HEX using REXX..



IBM's Command List programming language & Restructured Extended Executor

How to write a HEX string into a file as HEX using REXX..

Postby rajareddy.tkm » Fri Dec 25, 2009 10:31 am

I have a string 'RAJA' which should be written into a file as HEX data.
Here are sample codes which help me to describe the issue.
Case(a)
name = 'RAJA'   
name = C2X(name) /* Hex value = 'FRFAFJFA' */
QUEUE name.
Output to the file: FRFAFJFA

But if we use HEX data directly to write into file it's working fine
Case(b)
name = 'FRFAFJFA'X
QUEUE name.
Output to the file: RAJA

Issue: In case(a) when the string was converted into HEX using C2X, it returns a HEX data string not a HEX data. But in case(b) as HEX data was written to file. My question is how to let REXX interpreter know that the variable 'name' in case(a) has HEX data and to be written it as HEX. Hope i made the issue clear. Lemme tread towards a solution.

Thanks
Raja Reddy
rajareddy.tkm
 
Posts: 4
Joined: Fri Dec 25, 2009 9:58 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to write a HEX string into a file as HEX using REXX..

 

Re: How to write a HEX string into a file as HEX using REXX..

Postby Robert Sample » Sat Dec 26, 2009 10:39 am

Hexadecimal characters go from 0 to 9 and A to F. There is no such thing as FR or FJ in hexadecimal. Furthermore, you need to find a copy of the EBCDIC collating sequence (hint: Google is your friend) and study it long enough to understand how the upper case letters are stored internally on the mainframe.

Finally, every byte in every file ever written on a mainframe is in hexadecimal already. Your statement that the data should be written to a file in hex is completely and utterly nonsensical since every byte is already written in hex. Perhaps if you clarify exactly what you are attempting to accomplish, we can provide assistance. But as your problem was written, you have no issue because the file is already being written in hexadecimal.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: How to write a HEX string into a file as HEX using REXX..

Postby rajareddy.tkm » Wed Dec 30, 2009 2:59 pm

Hi Rob,
I took that HEX value as instance and I felt the issue will be sensed rather.

And I doubt what you said..
"Finally, every byte in every file ever written on a mainframe is in hexadecimal already. Your statement that the data should be written to a file in hex is completely and utterly nonsensical since every byte is already written in hex." There might be a possibility in mainframe that we can view any data as HEX. But please explain if you have something.
And here comes the actual part:

Finally, I could resolve MYSELF issue described top. There is built-in function in REXX called 'INTERPRET', which helps us in building dynamic REXX commands. Here is the single statement, made me run the module successfully:

INTERPRET name_hex "= '" || name || "'X"

It dynamically creates a REXX statement:

name_hex = 'name'X

which will tell REXX interpreter the string in 'name' as HEX data.

Awesome right! Hope I made you clear.. Do get back to me with your questions..
rajareddy.tkm
 
Posts: 4
Joined: Fri Dec 25, 2009 9:58 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to write a HEX string into a file as HEX using REXX..

Postby Robert Sample » Wed Dec 30, 2009 9:02 pm

Let me clarify: the mainframe uses binary for everything. Hexadecimal is merely a shorter form of binary. Every command you enter, every byte written to every file, everything done in memory -- all is binary to the computer, which means it is hexadecimal by its very nature. Period. If you use ISPF Edit to open a file, and you issue on the command line "HEX ON'", you will see the hexadecimal characters that are in that file. 12345 will be shown to be hexadecimal F1F2F3F4F5, or binary 111100011111001011110011111010011110101 (take your pick - they're the same values). If you write RAJA to a file, and use ISPF HEX mode to view that file, you will see D9C1D1C1 -- which is the hexadecimal values for the EBCDIC characters RAJA. And if you're working on an ASCII machine you'll get hexadecimal 52414A41 as the C2X value of 'RAJA'

You are obviously not testing anything or you would have known by now that C2X('RAJA') does not return FRFAFJFA since two of those "values" are not valid hex characters. I recommend you get on a system and experiment with it for a while before asking more questions -- you will be able to find out a lot by doing it yourself.

Until you clarify what you meant by
I have a string 'RAJA' which should be written into a file as HEX data.
there's not much more to be said.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: How to write a HEX string into a file as HEX using REXX..

Postby rajareddy.tkm » Mon Jan 04, 2010 4:34 pm

Robert,
I agree to what you said, but we have been throwing responses except on my issue. Prior to explaining my issue clearly, lemme say...
As you said, each and every byte is HEX(or binary) in Mainframe. But it differs in the case of numeric data. Strings dont get affected, so we got detoured from the root cause of the issue.

I knew that the function C2X returns 52414A41, not FRFAFJFA. I gave/used that value as i was eager to describe the problem and ofcourse that particular word was not tested for HEX value. If that detoured you! i'm sorry.

Now coming issue:

num = 2500
num_hex_str = C2X(num) /* HEX Value: 09C4*/

As per you, writing 2500 would be stored using mainframe as "F2F5F0F0" not like "09C4".

But I need num to be written as HEX. It was my bad that i had taken string data for instance instead of numeric data. Now if i write num_hex_str into a file, a string "09C4" will be written instead of special characers.

writing 09C4 as string is different from writing as HEX, I hope it make sense...
rajareddy.tkm
 
Posts: 4
Joined: Fri Dec 25, 2009 9:58 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to write a HEX string into a file as HEX using REXX..

Postby enrico-sorichetti » Mon Jan 04, 2010 5:35 pm

very little of what You have exposed makes sense :D
please explain clearly what You want to do!

given a number ... 2500 in your case the representation are...
char "2500" which is stored as "F2F5F0F0" and in rexx notation
"2500" and x"F2F5F0F0" are exactly the same thing viewed in two different terminologies
and the two <things> occupy four bytes each

what You are calling hex<stuff> is really a different concept ...
it' s a base conversion <thing> ,
You convert from base 10 to base 16 where each hex digit is stored as a semibyte
or convert to binary expressed in the hex shorthand convention

so please start again telling exactly what You want to do
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2643
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

Re: How to write a HEX string into a file as HEX using REXX..

Postby Anuj Dhawan » Tue Jan 05, 2010 9:27 pm

Robert - have fun...:D
Anuj
Anuj Dhawan
 
Posts: 274
Joined: Mon Feb 25, 2008 3:53 am
Location: Mumbai, India
Has thanked: 6 times
Been thanked: 4 times

Re: How to write a HEX string into a file as HEX using REXX..

Postby rajareddy.tkm » Thu Jan 07, 2010 8:20 am

Really lot of fun with you guys! :lol:
I would respond int he week-end, gotta go to office
Nice Day guys..
rajareddy.tkm
 
Posts: 4
Joined: Fri Dec 25, 2009 9:58 am
Has thanked: 0 time
Been thanked: 0 time


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post