简体   繁体   English

使用jCo(3.x)访问SAP表时不获取数据

[英]Getting No data when accessing SAP table with jCo(3.x))

Here is my sample code.In this example has only elementary types,no structure types has to set.But in the output no data exists in the table. 这是我的示例代码。在此示例中,只有基本类型,无需设置结构类型。但是在输出中,表中没有数据。

When I check the records in SAP it contains multiple records for this particular id.Can someone explain this to me? 当我检查SAP中的记录时,其中包含该特定ID的多个记录,有人可以向我解释吗?

public void invokeRFC(JCoDestination destination) {

    JCoFunction function=null;
    try

    {
        JCoFunctionTemplate functionTemplate = destination.getRepository().getFunctionTemplate("RFC_METHOD");

        if (functionTemplate != null) {
            function = functionTemplate.getFunction();
        }

        if (function == null)
            throw new RuntimeException("Not found in SAP.");

        //to fill elementary types and structures
        configureImportParameters(function,"xxx",  "abc");
        //to fill table type parameters
        configureTableParameters(function, "tblName",1,"100");
        function.execute(destination);


    } catch (JCoException e)
    {
        e.printStackTrace();
    }

}

public void configureTableParameters(JCoFunction function, String table_name, int index, String id) {
    JCoTable table = function.getTableParameterList().getTable("table_name");

    table.appendRow();
    table.setRow(index);
    table.setValue("Partner", "100");

}

private void exportTable(JCoFunction jCoFunction, String tblName) {
    JCoTable resultTable = jCoFunction.getTableParameterList().getTable(tblName);

    int value = resultTable.getNumRows();
    System.out.println(value);
}

private void configureImportParameters(JCoFunction function, String param1, String param2) {

    JCoParameterList parameterList = 
    function.getImportParameterList();
    parameterList.setValue("field1", param1);
    parameterList.setValue("field2", param2);

}

UPDATED the code. 更新了代码。

Test your ABAP remote function module with an SAP GUI via transaction code SE37 first. 首先通过事务代码SE37使用SAP GUI测试ABAP远程功能模块。 If this test is successful and you get a different result if called from JCo with using the same parameter values, then I recommend to study SAP note 206068 for possible reasons. 如果此测试成功,并且使用相同的参数值从JCo调用时得到的结果不同,那么出于可能的原因,我建议学习SAP注释206068

Also check your method configureTableParameters . 还要检查您的方法configureTableParameters I guess, index shall be a field index and not a row count. 我猜, index应该是字段索引,而不是行数。 Your implementation will create far too many unnecessary rows. 您的实现将创建太多不必要的行。 I assume you wanted to call table.appendRow(); 我假设您想调用table.appendRow(); instead of table.appendRows(index); 而不是table.appendRows(index); . Moreover, you maybe intended to fill the first field in the row with the value "100" , for which you would have to pass the index value 0 instead of 1 in this case. 此外,您可能打算用值"100"填充行中的第一个字段,在这种情况下,您必须为此传递索引值0而不是1

multiple problem can cause this. 多个问题可能导致此。

  1. if you setting "" or " " to fields. 如果您将“”或“”设置为字段。 (when you set values better set if those has some values (当您设置值时,如果这些值有些值,则最好设置

  2. if it says partner does not exist and if you sure its exist this mean your data does not pass properly. 如果提示合作伙伴不存在,并且您确定其存在,则表示您的数据无法正确传递。 add debug points to where you set the data and make sure you pass correct name and correct values. 将调试点添加到设置数据的位置,并确保传递正确的名称和正确的值。

  3. also you do not need to add(index) you can just table.appendRow(); 也不需要添加(index)就可以了table.appendRow(); // but this will not impact on your case //但这不会影响您的情况

  4. also when you setValue make sure its int filed. 另外,在setValue时,请确保将其int归档。 (normally not) in your given example its int (通常不是)在您给出的示例中,其int

eg: 例如:

private void configureTableParameters(JCoParameterList tableParameters){
    JCoTable jCoTable=tableParameters.getTable(key);
    jCoTable.appendRow();
    if(value!=null)
    jCoTable.setValue(fieldKey,String.valueOf(value));

}

this is just psuda code and will not work 这只是psuda代码,将无法正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM