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

ABAP - type conversion

Former Member
0 Likes
531

Hi Experts,

I have a curr variable with '-ve' sign. I want it to store it in a variable without the '-ve' sign.

Any suggestions?

3 REPLIES 3
Read only

naimesh_patel
Active Contributor
0 Likes
489

Hello,

if amount < 0

amount = amount * -1.

endif.

Regards,

Naimesh

Read only

Former Member
0 Likes
489

See the code..

Cheers,

Thomas.

FUNCTION Z_CONVERT_NEGATIVE_SIGN.
*"----------------------------------------------------------------------
*"*"Local interface:
*"       IMPORTING
*"             VALUE(DMBTR) LIKE  VBAK-NETWR
*"             VALUE(WAERS) LIKE  BSID-WAERS DEFAULT 'NTD'
*"       EXPORTING
*"             VALUE(ZMBTR) TYPE  CHAR16
*"----------------------------------------------------------------------

IF DMBTR > 0.
    WRITE DMBTR TO ZMBTR  RIGHT-JUSTIFIED CURRENCY WAERS.
ELSE.
    DMBTR = ABS( DMBTR ).
    WRITE DMBTR TO ZMBTR RIGHT-JUSTIFIED  CURRENCY WAERS.
    CONDENSE ZMBTR NO-GAPS.
    WRITE ZMBTR TO ZMBTR RIGHT-JUSTIFIED.
ENDIF.
ENDFUNCTION.

Read only

Former Member
0 Likes
489

u can do it in this way:

first find the length of that field value ,let it be <len.

now do

fld = fld + 2( len-1 ).