0

Friends. I'm currently consuming BAPI_CUSTOMER_GETCONTACTLIST. I've used any Z* one created by abappers or by me.

I code in C# vb. 2010. My question about that BAPI is that I currently see 2 tables, one with the parameters and another with the result.

So far I thing I've managed to fill the one with parameters, but I dont know how to retrieve the information of the resulting table.

I've searched through the internet with no answer. I don't know if I'm doing it right or wrong. :P

Thanks.

This is my code:

String include = "I", rango = "EQ";// EQ - BT -- Equal o Between
DataTable dt = new DataTable("ws_clientes_contactos");

dt.Columns.Add("PARTNEREMPLOYEEID", typeof(String));
dt.Columns.Add("CUSTOMER", typeof(String));
dt.Columns.Add("LASTNAME", typeof(String));
dt.Columns.Add("FIRSTNAME", typeof(String));
dt.Columns.Add("SEX", typeof(String));
dt.Columns.Add("TITLE_P", typeof(String));
dt.Columns.Add("LANGU_P", typeof(String));
dt.Columns.Add("LANGUP_ISO", typeof(String));
dt.Columns.Add("COUNTRY", typeof(String));
dt.Columns.Add("COUNTRYISO", typeof(String));
dt.Columns.Add("CITY", typeof(String));
dt.Columns.Add("POSTL_COD1", typeof(String));
dt.Columns.Add("REGION", typeof(String));
dt.Columns.Add("STREET", typeof(String));
dt.Columns.Add("TEL1_NUMBR", typeof(String));
dt.Columns.Add("FAX_NUMBER", typeof(String));
dt.Columns.Add("FUNCTION", typeof(String));
dt.Columns.Add("SORT1_P", typeof(String));
dt.Columns.Add("ADDRESS", typeof(String));
dt.Columns.Add("PERS_NO", typeof(String));
dt.Columns.Add("E_MAIL", typeof(String));

try
{

    RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination("DEV");
    RfcRepository SapRfcRepository = SapRfcDestination.Repository;
    IRfcFunction bapigetcontactlist = SapRfcRepository.CreateFunction("BAPI_CUSTOMER_GETCONTACTLIST");

    IRfcTable CUSTOMERRANGE, CONTACTADDRESSDATA;
    CUSTOMERRANGE = bapigetcontactlist.GetTable("CUSTOMERRANGE");

      //LLENA TABLA FILTROS DE LA BAPI

    if (Opc == "B")
    {
        rango = "BT";
    }

    CUSTOMERRANGE.Append();
    CUSTOMERRANGE.SetValue("SIGN", include);
    CUSTOMERRANGE.SetValue("OPTION", rango);
    CUSTOMERRANGE.SetValue("LOW", ClienteMin);

    if (Opc == "B")  // BETWEEEN
    {
        CUSTOMERRANGE.SetValue("HIGH", ClienteMax);
    }
    else // EQUAL = LWO 
    {
        CUSTOMERRANGE.SetValue("HIGH", " ");
    }

    bapigetcontactlist.SetValue("MAXROWS", 1000);

    //DataTable dtt = CreateDataTable(CUSTOMERRANGE);
    bapigetcontactlist.SetValue("CUSTOMERRANGE", CUSTOMERRANGE);
    CONTACTADDRESSDATA = bapigetcontactlist.GetTable("CONTACTADDRESSDATA");

    bapigetcontactlist.Invoke(SapRfcDestination);

    IRfcTable Result = bapigetcontactlist["CONTACTADDRESSDATA"].GetTable();
    
    for (Int16 i = 0; i < (Result.RowCount); i++)
    {
        DataRow dr = dt.NewRow();

        dr["PARTNEREMPLOYEEID"] = CONTACTADDRESSDATA[i].GetString(0);
        dr["CUSTOMER"] = CONTACTADDRESSDATA[i].GetString(1);
        dr["LASTNAME"] = CONTACTADDRESSDATA[i].GetString(2);
        dr["FIRSTNAME"] = CONTACTADDRESSDATA[i].GetString(3);
        dr["SEX"] = CONTACTADDRESSDATA[i].GetString(4);
        dr["TITLE_P"] = CONTACTADDRESSDATA[i].GetString(5);
        dr["LANGU_P"] = CONTACTADDRESSDATA[i].GetString(6);
        dr["LANGUP_ISO"] = CONTACTADDRESSDATA[i].GetString(7);
        dr["COUNTRY"] = CONTACTADDRESSDATA[i].GetString(08);
        dr["COUNTRYISO"] = CONTACTADDRESSDATA[i].GetString(9);
        dr["CITY"] = CONTACTADDRESSDATA[i].GetString(10);
        dr["POSTL_COD1"] = CONTACTADDRESSDATA[i].GetString(11);
        dr["REGION"] = CONTACTADDRESSDATA[i].GetString(12);
        dr["STREET"] = CONTACTADDRESSDATA[i].GetString(13);
        dr["TEL1_NUMBR"] = CONTACTADDRESSDATA[i].GetString(14);
        dr["FAX_NUMBER"] = CONTACTADDRESSDATA[i].GetString(15);
        dr["FUNCTION"] = CONTACTADDRESSDATA[i].GetString(16);
        dr["SORT1_P"] = CONTACTADDRESSDATA[i].GetString(17);
        dr["ADDRESS"] = CONTACTADDRESSDATA[i].GetString(18);
        dr["PERS_NO"] = CONTACTADDRESSDATA[i].GetString(19);
        dr["E_MAIL"] = CONTACTADDRESSDATA[i].GetString(20);


        dt.Rows.Add(dr);
    }
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • Seems to me that you properly invoke the function. What are the values of 'ClienteMin' and 'ClienteMax'? Maybe the parameters are wrong. Have you checked this [link](http://stackoverflow.com/questions/5300049/step-by-step-tutorial-to-use-sap-net-connector-with-vs-2008). – Nelson Miranda Mar 03 '16 at 22:40
  • those are Customer Codes, respectively Min and Max, that go as parameters on the BAPI. Example: 1027810 – Mario Rafael Tejada Mar 03 '16 at 23:58

2 Answers2

0

Well, I've never used a SAP Connector (I don't have it installed neither) but I'll try to answer your question;

I see in your code that you are trying to return the resulting datatable in 'CONTACTADDRESSDATA' however you haven't yet invoked the function 'BAPI_CUSTOMER_GETCONTACTLIST', so I think is empty.

Then you invoke the BAPI and store the resulting dataset in the variable IRfcTable 'Result'.

After that you try to read 'CONTACTADDRESSDATA' but, as I already pointed out, it's empty.

bapigetcontactlist.SetValue("CUSTOMERRANGE", CUSTOMERRANGE); // Context

CONTACTADDRESSDATA = bapigetcontactlist.GetTable("CONTACTADDRESSDATA"); // Here you try to get the datatable.

bapigetcontactlist.Invoke(SapRfcDestination); // Then you invoke the function

IRfcTable Result = bapigetcontactlist["CONTACTADDRESSDATA"].GetTable(); // The datatable you're trying to read is set here.

for (Int16 i = 0; i < (Result.RowCount); i++)
{
  DataRow dr = dt.NewRow();
  dr["PARTNEREMPLOYEEID"] = CONTACTADDRESSDATA[i].GetString(0); // Try to replace 'CONTACTADDRESSDATA' with 'Result'
  dr["CUSTOMER"] = CONTACTADDRESSDATA[i].GetString(1);

I analyzed your code based on this question.

Hope it helps.

Community
  • 1
  • 1
Nelson Miranda
  • 5,484
  • 5
  • 33
  • 54
0

I Finally found what was happening. When I executed the BAPI on SAP, I just wrote the Customer Code. Without the Left pad 000.

But when I Called it i just Needed to add the Zeros to the Customer Code.

          CUSTOMERRANGE.SetValue("LOW", "000" + ClienteMin);
  • I'm glad you could find out how to resolve your issue however the table parameter 'CUSTOMERRANGE' for BAPI 'BAPI_CUSTOMER_GETCONTACTLIST' has a 10 character length for 'LOW' and 'HIGH'. Best regards. – Nelson Miranda Mar 04 '16 at 20:51
  • Yes it was the problem, customer codes i use are only 7 digit codes, but still the bapi needed the 10 Char parameter. it could be a better approach to use something like this: foreach (string i in words) { if (i.Length > 1) { CustomerCode = i.PadLeft(10, '0').ToString(); } } – Mario Rafael Tejada Mar 07 '16 at 14:42
  • Actually you don't need the 'if' statement, my advice is don't use PadLeft, try with i.ToString("0000000000") instead. Internally SAP always store this data padded with zeroes on the left. Best regards. – Nelson Miranda Mar 07 '16 at 16:12