I need to search customers in SAP system from a C# application. I'm using C# .NET connector.
I tried to call the BAPI BAPI_CUSTOMER_FIND
to get all the customers with name that starts with "C" character, this is my code:
SAPConnectionConfigurator cfg = new SAPConnectionConfigurator();
RfcDestinationManager.RegisterDestinationConfiguration(cfg);
RfcDestination dest = RfcDestinationManager.GetDestination("mySAPdestination");
RfcRepository repo = dest.Repository;
IRfcFunction customerList = repo.CreateFunction("BAPI_CUSTOMER_FIND");
customerList.SetValue("MAX_CNT", "100");
IRfcTable searchFields = customerList.GetTable("SELOPT_TAB");
searchFields.Insert();
searchFields.CurrentRow.SetValue("COMP_CODE", "");
searchFields.CurrentRow.SetValue("TABNAME", "KNA1");
searchFields.CurrentRow.SetValue("FIELDNAME", "NAME1");
searchFields.CurrentRow.SetValue("FIELDVALUE", "C*");
customerList.Invoke(dest);
IRfcTable results = customerList.GetTable("RESULT_TAB");
The call works correctly but I don't know how to read the result. I need a list of customers but the RESULT_TAB
table has this strange structure:
comp_code bukrs char(4) Company Code
tabname tabname char(30) Table Name
fieldname fieldname char(30) Field Name
fieldvalue fieldvalue char(132) Field value
customer kunnr char(10) Customer Number
pstg_blk_g sperb_x char(1) Central posting block
pstg_blk_c sperb_b char(1) Posting block for company code
del_flag_g loevm_x char(1) Central Deletion Flag for Master Record
del_flag_c loevm_b char(1) Deletion Flag for Master Record (Company Code Level)
type bapi_mtype char(1) Message type: S Success, E Error, W Warning, I Info, A Abort
id symsgid char(20) Message Class
number symsgno numc(3) Message Number
message bapi_msg char(220) Message Text
log_no balognr char(20) Application Log: Log Number
log_msg_no balmnr numc(6) Application Log: Internal Message Serial Number
message_v1 symsgv char(50) Message Variable
message_v2 symsgv char(50) Message Variable
message_v3 symsgv char(50) Message Variable
message_v4 symsgv char(50) Message Variable
How can I get customers list? Am I calling the wrong BAPI?