0

我正在运行 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.
4

1 回答 1

1

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

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

  • “INVOICE_SUMMARIES”是一种表类型。注意for循环,它正在读取一个表格。

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

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;
}
于 2015-02-01T20:49:12.523 回答