‎2008 Aug 22 5:18 AM
1) I have to modify two fields in database table.please say the syntax for modify statement?
suppose I have three fields werks ,zdate ztime.after executing my program database table should be updated depending on werks
‎2008 Aug 22 5:44 AM
Hi NANI,
First create an internal table with work area. then put values in that work area. then modify...You can check the below code snippet.
Data: BEGIN OF ITAB OCCURS 0,
WERKS TYPE ZTAB-WERKS,
ZDATE TYPE ZTAB-ZDATE,
ZTIME TYPE ZTAB-ZTIME,
END OF ITAB.
ITAB-WERKS = <NEW VALUE>.
UPDATE <TABLE NAME> SET ZDATE = <DATE> ZTIME = <TIME>
WHERE WERKS = ITAB-WERKS.
MODIFY <TABLE NAME>.
THANKS
NITESH
‎2008 Aug 22 5:20 AM
HI
To overwrite a single line in a database table with the contents of a work area, use the following:
UPDATE <target> SET <set1> <set 2> ... WHERE <cond>.
check this snippet
DATA :
BEGIN OF fs_tab,
name1 TYPE kna1-name1,
land1 TYPE kna1-land1,
ort01 TYPE kna1-land1,
END OF fs_tab.
fs_tab-name1 = 'XYZ'.
fs_tab-land1 = 'IN'.
fs_tab-ort01 = 'Hyderabad'.
UPDATE kna1 SET name1 = fs_tab-name1 land1 = fs_tab-land1 ort01 =
fs_tab-ort01 WHERE kunnr = '0000000001'.
IF sy-subrc eq 0.
WRITE :
/ 'Updated'.
ENDIF.Regards
Pavan
‎2008 Aug 22 5:29 AM
hi kanneganti nani
chk this sample code..
*from work area
DATA message_wa TYPE t100.
message_wa-sprsl = 'EN'.
message_wa-arbgb = 'MYMSGCLASS'.
message_wa-msgnr = '100'.
message_wa-text = 'Some new message ...'.
MODIFY t100 FROM message_wa.
*From Internal Table
DATA message_itab like t100 occurs 0 with header line.
message_itab-sprsl = 'EN'.
message_itab-arbgb = 'MYMSGCLASS'.
message_itab-msgnr = '100'.
message_itab-text = 'Some new message ...'.
MODIFY t100 FROM TABLE message_itab.
Regards
DEVA
‎2008 Aug 22 5:36 AM
hi,
The genral syntax is like this,
update my_table
set field1 = value1
field2 = value2
where field3 = value3.
‎2008 Aug 22 5:44 AM
Hi NANI,
First create an internal table with work area. then put values in that work area. then modify...You can check the below code snippet.
Data: BEGIN OF ITAB OCCURS 0,
WERKS TYPE ZTAB-WERKS,
ZDATE TYPE ZTAB-ZDATE,
ZTIME TYPE ZTAB-ZTIME,
END OF ITAB.
ITAB-WERKS = <NEW VALUE>.
UPDATE <TABLE NAME> SET ZDATE = <DATE> ZTIME = <TIME>
WHERE WERKS = ITAB-WERKS.
MODIFY <TABLE NAME>.
THANKS
NITESH
‎2008 Aug 22 5:49 AM
refer this syntex.
it_final and zpayroll should have the same structure.
IF r_update = 'X'.
INSERT zpayroll FROM it_final.
* modify zpayroll FROM it_final.
IF sy-subrc = 0.
COMMIT WORK.
ELSE.
UPDATE zpayroll FROM it_final.
IF sy-subrc = 0.
COMMIT WORK.
ENDIF.
ENDIF.
ENDIF.
‎2008 Aug 22 5:53 AM
Hi,
For this requirement we need to use UPDATE... SET... WHERE.... statement.
plz have alook on this example :
UPDATE zo9_user_status
SET sub_date = sy-datum
sub_time = sy-uzeit
status = g_wa_outtab-status
WHERE representative = g_wa_outtab-representative AND
selection_id = g_wa_outtab-selection_id AND
sub_date = g_wa_outtab-sub_date AND
sub_time = g_wa_outtab-sub_time AND
superior = g_wa_outtab-superior.
IF sy-subrc EQ 0.
COMMIT WORK.
l_error = 'X1'.
ELSE.
l_error = 'X2'.
CLEAR l_error.
ROLLBACK WORK.
ENDIF.In your case we can have
UPDATE zo9_user_status
SET zdate = sy-datum
ztime = sy-uzeit
WHERE werks = g_wa_outtab-werks AND
sub_date = g_wa_outtab-zdate AND
sub_time = g_wa_outtab-ztime .
IF sy-subrc EQ 0.
COMMIT WORK.
l_error = 'X1'.
ELSE.
l_error = 'X2'.
CLEAR l_error.
ROLLBACK WORK.
ENDIF.This will surely solve your problem.
hope this helps.
thanx,
dhanashri.
Edited by: Dhanashri Pawar on Aug 22, 2008 6:54 AM
‎2008 Aug 22 6:06 AM
Try this-
Modify <dbtab> from <wa> transporting <field1> <field2>.
your work area should be of your database table type and field1 and field2 would be the fields that you want to change.