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

Variable in SQL ABAP Managed Database Procedure

Former Member
15,037

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

1 ACCEPTED SOLUTION
Read only

pfefferf
Active Contributor
5,314

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

3 REPLIES 3
Read only

amol_samte
Contributor
0 Kudos
5,314

Hi,

You can declare variable inside AMDP method like below,

declare lc_yes nvarchar(3) := 'YES';

-Amol S

Read only

pfefferf
Active Contributor
5,315

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

Read only

CarineTchoutouo
Product and Topic Expert
Product and Topic Expert
0 Kudos
5,314

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