abapsaprfcsapjco3

RFC Returns Pointer to Data Instead of Data Itself


I am running a RFC to get data from SAP. When I run this RFC, it appears that I get a pointer to the data, rather than the data itself.

<ET_RETURN>BAPIRET2_</ET_RETURN>

It appears that this BAPIRET2_ is some data set name or pointer. I want the data within this BAPIRET2_ dataset.

Is there any way to get the data itself?

Tim

EDIT: The RFC is:

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.

Solution

  • SAP JCo will return your data using its own object types. You will have to navigate through those objects to get your data. Below is an example of a Java method that connects to SAP for the purpose of obtaining invoice details using SAP JCo 3. There are two return types that you should note:

    Depending on if the export parameters of your RFC are tables (which they appear to be) or structures, you will want to adjust how you retrieve the data. Hopefully this example is enough to get you started.

    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;
    }