简体   繁体   中英

Order of ALV columns (with CL_SALV_TABLE)

I have a program which displays a simple table based on the class CL_SALV_TABLE , and I'd like to position the column CURRCODE at the fifth position, instead of 4 currently (default order defined in database table SCARR ), as shown here:

带有要移动的列的简单 ALV 输出

How can I do that?

Here is the current source code (compiles with ABAP version 7.40) :

  SELECT * FROM scarr INTO TABLE @DATA(scarr_s).

  cl_salv_table=>factory(
    IMPORTING
      r_salv_table = DATA(salv)
    CHANGING
      t_table      = scarr_s ).

  salv->display( ).

NB: if you want to reproduce and the table SCARR is empty, execute the program SAPBC_DATA_GENERATOR to fill it.

You have to do it in two steps, before the call of the method display :

  • Call the method GET_COLUMNS of the ALV instance (of class CL_SALV_TABLE ), to get the instance of the class CL_SALV_COLUMNS_TABLE corresponding to all columns.

  • The latter class has a method SET_COLUMN_POSITION to change the position of a given column whose name is passed as an argument.

Here is the source code:

  SELECT * FROM scarr INTO TABLE @DATA(scarr_s).

  cl_salv_table=>factory(
    IMPORTING
      r_salv_table = DATA(salv)
    CHANGING
      t_table      = scarr_s ).

  salv->get_columns( )->set_column_position( columnname = 'CURRCODE' position = 5 ). " <== ADD THIS LINE

  salv->get_columns( )->set_optimize( ).
  salv->display( ).

Result:

列按预期移动的简单 ALV 输出

NB: I also use the method SET_OPTIMIZE so that the width of all columns is automatically adjusted to their contents (but it's not related to the question).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM