Skip to Content
author's profile photo Former Member
Former Member

Edited or Entered data to be saved in table throgh ALV

Hai,

I have created an alv report, in which two fields are in editable mode.

when we entered or changed the respective data, what steps to be used

to save the same to our own table.

thanks,

Madhu.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 04:43 AM

    refer below link

    http://saptechnical.com/Tutorials/ALV/Edit/demo.htm

    Edited by: shan palani on Dec 19, 2008 10:21 AM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 04:48 AM

    Hi,

    Find the code below which is for the similar requirment. The code under the Form 'USERCOMM' must help you.

    REPORT  Z1ATL_RET_DB_DATA MESSAGE-ID ZRCH.
    
    ** Data declarations
    TYPE-POOLS: SLIS.
    DATA: DESCRIPTOR TYPE REF TO CL_ABAP_STRUCTDESCR.
    DATA: FLDDESCR TYPE DDFIELDS,
          WA_FLDDESCR LIKE LINE OF FLDDESCR.
    
    **--- Return table to handle selected field in F4 help ---**
    DATA: IT_RETURN LIKE DDSHRETVAL OCCURS 0 WITH HEADER LINE.
    
    TYPES: BEGIN OF TY_HELP,
           FIELDNAME TYPE FIELDNAME,
           END OF TY_HELP.
    
    DATA: IT_HELP TYPE TABLE OF TY_HELP,
          WA_HELP TYPE TY_HELP.
    
    DATA: V_DBTABLE_TEMP TYPE DD02L-TABNAME.
    
    DATA: V_INDEX_NEW TYPE I,
          V_INDEX TYPE I VALUE 1.
    
    DATA: IT_FIELDCATALOG1 TYPE SLIS_T_FIELDCAT_ALV,
          WA_FIELDCATLOG1 LIKE LINE OF IT_FIELDCATALOG1.
    
    DATA GD_REPID TYPE SY-REPID.
    
    **Selection Screen declarations
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECTION-SCREEN SKIP.
    PARAMETERS: P_TABLE LIKE DD02L-TABNAME OBLIGATORY,
                P_FIELD LIKE WA_FLDDESCR-FIELDNAME.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN END OF BLOCK B1." with text text-001.
    
    
    AT SELECTION-SCREEN ON P_TABLE.
    
      IF NOT P_TABLE IS INITIAL.
    
        SELECT SINGLE TABNAME
               FROM DD02L
               INTO V_DBTABLE_TEMP
               WHERE TABNAME EQ P_TABLE.
    
        IF SY-SUBRC EQ 0.
    
          DESCRIPTOR ?= CL_ABAP_STRUCTDESCR=>DESCRIBE_BY_NAME( P_TABLE ).
          FLDDESCR = DESCRIPTOR->GET_DDIC_FIELD_LIST( ).
    
        ELSE.
    
          MESSAGE E001 WITH P_TABLE.
    
        ENDIF.
    
      ENDIF.
    
    
    AT SELECTION-SCREEN ON P_FIELD.
    
      IF NOT FLDDESCR IS INITIAL AND P_FIELD IS NOT INITIAL.
    
        READ TABLE FLDDESCR INTO WA_FLDDESCR WITH KEY FIELDNAME = P_FIELD.
    
        IF SY-SUBRC <> 0.
    
          MESSAGE I000 WITH P_FIELD.
          STOP.
    
        ENDIF.
    
      ENDIF.
    
    **The list of fields displayed
    *AT SELECTION-SCREEN.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FIELD.
    
      LOOP AT FLDDESCR INTO WA_FLDDESCR.
    
        WA_HELP-FIELDNAME = WA_FLDDESCR-FIELDNAME.
        APPEND WA_HELP TO IT_HELP.
        CLEAR WA_HELP.
    
      ENDLOOP.
    
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
          RETFIELD         = 'FIELDNAME'
          DYNPPROG         = SY-CPROG
          DYNPNR           = SY-DYNNR
          VALUE_ORG        = 'S'
          CALLBACK_PROGRAM = SY-CPROG
        TABLES
          VALUE_TAB        = IT_HELP
          RETURN_TAB       = IT_RETURN
        EXCEPTIONS
          PARAMETER_ERROR  = 1
          NO_VALUES_FOUND  = 2.
    
      IF SY-SUBRC EQ 0.
        LOOP AT IT_RETURN.
          CLEAR P_FIELD.
          P_FIELD = IT_RETURN-FIELDVAL.
        ENDLOOP.
    
      ENDIF.
    
    
    START-OF-SELECTION.
    
      DATA: I_TAB TYPE REF TO DATA,
            NEW_LINE TYPE REF TO DATA.
      FIELD-SYMBOLS: <TAB> TYPE TABLE,
                     <DYN_WA>.
      CREATE DATA I_TAB TYPE TABLE OF (P_TABLE).
      ASSIGN I_TAB->* TO <TAB>.
    
    *Create dynamic work area and assign to FS
      CREATE DATA NEW_LINE LIKE LINE OF <TAB> .
      ASSIGN NEW_LINE->* TO <DYN_WA>.
    
      SELECT *
             FROM (P_TABLE)
             INTO TABLE <TAB>.
    
      IF SY-SUBRC EQ 0.
    
        PERFORM BUILD_FIELD_CATELOG.
    
        GD_REPID = SY-REPID.
    
    **   ALV DISPLAY   **
        IF NOT <TAB> IS INITIAL.
    
          CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
            EXPORTING
              I_CALLBACK_PROGRAM       = GD_REPID
              I_CALLBACK_PF_STATUS_SET = 'ABC'
              I_CALLBACK_USER_COMMAND  = 'USERCOMM'
              IT_FIELDCAT              = IT_FIELDCATALOG1[]
              I_SAVE                   = 'A'
            TABLES
              T_OUTTAB                 = <TAB>.
    
        ELSE.
    
          MESSAGE I007.
    
        ENDIF.
    
      ENDIF.
    
    ** Building field catelog.
    FORM BUILD_FIELD_CATELOG.
    
      LOOP AT FLDDESCR INTO WA_FLDDESCR.
    
        CASE WA_FLDDESCR-FIELDNAME.
    
          WHEN P_FIELD.
    
            V_INDEX_NEW = V_INDEX_NEW  + 1.
            WA_FIELDCATLOG1-FIELDNAME = WA_FLDDESCR-FIELDNAME.
            WA_FIELDCATLOG1-TABNAME    = '<tab>'.
            WA_FIELDCATLOG1-EDIT = 'X'.
            WA_FIELDCATLOG1-SELTEXT_L  = WA_FLDDESCR-FIELDNAME.
            WA_FIELDCATLOG1-COL_POS    =  V_INDEX_NEW.
            APPEND WA_FIELDCATLOG1 TO IT_FIELDCATALOG1.
            CLEAR WA_FIELDCATLOG1-KEY.
    
          WHEN OTHERS.
    
            V_INDEX_NEW = V_INDEX_NEW  + 1.
            WA_FIELDCATLOG1-FIELDNAME = WA_FLDDESCR-FIELDNAME.
            WA_FIELDCATLOG1-TABNAME    = '<tab>'.
            WA_FIELDCATLOG1-EDIT = ' '.
            WA_FIELDCATLOG1-SELTEXT_L  = WA_FLDDESCR-FIELDNAME.
            WA_FIELDCATLOG1-COL_POS    =  V_INDEX_NEW.
            APPEND WA_FIELDCATLOG1 TO IT_FIELDCATALOG1.
            CLEAR WA_FIELDCATLOG1-KEY.
    
        ENDCASE.
    
      ENDLOOP.
    
    ENDFORM.                    "build_field_catelog
    
    *&---------------------------------------------------------------------*
    *&      Form  ABC
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->EXTAB      text
    *----------------------------------------------------------------------*
    FORM ABC USING EXTAB TYPE SLIS_T_EXTAB.
      SET PF-STATUS 'ABC'. " excluding extab.
    ENDFORM.                    "ABC
    
    **&---------------------------------------------------------------------*
    *
    **&      Form  user_command
    *
    **&---------------------------------------------------------------------*
    *
    **       text
    *
    **----------------------------------------------------------------------*
    *
    FORM USERCOMM  USING UCOMM TYPE SY-UCOMM
    
                SELFIELD TYPE SLIS_SELFIELD.
    
      DATA: GD_REPID LIKE SY-REPID, "Exists
    
      REF_GRID TYPE REF TO CL_GUI_ALV_GRID.
    
      IF REF_GRID IS INITIAL.
    
        CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
          IMPORTING
            E_GRID = REF_GRID.
    
      ENDIF.
    
      IF NOT REF_GRID IS INITIAL.
    
        CALL METHOD REF_GRID->CHECK_CHANGED_DATA .
    
      ENDIF.
    
      CASE UCOMM.
    
        WHEN 'SAVE'.
    
          "Do Update the Data base here....
    
          SELFIELD-REFRESH = 'X'.
    
          UPDATE (P_TABLE) FROM TABLE <TAB>.
    
          IF SY-SUBRC EQ 0.
    
            MESSAGE S002 WITH P_TABLE.
    
          ELSE.
    
            MESSAGE S003 WITH P_TABLE.
    
          ENDIF.
    
        WHEN 'DELETE'.
    
          SUBMIT Z1ATL_DB_DELETE WITH P_TABLE = P_TABLE AND RETURN.
    
    
      ENDCASE.

    ENDFORM. "user_command

    Hope this helps,

    Murthy.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      Write Code for user command "SAVE".

      when u edit the value in the Output...the user need to save this entries.

      then u can add functionality for UCOMM = 'SAVE'.

      thanks.

      Edited by: sunil kumar on Dec 19, 2008 5:52 AM

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 04:55 AM

    Hi,

    If u are using OO ALV then u need to call a method.

    Do as follows,

    CLASS lcl_event_handler DEFINITION .

    PUBLIC SECTION .

    METHODS:

    handle_data_changed

    FOR EVENT data_changed OF cl_gui_alv_grid

    IMPORTING er_data_changed

    CLASS lcl_event_handler IMPLEMENTATION .

    METHOD handle_data_changed .

    PERFORM handle_data_changed USING er_data_changed .

    ENDMETHOD.

    Write ur code in that perform.

    Regards,

    Kusuma.

    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.