RFC Returns 指向数据而不是数据本身的指针

RFC Returns Pointer to Data Instead of Data Itself

我正在 运行使用 RFC 从 SAP 获取数据。当我 运行 这个 RFC 时,似乎我得到了一个指向数据的指针,而不是数据本身。

<ET_RETURN>BAPIRET2_</ET_RETURN>

看来这个 BAPIRET2_ 是某个数据集名称或指针。我想要此 BAPIRET2_ 数据集中的数据。

有没有办法自己获取数据?

蒂姆

编辑:RFC 是:

FUNCTION z_esrv_offer_getlist. 
*"---------------------------------------------------------------------- 
*"*"Local Interface: 
*"  IMPORTING 
*"     VALUE(IV_USERID) TYPE  UNAME OPTIONAL 
*"     VALUE(IV_REQUESTID) TYPE  ZESRVREQGUID OPTIONAL 
*"     VALUE(IV_OFFER_NUM) TYPE  TKONN OPTIONAL 
*"     VALUE(IV_STATUS_CHANGE_FROM_DATETIME) TYPE  ZDATETIME OPTIONAL 
*"     VALUE(IV_STATUS_CHANGE_TO_DATETIME) TYPE  ZDATETIME OPTIONAL 
*"     VALUE(IV_PURCH_SALES) TYPE  ZPUR_SALE OPTIONAL 
*"     VALUE(IV_TYPE) TYPE  BSARK OPTIONAL 
*"     VALUE(IV_IDOC) TYPE  XFELD DEFAULT SPACE 
*"     VALUE(IT_PLANTS) TYPE  CCVX_WERKS_TAB OPTIONAL 
*"     VALUE(IT_PARTNERS) TYPE  ZESRVBPLIST_TAB OPTIONAL 
*"     VALUE(IT_OFFER_STATUS_CODES) TYPE  ZESRV_BTBSTA_TAB OPTIONAL 
*"  CHANGING 
*"     VALUE(ET_OFFERS) TYPE  ZESRVOFFER_TAB 
*"     VALUE(ET_CHANGE_HIST) TYPE  ZESRVOFFER_HIST_TAB 
*"     VALUE(ET_RETURN) TYPE  BAPIRET2_TAB 
*"---------------------------------------------------------------------- 

  DATA: l_error     TYPE symsgv, 
        lv_return   TYPE bapiret2. 

  FIELD-SYMBOLS: <error>     TYPE bapiret2. 

* Initialize. 
  PERFORM initialize_setup. 
  PERFORM initialize_for_getlist. 
  gv_userid = iv_userid. 
  gv_req_id = iv_requestid. 

  PERFORM get_function_name CHANGING gv_funcname. 


* Unload selection criteria into global variables 

  gv_offer = iv_offer_num. 
  gv_frm_chngdtm = iv_status_change_from_datetime. 
  gv_to_chngdtm = iv_status_change_to_datetime. 
  gv_ps = iv_purch_sales. 
  gv_type = iv_type. "(F)irm / (S)oft 
  gv_idoc = iv_idoc. "X if for idoc creation 

* partners 
  IF it_partners[] IS NOT INITIAL. 
    r_partners-sign = 'I'. 
    r_partners-option = 'EQ'. 
    CLEAR r_partners-high. 
    LOOP AT it_partners INTO gs_partners. 
      APPEND gs_partners TO gt_logprtnrs. 
      r_partners-low = gs_partners-bu_partner. 
      APPEND r_partners TO gt_partner_rng. 
    ENDLOOP. 
  ENDIF. 
* plants 
  IF it_plants[] IS NOT INITIAL. 
    r_plants-sign = 'I'. 
    r_plants-option = 'EQ'. 
    CLEAR r_plants-high. 
    LOOP AT it_plants INTO gn_plant. 
      r_plants-low = gn_plant-werks. 
      APPEND r_plants TO gt_plant_rng. 
      APPEND gn_plant TO gt_plants. 
    ENDLOOP. 
  ENDIF. 
* status codes 
  IF it_offer_status_codes[] IS NOT INITIAL. 
    r_status-sign = 'I'. 
    r_status-option = 'EQ'. 
    CLEAR r_status-high. 
    LOOP AT it_offer_status_codes INTO gn_status. 
      r_status-low = gn_status-btbsta. 
      APPEND r_status TO gt_status_rng. 
      APPEND gn_status TO gt_status_codes. 
    ENDLOOP. 
  ENDIF. 

* make sure there is at least one criteria filled 
  IF iv_offer_num IS INITIAL AND 
     iv_status_change_from_datetime IS INITIAL AND 
     iv_status_change_to_datetime IS INITIAL AND 
     iv_type IS INITIAL AND 
     it_plants[] IS INITIAL AND 
     it_partners[] IS INITIAL AND 
     it_offer_status_codes[] IS INITIAL. 

    PERFORM get_message_for_bapi USING gc_warning gc_esrv '057' 
                               space space space space 
                                CHANGING lv_return. 
    APPEND lv_return TO et_return. 
    APPEND lv_return TO gt_error. 
*    IF iv_userid IS INITIAL AND iv_requestid = 0. 
*    ELSE. 
    PERFORM bapi_logging USING gv_funcname. 
*    ENDIF. 
    EXIT. 
  ENDIF. 

* at least one selection criteria has been entered, so validate selections 
  PERFORM validate_selections. 
  READ TABLE gt_error INTO lv_return WITH KEY type = 'W'. 
  IF sy-subrc = 0. 
*     errors found in selection criteria, stop 
    et_return[] = gt_error[]. 
    EXIT. 
  ELSE. 
*     no errors found, select data 
    PERFORM get_offers. 
    IF gt_offers[] IS NOT INITIAL. 
      PERFORM get_history. 
      et_change_hist[] = gt_chng_hist[]. 
      et_offers[] = gt_offers[]. 
    ENDIF. 
    DESCRIBE TABLE et_offers LINES gv_recordsfound. 
    IF gv_recordsfound = 0. 
*     no offers found 
      PERFORM get_message_for_bapi USING gc_warning gc_esrv '061' 
                                 space space space space 
                                  CHANGING lv_return. 
      APPEND lv_return TO et_return. 
      APPEND lv_return TO gt_error. 
*      IF iv_userid IS INITIAL AND iv_requestid = 0. 
*      ELSE. 
      PERFORM bapi_logging USING gv_funcname. 
*      ENDIF. 
      EXIT. 
    ELSE. 
      READ TABLE et_return INTO lv_return WITH KEY type = 'W'. 
      IF sy-subrc <> 0. 
*       success, history returned 
        PERFORM get_message_for_bapi USING gc_success gc_esrv '002' 
                                   space space space space 
                                    CHANGING lv_return. 
        APPEND lv_return TO gt_error. 
        APPEND lv_return TO et_return. 
*        IF iv_userid IS INITIAL AND iv_requestid = 0. 
*        ELSE. 
        PERFORM bapi_logging USING gv_funcname. 
*        ENDIF. 
      ENDIF. 
    ENDIF. 
  ENDIF. 

ENDFUNCTION.

SAP JCo 将 return 您的数据使用它自己的对象类型。您将必须浏览这些对象才能获取数据。下面是连接到 SAP 以使用 SAP JCo 3 获取发票详细信息的 Java 方法的示例。您应该注意两种 return 类型:

  • "RETURN" 是结构类型。在 java 中,这有点像 java 中的 POJO。或者您可以将其视为单个数据记录。 Google“SAP 结构”了解更多详情。

  • "INVOICE_SUMMARIES" 是 table 类型。注意 for 循环,它正在读取 table.

根据 RFC 的导出参数是 tables(它们看起来是)还是结构,您需要调整检索数据的方式。希望这个示例足以让您入门。

private List<InvoiceSummary> getInvoices(String userId, String customerNumber, String invoiceNumber) throws InvoiceRetrievalException, JCoException {

    ArrayList<InvoiceSummary> invoices = new ArrayList<InvoiceSummary>();
    try {
        //Verify SAP connection.
        DAOFactory.registerDestination();
        JCoDestination dest = JCoDestinationManager.getDestination(DAOFactory.getDestinationName());
        JCoRepository repository = dest.getRepository();

        JCoFunctionTemplate ft = repository.getFunctionTemplate("Z_BAPI_GET_INVOICES");
        JCoFunction jFunction = ft.getFunction();

        //Set parameters.
        jFunction.getImportParameterList().setValue("USER_ID", userId);
        jFunction.getImportParameterList().setValue("CUSTOMER_NUMBER", customerNumber);
        jFunction.getImportParameterList().setValue("INVOICE_NUMBER", invoiceNumber);

        //Execute the function and read the results.
        jFunction.execute(dest);

        //Check the SAP return object for errors.
        JCoStructure out = jFunction.getExportParameterList().getStructure("RETURN");
        if ("E".equals(out.getString("TYPE"))) {
            throw new InvoiceRetrievalException(out.getString("MESSAGE"));
        }

        //Parse the returned invoices into InvoiceSummary objects.
        JCoTable invoiceTable = jFunction.getTableParameterList().getTable("INVOICE_SUMMARIES");
        for (int i = 0; i < invoiceTable.getNumRows(); i++) {
            InvoiceSummary invoice = new InvoiceSummary();
            invoiceTable.setRow(i);

            invoice.setInvoiceNumber(invoiceTable.getString("INVOICE_NUMBER"));
            invoice.setReleaseNumber(invoiceTable.getString("RELEASE_NUMBER"));
            invoice.setItemNumber(invoiceTable.getString("ITEM_NUMBER"));
            invoice.setInvoiceDate(invoiceTable.getString("INVOICE_DATE"));
            invoice.setProductDescription(invoiceTable.getString("DESCRIPTION"));
            invoice.setDueDate(invoiceTable.getString("DUE_DATE"));
            invoice.setCustomerNumber(invoiceTable.getString("CUSTOMER_NUMBER"));

            invoices.add(invoice);
        }
    } catch (InvoiceRetrievalException e) {
        logger.error("An error occurred while attempting to retrieve an invoice." +
            " userId = " + userId +
            " invoiceNumber = " + invoiceNumber, e);
        throw e;
    } catch (JCoException e) {
        logger.error("An error occurred while calling Z_BAPI_GET_INVOICES." +
            " userId = " + userId +
            " invoiceNumber = " + invoiceNumber, e);
        throw e;
    }
    return invoices;
}