Application Development 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: 

using UPDATE table SET with field symbols

Former Member
0 Kudos

Hi,

i need to update database table and the requriement is that i need to update only one field depending on the condition.

loop at itab.

case itab-no.

when '01'.

field 1 = field1 + itab-field1.

........

when '14'.

field14 = field14 + itab-field1.

endcase.

endloop.

here i need to update only one of the 14 fields in the database table and i want to avoid 'MODIFY' . i want to use UPDATE dbtable SET field (depending on condition) = value(depending on condition) and i want to use this only once rather than in every 'when'. is there any way to achieve this using field symbols. im looking at how to pass FIELD NAME using field symbols.

your help would be appreciated.

Thanks,

ravi.

2 REPLIES 2

Former Member
0 Kudos

Ravi,

Try this.

constant :c_field(5) value 'field'

Data : fieldname(7).

data : no type n value '01'.

field-symbols : <fs_any> type any.

loop at itab.

concatenate (c_field) itab-no into fieldname.

assign fieldname to <fs_any>.

<fs_any> = <fs_any> + itab-fieldname.

endloop.

The syntax might be wrong, but the logic should work.

Regards,

Ravi

Former Member
0 Kudos

Hi

DATA: SET_CLAUSE TYPE STRING,

FIELD_NAME(30).

FIELD-SYMBOLS: <FS_1> TYPE ANY,

<FS_2> TYPE ANY.

LOOP AT itab.

CASE itab-no.

WHEN '01'. field_name = field1.

WHEN '02'. field_name = field2.

WHEN '03'. ............

ENDCASE.

ASSIGN COMPONENT field_name OF STRUCTURE itab TO <fs_1>.

ASSIGN (field_name) TO <fs_2>.

<fs_1> = <fs_1> + <fs_2>.

CONCATENATE '''' cond '''' INTO field_cond.

CONCATENATE field_name '=' field_cond INTO set_clause

SEPARATED BY space.

ENDLOOP.

update TABLE set (set_clause) where ......

Max