Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Decimals in ALV field

former_member329522
Participant
0 Kudos

Hi all!! How're u today?

I've an alv with a weight column, like this:

2,324

2,456

5,323

3

0

0

2,343

And I need to show the decimals in the integer numbers... How can i do that??

Thank you so much!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,,,,,

Yes I got it.......

I think you have declared it as quan in your internal table.....

please declare it as

data: quan type p decimals 3.

thanks

Saurabh

13 REPLIES 13

Former Member
0 Kudos

Hi,,,,

In your Internal Table where you are declaring the weight field....

Declare it as-


data: weight type p decimals 4.

Then in output it will appear as a 2.345.

Thanks

Saurabh

0 Kudos

I've declare it like QUAN with 3 decimals... But it doesn't works

Former Member
0 Kudos

Hi

What do you mean?

U need to split the integer and decimals part into two different colunm or u need to show the weight as integer number?

In the first case u need to two colunm as integer number:

DATA WEIGHT TYPE P DECIMALS 4.

DATA: INT TYPE I,
      DEC TYPE I.

INT = TRUNC( WEIGHT ).
DEC = FRAC( WEIGHT ).

In the second case u need to move the weight to new field

DATA: INT TYPE I.

MOVE WEIGHT TO INT.

Max

0 Kudos

Hi Max... no no,

I've a column with some weights like this...

2.365

4.258

4.215

5.705

5

1

0

0.258

And I need to show 3 decimals in 0 numbers and in integer numbers:

Something like this:

0.000

5.000

4.568

4.123

7.000

Former Member

Former Member
0 Kudos

Hi,,,,,

Where you have difined the field catalog, in that there is an option.

for ex..


fieldcat-decimals_out = 3.

Thanks

Saurabh

0 Kudos

I try with that:

WHEN 'M3'.

  • wa_fieldcat-edit = 'X'.

wa_fieldcat-seltext_l = 'M3'.

wa_fieldcat-seltext_m = 'M3'.

wa_fieldcat-seltext_s = 'M3'.

wa_fieldcat-decimals_out = '3'.

MODIFY gt_fieldcat FROM wa_fieldcat INDEX sy-tabix.

But it doesn't work neither...

0 Kudos

Hi Julio ,

Try this code (Gross Weight with decimal places). Can you paste your code here.

TYPES : BEGIN OF TY_MARA,
        MATNR TYPE MARA-MATNR,
        BRGEW TYPE MARA-BRGEW, "Gross Weight
        END OF TY_MARA.

DATA : IT_MARA       TYPE TABLE OF TY_MARA,
       WA_MARA       TYPE TY_MARA,
       IT_MARA_COLL  TYPE TABLE OF TY_MARA.

DATA : GR_TABLE TYPE REF TO CL_SALV_TABLE.

SELECT MATNR
       BRGEW
FROM MARA
INTO TABLE IT_MARA UP TO 500 ROWS.

*TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY
*  EXPORTING
*    LIST_DISPLAY   = IF_SALV_C_BOOL_SAP=>FALSE
*    R_CONTAINER    =
*    CONTAINER_NAME =
  IMPORTING
    R_SALV_TABLE   = GR_TABLE
  CHANGING
    T_TABLE        = IT_MARA
    .
* CATCH CX_SALV_MSG .
*ENDTRY.
.

CALL METHOD GR_TABLE->DISPLAY
  .

Regards

Former Member
0 Kudos

Hi....

In your internal Table have you defined your quantity field as decimal,,,, I mean only decimal not quan or type p.....

if this is not working........

let me know your req clearly..........

I think you have a quantity and it's output is coming as

2,345

and you want,,,,,

2.345

Thanks

Saurabh

0 Kudos

No,

I've right fields with 3.256 for example. But when the field has an integer (example 5.000 kg) it only shows 5, without decimals.

I need to show the decimals.... 5.000 and 0.000 and 3.454

Did you understand?

Former Member
0 Kudos

Hi,,,,,

Yes I got it.......

I think you have declared it as quan in your internal table.....

please declare it as

data: quan type p decimals 3.

thanks

Saurabh

0 Kudos

Thanks! Problem fixed!

0 Kudos

Hi

this sample works fine:

DATA: BEGIN OF T_OUTPUT OCCURS 0,
        MATNR  LIKE MARA-MATNR,
        WEIGHT TYPE P DECIMALS 3,
        UNIT   LIKE MARA-MEINS,
      END   OF T_OUTPUT.


DATA: LT_REPORT TYPE SY-REPID,
      LT_INCLUDE TYPE SY-REPID.

DATA: GT_FIELDCAT TYPE  SLIS_T_FIELDCAT_ALV WITH HEADER LINE.

START-OF-SELECTION.

* Load file
  T_OUTPUT-MATNR = 'A'.
  T_OUTPUT-WEIGHT = '3.123'.
  T_OUTPUT-UNIT   = 'KG'.
  APPEND T_OUTPUT.

  T_OUTPUT-MATNR = 'A'.
  T_OUTPUT-WEIGHT = 4.
  T_OUTPUT-UNIT   = 'KG'.
  APPEND T_OUTPUT.

  T_OUTPUT-MATNR = 'A'.
  T_OUTPUT-WEIGHT = 0.
  T_OUTPUT-UNIT   = 'KG'.
  APPEND T_OUTPUT.

  T_OUTPUT-MATNR = 'A'.
  T_OUTPUT-WEIGHT = '15.123'.
  T_OUTPUT-UNIT   = 'KG'.
  APPEND T_OUTPUT.

* Load catalog table

  LT_REPORT = LT_INCLUDE = SY-REPID.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
       EXPORTING
            I_PROGRAM_NAME         = LT_REPORT
            I_INTERNAL_TABNAME     = 'T_OUTPUT'
            I_INCLNAME             = LT_INCLUDE
       CHANGING
            CT_FIELDCAT            = GT_FIELDCAT[]
       EXCEPTIONS
            INCONSISTENT_INTERFACE = 1
            PROGRAM_ERROR          = 2
            OTHERS                 = 3.

  LOOP AT GT_FIELDCAT WHERE FIELDNAME = 'WEIGHT'.
    GT_FIELDCAT-SELTEXT_L = 'KG'.
    GT_FIELDCAT-SELTEXT_M = 'KG'.
    GT_FIELDCAT-SELTEXT_S = 'KG'.

*    GT_FIELDCAT-QFIELDNAME = 'UNIT'.
*    GT_FIELDCAT-QTABNAME   = 'T_OUTPUT'.
*
*    GT_FIELDCAT-edit_mask = '
    MODIFY GT_FIELDCAT.
  ENDLOOP.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            IT_FIELDCAT = GT_FIELDCAT[]
       TABLES
            T_OUTTAB    = T_OUTPUT.

U don't need to indicate the unit fields as control field for the quantity field.

Max