cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to pass the IMPORT Parameter of AMDP Class as SQL APPLY_FILTER's second parameter.

Sijin_Chandran
Active Contributor
0 Kudos

Hello All,

I have an Import parameter of an AMDP Class's Method say "iv_sel_opt" of type String.

Which would be indeed having values from "CL_SHDB_SELTAB=>combine_seltabs", so it will convert Select-Options of a Report Screen and convert it into SQL Where Clause.

Now am not able to use this "iv_sel_opt" inside AMDP Method Implementation as second parameter for "APPLY_FILTER".

It says "SQLSCRIPT message: Parameter has a non supported type: APPLY_FILTER: second parameter has to be a scalar variable &A0&A1&A2&A3&A4&A5&A6&A7&A8&A9"

Is there anyway it could be achieved apart from using CDS Table Functions ?

Helpful comments much appreciated.

Thanks,

Sijin

Please find my code :

CLASS zcl_demo_consume_amdp_abap DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .


PUBLIC SECTION.
  INTERFACES : if_amdp_marker_hdb.


  TYPES:
    BEGIN OF ty_mara,
        matnr TYPE c LENGTH 40,
        ernam TYPE c LENGTH 12,
    END OF ty_mara,


    tt_mara TYPE STANDARD TABLE OF ty_mara.
    
  CLASS-METHODS get_mara
    IMPORTING
        VALUE(iv_client)  TYPE mandt
        VALUE(iv_sel_opt) TYPE string
    EXPORTING
        VALUE(et_mara)    TYPE tt_mara.
        
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.


CLASS zcl_demo_consume_amdp_abap IMPLEMENTATION.
  METHOD get_mara BY DATABASE PROCEDURE
                  FOR HDB
                  LANGUAGE SQLSCRIPT
                  OPTIONS  READ-ONLY
                  USING mara.
    et_mara = apply_filter ( mara , iv_sel_opt); " <== Here is the error
  ENDMETHOD.
ENDCLASS.
<br>

Sijin_Chandran
Active Contributor
0 Kudos

As highlighted by some of the members I had tried adding with ':' also,

The message says :

SQLSCRIPT message: return type mismatch: Procedure ZCL_DEMO_CONSUME_AMDP_ABAP=>GET_MARA: ET_MARA[ MANDT:NVARCHAR(3) MATNR:NVARCHAR(40) ERSDA:NVARCHAR(8) ERNAM:NVARCHAR(12) LAEDA:NVARCHAR(8) AENAM:NVARCHAR(12) VPSTA:NVARCHAR(15) PSTAT:NVARCH

Can anything be done to do away with this error ?

Sijin_Chandran
Active Contributor
0 Kudos

Am really clueless why my question is downvoted by someone. AMDP is quite new and I was not able to find any solution for this over internet.

Accepted Solutions (1)

Accepted Solutions (1)

pfefferf
Active Contributor
0 Kudos

Sure you get this error (mentioned in the comments), because the MARA table has more fields than defined in your output table ET_MARA. You can resolve using for instance like following:

...
lt_mara = apply_filter(mara, :iv_sel_opt);
et_mara = select matnr, ernam from :lt_mara;
Sijin_Chandran
Active Contributor
0 Kudos

Hi Florian,

First thanks a lot, yeah I was missing this part:

et_mara = select matnr, ernam from :lt_mara;

Can you please make this comment as a new Answer, so that I can accept it as a solution for this query.

Thanks,

Sijin

Answers (3)

Answers (3)

s1252
Participant
0 Kudos

Hi,

The 2nd error is nothing to do with apply filter, it says return table structure of apply filter does not match with the table given LHS.

In this case, et_mara and mara( inside apply filter) have different structures.

Please verity and correct the structures in LHS & RHS are same , then et_mara = apply_filter ( mara ,:iv_sel_opt); should work.

-Krishna S

pfefferf
Active Contributor
0 Kudos

I think that was already clarified, or what you wanna say with that answer??

former_member302041
Contributor
0 Kudos

I would add that CE functions are obsolete (as per SQL Reference Guide) and you should use SQL functions (select a,b,c... from mara where column = :iv_sel_opt)

Sijin_Chandran
Active Contributor
0 Kudos

I had tried with that also,

but was getting the below error message in Eclipse Editor itself,

Multiple markers at this line:
    - (
    - )
    - SQLSCRIPT message: return type mismatch: Procedure ZCL_DEMO_CONSUME_AMDP_ABAP=>GET_MARA: ET_MARA[ MANDT:NVARCHAR(3) MATNR:NVARCHAR(40) ERSDA:NVARCHAR(8) ERNAM:NVARCHAR(12) LAEDA:NVARCHAR(8) AENAM:NVARCHAR(12) VPSTA:NVARCHAR(15) PSTAT:NVARCH
former_member302041
Contributor
0 Kudos

The error talking about types mismatch...

That code doesn't work?

et_mata = select matnr, ernam from mara where SOME_COLUMN = :iv_sel_opt.
pfefferf
Active Contributor
0 Kudos

APPLY_FILTER is not a CE function and therefore not obsolete. It a function part of the SQLScript dynamic SQL area.

The way you suggest to compare the value of IV_SEL_OPT against a specific column will not work, as this parameter does not just contain a restriction for a single column, but a whole condition set (e.g. for different columns with different operators/values/...).

pfefferf
Active Contributor
0 Kudos

The only point I see is that the colon to address the IV_SELOPT parameter in your AMDP is missing. Can you add a colon in front of the parameter name.

et_mara = apply_filter ( mara , :iv_sel_opt);
Sijin_Chandran
Active Contributor
0 Kudos

Am sorry I didn't mention,

actually I had tried with that also and was getting the below message ,

Multiple markers at this line:
    - (
    - )
    - SQLSCRIPT message: return type mismatch: Procedure ZCL_DEMO_CONSUME_AMDP_ABAP=>GET_MARA: ET_MARA[ MANDT:NVARCHAR(3) MATNR:NVARCHAR(40) ERSDA:NVARCHAR(8) ERNAM:NVARCHAR(12) LAEDA:NVARCHAR(8) AENAM:NVARCHAR(12) VPSTA:NVARCHAR(15) PSTAT:NVARCH