2

我正在尝试使用标准 BAPI (PurchaseRequisition.CreateFromData) 在采购申请中“插入”(或)“添加一行”。

我正在使用 JCo3。JCo3 中的示例表明我们应该使用 table.appendRow() 或 table.insertRow() 方法。我正在尝试使用 table.appendRow() 和 table.appendRows(1)。当我尝试插入一行时,我没有收到任何错误,并且没有插入该行。

下面是我要执行的程序。/** 下面是该程序运行所需的输入//第 1 步 **/ String BAPI_NAME = "BAPI_REQUISITION_CREATE";

    /** Step 2 **/
    String query_input_column1 = "DOCUMENTY_TYPE"; 
    String query_input_column1_value = "NB";

    String query_input_column2 = "PREQ_NAME";
    String query_input_column2_value = "Name";

    String query_input_column3 = "ACCTASSCAT";
    String query_input_column3_value = "U";

    String query_input_column4 = "DELIV_DATE";
    String query_input_column4_value = "20131101";

    String query_input_column5 = "MATERIAL";
    String query_input_column5_value = "DELL-RQ2013";

    String query_input_column6 = "QUANITY";
    int query_input_column6_value = 10100;




    /** Step 3 **/
    String targetTableUnderBAPI = "REQUISITION_ITEMS";

    /** Step 4 **/
    /** For the confirmation read the value from export parameter after insertion execution **/
    String result_column1 = "NUMBER";


    JCoDestination destination = null;
    try {
        destination = JCoDestinationManager.getDestination(DestinationManager.DESTINATION_NAME1);
        JCoRepository repository = destination.getRepository();
        JCoContext.begin(destination);

        JCoFunction function = repository.getFunction(BAPI_NAME);

        if(function == null)
            throw new RuntimeException(BAPI_NAME + " not found in SAP.");

        System.out.println("BAPI Name from function object: " + function.getName());            

        //function.getImportParameterList().setValue(query_input_column1, query_input_column1_value);
        JCoTable table = function.getTableParameterList().getTable(targetTableUnderBAPI); //it is taken from the response value of metadata
        //System.out.println("No of Columns: "+ table.getNumColumns());
        System.out.println("Trying to execute append row");

        table.appendRow();
            table.setValue(query_input_column1,query_input_column1_value);
            table.setValue(query_input_column2,query_input_column2_value);
            table.setValue(query_input_column3,query_input_column3_value);
            //table.setValue(query_input_column4,new java.util.Date(query_input_column4_value));

//跳过其他列相关代码

        try{
            function.execute(destination);
        }
        catch(AbapException e){
            System.out.println(e.toString());
            return;
        }

        System.out.println("Let us check the result from export parameter");
        String exportParamStructure = (String)function.getExportParameterList().getValue(result_column1); //getStructure(result_column1); // getValue(result_column1);
        System.out.println("Resulting PR#: "+exportParamStructure);

    } catch (JCoException e) {
        e.printStackTrace();
    }
    finally
    {
        try {
            JCoContext.end(destination);
        } catch (JCoException e) {
            e.printStackTrace();
        }
    }

我不明白如何阅读响应并试图从 exportParameters 中获取它!

  1. 任何人都可以分享一段代码来插入和
  2. 获得确认响应(我们是否得到 PREQ_NO 作为响应?)
  3. 我将日期字段值添加为“20131101”,但不确定格式和方法是否正确?
  4. 当我尝试添加 Quantity 列值时,我收到一条错误消息,抱怨此列不是 BAPIIEBANC 的一部分。但是该列在 BAPIIEBANC 类型中是可见的。
  5. 要检查 SAP 端的任何配置?
  6. 我应该激活 JCo 端的任何字段吗?如果是这样,如何

请注意,我对 SAP 的了解非常有限。

等待专家回复。

谢谢。

4

2 回答 2

1

首先,您应该查看 SAP JCo 文档,例如 http://help.sap.com/saphelp_nw04/helpdata/en/6f/1bd5c6a85b11d6b28500508b5d5211/content.htm

关于您的代码:

  • 乍一看,向表中添加(一个)行看起来是正确的。
  • 您的代码说 QUANITY 而不是 QUANTITY。
  • 您应该将日期值添加为 java.util.Date;如果从字符串格式创建日期,则应使用 java.text.DateFormat.parse()。请参阅http://docs.oracle.com/javase/6/docs/api/java/util/Date.html(但这是 Java 特定的,与 JCo 无关)。
  • 如果在 SAP 中更改任何内容,请不要忘记最后调用 BAPI_TRANSACTION_COMMIT 以完成逻辑工作单元(也称为事务),否则实际上不会更改任何内容。

如果您不喜欢摆弄或多或少复杂和冗长的 JCo API,请尝试使用 Hibersap,它在 SAP ERP 中调用函数时为您提供更好的编程模型:http: //hibersap.org

但是,您仍然需要基本了解 SAP 功能模块在技术上如何工作(例如参数类型或数据类型)以及它们背后的特定领域模型(在您的情况下,创建申请)。即您可能需要与您的 SAP 专家沟通。

于 2013-11-04T10:27:33.840 回答
1

在这里,我添加了 2 种类型的插入:

  1. insertval()在abap程序员的帮助下,用户定义模块的功能驻留在sap中
  2. 它是一个标准模块,用于使用 jco 将工单插入 SOLMAN 系统。首先,您必须分析导入、导出、表和结构参数,并据此传递值并检索响应。在第二个函数中,它会在 solman 中成功插入票后返回票号。

我希望这个示例代码对你有帮助,它对我有用。

  public class jco
    {

    static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";
        static String DESTINATION_NAME2 = "ABAP_AS_WITH_POOL";

    static
        {

            Properties connectProperties = new Properties();
            connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "192.1.1.1");
            connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,  "01");
            connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "500");
            connectProperties.setProperty(DestinationDataProvider.JCO_USER,   "uname");
            connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "pwd");
            connectProperties.setProperty(DestinationDataProvider.JCO_LANG,   "en");

            createDestinationDataFile(DESTINATION_NAME1, connectProperties);
            connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
            connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,    "10");
            createDestinationDataFile(DESTINATION_NAME2, connectProperties);
            System.err.println("hai");

        }

        static void createDestinationDataFile(String destinationName, Properties connectProperties)
        {
            File destCfg = new File(destinationName+".jcoDestination");
            try
            {
                try (FileOutputStream fos = new FileOutputStream(destCfg, false)) {
                    connectProperties.store(fos, "for tests only !");
                }
            }
            catch (IOException e)
            {
                throw new RuntimeException("Unable to create the destination files", e);
            }
        }






        public void insertval() throws JCoException
        {

            JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME1);

          JCoFunction jf=destination.getRepository().getFunction("ZUSER_DET");

       jf.getImportParameterList().setValue("FIRST_NAME","member");
      jf.getImportParameterList().setValue("LAST_NAME","c");
         jf.getImportParameterList().setValue("USER_NO","1000");

         jf.execute(destination);
    System.out.println(jf);
        }





public void insertticket() throws JCoException
    { 
        JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME2);
        System.out.println("test"+"\n");
      JCoFunction jf=destination.getRepository().getFunction("BAPI_NOTIFICATION_CREATE");

      JCoTable jt1=jf.getTableParameterList().getTable("APPX_HEADERS");


      JCoTable jt2=jf.getTableParameterList().getTable("APPX_LINES");


      JCoTable jt3=jf.getTableParameterList().getTable("APPX_LINES_BIN");


      JCoTable jt4=jf.getTableParameterList().getTable("NOTIF_NOTES");



      JCoTable jt5=jf.getTableParameterList().getTable("NOTIF_PARTNERS");
      JCoTable jt6=jf.getTableParameterList().getTable("NOTIF_SAP_DATA");
      JCoTable jt7=jf.getTableParameterList().getTable("NOTIF_TEXT_HEADERS");
      JCoTable jt8=jf.getTableParameterList().getTable("NOTIF_TEXT_LINES");


      JCoStructure jfn1=jf.getImportParameterList().getStructure("NOTIF_EXT");
  JCoStructure jfn2=jf.getImportParameterList().getStructure("NOTIF_CRM");
JCoStructure jfn3=jf.getImportParameterList().getStructure("IBASE_DATA");
jfn1.setValue("NUMB","1234");
jfn1.setValue("REFNUM","123");
jfn1.setValue("TYPE_NOTIF","SLFN");
jfn1.setValue("SUBJECT","tl");
jfn1.setValue("PRIORITY","2");
jfn1.setValue("LANGUAGE","EN");
jfn1.setValue("CATEGORY","Z01");
 jfn2.setValue("CODE","0011");
 jfn2.setValue("CODEGROUP","0011");
   jfn2.setValue("CATEGORY","Z01");
jfn3.setValue("INSTANCE","489");
  jfn3.setValue("IBASE","500");



jt1.appendRow();
jt1.setValue("DESCR","practise");
 jt2.appendRow();

      jt2.setValue("LINE","CVXCVXCV");
  jt3.appendRow();
      jt3.setValue("LINE","second text line");
      jt4.appendRow();
      jt4.setValue("TYPE_NOTE","my");
      jt4.setValue("IDENT","hoe twwrtgw");
      jt4.setValue("DESCRIPTION","its description ");
jt5.appendRow();

jt5.setValue("PARNR","new ");
jt5.setValue("TYPE_PAR","FN");
jt5.setValue("FUNC_PAR","EN");
jt5.setValue("PAR_ACTIVE","1");
jt6.appendRow();
jt6.setValue("INSTN","0020214076");
jt6.setValue("COMP","FI-AA");
jt6.setValue("SYSTYPE","P");
jt6.setValue("SYSID","PRD");
jt6.setValue("MANDT","900");
jt8.appendRow();
jt8.setValue("TXT_NUM","1");
jt8.setValue("TDFORMAT",">X");
jt8.setValue("TDLINE","/(performing all test)");






jf.execute(destination);
String jfex=jf.getExportParameterList().getString("REFNUM");

               System.out.println("hi "+jfex);

    }
于 2013-12-28T07:12:27.680 回答