02/08/2010

Report using the ALV Grid Function - 004


*-----------------------------------------------------------------------
* 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'.
* A custom control named CONTAINER is also necessary.
*-----------------------------------------------------------------------
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,
record(5) type c,
mygrid TYPE REF TO cl_gui_alv_grid,
mycontainer TYPE scrfname VALUE 'CONTAINER',
custom_container TYPE REF TO cl_gui_custom_container,
field_catal TYPE lvc_t_fcat WITH HEADER LINE.


*-----------------------------------------------------------------------
* Read data from SFLIGHT
*-----------------------------------------------------------------------
START-OF-SELECTION.
SELECT * FROM sflight
UP TO 30 ROWS
INTO CORRESPONDING FIELDS OF TABLE mytable.


CALL SCREEN 0100.


*-----------------------------------------------------------------------
* Module PAI INPUT
*-----------------------------------------------------------------------
MODULE user_command_0100.

* to react on oi_custom_events:
CALL METHOD cl_gui_cfw=>dispatch.

CASE okcode.
WHEN 'CANC' OR 'BACK'.
SET SCREEN 0.
WHEN OTHERS.
* LEAVE PROGRAM.
ENDCASE.

ENDMODULE.


*-----------------------------------------------------------------------
* Module PBO OUTPUT
*-----------------------------------------------------------------------
MODULE status_0100 OUTPUT.

SET PF-STATUS 'STATUS-100'.
SET TITLEBAR '100'.

IF custom_container IS INITIAL.
PERFORM build_field_catal.
describe table mytable lines record.

CREATE OBJECT custom_container
EXPORTING
container_name = mycontainer.

CREATE OBJECT mygrid
EXPORTING
i_appl_events = 'X'
i_parent = custom_container.

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.

CALL METHOD mygrid->set_toolbar_interactive.

ELSE.
CALL METHOD mygrid->refresh_table_display.
ENDIF.

ENDMODULE.


*-----------------------------------------------------------------------
* Build the field catalogue
*-----------------------------------------------------------------------
FORM build_field_catal.

REFRESH field_catal.
CLEAR field_catal.

field_catal-fieldname = 'CARRID'.
field_catal-ref_field = 'CARRID'.
field_catal-scrtext_l = 'Airline carrier'.
field_catal-fix_column = 'X'.
APPEND field_catal.
CLEAR field_catal.

field_catal-fieldname = 'CONNID'.
field_catal-ref_field = 'CONNID'.
field_catal-scrtext_l = 'Flight connection'.
field_catal-fix_column = 'X'.
APPEND field_catal.
CLEAR field_catal.

field_catal-fieldname = 'FLDATE'.
field_catal-ref_field = 'FLDATE'.
field_catal-scrtext_l = 'Flight date'.
field_catal-fix_column = 'X'.
APPEND field_catal.
CLEAR field_catal.

field_catal-fieldname = 'PRICE'.
field_catal-ref_field = 'PRICE'.
field_catal-scrtext_l = 'Airfare'.
APPEND field_catal.
CLEAR field_catal.

field_catal-fieldname = 'CURRENCY'.
field_catal-ref_field = 'CURRENCY'.
field_catal-scrtext_l = 'Local currency'.
field_catal-outputlen = 10.
APPEND field_catal.
CLEAR field_catal.

field_catal-fieldname = 'PLANETYPE'.
field_catal-ref_field = 'PLANETYPE'.
field_catal-scrtext_l = 'Plane type'.
field_catal-outputlen = 10.
APPEND field_catal.
CLEAR field_catal.

field_catal-fieldname = 'SEATSMAX'.
field_catal-ref_field = 'SEATSMAX'.
field_catal-scrtext_l = 'Maximum capacity'.
field_catal-outputlen = 10.
APPEND field_catal.
CLEAR field_catal.

field_catal-fieldname = 'SEATSOCC'.
field_catal-ref_field = 'SEATSOCC'.
field_catal-scrtext_l = 'Occupied seats'.
field_catal-outputlen = 10.
APPEND field_catal.
CLEAR field_catal.

field_catal-fieldname = 'PAYMENTSUM'.
field_catal-ref_field = 'PAYMENTSUM'.
field_catal-scrtext_l = 'Total current bookings'.
field_catal-outputlen = 15.
APPEND field_catal.
CLEAR field_catal.

ENDFORM.

Nenhum comentário:

Postar um comentário