Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

need help on modify

Former Member
0 Likes
820

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
786

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

7 REPLIES 7
Read only

bpawanchand
Active Contributor
0 Likes
786

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

Read only

Former Member
0 Likes
786

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

Read only

Former Member
0 Likes
786

hi,

The genral syntax is like this,

update my_table

set field1 = value1

field2 = value2

where field3 = value3.

Read only

Former Member
0 Likes
787

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

Read only

Former Member
0 Likes
786

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.

Read only

Former Member
0 Likes
786

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

Read only

Former Member
0 Likes
786

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.