Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Function module - Urgent

Former Member
0 Kudos

Hi Friends,

I have a statement as below in one function module :

SELECT a~matnr

INTO TABLE t_mast

FROM mast AS a

INNER JOIN stko AS k

ON astlnr EQ kstlnr

AND astlal EQ kstlal

WHERE a~werks eq plant

AND a~stlal eq alt

AND k~datuv EQ date .

Import parameters are : Plant , Alt and Date.

Here the problem is while I am executing the f/m it is giving the correct values only if input all the input parameters Plant,Alt and Date.If I give Plant and Alt as blank then it is not giving any values from the table.

Could you please telme the resolution for this.

Regards,

Vishnu.

If I am not

9 REPLIES 9

Former Member
0 Kudos

Hi,

Check before the select if plant or alt or date is initial and then put in where clause only the informed parameters.

Regards.

Mireia

naimesh_patel
Active Contributor
0 Kudos

You can overcome from this problem by using the RANGES.

Like:

ranges: r_alt for mast-stlal,
        r_date for stko-datuv,
        r_plant for mast-werks.
        
if not alt is initial.        
r_alt-sign = 'I'.
r_alt-option = 'EQ'.
r_alt-low = alt.
append r_alt.        
endif.

if not date is initial.        
r_date-sign = 'I'.
r_date-option = 'EQ'.
r_date-low = date.
append r_date.        
endif.

if not plant is initial.        
r_plant-sign = 'I'.
r_plant-option = 'EQ'.
r_plant-low = plant.
append r_plant.
endif.

SELECT a~matnr
INTO TABLE t_mast
FROM mast AS a
INNER JOIN stko AS k
ON a~stlnr EQ k~stlnr
AND a~stlal EQ k~stlal
WHERE a~werks in r_plant
AND a~stlal in r_alt
AND k~datuv in r_date.

Regards,

Naimesh Patel

0 Kudos

Hi Naimesh,

Thanks a lot.But what is the reason for this.Because if i run a report with the same statement it works.But why is not working in a fm.If I am not entereing any value for Plant,Alt or date why it is not getting the data where it is supposed to get the entire data.

Regards,

Vishnu.

0 Kudos

Hi again,

Are you sure that in the fm the parameters don't have any value? I mean any space or something?

If the select in the report works, it should also work in the fm....

Mireia

0 Kudos

Because you don't have any entry with the BLANK plant, alt and date. When you exectue this query without entring any data in these fields system tries to find out the data as BLANK and it could not find it.

System tries to select the data with the BLANK becasuse you have used the EQ operator in the where clause. IF you use the IN caluse than it will work and you can use the IN caluse only with the ranges or select options. So, If you change as per my directions you will get the data even if you don't put any thing.

Regards,

Naimesh Patel

0 Kudos

Yes it is working Naimesh .But when we use parameters in a report and if we give eq operator it works rite?Also is it the only way to get the data by using ranges in case of function modules or is there any other way? I mean is it the general way to do..

Regards,

Vishnu.

0 Kudos

It is working in the report because we put OBLIGATORY which forces use to put the values on the selection screen.

You can use some predefined ranges table types in the FM's Import parameter.

Like for

PLNAT you can use RANGE_T_WERKS_D

If it not avalible you can create on your own by SE11. Take the reference as RANGE_T_WERKS_D.

Regards,

Naimesh Patel

Former Member
0 Kudos

Change your code to:

SELECT a~matnr
INTO TABLE t_mast
FROM mast AS a
INNER JOIN stko AS k
ON a~stlnr EQ k~stlnr
AND a~stlal EQ k~stlal
WHERE a~werks IN plant     "Here
AND a~stlal IN alt     "Here
AND k~datuv IN date .     "Here

Regards

Aneesh.

0 Kudos

Hi Aneesh,

My input values Plant,Alt and Date are single values not range of values.Is it possible to give range of values in import parameters.If so please explain me how to declare.

Vishnu