rfcs and bapis

18
RFC (Remote Function calls)  RFC allows for remote calls between two SAP Systems (R/3 or R/2), or between an SAP System and a non-SAP System.  The called function can run in a different system on a different machine in the network.  The remote function can also be called from within the same system (as a remote call).  RFC consists of two interfaces: A calling interface for ABAP Programs and a calling interface for Non-SAP programs.  Any ABAP program can call a remote function using the CALL FUNCTION...DESTINATION statement.  The DESTINATION parameter tells the SAP System t hat the called function runs in a system other than the caller's.  You can use the CALL F UNCTION statement to call remote functions by including an additional DESTINATION clause.  CALL FUNCTION ‘remote function DESTINATION dest EXPORTING f1 = IMPORTING f2 = TABLES t1 = EXCEPTIONS  The field ‘dest’ can be either a literal or a variable. Logical destinations are defined in the RFCDES table via transaction SM59 or via the menu path: Tools ->Administration, Administration->Network->RFC destinations. Types of RFC’s  Synchronous RFC(Default type)    o The calling program continues the execution only after t he called function is complete. o Eg: CALL FUNCTION ‘ remote function’ destination ‘XXXX’  Asynchronous RFC   o The calling program continues the execution without waiting for return from the called function. o Eg: CALL FUNCTION ‘remotefunction’ STARTING NEW TASK ‘taskname’.   Transactional RFC   o The called function module is executed exactly once in the RFC server system. Each function call is seen as a transaction in the target system. Transactional RFCs use the suffix IN BACKGROUND TASK. o Eg : CALL FUNCTION ‘remotefunction’ IN BACKGROUND TASK  

Upload: piyush658

Post on 04-Jun-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 1/18

RFC (Remote Function calls)

  RFC allows for remote calls between two SAP Systems (R/3 or R/2), or between an SAP System

and a non-SAP System.

  The called function can run in a different system on a different machine in the network.

  The remote function can also be called from within the same system (as a remote call).

  RFC consists of two interfaces: A calling interface for ABAP Programs and a calling interface for

Non-SAP programs.

  Any ABAP program can call a remote function using the CALL FUNCTION...DESTINATION

statement.

  The DESTINATION parameter tells the SAP System that the called function runs in a system other

than the caller's.

  You can use the CALL FUNCTION statement to call remote functions by including an additional

DESTINATION clause.  CALL FUNCTION ‘remote function’ 

DESTINATION dest

EXPORTING f1 =

IMPORTING f2 =

TABLES t1 =

EXCEPTIONS 

  The field ‘dest’ can be either a literal or a variable. Logical destinations are defined in the

RFCDES table via transaction SM59 or via the menu path: Tools ->Administration,

Administration->Network->RFC destinations. 

Types of RFC’s 

  Synchronous RFC(Default type)  – 

o  The calling program continues the execution only after the called function is complete.

o  Eg: CALL FUNCTION ‘remote function’ destination ‘XXXX’ 

  Asynchronous RFC  – 

o  The calling program continues the execution without waiting for return from the called

function.

o  Eg: CALL FUNCTION ‘remotefunction’ STARTING NEW TASK ‘taskname’. 

  Transactional RFC  – 

o  The called function module is executed exactly once in the RFC server system. Each

function call is seen as a transaction in the target system. Transactional RFCs use the

suffix IN BACKGROUND TASK.

o  Eg : CALL FUNCTION ‘remotefunction’ IN BACKGROUND TASK 

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 2/18

Writing remote function modules

  In the function module attributes tab (transaction code SE37), set the processing type as

Remote-enabled module to create a remote function module.

  Write the code for the function module in Source code tab.

  Define the destination of the RFC server in the RFC client system that calls the remote function

(via SM59 transaction).

  It is not possible to debug a remote function call to another system.

  Declaring Parameters: 

o  All parameter fields for a remote function module must be defined as reference fields,

that is, like ABAP Dictionary fields.

  Exceptions: 

o  The system raises COMMUNICATION_FAILURE and SYSTEM_FAILURE internally.

o  You can raise exceptions in a remote function just as you would in a locally called

function.

o  SYSTEM_FAILURE: This exception reports all failures and system problems on theremote machine.

o  COMMUNICATION_FAILURE: This exception is raised when a connection or

communications failure occurs. It does not report system problems (for example,

abnormal termination) that occur on the remote machine.

BAPI’s (Business Application Programming Interface)

  BAPIs are standardized programming interfaces (methods) enabling external applications to

access business processes and data in the R/3 System.

  BAPIs provide stable and standardized methods to achieve seamless integration between the

R/3 System and external applications, legacy systems and add-ons.

  BAPIs are defined in the BOR (Business object repository) as methods of SAP business object

types that carry out specific business functions.

  BAPI’s are based on Function modules that are RFC enabled.  

  BAPIs are implemented as RFC-enabled function modules and are created in the Function

Builder of the ABAP Workbench.

  Transaction code  – BAPI.

Working with BAPI’s 

  There are 2 methods of accessing BAPI.

o  Object –Oriented Access -

  Uses Object-oriented method calls from BAPI’s in the BOR. 

o  Function – Oriented access -

  Uses RFC calls to function modules. BAPI’s are based on Function modules that

are RFC enabled.

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 3/18

  BAPI’ can be accessed by two types of applications.

o  Dialog application-

  Calls a BAPI and waits for results as the BAPI is processed.

o  Distributed application-

  Uses ALE to exchange and replicate data between distributed systems.

BAPI Explorer- (Transaction: - BAPI)

  The BAPI Explorer is the R/3 System working environment for developing BAPIs.

  A BAPI interface is defined by:

o  Import parameters

o  Export parameters

o  Import/export (table) parameters

  Each function module underlying a BAPI:

o  Supports the Remote Function Call (RFC) protocol.

o  Has been assigned as a method to an SAP Business Object in the BOR.

o  Is processed without returning any screen dialogs to the calling application.

BAPI Programming

  The process of defining and implementing a BAPI consists of the following steps:

o  Firstly, we describe the scenario the BAPI is to be used in.

o  The BAPI concept and scenario is reviewed.

o  The BAPI and its interface is defined.

o  The individual programming objects for BAPI are created.

o  The BAPI is tested.

o  The BAP is released and frozen for further use.

  Some BAPIs and methods provide basic functions and can be used for most SAP Business

Objects. These are called STANDARDIZED BAPI’s.

Standardized BAPIs

  BAPIs for Reading Data 

o  GetList() ,

o  GetDetail() ,

o  GetStatus() ,

o  ExistenceCheck()

  BAPIs for Creating or Changing Data 

o  Create() or CreateFromData(),

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 4/18

o  Change(),

o  Delete()

o  Undelete()

  BAPIs for Mass Processing 

o  ChangeMultiple(),

o  CreateMultiple(),

o  DeleteMultiple().

  BAPIs for Replicating Business Object Instances 

o  Replicate() SaveReplica()

Creating a BAPI

  Go to transaction swo1.

  Select the business object (Generally of type BUS nnnn), according to the functional

requirement for which the BAPI is being created.

 Open the business object in change mode. Then Select Utilities -> API Methods ->Add method. 

  Then enter the name of the function module and select Continue.

  In the next dialog box, following information needs to be specified :

Method: Suggest an appropriate name for the method,

Texts: Enter description for the BAPI,

Radio buttons: Dialog, Synchronous, Instance-independent . BAPI ‘s are usually

implemented synchronously.

Now, select Next step.

  To create the method select Yes in the next dialog box.

  After the program has been generated and executed, check the program in the method just

created  Thus, a BAPI is created.

Testing the BAPI

  You can test the BAPI by testing the individual method of the Business Object in the Business

Object Builder.

  OR one can use the transaction ‘swud’ to test the method.

Releasing and freezing the BAPI

  To release the BAPI , first release the function module ( using transaction se37 )

  Set the status of the method to 'released' in the Business Object Builder. ( using transaction

swo1 – Edit-> change status-> released. )

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 5/18

 

Custom BAPI Implementation

Create the Structure

  Go to transaction SE11 and create a structure as shown or as per your requirement.

And give the name in the Data type field and click create button.

  In the pop-up that comes up, select the radio button “structure”. 

  In the components tab of the structure, give the different fields and their

corresponding field types and press enter to check the compatibility.

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 6/18

 

  Save it in  package and activate the same.

Creating BAPI Function Module

  Go to transaction SE37 where you create function modules. Click on create after you

enter the name of the Function module.

  A screen as shown above would pop-up where you mention the function group to

save the function module and also provide some short text describing your function

module.

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 7/18

   In the next pop-up that follows, click on continue as shown above.

  Go to the Attributes tab and select the radio button reading “remote-enabled

module”. Come back to the imports tab and provide the import parameters as shown

or as per your requirement.

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 8/18

  Now in the Export tab, provide the export parameters as shown or as per your

requirement.

  In the tables tab, provide the information as shown or as per your requirement.

  The next screen you visit is the source code. It would look like this.

  After successful activation, go to the attributes tab. Go to Function

moduleReleaseRelease.

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 9/18

 

Defining BAPI Methods In the BOR

  Go to transaction swo1 and enter the name of the BAPI you would like to create or

as shown in the screen and click the create button.

  Give the name of the BAPI as above and click on create.

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 10/18

 

  Give the above-mentioned details and click on the continue icon.

  The resulting screen is as follows.

  Now click on the methods to drop down and see what methods are provided by

default. There would be two methods, showing in red color which comes by default

while creating the BAPI.

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 11/18

 

  Give the Function module name.

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 12/18

 In the ultimate pop-up, click the next step icon. We observe that the information is

predefined in the fields

  This is the next screen where you would just click on the “next” icon. 

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 13/18

 

  Click on “Yes”. You can see an information message reading “ZBAPIFMWBS”

inserted.

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 14/18

  Now save after you add the method. Select & Double click on the API method.

  Go to: EditChange Release StatusObject type To Modeled.

 The message shows, the object type status set to modeled. (or already modeled)

  Go to: EditChange Release StatusObject type Component  To Implemented.

You can see a message reading “Object type status set to implemented”  

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 15/18

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 16/18

  Now go to BAPI T-code (BAPI) we can find the BAPI (our BAPI)

  The BAPI browser would look like the screen below.

  You can click on the Alphabetical tab so that you can browse the BAPI’s in an

alphabetical order. Find your BAPI as shown below.

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 17/18

Testing the BAPI

8/13/2019 Rfcs and Bapis

http://slidepdf.com/reader/full/rfcs-and-bapis 18/18

Can see the result as below.