Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata
Error rendering macro 'code': Invalid value specified for parameter 'lang'
*&---------------------------------------------------------------------*
*& Report  Z_DEMO_JG
*&
*&---------------------------------------------------------------------*
*& Classical report with sort option
*&---------------------------------------------------------------------*

REPORT  z_demo_jg LINE-SIZE 80 LINE-COUNT 50
                                     NO STANDARD PAGE HEADING.
TABLES: sflight.

* Type declaration
TYPES : BEGIN OF ty_flight,
         carrid(19) TYPE c,
         connid(18) TYPE c,
         fldate LIKE sflight-fldate,
         fldate1(14) TYPE c,
         planetype(13) TYPE c,
        END OF ty_flight.

* Data declaration
DATA: i_flight TYPE STANDARD TABLE OF ty_flight,
      w_flight TYPE ty_flight.
DATA: field(50) TYPE c.
DATA: part1(30) TYPE c,
      part2(30) TYPE c.

* Selection screen
SELECT-OPTIONS: s_carrid FOR sflight-carrid.


START-OF-SELECTION.

* Fetch data from sflight table
  SELECT carrid
         connid
         fldate
         planetype
   FROM sflight
  INTO CORRESPONDING FIELDS OF TABLE i_flight
  WHERE carrid IN s_carrid.

  CHECK sy-subrc = 0.

* Display report header
  PERFORM display_column_name.

* Display final data
  PERFORM display_data.


AT USER-COMMAND.


  CLEAR: field,part1,part2.

* Get the cursor position
  GET CURSOR FIELD field.

  CHECK sy-subrc = 0 AND field IS NOT INITIAL.

* Findout the field name
  SPLIT field AT '-' INTO part1  part2.
  CHECK part2 IS NOT INITIAL.
  CASE sy-ucomm.
    WHEN 'ASC'.

*     Sort ascending
      SORT i_flight BY (part2)  ASCENDING.
    WHEN 'DSC'.

*     Sort descending
      SORT i_flight BY (part2) DESCENDING.
  ENDCASE.

* Set the list as basic list
  CLEAR sy-lsind.

* Display report header
  PERFORM display_column_name.

* Display final data
  PERFORM display_data.

*&---------------------------------------------------------------------*
*&      Form  display_column_name
*&---------------------------------------------------------------------*
*       Display column header
*----------------------------------------------------------------------*
*       None
*----------------------------------------------------------------------*
FORM display_column_name .

* Set gui stats for the list
  SET PF-STATUS 'BASIC'.

* Store report header texts
  w_flight-carrid = 'Airline Code'(001).
  w_flight-connid = 'Flight Connection'(002).
  w_flight-fldate1 = 'Flight date'(003).
  w_flight-planetype = 'Aircraft Type'(004).

* Display report header
  SKIP.
  ULINE.
  FORMAT INTENSIFIED ON COLOR 1.
  WRITE: 1 sy-vline,
         2 w_flight-carrid,
         21 sy-vline,
         22 w_flight-connid,
         40 sy-vline,
         41 w_flight-fldate1,
         55 sy-vline,
         56 w_flight-planetype,
         80 sy-vline.

  ULINE.
ENDFORM.                    " display_column_name

*&---------------------------------------------------------------------*
*&      Form  display_data
*&---------------------------------------------------------------------*
*       Display flight data
*----------------------------------------------------------------------*
*       None
*----------------------------------------------------------------------*
FORM display_data .

  CLEAR w_flight.

* Display report final data
  LOOP AT i_flight INTO w_flight.
    w_flight-fldate1 = w_flight-fldate.
    FORMAT INTENSIFIED ON COLOR 2.
    WRITE: 1 sy-vline,
           2 w_flight-carrid,
           21 sy-vline,
           22 w_flight-connid,
           40 sy-vline,
           41 w_flight-fldate1,
           55 sy-vline,
           56 w_flight-planetype,
           80 sy-vline.

    ULINE.

  ENDLOOP.
ENDFORM.                    " display_data

Note: Create pf-status BASIC with 2 buttons in application tool bar for ascending and descending sort and attach fcode 'ASC' with ascending sort button and fcode  'DSC' with descending sort button.