ABAP List Viewer(ALV) – 4

* ALV USING FM- REUSE_ALV_GRID_DISPLAY & FIELD CATALOG & LAYOUT *

type-pools : slis.

types : begin of ty_flight,

        CH TYPE C,

        carrid type sflight-carrid,

        connid type sflight-connid,

        fldate type sflight-fldate,

        price type sflight-price,

        seatsmax type sflight-seatsmax,

        seatsocc type sflight-seatsocc,

       end of ty_flight.


 data : it_flight type table of ty_flight,

            wa_flight type ty_flight.


data : it_fieldcat type slis_t_fieldcat_alv,

           wa_fieldcat type slis_fieldcat_alv.


DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV.

select-options : s_carrid for wa_flight-carrid.


start-of-selection.

 select * from sflight into corresponding fields of table it_flight where carrid in s_carrid.

 

*Building field catalog for the ALV *

wa_fieldcat-row_pos = 1.

 wa_fieldcat-col_pos = 1.

 wa_fieldcat-fieldname = ‘CH’.

 wa_fieldcat-TABNAME = ‘IT_FLIGHT’.

 wa_fieldcat-CHECKBOX = ‘X’.

 wa_fieldcat-SELTEXT_S = ‘CHECK’.


 APPEND WA_FIELDCAT TO IT_FIELDCAT.

 CLEAR WA_FIELDCAT.


 wa_fieldcat-row_pos = 1.

 wa_fieldcat-col_pos = 2.

 wa_fieldcat-fieldname = ‘CARRID’.

 wa_fieldcat-TABNAME = ‘IT_FLIGHT’.

 wa_fieldcat-REF_TABNAME = ‘SFLIGHT’.

 wa_fieldcat-KEY = ‘X’.

 wa_fieldcat-SELTEXT_S = ‘FLIGHT CODE’.

 APPEND WA_FIELDCAT TO IT_FIELDCAT.

 CLEAR WA_FIELDCAT.


  wa_fieldcat-row_pos = 1.

 wa_fieldcat-col_pos = 3.

 wa_fieldcat-fieldname = ‘CONNID’.

 wa_fieldcat-TABNAME = ‘IT_FLIGHT’.

 wa_fieldcat-REF_TABNAME = ‘SFLIGHT’.

 wa_fieldcat-KEY = ‘X’.

 APPEND WA_FIELDCAT TO IT_FIELDCAT.

 CLEAR WA_FIELDCAT.


  wa_fieldcat-row_pos = 1.

 wa_fieldcat-col_pos = 4.

 wa_fieldcat-fieldname = ‘FLDATE’.

 wa_fieldcat-TABNAME = ‘IT_FLIGHT’.

 wa_fieldcat-REF_TABNAME = ‘SFLIGHT’.

 wa_fieldcat-KEY = ‘X’.

 APPEND WA_FIELDCAT TO IT_FIELDCAT.

 CLEAR WA_FIELDCAT.


  wa_fieldcat-row_pos = 1.

 wa_fieldcat-col_pos = 5.

 wa_fieldcat-fieldname = ‘PRICE’.

 wa_fieldcat-TABNAME = ‘IT_FLIGHT’.

 wa_fieldcat-REF_TABNAME = ‘SFLIGHT’.

 wa_fieldcat-EMPHASIZE = ‘C515’.

 APPEND WA_FIELDCAT TO IT_FIELDCAT.

 CLEAR WA_FIELDCAT.


  wa_fieldcat-row_pos = 1.

 wa_fieldcat-col_pos = 6.

 wa_fieldcat-fieldname = ‘SEATSMAX’.

 wa_fieldcat-TABNAME = ‘IT_FLIGHT’.

 wa_fieldcat-REF_TABNAME = ‘SFLIGHT’.

 wa_fieldcat-EMPHASIZE = ‘C615’.

 APPEND WA_FIELDCAT TO IT_FIELDCAT.

 CLEAR WA_FIELDCAT.


  wa_fieldcat-row_pos = 1.

 wa_fieldcat-col_pos = 7.

 wa_fieldcat-fieldname = ‘SEATSOCC’.

 wa_fieldcat-TABNAME = ‘IT_FLIGHT’.

 wa_fieldcat-REF_TABNAME = ‘SFLIGHT’.

 wa_fieldcat-EMPHASIZE = ‘C300’.

* wa_fieldcat-no_out = ‘X’.

 APPEND WA_FIELDCAT TO IT_FIELDCAT.

 CLEAR WA_FIELDCAT.

 

* Building Layout for the ALV *

 WA_LAYOUT-NO_COLHEAD = ‘X’.

 WA_LAYOUT-NO_VLINE = ‘X’.

 WA_LAYOUT-NO_HLINE = ‘X’.

 WA_LAYOUT-EDIT = ‘X’.

 WA_LAYOUT-zebra = ‘X’.

 WA_LAYOUT-colwidth_optimize = ‘X’.


 call function 'REUSE_ALV_GRID_DISPLAY'

  EXPORTING

    I_CALLBACK_PROGRAM     = SY-CPROG

    I_GRID_TITLE           = ‘Flight Details’

    IS_LAYOUT    = WA_LAYOUT  ” pass the layout 

    IT_FIELDCAT  = IT_FIELDCAT ” pass fieldcatlog 

   tables

     t_outtab    = IT_FLIGHT.


 Output-




Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s