A Wrapper to Call Dynamically Function via RFC



Similar documents
Changing Partner s Address Data of the Sales Order

Offsetting Account Description in FBL3N and FAGLL03 GL Line Item Display Reports

Application Logging in SAP Using ABAP

Step by Step Guide How to Copy Flat File from Other Application Server to BI and Load through Info Package

Restricting Search Operators in any Search View

SAP BI Generic Extraction Using a Function Module

Step by Step Guide for Language Translation Tool

Release Strategy Enhancement in Purchase Order

Table of Contents. Passing Data across Components through Component Controller between Two Value Nodes

Scenario... 3 Step-by-Step Solution Virtual Infocube... 4 Function Module (Virtual InfoCube)... 5 Infocube Data Display... 7

Display Popup Window and Dialog Box in ALV

Converting and Exporting Data in XML Format

ALV List with Radio Buttons

How to Generate Stack Xml for Ehp4 and Above Upgrade

Step by Step Guide to Fiscal Week and Fiscal Quarter

Message handling in SAP CRM Web UI

ABAP Proxy Interfacing

Creating Content Using SO10 Objects and Text Symbols

How to Modify, Create and Delete Table Entries from SE16

Exposing RFC as Web Service and Consuming Web Service in Interactive Forms in ABAP

Creating Transaction and Screen Variants

BW Performance Monitoring

SDN Community Contribution

How to Assign Transport Request for Language Translation?

ALE Settings, for Communication between a BW System and an SAP System

Creating Mobile Applications on Top of SAP, Part 1

Process Controlled Workflow SRM 7.0 (Using BRF)

SAP BW - Excel Pivot Chart and Pivot Table report (Excel)

SAP NetWeaver Developer Studio 7.30 Installation Guide

Step by Step Guide to Create a Generic Datasource Based on Infoset Query Populated Via External Program

Creation and Configuration of Business Partners in SAP CRM

Creating Web Service from Function Modules/BAPIs & Integrating with SAP Interactive Forms

Merge PDF files in ABAP

SAP CRM Campaign Automation

Dynamic Authorization Concept and Role Assignment in BI

Guidelines for Effective Data Migration

Quick Viewer: SAP Report Generating Tool

Compounding in Infoobject and Analyzing the Infoobject in a Query

Step by Step Procedure to Block and Debug a CIF Queue Flowing from R/3 to APO System

Display Options in Transaction SE16

Table of Content. SAP Query creation and transport Procedure in ECC6

Splitting the Custom Container & Display more than one ALV

Sending an Image File Through XI in a File-to-Mail Scenario

Reverse Transport Mechanism in SAP BI

ABAP Debugging Tips and Tricks

SAP FI - Automatic Payment Program (Configuration and Run)

Transfer of GL Master from Source SAP System to a Target SAP System through IDOCS

SAP CRM 7.0 E2C Setup: CRM via Toolset

Web Dynpro: Multiple ALV Grids and Layouts in ALV

Deleting the Requests from the PSA and Change Log Tables in Business Intelligence

Working with SAP BI 7.0 Data Transfer Process (DTP)

ABAP. Finding Appropriate Abstractions for Business Application Programming. Horst Keller, SAP AG Tobias Wenner, SAP AG

Configuration of Enterprise Services using SICF and SOA Manager

Salesforce.com Integration Using SAP PI: A Case Study

Deleting the User Personalization done on Enterprise Portal

Business Scenario Using GP/Web Dynpro with Back and Forth 3 Level Process and Dynamic Approvers in a Loop

Step by Step Procedures to Load Master Data (Attribute and Text) from FlatFile in BI 7.0

XSLT Mapping in SAP PI 7.1

SAP Workflow in Plain English

Web Dynpro ABAP: ALV and Table in Popup Window

Customer Exit Variables in SAP BW/BI Reports First day of the Current/Previous Month

How to Integrate CRM 2007 WebClient UI with SAP NetWeaver Portal

Embedding Crystal Reports inside ECC ALV Reports

Adobe Document Service Configuration and Troubleshooting Guide

Creating New Unit of Measure in SAP BW

How to Develop Programs for SAP Mobile RF

Organizational Management- Organizational Structure Creation

Standard SAP Configuration of SMS through HTTP with Third Party SMS Gateway

Multi Provider Creation Based on Sales and Planning Info Cubes

Extractor in R/3 and Delta Queue

How to Load Data from Flat Files into BW PSA

Configuring HTTPs Connection in SAP PI 7.10

BOM Header and Item Extraction in SAP - Business Intelligence

Understanding BW Non Cumulative Concept as Applicable in Inventory Management Data Model

Integration of SAP R/3 with BO Universe Using Data Federator Connector

SAP CRM 7.0 for Newbies: (Part 1) Simple BOL Object Creation for CRM Webclient UI

Create Automatic Mail Notification/ Alert for Process Chain Monitoring

SAP MM: Purchase Requisition with Classification and Workflow Approval

SAP CRM System 6.0/7.0. For more information, visit the Customer Relationship Management homepage

Using PI to Exchange PGP Encrypted Files in a B2B Scenario

Forgot or Lock "Administrator or J2EE_ADMIN" Password

SPDD & SPAU Adjustments Handbook

Introduction to COPA and COPA Realignment

Middleware Configuration and Monitoring for Master Data Transfer from SRM to ECC

Salesforce Integration Using PI: How to Perform Query and Other DML Operations Using the Enterprise WSDL

Step by Step guide of Report-to- Report Interface in BW Reporting

Consuming Services in SOA Manager

Mandatory Field Check in Web Dynpro- ABAP

Step by Step Guide to Archiving and Deleting of XML Messages in SAP NetWeaver PI

Understanding BEx Query Designer: Part-2 Structures, Selections and Formulas

Invoice Collaboration: Self Billing Invoice

Multi Level Purchase Order Release Strategy

LSMW: Upload Master Data using Batch Input Recording

Tutorial - Creating Pop Up Window Using New Features in WebDynpro Java CE 7.1 Ehp1

Upload Data in Web Dynpro Table from a Text File with Delimiters

This document applies to SAP ECC 6.0, SAP Netweaver 2004s. For more information, visit the Web Dynpro ABAP homepage.

First step to Understand a Payroll Schema

Data Extraction and Retraction in BPC-BI

This article demonstrates in a step-by-step process to write ABAP Reports that use BAPI function modules.

SAP CRM Middleware Configurations

Transcription:

A Wrapper to Call Dynamically Function via RFC Applies to: Any integration with SAP R/3 system and external applications. For more information, visit the ABAP homepage. Summary This article explains how to write a wrapper to call dynamically any function via RFC. Author: Oleg Zilin Company: Ozone Consulting JLLC, Republic of Belarus Created on: 20 August 2010 Author Bio Oleg Zilin started his IT career more than 30 years ago. He programmed with COBOL, Visual Basic, Delphi, and Java and long ago with FORTRAN for mainframes. He has been working with the SAP solutions since 2004. He has the experience in IT Services, Automotive, Electronics, Consumer Products, Manufacturing industries. At present he works for the company Ozone Consulting JLLC in Republic of Belarus as programmer analyst (ABAP4 Developer) 2010 SAP AG 1

Table of Contents Introduction... 3 We Create All Necessary Structures... 4 We Make the Interface of our Function... 6 We Write the Wrapper... 7 Example of Usage of the Wrapper... 9 Conclusion... 11 Related Content... 12 Disclaimer and Liability Notice... 13 2010 SAP AG 2

Introduction Once for me it was necessary to develop the program, this had to collect and process data from different ERP-systems. Here I used calls of functions via RFC. All functions had different interfaces. In order to facilitate the development, I decided to write a RFC wrapper for the dynamic call of functions. You can see the diagram of the wrapper below: We will transfer the parameters into our wrapper in this way: Input parameters - Internal tables - XML Xstring Flat structures - Xstring Output parameters - Internal tables - XML Xstring Flat structures - XML Xstring 2010 SAP AG 3

We Create All Necessary Structures As we know, as it is written in ABAP keyword documentation, function can be dynamically called in this way: DATA: func TYPE string, ptab TYPE abap_func_parmbind_tab, ptab_line TYPE abap_func_parmbind, etab TYPE abap_func_excpbind_tab, etab_line TYPE abap_func_excpbind. CALL FUNCTION func PARAMETER-TABLE ptab EXCEPTION-TABLE etab. Types for the call are: 2010 SAP AG 4

As we see, the basic difficulty for the use RFC-access is the type - ref to of data Therefore we will make our types: Finally, the type for the handling of the exceptions is: 2010 SAP AG 5

We Make the Interface of our Function Now we create RFC-function Z_RFC_FUNC_CALL with the interface: 2010 SAP AG 6

We Write the Wrapper This is the code of wrapper: FUNCTION Z_RFC_FUNC_CALL. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(IM_FNAME) TYPE RS38L_FNAM *" CHANGING *" VALUE(CH_PARAMETERS) TYPE ZRFC_PAR_T OPTIONAL *" VALUE(CH_ERR_MESSAGES) TYPE ZRFC_ERR_T OPTIONAL *" EXCEPTIONS *" FUNCTION_NOT_EXIST *" WRONG_DATA_IN_PARAMETERS *"---------------------------------------------------------------------- type-pools : abap. data : lt_para TYPE abap_func_parmbind_tab, ls_para TYPE abap_func_parmbind, lt_err TYPE abap_func_excpbind_tab, ls_err TYPE abap_func_excpbind, ld_dref TYPE REF TO data, ld_err TYPE REF TO data, ls_content TYPE string, lcl_conv TYPE REF TO cl_abap_conv_in_ce, lv_len TYPE i, lt_parameters TYPE zrfc_par_t, ls_parameters TYPE zrfc_par_s, lt_err_messages TYPE zrfc_err_t, ls_err_messages TYPE zrfc_err_s. field-symbols : <fs_para_s> TYPE abap_func_parmbind, <fs_err_s> TYPE abap_func_excpbind, <fs_rfc_par_s> TYPE zrfc_par_s, <fs_rfc_err_s> TYPE zrfc_err_s, <fs_any> TYPE any. * ---------------------------- * Check Name Of Function * ---------------------------- CALL FUNCTION 'FUNCTION_EXISTS' EXPORTING FUNCNAME = IM_FNAME EXCEPTIONS FUNCTION_NOT_EXIST = 1 OTHERS = 2. IF SY-SUBRC <> 0. message e651(fl) with im_fname raising function_not_exist. ENDIF. * ----------------------------- * Create Data according to type * ----------------------------- loop at CH_PARAMETERS assigning <fs_rfc_par_s>. TRY. if <fs_rfc_par_s>-par_kind = abap_func_tables. CREATE DATA ld_dref TYPE STANDARD TABLE OF (<fs_rfc_par_s>-par_type). else. CREATE DATA ld_dref TYPE (<fs_rfc_par_s>-par_type). endif. unassign <fs_any>. ASSIGN ld_dref->* TO <fs_any>. ls_para-value := ld_dref. 2010 SAP AG 7

if not <fs_rfc_par_s>-par_value is initial. * Read Internal Table TRY. CALL TRANSFORMATION ('ID') SOURCE XML <fs_rfc_par_s>-par_value RESULT tab = <fs_any>. * Read flat structure CATCH cx_transformation_error. lcl_conv := CL_ABAP_CONV_IN_CE=>CREATE( input = <fs_rfc_par_s>par_value ). lcl_conv->read( importing data = ls_content len = lv_len ). <fs_any> := ls_content. ENDTRY. endif. ls_para-kind := <fs_rfc_par_s>-par_kind. ls_para-name := <fs_rfc_par_s>-par_name. append ls_para to lt_para. CATCH cx_sy_create_data_error. message 'Parameters have a wrong data!' type 'E' raising wrong_data_in_parameters. ENDTRY. endloop. * Set Table Of Errors loop at CH_ERR_MESSAGES assigning <fs_rfc_err_s>. ls_err-value := <fs_rfc_err_s>-err_value. ls_err-name := <fs_rfc_err_s>-err_name. insert ls_err into table lt_err. endloop. * ---------------------------- * Start of Function * ---------------------------- call function IM_FNAME PARAMETER-TABLE lt_para EXCEPTION-TABLE lt_err. unassign: <fs_rfc_par_s>, <fs_rfc_err_s>, <fs_any>. * ---------------------------- * Return result * ---------------------------- loop at lt_para assigning <fs_para_s>. unassign <fs_any>. clear ls_parameters. * field 'par_value' ASSIGN <fs_para_s>-value->* TO <fs_any>. CALL TRANSFORMATION ('ID') SOURCE tab = <fs_any> RESULT XML ls_parameters-par_value. * field 'par_kind' ls_parameters-par_kind := <fs_para_s>-kind. * field 'par_name' ls_parameters-par_name := <fs_para_s>-name. * field 'par_type' read table ch_parameters assigning <fs_rfc_par_s> with key par_name = <fs_para_s>-name. ls_parameters-par_type := <fs_rfc_par_s>-par_type. 2010 SAP AG 8

append ls_parameters to lt_parameters. endloop. loop at lt_err assigning <fs_err_s>. * ERR_MESSAGE REF TO DATA (not yet at the moment). ls_err_messages-err_value := <fs_err_s>-value. ls_err_messages-err_name := <fs_err_s>-name. append ls_err_messages to lt_err_messages. endloop. CH_PARAMETERS[] := lt_parameters[]. CH_ERR_MESSAGES[] := lt_err_messages[]. ENDFUNCTION. Note: We used here Id transformation, but it s possible to write own format of the conversion of table into Xstring. Example of Usage of the Wrapper We will try to call the function "READ_SPFLI_INTO_TABLE". In this function Processing Type is Normal Function Module. It means that directly RFC-access is impossible, we call this function via our wrapper. This is an example of an ABAP4 code sample: *&---------------------------------------------------------------------* *& Report Z_RFC_START_FUNCTION *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT Z_RFC_START_FUNCT. type-pools : abap. data : lv_fname TYPE rs38l_fnam value 'READ_SPFLI_INTO_TABLE', lv_drfc TYPE rfcdisplay-rfctytext value 'type_our_destin', lt_parameters TYPE zrfc_par_t, ls_parameters TYPE zrfc_par_s, lt_err_mess TYPE zrfc_err_t, ls_err_mess TYPE zrfc_err_s, lv_carrier TYPE string, lt_spfli TYPE spfli_tab, ls_content TYPE string, lcl_conv TYPE REF TO cl_abap_conv_in_ce, lv_len TYPE i, ls_carrid TYPE spfli-carrid. start-of-selection. * ------------------------- * Set parameter 1 - 'ID' * ------------------------- lv_carrier = 'LH'. ls_parameters-par_name = 'ID'. ls_parameters-par_kind = ABAP_FUNC_EXPORTING. CALL FUNCTION 'SCMS_STRING_TO_XSTRING' EXPORTING TEXT = lv_carrier IMPORTING BUFFER = ls_parameters-par_value. 2010 SAP AG 9

ls_parameters-par_type = 'SPFLI-CARRID'. append ls_parameters to lt_parameters. * -------------------------- * Set parameter 2 - 'ITAB' * -------------------------- ls_parameters-par_name = 'ITAB'. ls_parameters-par_kind = ABAP_FUNC_IMPORTING. CALL TRANSFORMATION ('ID') SOURCE tab = lt_spfli RESULT XML ls_parameters-par_value. ls_parameters-par_type = 'SPFLI_TAB'. append ls_parameters to lt_parameters. * --------------------------- * The possible exceptions * --------------------------- ls_err_mess-err_name = 'NOT_FOUND'. ls_err_mess-err_value = 1. insert ls_err_mess into table lt_err_mess. ls_err_mess-err_name = 'OTHERS'. ls_err_mess-err_value = 4. insert ls_err_mess into table lt_err_mess. CALL FUNCTION 'Z_RFC_FUNC_CALL' destination lv_drfc EXPORTING IM_FNAME = lv_fname CHANGING CH_PARAMETERS = lt_parameters CH_ERR_MESSAGES = lt_err_mess EXCEPTIONS FUNCTION_NOT_EXIST = 1 WRONG_DATA_IN_PARAMETERS = 2 OTHERS = 3. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. * -------------------------- * Read parameter 1 - 'ID' * -------------------------- read table lt_parameters into ls_parameters with key par_name = 'ID'. TRY. CALL TRANSFORMATION ('ID') SOURCE XML ls_parameters-par_value RESULT tab = ls_carrid. CATCH cx_transformation_error. message 'Parameters have a wrong data!' TYPE 'I'. Endtry. * -------------------------- * Read parameter 2 - 'ITAB' * -------------------------- read table lt_parameters into ls_parameters 2010 SAP AG 10

with key par_name = 'ITAB'. TRY. CALL TRANSFORMATION ('ID') SOURCE XML ls_parameters-par_value RESULT tab = lt_spfli. CATCH cx_transformation_error. message 'Parameters have a wrong data!' TYPE 'I'. Endtry. The result of calling you can see in the internal table lt_spfli. Conclusion Thus we can call dynamically practically any function. 2010 SAP AG 11

Related Content SCN ABAP Articles For more information, visit the ABAP homepage. 2010 SAP AG 12

Disclaimer and Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade. SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk. SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document. 2010 SAP AG 13