Application Development and Automation 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: 

Thousand separator required in Contents of ALV

former_member515644
Participant
0 Kudos
1,306

I require Thousand separator to be displayed in fields displayed of ALV like Current Stock qty, SO Qty, etc. The data type of the fields is string. I need to display them like 92,061.00.

Kindly suggest.

7 REPLIES 7

faisalatsap
Active Contributor
881

Hi lakpajnee,

Please test below sample code.

(Remember you have to change Data type from String to Char)

TYPES:  BEGIN OF ty1_alv,
        char_decimal  TYPE char35,
        END OF ty1_alv.
DATA: it1_alv   TYPE STANDARD TABLE OF ty1_alv,
      wa1_alv   TYPE ty1_alv,
      quantity  TYPE fkimg.
FIELD-SYMBOLS: <wa1_alv> TYPE ty1_alv.

START-OF-SELECTION.

  wa1_alv-char_decimal = '12345.238'.   APPEND wa1_alv TO it1_alv.
  wa1_alv-char_decimal = '234566'.      APPEND wa1_alv TO it1_alv.
  wa1_alv-char_decimal = '2324553.20'.  APPEND wa1_alv TO it1_alv.

  LOOP AT it1_alv ASSIGNING <wa1_alv>.
    quantity = <wa1_alv>-char_decimal.
    WRITE: quantity TO <wa1_alv>-char_decimal.
  ENDLOOP.

  PERFORM show_alv TABLES it1_alv USING 'ALV: Quantity to Character with Thousand separator'.

*&---------------------------------------------------------------------*
*&      Form  show_alv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->IT         text
*      -->HEADING    text
*----------------------------------------------------------------------*
FORM show_alv TABLES it USING heading.


  DATA: ref_table             TYPE REF TO cl_salv_table,
        ref_form_layout_grid  TYPE REF TO cl_salv_form_layout_grid,
        ref_functions         TYPE REF TO cl_salv_functions,
        ref_columns           TYPE REF TO cl_salv_columns_table.

  TRY.
      cl_salv_table=>factory(
        IMPORTING
          r_salv_table = ref_table
        CHANGING
            t_table = it[] ).

      ref_functions = ref_table->get_functions( ).
      ref_functions->set_all( abap_true ).
      ref_columns = ref_table->get_columns( ).

      ref_columns->set_optimize( 'X' ).

      CREATE OBJECT ref_form_layout_grid.

*        Set Header Text
      ref_form_layout_grid->create_header_information( row = 1 column = 1 text = heading ).

*        Set the top of list
      ref_table->set_top_of_list( ref_form_layout_grid ).

      ref_table->display( ).

    CATCH cx_salv_not_found.
      MESSAGE 'Error: CX_SALV_NOT_FOUND' TYPE 'I'.
    CATCH cx_salv_msg.
      MESSAGE 'Error: CX_SALV_MSG' TYPE 'I'.

  ENDTRY.

ENDFORM.                    "show_alv

Thanks and Best Regards,

Faisal

0 Kudos
881

And then Lakashey will loose all the alv standard functionalities related to numbers.

Plus he doesn't need it at all..

0 Kudos
881

Sorry, i didn't read it was a string type in the question.

My bad.

0 Kudos
881

Nevertheless, I would add a TRY/CATCH/ENDTRY when mapping string to decimal work field (just in case, kind of cx_sy_conversion_error)

raymond_giuseppi
Active Contributor
0 Kudos
881

What did you already try before posting: converting back text to numeric variable and then write it back to text type variable, or using some string functions of Abap?

DoanManhQuynh
Active Contributor
0 Kudos
881

I guess your original data should be quantity type and for some reason you move it to string and display but there is no thousand seperator. if that were the case, you should WRITE your original data with addition UNIT instead of move directly.

Abinathsiva
Active Contributor
0 Kudos
881

Hi,

Since it's quantity better you can use any quantity reference field like menge, fkimg etc., or if you need it only in string then assign it to char field.

or string can be converted into decimals using FM WSAF_CONV_STRING_TO_DECIMAL or MOVE_CHAR_TO_NUM..