on 11-10-2014 10:23 PM
All, I'm working on a proof of concept for entering sales order via a .net app. I have most of it working now, but there is one issue. I can't seem to get a value into the customer material number on the sales order. I"m attempting to pass it through CUST_MAT22 in the order details table. Anyone had success getting this to work? Here's my code.
TIA for in help you can provide.
Pat
RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination("Q01");
RfcRepository SapRfcRepository = SapRfcDestination.Repository;
IRfcFunction salesOrderCreate = SapRfcRepository.CreateFunction("BAPI_SALESORDER_CREATEFROMDAT2");
IRfcFunction salesDocCommit = SapRfcRepository.CreateFunction("BAPI_TRANSACTION_COMMIT");
IRfcStructure salesHeader = salesOrderCreate.GetStructure("ORDER_HEADER_IN");
IRfcTable salesItems = salesOrderCreate.GetTable("ORDER_ITEMS_IN");
IRfcTable salesSchedItms = salesOrderCreate.GetTable("ORDER_SCHEDULES_IN");
IRfcTable salesPartners = salesOrderCreate.GetTable("ORDER_PARTNERS");
IRfcTable OrderKeys = salesOrderCreate.GetTable("ORDER_KEYS");
IRfcTable salesItemsX = salesOrderCreate.GetTable("ORDER_ITEMS_INX");
IRfcTable orderConditions = salesOrderCreate.GetTable("ORDER_CONDITIONS_IN");
IRfcStructure salesItemsStruct = salesItems.Metadata.LineType.CreateStructure();
IRfcStructure salesPartnersStruct = salesPartners.Metadata.LineType.CreateStructure();
IRfcStructure salesPartnersStructRow2 = salesPartners.Metadata.LineType.CreateStructure();
IRfcStructure salesSchedItmStruct = salesSchedItms.Metadata.LineType.CreateStructure();
IRfcStructure salesItemsStructX = salesItemsX.Metadata.LineType.CreateStructure();
IRfcStructure orderConditionsStruct = orderConditions.Metadata.LineType.CreateStructure();
//Sales Header
salesHeader.SetValue("DOC_TYPE", "TA");
salesHeader.SetValue("SALES_ORG", "1000");
salesHeader.SetValue("DISTR_CHAN", "10");
salesHeader.SetValue("DIVISION", "01");
salesHeader.SetValue("SALES_OFF", "1000");
salesHeader.SetValue("PURCH_NO_C", "RFC_TEST1");
salesHeader.SetValue("REQ_DATE_H", DateTime.Today.AddMonths(3).ToString("yyyyMMdd"));
//Sales Items
salesItemsStructX.SetValue("ITM_NUMBER", "10");
//salesItemsStructX.SetValue("UPDATEFLAG", "X");
salesItemsStructX.SetValue("PLANT", "X");
salesItemsStructX.SetValue("MATERIAL", "X");
salesItemsStructX.SetValue("CUST_MAT22", "X");
salesItemsStructX.SetValue("TARGET_QTY", "X");
salesItemsX.Append(salesItemsX);
salesItemsStruct.SetValue("ITM_NUMBER", "10");
salesItemsStruct.SetValue("PLANT", "1000");
salesItemsStruct.SetValue("MATERIAL", "STL72RB");
salesItemsStruct.SetValue("CUST_MAT22", "STL72RB"); //marked as obsolete
salesItemsStruct.SetValue("TARGET_QTY", "200");
salesItems.Append(salesItemsStruct);
//SChedule Line Items
salesSchedItmStruct.SetValue("ITM_NUMBER", "10");
salesSchedItmStruct.SetValue("REQ_QTY", "200");
salesSchedItmStruct.SetValue("REQ_DATE", DateTime.Today.AddMonths(3).ToString("yyyyMMdd"));
salesSchedItms.Append(salesSchedItmStruct);
//Add conditions / EDI1 price for customer expected price
orderConditionsStruct.SetValue("ITM_NUMBER", "10");
orderConditionsStruct.SetValue("COND_TYPE", "EDI2");
orderConditionsStruct.SetValue("COND_VALUE", 7.83 / 10); //divide by 10 required for converstion
orderConditions.Append(orderConditionsStruct);
// Partner - can also add addresses if present. THe added address will override SAP address.
salesPartnersStruct.SetValue("PARTN_ROLE", "AG");
salesPartnersStruct.SetValue("PARTN_NUMB", "0001002931");
salesPartners.Append(salesPartnersStruct);
salesPartnersStruct.SetValue("PARTN_ROLE", "WE");
salesPartnersStruct.SetValue("PARTN_NUMB", "0001002931");
salesPartners.Append(salesPartnersStruct);
//start confirmation processing set context so transactions use one thread to ensure success for commit
IRfcTable RfcReturn = salesOrderCreate.GetTable("RETURN");
RfcSessionManager.BeginContext(SapRfcDestination); //make stateful connection instead of stateless
salesOrderCreate.Invoke(SapRfcDestination);
switch ( RfcReturn.GetValue("TYPE").ToString())
{
case "E":
Console.WriteLine("ERROR: " + RfcReturn.GetValue("MESSAGE").ToString());
break;
case "S":
salesDocCommit.Invoke(SapRfcDestination);
Console.WriteLine("Saved order number: " + OrderKeys[0].GetValue("DOC_NUMBER"));
break;
case "I":
salesDocCommit.Invoke(SapRfcDestination);
Console.WriteLine("Saved order number: " + OrderKeys[0].GetValue("DOC_NUMBER"));
break;
}
RfcSessionManager.EndContext(SapRfcDestination);
Found the solution. Used CUST_MAT35 and it works beautifully. Maybe this can help someone else.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.