Function Button in OO ALV
Function Button in OO ALV
Function Button in OO ALV
https://community.sap.com/t5/technology-q-a/function-button-in-oo-alv/qaq-p/13766578
There is a help i want in my report, this is the code for my report. Here i needed to create a
custom button and on click of that custom button i want to execute certain line of code to
update a Z database table. Here i've created a button in my report, but the problem is that
button is performing no action on the click of it. There is something i'm missing but i dont know
what. Requesting for a help and an expertise input.
Thankyou.
REPORT ZADR_WORK_CONTENT_REP_01.
TABLES: ZADT_CONV_COST.
*------SELECTION-SCREEN
SELECTION-SCREEN BEGIN OF BLOCK BK1 WITH FRAME TITLE TEXT-001.
PARAMETERS: IN_PLANT TYPE ZADT_CONV_COST-PLANT,
IN_ASSY TYPE ZADT_CONV_COST-ASSY_PART_NO,
IN_VEND TYPE ZADT_CONV_COST-VENDOR_CD.
SELECTION-SCREEN END OF BLOCK BK1.
TRY.
CALL METHOD GR_TABLE->SET_SCREEN_STATUS
EXPORTING
REPORT = SY-REPID
PFSTATUS = 'PF_STATUS'.
ENDTRY.
IF GR_TABLE IS INITIAL.
MESSAGE TEXT-002 TYPE 'I' DISPLAY LIKE 'I'.
EXIT.
ENDIF.
ENDMETHOD.
METHOD M_DATA.
DATA: S_PLANT TYPE WERKS_D,
S_ASSY TYPE Z_ASSY_PTNO,
S_VEND(12) TYPE C.
SELECT *
FROM ZADT_CONV_COST
INTO TABLE @DATA(I_ZADT)
WHERE PLANT = @IN_PLANT
AND ASSY_PART_NO = @IN_ASSY
AND VENDOR_CD LIKE @IN_VEND.
IF I_ZADT IS INITIAL.
MESSAGE 'NO data found, check input' TYPE 'I' DISPLAY LIKE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
METHOD BUILD_FC.
INCLUDE <COLOR>.
*-----TOOLBAR FUNCTION
TRY.
GR_FUNCTIONS = GR_TABLE->GET_FUNCTIONS( ).
GR_FUNCTIONS->SET_ALL( ABAP_TRUE ).
ENDTRY.
*-----COLUMN
TRY.
GR_COLUMNS = GR_TABLE->GET_COLUMNS( ).
GR_COLUMNS->SET_OPTIMIZE( ABAP_TRUE ).
ENDTRY.
TRY.
GR_COLUMN ?= GR_COLUMNS->GET_COLUMN('MATL_NO').
GR_COLUMN->SET_SHORT_TEXT('MATNR NO.').
GR_COLUMN->SET_MEDIUM_TEXT('MATERIAL NUMBER').
LS_COLOR-COL = 3.
GR_COLUMN->SET_COLOR( LS_COLOR ).
CATCH CX_SALV_NOT_FOUND.
ENDTRY.
TRY.
GR_COLUMN ?= GR_COLUMNS->GET_COLUMN('MATL_DESC').
GR_COLUMN->SET_SHORT_TEXT('MAT DESC.').
GR_COLUMN->SET_MEDIUM_TEXT('MATERIAL DESCRIPTION').
GR_COLUMN->SET_LONG_TEXT('MATERIAL DESCRIPTION').
CATCH CX_SALV_NOT_FOUND.
ENDTRY.
TRY.
GR_COLUMN ?= GR_COLUMNS->GET_COLUMN('ACTIVITY_NO').
GR_COLUMN->SET_LONG_TEXT('ACTIVITY NUMBER').
GR_COLUMN->SET_SHORT_TEXT('ACT NO.').
GR_COLUMN->SET_MEDIUM_TEXT('ACTIVITY NO.').
LS_COLOR-COL = 1.
GR_COLUMN->SET_COLOR( LS_COLOR ).
CATCH CX_SALV_NOT_FOUND.
ENDTRY.
TRY.
GR_COLUMN ?= GR_COLUMNS->GET_COLUMN('ACTIVITY_DESC').
GR_COLUMN->SET_MEDIUM_TEXT('ACTIVITY DESCRIPTION').
CATCH CX_SALV_NOT_FOUND.
ENDTRY.
TRY.
GR_COLUMN ?= GR_COLUMNS->GET_COLUMN('ASSY_QTY').
GR_COLUMN->SET_SHORT_TEXT('ASSY QTY').
GR_COLUMN->SET_MEDIUM_TEXT('ASSEMBLY QUANTITY').
CATCH CX_SALV_NOT_FOUND.
ENDTRY.
TRY.
GR_COLUMN ?= GR_COLUMNS->GET_COLUMN('ACTIVITY_QTY').
GR_COLUMN->SET_SHORT_TEXT('ACT. QTY').
GR_COLUMN->SET_MEDIUM_TEXT('ACTIVITY QTY').
GR_COLUMN->SET_LONG_TEXT('ACTIVITY QUANTITY').
CATCH CX_SALV_NOT_FOUND.
ENDTRY.
TRY.
GR_COLUMN ?= GR_COLUMNS->GET_COLUMN('UNIT').
GR_COLUMN->SET_SHORT_TEXT('UNIT').
CATCH CX_SALV_NOT_FOUND.
ENDTRY.
TRY.
GR_COLUMN ?= GR_COLUMNS->GET_COLUMN('ACTIVITY_RATE').
GR_COLUMN->SET_SHORT_TEXT('ACT. RT.').
GR_COLUMN->SET_MEDIUM_TEXT('ACTIVITY RT.').
GR_COLUMN->SET_LONG_TEXT('ACTIVITY RATE').
CATCH CX_SALV_NOT_FOUND.
ENDTRY.
TRY.
GR_COLUMN ?= GR_COLUMNS->GET_COLUMN('ACTIVITY_VALUE').
GR_COLUMN->SET_SHORT_TEXT('ACT. VAL.').
GR_COLUMN->SET_MEDIUM_TEXT('ACTIVITY VALUE').
GR_COLUMN->SET_LONG_TEXT('ACTIVITY VALUE').
CATCH CX_SALV_NOT_FOUND.
ENDTRY.
TRY.
GR_COLUMN ?= GR_COLUMNS->GET_COLUMN('CONV_VALUE').
GR_COLUMN->SET_SHORT_TEXT('CONV. VAL.').
GR_COLUMN->SET_MEDIUM_TEXT('CONVERSION VALUE').
GR_COLUMN->SET_LONG_TEXT('CONVERSION VALUE').
CATCH CX_SALV_NOT_FOUND.
ENDTRY.
TRY.
GR_COLUMN ?= GR_COLUMNS->GET_COLUMN('OTHER_CHARGES').
GR_COLUMN->SET_SHORT_TEXT('OTH. CHRG.').
GR_COLUMN->SET_MEDIUM_TEXT('OTHER CHARGES').
GR_COLUMN->SET_LONG_TEXT('OTHER CHARGES').
CATCH CX_SALV_NOT_FOUND.
ENDTRY.
TRY.
GR_COLUMN ?= GR_COLUMNS->GET_COLUMN('MISC_COST').
GR_COLUMN->SET_SHORT_TEXT('MISC COST').
GR_COLUMN->SET_MEDIUM_TEXT('MISCELLANEOUS COST').
GR_COLUMN->SET_LONG_TEXT('MISCELLANEOUS COST').
CATCH CX_SALV_NOT_FOUND.
ENDTRY.
TRY.
GR_COLUMN ?= GR_COLUMNS->GET_COLUMN('REMARKS').
GR_COLUMN->SET_SHORT_TEXT('REMARKS').
GR_COLUMN->SET_MEDIUM_TEXT('REMARKS').
GR_COLUMN->SET_LONG_TEXT('REMARKS').
CATCH CX_SALV_NOT_FOUND.
ENDTRY.
**------SORT
TRY.
GR_SORTS = GR_TABLE->GET_SORTS( ).
GR_SORTS->ADD_SORT( COLUMNNAME = 'MATL_NO' SUBTOTAL = ABAP_TRUE ).
GR_SORTS->ADD_SORT( COLUMNNAME = 'VENDOR_CD' ).
CATCH CX_SALV_DATA_ERROR.
CATCH CX_SALV_EXISTING.
CATCH CX_SALV_NOT_FOUND.
ENDTRY.
*------AGGREGATION
TRY.
GR_AGG = GR_TABLE->GET_AGGREGATIONS( ).
GR_AGG->ADD_AGGREGATION('ASSY_QTY').
GR_AGG->ADD_AGGREGATION('ACTIVITY_QTY').
GR_AGG->ADD_AGGREGATION('ACTIVITY_RATE').
GR_AGG->ADD_AGGREGATION('ACTIVITY_VALUE').
GR_AGG->ADD_AGGREGATION('CONV_VALUE').
GR_AGG->ADD_AGGREGATION('OTHER_CHARGES').
GR_AGG->ADD_AGGREGATION('MISC_COST').
CATCH CX_SALV_DATA_ERROR.
CATCH CX_SALV_NOT_FOUND.
CATCH CX_SALV_EXISTING.
ENDTRY.
ENDMETHOD.
METHOD DISP_ALV.
SET_TOT( ).
BUILD_FC( ).
END_OF_PAGE( ).
GR_FUNCTIONS = GR_TABLE->GET_FUNCTIONS( ).
GR_FUNCTIONS->SET_ALL( ABAP_TRUE ).
GR_TABLE->SET_TOP_OF_LIST( LR_LOGO ).
GR_TABLE->SET_END_OF_LIST( LR_FOOTER ).
GR_DISPLAY = GR_TABLE->GET_DISPLAY_SETTINGS( ).
GR_DISPLAY->SET_STRIPED_PATTERN( CL_SALV_DISPLAY_SETTINGS=>TRUE ).
GR_TABLE->DISPLAY( ).
ENDMETHOD.
METHOD SET_TOT.
CREATE OBJECT LR_GRID.
CREATE OBJECT LR_LOGO.
LR_LOGO->SET_LEFT_CONTENT( LR_GRID ).
DATA(LV_TEXT_DATE) = |{ SY-DATUM+6(2) }-{ SY-DATUM+4(2) }-{ SY-DATUM+0(4) }|.
DATA(INFO) = |WORK CONTENT REPORT OF { LV_TEXT_DATE }|.
LR_GRID->CREATE_HEADER_INFORMATION(
ROW = 1
COLUMN = 1
TEXT = INFO
TOOLTIP = 'WORK').
LR_GRID->CREATE_HEADER_INFORMATION(
ROW = 2
COLUMN = 1
TEXT = ''
).
ENDMETHOD.
METHOD END_OF_PAGE.
ENDMETHOD.
METHOD HANDLER.
* CASE SY-UCOMM.
* WHEN 'BACK'.
* MESSAGE 'Database Updated!' TYPE 'I' DISPLAY LIKE 'I'.
* WHEN 'INIT'.
* MESSAGE 'INITIALIZATION' TYPE 'I' DISPLAY LIKE 'I'.
* ENDCASE.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
SET PF-STATUS 'PF_STATUS'.
DATA(WORK_OBJ) = NEW CONTENT( ).
CALL METHOD: WORK_OBJ->M_DATA( ),
WORK_OBJ->DISP_ALV( ).