Ramzi
Ramzi

Reputation: 162

How to deal with unconverted value in itab from database SAP ABAP?

I'm a little bit confused about getting converted data in ABAP because I'm still new to the ABAP world.

I have a table with data as shown here:

enter image description here

As you can see in the screenshot, there are two columns for Value Unconverted and Value (which is converted).

When I do a SELECT query, I always get the unconverted value, and what I need is the converted value, because there's a big difference between (6.070) and (6,070).

I did some research but still nothing helps.

Here's is my code:

    SELECT tknum
       tplst
       erdat
       vsart
       exti1
       exti2
FROM vttk
INTO CORRESPONDING FIELDS OF TABLE gt_vttk
FOR ALL ENTRIES IN lt_vttp
WHERE tplst EQ p_tplst
AND   tknum EQ lt_vttp-tknum
AND   erdat IN s_erdat.

IF gt_vttk IS NOT INITIAL. // if return of above query is not empty

 // below is the query for fetching value that I'm talking about
   SELECT vsart
       volum
   FROM YMSNVT003
   INTO CORRESPONDING FIELDS OF TABLE it_mtiga
   FOR ALL ENTRIES IN gt_vttk
   WHERE vsart EQ gt_vttk-vsart.
ENDIF.

and u can see the return of it in debug mode : enter image description here

So what I'm confused about is:

  1. Is there any way to get converted value immediately with Select query in ABAP? If no, then how to deal with unconverted value to make it converted ? (from 6.070 to be 6,070)
  2. After getting converted value is done, I want to do conversion from M3 to CCM, can someone tell me how to convert from M3 (Cubic Meter) into CCM (Cubit Centimeter)?

Please let me know if my question is not clear so I can edit it and make it clear for you so I can get helps from you guys :)

Upvotes: 0

Views: 1682

Answers (4)

Simon Perez
Simon Perez

Reputation: 111

As @Kisbandi said, you see the unconverted value when you are in Debug mode.
enter image description here

The value format in the blue circle is displayed based on the user's settings. According to the image, this user's decimal places configuration is a comma separator. You can confirm this in transaction SU01 in the Defaults tab.
User Settings

Values will be displayed based on this configuration, you can change this accordingly.

Upvotes: 2

Philipp
Philipp

Reputation: 69663

AFAIK you can't do the format conversion on the database layer. But you can use string templates in order to format a decimal number as a text string in the preferred number format of the user:

DATA(number_type_string_var) = |{ number_type_p_var NUMBER = USER }|.

The format option NUMBER = USER will use the preferred number format in the settings of the current user. There is also NUMBER = ENVIRONMENT in combination with SET COUNTRY which can be used to force the number format of a specific locale independent from the user settings. This can be important if the resulting value needs to be formatted in a specific way for a technical purpose and not just for presentation to the end-user.

Upvotes: 1

Kisbandi
Kisbandi

Reputation: 313

  1. When displayed, will the value remain in this form 6.070? The language in which you use SAP has a lot to do with it, because it will translate it into the format of the user's login language. So when the value is displayed, it uses the "comma" character that is appropriate for you.

Does the format that debug uses affect the logic? I think debug always displays the uncoverted value and then the converted value is displayed to the user.

I checked how to change the format for currency and found these function modules: BAPI_CURRENCY_CONV_TO_EXTERNAL, BAPI_CURRENCY_CONV_TO_INTERNAL. You can change the display format, but the debug shows dot for both. The conversion can be done for other units, but the problem will be the same.

  1. You can use the function module CONVERSION_FACTOR_GET. There are 2 parameters where you can set the unit of measurement. You can find all all unit of measurement in the table T006.

Upvotes: 1

phili
phili

Reputation: 21

For the first part with the converted value: I dont think you can select the converted value, but you can convert it manually by replacing , with . and . with , .

For unit conversion you can use Fuba UNIT_CONVERSION_SIMPLE

Upvotes: 1

Related Questions