Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member183289
Participant
10,946

Hello SCN members,

Good Evening.

Today i want to explain a simple and very important point particularly about the reports sent to persons like President or Vice-President in a Company.

I have been asked to change a report based on the user settings. For your understanding i am giving the screen shot as below:

SAP Menu ---> System --->User Profile ----> Own Data, click on the Defaults Tab.

The above Decimal Notation has 3 types of number formats i.e Space, X and Y.

SPACE" 1.234.567,89

          'X'. " 1,234,567.89

        'Y'. " 1 234 567,89

Different Countries use different Decimal Notations based on their habitat or convenience.


Regarding that i have searched so much and people have used below function module for currency and even quantity fields.

HRCM_STRING_TO_AMOUNT_CONVERT.

But the above function module did not work for all the situations.


So, i have made a change as below:


REPORT  ZTEST_QTY_CONV.

DATA : SS_USR01 TYPE USR01.

DATA: LP_DATA     TYPE REF TO DATA,

         L_THOUSANDS TYPE C LENGTH 1,

         L_DECIMAL   TYPE C LENGTH 1,

         L_TRANSLATE TYPE C LENGTH 2.

DATA: LT_RESULTS TYPE MATCH_RESULT_TAB,

       LS_RESULT  TYPE MATCH_RESULT,

       L_MATCH    TYPE STRING VALUE `^\s*-?\s*(?:\d{1,3}(?:(T?)\d{3})?(?:\1\d{3})*(D\d*)?|D\d+)\s*$`.

DATA: L_INT TYPE STRING,

       L_DEC TYPE STRING,

       INPUT TYPE STRING,

       OUTPUT TYPE STRING.

PARAMETERS : P_QTY TYPE CHAR17.

BREAK-POINT.

FIELD-SYMBOLS: <L_INPUT> TYPE ANY.

CREATE DATA LP_DATA LIKE INPUT.

ASSIGN LP_DATA->* TO <L_INPUT>.

<L_INPUT> = P_QTY.

* Get separator from user record

IF SS_USR01 IS INITIAL.

   SELECT SINGLE * FROM USR01 INTO SS_USR01 WHERE BNAME EQ SY-UNAME.

ENDIF.

CASE SS_USR01-DCPFM.

   WHEN SPACE" 1.234.567,89

     L_THOUSANDS = '.'.

     L_DECIMAL   = ','.

   WHEN 'X'.    " 1,234,567.89

     L_THOUSANDS = ','.

     L_DECIMAL   = '.'.

   WHEN 'Y'.    " 1 234 567,89

     L_THOUSANDS = SPACE.

     L_DECIMAL   = ','.

ENDCASE.

IF SS_USR01-DCPFM <> 'Y'.

* Modify regex to handle the user's selected notation

   REPLACE ALL OCCURRENCES OF 'T' IN L_MATCH WITH L_THOUSANDS.

   else.

     REPLACE ALL OCCURRENCES OF 'T' IN L_MATCH WITH ' '.    " (This statement is not happened)

*so, i did as below,

CLEAR : L_MATCH.

*L_MATCH   = `^\s*-?\s*(?:\d{1,3}(?:(T?)\d{3})?(?:\1\d{3})*(D\d*)?|D\d+)\s*$`.  " Removed the T with space.

L_MATCH   = `^\s*-?\s*(?:\d{1,3}(?:( ?)\d{3})?(?:\1\d{3})*(D\d*)?|D\d+)\s*$`.

ENDIF.

IF L_DECIMAL EQ '.'.

   REPLACE ALL OCCURRENCES OF 'D' IN L_MATCH WITH '\.'.

ELSE.

   REPLACE ALL OCCURRENCES OF 'D' IN L_MATCH WITH L_DECIMAL.

ENDIF.

*  if SS_USR01-DCPFM <> 'Y'.

CONDENSE <L_INPUT> NO-GAPS.

* Check the number is valid

FIND REGEX L_MATCH IN <L_INPUT>.

*  endif.

IF SY-SUBRC IS NOT INITIAL.

   MESSAGE 'Invalid' TYPE 'E'.

*    RAISE EXCEPTION TYPE CX_SY_CONVERSION_NO_NUMBER.

ENDIF.

* Translate thousand separator into "space"

CONCATENATE L_THOUSANDS SPACE INTO L_TRANSLATE.

TRANSLATE <L_INPUT> USING L_TRANSLATE.

* Translate decimal into .

CONCATENATE L_DECIMAL '.' INTO L_TRANSLATE.

TRANSLATE <L_INPUT> USING L_TRANSLATE.

* Remove spaces

CONDENSE <L_INPUT> NO-GAPS.

OUTPUT = <L_INPUT>.

*To get the User profile format after all calculations.

DATA :Quantity  TYPE  STPO-MENGE.

           quantity = output.

write: output, / 'Do calculations and print the values in User Profile Settings:', quantity.


Note: Whenever you have changed the user profile and want to see the result of the values like QUAN (usually 13 digits and 3 decimals), you need log out and log in once. Then only user settings will be applied.


Regards,

Siva kumar. D

13 Comments
Labels in this area