Skip to Content

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.

defaults screen.png

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 SYUNAME.

ENDIF.

CASE SS_USR01DCPFM.

   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_USR01DCPFM <> ‘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> NOGAPS.

* Check the number is valid

FIND REGEX L_MATCH IN <L_INPUT>.

*  endif.

IF SYSUBRC 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> NOGAPS.

OUTPUT = <L_INPUT>.

*To get the User profile format after all calculations.

DATA :Quantity  TYPE  STPOMENGE.

           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

To report this post you need to login first.

13 Comments

You must be Logged on to comment or reply to a post.

  1. Arseni Gallardo

    Hi,

    I suggest you to try function modules RS_CONV_EX_2_IN_NO_DD and/or RS_CONV_EX_2_IN. They are documented and do the same job.

    Kind regards

    (0) 
  2. Manish Kumar

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

    What are those situations?

    So, i have made a change as below:

    Can you add a set of input/outputs that demonstrate what the program does?

    It is unlikely for a person reading blog while traveling to have access to SAP Server.

    (0) 
    1. Siva kumar Devana Post author

      Hi Manish,

      The above situations means, when the user setting is SPACE, or ‘X’ or ‘Y’ situations.(i mean dcpfm field from usr01 table.

      it goes to dump and for that i have changed as per the code mentioned on the blog.

      Regards,

      siva kumar.

      (0) 
        1. Siva kumar Devana Post author

          Hi Manish,

          Our values are as follows:1.234.567,89 , 1,234,567.89, 1 234 567,89, 2.5, 2,5, 2 5 like that.

          changing the dcpfm to space once, and dcpfm to x and dcpfm to y.(different situations).

          Regards,

          siva kumar.

          (0) 
          1. Manish Kumar

            From what I understand, you wrote the code to avoid the occasional dump and to get correct decimal notation. As pointed by Shai Sinai, WRITE..TO statement can be used to get correct decimal notation as per user profile.

            Your code has a commented line RAISE EXCEPTION TYPE CX_SY_CONVERSION_NO_NUMBER, which probably means you were trying to handle the dump in case of non-numeric input.

            Try running below snippet. Input 1234567.89 and 1 234567.89 will give same output whereas input a1234567.89 will give error message instead of dump.

            DATA quan TYPE stpo-menge VALUE ‘1234567.89’.

            DATA output TYPE char20.

            PARAMETERS input TYPE char17 DEFAULT ‘1 234567.89’.

            CONDENSE input NO-GAPS.

            TRY .

                quan = input.

              CATCH cx_sy_conversion_no_number.

                MESSAGE ‘Invalid’ TYPE ‘E’.

            ENDTRY.

            WRITE:/ input,

                  / quan DECIMALS 2,

                    quan DECIMALS 2 TO output LEFT-JUSTIFIED.

            WRITE:/ output.

            Let me know if there is any scenario that is not covered by above code.

            My point is that most of the REGEX and TRANSLATE part is not required.

            /.

            (0) 
            1. Siva kumar Devana Post author

              Hi Manish,

              Exactly, my Team leader stressed about the Dump part(which should not come”).So, i made the change like that and issue was closed.

              Regards,

              Siva kumar.

              (0) 
  3. Suhas Saha

    If your ABAP release supports string formatting options, then i would say – “Much ado about nothing“.

    What was your approach when you had this requirement? Did you check if there were any standard ABAP commands which would do the job for you? Or did you open the ABAP editor (or Eclipse) and start coding?

    I would have deleted the content, but thought otherwise because there were some sane comments.

    (0) 
  4. Siva rama Krishna Pabbraju

    Hi,

           It may not be right place to discuss or mention but somehow I wanted to bring this point. Program ‘DEMO_WRITE_CUTOFFS’ ,illustrated about behavior of write statement pertaining to user settings specific to Country .

    Regards,

    Siva

    (0) 
  5. Matthew Billingham

    Your program has a hardcoded break point. The code itself is badly formatted and hard to read. You should point out the use of Regex and how it works in this context. You should remove entirely any obsolete code.

    (0) 

Leave a Reply