‎2011 Apr 08 1:03 PM
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?
‎2011 Apr 08 1:24 PM
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
‎2011 Apr 08 1:15 PM
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@
‎2011 Apr 08 1:24 PM
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
‎2011 Apr 08 1:56 PM
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 ( ).