Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Hi is there any function module for radix conversion

Former Member
0 Likes
650

Hi,

I need to convert number of base 36 to decimal number. Is there any function module for that.

i.e) z to 35

10 to 36

11 t0 37

Hi,

I need to convert number of base 36 to decimal number. Is there any function module for that.

i.e) z to 35

10 to 36

11 t0 37

2 REPLIES 2
Read only

Former Member
0 Likes
518

Hi,

Only the following maths functionas are there in SAP:

abs -Absolute value of the argument arg

sign- Plus/minus sign of the argument arg: -1, if the value of arg is negative; 0 if the value of arg is 0; 1 if the value of arg is positive.

ceil -Smallest integer number that is not smaller than the value of the argument arg.

floor- Largest integer number that is not larger than the value of the argument arg.

trunc- Value of the integer part of the argument arg

frac- Value of the decimal places of the argument arg

acos -Arcuscosinus [-1,1]

asin- Arcussinus [-1,1]

atan- Arcustangens

cos- Cosinus

sin- Sinus

tan- Tangens

cosh- Hyperbelcosinus

sinh -Hyperbelsinus

tanh -Hyperbeltangens

exp -Exponential function for basis e [-709, 710]

log -Natural logarithm > 0

log10 -Logarithm for basis 10 > 0

sqrt -Square root

reward if useful

regards,

Anji

Read only

Former Member
0 Likes
518

Hai,

This program perfectly converts a number from one number system to another number system.

REPORT Z_RADIX_CONVERSION.

PARAMETERS:

P_S_RAD(2) TYPE N, " Source Radix

P_D_RAD(2) TYPE N, " Destination Radix

P_S_NUM(5) TYPE C. " Source Number

***********************************************************************

*" Data declarations...................................................

"----


  • Work variables *

"----


DATA:

W_LEN TYPE I,

W_FACT TYPE I,

W_D_NUM(5) TYPE N,

W_T_LEN TYPE I,

W_NUM TYPE C,

W_NUM1 TYPE I,

W_REM TYPE I,

W_INDEX TYPE I VALUE 20,

W_T_NUM(30) TYPE C,

W_T_NUMBER(5) TYPE N.

IF P_S_RAD GE 1 AND

P_S_RAD LE 16 AND

P_D_RAD GE 1 AND

P_D_RAD LE 16.

IF P_S_RAD EQ 01 AND P_S_NUM CO '0 ' OR

P_S_RAD EQ 02 AND P_S_NUM CO '01 ' OR

P_S_RAD EQ 03 AND P_S_NUM CO '012 ' OR

P_S_RAD EQ 04 AND P_S_NUM CO '0123 ' OR

P_S_RAD EQ 05 AND P_S_NUM CO '01234 ' OR

P_S_RAD EQ 06 AND P_S_NUM CO '012345 ' OR

P_S_RAD EQ 07 AND P_S_NUM CO '0123456 ' OR

P_S_RAD EQ 08 AND P_S_NUM CO '01234567 ' OR

P_S_RAD EQ 09 AND P_S_NUM CO '012345678 ' OR

P_S_RAD EQ 10 AND P_S_NUM CO '0123456789 ' OR

P_S_RAD EQ 11 AND P_S_NUM CO '0123456789A ' OR

P_S_RAD EQ 12 AND P_S_NUM CO '0123456789AB ' OR

P_S_RAD EQ 13 AND P_S_NUM CO '0123456789ABC ' OR

P_S_RAD EQ 14 AND P_S_NUM CO '0123456789ABCD ' OR

P_S_RAD EQ 15 AND P_S_NUM CO '0123456789ABCDE ' OR

P_S_RAD EQ 16 AND P_S_NUM CO '00123456789ABCDEF ' .

W_LEN = STRLEN( P_S_NUM ).

W_T_LEN = W_LEN - 1.

DO W_LEN TIMES.

W_NUM = P_S_NUM+W_T_LEN(1).

CASE W_NUM.

WHEN 'A'.

W_NUM1 = 10.

WHEN 'B'.

W_NUM1 = 11.

WHEN 'C'.

W_NUM1 = 12.

WHEN 'D'.

W_NUM1 = 13.

WHEN 'E'.

W_NUM1 = 14.

WHEN 'F'.

W_NUM1 = 15.

WHEN OTHERS.

W_NUM1 = W_NUM.

ENDCASE.

W_D_NUM = W_D_NUM + W_NUM1 * ( P_S_RAD ** W_FACT ).

ADD 1 TO W_FACT.

SUBTRACT 1 FROM W_T_LEN.

ENDDO.

ELSE.

WRITE'Invalid Number'(003).

ENDIF.

ELSE.

WRITE'Enter radix between 1 and 16 '(002).

ENDIF.

W_T_NUMBER = W_D_NUM.

IF P_D_RAD = 1.

DO W_D_NUM TIMES.

WRITE'O'.

ENDDO.

ELSE.

WHILE W_T_NUMBER NE 0.

W_REM = W_T_NUMBER MOD P_D_RAD.

CASE W_REM.

WHEN 10.

W_T_NUM+W_INDEX(1) = 'A'.

WHEN 11.

W_T_NUM+W_INDEX(1) = 'B'.

WHEN 12.

W_T_NUM+W_INDEX(1) = 'C'.

WHEN 13.

W_T_NUM+W_INDEX(1) = 'D'.

WHEN 14.

W_T_NUM+W_INDEX(1) = 'E'.

WHEN 15.

W_T_NUM+W_INDEX(1) = 'F'.

WHEN OTHERS.

W_T_NUM+W_INDEX(1) = W_REM.

ENDCASE. " CASE W_REM.

SUBTRACT 1 FROM W_INDEX.

W_T_NUMBER = W_T_NUMBER DIV P_D_RAD.

ENDWHILE.

ENDIF.

WRITE:

/10 'The Equivallent number in Base'(001),

P_D_RAD,

'is',

W_T_NUM.

<b>Reward points if helpful .</b>

regards,

rama pammi