‎2007 Sep 24 8:19 PM
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.
‎2007 Sep 24 8:23 PM
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.
‎2007 Sep 24 8:24 PM
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.
‎2007 Sep 24 8:26 PM
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
‎2007 Sep 24 8:29 PM
Your code appears to be OK other than the fact that it may time out. What problem do you have?
Rob
‎2007 Sep 24 8:42 PM
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.
‎2007 Sep 24 8:44 PM
‎2007 Sep 24 8:45 PM
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
‎2007 Sep 24 9:13 PM
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.
‎2007 Sep 24 9:15 PM
‎2007 Sep 24 9:15 PM
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.
‎2008 Feb 22 9:08 PM