Skip to Content

Saving the edited ALV data

Hi All,

I have created an editable ALV, when i entered data into the column and tried to save but the data of the internal table is not changing because of which i was not able to modify the database table.

Below is my code, please suggest me where i went wrong.

REPORT /tli/tabgui3.

TYPE-POOLS: vrm,slis, icon..
TABLES: sscrfields.
DATA: lv_name  TYPE         vrm_id,
       lv_list  TYPE         vrm_values,
       lv_value LIKE LINE OF lv_list.
DATA: pbu1         TYPE string.


TYPES: BEGIN OF ty_ivcus,
          kunnr          TYPE kunnr,
          /tli/viv_resco TYPE /tli/viv_resco,
          stceg          TYPE stceg,
          bname          TYPE xubname,
          /tli/date      TYPE sydats,
          time           TYPE sytime,
          /tli/viv_rsn   TYPE  /tli/viv_rsn,
        END OF ty_ivcus.
DATA : it_ivcus  TYPE TABLE OF ty_ivcus,
        it_ivcus1 TYPE TABLE OF ty_ivcus,
        wa_ivcus  TYPE ty_ivcus.

DATA :  it_ivcuscp TYPE  STANDARD TABLE OF ty_ivcus, "temparary table for MARA
         it_changes TYPE  STANDARD TABLE OF ty_ivcus. "changes on grid

DATA: alv_container TYPE REF TO cl_gui_custom_container,
       alv_grid      TYPE REF TO cl_gui_alv_grid,
       ok_code       LIKE sy-ucomm,
       fieldcat      TYPE lvc_t_fcat.

DATA :  wa_fieldcat      TYPE  slis_fieldcat_alv, "Field catalog work area
         it_fieldcat      TYPE  slis_t_fieldcat_alv, "field catalog internal table
         it_layout        TYPE slis_layout_alv, "ALV layout settings
         form_top_of_page TYPE slis_formname VALUE 'FORM_TOP_OF_PAGE', "for avl header.
         form_callback    TYPE slis_formname VALUE 'USER_COMMAND'. "For user comman

SELECTION-SCREEN BEGIN OF BLOCK list WITH FRAME TITLE text-001.
PARAMETERS pa_typ TYPE /tli/viv_name AS LISTBOX VISIBLE LENGTH 40.
SELECTION-SCREEN END OF BLOCK list.

SELECTION-SCREEN SKIP 2.
SELECTION-SCREEN PUSHBUTTON 25(50) text-002 USER-COMMAND onli VISIBLE LENGTH 10.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_typ.
   lv_name = 'PA_TYP'.
   lv_value-key  = '1'.
   lv_value-text = 'ALL RECORDS'.
   APPEND lv_value TO lv_list.
   CLEAR lv_value.

   lv_value-key = '2'.
   lv_value-text = 'RECORDS WITH NO REASON FOR INVALIDITY'.
   APPEND lv_value TO lv_list.
   CLEAR lv_value.

   lv_value-key = '3'.
   lv_value-text = 'RECORDS WITH A REASON FOR INVALIDITY'.
   APPEND lv_value TO lv_list.
   CLEAR lv_value.

   CALL FUNCTION 'VRM_SET_VALUES'
     EXPORTING
       id              = lv_name
       values          = lv_list
     EXCEPTIONS
       id_illegal_name = 1
       OTHERS          = 2.
   IF sy-subrc <> 0.
*    MESSAGE e002 DISPLAY LIKE 'I'.
   ENDIF.
   CLEAR lv_list.

AT SELECTION-SCREEN.
   IF sscrfields-ucomm = 'VERIFY'.

     CALL FUNCTION 'ICON_CREATE'
       EXPORTING
         name                  = 'ICON CHECKED'
         text                  = 'VERIFY'
         info                  = 'VERIFY'
*       ADD_STDINF            = 'X'
       IMPORTING
         result                = pbu1
       EXCEPTIONS
         icon_not_found        = 1
         outputfield_too_short = 2
         OTHERS                = 3.
     IF sy-subrc <> 0.
*      MESSAGE e000.
     ENDIF.
   ENDIF.

START-OF-SELECTION.

   SELECT * FROM /tli/viv_ivcus INTO CORRESPONDING FIELDS OF TABLE it_ivcus1.
   CASE pa_typ.
     WHEN 1.
       it_ivcus[] = it_ivcus1[].
     WHEN 2.
       LOOP AT it_ivcus1 INTO wa_ivcus WHERE /tli/viv_rsn IS INITIAL.
         APPEND wa_ivcus TO it_ivcus.
       ENDLOOP.
     WHEN 3.
       LOOP AT it_ivcus1 INTO wa_ivcus WHERE /tli/viv_rsn IS NOT INITIAL.
         APPEND wa_ivcus TO it_ivcus.
       ENDLOOP.
     WHEN OTHERS.
       it_ivcus[] = it_ivcus1[].
   ENDCASE.

   CALL SCREEN 100.

************************************************************************
*      Module  status_0100  OUTPUT
************************************************************************
MODULE status_0100 OUTPUT.
   SET PF-STATUS '0100'.
   SET TITLEBAR '0100'.


* Create Controls
   CREATE OBJECT alv_container
     EXPORTING
       container_name = 'ALV_CONTAINER'.

   CREATE OBJECT alv_grid
     EXPORTING
       i_parent = alv_container.

*  Populate Field Catalog
   PERFORM get_fieldcatalog.

   it_ivcuscp[] = it_ivcus[].
   CALL METHOD alv_grid->set_table_for_first_display
     CHANGING
       it_outtab       = it_ivcus[]
       it_fieldcatalog = fieldcat[].


ENDMODULE.

************************************************************************
*      Module  USER_COMMAND_0100  INPUT
************************************************************************
MODULE user_command_0100 INPUT.

   CASE sy-ucomm.

     WHEN 'BACK' OR 'CANC' OR 'EXIT'.
       LEAVE PROGRAM.
     WHEN 'SAVE'.
       IF it_ivcuscp[] = it_ivcus[].
         MESSAGE 'No changes are made' TYPE 'I'.
       ELSE.
         MESSAGE 'Data Changed' TYPE 'I'.
       ENDIF.

       DATA : wa_ivcuscp     TYPE ty_ivcus.
       DATA : wa_ivcus_tmp TYPE /tli/viv_ivcus.
       CLEAR it_changes[].
       LOOP AT it_ivcus INTO wa_ivcus.
         READ TABLE it_ivcuscp INTO wa_ivcuscp INDEX sy-tabix.
         IF wa_ivcuscp NE wa_ivcus.
           APPEND wa_ivcus TO it_changes.
           MOVE-CORRESPONDING wa_ivcus TO wa_ivcus_tmp.
           wa_ivcus_tmp-bname = sy-uname.
           MODIFY /tli/viv_ivcus FROM wa_ivcus_tmp .
           IF sy-subrc EQ 0.
             MESSAGE 'Data Updated' TYPE 'I'.
           ENDIF.
         ELSE.
*      MESSAGE 'No Data changed' TYPE 'I'.
         ENDIF.
         CLEAR wa_ivcuscp.
       ENDLOOP.

   ENDCASE.

ENDMODULE.


************************************************************************
*      Form  Get_Fieldcatalog - Set Up Columns/Headers
************************************************************************
FORM get_fieldcatalog.
   DATA: ls_fcat TYPE lvc_s_fcat.

   REFRESH: fieldcat.

   CLEAR: ls_fcat.
   ls_fcat-reptext    = 'Customer Number'.
   ls_fcat-fieldname  = 'KUNNR'.
   ls_fcat-ref_table  = 'IT_IVCUS'.
   ls_fcat-outputlen  = '15'.
   APPEND ls_fcat TO fieldcat.

   CLEAR: ls_fcat.
   ls_fcat-reptext    = 'Result Code'.
   ls_fcat-fieldname  = '/TLI/VIV_RESCO'.
   ls_fcat-ref_table  = 'IT_IVCUS'.
   ls_fcat-outputlen  = '10'.
   APPEND ls_fcat TO fieldcat.

   CLEAR: ls_fcat.
   ls_fcat-reptext    = 'VAT Reg. No.'.
   ls_fcat-fieldname  = 'STCEG'.
   ls_fcat-ref_table  = 'IT_IVCUS'.
   ls_fcat-outputlen  = '20'.
   APPEND ls_fcat TO fieldcat.

   CLEAR: ls_fcat.
   ls_fcat-reptext    = 'USER'.
   ls_fcat-fieldname  = 'BNAME'.
   ls_fcat-ref_table  = 'IT_IVCUS'.
   ls_fcat-outputlen  = '12'.
   APPEND ls_fcat TO fieldcat.

   CLEAR: ls_fcat.
   ls_fcat-reptext    = 'DATE'.
   ls_fcat-fieldname  = '/TLI/DATE'.
   ls_fcat-ref_table  = 'IT_IVCUS'.
   ls_fcat-outputlen  = '10'.
   APPEND ls_fcat TO fieldcat.

   CLEAR: ls_fcat.
   ls_fcat-reptext    = 'TIME'.
   ls_fcat-fieldname  = 'TIME'.
   ls_fcat-ref_table  = 'IT_IVCUS'.
   ls_fcat-outputlen  = '10'.
   APPEND ls_fcat TO fieldcat.

   CLEAR: ls_fcat.
   ls_fcat-reptext    = 'Reason'.
   ls_fcat-fieldname  = '/TLI/VIV_RSN'.
   ls_fcat-ref_table  = 'IT_IVCUS'.
   ls_fcat-edit = 'X'.
   ls_fcat-outputlen  = '100'.
   APPEND ls_fcat TO fieldcat.
ENDFORM.

Thanks & regards,

NarsiReddy.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Sep 14, 2015 at 05:19 PM

    Hi,

    Implement the event data_changed .

    DATA grid3 TYPE REF TO cl_gui_alv_grid.

    CLASS lcl_event_receiver DEFINITION.

    PUBLIC SECTION.

    METHODS handle_data_changed

    FOR EVENT data_changed OF cl_gui_alv_grid

    IMPORTING er_data_changed.

    ENDCLASS.

    CLASS lcl_event_receiver IMPLEMENTATION.

    METHOD handle_data_changed.

    ENDMETHOD. "handle_data_changed

    ENDCLASS.

    DATA: event_receiver TYPE REF TO lcl_event_receiver.

    CREATE OBJECT event_receiver.

    SET HANDLER event_receiver->handle_data_changed FOR grid3.

    CALL METHOD grid3->register_edit_event

    EXPORTING

    i_event_id = cl_gui_alv_grid=>mc_evt_modified.

    Hope it helpful,

    Regards,

    Venkat.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.