Register Login

Convert Negative Values into the String

Updated May 18, 2018

ABAP - Function Module To Convert Negative Values Into The String In Preceding Negation Display Format.

If there are some negative values present on the screen. If we try to download these values as it is, they are internally stored as ‘123.123-‘. But it is expected to display them as ‘-123.123’. So this FM helps to convert these negative values in the format

‘-123.123’. This functionality is not available in standard SAP function module

Import parameter: IW_VALUE type char30.

Export parameter: EW_CONV_VALUE type char30

*$*$**************************************************************$*$    GLOBAL CONSTANTS
*$*$    naming convention: "c_name"
*$*$*************************************************************

CONSTANTS : c_minus_one TYPE i VALUE '-1',
              c_minus(1)  type c value '-'.

*$*$*************************************************************
*$*$    Global Elementary Variables
*$*$    naming convention: "w_name"
*$*$*************************************************************

DATA: w_length TYPE i.

*” Remove all blank spaces
  
CONDENSE iw_value.

*” Take total length of the value
  
w_length = STRLEN( iw_value ).

*” Reduce length by one 
  
ADD c_minus_one TO w_length.

*" IF value is negative then convert value from 123- to -123 format

IF iw_value+w_length(1) EQ c_minus.

iw_value = iw_value(w_length).

CONCATENATE c_minus

iw_value

INTO ew_conv_value.

CONDENSE ew_conv_value.

ELSE.

MOVE iw_value TO ew_conv_value.

ENDIF.

Sample Output:


×