Hi Experts-
I have a need (in ABAP) for being able to convert a decimal value to its hex representation.
I have Document IDs such as '189' and '192' and there is an image file associated with each document called '000000BD' and '000000C0.jpg' respectively. The C0 is the hex representation of the decimal 192 and BD of 189.
Is there a standard function module that I can use for determining this? If not, any quick custom code you can think of?
Thank you,
- Vik.
Hi,
Try this code.
REPORT ZC1_NUMBER_CONVERSION .
data: v_hexa type x,
v_deci type i.
v_deci = '192'.
v_hexa = v_deci.
write:/ 'Decimal :' , v_deci , ' = Hexa Decimal :' , v_hexa.
I got the following result,
Number Conversion
Decimal : 192 = Hexa Decimal : C0
Hope this helps you.
Cheers
Kathir~
Hi,
Hope you have got your problem solved. If you require the same in a function module that will return a value of size 8
as you have shown, i.e. 192 -> 000000C0 then this code will be helpful i believe.
FUNCTION Z_DECIMAL_TO_HEXA.
*"----
""Local interface:
*" IMPORTING
*" VALUE(V_DECIMAL) TYPE I DEFAULT 0
*" EXPORTING
*" VALUE(V_HEXA_VALUE) TYPE CHAR8
*"----
data: v_hexa type x,
v_cnt type i.
v_hexa = v_decimal.
v_hexa_value = v_hexa.
v_cnt = strlen( v_hexa_value ).
v_cnt = 8 - v_cnt.
do v_cnt times.
concatenate '0' v_hexa_value into v_hexa_value.
enddo.
ENDFUNCTION.
Then if you requirement is met please close this topic.
Thanks and Regards,
Kathir~
Hi Vik,
I don't see a need for a Function Module in this case. As Kathir had mentioned, a simple type conversion will do the trick. Push an integer into a Hex field and you'll get what you want.
Also, I notice that quite a few of your recent postings have not been closed. Could you please mark them as answered ?
Regards,
Anand Mandalika.
Hi Poornanand,
First of all thanks for your valid points. Basically, i was trying to help with a logic and did not investigate much say handling large values, thinking that the concerned will take care of the same.
Thanking you again for your suggestions.
Thanks & Regards,
Kathir~
Add a comment