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

Dynamically accessing components

Former Member
0 Likes
612

Hello Everybody!

I'm a new ABAP developer and experimenting with the language a bit.

I'm having some trouble with something I'm not actually sure is a possibility. I'd like to call components of a structure from a string variable. I know that it's possible to do so with the table it self. I have setup:


DATA:
        column_name type string.

        column_name = 'c1'.

        UPDATE (table_name) SET (column_name) = 'X'
          WHERE LETTER = row.

(table_name) is called via USING by the subroutine. That part is working OK. I also have a try catch block around the UPDATE which catches cx_sy_dynamic_osql_semantics saying that (table_name) has no component named (column_name). Anybody have an idea how to properly execute this?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
580

Hello,

Please try the below code from F1 help of Update

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.

Thanks.

Ramya

3 REPLIES 3
Read only

ThomasZloch
Active Contributor
0 Likes
580

Looking at the online help for the UPDATE statement, it seems you'll have to replace

SET (column_name) = 'X'

by

SET (full_expression_syntax)

and prepare the syntax string accordingly.

Thomas

http://help.sap.com/abapdocu_70/en/ABAPUPDATE_SET_EXPRESSION.htm#&ABAP_ADDITION_4@4@

Read only

Former Member
0 Likes
581

Hello,

Please try the below code from F1 help of Update

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.

Thanks.

Ramya

Read only

Former Member
0 Likes
580

Thank you both for the prompt replies!

I had at first tried to do it the way Thomas did, but I didn't realize that I had to pass the entire argument as a string and not just throw the expression in ( ).