2008 Apr 23 10:50 AM
hello sir,
i had done display data in alv from any custom table and that was edit and change..but now i want that data save in database through internal table ...what is coding for save butten.....
thanks
hello sir,
i had done display data in alv from any custom table and that was edit and change..but now i want that data save in database through internal table ...what is coding for save butten.....
thanks
2008 Apr 23 10:55 AM
hi,,
Here iam forwarding the example code for your requirement.
MODULE user_command_0100 INPUT.
DATA :gd_answer TYPE c.
CASE ok_code.
WHEN 'EXIT' OR 'CANC' OR 'BACK'.
LEAVE to screen 0.
WHEN 'SAVE'.
CALL METHOD grid->check_changed_data.
IF lt_display EQ gt_mara.
MESSAGE s001(00) WITH 'No data changed'.
ELSE.
CLEAR: gd_answer.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
text_question = 'Save data?'
IMPORTING
answer = gd_answer
EXCEPTIONS
text_not_found = 1
OTHERS = 2.
IF sy-subrc EQ 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*
IF ( gd_answer = '1' ). " yes
MESSAGE s001(00) WITH 'Data successfully saved' .
lt_display = gt_mara. " update PBO data !!!
ELSE.
MESSAGE s001(00) WITH 'Action cancelled by user' .
ENDIF.
ENDIF.
MODIFY ztest_mara12 FROM TABLE GT_MARA.
IF SY-SUBRC EQ 0.
COMMIT WORK.
Even i have done the same procedure to update.
Regards,
Madhavi
2008 Apr 24 8:40 AM
hello madam
i used ur code for save butten...plz say that
lt_display whitch type of data....
ur code working some wrong....
ok thanks
2008 Jun 13 7:50 AM
Hello ,
In case of displaying ALV using OOPS Concept then
need to use method in PAI user command.
CALL METHOD alv_grid->check_changed_data.
where alv_grid is declare as ,
alv_grid TYPE REF TO cl_gui_alv_grid.
for e.g.
In PAI module
CASE ok_code.
WHEN 'SAVE'.
CALL METHOD alv_grid->check_changed_data.
endcase.
Thanks.
2008 Apr 23 11:44 AM
Hi
OOPS ALV....
U should check the method handle_data_changed (in BCALV_EDIT_04), this method is triggered as soon as the table is modified.
Here you can understand if a new record is inserted or old record is updated or deleted.
*****************************************************
Normal ALV
Here is the sample code.If you executed the program and edited something,then after pressing back you will get the changed value in output.For that,I have used loop..Endloop. after FM.SInce your requirement is to update DB,you use
modify db from table itab.
That will insert/update the entries in db.
Kindly reward points by clicking the star on the left of reply,if it helps.
TYPE-POOLS: slis.
DATA: report_id LIKE sy-repid.
DATA: ws_title TYPE lvc_title VALUE 'An ALV Report'.
DATA: i_layout TYPE slis_layout_alv.
DATA: i_fieldcat TYPE slis_t_fieldcat_alv.
types : begin of ty,
pernr type pa0001-pernr,
SEQNR type pa0001-seqnr,
end of ty.
data itab type standard table of ty.
data wa type ty.
select pernr seqnr from pa0001 into table itab.
report_id = sy-repid.
PERFORM f1000_layout_init CHANGING i_layout.
PERFORM f2000_fieldcat_init CHANGING i_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = report_id
i_grid_title = ws_title
is_layout = i_layout
it_fieldcat = i_fieldcat
i_save = 'A'
TABLES
t_outtab = itab
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.
*Use modify statement here instead of loop
loop at itab into wa.
write : / wa-pernr, wa-seqnr.
endloop.
FORM f1000_layout_init USING i_layout TYPE slis_layout_alv.
CLEAR i_layout.
i_layout-colwidth_optimize = 'X'.
i_layout-edit = 'X'.
ENDFORM.
FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv.
DATA: line_fieldcat TYPE slis_fieldcat_alv.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'PERNR'. " The field name and the table
line_fieldcat-tabname = 'ITAB'. " name are the two minimum req.
line_fieldcat-key = 'X'. " Specifies the column as a key (Blue)
line_fieldcat-seltext_m = 'Personal No.'. " Column Header
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'SEQNR'.
line_fieldcat-tabname = 'ITAB'.
line_fieldcat-seltext_l = 'No. of records with same key'.
line_fieldcat-edit = 'X'. APPEND line_fieldcat TO i_fieldcat.
ENDFORM. " f2000_fieldcat_init
***********************************************
Regards
Vasu