cancel
Showing results for 
Search instead for 
Did you mean: 

.Net Connector 3.0: change SO via BAPI_SALESORDER_CHANGE

Former Member
0 Kudos

Hi folks,

Huge number of questions were been asked about FM BAPI_SALESORDER_CHANGE.

Nevertheless, still I cannot solve my issue with changes in existing Sales Order by using .NET Connector 3.0.

I have a good working sample of how I'm changing SO Header data:

public DataTable BAPI_SALESORDER_CHANGE(RfcDestination destination)
{
  
RfcRepository repo = destination.Repository;
  
IRfcFunction salesDoc = repo.CreateFunction("BAPI_SALESORDER_CHANGE");
  
IRfcFunction salesDocCommit = repo.CreateFunction("BAPI_TRANSACTION_COMMIT");
   salesDoc
.SetValue("SALESDOCUMENT", "3939393837");

  
IRfcStructure salesHeader = salesDoc.GetStructure("ORDER_HEADER_IN");
   salesHeader
.SetValue("PURCH_NO_C", "Order_01");
  
IRfcStructure salesHeaderINX = salesDoc.GetStructure("ORDER_HEADER_INX");
   salesHeaderINX
.SetValue("UPDATEFLAG", "U");
   salesHeaderINX
.SetValue("PURCH_NO_C", "X");

  
RfcSessionManager.BeginContext(destination);
   salesDoc
.Invoke(destination);
   salesDocCommit
.Invoke(destination);
  
RfcSessionManager.EndContext(destination);

  
IRfcTable returnTable = salesDoc.GetTable("RETURN");

  
return ConvertToDataTable(returnTable);  
}


It is works perfect, customer PO number has been changed successfully.

Now I'm doing the same, but would like to add new item to Sales Order:

public DataTable BAPI_SALESORDER_CHANGE(RfcDestination destination)
{
   RfcRepository repo = destination.Repository;
  
IRfcFunction salesDoc = repo.CreateFunction("BAPI_SALESORDER_CHANGE");
  
IRfcFunction salesDocCommit = repo.CreateFunction("BAPI_TRANSACTION_COMMIT");
   salesDoc
.SetValue("SALESDOCUMENT", "3939393837");



  
IRfcStructure salesHeader = salesDoc.GetStructure("ORDER_HEADER_IN");
  
IRfcStructure salesHeaderINX = salesDoc.GetStructure("ORDER_HEADER_INX");
   salesHeaderINX
.SetValue("UPDATEFLAG", "U");

  
IRfcTable salesItems = salesDoc.GetTable("ORDER_ITEM_IN");
   salesItems
.Append();
   salesItems
.SetValue("ITM_NUMBER", 130);
   salesItems
.SetValue("MATERIAL", "000000000081828282");
   salesItems
.SetValue("TARGET_QTY", Convert.ToDecimal("1"));
  
IRfcTable salesItemsINX = salesDoc.GetTable("ORDER_ITEM_INX");
   salesItemsINX
.Append();
   salesItemsINX
.SetValue("UPDATEFLAG", "I");
   salesItemsINX
.SetValue("ITM_NUMBER", 130);
   salesItemsINX
.SetValue("MATERIAL", "X");
   salesItemsINX
.SetValue("TARGET_QTY", "X");
   RfcSessionManager.BeginContext(destination);
   salesDoc
.Invoke(destination); //HERE I'M GETTING ERROR
   salesDocCommit
.Invoke(destination);
  
RfcSessionManager.EndContext(destination);

  
IRfcTable returnTable = salesDoc.GetTable("RETURN");

  
return ConvertToDataTable(returnTable);

}

In this case I'm getting error "Screen output without connection to user" on invoke method calling. How to avoid this isse?

Can someone provide which fields needs to be flilled to add new item to sales order?

What I'm doing wrong?

Let me know if you need more info.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I found key for my issue. It is DYNPRO_SEND_IN_BACKGROUND error.

Alos I found old interesting thread regarding this

When I'm trying to add new item to Sales Order system is trying to call dialog/window, but this is not allowed without SAPGUI. I assume this dialog is "reason code" widow I have to enter when I'm trying to save my sales order:



As per investigation I provided above, most RFCs support flags for "dark" processing without user interaction (and creating visual "objects").


Does BAPI_SALESORDER_CHANGE FM has such flag?

Also what is NOBINPT='X parameter? Where can I set it?

Are there other ways how to avoid dialog calling?

hynek_petrak
Active Participant
0 Kudos

Does the dialog pop up, if you call the FM via SE37?

If you look into the source code of the BAPI_SALESORDER_CHANGE, suppressing the dialog is the very first action:


* 00. BAPIs run without dialog, set the flag

  CALL FUNCTION 'DIALOG_SET_NO_DIALOG'.

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

in case Hynek's suggestion to suppress the dialog is not an option in your case, you can add RfcConfigParameters.UseSAPGui (USE_SAPGUI in app.config) with the value RfcConfigParameters.RfcUseSAPGui.Hidden (2) or RfcConfigParameters.RfcUseSAPGui.Use (1). Then, a SAPGui will be started when opening a connection. This certainly requires a SAPGui to be started on the same system, on which the NCo application is running.

Best regards,

Markus

Former Member
0 Kudos

Hi Hynek, thanks for reply.

Unfortunatelly, do not have access to SM37 to check if FM is triggering dialog.

Will try to ask our administrators to check it. But very strange if FM is alredy contain dialogs preventing function but issue is still appearing.

Are there any workarounds assuming SM37 is also returning dialogs?

hynek_petrak
Active Participant
0 Kudos

Hi Mikhail,

actually I'm not an experienced ABAPer, therefore I can imagine someone from user exit to call up a pop up window, ignoring the fact that it's being called from BAPI. Which shall be considered as a bug.

Therefore I've been suggesting simulating via SE37 in order to identify the server response.

In your case enabling UseSAPGui as suggested by Marcus is even easier.

Once you identify the returning dialog, either you provide the required data or you look for the workaround. Not sure if ignoring the response by default is a good thing.

Former Member
0 Kudos

Hi Marcus, thanks!

This is almost exactly what I'm looking for.


I did as you suggested


RfcConfigParameters rfc = new RfcConfigParameters();

...

rfc.Add(RfcConfigParameters.UseSAPGui, "2"); //hidden mode


DYNPRO_SEND_IN_BACKGROUND issue has dissapeared

And now I'm proposing to enter reason code in dialog window which appears over my .Net application.

Once reson code is entered -> I'm getting successfull result:



Is there way how to easily put reason code automatically to avoid user manual interventions there? In case of any obvious ideas, please, let me know.

However, even with such solution I'm fully satisfied at the moment.


MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Mikhail,

there is no generic way to automatically choose a value. Actually, this is function module implementation sepcific and if it was possible to suppress the dialog, there would be an option to define this value. But for that one has to look closer at the source code of that BAPI.

Best regards,

Markus

Answers (0)