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: 

get SALV columns in wrong order

jan_dahl
Explorer
0 Kudos
308

Hi folks

I'm building a header line from my SALV table to use it in my CSV-File by this method.

  METHOD get_headerline_from_salv.
* build a header line
LOOP AT i_salv->get_columns( )->get( ) INTO DATA(ls_col).
r_result = |{ r_result }{ ls_col-r_column->get_long_text( ) }{ i_sep }|.
ENDLOOP.
ENDMETHOD.

Most of the time this works fine, especially when I debug and try to find the bug it is always perfectly fine. But if I don't watch, sometimes the colums are in a wrong order?!?

Any idea why? What can I do about it?

Cheers Jan

1 ACCEPTED SOLUTION

thkolz
Contributor
0 Kudos
253

It's really strange that this is not stable.
I would rather start from the table (VBAK in my example) and use the technical field names...

DATA: r_type_desr TYPE REF TO cl_abap_structdescr,
      s_vbak      TYPE vbak,
      v_string    TYPE string.

r_type_desr ?= cl_abap_typedescr=>describe_by_data( s_vbak ).

LOOP AT r_type_desr->components INTO DATA(s_components).
  IF v_string IS INITIAL.
    v_string = s_components-name.
  ELSE.
    v_string = |{ v_string }', '{ s_components-name }|.
  ENDIF.
ENDLOOP.

WRITE v_string.
2 REPLIES 2

thkolz
Contributor
0 Kudos
254

It's really strange that this is not stable.
I would rather start from the table (VBAK in my example) and use the technical field names...

DATA: r_type_desr TYPE REF TO cl_abap_structdescr,
      s_vbak      TYPE vbak,
      v_string    TYPE string.

r_type_desr ?= cl_abap_typedescr=>describe_by_data( s_vbak ).

LOOP AT r_type_desr->components INTO DATA(s_components).
  IF v_string IS INITIAL.
    v_string = s_components-name.
  ELSE.
    v_string = |{ v_string }', '{ s_components-name }|.
  ENDIF.
ENDLOOP.

WRITE v_string.

Sandra_Rossi
Active Contributor
0 Kudos
253

Weird. Check the SAP notes.

(but I would think that you are in a special case, but I can't say without any further description/steps to reproduce)