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

Sort :

 If u want to display ALV list with the sort order u require and the order of the fields in ur manner ,u can make use of sort structure lvc_s_sort.

Here u can mention the order of the fields,ascending order or descending order.

 Filter :

If u want to display ur ALV list with only some fields or only particular set of records,use filter structure lvc_s_filt.

Here u need to mention sign,option,low value ,high value in the structure as like select-options.

Mention sign as 'I' for including the set,'E' for excluding the set.

Mention option as 'EQ' for single value selection,'BT' for multiple selection.

Report zprogram.
TABLES :

spfli.

TYPES :

BEGIN OF type_s_fs,

carrid TYPE spfli-carrid,

connid TYPE spfli-connid,

cityfrom TYPE spfli-cityfrom,

cityto TYPE spfli-cityto,

END OF type_s_fs.

DATA fs TYPE type_s_fs.

DATA : r_container TYPE REF TO cl_gui_custom_container,

r_alv_grid TYPE REF TO cl_gui_alv_grid.

DATA itab LIKE STANDARD TABLE OF fs.

DATA :

t_cat TYPE lvc_t_fcat,

w_cat TYPE lvc_s_fcat,

w_lay TYPE lvc_s_layo,

w_sort TYPE lvc_s_sort,

t_sort TYPE lvc_t_sort,

w_fil TYPE lvc_s_filt,

t_fil TYPE lvc_t_filt.

START-OF-SELECTION.

SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE itab.

CALL SCREEN 2000.

*&---------------------------------------------------------------------*

*& Module STATUS_2000 OUTPUT

*----------------------------------------------------------------------*

MODULE status_2000 OUTPUT.

SET PF-STATUS 'ALV'.

SET TITLEBAR 'Program to display spfli details'.

ENDMODULE. " STATUS_2000 OUTPUT

*----------------------------------------------------------------------*

* MODULE alv_output OUTPUT

*----------------------------------------------------------------------*

MODULE alv_output OUTPUT.

w_cat-fieldname = 'CARRID'.

w_cat-coltext = 'CARRID'.

w_cat-col_pos = 1.

w_cat-emphasize = 'C700'.

APPEND w_cat TO t_cat.

CLEAR w_cat.

w_cat-fieldname = 'CONNID'.

w_cat-coltext = 'Connection id'.

w_cat-col_pos = 2.

w_cat-lzero = 'X'.

w_cat-just = 'C'.

APPEND w_cat TO t_cat.

CLEAR w_cat.

w_cat-fieldname = 'CITYFROM'.

w_cat-coltext = 'DEPARTURE CITY'.

w_cat-col_pos = 3.

APPEND w_cat TO t_cat.

CLEAR w_cat.

w_cat-fieldname = 'CITYTO'.

w_cat-coltext = 'ARRIVAL CITY'.

w_cat-col_pos = 4.

APPEND w_cat TO t_cat.

CLEAR w_cat.

w_lay-grid_title = 'Flight details'.

w_lay-zebra = 'X'.

w_lay-edit = 'X'.

w_lay-CWIDTH_OPT = 'X'.

w_sort-spos = '1'.    " ---->( Which field u want to sort first )

w_sort-fieldname = 'CITYFROM'.

w_sort-down = 'X'.   " ---> ( For descending order )

APPEND w_sort TO t_sort.

CLEAR w_sort.

w_sort-spos = '2'.

w_sort-fieldname = 'CARRID'.

w_sort-down = 'X'.

APPEND w_sort TO t_sort.

CLEAR w_sort.

w_fil-fieldname = 'CARRID'.  " ---->( Field name )

w_fil-sign = 'E'. " -->( Give sign E for excluding the set, I for including the set )

w_fil-option = 'BT'.  "----> ( Give 'EQ' for only single value , 'BT' for ranges )

w_fil-low = 'JL'. " ----> ( Mention value u want to exclude or include )

w_fil-high = 'LH'. "----> ( Mention value u want to exclude or include )

APPEND w_fil TO t_fil.

CLEAR w_fil.

w_fil-fieldname = 'CITYFROM'.

 w_fil-sign = 'E'.

w_fil-option = 'EQ'.

 w_fil-low = 'NEW YORK'.

APPEND w_fil TO t_fil.

CLEAR w_fil.

CREATE OBJECT r_container

EXPORTING

container_name = 'CCCONTAINER'.

IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CREATE OBJECT r_alv_grid

EXPORTING

i_parent = r_container.

IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL METHOD r_alv_grid->set_table_for_first_display

EXPORTING

i_structure_name = 'FS' " -------->( Pass structure name )

is_layout = w_lay " ----> (Pass layout structure )

CHANGING

it_outtab = itab "----> (Pass internal table  which holds data )

it_fieldcatalog = t_cat  "----->( Pass field catalogue)

it_sort = t_sort " -----> ( Pass Sort internal table)

it_filter = t_fil "----> ( Pass filter internal table ).

IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.
ENDMODULE. "alv_output OUTPUT

*&---------------------------------------------------------------------*

*& Module USER_COMMAND_2000 INPUT

*----------------------------------------------------------------------*

MODULE user_command_2000 INPUT.

CASE sy-ucomm.

WHEN 'BACK' OR 'EXIT' OR 'RETURN'.

SET SCREEN '0'.

ENDCASE.

ENDMODULE. " USER_COMMAND_2000 INPUT