on 2024 Jul 20 4:58 AM
Hello
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.
TYPES: BEGIN OF TY_STR,
MATL_NO TYPE ZADT_CONV_COST-MATL_NO,
MATL_DESC TYPE ZADT_CONV_COST-MATL_DESC,
ACTIVITY_NO TYPE ZADT_CONV_COST-ACTIVITY_NO,
ACTIVITY_DESC TYPE ZADT_CONV_COST-ACTIVITY_DESC,
ASSY_QTY TYPE ZADT_CONV_COST-ASSY_QTY,
ACTIVITY_QTY TYPE ZADT_CONV_COST-ACTIVITY_QTY,
UNIT TYPE ZADT_CONV_COST-UNIT,
ACTIVITY_RATE TYPE ZADT_CONV_COST-ACTIVITY_RATE,
ACTIVITY_VALUE TYPE ZADT_CONV_COST-ACTIVITY_VALUE,
CONV_VALUE TYPE ZADT_CONV_COST-CONV_VALUE,
OTHER_CHARGES TYPE ZADT_CONV_COST-OTHER_CHARGES,
MISC_COST TYPE ZADT_CONV_COST-MISC_COST,
REMARKS TYPE ZADT_CONV_COST-REMARKS,
END OF TY_STR.
DATA: ITAB TYPE TABLE OF TY_STR,
WTAB LIKE LINE OF ITAB.
*------CL_SALV_TABLE DATA DECLARATION
DATA: GR_TABLE TYPE REF TO CL_SALV_TABLE,
GR_FUNCTIONS TYPE REF TO CL_SALV_FUNCTIONS,
GR_COLUMNS TYPE REF TO CL_SALV_COLUMNS_TABLE,
GR_COLUMN TYPE REF TO CL_SALV_COLUMN_TABLE,
GR_DISPLAY TYPE REF TO CL_SALV_DISPLAY_SETTINGS,
LR_GRID TYPE REF TO CL_SALV_FORM_LAYOUT_GRID,
LR_GRIDX TYPE REF TO CL_SALV_FORM_LAYOUT_GRID,
LR_LOGO TYPE REF TO CL_SALV_FORM_LAYOUT_LOGO,
LR_LABEL TYPE REF TO CL_SALV_FORM_LABEL,
LR_TEXT TYPE REF TO CL_SALV_FORM_TEXT,
LR_FOOTER TYPE REF TO CL_SALV_FORM_LAYOUT_GRID,
LS_COLOR TYPE LVC_S_COLO,
GR_AGG TYPE REF TO CL_SALV_AGGREGATIONS,
GR_SORTS TYPE REF TO CL_SALV_SORTS,
LO_EVENTS TYPE REF TO CL_SALV_EVENTS_TABLE.
DATA: VENDOR_CODE TYPE ZADT_CONV_COST-VENDOR_CD,
VENDOR_DESC TYPE ZADT_CONV_COST-VENDOR_NAME,
PLANT_CODE TYPE WERKS_D,
PLANT_NAME TYPE NAME1,
ASSY_PT_NO TYPE ZADT_CONV_COST-ASSY_PART_NO,
ASSY_PT_DESC TYPE ZADT_CONV_COST-ASSY_PART_DESC.
*------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.
CLASS CONTENT DEFINITION.
PUBLIC SECTION.
METHODS: CONSTRUCTOR, M_DATA, M_WRITE, BUILD_FC, DISP_ALV, END_OF_PAGE, SET_TOT,
HANDLER FOR EVENT ADDED_FUNCTION OF CL_SALV_EVENTS_TABLE IMPORTING E_SALV_FUNCTION.
ENDCLASS.
CLASS CONTENT IMPLEMENTATION.
METHOD CONSTRUCTOR.
TRY.
CL_SALV_TABLE=>FACTORY( IMPORTING R_SALV_TABLE = GR_TABLE CHANGING T_TABLE = ITAB ).
CATCH CX_SALV_MSG.
ENDTRY.
TRY.
CALL METHOD GR_TABLE->SET_SCREEN_STATUS
EXPORTING
REPORT = SY-REPID
PFSTATUS = 'PF_STATUS'.
ENDTRY.
CALL METHOD GR_TABLE->GET_EVENT
RECEIVING
VALUE = LO_EVENTS.
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.
CONCATENATE '%' IN_PLANT '%' INTO S_PLANT.
CONCATENATE '%' IN_ASSY '%' INTO S_ASSY.
CONCATENATE '%' IN_VEND '%' INTO S_VEND.
IN_VEND = |{ IN_VEND ALPHA = OUT }|.
IF IN_PLANT IS INITIAL AND IN_ASSY IS INITIAL AND IN_VEND IS INITIAL.
MESSAGE 'All input fields are MANDATORY fields' TYPE 'I' DISPLAY LIKE 'I'.
LEAVE LIST-PROCESSING.
EXIT.
ELSEIF IN_PLANT IS NOT INITIAL AND IN_ASSY IS NOT INITIAL AND IN_VEND IS NOT INITIAL.
SELECT SINGLE NAME1
FROM T001W
INTO @PLANT_NAME
WHERE WERKS LIKE @IN_PLANT.
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.
LOOP AT I_ZADT ASSIGNING FIELD-SYMBOL(<W_ZADT>).
PLANT_CODE = <W_ZADT>-PLANT.
ASSY_PT_NO = <W_ZADT>-ASSY_PART_NO.
WTAB-MATL_NO = <W_ZADT>-MATL_NO.
VENDOR_CODE = <W_ZADT>-VENDOR_CD.
WTAB-ACTIVITY_NO = <W_ZADT>-ACTIVITY_NO.
ASSY_PT_DESC = <W_ZADT>-ASSY_PART_DESC.
WTAB-MATL_DESC = <W_ZADT>-MATL_DESC.
VENDOR_DESC = <W_ZADT>-VENDOR_NAME.
WTAB-ACTIVITY_DESC = <W_ZADT>-ACTIVITY_DESC.
WTAB-ASSY_QTY = <W_ZADT>-ASSY_QTY.
WTAB-ACTIVITY_QTY = <W_ZADT>-ACTIVITY_QTY.
WTAB-UNIT = <W_ZADT>-UNIT.
WTAB-ACTIVITY_RATE = <W_ZADT>-ACTIVITY_RATE.
WTAB-ACTIVITY_VALUE = <W_ZADT>-ACTIVITY_VALUE.
WTAB-CONV_VALUE = <W_ZADT>-CONV_VALUE.
WTAB-OTHER_CHARGES = <W_ZADT>-OTHER_CHARGES.
WTAB-MISC_COST = <W_ZADT>-MISC_COST.
WTAB-REMARKS = <W_ZADT>-REMARKS.
APPEND WTAB TO ITAB.
ENDLOOP.
UNASSIGN <W_ZADT>.
ENDMETHOD.
METHOD M_WRITE.
ENDMETHOD.
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 = ''
).
LR_GRIDX = LR_GRID->CREATE_GRID( ROW = 3 COLUMN = 1 ).
LR_LABEL = LR_GRIDX->CREATE_LABEL( ROW = 3 COLUMN = 1 ).
DATA: LV_TEXT(30) TYPE C.
LV_TEXT = VENDOR_CODE.
DATA(LV_TEXT_PLANT) = |PLANT: { PLANT_CODE } / { PLANT_NAME }|.
LR_TEXT = LR_GRIDX->CREATE_TEXT( ROW = 3 COLUMN = 1
TEXT = LV_TEXT_PLANT TOOLTIP = LV_TEXT_PLANT
).
DATA(LV_TEXT_VENDOR) = |VENDOR: { LV_TEXT } / { VENDOR_DESC }|.
LR_TEXT = LR_GRIDX->CREATE_TEXT( ROW = 4 COLUMN = 1
TEXT = LV_TEXT_VENDOR TOOLTIP = LV_TEXT_VENDOR
).
DATA(LV_TEXT_PT_DESC) = |ASSY PART NO.: { ASSY_PT_NO } / { ASSY_PT_DESC }|.
LR_TEXT = LR_GRIDX->CREATE_TEXT( ROW = 5 COLUMN = 1
TEXT = LV_TEXT_PT_DESC
).
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( ).
SET HANDLER WORK_OBJ->HANDLER FOR LO_EVENTS.
CALL METHOD: WORK_OBJ->HANDLER( ).
Do SET HANDLER before displaying the ALV.
NB:
Your code is difficult to read -> Use Clean ABAP.
Don't call the handler explicitly (the concept of events is that it's the ALV framework which will call the handler by triggering the event).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
66 | |
10 | |
8 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.