02/08/2010

Report using the ALV Grid function - 002


*-----------------------------------------------------------------------
* 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: 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.




*-----------------------------------------------------------------------
* 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'.
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.

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.


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.
fieldcat_aux-emphasize = 'C210'.

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.

Nenhum comentário:

Postar um comentário