cancel
Showing results for 
Search instead for 
Did you mean: 

NCo 3.0 BAPI commit without return parameters

CSonek
Discoverer
0 Kudos

Hi all,

I'm using the NCo 3.0 Connector to call BAPI Methods.

Unfortunately I don't get any return parameters when I use a RfcTransaction with the Commit function:

RfcDestination destination

fu = destination.Repository.CreateFunction("BAPI_CUSTOMER_CREATEFROMDATA1")

RfcTransaction transaction

transaction.AddFunction(fu);

transaction.Commit(destination)

string message = fu.GetStructure("RETURN").GetString("MESSAGE");

Message is empty

When I'm calling the Function without transaction, the BAPI method returns a message.

fu.Invoke(destination);

string message = fu.GetStructure("RETURN").GetString("MESSAGE");

Message: Make an entry in all fields where required

How can I use the NCo Connector to commit BAPI methods and get return parameters?

Regards,

Christian

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hello - I am having this problem too. Did you find a solution?

Thanks,

Alan

Former Member
0 Kudos

Hello Alan,

I've tested the calling of different BAPI methods, but there are no return tables available.

It seems that NCo does not support the Standardized BAPI concept, which includes export and table

parameters.

Christian

ronny_schneider
Explorer
0 Kudos

Hi,

I just build my first little app using the NCo3. There are some known things from NCo2 and BizTalk adapter in. I have not tested the following sample, because I used the QIRF function modules and as you may know there is a special commit function module (without any parameters too) in this function pool. I changed my sample for your problem with the function module BAPI_CUSTOMER_CREATEFROMDATA1:

namespace WindowsFormsApplication3
{ 
   public partial class Form1 : Form
   {
        public Form1()
        {
            InitializeComponent();
            RfcDestinationManager.RegisterDestinationConfiguration(new MyBackendConfig());
        }
        private void button1_Click(object sender, EventArgs e)
        {
            RfcDestination dest = RfcDestinationManager.GetDestination("RFC_000");

            try
            {
                RfcRepository repo = dest.Repository;

                //Get Functions from SAP
                IRfcFunction customerCreate = repo.CreateFunction("BAPI_CUSTOMER_CREATEFROMDATA1");
                IRfcFunction bapiCommit = repo.CreateFunction("BAPI_TRANSACTION_COMMIT");

                //Get Import Structure from SAP 
                //the following structures in IMPORT section of BAPI_CUSTOMER_CREATEFROMDATA1
                // are required: PI_PERSONALDATA and PI_COPYREFERENCE (not optional)
                IRfcStructure importPersonalData = customerCreate.GetStructure("PI_PERSONALDATA");
                IRfcStructure importCopyReference = customerCreate.GetStructure("PI_COPYREFERENCE");

                for (int i = 0; i < importPersonalData.Metadata.FieldCount; i++)
                {
                    if (importPersonalData.Metadata<i>.Name == "TITLE_P")
                    {
                        importPersonalData.SetValue(i, "Prof.Dr.");
                    }
                    if (importPersonalData.Metadata<i>.Name == "FIRSTNAME")
                    {
                        importPersonalData.SetValue(i, "User");
                    }
                    if (importPersonalData.Metadata<i>.Name == "MIDDLENAME")
                    {
                        importPersonalData.SetValue(i, "I.D.");
                    }
                    if (importPersonalData.Metadata<i>.Name == "LASTNAME")
                    {
                        importPersonalData.SetValue(i, "Fix");
                    }
                }
                customerCreate.SetValue("PI_PERSONALDATA", importPersonalData);

                //do the same for PI_COPYREFERENCE
                for (int i = 0; i < importCopyReference.Metadata.FieldCount; i++)
                {
                    //fill the required fields of PI_COPYREFERENCE
                    //guess it's possible to add an empty PI_COPYREFERENCE without values in the fields like in BizTalk adapter
                    //but have not tested yet
                    //that means: don't use that "for (int i = 0; i < importPersonalData.Metadata.FieldCount; i++)"
                    //just write "customerCreate.SetValue("PI_COPYREFERENCE", importCopyReference);"
                }

                customerCreate.SetValue("PI_COPYREFERENCE", importCopyReference);

                //open a stateful call (in NCo 2.0 it was called Session Context)
                //open session with BeginContext
                RfcSessionManager.BeginContext(dest);
                customerCreate.Invoke(dest);
                //the commit has to be sent within the same context as the BAPI invoke!!!
                bapiCommit.Invoke(dest);
                //open session with EndContext
                RfcSessionManager.EndContext(dest);
            }
            catch (RfcCommunicationException rfcCommEx)
            {
                tBox3.Text = rfcCommEx.Message.ToString();
            }
            catch (RfcLogonException rfcLogonEx)
            {
                tBox3.Text = rfcLogonEx.Message.ToString();
            }
            catch (RfcAbapRuntimeException rfcAbapRuntimeEx)
            {
                tBox3.Text = rfcAbapRuntimeEx.Message.ToString();
            }
            catch (RfcAbapBaseException rfcAbapBaseEx)
            {
                if (rfcAbapBaseEx.Message.ToString() == String.Empty)
                {
                    //to read the ABAP Exception cast RfcAbapBaseException that way :)
                    tBox3.Text = ((SAP.Middleware.Connector.RfcAbapClassicException)(rfcAbapBaseEx)).Key.ToString();
                }
                else
                {
                    tBox3.Text = rfcAbapBaseEx.Message.ToString();
                }
            }
        }
    }

I tried to comment the important parts. If you have some questions let me know. How to work with response tables I have not implemented yet.

regards

Ronny

ronny_schneider
Explorer
0 Kudos

I forgot:

Christian, you got the message

Make an entry in all fields where required

because you did not pay attention to the required import parameters of the function module BAPI_CUSTOMER_CREATEFROMDATA1. (not marked as optional)

ronny_schneider
Explorer
0 Kudos

If you want to work with tables, just use this code after the function module invoke:

IRfcTable table = customerCreate.GetTable("TABLE");

Former Member
0 Kudos

Thanks Ronny, your solution works

Answers (0)