*-----------------------------------------------------------------------
* 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 END OF mytable.
DATA:
okcode LIKE sy-ucomm,
mygrid TYPE REF TO cl_gui_alv_grid,
mycontainer TYPE REF TO cl_gui_custom_container,
field_catal TYPE lvc_t_fcat,
fieldcat_aux TYPE lvc_s_fcat.
DATA: aux_sort LIKE TABLE OF lvc_s_sort WITH HEADER LINE,
sort_tab TYPE lvc_t_sort.
*-----------------------------------------------------------------------
* Read data from SFLIGHT
*-----------------------------------------------------------------------
START-OF-SELECTION.
SELECT * FROM sflight
INTO TABLE mytable
WHERE carrid IN ('LH', 'AZ', 'AA')
ORDER BY carrid connid.
CALL SCREEN 0100.
*-----------------------------------------------------------------------
* Module PAI INPUT
*-----------------------------------------------------------------------
MODULE user_command_0100.
CASE okcode.
WHEN 'CANC' OR 'BACK'.
LEAVE PROGRAM.
WHEN OTHERS.
* do nothing
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.
CREATE OBJECT mygrid
EXPORTING i_parent = mycontainer.
CALL METHOD mygrid->set_table_for_first_display
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.
aux_sort-spos = 1.
aux_sort-fieldname = 'CARRID'.
aux_sort-up = 'X'.
aux_sort-subtot = 'X'.
APPEND aux_sort TO sort_tab.
CALL METHOD mygrid->set_sort_criteria
EXPORTING
it_sort = sort_tab.
CALL METHOD mygrid->set_toolbar_interactive.
CALL METHOD mygrid->refresh_table_display.
ELSE.
CALL METHOD mygrid->refresh_table_display.
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-ref_field = '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.
ENDFORM.
02/08/2010
Report using the ALV Grid function - 001
Assinar:
Postar comentários (Atom)
Nenhum comentário:
Postar um comentário