From 549cdf3fa59438bde8ef0fe11a4ccb42baffc14b Mon Sep 17 00:00:00 2001 From: f_compcontrol Date: Mon, 2 Feb 2026 09:46:18 +0100 Subject: [PATCH] First functioning Version at GBS --- .../Standard/SapStandardFunctions.cs | 85 ++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/CompControl.SapFrameworkConnector/Standard/SapStandardFunctions.cs b/CompControl.SapFrameworkConnector/Standard/SapStandardFunctions.cs index 6094110..273dcd2 100644 --- a/CompControl.SapFrameworkConnector/Standard/SapStandardFunctions.cs +++ b/CompControl.SapFrameworkConnector/Standard/SapStandardFunctions.cs @@ -265,7 +265,7 @@ namespace CompControl.SapFrameworkConnector } _log.Debug($"Added {import.GOODSMVT_ITEM.Count} items to GOODSMVT"); _log.Debug(sb.ToString()); - BAPI_GOODSMVT_CREATE_EXPORT export = BAPI_GOODSMVT_CREATE_WithDirectCommit(import); + BAPI_GOODSMVT_CREATE_EXPORT export = ZBAPI_GOODSMVT_CREATE(import); //BAPI_TRANSACTION_COMMIT(); } catch (Exception ex) @@ -1431,6 +1431,89 @@ namespace CompControl.SapFrameworkConnector return export; } + private static BAPI_GOODSMVT_CREATE_EXPORT ZBAPI_GOODSMVT_CREATE(BAPI_GOODSMVT_CREATE_IMPORT import) + { + string errorMsg = ""; + BAPI_GOODSMVT_CREATE_EXPORT export = new BAPI_GOODSMVT_CREATE_EXPORT(); + + try + { + RfcDestination dest = RfcDestinationManager.GetDestination(ConfigHelper.ActiveSapDestinationName); + IRfcFunction func = dest.Repository.CreateFunction("ZBAPI_GOODSMVT_CREATE"); + IRfcStructure goodsmvt_header = func.GetStructure("GOODSMVT_HEADER"); + goodsmvt_header.SetValue("DOC_DATE", import.GOODSMVT_HEADER.DOC_DATE); + goodsmvt_header.SetValue("PR_UNAME", import.GOODSMVT_HEADER.PR_UNAME); + goodsmvt_header.SetValue("PSTNG_DATE", import.GOODSMVT_HEADER.PSTNG_DATE); + goodsmvt_header.SetValue("REF_DOC_NO", import.GOODSMVT_HEADER.REF_DOC_NO); + func.GetStructure("GOODSMVT_CODE").SetValue("GM_CODE", import.GOODSMVT_CODE.GM_CODE); + IRfcTable goodsmvt_item = func.GetTable("GOODSMVT_ITEM"); + + _log.Debug($"GOODSMVT: Will transmit {import.GOODSMVT_ITEM.Count} reels to SAP"); + foreach (BAPI2017_GM_ITEM_CREATE item in import.GOODSMVT_ITEM) + { + goodsmvt_item.Append(); + //goodsmvt_header.SetValue("NO_MORE_GR", " "); + if (item.DELIV_ITEM != null && !item.BATCH.Trim().Equals("")) { goodsmvt_item.SetValue("BATCH", item.BATCH); } + if (item.DELIV_ITEM != null && !item.DELIV_ITEM.Trim().Equals("")) { goodsmvt_item.SetValue("DELIV_ITEM", item.DELIV_ITEM); } + if (item.DELIV_NUMB != null && !item.DELIV_NUMB.Trim().Equals("")) { goodsmvt_item.SetValue("DELIV_NUMB", item.DELIV_NUMB); } + goodsmvt_item.SetValue("ENTRY_QNT", item.ENTRY_QNT); + if (item.ENTRY_UOM != null && !item.ENTRY_UOM.Trim().Equals("")) { goodsmvt_item.SetValue("ENTRY_UOM", item.ENTRY_UOM); } + if (item.ENTRY_UOM_ISO != null && !item.ENTRY_UOM_ISO.Trim().Equals("")) { goodsmvt_item.SetValue("ENTRY_UOM_ISO", item.ENTRY_UOM_ISO); } + if (item.EXPIRYDATE != null && !item.EXPIRYDATE.Trim().Equals("")) { goodsmvt_item.SetValue("EXPIRYDATE", item.EXPIRYDATE); } + if (item.ITEM_TEXT != null && !item.ITEM_TEXT.Trim().Equals("")) { goodsmvt_item.SetValue("ITEM_TEXT", item.ITEM_TEXT); } + if (item.MATERIAL != null && !item.MATERIAL.Trim().Equals("")) { goodsmvt_item.SetValue("MATERIAL", item.MATERIAL); } + if (item.MOVE_BATCH != null && !item.MOVE_BATCH.Trim().Equals("")) { goodsmvt_item.SetValue("MOVE_BATCH", item.MOVE_BATCH); } + if (item.MOVE_PLANT != null && !item.MOVE_PLANT.Trim().Equals("")) { goodsmvt_item.SetValue("MOVE_PLANT", item.MOVE_PLANT); } + if (item.MOVE_STLOC != null && !item.MOVE_STLOC.Trim().Equals("")) { goodsmvt_item.SetValue("MOVE_STLOC", item.MOVE_STLOC); } + if (item.MOVE_TYPE != null && !item.MOVE_TYPE.Trim().Equals("")) { goodsmvt_item.SetValue("MOVE_TYPE", item.MOVE_TYPE); } + if (item.MVT_IND != null && !item.MVT_IND.Trim().Equals("")) { goodsmvt_item.SetValue("MVT_IND", item.MVT_IND); } + if (item.NO_TRANSFER_REQ != null && !item.NO_TRANSFER_REQ.Trim().Equals("")) { goodsmvt_item.SetValue("NO_TRANSFER_REQ", item.NO_TRANSFER_REQ); } + if (item.PLANT != null && !item.PLANT.Trim().Equals("")) { goodsmvt_item.SetValue("PLANT", item.PLANT); } + if (item.PO_ITEM != null && !item.PO_ITEM.Trim().Equals("")) { goodsmvt_item.SetValue("PO_ITEM", item.PO_ITEM); } + if (item.PO_NUMBER != null && !item.PO_NUMBER.Trim().Equals("")) { goodsmvt_item.SetValue("PO_NUMBER", item.PO_NUMBER); } + if (item.SPEC_STOCK != null && !item.SPEC_STOCK.Trim().Equals("")) { goodsmvt_item.SetValue("SPEC_STOCK", item.SPEC_STOCK); } + if (item.STCK_TYPE != null && !item.STCK_TYPE.Trim().Equals("")) { goodsmvt_item.SetValue("STCK_TYPE", item.STCK_TYPE); } + if (item.STGE_LOC != null && !item.STGE_LOC.Trim().Equals("")) { goodsmvt_item.SetValue("STGE_LOC", item.STGE_LOC); } + if (item.VENDOR != null && !item.VENDOR.Trim().Equals("")) { goodsmvt_item.SetValue("VENDOR", item.VENDOR); } + _log.Debug($"GOODSMVT: Will transmit reel => MATERIAL:{item.MATERIAL}, QNT:{item.ENTRY_QNT}"); + } + func.Invoke(dest); + + export.MATDOCUMENTYEAR = func.GetString("MATDOCUMENTYEAR"); + export.MATERIALDOCUMENT = func.GetString("MATERIALDOCUMENT"); + + _log.Debug($"ZBAPI_GOODSMVT_CREATE: MATERIALDOCUMENTYEAR={export.MATDOCUMENTYEAR} MATERIALDOCUMENT={export.MATERIALDOCUMENT}"); + + IRfcTable ret_table = func.GetTable("RETURN"); + foreach (IRfcStructure row in ret_table) + { + BAPIRET2 temp = new BAPIRET2(); + temp.FIELD = ret_table.GetString("FIELD"); + temp.ID = ret_table.GetString("ID"); + temp.LOG_MSG_NO = ret_table.GetString("LOG_MSG_NO"); + temp.LOG_NO = ret_table.GetString("LOG_NO"); + temp.MESSAGE = ret_table.GetString("MESSAGE"); + temp.MESSAGE_V1 = ret_table.GetString("MESSAGE_V1"); + temp.MESSAGE_V2 = ret_table.GetString("MESSAGE_V2"); + temp.MESSAGE_V3 = ret_table.GetString("MESSAGE_V3"); + temp.MESSAGE_V4 = ret_table.GetString("MESSAGE_V4"); + temp.NUMBER = ret_table.GetString("NUMBER"); + temp.PARAMETER = ret_table.GetString("PARAMETER"); + temp.ROW = ret_table.GetString("ROW"); + temp.SYSTEM = ret_table.GetString("SYSTEM"); + temp.TYPE = ret_table.GetString("TYPE"); + export.RETURN.Add(temp); + + _log.Debug($"Return ({temp.TYPE} | {temp.ID} | NUM:{temp.NUMBER}): " + temp.MESSAGE + $" | V1:{temp.MESSAGE_V1} | V2:{temp.MESSAGE_V2} | V3:{temp.MESSAGE_V3} | V4:{temp.MESSAGE_V4}"); + } + } + catch (Exception ex) { errorMsg += "SAP Other Exception: " + ex; export.RETURN.Add(new BAPIRET2() { TYPE = "E", MESSAGE = ex.ToString() }); } + + if (!errorMsg.Equals("")) { _log.Error(errorMsg); } + + return export; + } + private static BAPI_TRANSACTION_COMMIT_EXPORT BAPI_TRANSACTION_COMMIT() //BAPI_TRANSACTION_COMMIT_IMPORT import ??? { string errorMsg = "";