05-18-2016 10:50 AM
Hello Expert,
I am using select_options in SAP AMDP. But it is showing the below error:
CLASS ZCL_HANA_AMDP DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES:if_amdp_marker_hdb,
IF_SHDB_DEF.
TYPES: ty_where_t type TABLE OF IF_SHDB_DEF=>TT_NAMED_DREF.
CLASS-METHODS: select_options importing value(iv_where_cond) type ty_where_t
exporting value(et_sflight) type tt_sflight.
PROTECTED SECTION.
PRIVATE SECTION.
DATA : itab TYPE TABLE OF sflight.
ENDCLASS.
Error Details:
The method "SELECT_OPTIONS" contains a database procedure, which means that the row type of "IV_WHERE_COND" must be structured. All components of the row type must be elementary.
Please help me to fix this problem.
Thank you.
Best Regards,
Kailash
05-18-2016 11:26 AM
Hi,
The type you are using has one of the fields of "TYPE REF". The parameters of an AMDP class can only have scalar elements i.e each field should have a fixed data type.
This is one of the limitations of AMDP.
Regards,
Ashish
05-18-2016 11:45 AM
05-18-2016 11:59 AM
To use select option in AMDP, you need to convert your select-option table into a "where clause" string.
That can be done using FM "RSDS_RANGE_TO_WHERE".
Please find sample code below :
data : lt_range type rs_t_rscedst,
ls_range type rs_rscedst,
lv_whereclause type string.
loop at s_optiontab.
clear ls_range.
ls_range-fname = 'FIELDNAME'. "name of column on which the filter will act
ls_range-sign = s_optiontab-sign.
ls_range-option = s_optiontab-option.
ls_range-low = s_optiontab-low.
l s_range-high = s_optiontab-high.
append ls_range to lt_range.
endloop.
call function 'RSDS_RANGE_TO_WHERE'
exporting
i_t_range = lt_range
importing
e_where = lv_whereclause
exceptions
internal_error = 1
others = 2.
Now, pass this lv_whereclause string to the AMDP class.
Inside the AMDP after you have selected the data into the internal table use the where clause string to filter data by the following syntax.
it_data = APPLY_FILTER(:it_data,:lv_whereclause);
PS: the column on which the filter needs to work has to be in the selected columns i.e it needs to exist in the internal table.
05-18-2016 11:32 AM
Hi Kailash,
the answer of Ashish is correct.
Another remark would be, what you want to do with the select options in AMDP? You have to resolve them beforehand to a dynamic WHERE condition. See the article on how to solve your problem:
But why are you using AMDP at all? Can't your problem be solved within CDS or Open SQL? Open SQL can handle select options naturally. It is very questionable if you gain any speed by first converting the select options to a dynamic where within the ABAP code and then calling a HANA stored procedure.
Best regards,
Kilian.
05-18-2016 11:49 AM
Hello Kilian,
Thank you for your reply.
Yes, we can achieve the same using open sql or CDS view. But for practice purpose i want to do this using AMDP. Can you please help me to fix the problem.
Best Regards,
Kailash