Beispiel #1
0
        public Dictionary <String, Object> Execute_VA01(VA01_DTO simulator)
        {
            try
            {
                RfcDestinationManager.RegisterDestinationConfiguration(this.SAPConfig);
                var           rfcDest = RfcDestinationManager.GetDestination(this.ConfigurationName);
                RfcRepository rfcRep  = null;
                rfcRep = rfcDest.Repository;

                IRfcFunction customerList = rfcRep.CreateFunction("ABAP4_CALL_TRANSACTION");

                customerList.SetValue("TCODE", "VA01");
                customerList.SetValue("MODE_VAL", "N");
                customerList.SetValue("UPDATE_VAL", "S");


                IRfcTable USIGN_TAB = customerList.GetTable("USING_TAB");

                #region ClasePedido

                USIGN_TAB.Append();
                USIGN_TAB.SetValue("PROGRAM", "SAPMV45A");
                USIGN_TAB.SetValue("DYNPRO", "0101");
                USIGN_TAB.SetValue("DYNBEGIN", "X");
                USIGN_TAB.SetValue("FNAM", "VBAK-AUART");
                USIGN_TAB.SetValue("FVAL", simulator.CPedido);

                #endregion

                #region OrgVentas

                USIGN_TAB.Append();
                USIGN_TAB.SetValue("PROGRAM", "SAPMV45A");
                USIGN_TAB.SetValue("DYNPRO", "0101");
                USIGN_TAB.SetValue("DYNBEGIN", "X");
                USIGN_TAB.SetValue("FNAM", "VBAK-VKORG");
                USIGN_TAB.SetValue("FVAL", simulator.OrgVentas);

                #endregion

                #region Canal

                USIGN_TAB.Append();
                USIGN_TAB.SetValue("PROGRAM", "SAPMV45A");
                USIGN_TAB.SetValue("DYNPRO", "0101");
                USIGN_TAB.SetValue("DYNBEGIN", "X");
                USIGN_TAB.SetValue("FNAM", "VBAK-VTWEG");
                USIGN_TAB.SetValue("FVAL", simulator.Canal);

                #endregion

                #region Sector

                USIGN_TAB.Append();
                USIGN_TAB.SetValue("PROGRAM", "SAPMV45A");
                USIGN_TAB.SetValue("DYNPRO", "0101");
                USIGN_TAB.SetValue("DYNBEGIN", "X");
                USIGN_TAB.SetValue("FNAM", "VBAK-SPART");
                USIGN_TAB.SetValue("FVAL", simulator.Sector);

                #endregion


                #region Obra

                USIGN_TAB.Append();
                USIGN_TAB.SetValue("PROGRAM", "SAPMV45A");
                USIGN_TAB.SetValue("DYNPRO", "4701");
                USIGN_TAB.SetValue("DYNBEGIN", "X");
                USIGN_TAB.SetValue("FNAM", "KUWEV-KUNNR");
                USIGN_TAB.SetValue("FVAL", simulator.CodObra);

                #endregion

                #region Fecha

                USIGN_TAB.Append();
                USIGN_TAB.SetValue("PROGRAM", "SAPMV45A");
                USIGN_TAB.SetValue("DYNPRO", "4401");
                USIGN_TAB.SetValue("DYNBEGIN", "X");
                USIGN_TAB.SetValue("FNAM", "RV45A-KETDAT");
                USIGN_TAB.SetValue("FVAL", simulator.Fecha);//DD.MM.AAAA

                #endregion



                #region Material

                USIGN_TAB.Append();
                USIGN_TAB.SetValue("PROGRAM", "SAPMV45A");
                USIGN_TAB.SetValue("DYNPRO", "4900");
                USIGN_TAB.SetValue("DYNBEGIN", "X");
                USIGN_TAB.SetValue("FNAM", "VBAP-MATNR");
                USIGN_TAB.SetValue("FVAL", simulator.Material);

                #endregion

                #region Volumen

                USIGN_TAB.Append();
                USIGN_TAB.SetValue("PROGRAM", "SAPMV45A");
                USIGN_TAB.SetValue("DYNPRO", "4900");
                USIGN_TAB.SetValue("DYNBEGIN", "X");
                USIGN_TAB.SetValue("FNAM", "RV45A-KWMENG");
                USIGN_TAB.SetValue("FVAL", simulator.Vol);

                #endregion
                IRfcTable MESS_TAB = customerList.GetTable("MESS_TAB");

                customerList.Invoke(rfcDest);
                IRfcStructure Data = customerList.GetStructure("KOMP");

                /* IRfcFunction customprice = rfcRep.CreateFunction("RFC_GETPRICING");
                 * customprice.*/
                IEnumerator <IRfcField> list = Data.GetEnumerator();
                string[] strArray            = null;
                int      i = 0;

                while (list.MoveNext())
                {
                    strArray[i] = list.Current.GetValue().ToString();
                }

                /* DataTable dt = new DataTable();
                 * FillRowsFromSapTable(dt, Data);
                 * GetColumnsFromSapTable(dt, Data);*/

                var res = Data.Last().ToString();

                /* #region Guardar:
                 *
                 * USIGN_TAB.Append();
                 * USIGN_TAB.SetValue("PROGRAM", "SAPMZCX_CFIAR0MX104");
                 * USIGN_TAB.SetValue("DYNPRO", "0101");
                 * USIGN_TAB.SetValue("DYNBEGIN", "X");
                 * USIGN_TAB.SetValue("FNAM", "BDC_OKCODE");
                 * USIGN_TAB.SetValue("FVAL", "=SAVE");
                 *
                 #endregion
                 *
                 * IRfcTable MESS_TAB = customerList.GetTable("MESS_TAB");
                 *
                 * customerList.Invoke(rfcDest);*/
            }
            catch (RfcLogonException le)
            {
                return(new Dictionary <string, object>()
                {
                    { "Response", false }, { "Message", le.Message }
                });
            }
            catch (Exception ex)
            {
                return(new Dictionary <string, object>()
                {
                    { "Response", false }, { "Message", ex.Message + " : " + ex.StackTrace }
                });
            }
            finally
            {
                RfcDestinationManager.UnregisterDestinationConfiguration(this.SAPConfig);
            }
            return(new Dictionary <string, object>()
            {
                { "Response", true }, { "Message", "Success" }
            });
        }