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

RFC and dynamic SQL

matt
Active Contributor
2,238

I've got an RFC enabled function module, which uses a dynamic where clause, like

TRY.
       DATA(Where) = `somefield EQ zcl_someclass=>c_constant-value`.
       SELECT * FROM table INTO internal_Table WHERE (where).    
    CATCH cx_sy_dynamic_osql_error INTO DATA(sql_error).
      e_error-message = sql_error->get_text( ) && ` : ` && sql_error->get_longtext( ).
      e_error-type = 'E'.
      RETURN.
  ENDTRY.

I'm calling it with a destinations that's just to another client in the same instance. It throws an exception - it does not like zcl_someclass=>c_constant-value. It says that the value can't be established.

This is in a 7.31 system. I'll be testing in a 752 system when I get some time.

Has anyone noticed this strange behaviour, or have an explanation? It only happens with an RFC. Locally, it works fine.

1 ACCEPTED SOLUTION
Read only

joltdx
Active Contributor
2,122

There's no mention of it in the 7.31 documentation, but in the 7.52 docs says right here that:

  • In dynamic SQL conditions, static attributes or constants of a class cannot be accessed from outside in cases where the class has a static constructor and the constructor was not yet executed.

Both doc versions says that:

  • The data objects specified in a dynamic condition should be declared in the same context, if possible, since searches in higher contexts at runtime are more unwieldy.

I don't know what it could be, but is it something with the class and RFC?

9 REPLIES 9
Read only

FredericGirod
Active Contributor
0 Likes
2,122

in debug, the class=>constant gives a result ?

Read only

matt
Active Contributor
0 Likes
2,122

No.

Neither in update, nor in local.

When I debug locally, I don't get the exception.

Read only

FredericGirod
Active Contributor
0 Likes
2,122

sorry, you debug in RFC ? or just in local call ?

Read only

matt
Active Contributor
0 Likes
2,122

I get the error in RFC (debug or not debug -> I updated the question):

Could not interpret the value 'CLASS=>CONSTANT'

An attempt was made to execute an Open SQL stateme nt, in which the dynamic WHERE or SET condition contains the illegal value 'CLASS=>CONSTANT'. For instance, one of the value fields, addressed by a LIKE operator in the WHERE clause, is not type C.

The constant type is CHAR 1.

When I put the value in directly, like

       DATA(Where) = `somefield EQ '1'`.
       SELECT * FROM table INTO internal_Table WHERE (where). 

It also works fine.

Read only

joltdx
Active Contributor
0 Likes
2,122

Try assigning zcl_someclass=>c_constant-value to a local helper variable to see if that makes any difference...?

Read only

joltdx
Active Contributor
2,123

There's no mention of it in the 7.31 documentation, but in the 7.52 docs says right here that:

  • In dynamic SQL conditions, static attributes or constants of a class cannot be accessed from outside in cases where the class has a static constructor and the constructor was not yet executed.

Both doc versions says that:

  • The data objects specified in a dynamic condition should be declared in the same context, if possible, since searches in higher contexts at runtime are more unwieldy.

I don't know what it could be, but is it something with the class and RFC?

Read only

matt
Active Contributor
2,122

There you go. The caller of the FM has already run class constructor. - it works locally.

However, in the RFC context in the FM, the class constructor has not run - and we get the error.

Read only

joltdx
Active Contributor
2,122

Lovely! 🙂

Read only

matt
Active Contributor
0 Likes
2,122

Tried that - works.

Also tried

DATA(Where) = `somefield EQ '` &&  zcl_someclass=>c_constant-value && `'`.

and that works too.