2016 Jan 28 11:52 AM
Dear all
I have a question regarding the use of a variable in an ABAP Managed Database Procedure.
The following method I implemented into a class:
How can I now insert a variable for the string 'YES' ?
I tried declaring a constant:
But I cannot use
... WHERE a.giftsyesorno = lc_yes;
Is there a solution for this problem? I would really like to use variables in the SQL syntax in the method.
Best regards
Thomas Bretonnet
2016 Jan 28 12:12 PM
Hello Thomas,
using a constant defined in the ABAP code of the AMDP class is not possible within an AMDP method. The only way to be able to use it is to pass it to the AMDP method as parameter.
The reason is that in the generated database procedure the constant defined in the ABAP code cannot be accessed.
But of course you can define the constant in the AMDP method itself using the SQLScript syntax:
DECLARE lc_yes CONSTANT nvarchar(3) := 'YES';
This has to be done unfortunately in each method you need it, cause there is not enclosing scope for several procedures.
Regards,
Florian
2016 Jan 28 12:10 PM
Hi,
You can declare variable inside AMDP method like below,
declare lc_yes nvarchar(3) := 'YES';
-Amol S
2016 Jan 28 12:12 PM
Hello Thomas,
using a constant defined in the ABAP code of the AMDP class is not possible within an AMDP method. The only way to be able to use it is to pass it to the AMDP method as parameter.
The reason is that in the generated database procedure the constant defined in the ABAP code cannot be accessed.
But of course you can define the constant in the AMDP method itself using the SQLScript syntax:
DECLARE lc_yes CONSTANT nvarchar(3) := 'YES';
This has to be done unfortunately in each method you need it, cause there is not enclosing scope for several procedures.
Regards,
Florian
2016 Jan 29 7:02 AM
Hello Thomas,
another possibility here, may be to define an appropriate IMPORTING parameter to the method interface, so the value of the variable (or constant) can be passed at the AMDP method call. This gives you the possibility to pass another value (e.g. NO) at runtime, depending on your scenario.
For example:
CLASS-METHODS giftyes
IMPORTING
VALUE(iv_variable) TYPE xxx
EXPORTING
VALUE(et_table) TYPE xxx.
Kind regards,
Carine