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

What is wrong with this update statement

Former Member
0 Likes
609

Hi all,

I am trying to create a simple update program that allows user to enter table name, key fields and one field to update and its value.

But report goes into dump at update statement?

Here is the code:

REPORT  ZTABLE_UPDATE.


parameters: tabname(18).


PARAMETERS: key1(15),"use at where condition
            key1val(20),
            key2(15),"use at where condition
            key2val(20),
            field2(15)."field to be updated

PARAMETERS: yenideg1(20),
            yenideg2(20).


CONDENSE: tabname, field2,
          yenideg1, yenideg2,
          key1val, key2val,
          key1, key2.

data: wa like tabname.

*update (tabname) SET field2 = yenideg1*
                 *WHERE key1 like key1val and key2 like key2val.*if sy-subrc eq 0. 
  SELECT SINGLE * FROM (tabname) INTO wa
                  WHERE key1 like key1val
                    and key2 like key2val.
    WRITE / wa. "to test whether replacement is ok.
endif.

Thanks in advance.

Deniz

Hi all,

I am trying to create a simple update program that allows user to enter table name, key fields and one field to update and its value.

But report goes into dump at update statement?

Here is the code:

REPORT  ZTABLE_UPDATE.


parameters: tabname(18).


PARAMETERS: key1(15),"use at where condition
            key1val(20),
            key2(15),"use at where condition
            key2val(20),
            field2(15)."field to be updated

PARAMETERS: yenideg1(20),
            yenideg2(20).


CONDENSE: tabname, field2,
          yenideg1, yenideg2,
          key1val, key2val,
          key1, key2.

data: wa like tabname.

*update (tabname) SET field2 = yenideg1*
                 *WHERE key1 like key1val and key2 like key2val.*if sy-subrc eq 0. 
  SELECT SINGLE * FROM (tabname) INTO wa
                  WHERE key1 like key1val
                    and key2 like key2val.
    WRITE / wa. "to test whether replacement is ok.
endif.

Thanks in advance.

Deniz

4 REPLIES 4
Read only

Former Member
0 Likes
589

Check if there is any field with name field2 in your table which

UR passing with (tabname)

Read only

0 Likes
589

hi,

In ABAP Editor put cursor on update keywod and press f1 it will give how to use update keyword.

warm regrads

Surendar Reddy.

Read only

Former Member
0 Likes
589

Hi

LIKE key word will not work with UPDATE.

use MODIFY (tablename) TRANSPORTING (fields) WHERE (ur where condition).

Read only

Former Member
0 Likes
589

Hi:

follows is ok:

DATA: dy_table TYPE REF TO data,

dy_line TYPE REF TO data,

ifc TYPE lvc_t_fcat,

xfc TYPE lvc_s_fcat.

DATA: it_clrs_fields LIKE TABLE OF dfies WITH HEADER LINE.

DATA: cond(72) TYPE c,

itab LIKE TABLE OF cond,

itab2 LIKE TABLE OF cond.

FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,

<dyn_wa>,

<dyn_field>,

<fs>.

PARAMETERS: tabname TYPE ddobjname OBLIGATORY.

PARAMETERS: key1(15) OBLIGATORY,"use at where condition

key1val(20) OBLIGATORY,

key2(15),"use at where condition

key2val(20),

field2(15)."field to be updated

PARAMETERS: yenideg1(20),

yenideg2(20).

***START

CONDENSE: tabname, field2,

yenideg1, yenideg2,

key1val, key2val,

key1, key2.

CALL FUNCTION 'DDIF_FIELDINFO_GET'

EXPORTING

tabname = tabname

TABLES

dfies_tab = it_clrs_fields[]

  • FIXED_VALUES =

EXCEPTIONS

not_found = 1

internal_error = 2

OTHERS = 3

.

LOOP AT it_clrs_fields .

MOVE-CORRESPONDING it_clrs_fields TO xfc.

APPEND xfc TO ifc.

CLEAR: xfc.

ENDLOOP.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = ifc

IMPORTING

ep_table = dy_table.

ASSIGN dy_table->* TO <dyn_table>.

CREATE DATA dy_line LIKE LINE OF <dyn_table>.

ASSIGN dy_line->* TO <dyn_wa>.

CLEAR COND.

CONCATENATE key1 ' = ''' key1val '''' 'AND' INTO cond.

APPEND cond TO itab.

CLEAR COND.

CONCATENATE key2 ' = ''' key2val '''' INTO cond.

APPEND cond TO itab.

SELECT *

INTO <dyn_wa>

FROM (tabname)

WHERE (itab).

ENDSELECT.

IF sy-subrc <> 0.

WRITE / 'no this data in dbtab'.

EXIT.

ENDIF.

CLEAR COND.

CONCATENATE field2 ' = ''' yenideg1 '''' INTO cond.

UPDATE (tabname) SET (cond)

WHERE (itab).

IF sy-subrc EQ 0.

SELECT SINGLE * FROM (tabname) INTO <dyn_wa>

WHERE (itab).

WRITE / <dyn_wa>. "to test whether replacement is ok.

ENDIF.

you alse can use:

FM: VIEW_MAINTENANCE_CALL can used to do table maintenance.

note:

1.to do Table Maintenance Generator.

2.be authorized to to use tansaction sm30.

好运,

启明星