Loading

To populate filds dynamically in query

Requirement
Our requirement was , we were having one Ztable in Ecc and from Ecc we were fetching all the data upto standard dso in BI , and from some other source we are having data up to cube .In our flow we were having 4 ds including the above Ztable.
All flow were independent.Like DS-WOP DSO-Std.DSO-CUBE , on top of all 3 cube we were having one Multiprovider, and we were having our query , but even though Ztable flow was there in that flow but we dnt add the dso of Ztable flow in our Multiprovider.all the above flow were having profit center and Company code as key field , based on company code user was expecting all the Key figures from the Ztable but their intention was those KF IOs sd not be there in query .In that table around 20 KFS were there (User was not bother about the performance, also ).Company code was Mandatory and Single value in our selection, also currency was constant that is USD.
To achive this what I did , I have created one data source for that Ztable and loaded data upto standard DSO.
den Have created 20 formula variable processing type user exit .
and was achived the requirement .the sample code for one formula variable as follow .



IF i_step = 2.
IF i_vnam EQ 'ZFORVAR'. "formula variable
SELECT *
FROM /
INTO TABLE itab
WHERE company code EQ ‘Var name in selection screen’."ZVAR'
IF sy-subrc EQ 0.
READ TABLE i_t_var_range INTO wa_t_var_range WITH KEY vnam = 'ZVAR'. "user input variable
IF sy-subrc EQ 0.
LOOP AT itab INTO wa_itab.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
l_s_range-low = wa_itab-give ur KF name
APPEND l_s_range TO e_t_range.
exit.
ENDLOOP.
ENDIF.
else.
ENDIF.
ENDIF.
ENDIF.
Like this populate for all variables (all the KFs).