06-01-2007 8:49 AM
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.
06-01-2007 8: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
06-01-2007 8:59 AM
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
06-01-2007 8:52 AM
Hi
you need to use the SET keyword .......
SET MARD-LBSTF = 'xxxx'.
MODIFY MARD.
Regards
Sudheer
06-01-2007 8: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.
06-01-2007 8: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............
06-01-2007 9:07 AM
Thanks, Biju, but what about updating only those rows, which are selected in the alv-grid. e.g. there are 10 rows in the internal table, they all are displayed in alv-grid. User selects only 3 of them (already in alv-grid) and by pushing 'SAVE' wants to update these 3 recordings in the field LBSTF of the table MARD.
06-01-2007 9:19 AM
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
06-01-2007 9: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.