*-----------------------------------------------------------------------
* Report using the ALV Grid function.
* All you have to do is create a screen named 0100 and define the
* content of pf-status 'STATUS-100' and titlebar '100'.
* When the grid with the data shows up, press the new button on the
* toolbar and then, make a double click on the grid.
*-----------------------------------------------------------------------
REPORT ztest NO STANDARD PAGE HEADING.
TABLES: sflight.
DATA: BEGIN OF mytable OCCURS 0.
INCLUDE STRUCTURE sflight.
DATA: icon_id TYPE icons-text,
line_color(4) TYPE c,
END OF mytable.
INCLUDE.
DATA:
aux_table LIKE mytable,
okcode LIKE sy-ucomm,
mygrid TYPE REF TO cl_gui_alv_grid,
mycontainer TYPE REF TO cl_gui_custom_container,
mylayout TYPE lvc_s_layo,
field_catal TYPE lvc_t_fcat,
fieldcat_aux TYPE lvc_s_fcat,
new_button TYPE stb_button,
new_button2 TYPE stb_button,
save_button TYPE stb_button,
index_rows TYPE lvc_t_row,
sel_row LIKE lvc_s_row,
line TYPE i.
* Class Definition
CLASS myevent_receiv_001 DEFINITION DEFERRED. "for Toolbar button
CLASS myevent_receiv_002 DEFINITION DEFERRED. "for double click
* Event Declaration
DATA: user_event_receiver TYPE REF TO myevent_receiv_001,
user_event_receiver_002 TYPE REF TO myevent_receiv_002.
INCLUDE ztest.
*-----------------------------------------------------------------------
* Read data from SFLIGHT
*-----------------------------------------------------------------------
START-OF-SELECTION.
SELECT * FROM sflight
INTO TABLE mytable
WHERE carrid IN ('LH', 'AZ', 'AA')
ORDER BY carrid connid.
* Add an Icon to the internal table
LOOP AT mytable.
CALL FUNCTION 'ICON_CREATE'
EXPORTING
name = 'ICON_GREEN_LIGHT'
info = 'Not ready'
IMPORTING
result = mytable-icon_id.
MODIFY mytable TRANSPORTING icon_id.
ENDLOOP.
CALL SCREEN 0100.
*-----------------------------------------------------------------------
* Module PAI INPUT
*-----------------------------------------------------------------------
MODULE user_command_0100.
CASE okcode.
WHEN 'CANC' OR 'BACK'.
CALL METHOD mygrid->free.
LEAVE PROGRAM.
WHEN OTHERS.
CALL METHOD cl_gui_cfw=>dispatch.
ENDCASE.
ENDMODULE.
*-----------------------------------------------------------------------
* Module PBO OUTPUT
*-----------------------------------------------------------------------
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS-100'.
SET TITLEBAR '100'.
PERFORM build_field_catal.
IF mygrid IS INITIAL.
PERFORM build_layout.
PERFORM set_color.
CREATE OBJECT mygrid
EXPORTING i_parent = mycontainer.
CALL METHOD mygrid->set_table_for_first_display
EXPORTING
is_layout = mylayout
CHANGING
it_outtab = mytable[]
it_fieldcatalog = field_catal[]
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc NE '0'.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
STOP.
ENDIF.
* Select a line on the grid:
* APPEND 4 TO index_rows.
* CALL METHOD mygrid->set_selected_rows
* EXPORTING
* it_index_rows = index_rows.
*Event receiver for handling alv toolbar events:
CREATE OBJECT user_event_receiver.
SET HANDLER user_event_receiver->handle_user_command FOR mygrid.
SET HANDLER user_event_receiver->handle_toolbar FOR mygrid.
CALL METHOD mygrid->set_toolbar_interactive.
ELSE.
CALL METHOD mygrid->refresh_table_display.
ENDIF.
* handle double click event:
IF user_event_receiver_002 IS INITIAL.
CREATE OBJECT user_event_receiver_002.
SET HANDLER user_event_receiver_002->handle_double_click FOR mygrid.
ENDIF.
ENDMODULE.
*-----------------------------------------------------------------------
* Build the field catalogue
*-----------------------------------------------------------------------
FORM build_field_catal.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
ct_fieldcat = field_catal.
LOOP AT field_catal INTO fieldcat_aux.
CASE fieldcat_aux-fieldname.
WHEN 'CARRID'.
fieldcat_aux-scrtext_l = 'Airline carrier'.
fieldcat_aux-fix_column = 'X'.
WHEN 'CONNID'.
fieldcat_aux-scrtext_l = 'Flight connection'.
fieldcat_aux-fix_column = 'X'.
WHEN 'FLDATE'.
fieldcat_aux-scrtext_l = 'Flight date'.
fieldcat_aux-fix_column = 'X'.
WHEN 'PRICE'.
fieldcat_aux-scrtext_l = 'Airfare'.
fieldcat_aux-do_sum = 'X'.
WHEN 'CURRENCY'.
fieldcat_aux-scrtext_l = 'Local currency'.
fieldcat_aux-outputlen = 10.
WHEN 'PLANETYPE'.
fieldcat_aux-scrtext_l = 'Plane type'.
fieldcat_aux-outputlen = 10.
WHEN 'SEATSMAX'.
fieldcat_aux-scrtext_l = 'Maximum capacity'.
fieldcat_aux-do_sum = 'X'.
fieldcat_aux-outputlen = 10.
WHEN 'SEATSOCC'.
fieldcat_aux-scrtext_l = 'Occupied seats'.
fieldcat_aux-do_sum = 'X'.
fieldcat_aux-outputlen = 10.
WHEN 'PAYMENTSUM'.
fieldcat_aux-scrtext_l = 'Total current bookings'.
fieldcat_aux-do_sum = 'X'.
fieldcat_aux-outputlen = 15.
ENDCASE.
MODIFY field_catal FROM fieldcat_aux.
ENDLOOP.
CLEAR fieldcat_aux.
fieldcat_aux-col_pos = 10.
fieldcat_aux-fieldname = 'ICON_ID'.
fieldcat_aux-tabname = 1.
fieldcat_aux-scrtext_l = 'Status'.
fieldcat_aux-outputlen = 5.
APPEND fieldcat_aux TO field_catal.
ENDFORM.
*-----------------------------------------------------------------------
* Build the grid´s layout
* SEL_MODE: determines how rows can be selected.
* A Multiple columns, multiple rows with selection buttons.
* B Simple selection, listbox, Single row/column
* C Multiple rows without buttons
* D Multiple rows with buttons and select all ICON
*-----------------------------------------------------------------------
FORM build_layout.
mylayout-grid_title = 'My Title here'.
mylayout-smalltitle = '3'.
* mylayout-no_hgridln = 'X'.
* mylayout-no_vgridln = 'X'.
* mylayout-no_headers = 'X'.
mylayout-cwidth_opt = 'X'.
* mylayout-no_rowmark = 'X'.
* mylayout-no_toolbar = 'X'.
mylayout-sel_mode = 'A'.
mylayout-edit = 'X'.
mylayout-totals_bef = 'X'.
* mylayout-no_totline = ' '.
* mylayout-keyhot = 'X'.
mylayout-info_fname = 'LINE_COLOR'.
ENDFORM.
*-----------------------------------------------------------------------
* Set color on certain lines:
* Char 1 = C --> This is a color property
* Char 2 --> Color code (1 - 7)
* Char 3 --> Intensified on/off (1 = on)
* Char 4 --> Inverse display (0 = off)
*-----------------------------------------------------------------------
FORM set_color.
LOOP AT mytable.
IF mytable-seatsocc < 60.
mytable-line_color = 'C610'.
MODIFY mytable.
ENDIF.
ENDLOOP.
ENDFORM.
02/08/2010
Report using the ALV Grid Function - 003
Assinar:
Postar comentários (Atom)
Nenhum comentário:
Postar um comentário