Application Development and Automation 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: 
Read only

Problem in Function Module.

Former Member
0 Likes
1,136

Hi,

I developed a Functional Module.The requirement is

(1) I should extract data from Table BKPF based on screen inputs BELNR,BUKRS etc

(2) then I shud extract data from BSEG for all entries in IT_bkpf.

the problem is there are 4 parameters and alla re optional.Even if i dont populate 1 parameter the code returns me a null value.I want this to work like select option in a report.if dont populate any value it should avoid the parameter from selection criteria.

I also tried defining select option tables for all my parameters but still its not working.I have attached my code.Please help me find a solution.

FUNCTION Z_NEW_FUNC.

*"----


""Local interface:

*" IMPORTING

*" REFERENCE(P_BUKRS) TYPE BKPF-BUKRS OPTIONAL

*" REFERENCE(P_BELNR) TYPE BKPF-BELNR OPTIONAL

*" REFERENCE(P_GJAHR) TYPE BKPF-GJAHR OPTIONAL

*" REFERENCE(P_CPUDT) TYPE BKPF-CPUDT OPTIONAL

*" REFERENCE(P_CPUTM) TYPE BKPF-CPUTM OPTIONAL

*" TABLES

*" IT_RESULT STRUCTURE BSEG OPTIONAL

*"----


TYPES : BEGIN OF T_BKPF,

BUKRS type BKPF-BUKRS,

BELNR type BKPF-BELNR,

GJAHR type BKPF-GJAHR,

CPUDT type BKPF-CPUDT,

CPUTM type BKPF-CPUTM,

END OF T_BKPF.

DATA: s_Bukrs TYPE RANGE OF BKPF-bukrs,

s_Bukrs_wa LIKE LINE OF s_Bukrs.

if not p_bukrs is initial.

s_Bukrs_wa-sign = 'I'.

s_Bukrs_wa-option = 'EQ'.

s_Bukrs_wa-low = P_BUKRS.

APPEND s_Bukrs_wa TO s_Bukrs.

endif.

DATA: s_BELNR TYPE RANGE OF BKPF-BELNR,

s_BELNR_wa LIKE LINE OF s_BELNR.

if not p_belnr is initial.

s_BELNR_wa-sign = 'I'.

s_BELNR_wa-option = 'EQ'.

s_BELNR_wa-low = P_BELNR.

APPEND s_BELNR_wa TO s_BELNR.

endif.

DATA: s_GJAHR TYPE RANGE OF BKPF-GJAHR,

s_GJAHR_wa LIKE LINE OF s_GJAHR.

if not p_gjahr is initial.

s_GJAHR_wa-sign = 'I'.

s_GJAHR_wa-option = 'EQ'.

s_GJAHR_wa-low = P_GJAHR.

APPEND s_GJAHR_wa TO s_GJAHR.

endif.

DATA: s_CPUDT TYPE RANGE OF BKPF-CPUDT,

s_CPUDT_wa LIKE LINE OF s_CPUDT.

if not p_cpudt is initial.

s_CPUDT_wa-sign = 'I'.

s_CPUDT_wa-option = 'EQ'.

s_CPUDT_wa-low = P_CPUDT.

APPEND s_CPUDT_wa TO s_CPUDT.

endif.

DATA: s_CPUTM TYPE RANGE OF BKPF-CPUTM,

s_CPUTM_wa LIKE LINE OF s_CPUTM.

if not p_cputm is initial.

s_CPUTM_wa-sign = 'I'.

s_CPUTM_wa-option = 'EQ'.

s_CPUTM_wa-low = P_CPUTM.

APPEND s_CPUTM_wa TO s_CPUTM.

endif.

DATA : IT_BKPF TYPE STANDARD TABLE OF T_BKPF WITH HEADER LINE.

SELECT BUKRS

BELNR

GJAHR

BUDAT

FROM BKPF

INTO TABLE IT_BKPF

WHERE BUKRS IN s_BUKRS

AND BELNR IN s_BELNR

AND GJAHR IN S_GJAHR

AND CPUDT IN S_CPUDT

AND CPUTM IN S_CPUTM.

IF NOT IT_BKPF[] IS INITIAL.

SELECT * FROM BSEG INTO TABLE IT_RESULT

FOR ALL ENTRIES IN IT_BKPF WHERE BUKRS = IT_BKPF-BUKRS

AND BELNR = IT_BKPF-BELNR

AND GJAHR = IT_BKPF-GJAHR.

ENDIF.

ENDFUNCTION.

11 REPLIES 11
Read only

Former Member
0 Likes
1,094

Replace this...


s_Bukrs_wa-sign = 'I'.
s_Bukrs_wa-option = 'EQ'.
s_Bukrs_wa-low = P_BUKRS.

With this...


s_Bukrs_wa-sign = 'I'.
s_Bukrs_wa-option = 'BT'.
s_Bukrs_wa-low = P_BUKRS.

Replace all EQ with BT -;)

Greetings,

Blag.

Read only

Former Member
0 Likes
1,094

Can you check once in debug mode. BTW the structure of T_BKPF / IT_BKPF is not matching with fields provided in SELECT BKPF. Check this one too.

Select option ranges are populated correctly for all parameters so do not make any change in that.

Read only

Former Member
0 Likes
1,094

Actually...this should be better...


if not p_bukrs is initial.
s_Bukrs_wa-sign = 'I'.
s_Bukrs_wa-option = 'EQ'.
s_Bukrs_wa-low = P_BUKRS.
else.
s_Bukrs_wa-sign = 'I'.
s_Bukrs_wa-option = 'BT'.
s_Bukrs_wa-low = P_BUKRS.
endif.

APPEND s_Bukrs_wa TO s_Bukrs.

Greetings,

Blag.

Edited by: Alvaro Tejada Galindo on Feb 22, 2008 4:21 PM

Read only

Former Member
0 Likes
1,094

Your code appears to be OK other than the fact that it may time out. What problem do you have?

Rob

Read only

Former Member
0 Likes
1,094

Hi Rob,

As u sed its timed out if say select * from BSEG. even I avoid * and specify specifc fields,when I check in debugger it_bseg does'nt gets any entry.

Read only

0 Likes
1,094

Can you check in debug if you get any entries in IT_BKPF?

Read only

0 Likes
1,094

You can't avoid that if you allow blank parameters for bukrs and belnr. You have to have at least a range of document numbers.

Does it make any sense to retrieve every document in the system??

Rob

Read only

Former Member
0 Likes
1,094

Hi Rob,

Its not that I gonna extract all the documents from the table,But I will extract data based any one of the parameters mentioned ot any two or any three or all the four.The problem is even if dont populate one parameter it considers that to be a blank entry,checks for the same blank entry in the Databese(I guess) and returns me nothing.

Read only

0 Likes
1,094

But the code you posted works.

Rob

Read only

Former Member
0 Likes
1,094

Hi Ashish,

yes.Theres are entries in the IT_BKPF when i checked it in the debugger.But i dont get any entry fo the internal table IT_bseg.

Read only

Former Member
0 Likes
1,094

Thanks Alvaro....

I am clsoing this thread