cancel
Showing results for 
Search instead for 
Did you mean: 

AMDP Script - Customer Namespace - Using Global Variables

andrewlewisza
Discoverer
0 Kudos

HI

I have an AMDP class in a customer namespace, used by CDS views and Table Functions.

The header of the class looks like this:

CLASS /abc/xyz_cl_extract_material DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.

    INTERFACES if_amdp_marker_hdb .

    CLASS-METHODS :

      makt           FOR TABLE FUNCTION /abc/xyz_tf_makt,
      mara           FOR TABLE FUNCTION /abc/xyz_tf_mara,
      marc           FOR TABLE FUNCTION /abc/xyz_tf_marc,
      mlgn           FOR TABLE FUNCTION /abc/xyz_tf_mlgn.

    CONSTANTS :
                  gc_client type mandt value '010'.

  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

I want to use that constant in the methods, so that it is only defined once. Makes for neater code.

                               left outer join t006a as uom
                                 on marc.meins = uom.msehi
                                and uom.spras = 'E'
                                and uom.mandt = gc_client

However, the above doesn't work .. syntax error.

From reading on Google, it seems I need to prefix the constant with my class name. In the examples given, that would then be something like:

                               left outer join t006a as uom
                                 on marc.meins = uom.msehi
                                and uom.spras = 'E'
                                and uom.mandt = my_class=>gc_client

In this, however, my class name is "/abc/xyz_cl_extract_material", which means the code needs to look as follows:

                               left outer join t006a as uom
                                 on marc.meins = uom.msehi
                                and uom.spras = 'E'
                                and uom.mandt = /abc/xyz_cl_extract_material=>gc_client

That still doesn't work ... syntax error near the "/". I've tried escaping using "" as well as [ ], still nothing accepted. There is no auto-complete available in Eclipse to help me out here either.

Any ideas on how I can escape the "/" in the class name somehow ?Regards,Andrew

Accepted Solutions (1)

Accepted Solutions (1)

helmut_prestel
Discoverer
0 Kudos

In AMDP, there is currently no way to access constant values defined in ABAP directly. If you want to know ABAP constant values in an AMDP method, you normally need to use a method parameter to pass the value to the AMDP method. You may also define an additional AMDP scalar function which returns the "constant value" - this is then still not the same constant definition like in ABAP, but can be reused in AMDP methods.

And in case the parameter is for the ABAP client value ("MANDT") which should control all accesses to client-dependent tables and views, we recommend to use the built-in AMDP client handling via a method parameter and AMDP addition CDS SESSION CLIENT for this.

Answers (1)

Answers (1)

andrewlewisza
Discoverer
0 Kudos

Thanks for the reply Helmut, much appreciated.

I had a look at the CDS Session Client stuff you mentioned but that wouldn't work.

What I did do, in the end, was use the "$session.client" option in the CDS view to pass the session client through to a parameter in the Table Function. That parameter I could then use in the SQLScript AMDP method, and all is now running nicely.

It looked complicated in the beginning to implement, but now that I've done it, it is a nice neat solution with no hardcoding anywhere