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

UPDATE dynamic

ronaldo_aparecido
Contributor
0 Likes
5,397

Hello guys

I need to use the command update dynamic but he does not accept the set dynamic

how can I do this command:

       UPDATE (v_tbnam) SET (field) = 'TBRA'.

He says that the set is wrong.

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,380

Hi,

see the SAP example:

Example

Dynamic conversion of the content of an arbitrary column in an arbitrary database table of a previous currency in Euro.

PARAMETERS: table    TYPE c LENGTH 30,
            column   TYPE c LENGTH 30,
            old_curr TYPE sycurr.

DATA: set_expr  TYPE string,
      condition TYPE string.

CONCATENATE column ` = 'EUR'`
            INTO set_expr.

CONCATENATE column ` = old_curr`
            INTO condition.

TRY.
    UPDATE (table)
    SET    (set_expr)
    WHERE  (condition).
  CATCH cx_sy_dynamic_osql_error.
    MESSAGE `Error in update!` TYPE 'I'.
ENDTRY.

Regards,

Klaus

12 REPLIES 12
Read only

Former Member
0 Likes
3,381

Hi,

see the SAP example:

Example

Dynamic conversion of the content of an arbitrary column in an arbitrary database table of a previous currency in Euro.

PARAMETERS: table    TYPE c LENGTH 30,
            column   TYPE c LENGTH 30,
            old_curr TYPE sycurr.

DATA: set_expr  TYPE string,
      condition TYPE string.

CONCATENATE column ` = 'EUR'`
            INTO set_expr.

CONCATENATE column ` = old_curr`
            INTO condition.

TRY.
    UPDATE (table)
    SET    (set_expr)
    WHERE  (condition).
  CATCH cx_sy_dynamic_osql_error.
    MESSAGE `Error in update!` TYPE 'I'.
ENDTRY.

Regards,

Klaus

Read only

0 Likes
3,380

Better type 'A' so in case of an error all previous updates are rolled back to have a consistent state.

Read only

Former Member
0 Likes
3,380

Hi,

Provide the where condition along with this.

Please see below:

TRY.

    UPDATE (table)

    SET    (set_expr)

    WHERE  (condition).

  CATCH cx_sy_dynamic_osql_error.

    MESSAGE `Error in update!` TYPE 'I'.

ENDTRY.

Regards,

Jayshree.

Read only

FredericGirod
Active Contributor
0 Likes
3,380

Hi Ronaldo,

I never do this, but the SAP logic would be :

Update (W_TBNAME) SET (W_SET) WHERE (WHERE).

regards

Fred

Read only

Former Member
0 Likes
3,380

Hi Ronaldo,

Use Field Symbol to achieve your goal.

Use the following Syntax:

DATA tbnam TYPE TABLE OF v_tbnamt.

FIELD-SYMBOLS <fs_tbnam> TYPE v_tbnam.

SELECT *  FROM v_tbnamt INTO TABLE tbnamt.

IF sy-subrc = 0.

  LOOP AT tbnamt ASSIGNING <fs_tbnam>.

   <fs_tbnam>-field = New_value.

  ENDLOOP.

ENDIF.

UPDATE (v_tbnam) FROM TABLE tbnam.

Thanks

Dileep Kumar

Read only

Former Member
0 Likes
3,380

Hi,

You can do it like this.

TABLE_NAME = 'ZMYTABLE'

CONCATENATE 'MYFIELDNAME = ' '''' 'MYVALUE' '''' INTO T_SET.

UPDATE (TABLE_NAME) SET (T_SET).

BR

Yakub Shah

Read only

rainer_hbenthal
Active Contributor
0 Likes
3,380

You have to put the whole logical condition into a variable:

[code]

   concatenate fieldname `=` value into condition.

  update (v_tbname) set (condition),

[code]

Read only

0 Likes
3,380

thanks worked

Read only

RaymondGiuseppi
Active Contributor
0 Likes
3,380

I just hope you are not updating a standard table with a dynamic sql statement

Regards,

Raymond

Read only

0 Likes
3,380

Whatever can be used will be used (somewhere)

Read only

0 Likes
3,380

Yes, and Anything that can go wrong, will go wrong (someday)

Read only

0 Likes
3,380

Its Z table relax