0

我正在尝试使用以下 JCo 代码在 SAP 中创建采购信息记录 (ME11):

它执行没有失败并且没有抛出错误,但是我无法在 SAP 中获取新创建的信息记录。在 ME13 中,它说找不到信息记录。我能知道我错过了什么吗?

IFunctionTemplate ft1 = mRepository.getFunctionTemplate("ZME_INITIALIZE_INFORECORD");
    JCO.Function function1 = ft1.getFunction();
    mConnection.execute(function1);

    IFunctionTemplate ft = mRepository.getFunctionTemplate("ZME_DIRECT_INPUT_INFORECORD");
    JCO.Function function = ft.getFunction();
    JCO.ParameterList importparams =function.getImportParameterList();

    //  Setting HeadData Structure Information
    JCO.Structure headStructure = importparams.getStructure("I_EINA");
    //headStructure.setValue("105","MANDT");
    //headStructure.setValue("5300259768", "INFNR");
    headStructure.setValue("MYPART0006", "MATNR");      
    //headStructure.setValue("MYPART0006", "IDNLF");
    headStructure.setValue("100002","LIFNR");
    headStructure.setValue("10000","MATKL");
    headStructure.setValue("KGS","MEINS");
    headStructure.setValue("1","UMREZ");
    headStructure.setValue("1","UMREN");
    headStructure.setValue("SG","URZLA");
    headStructure.setValue("KGS","LMEIN");
    //headStructure.setValue("0000005300259768","URZZT");

    JCO.Structure headStructure1 = importparams.getStructure("O_EINA");
    //headStructure1.setValue("105","MANDT");
    //headStructure1.setValue("5300259768", "INFNR");
    headStructure1.setValue("MYPART0006", "MATNR");     
    //headStructure1.setValue("MYPART0006", "IDNLF");
    headStructure1.setValue("100002","LIFNR");
    headStructure1.setValue("10000","MATKL");
    headStructure1.setValue("KGS","MEINS");
    headStructure1.setValue("1","UMREZ");
    headStructure1.setValue("1","UMREN");
    headStructure1.setValue("SG","URZLA");
    headStructure1.setValue("KGS","LMEIN");

    //headStructure1.setValue("0000005300259768","URZZT");
    System.out.println("General Data Set");

    JCO.Structure purchaseDataStructure = importparams.getStructure("I_EINE");
    //purchaseDataStructure.setValue("105","MANDT");
    //purchaseDataStructure.setValue("5300259768", "INFNR");
    purchaseDataStructure.setValue("1000","EKORG");
    purchaseDataStructure.setValue("1000", "WERKS");
    purchaseDataStructure.setValue("003","EKGRP");
    purchaseDataStructure.setValue("USD","WAERS");
    purchaseDataStructure.setValue("3","APLFZ");
    purchaseDataStructure.setValue("1","PEINH");
    purchaseDataStructure.setValue("1","BPUMZ");
    purchaseDataStructure.setValue("1","BPUMN");
    purchaseDataStructure.setValue("1000","EFFPR");     
    purchaseDataStructure.setValue("0001","BSTAE");     
    purchaseDataStructure.setValue("100000","NETPR");
    purchaseDataStructure.setValue("X","KZABS");

    JCO.Structure purchaseDataStructure1 = importparams.getStructure("O_EINE");
    //purchaseDataStructure1.setValue("105","MANDT");
    //purchaseDataStructure1.setValue("5300259768", "INFNR");
    purchaseDataStructure1.setValue("1000","EKORG");
    purchaseDataStructure1.setValue("1000", "WERKS");
    purchaseDataStructure1.setValue("003","EKGRP");
    purchaseDataStructure1.setValue("USD","WAERS");
    purchaseDataStructure1.setValue("3","APLFZ");
    purchaseDataStructure1.setValue("1","PEINH");
    purchaseDataStructure1.setValue("1","BPUMZ");
    purchaseDataStructure1.setValue("1","BPUMN");
    purchaseDataStructure1.setValue("1000","EFFPR");        
    purchaseDataStructure1.setValue("0001","BSTAE");        
    purchaseDataStructure1.setValue("100000","NETPR");
    purchaseDataStructure1.setValue("X","KZABS");

    mConnection.execute(function);

    IFunctionTemplate ft2 = mRepository.getFunctionTemplate("ZME_POST_INFORECORD");
    JCO.Function function2 = ft2.getFunction();

    JCO.ParameterList importparams2 =function2.getImportParameterList();
    importparams2.setValue("MYPART0006", "I_MATNR");
    importparams2.setValue("MYPART0006", "O_MATNR");
    mConnection.execute(function2);
4

2 回答 2

1

我可能是错的,但我认为你得到了你填写的结构的副本。您可以通过在函数执行之前添加一组“setValue”来测试它吗,即:

importparams.setValue("I_EINA", headStructure);
importparams.setValue("O_EINA", headStructure1);
importparams.setValue("I_EINE", purchaseDataStructure);
importparams.setValue("O_EINE", purchaseDataStructure1);
mConnection.execute(function);

否则,可以在函数中添加外部断点(java 函数的执行将触发 ABAP 中的调试会话),

  • 并检查 ABAP 中的值是什么,以及执行
  • 您说该函数不会引发任何错误,但我没有在您的代码中看到任何错误检查。您的函数应该在 ABAP 端返回一个指示成功或错误的结构或表(例如,键入 BAPIRETURN1)。仅当存在 ABAP 转储或无效参数时,JCO 才会自行触发错误。

问候

于 2011-12-17T21:32:22.523 回答
0

除了@PATRY 的好答案:

  1. 您可能忘记了提交工作。
  2. 在从 Java 中使用它之前,我通常会在 ABAP 中编写一个小型测试程序。通常值得花时间,尽管您可以从 Java 触发 Abap 调试器。
  3. 正如@PATRY 所说,像你一样忽略返回参数是个坏主意。
于 2015-12-29T23:49:53.080 回答