Online Tutorials & Training Materials | STechies.com
Register Login

Save Button Not Working in ALV Grid

|| || 3

Save Button Not Working in ALV Grid
Stechies

*matnr ersda should be as i/p.
*after executing it should show fields from mara table as grid_display.
*there ernam field should be editable n have a custom save button in standard
* toolbar to save the changed ernam field to mara table(updating ernam).
*i can edit the field ernam but while saving the internal table is not refreshing
* and the edited value is not update in the mara table.HOW to do this?
*if after editing i m double clicking the cell n den saving it is updating.
*But i supposed to do bu simply editing the cell and click the save button.
*Help me.
*Thanks in advance.
My program:
REPORT ZDEMO10.
TYPE-POOLS :slis.
TABLES : mara,makt.
TYPES:BEGIN OF ty_mara,
matnr TYPE matnr,
ersda TYPE ersda,
ernam TYPE ernam,
mtart TYPE mtart,
matkl TYPE matkl,
END OF ty_mara.

DATA :fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat_mara TYPE slis_fieldcat_alv,
it_mara TYPE TABLE OF ty_mara,
wa_mara TYPE ty_mara,
wa_mara_str TYPE mara,
list_top TYPE TABLE OF slis_listheader,
wa_list_top TYPE slis_listheader.

SELECT-OPTIONS: s_matnr FOR mara-matnr,
s_ersda FOR mara-ersda.

START-OF-SELECTION.
SELECT matnr ersda ernam mtart matkl
FROM mara
INTO TABLE it_mara
WHERE matnr IN s_matnr
AND ersda IN s_ersda.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = 'IT_MARA'
i_structure_name = 'MARA'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_INCLNAME =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
ct_fieldcat = fieldcat
* EXCEPTIONS
* INCONSISTENT_INTERFACE = 1
* PROGRAM_ERROR = 2
* OTHERS = 3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

LOOP AT fieldcat INTO wa_fieldcat_mara.
IF wa_fieldcat_mara-fieldname = 'ERNAM'.
wa_fieldcat_mara-edit = 'X'.
wa_fieldcat_mara-key = 'X'.
MODIFY fieldcat FROM wa_fieldcat_mara.
endif.

ENDLOOP.

wa_list_top-typ = 'H'.
wa_list_top-info = 'Grid Display of MARA Table'.
APPEND wa_list_top TO list_top.
CLEAR wa_list_top.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
i_callback_pf_status_set = 'PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
i_callback_top_of_page = 'TOP_OF_PAGE'
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
i_grid_title = 'Editable field : Created By'
* I_GRID_SETTINGS =
* IS_LAYOUT =
it_fieldcat = fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_mara
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

*&---------------------------------------------------------------------*
*& Form PF_STATUS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZSTANDARD'.

ENDFORM. "PF_STATUS

*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM user_command USING r_ucomm TYPE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.

WHEN 'SAVE'.
LOOP AT it_mara INTO wa_mara.
IF rs_selfield-fieldname = 'ERNAM'.
READ TABLE it_mara INDEX rs_selfield-tabindex INTO wa_mara.
IF sy-subrc = 0.
MOVE-CORRESPONDING wa_mara TO wa_mara_str.
MODIFY mara FROM wa_mara_str.
IF sy-subrc = 0.
MESSAGE s000(zmsg_srs).
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN OTHERS.
MESSAGE 'Wrong Input' TYPE 'I'.
ENDCASE.


ENDFORM. "USER_COMMAND

*&---------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = list_top
* I_LOGO =
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.
ENDFORM. "TOP_OF_PAGE


Comments

  • 15 Jul 2013 11:08 am
    Hi,
    Don't try to modify standard table with work area...declare
    one internal table with table type of mara,modify the internal table with
    the workarea,and modify the mara table with the internal table...
  • 15 Jul 2013 11:08 am
    Hi,

    Debug the program before clicking on save button then you can discover why
    it is not triggering and I have a doubt about your pf status name cross check it once
  • 15 Jul 2013 11:42 am
    Let's start by killing off the bad advice. You MUST NOT directly modify a
    DB table like MARA. You may only do this through SAP standard
    functionality (eg. BAPI, BDC of MM02..)

    Is this what you are actually trying to do?