‎2008 Jun 12 1:20 PM
Hi guys,
I want to update a database table with the below code:
SELECT SINGLE *
FROM z_pay
WHERE period = p_period
IF sy-subrc = 0.
zft_pay-stat = '2'.
ENDIF.
UPDATE z_pay.
is this code ok or not?
‎2008 Jun 12 1:42 PM
Hi Mark,
It seems some problem for me. Is the field *period is the only key field of ur ztable. When ever we update data base its better to select and update based on all key fields.
If u want to modify all the records for which period is equal to p_period then its fine.
DATA: wa_z_pay TYPE z_pay.
*CLEAR z_pay*
SELECT SINGLE *
FROM z_pay
INTO wa_z_pay "Use explicit work areas
WHERE period = p_period
--IF sy-subrc = 0.--
--zft_pay-stat = '2'. --
"Here u r getting data into zft_pay but updating with header
"line z_pay. So it will nor work.
--ENDIF.--
*CHECK sy-subrc IS INITIAL.*
wa_z_pay-stat = '2'.
UPDATE z_pay FROM wa_z_pay.
Thanks,
Vinod.
UPDATE z_pay.
‎2008 Jun 12 1:23 PM
Mark,
SELECT SINGLE *
FROM z_pay
WHERE period = p_period
IF sy-subrc = 0.
zft_pay-stat = '2'.
UPDATE z_pay where period = p_period.
ENDIF.
This is the right code.
please mark all good ans.
Amit.
‎2008 Jun 12 1:24 PM
Hi,
it looks OK. Probably you should put update statement inside of the if statement. Also using tables with header line is obsolete. You should explicitly define your working area.
‎2008 Jun 12 1:25 PM
It's OK .. But what RU updating to the table ...
SELECT SINGLE *
FROM z_pay
WHERE period = p_period
IF sy-subrc = 0.
zft_pay-stat = '2'. <-- is it z_pay-stat or zft_pay-stat
UPDATE z_pay.
ENDIF.
‎2008 Jun 12 1:33 PM
Hi,
UPDATE z_pay
SET zft_pay-stat = '2'.
WHERE period = p_period.
IF sy-subrc EQ 0.
COMMIT WORK.
....
ELSE.
....
ROLLBACK WORK.
ENDIF.
Check if this serves your purpose.
<REMOVED BY MODERATOR>
Thanks,
Dhanashri.
Edited by: Dhanashri Pawar on Jun 12, 2008 2:33 PM
Edited by: Dhanashri Pawar on Jun 12, 2008 2:34 PM
Edited by: Alvaro Tejada Galindo on Jun 12, 2008 2:10 PM
‎2008 Jun 12 1:37 PM
Hi,
Yes u can update table using UPDATE and SET statement but before updating a database table u need to lock it using
Function module ENQUEUE_TABLE_E
and dequeue after updation by DEQUEUE_TABLE_E by passing table name.
‎2008 Jun 12 1:42 PM
Hi Mark,
It seems some problem for me. Is the field *period is the only key field of ur ztable. When ever we update data base its better to select and update based on all key fields.
If u want to modify all the records for which period is equal to p_period then its fine.
DATA: wa_z_pay TYPE z_pay.
*CLEAR z_pay*
SELECT SINGLE *
FROM z_pay
INTO wa_z_pay "Use explicit work areas
WHERE period = p_period
--IF sy-subrc = 0.--
--zft_pay-stat = '2'. --
"Here u r getting data into zft_pay but updating with header
"line z_pay. So it will nor work.
--ENDIF.--
*CHECK sy-subrc IS INITIAL.*
wa_z_pay-stat = '2'.
UPDATE z_pay FROM wa_z_pay.
Thanks,
Vinod.
UPDATE z_pay.