ZTable Update From ALV
ZTable Update From ALV
*&---------------------------------------------------------------------*
*& Report YRA_ZTAB3
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT yra_ztab4. " Define the report name
TYPE-POOLS: slis, lvc. " Include type pools for ALV grid
DATA : e_grid TYPE REF TO cl_gui_alv_grid. " Define reference variable for ALV grid
START-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
FORM get_data.
" If lt_mara is not initial, select corresponding data from MAKT table into
lt_makt
IF lt_mara IS NOT INITIAL.
SELECT matnr spras maktx
FROM makt INTO TABLE lt_makt
FOR ALL ENTRIES IN lt_mara
WHERE matnr = lt_mara-matnr.
ENDIF.
*&---------------------------------------------------------------------*
*& Form display_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
FORM display_data.
DATA : cpos TYPE i VALUE 1.
cpos = cpos + 1.
ls_fieldcat-col_pos = cpos.
ls_fieldcat-tabname = 'LT_FINAL'.
ls_fieldcat-fieldname = 'ERSDA'.
ls_fieldcat-scrtext_l = 'Created On'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat.
cpos = cpos + 1.
ls_fieldcat-col_pos = cpos.
ls_fieldcat-tabname = 'LT_FINAL'.
ls_fieldcat-fieldname = 'LAEDA'.
ls_fieldcat-scrtext_l = 'Date of Last Change'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat.
cpos = cpos + 1.
ls_fieldcat-col_pos = cpos.
ls_fieldcat-tabname = 'LT_FINAL'.
ls_fieldcat-fieldname = 'PSTAT'.
ls_fieldcat-scrtext_l = 'Maintenance Status'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat.
cpos = cpos + 1.
ls_fieldcat-col_pos = cpos.
ls_fieldcat-tabname = 'LT_FINAL'.
ls_fieldcat-fieldname = 'MTART'.
ls_fieldcat-scrtext_l = 'Material Type'.
ls_layout-ctab_fname = 'FCOLOR'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat.
cpos = cpos + 1.
ls_fieldcat-col_pos = cpos.
ls_fieldcat-tabname = 'LT_FINAL'.
ls_fieldcat-fieldname = 'SPRAS'.
ls_fieldcat-scrtext_l = 'Language Key'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat.
cpos = cpos + 1.
ls_fieldcat-col_pos = cpos.
ls_fieldcat-tabname = 'LT_FINAL'.
ls_fieldcat-fieldname = 'MAKTX'.
ls_fieldcat-scrtext_l = 'Material Description'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat.
cpos = cpos + 1.
ls_fieldcat-col_pos = cpos.
ls_fieldcat-tabname = 'LT_FINAL'.
ls_fieldcat-fieldname = 'CUSTOM_FIELD'.
ls_fieldcat-scrtext_l = 'Remarks'.
ls_fieldcat-edit = 'X'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR ls_fieldcat.
WHEN 'MODIFY'.
" Get ALV grid object
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = e_grid.
IF sy-subrc = 0.
" Record exists, add to update table
APPEND ls_final1 TO lt_final_update.
ELSE.
" Record does not exist, add to insert table
APPEND ls_final1 TO lt_final_insert.
ENDIF.
ENDLOOP.
WHEN '&IC1'.
" Check if the field clicked is the hotspot field
IF rs_selfield-fieldname = 'MATNR'. " Change 'MATNR' to your specific field
name
" Call transaction MM03 with material number
SET PARAMETER ID 'MAT' FIELD rs_selfield-value.
CALL TRANSACTION 'MM03'.
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form set_specific_field_attributes
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
FORM set_specific_field_attributes.
DATA : ls_stylerow TYPE lvc_s_styl,
lt_styletab TYPE lvc_t_styl.
ls_final-field_style = lt_styletab.
MODIFY lt_final FROM ls_final TRANSPORTING field_style.
ENDIF.
ENDLOOP.
ENDFORM. " set_specific_field_attributes