You are on page 1of 7

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

*& Report ZCPRG9_00_SS1


*&
*&---------------------------------------------------------------------*
*&
*& Sorin Serbanescu
*&---------------------------------------------------------------------*
REPORT zcprg9_00_ss1.
*&---------------------------------------------------------------------*
*& TYPE-POOLS
*&---------------------------------------------------------------------*
TYPE-POOLS: slis. "delcaratii de tipuri pentru structuri si tabele interne
*
folosite in lucrul cu ALV
*&---------------------------------------------------------------------*
*& TYPES
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& DATA
*&---------------------------------------------------------------------*
*** Declaratii de date globale
DATA: gt_sflight TYPE sflight_tab1, "Flights Internal table
gs_spfli
TYPE spfli,
"Flight schedule
gs_scarr
TYPE scarr,
"Airline
gv_records TYPE i,
"Number of records
gv_sum
TYPE s_sum.
"Total of current bookings
*&---------------------------------------------------------------------*
*& CONSTANTS
*&---------------------------------------------------------------------*
DATA
gc_on
TYPE c LENGTH 1 VALUE 'X'.
DATA
gc_off
TYPE c LENGTH 1 VALUE space.
*&---------------------------------------------------------------------*
*& SELECTION SCREEN
*&---------------------------------------------------------------------*
*** Selection screen
PARAMETERS:
p_carrid
TYPE sflight-carrid DEFAULT 'LH' OBLIGATORY, "Airline code
p_connid
TYPE sflight-connid DEFAULT '401'.
"Connection Nu
mber
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM select_data.
PERFORM output_data.
*&---------------------------------------------------------------------*
*&
Form SELECT_DATA
*&---------------------------------------------------------------------*
*&
Select flights data using a Function Molule
*&---------------------------------------------------------------------*
FORM select_data.

* select flights data from SFLIGHT; get no. of selected flights and related
* SPFLI record; calculate total PaymentSum of selected flights
CALL FUNCTION 'ZCFM1_00_MB'
EXPORTING
iv_carrid
= p_carrid
iv_connid
= p_connid
IMPORTING
et_sflight
= gt_sflight
es_spfli
= gs_spfli
es_scarr
= gs_scarr
ev_records
= gv_records
ev_sum
= gv_sum
EXCEPTIONS
no_data
= 1
carrid_not_found = 2
connid_not_found = 3
negative_sum
= 4
OTHERS
= 5.
IF sy-subrc = 0.
SORT gt_sflight BY carrid connid fldate.
ELSE.
MESSAGE 'Error selecting flights data' TYPE 'E'.
ENDIF.
ENDFORM.

" SELECT_DATA

*&---------------------------------------------------------------------*
*&
Form OUTPUT_DATA
*&---------------------------------------------------------------------*
*&
Output selected data using an ALV GRID tool
*&---------------------------------------------------------------------*
FORM output_data.
*** Data Declaration for ALV GRID **************************************
**
*
*
*
*

List Layout Specifications for ALV GRID


Structure needed for describing the list to be output. Parameters are
described and grouped based on many categories: Exceptions, Totals,
Interaction, Color, Detail Screen, Other
DATA ls_layout
TYPE slis_layout_alv.

** ALV GRIG Title


DATA lv_title

TYPE lvc_title.

** Field Catalog with field descriptions for ALV GRID


*
* Field catalog containing the field descriptions of the fields to be consider
ed
* for the list output (usually, this is a subset of the fields in the internal
output table).
DATA lt_fcat
TYPE slis_t_fieldcat_alv.
** Sort Criteria for first
*
* Using an internal table
d/or
* the subtotalling of the
DATA lt_sort
TYPE

list display
(LT_SORT[]), the caller determines the sort order an
basic list.
slis_t_sortinfo_alv.

*** Configure ALV GRID layout by setting LS_LAYOUT structure ***********


PERFORM prepare_layout CHANGING ls_layout.
*** Prepare ALV GRID field catalog *************************************
PERFORM prepare_alv_fcat CHANGING lt_fcat.
*** Prepare ALV GRID sort criteria *************************************
PERFORM prepare_sort_criteria CHANGING lt_sort.
*** Set ALV GRID Title *************************************************
lv_title = 'Flights Data'(g01).
*** Create and display the ALV GRID
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program
= sy-repid
"Name of the calling program
i_callback_top_of_page = 'TOP_OF_PAGE_FORM' "EXIT routine for handling TOP
-OF-PAGE
i_grid_title
= lv_title
"Control title
is_layout
= ls_layout
"Layout specifications
it_fieldcat
= lt_fcat
"Field catalog with field desc
riptions
it_sort
= lt_sort
"Sort Criteria
TABLES
t_outtab
= gt_sflight
EXCEPTIONS
program_error
= 1
OTHERS
= 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM.

" OUTPUT_DATA

*&---------------------------------------------------------------------*
*&
Form PREPARE_LAYOUT
*&---------------------------------------------------------------------*
*
Prepare Layout specifications for ALV GRID
*----------------------------------------------------------------------*
FORM prepare_layout CHANGING cs_layout TYPE slis_layout_alv. .
** Display options
* Optimize the column width to ensure that the content is displayed completely
cs_layout-colwidth_optimize = gc_on.
* Striped pattern
cs_layout-zebra
= gc_on.
** Totals
* Calculating subtotals is allowed
cs_layout-no_subtotals
= gc_off.
** Other
* Input not allowed
cs_layout-no_input
= gc_on.
ENDFORM.

" PREPARE_LAYOUT

*&---------------------------------------------------------------------*
*&
Form PREPARE_ALV_FCAT
*&---------------------------------------------------------------------*
*
Prepare Field Catalog for ALV GRID
*----------------------------------------------------------------------*
FORM prepare_alv_fcat CHANGING ct_fcat TYPE slis_t_fieldcat_alv.
** Set output attributes for each Field/Column of the ALV GRID
*
* Structure used to assign output attributes to a field of internal table
* containting data to be displayed
DATA ls_fcat
TYPE slis_fieldcat_alv.
** Set output attributes for field SFLIGHT-CARRID
CLEAR ls_fcat.
* Identification component (FIELDNAME) in the output attributes structure
ls_fcat-fieldname
= 'CARRID'.
* Reference to the Data Dictionary - name of a structure or table in the Data
Dictionary
ls_fcat-ref_tabname = 'SFLIGHT'.
* Reference to the Data Dictionary - name of a field in the Data Dictionary
ls_fcat-ref_fieldname = 'CARRID'.
* Key (Key column)
ls_fcat-key
= gc_on.
* Store output attributes for current field in the Field Catalog Internal Tabl
e
APPEND ls_fcat TO ct_fcat.
** Set output attributes for field SFLIGHT-CONNID
CLEAR ls_fcat.
ls_fcat-fieldname
= 'CONNID'.
ls_fcat-ref_tabname = 'SFLIGHT'.
ls_fcat-ref_fieldname = 'CONNID'.
ls_fcat-key
= gc_on.
APPEND ls_fcat TO ct_fcat.
** Set output attributes for field SFLIGHT-FLDATE
CLEAR ls_fcat.
ls_fcat-fieldname
= 'FLDATE'.
ls_fcat-ref_tabname = 'SFLIGHT'.
ls_fcat-ref_fieldname = 'FLDATE'.
ls_fcat-key
= gc_on.
APPEND ls_fcat TO ct_fcat.
** Set output attributes for field SFLIGHT-PRICE
CLEAR ls_fcat.
ls_fcat-fieldname
= 'PRICE'.
ls_fcat-ref_tabname = 'SFLIGHT'.
ls_fcat-ref_fieldname = 'PRICE'.
* Reference to the Currency Unit: relevant to amount columns with unit reference
.
ls_fcat-cfieldname
= 'CURRENCY'.
* Parameters for texts
ls_fcat-seltext_s
= 'Tick.Price'(g01).
"(short field label)
ls_fcat-seltext_m
= 'Tick.Price'(g01).
"(medium field label)
ls_fcat-seltext_l
= 'Tick.Price'(g01).
"(long field label)

ls_fcat-reptext_ddic = 'Tick.Price'(g01).
APPEND ls_fcat TO ct_fcat.

"(heading)

** Set output attributes for field SFLIGHT-CURRENCY


CLEAR ls_fcat.
ls_fcat-fieldname
= 'CURRENCY'.
ls_fcat-ref_tabname = 'SFLIGHT'.
ls_fcat-ref_fieldname = 'CURRENCY'.
APPEND ls_fcat TO ct_fcat.
** Set output attributes for field SFLIGHT-PLANETYPE
CLEAR ls_fcat.
ls_fcat-fieldname
= 'PLANETYPE'.
ls_fcat-ref_tabname = 'SFLIGHT'.
ls_fcat-ref_fieldname = 'PLANETYPE'.
APPEND ls_fcat TO ct_fcat.
** Set output attributes for field SFLIGHT-SEATSOCC
CLEAR ls_fcat.
ls_fcat-fieldname
= 'SEATSOCC'.
ls_fcat-ref_tabname = 'SFLIGHT'.
ls_fcat-ref_fieldname = 'SEATSOCC'.
APPEND ls_fcat TO ct_fcat.
** Set output attributes for field SFLIGHT-PAYMENTSUM
CLEAR ls_fcat.
ls_fcat-fieldname
= 'PAYMENTSUM'.
ls_fcat-ref_tabname = 'SFLIGHT'.
ls_fcat-ref_fieldname = 'PAYMENTSUM'.
* Reference to the Currency Unit: relevant to amount columns with unit reference
.
ls_fcat-cfieldname
= 'CURRENCY'.
APPEND ls_fcat TO ct_fcat.
ENDFORM.

" PREPARE_ALV_FCAT

*&---------------------------------------------------------------------*
*&
Form PREPARE_SORT_CRITERIA
*&---------------------------------------------------------------------*
*
Set the sort order
*----------------------------------------------------------------------*
FORM prepare_sort_criteria CHANGING ct_sort TYPE slis_t_sortinfo_alv.
** Set sort attributes for specific fields of ALV GRID Field Catalog
*
*

Structure used to assign sort attributes to a field of internal table


containting data to be displayed
DATA ls_sort
TYPE slis_sortinfo_alv.

** Set sort attributes for field SFLIGHT-CARRID


CLEAR ls_sort.
* Identification component (FIELDNAME) in the output attributes structure
ls_sort-fieldname = 'CARRID'.
* Sort order
ls_sort-spos
= 1.
* 'X' = Sorted in ascending order
ls_sort-up
= gc_on.

APPEND ls_sort TO ct_sort.


CLEAR ls_sort.
ls_sort-fieldname
ls_sort-spos
ls_sort-up
APPEND ls_sort TO

= 'CONNID'.
= 2.
= gc_on.
ct_sort.

CLEAR ls_sort.
ls_sort-fieldname
ls_sort-spos
ls_sort-down
APPEND ls_sort TO

= 'SEATSOCC'.
= 3.
= gc_on.
ct_sort.

ENDFORM.

" PREPARE_SORT_CRITERIA

*&---------------------------------------------------------------------*
*&
Form TOP_OF_PAGE_FORM
*&---------------------------------------------------------------------*
*
EXIT routine for handling TOP-OF-PAGE
*----------------------------------------------------------------------*
FORM top_of_page_form.
"#EC CALLED
** Set data in Top Of Page of ALV GRID
*
*

Structure and internal table used to write data in the TOP-OF-PAGE


section (Header Information)
DATA lt_list TYPE slis_t_listheader.
DATA ls_line TYPE slis_listheader.
DATA lv_text TYPE c LENGTH 20.

** Write the total number of selected flights in the TOP-OF-PAGE section


* on the first line
CLEAR: ls_line, lv_text.
ls_line-typ = 'S'.
ls_line-key = 'Selected Records'(tp1).
MOVE gv_records TO lv_text.
SHIFT lv_text LEFT DELETING LEADING space.
MOVE lv_text TO ls_line-info.
APPEND ls_line TO lt_list.
** Write the Carrier ID in the TOP-OF-PAGE section line 2
CLEAR ls_line.
ls_line-typ = 'S'.
ls_line-key = 'Carrier'(tp2).
MOVE gs_spfli-carrid TO ls_line-info.
APPEND ls_line TO lt_list.
** Write the Connection ID in the TOP-OF-PAGE section line 3
CLEAR ls_line.
ls_line-typ = 'S'.
ls_line-key = 'Connection ID'(tp3).
MOVE gs_spfli-connid TO ls_line-info.
APPEND ls_line TO lt_list.
** Write the total Payment sum in the TOP-OF-PAGE section line 4
CLEAR: ls_line, lv_text.
ls_line-typ = 'S'.
ls_line-key = 'Total Sum'(tp4).

MOVE gv_sum TO lv_text.


SHIFT lv_text LEFT DELETING LEADING space.
MOVE lv_text TO ls_line-info.
APPEND ls_line TO lt_list.
** Module REUSE_ALV_COMMENTARY_WRITE si called within the EXIT routine.
** This module is responsible for formatting the header information and
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = lt_list[]
EXCEPTIONS
OTHERS
= 0.
ENDFORM.

" TOP_OF_PAGE_FORM

You might also like