cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

GetEntitySet with range table creates multiple/repeating entries

natasha_baunach
Explorer
0 Likes
763

Hello,

I map Query to a function module that has range table as input parameter (method GetEntitySet is generated). Here is example of my call is I use filter=Material eq '51' or Material eq '52' or Material eq '35'

Generated code looks like this:

* Maps filter table lines to function module parameters
LOOP AT lt_filter_select_options INTO ls_filter.

LOOP AT ls_filter-select_options INTO ls_filter_range.
CASE ls_filter-property.
WHEN 'MATERIAL'. " Equivalent to 'Material' property in the service
lo_filter->convert_select_option(
EXPORTING
is_select_option = ls_filter
IMPORTING
et_select_option = lr_material ).

LOOP AT lr_material INTO ls_material.
ls_it_material-high = ls_material-high.
ls_it_material-low = ls_material-low.
ls_it_material-option = ls_material-option.
ls_it_material-sign = ls_material-sign.
APPEND ls_it_material TO it_material.
ENDLOOP.

Table IT_MATERIAL ends up with 9 entries (3 sets of same 3 materials) because it loops on the second loop three times since I have 3 materials and each time, adds three materials.

I know I can redefine method and delete duplicate entries but it seems like SAP should know NOT to do this. Is there a standard way of preventing this from happening?

Thanks in advance,

Natasha

View Entire Topic
ThorstenHoefer
Active Contributor
0 Likes

Hi Nathalie,

please check your loop:

you loop over t_filter_select_options and in this loop over AT ls_filter-select_options into ls_filter_range,

but you never use ls_filter_range?

LOOP AT lt_filter_select_options INTO ls_filter.
LOOP AT ls_filter-select_options INTO ls_filter_range.

Proposal:

 Maps filter table lines to function module parameters
LOOP AT lt_filter_select_options INTO ls_filter.
CASE ls_filter-property.
WHEN 'MATERIAL'. " Equivalent to 'Material' property in the service
lo_filter->convert_select_option(
EXPORTING
is_select_option = ls_filter
IMPORTING
et_select_option = lr_material ).

LOOP AT lr_material INTO ls_material.
ls_it_material-high = ls_material-high.
ls_it_material-low = ls_material-low.
ls_it_material-option = ls_material-option.
ls_it_material-sign = ls_material-sign.
APPEND ls_it_material TO it_material.
ENDLOOP.
ENDLOOP
natasha_baunach
Explorer
0 Likes

Hello Thorsten,

I know how to fix it by redefining the generated method, but I am trying to avoid that. SAP Gateway generates that code and I am wondering if I am doing something wrong that it generates it like that.

Thank you,

Natasha