SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow

Move Minus Sign from Right to Left of Negative Number in SAP Smartform


In ABAP when displaying or printing negative numeric value the minus sign is on the right of the value instead of left of the number. So ABAP developers or Smartform developers are required to format negative numbers and move minus sign from right to left of the number before printing it.

This ABAP tutorial includes a following methods :
number format option for SAP Smartform to shift the negative sign from right to the left of the number
ABAP codes to move minus sign from right to the left of the negative number
ABAP function module CLOI_PUT_SIGN_IN_FRONT to set negative sign to the left side of the number value

move minus from right side to left of negative value

As best practice to print negative values with minus sign leading the value instead of trailing is to format negative numeric values according to your requirements. And the solution is as simple as using the (<C) formatting option in the Text control where you print the numeric value.

move minus sign to left from right





Here is ABAP code block which can help you convert a numeric value into string, condense string value to remove leading spaces and then move minus sign to left from right of negative number value.
Please note that the following ABAP code reads numeric value into a local variable. Then checks if it is a negative number or not. If it has a negative numeric value then multiplies with -1 in order to take the absolute value of the numeric data. After making the number positive, the ABAP code saves it into a character variable which is used to display numeric value on Text object on SAP Smartform document. We've now get rid of the minus sign of the number value. Using SHIFT ... LEFT DELETE LEADING ' ' statement the leading space characters are cleared. If the original number value is negative, as last step of the ABAP script, the minus sign "-" is added in front of the character value by using CONCATENATE command.

This is how ABAP developers can move minus sign from right of the negative number to left side by using ABAP code and display value on a Text object on SAP Smartform document.

*DATA GV_CONDVALUE_TXT TYPE CHAR20. " in Global Data definition
DATA lv_kwert TYPE kwert.

lv_kwert = gs_it_kond-kwert.

IF gs_it_kond-kwert < 0.
 lv_kwert = -1 * lv_kwert .
ENDIF.
WRITE lv_kwert TO gv_condvalue_txt.
SHIFT gv_condvalue_txt LEFT DELETING LEADING ' '.
IF gs_it_kond-kwert < 0.
 CONCATENATE '-' gv_condvalue_txt INTO gv_condvalue_txt.
ENDIF.
Code

leading minus sign

You can create a form method in order to simplify this ABAP code block for using every numeric value you print on your SAP Smartforms output documents.

Using ABAP function module CLOI_PUT_SIGN_IN_FRONT is an other option to bring the minus sign to front of the negative number value.
In order to use the CLOI_PUT_SIGN_IN_FRONT function module, ABAP developers should store the numeric value in a character like CLIKE data type. Here is an example where you can use the codes in your ABAP programs.

DATA gv_negativenumericvalue TYPE kwert VALUE -100.
DATA gv_negativenumericvalue_txt TYPE char40.

WRITE gv_negativenumericvalue TO gv_negativenumericvalue_txt.
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
 CHANGING
  value = gv_negativenumericvalue_txt.
WRITE :/ 'negative number : ', gv_negativenumericvalue.
WRITE :/ 'FM format number: ', gv_negativenumericvalue_txt.
Code

The output of the above ABAP sample report is as seen in below screenshot

ABAP function module cloi_put_sign_in_front



SAP HANA and ABAP

Install SAP Free
CRM Companies List
Web Based CRM Software


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.