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

modifying few fields in the database table

Hi all. I have an internal table, displayed in alv-grid. It has column named LBSTF. Database table MARD has the same field. I need to modify the data in this field in table MARD from the internal table, but only in rows, which are selected in the alv-grid. The internal table also has fields named as key fields of the table MARD.

Thanks all in advance.

Regards, Nikolai.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jun 01, 2007 at 07:52 AM

    Hi

    U need to implement a routine for the USER-COMMAND event:

    FORM USER_COMMAND USING R_UCOMM     LIKE SY-UCOMM
                            RS_SELFIELD TYPE SLIS_SELFIELD.
    
      IF R_UCOMM = 'UPDT'.
        LOOP AT OUTTAB WHERE MARK = 'X'.
    * Check MARD
          SELECT SINGLE * FROM MARD WHERE MATNR = OUTTAB-MATNR 
                                      AND WERKS = OUTTAB-WERKS
                                      AND LGORT = OUTTAB-WERKS.
          IF SY-SUBRC = 0.
            IF MARD-FIELD <> OUTTAB-FIELD.
              BAPIMATHEAD-MATERIAL     = OUTTAB-MATNR.
              BAPIMATHEAD-STORAGE_VIEW = 'X'.
              BAPI_MARDX-PLANT = BAPI_MARD-PLANT       = OUTTAB-WERKS.
              BAPI_MARDX-STGE_LOC = BAPI_MARD-STGE_LOC = OUTTAB-LGORT.
              BAPI_MARD-<FIELD>  = OUTTAB-FIELD.
              BAPI_MARDX-<FIELD> = 'X'.
    
              CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
                  EXPORTING
                   HEADDATA            = BAPIMATHEAD
                   STORAGELOCATIONDATA = BAPI_MARD
                  IMPORTING
                   RETURN              = BAPIRET2.
             ENDIF. 
          ENDIF.        
        ENDLOOP.
      ENDIF. 
    ENDFORM.

    Max

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi, max, I have a routine for the USER-COMMAND event. There is a button at the toolbar with the function 'SAVE', the code is the following

        METHOD handle_user_command.
          CASE e_ucomm.
            WHEN 'SAVE'. 
      
      "-----------------------???????????????
      
          ENDCASE.
        ENDMETHOD.                    "handle_user_command
      

  • author's profile photo Former Member
    Former Member
    Posted on Jun 01, 2007 at 07:52 AM

    Hi

    you need to use the SET keyword .......

    SET MARD-LBSTF = 'xxxx'.

    MODIFY MARD.

    Regards

    Sudheer

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 01, 2007 at 07:56 AM
    1. i hope u have a checkbox to select the fields
    
    2. declare one more itab1 same as ur internal table
    
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = W_REPID
    I_CALLBACK_USERCOMMAND = 'USER_COMMAND'.
    I_GRID_TITLE = 'GRID DISPLAY'
    IS_LAYOUT_LVC = WA_LAYOUT
    IT_FIELDCAT_LVC = IT_FIELDCAT
    TABLES
    T_OUTTAB = IT_FINAL
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2.
    
    FORM USER_COMMAND  using ucomm like p_uconn 
                                                      p_selfield TYPE SLIS_SELFIELD.
    
    Data ref1 type ref to cl_gui_alv_grid.
    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
    E_GRID = ref1.
    call method ref1->check_changed_data
    
    case ucomm.
    
       when 'SAVE'.
           loop at itab where check eq 'X'.
              move-corresponding itab to itab1.
              append itab1.
           endloop.
        update ztable from table itab1.
    
    endcase.
    
    ENDFORM.
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 01, 2007 at 07:57 AM

    Hi

    First of all Check whether you have the Authorization to do this. If you have as per you told (you have the key-fields of MARA in your internal table) simply you can update with UPDATE command..

    See the code below.Change the fields accordingly...

    loop at itab.

    Update MARD st LBSTF = itab-lbstf

    where matnr = itab-matnr and

    werks = itab-werks and

    lgort = itab-lgort.

    endloop.

    Also you can use UPDATE outside of the loop but before filter the internal table accordingly.Otherwise use the above mothod.

    Thats all you have to do.

    Reward All The Helpfull Answers............

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi

      Just as I explain in my prevoius answer you have to add in your output table a field for the mark and run the BAPI ( <b>don't update that table directly</b>) for the item selected:

      FORM USER_COMMAND USING R_UCOMM     LIKE SY-UCOMM
                              RS_SELFIELD TYPE SLIS_SELFIELD.
       
        IF R_UCOMM = 'UPDT'.
          LOOP AT OUTTAB WHERE MARK = 'X'.
      * Check MARD
            SELECT SINGLE * FROM MARD WHERE MATNR = OUTTAB-MATNR 
                                        AND WERKS = OUTTAB-WERKS
                                        AND LGORT = OUTTAB-WERKS.
            IF SY-SUBRC = 0.
              IF MARD-LBSTF <> OUTTAB-LBSTF.
                BAPIMATHEAD-MATERIAL     = OUTTAB-MATNR.
                BAPIMATHEAD-STORAGE_VIEW = 'X'.
                BAPI_MARDX-PLANT = BAPI_MARD-PLANT       = OUTTAB-WERKS.
                BAPI_MARDX-STGE_LOC = BAPI_MARD-STGE_LOC = OUTTAB-LGORT.
                BAPI_MARD-LBSTF  = OUTTAB-LBSTF.
                BAPI_MARDX-LBSTF = 'X'.
       
                CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
                    EXPORTING
                     HEADDATA            = BAPIMATHEAD
                     STORAGELOCATIONDATA = BAPI_MARD
                    IMPORTING
                     RETURN              = BAPIRET2.
               ENDIF. 
            ENDIF.        
          ENDLOOP.
        ENDIF. 
      ENDFORM.

      I don't rember if this BAPI wants the BAPI for the commit after calling it.

      U can indicate which field has to be used for the mark in layout structure:

      lt_layout-box_fieldname = 'MARK'.

      Max

  • author's profile photo Former Member
    Former Member
    Posted on Jun 01, 2007 at 08:07 AM

    Hi Nikolai,

    You can code this in the event USER_COMMAND of CL_GUI_ALV_GRID

    DATA: x_lt_rows TYPE lvc_t_row .
    DATA: x_ls_rows LIKE LINE OF x_lt_rows.
    
    CALL METHOD grid_req->get_selected_rows
      IMPORTING
        et_index_rows = x_lt_rows.
    
    LOOP AT x_lt_rows INTO x_ls_rows.
      READ TABLE ITAB INDEX x_ls_rows-index INTO WA.
      APPEND WA TO IT_MARD.
    ENDLOOP.
    MODIFY MARD FROM IT_MARD.
    
    

    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.