This program describes how to include Drop down, F4 help, hot spot, editable fields in ALV Grid.
- Create report ZALV_EXAMPLE.
- Create screen 100 and press layout button for screen painting.
- Create custom control and adjust according to your screen area.
- Create GUI status for screen 100 'STATUS_100'
- Create message class ZFLIGHT and enter 'Total price for Air line & of plane type & is & &' in message 001
- Then paste below code in the report and activate it.
REPORT ZALV_EXAMPLE MESSAGE-ID ZFLIGHT.
type-pools: SLIS.
DATA:
begin of IT_SFLIGHT,
carrid type sflight-carrid,
connid type sflight-connid,
FLDATE type sflight-FLDATE,
PRICE type sflight-PRICE,
CURRENCY type sflight-CURRENCY,
PLANETYPE type sflight-planetype,
comments TYPE char250,
end of IT_SFLIGHT.
DATA:
BEGIN OF PLNTYPEF4,
PLANETYPE TYPE CHAR10,
END OF PLNTYPEF4.
DATA :G_CONTAINER TYPE SCRFNAME VALUE 'GRID',
ALV_GRID TYPE REF TO CL_GUI_ALV_GRID,
G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
WA_SFLIGHT LIKE TABLE OF IT_SFLIGHT WITH HEADER LINE,
GT_FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE,
WA_PLNTYPEF4 LIKE STANDARD TABLE OF PLNTYPEF4 WITH HEADER LINE.
CALL SCREEN 100.
" create class to handle f4 and hotspot clic events.
CLASS LCL_EVENT_HANDLER DEFINITION.
PUBLIC SECTION.
METHODS ON_F4 FOR EVENT ONF4 OF CL_GUI_ALV_GRID
IMPORTING E_FIELDNAME
ES_ROW_NO
ER_EVENT_DATA
ET_BAD_CELLS
E_DISPLAY.
METHODS HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
IMPORTING ES_ROW_NO
E_ROW_ID
E_COLUMN_ID.
ENDCLASS.
CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
METHOD ON_F4.
PERFORM ON_F4_HELP USING E_FIELDNAME
ES_ROW_NO-ROW_ID
ER_EVENT_DATA
ET_BAD_CELLS
E_DISPLAY.
ER_EVENT_DATA->M_EVENT_HANDLED = 'X'.
ENDMETHOD.
METHOD HOTSPOT_CLICK.
PERFORM HOTSPOT_CLICK USING ES_ROW_NO
E_ROW_ID
E_COLUMN_ID.
ENDMETHOD.
ENDCLASS.
DATA :GO_HANDLE TYPE REF TO LCL_EVENT_HANDLER.
FORM ON_F4_HELP USING P_E_FIELDNAME ROW_ID P_ER_EVENT_DATA TYPE REF TO CL_ALV_EVENT_DATA P_ET_BAD_CELLS P_E_DISPLAY.
DATA :LINE TYPE CHAR10,
RETURN_TAB TYPE TABLE OF DDSHRETVAL WITH HEADER LINE.
REFRESH WA_PLNTYPEF4.
CLEAR WA_PLNTYPEF4.
SELECT DISTINCT PLANETYPE FROM SFLIGHT INTO LINE.
APPEND LINE TO WA_PLNTYPEF4.
ENDSELECT.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
RETFIELD = 'PLANETYPE'
VALUE_ORG = 'S'
DYNPPROG = SY-REPID
DYNPNR = SY-DYNNR
TABLES
VALUE_TAB = WA_PLNTYPEF4
RETURN_TAB = RETURN_TAB
EXCEPTIONS
PARAMETER_ERROR = 1
NO_VALUES_FOUND = 2
OTHERS = 3.
READ TABLE WA_SFLIGHT INDEX ROW_ID.
IF RETURN_TAB-FIELDVAL IS NOT INITIAL.
WA_SFLIGHT-PLANETYPE = RETURN_TAB-FIELDVAL.
ENDIF.
MODIFY WA_SFLIGHT INDEX ROW_ID.
CALL METHOD ALV_GRID->REFRESH_TABLE_DISPLAY.
ENDFORM.
FORM HOTSPOT_CLICK USING ES_ROW_NO
E_ROW_ID
E_COLUMN_ID.
READ TABLE WA_SFLIGHT INDEX E_ROW_ID.
MESSAGE S001 WITH WA_SFLIGHT-CONNID WA_SFLIGHT-PLANETYPE WA_SFLIGHT-PRICE WA_SFLIGHT-CURRENCY.
ENDFORM.
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'STATUS_100'.
SELECT * FROM SFLIGHT INTO CORRESPONDING FIELDS OF TABLE WA_SFLIGHT.
REFRESH GT_FIELDCAT.
PERFORM BUILD_FIELDCAT USING 1 'CARRID' 'WA_SFLIGHT' 'Airline Code'.
PERFORM BUILD_FIELDCAT USING 2 'CONNID' 'WA_SFLIGHT' 'Flight Conn No'.
PERFORM BUILD_FIELDCAT USING 3 'FLDATE' 'WA_SFLIGHT' 'Flight date'.
PERFORM BUILD_FIELDCAT USING 4 'PRICE' 'WA_SFLIGHT' 'Airfare'.
PERFORM BUILD_FIELDCAT USING 5 'CURRENCY' 'WA_SFLIGHT' 'Local currency'.
PERFORM BUILD_FIELDCAT USING 6 'PLANETYPE' 'WA_SFLIGHT' 'Aircraft Type'.
PERFORM BUILD_FIELDCAT USING 7 'COMMENTS' 'WA_SFLIGHT' 'Comments'.
IF G_CUSTOM_CONTAINER IS INITIAL.
CREATE OBJECT G_CUSTOM_CONTAINER
EXPORTING CONTAINER_NAME = G_CONTAINER.
CREATE OBJECT ALV_GRID
EXPORTING I_PARENT = G_CUSTOM_CONTAINER.
PERFORM DROPDOWN_TABLE CHANGING ALV_GRID.
CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING IT_OUTTAB = WA_SFLIGHT[]
IT_FIELDCATALOG = GT_FIELDCAT[].
CALL METHOD ALV_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.
CREATE OBJECT GO_HANDLE.
SET HANDLER :GO_HANDLE->ON_F4 FOR ALV_GRID,
GO_HANDLE->HOTSPOT_CLICK FOR ALV_GRID.
ELSE.
CALL METHOD ALV_GRID->REFRESH_TABLE_DISPLAY.
ENDIF.
ENDMODULE.
MODULE USER_COMMAND_0100 INPUT.
IF sy-ucomm = 'BACK' OR
sy-ucomm = 'EXIT' OR
sy-ucomm = 'CANCEL'.
LEAVE PROGRAM.
ENDIF.
ENDMODULE.
FORM BUILD_FIELDCAT USING POS FIELD TABLE TEXT.
CLEAR GT_FIELDCAT.
GT_FIELDCAT-COL_POS = POS.
GT_FIELDCAT-FIELDNAME = FIELD.
GT_FIELDCAT-TABNAME = TABLE.
GT_FIELDCAT-COL_OPT = 'X'.
GT_FIELDCAT-OUTPUTLEN = 50.
IF ( POS = 5 OR POS = 7 ).
GT_FIELDCAT-EDIT = 'X'.
ENDIF.
IF POS = 6.
GT_FIELDCAT-F4AVAILABL = 'X'.
ENDIF.
IF POS = 2.
GT_FIELDCAT-HOTSPOT = 'X'.
ENDIF.
GT_FIELDCAT-SELTEXT = TEXT.
GT_FIELDCAT-COLTEXT = TEXT.
APPEND GT_FIELDCAT.
ENDFORM.
FORM DROPDOWN_TABLE CHANGING ALV_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA :LT_DROPDOWN TYPE LVC_T_DROP WITH HEADER LINE.
DATA: GS_F4 type LVC_S_F4,
GT_F4 type LVC_T_f4.
LOOP AT GT_FIELDCAT.
IF GT_FIELDCAT-FIELDNAME = 'CURRENCY'.
GT_FIELDCAT-DRDN_HNDL = '1'.
GT_FIELDCAT-OUTPUTLEN = 20.
MODIFY GT_FIELDCAT.
ENDIF.
ENDLOOP.
CLEAR GT_F4.
GS_F4-FIELDNAME = 'PLANETYPE'.
GS_F4-REGISTER = 'X'.
GS_F4-GETBEFORE = 'X'.
GS_F4-CHNGEAFTER = 'X'.
APPEND GS_F4 to GT_F4.
CALL METHOD ALV_GRID->REGISTER_F4_FOR_FIELDS
EXPORTING
IT_F4 = GT_F4.
LT_DROPDOWN-HANDLE = '1'.
LT_DROPDOWN-VALUE = 'CAD'.
APPEND LT_DROPDOWN.
LT_DROPDOWN-HANDLE = '1'.
LT_DROPDOWN-VALUE = 'EUR'.
APPEND LT_DROPDOWN.
LT_DROPDOWN-HANDLE = '1'.
LT_DROPDOWN-VALUE = 'DEM'.
APPEND LT_DROPDOWN.
LT_DROPDOWN-HANDLE = '1'.
LT_DROPDOWN-VALUE = 'USD'.
APPEND LT_DROPDOWN.
LT_DROPDOWN-HANDLE = '1'.
LT_DROPDOWN-VALUE = 'LIT'.
APPEND LT_DROPDOWN.
CALL METHOD ALV_GRID->SET_DROP_DOWN_TABLE
EXPORTING
IT_DROP_DOWN = LT_DROPDOWN[].
ENDFORM.
===================================================================
The output will be look like below. In here you can find hot spot in column 2, drop down in column 5, f4 help column 6 and editable fields in column 7.
F4 help can get from clicking f4 help buttun from any of the field from 6th column.
Then popup will diaplay with possible values for that field.
Once you selected required field ALV grid will change accordingly.
And if click on any hotspot from 2nd column status message of the row will be displayed.
Then popup will diaplay with possible values for that field.
Once you selected required field ALV grid will change accordingly.
And if click on any hotspot from 2nd column status message of the row will be displayed.
The information which you have provided is very good. It is very useful who is looking for SAP BPC ONLINE TRAINING
ReplyDeleteHi your a active yet
ReplyDelete