02-09-2009 2:21 PM
Hi,
I am trying to create a BAPI that should retrieve a customer list. This Bapi should accept empty parameters in order to select a range of customers. This Bapi should accept wildcards * in the search like a ABAP program. But right now i only can retrieve some significant values if all the parameters are filled.
Am i doing something wrong? I know this is a basic request but it is my first BAPI.
The code is:
FUNCTION ZBAPI_CLIENTE.
*"----
-
""Interface local:
*" IMPORTING
*" VALUE(KUNNR) LIKE KNA1-KUNNR OPTIONAL
*" VALUE(STCEG) LIKE KNA1-STCEG OPTIONAL
*" VALUE(NAME1) LIKE KNA1-NAME1 OPTIONAL
*" VALUE(NAME2) LIKE KNA1-NAME2 OPTIONAL
*" VALUE(VTWEG) LIKE KNVV-VTWEG
*" EXPORTING
*" VALUE(RETURN) LIKE BAPIRETURN STRUCTURE BAPIRETURN
*" TABLES
*" ZITEMDATA STRUCTURE ZBAPICLIENTES
*"----
-
tables: kna1, knvv.
data: cli like kna1-kunnr.
data: nct like kna1-stceg.
data: nm1 like kna1-name1.
data: nm2 like kna1-name2.
cli = kunnr.
nct = stceg.
nm1 = name1.
nm2 = name2.
select * from kna1 where kunnr = cli and stceg = nct and name1 =
nm1 and name2 = nm2.
*select * from kna1 where kunnr = cli.
select * from knvv where kunnr = kna1-kunnr and vkorg = 'MR01' and
vtweg = vtweg and spart = '00'.
move kna1-kunnr to ZITEMDATA-kunnr.
move kna1-stceg to ZITEMDATA-stceg.
move kna1-name1 to ZITEMDATA-name1.
move kna1-name2 to ZITEMDATA-name2.
move knvv-vtweg to ZITEMDATA-vtweg.
append zitemdata.
endselect.
endselect.
ENDFUNCTION.
Can someone help me?
Thanks in advance
Best Regards
João Fernandes
02-09-2009 2:29 PM
Hi,
Firstly the FM should be Remote Enabled (Set the Attributes) in se37. and if u don't provide any values then it will display all the records.
Follow the Steps for BAPI Creation Carefully.
Thanks
Ravi
02-09-2009 3:15 PM
Hi,
The bapi is set for remote enabling.
Best Regards
João Fernandes
02-09-2009 10:29 PM
First of all, please use Code tags when posting the code.
Have you tried your code in a stand-alone report? I bet it won't work either. Wildcards work only with ranges or selection options, but in your SELECT you're looking for an exact match (=).
Instead of using CLI variable of the same type (which doesn't make any sense, by the way), make it a range table for KUNNR. See ABAP Help for TYPES - RANGE OF. Another option (might be a better one) is to use a table instead of a single KUNNR value to pass the data to BAPI.