cancel
Showing results for 
Search instead for 
Did you mean: 

Customer exit variable with multiple input conditions

ikirilova1
Participant
0 Kudos
207

Hello, gurus!

I have the following task: when the user starts the query, he fills in the prompt selected date and list of materials. The query should return all of the materials from the filter with their lowest price for the period between the chosen date and 30 days ago from it.

I created two customer exit variables for the dates - one to get the selected date and another to calculate the date 30 days ago. I am using them as parameters in another CE which have to return the right price condition number.

I came with this code, but I am not very good at ABAP and it doesn't work properly. Right now it runs without errors and returns nothing. If I remove the initial check at the end the result is multiple # rows, which makes me think the list of materials is not loading properly into the variables. I tried to debug it but I am even worst in debugging and could understand a thing in the debugger.

I've checked the date CEs and they return correct results. Also I am sure I use valid data when testing (the test materials have price conditions in the selected period).



      WHEN 'ZCE_LOWEST_PRICE_LAST_30_DAYS'.
*"Variable to show the lowest price for 30 days before selected date"*
*" "*

IF i_step = 2.
READ TABLE i_t_var_range INTO l_s_var_range WITH KEY vnam = 'ZCE_SELECTED_DATE'.
date_temp = l_s_var_range-low.
c_year = date_temp(4).
c_month = date_temp+4(2).
c_day = date_temp+6(2).
CONCATENATE p_year c_month c_day INTO date_new.

clear l_s_var_range.

READ TABLE i_t_var_range INTO l_s_var_range WITH KEY vnam = 'ZCE_30_DAYS_FROM_SEL_DATE_2'.
date_temp = l_s_var_range-low.
c_year = date_temp(4).
c_month = date_temp+4(2).
c_day = date_temp+6(2).
CONCATENATE p_year c_month c_day INTO date_new_2.

clear l_s_var_range.

READ TABLE i_t_var_range ASSIGNING FIELD-SYMBOL(<fs_material>) WITH KEY vnam = '0S_MATL'.

SELECT MATERIAL FROM /BIC/AZPMM011100 INTO CORRESPONDING FIELDS OF TABLE it_mat_list
WHERE MATERIAL = <fs_material>-low.

LOOP AT it_mat_list INTO wa_mat_list.
price = 1000000.

SELECT * FROM /BIC/AZPMM011100 INTO CORRESPONDING FIELDS OF TABLE it_last_30_days_conditions
WHERE DATETO GE date_new_2 AND
DATEFROM LE date_new AND
MATERIAL EQ wa_mat_list-material.

LOOP AT it_last_30_days_conditions INTO wa_last_30_days_conditions.
IF price > wa_last_30_days_conditions-AMOUNT.
price = wa_last_30_days_conditions-AMOUNT.
pr_cond = wa_last_30_days_conditions-/BIC/KNUMH.
ENDIF.
ENDLOOP.

IF NOT pr_cond IS INITIAL.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
l_s_range-low = pr_cond.
APPEND l_s_range TO e_t_range.
ENDIF.

ENDLOOP.
ENDIF. SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; }.L0S31 { font-style: italic; color: #808080; }.L0S32 { color: #3399FF; }.L0S33 { color: #4DA619; }.L0S52 { color: #0000FF; }.L0S55 { color: #800080; }.L0S70 { color: #808080; }
raymond_giuseppi
Active Contributor
0 Kudos

Where do you fill this p_year variable (not c_year?)

ikirilova1
Participant
0 Kudos

Thanks Raymond, I fixed it. Unfortunately it is not enough.

Accepted Solutions (0)

Answers (1)

Answers (1)

appel_solar_dk
Active Participant
0 Kudos

Hi Ivelina

It looks a bit complicated. Why not just have the prompt for the date and use an offset for that in the query? In your key figure you create a calculated figure that use the price with an exception aggregation Minimum with respect to material. Done. No code needed.

Regards

Kristian

ikirilova1
Participant
0 Kudos

I need to filter price conditions valid for the 30 days period. The interval should be price valid from <= selected date and valid to >= selected day - 30 days. I cannot use the same time variable with different conditions in one query.

appel_solar_dk
Active Participant
0 Kudos

OK then I understand a bit more.

I don't think that variables are the answer. Think of variables as an automatic way to fill the prompt in SE16, basically you want separat from/to values for each material, that would be some thing like

("material" = x and "from" >= y and "to" <= z) or ("material" = q and "from" >= t and "to" <= r)

this is not possible to do in a selection in SAP.

One option could be to explode your price table into a full set for each day then you could use normal reporting features. If you have many materials it could become big...

If you are running on HANA (I don't think you are) then you could create a calculation view with a temporal join to eg /BI0/PDATE then you would have a virtual table with prices for each day.

You could also try out infosets, they can handle from / to dates (temporal joins) but I'm not an expert and I'm not sure it would work.

With kind regards

Kristian