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: 
Read only

Sort the classical report

Former Member
0 Likes
576

Hi,

I have a classical report. Now on the report screen I want to sort the report by clicking on column headings.

How can we sort the classical report?

Regards,

RH

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
502

catch the click, recognize on what the user clicked and then sort your Internal table by the field.

Then process again your write statements.

3 REPLIES 3
Read only

Former Member
0 Likes
503

catch the click, recognize on what the user clicked and then sort your Internal table by the field.

Then process again your write statements.

Read only

0 Likes
502

Thanks for reply but how to do that?

Read only

0 Likes
502

This example will help you for logic, here the fields are taken manually.

You can do it dynamically also, there are some methods available for that.


REPORT abc NO STANDARD PAGE HEADING.

TYPE-POOLS:abap.

DATA:it TYPE TABLE OF marc.
DATA:wa TYPE marc.
TYPES:BEGIN OF ty,
      field1 TYPE abap_compname ,
      field2 TYPE abap_compname ,
      END OF ty.
DATA: wa_field TYPE ty.
DATA:lv_value TYPE char25,
     lv_field TYPE char25.

AT LINE-SELECTION.
  GET CURSOR FIELD lv_field VALUE lv_value.
  SORT it BY (lv_value) ASCENDING.
  sy-lsind = 0.
  PERFORM write_data.

START-OF-SELECTION.
  SELECT * FROM marc INTO TABLE it UP TO 100 ROWS.
  wa_field-field1 = 'MATNR'.
  wa_field-field2 = 'WERKS'.
  PERFORM write_data.

FORM write_data .
  WRITE AT 1 wa_field-field1 HOTSPOT ON.
  WRITE AT 19 sy-vline.
  WRITE AT 20 wa_field-field2 HOTSPOT ON.
  WRITE AT 25 sy-vline.
  HIDE wa_field.

  WRITE /  sy-uline.
  LOOP AT it INTO wa.
    WRITE:/1 wa-matnr,
          19 sy-vline,
          20 wa-werks,
          25 sy-vline.
  ENDLOOP.
ENDFORM.                    " WRITE_DATA