SlideShare a Scribd company logo
Compiled by Y R Nagesh 1
BAPI
Business Application Programming Interface
Compiled by Y R Nagesh 2
What is BAPI
A Business Application Programming Interface is a
precisely defined interface providing access process
and data in Business Applications Systems Such as
SAP R/3
Compiled by Y R Nagesh 3
Benefits of BAPI
Can be used in diverse languages / Development Environments
(ABAP, Visual Basic, Java, C++, etc.)
Can be called from diverse platforms (COM, CORBA, Unix)
Reduced development cost
Reduced maintenance cost
“Best-of-both-worlds” approach
Rich functionality of the R/3 system
User-specific front-ends
Compiled by Y R Nagesh 4
Where BAPIs can be used
Compiled by Y R Nagesh 5
Return Code Information
Usually a structure, sometimes a table
Data dictionary structures used
BAPIRETURN
BAPIRETURN1
BAPIRET1
BAPIRET2
Compiled by Y R Nagesh 6
BAPI Return Structure
Type Message type
blank or "S"=Success
"E"=Error
"W"=Warning
"I"=Information
"A"=Abort
Message Message text
Log_No Application Log Number
Log_Msg_No Application Log Message Serial Number
Message_V1 - V4 Message variables
Compiled by Y R Nagesh 7
SAP transactions
BAPI Business Object Browser (BAPIs only)
SWO1 Business Object Builder (all objects)
SWO2 Business Object Browser (all objects)
SE11 Data Dictionary
SE37 Function Builder
Compiled by Y R Nagesh 8
JCO Overview
High-performance JNI-based middleware
Support R/3 3.1H and higher.
Supports inbound and outbound calls.
Supports client pooling.
Supports desktop and web/application server applications.
Multi-platform
Complete and correct code page handling
Easy to install and deploy
Compiled by Y R Nagesh 9
Installation and Deployment
Required files in WINNTsystem32:
librfc32.dll (at least 46D, build 263)
jRFC11.dll (JDK 1.1)
jRFC12.dll (JDK 1.2 and 1.3)
Required files in Java class path:
jCO.jar
Compiled by Y R Nagesh 10
BAPI step by step procedure
STEP 1 - Define Structure For The BAPI
STEP 2 - Write Function Module
STEP 3 - Create the API Method Using The BAPI WIZARD
STEP 4 – Final Steps
Compiled by Y R Nagesh 11
About the Example
About the Example:
Front End : Java Servlets (Web Application)
Web Server : Apache Tomcat
The Servlet takes Vendor number and passes it to the BAPI which
in turn fetches the Vendor information from the LFA1 table and
returns it in BAPIRET2 format to the servlet, the servlet fetches the
data from return structure and displays it.
Compiled by Y R Nagesh 12
Step 1 : Define a Structure for BAPI
In this step structures for the parameters and tables of the
function module used for the BAPI are defined.
USE TCODE : SE11 then Data type -> Structure
Define the structure Name : Ex: ZVEND
Important note: You will have to define a structure for
every parameter in the BAPI. You cannot use the same
structures used in existing applications because BAPI
structures are frozen when BAPIs are released and then
there are restrictions on changing them.
Compiled by Y R Nagesh 13
Creating a Structure
Enter the
Structure
name
Click on Create
Button
Compiled by Y R Nagesh 14
Creating a Structure
Select
Structure
Click on
Check Button
Compiled by Y R Nagesh 15
Creating a Structure
Activate the
Structure
Compiled by Y R Nagesh 16
Step 2 : Write Function Module
Each BAPI must have its own function group.
Under the attributes tab remember to select Processing Type Remote
Enabled module, otherwise the function module cannot be invoked via
RFC and used as a BAPI
Import/Export parameters can only be BY VALUE for an RFC enabled
function module
Compiled by Y R Nagesh 17
Creating Function group
Compiled by Y R Nagesh 18
Creating Function group
Compiled by Y R Nagesh 19
Creating Function module
Click on
Create
Click on Save
Compiled by Y R Nagesh 20
Creating Function module
Make the function
Remote Enabled
Compiled by Y R Nagesh 21
Creating Function module
Import Parameters
Check
“ Pass Value”
Compiled by Y R Nagesh 22
Creating Function module
Tables
Compiled by Y R Nagesh 23
Creating Function module
Source Code
Compiled by Y R Nagesh 24
Creating Function module
Activate Function Module
Activate
Compiled by Y R Nagesh 25
Releasing Function module
Release the Function Module
Compiled by Y R Nagesh 26
Step 2 : Create the API Method Using
The BAPI WIZARD
BAPI wizard is used to expose the remote function module as a BAPI
Wizard will generate some additional code, so the function module is a valid
method of the BOR. This allows the BAPI to be called as a workflow method
in addition to be called by an outside program.
Each function module corresponds to a method in the BOR
Go to the Business Object Builder SWO1.
You can either create the new Object type as a subtype of an existing business
object or create a new business object from scratch..
Compiled by Y R Nagesh 27
Create new BAPI Object
USE TCODE
SWO1
Supertype not
required as we are
creating a new Object
* for Cross
Apps
Compiled by Y R Nagesh 28
Create new BAPI Object
Note that when you create the business object a standard
interface, an attribute ObjectType and the methods
ExistenceCheck and Display are automatically generated.
These cannot be changed !
Compiled by Y R Nagesh 29
Adding API method
Compiled by Y R Nagesh 30
Adding API method
Click
here
Compiled by Y R Nagesh 31
Adding API method
Compiled by Y R Nagesh 32
Adding API method
Click Yes
API method
added
Compiled by Y R Nagesh 33
Implementing BAPI Object
Select the BAPI object
Compiled by Y R Nagesh 34
Implementing BAPI Object
Change release status To implemented
Compiled by Y R Nagesh 35
Releasing BAPI Object
Change release status To released
Compiled by Y R Nagesh 36
Implementing API Method
Select the API Method
Compiled by Y R Nagesh 37
Implementing API Method
Change release status To implemented
Compiled by Y R Nagesh 38
Releasing API Method
Change release status To released
Compiled by Y R Nagesh 39
Generating API Method
Click on Generate
Button
Compiled by Y R Nagesh 40
Configuring Apache Tomcat
Directory Structure
Jakarta-tomcat-4.1.31
Webapps
<User Folder> (Vendor)
WEB-INF
classes
lib
Web.xml
Index.html
Compiled by Y R Nagesh 41
Configuring Apache Tomcat
classes
This folder contains all the class files created for successful execution
of the servlet.
lib
This folder contains all the library files required i.e
sapjco.jar
servlet.jar
Note: While compiling the java code make sure that the Classpath is set to the above to .jar files
Compiled by Y R Nagesh 42
Configuring Apache Tomcat
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee“
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd“ version="2.4">
<servlet>
<servlet-name>Some internal name</servlet-name>
<servlet-class>display_vend</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Some internal name</servlet-name>
<url-pattern>/NameSeenByUser.do</url-pattern>
</servlet-mapping>
</web-app>
Servlet name
Web.xml
Compiled by Y R Nagesh 43
Servlet Program
import statements required
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.sap.mw.jco.*;
Compiled by Y R Nagesh 44
Servlet Program
public class display_vend extends HttpServlet
{
PrintWriter pw;
public void doPost(HttpServletRequest req, HttpServletResponse res)
{ int num = Integer.parseInt(req.getParameter("rand"));
String no,name,city,district,po,tele,fax;
String SID = "R"+num;
String vendno = req.getParameter("vendno");
IRepository repository; // The repository we will be using
try {
// Add a connection pool to the specified system
JCO.addClientPool(SID, 100, "800", "hari", "sapnjoy", "EN", "sapides", "00” );
// Alias for this pool , Max. number of connections , SAP client , userid
// password , language , host name
Unique name for
connection pool each
time connection is
established random
number is generated in
the index.html i.e
starting page and
value is passed to
servlet
Compiled by Y R Nagesh 45
Servlet Program
repository = JCO.createRepository("MYRepository", SID); // Create a new repository
// Get a function template from the repository
IFunctionTemplate ftemplate = repository.getFunctionTemplate("ZVENDFUN");
// Create a function from the template
JCO.Function function = new JCO.Function(ftemplate);
JCO.Client client = JCO.getClient(SID); // Get a client from the pool
JCO.ParameterList input = function.getImportParameterList(); // Fill in input parameters
input.setValue(vendno, "LIFNR" );
client.execute(function); // Call the remote system
JCO.Structure ret = function.getExportParameterList().getStructure("RETURN");
pw = res.getWriter();
pw.println("<html><body bgcolor=#eeeff8><center><hr><h1>Customer Details</h1><hr>");
// Get table containing the data
JCO.Table vend = function.getTableParameterList().getTable("ITAB");
Compiled by Y R Nagesh 46
Servlet Program
for (int i = 0; i < vend.getNumRows(); i++)
{
vend.setRow(i);
no = vend.getString("LIFNR");
name = vend.getString("NAME1");
city = vend.getString("ORT01") ;
district = vend.getString("ORT02") ;
po = vend.getString("PFACH") ;
tele = vend.getString("TELF1") ;
fax = vend.getString("TELFX") ;
// Fetching data from SAP database and storing in local variables
Compiled by Y R Nagesh 47
Servlet Program
pw.println("<table border=1><tr><td><B>Vendor Number</B></td><td>"+no+ "</td></tr><tr><td>" +
"<B>Customer Name</B></td><td>"+name+ "</td></tr><tr><td>" +
"<B>Customer Address</B></td><td></tr>"+
"<tr><td> </td><td><B>City</B></td><td>"+city+"</td></tr>" +
"<tr><td> </td><td><B>District</B></td><td>"+district+"</td></tr>"+
"<tr><td> </td><td><B>PO Box</B></td><td>"+po+"</td></tr>"+
"<tr><td><B>Telephone</B></td><td>"+tele+"</td></tr>"+
"<tr><td><B>TeleFax</B></td><td>"+fax+"</td></tr></table>" );
pw.println("<form name=form1 action='index.html' method=get><input type=submit
value='Back'></form></center></body></html>"); } }
catch (Exception E)
{
System.out.println(E);
}
} }
Compiled by Y R Nagesh 48
Index.html
<html>
<head><script language="JavaScript">
function randomnumber() {
var r=Math.floor(Math.random()*1111)
if (r!=0) document.form1.rand.value=r; }
</script>
</head>
<body bgcolor=#eeeff8 onLoad="javascript:randomnumber();">
<center><hr><h1>Enter the Vendor Number</h1><hr>
</center><form name=form1 action="NameSeenByUser.do" method=post>
<center><input type=text name=vendno>
<input type=submit value="Submit">
<input type=hidden name="rand"></center>
</form></body></html>
Compiled by Y R Nagesh 49
Output
Compiled by Y R Nagesh 50
Output

More Related Content

PDF
Bapi step-by-step
DOC
Bapi programming
PDF
Enhancing data sources with badi in SAP ABAP
PDF
Step by step procedure for loading of data from the flat file to the master d...
PDF
Hadoop + Forcedotcom = Like
PDF
Work status illustrated
PDF
BPC Session1
PDF
T4 web dynpro for abap - display bookings for selected flights
Bapi step-by-step
Bapi programming
Enhancing data sources with badi in SAP ABAP
Step by step procedure for loading of data from the flat file to the master d...
Hadoop + Forcedotcom = Like
Work status illustrated
BPC Session1
T4 web dynpro for abap - display bookings for selected flights

What's hot (20)

PDF
Technical Overview of CDS View - SAP HANA Part II
PPTX
LeverX SAP ABAP Tutorial - Creating and Calling Web Services
PDF
BPC Configuration and User Guide Ver 10.0
PDF
Fm extraction
PDF
Abap sample
PDF
Variables in sap bi
PDF
News in abap concepts to further increase the power of abap development
PDF
Start learning sap bpc by yourself
PDF
Abap proxies
PDF
SAP LSMW - Direct input approach v2.5 by Pavan Golesar
PPT
Sap BPC concepts
PDF
Getting Started with FDMEE
PDF
Bpc 10.1 unified training
PPT
Differences R12 Vs 11i.5.10
PDF
XLSX Upload - IN SAP GUI and WDA
PDF
Technical Overview of CDS View – SAP HANA Part I
PDF
SUSE Technical Webinar: Build B1 apps in the Framework of the SAP and SUSE Ca...
PPT
New Enhancements + Upgrade Path to Oracle EBS R12.1.3
PDF
Sap cloud platform rebranding
PDF
Data extraction and retraction in bpc bi
Technical Overview of CDS View - SAP HANA Part II
LeverX SAP ABAP Tutorial - Creating and Calling Web Services
BPC Configuration and User Guide Ver 10.0
Fm extraction
Abap sample
Variables in sap bi
News in abap concepts to further increase the power of abap development
Start learning sap bpc by yourself
Abap proxies
SAP LSMW - Direct input approach v2.5 by Pavan Golesar
Sap BPC concepts
Getting Started with FDMEE
Bpc 10.1 unified training
Differences R12 Vs 11i.5.10
XLSX Upload - IN SAP GUI and WDA
Technical Overview of CDS View – SAP HANA Part I
SUSE Technical Webinar: Build B1 apps in the Framework of the SAP and SUSE Ca...
New Enhancements + Upgrade Path to Oracle EBS R12.1.3
Sap cloud platform rebranding
Data extraction and retraction in bpc bi
Ad

Viewers also liked (6)

DOCX
Idocs tcodes and others , sap idoc
DOCX
Edit idoc , reprocess and test idoc
PDF
PPT
IDOC , ALE ,EDI
PPT
Sap abap ale idoc
PDF
SAP IDoc
Idocs tcodes and others , sap idoc
Edit idoc , reprocess and test idoc
IDOC , ALE ,EDI
Sap abap ale idoc
SAP IDoc
Ad

Similar to Bapi jco (20)

PDF
Bapi jco[1]
DOCX
Functional module
PPTX
SAP Tips and Tricks for Automation Developers from ABAP Developer
PDF
Step by-step creation of a bapi in detailed steps with scr…
PDF
Integrating SAP and Low-Code Plaforms
PPT
Salesforce and sap integration
DOCX
Sap index
PPT
Abap course chapter 7 abap objects and bsp
PPT
PPTX
API Management
PDF
REST - What's It All About? (SAP TechEd 2012, CD110)
PDF
Create and Manage APIs with API Connect, Swagger and Bluemix
PDF
SAP NetWeaver Gateway - RFC & BOR Generators
PPTX
SAP Cloud Platform API Management Technical Brief
PDF
A Collection of Real World (JavaScript) Security Problems: Examples from 2 1/...
PDF
Introduction to API
PDF
What Makes a Great Open API?
PDF
End to-end sap fiori extensibility use case
PPTX
UDDI from JAVA Web services
PDF
Z sap boe-2016-techws-04_vs_fiori-app-with-eclipseluna-accessing-zsap-system
Bapi jco[1]
Functional module
SAP Tips and Tricks for Automation Developers from ABAP Developer
Step by-step creation of a bapi in detailed steps with scr…
Integrating SAP and Low-Code Plaforms
Salesforce and sap integration
Sap index
Abap course chapter 7 abap objects and bsp
API Management
REST - What's It All About? (SAP TechEd 2012, CD110)
Create and Manage APIs with API Connect, Swagger and Bluemix
SAP NetWeaver Gateway - RFC & BOR Generators
SAP Cloud Platform API Management Technical Brief
A Collection of Real World (JavaScript) Security Problems: Examples from 2 1/...
Introduction to API
What Makes a Great Open API?
End to-end sap fiori extensibility use case
UDDI from JAVA Web services
Z sap boe-2016-techws-04_vs_fiori-app-with-eclipseluna-accessing-zsap-system

Recently uploaded (20)

PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
Soil Improvement Techniques Note - Rabbi
PPTX
Artificial Intelligence
PDF
August 2025 - Top 10 Read Articles in Network Security & Its Applications
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PPTX
Fundamentals of Mechanical Engineering.pptx
PDF
Abrasive, erosive and cavitation wear.pdf
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PPTX
communication and presentation skills 01
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PPTX
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
Categorization of Factors Affecting Classification Algorithms Selection
Soil Improvement Techniques Note - Rabbi
Artificial Intelligence
August 2025 - Top 10 Read Articles in Network Security & Its Applications
Exploratory_Data_Analysis_Fundamentals.pdf
Fundamentals of Mechanical Engineering.pptx
Abrasive, erosive and cavitation wear.pdf
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
communication and presentation skills 01
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
Management Information system : MIS-e-Business Systems.pptx
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
Automation-in-Manufacturing-Chapter-Introduction.pdf
Nature of X-rays, X- Ray Equipment, Fluoroscopy

Bapi jco

  • 1. Compiled by Y R Nagesh 1 BAPI Business Application Programming Interface
  • 2. Compiled by Y R Nagesh 2 What is BAPI A Business Application Programming Interface is a precisely defined interface providing access process and data in Business Applications Systems Such as SAP R/3
  • 3. Compiled by Y R Nagesh 3 Benefits of BAPI Can be used in diverse languages / Development Environments (ABAP, Visual Basic, Java, C++, etc.) Can be called from diverse platforms (COM, CORBA, Unix) Reduced development cost Reduced maintenance cost “Best-of-both-worlds” approach Rich functionality of the R/3 system User-specific front-ends
  • 4. Compiled by Y R Nagesh 4 Where BAPIs can be used
  • 5. Compiled by Y R Nagesh 5 Return Code Information Usually a structure, sometimes a table Data dictionary structures used BAPIRETURN BAPIRETURN1 BAPIRET1 BAPIRET2
  • 6. Compiled by Y R Nagesh 6 BAPI Return Structure Type Message type blank or "S"=Success "E"=Error "W"=Warning "I"=Information "A"=Abort Message Message text Log_No Application Log Number Log_Msg_No Application Log Message Serial Number Message_V1 - V4 Message variables
  • 7. Compiled by Y R Nagesh 7 SAP transactions BAPI Business Object Browser (BAPIs only) SWO1 Business Object Builder (all objects) SWO2 Business Object Browser (all objects) SE11 Data Dictionary SE37 Function Builder
  • 8. Compiled by Y R Nagesh 8 JCO Overview High-performance JNI-based middleware Support R/3 3.1H and higher. Supports inbound and outbound calls. Supports client pooling. Supports desktop and web/application server applications. Multi-platform Complete and correct code page handling Easy to install and deploy
  • 9. Compiled by Y R Nagesh 9 Installation and Deployment Required files in WINNTsystem32: librfc32.dll (at least 46D, build 263) jRFC11.dll (JDK 1.1) jRFC12.dll (JDK 1.2 and 1.3) Required files in Java class path: jCO.jar
  • 10. Compiled by Y R Nagesh 10 BAPI step by step procedure STEP 1 - Define Structure For The BAPI STEP 2 - Write Function Module STEP 3 - Create the API Method Using The BAPI WIZARD STEP 4 – Final Steps
  • 11. Compiled by Y R Nagesh 11 About the Example About the Example: Front End : Java Servlets (Web Application) Web Server : Apache Tomcat The Servlet takes Vendor number and passes it to the BAPI which in turn fetches the Vendor information from the LFA1 table and returns it in BAPIRET2 format to the servlet, the servlet fetches the data from return structure and displays it.
  • 12. Compiled by Y R Nagesh 12 Step 1 : Define a Structure for BAPI In this step structures for the parameters and tables of the function module used for the BAPI are defined. USE TCODE : SE11 then Data type -> Structure Define the structure Name : Ex: ZVEND Important note: You will have to define a structure for every parameter in the BAPI. You cannot use the same structures used in existing applications because BAPI structures are frozen when BAPIs are released and then there are restrictions on changing them.
  • 13. Compiled by Y R Nagesh 13 Creating a Structure Enter the Structure name Click on Create Button
  • 14. Compiled by Y R Nagesh 14 Creating a Structure Select Structure Click on Check Button
  • 15. Compiled by Y R Nagesh 15 Creating a Structure Activate the Structure
  • 16. Compiled by Y R Nagesh 16 Step 2 : Write Function Module Each BAPI must have its own function group. Under the attributes tab remember to select Processing Type Remote Enabled module, otherwise the function module cannot be invoked via RFC and used as a BAPI Import/Export parameters can only be BY VALUE for an RFC enabled function module
  • 17. Compiled by Y R Nagesh 17 Creating Function group
  • 18. Compiled by Y R Nagesh 18 Creating Function group
  • 19. Compiled by Y R Nagesh 19 Creating Function module Click on Create Click on Save
  • 20. Compiled by Y R Nagesh 20 Creating Function module Make the function Remote Enabled
  • 21. Compiled by Y R Nagesh 21 Creating Function module Import Parameters Check “ Pass Value”
  • 22. Compiled by Y R Nagesh 22 Creating Function module Tables
  • 23. Compiled by Y R Nagesh 23 Creating Function module Source Code
  • 24. Compiled by Y R Nagesh 24 Creating Function module Activate Function Module Activate
  • 25. Compiled by Y R Nagesh 25 Releasing Function module Release the Function Module
  • 26. Compiled by Y R Nagesh 26 Step 2 : Create the API Method Using The BAPI WIZARD BAPI wizard is used to expose the remote function module as a BAPI Wizard will generate some additional code, so the function module is a valid method of the BOR. This allows the BAPI to be called as a workflow method in addition to be called by an outside program. Each function module corresponds to a method in the BOR Go to the Business Object Builder SWO1. You can either create the new Object type as a subtype of an existing business object or create a new business object from scratch..
  • 27. Compiled by Y R Nagesh 27 Create new BAPI Object USE TCODE SWO1 Supertype not required as we are creating a new Object * for Cross Apps
  • 28. Compiled by Y R Nagesh 28 Create new BAPI Object Note that when you create the business object a standard interface, an attribute ObjectType and the methods ExistenceCheck and Display are automatically generated. These cannot be changed !
  • 29. Compiled by Y R Nagesh 29 Adding API method
  • 30. Compiled by Y R Nagesh 30 Adding API method Click here
  • 31. Compiled by Y R Nagesh 31 Adding API method
  • 32. Compiled by Y R Nagesh 32 Adding API method Click Yes API method added
  • 33. Compiled by Y R Nagesh 33 Implementing BAPI Object Select the BAPI object
  • 34. Compiled by Y R Nagesh 34 Implementing BAPI Object Change release status To implemented
  • 35. Compiled by Y R Nagesh 35 Releasing BAPI Object Change release status To released
  • 36. Compiled by Y R Nagesh 36 Implementing API Method Select the API Method
  • 37. Compiled by Y R Nagesh 37 Implementing API Method Change release status To implemented
  • 38. Compiled by Y R Nagesh 38 Releasing API Method Change release status To released
  • 39. Compiled by Y R Nagesh 39 Generating API Method Click on Generate Button
  • 40. Compiled by Y R Nagesh 40 Configuring Apache Tomcat Directory Structure Jakarta-tomcat-4.1.31 Webapps <User Folder> (Vendor) WEB-INF classes lib Web.xml Index.html
  • 41. Compiled by Y R Nagesh 41 Configuring Apache Tomcat classes This folder contains all the class files created for successful execution of the servlet. lib This folder contains all the library files required i.e sapjco.jar servlet.jar Note: While compiling the java code make sure that the Classpath is set to the above to .jar files
  • 42. Compiled by Y R Nagesh 42 Configuring Apache Tomcat <?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee“ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd“ version="2.4"> <servlet> <servlet-name>Some internal name</servlet-name> <servlet-class>display_vend</servlet-class> </servlet> <servlet-mapping> <servlet-name>Some internal name</servlet-name> <url-pattern>/NameSeenByUser.do</url-pattern> </servlet-mapping> </web-app> Servlet name Web.xml
  • 43. Compiled by Y R Nagesh 43 Servlet Program import statements required import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import com.sap.mw.jco.*;
  • 44. Compiled by Y R Nagesh 44 Servlet Program public class display_vend extends HttpServlet { PrintWriter pw; public void doPost(HttpServletRequest req, HttpServletResponse res) { int num = Integer.parseInt(req.getParameter("rand")); String no,name,city,district,po,tele,fax; String SID = "R"+num; String vendno = req.getParameter("vendno"); IRepository repository; // The repository we will be using try { // Add a connection pool to the specified system JCO.addClientPool(SID, 100, "800", "hari", "sapnjoy", "EN", "sapides", "00” ); // Alias for this pool , Max. number of connections , SAP client , userid // password , language , host name Unique name for connection pool each time connection is established random number is generated in the index.html i.e starting page and value is passed to servlet
  • 45. Compiled by Y R Nagesh 45 Servlet Program repository = JCO.createRepository("MYRepository", SID); // Create a new repository // Get a function template from the repository IFunctionTemplate ftemplate = repository.getFunctionTemplate("ZVENDFUN"); // Create a function from the template JCO.Function function = new JCO.Function(ftemplate); JCO.Client client = JCO.getClient(SID); // Get a client from the pool JCO.ParameterList input = function.getImportParameterList(); // Fill in input parameters input.setValue(vendno, "LIFNR" ); client.execute(function); // Call the remote system JCO.Structure ret = function.getExportParameterList().getStructure("RETURN"); pw = res.getWriter(); pw.println("<html><body bgcolor=#eeeff8><center><hr><h1>Customer Details</h1><hr>"); // Get table containing the data JCO.Table vend = function.getTableParameterList().getTable("ITAB");
  • 46. Compiled by Y R Nagesh 46 Servlet Program for (int i = 0; i < vend.getNumRows(); i++) { vend.setRow(i); no = vend.getString("LIFNR"); name = vend.getString("NAME1"); city = vend.getString("ORT01") ; district = vend.getString("ORT02") ; po = vend.getString("PFACH") ; tele = vend.getString("TELF1") ; fax = vend.getString("TELFX") ; // Fetching data from SAP database and storing in local variables
  • 47. Compiled by Y R Nagesh 47 Servlet Program pw.println("<table border=1><tr><td><B>Vendor Number</B></td><td>"+no+ "</td></tr><tr><td>" + "<B>Customer Name</B></td><td>"+name+ "</td></tr><tr><td>" + "<B>Customer Address</B></td><td></tr>"+ "<tr><td> </td><td><B>City</B></td><td>"+city+"</td></tr>" + "<tr><td> </td><td><B>District</B></td><td>"+district+"</td></tr>"+ "<tr><td> </td><td><B>PO Box</B></td><td>"+po+"</td></tr>"+ "<tr><td><B>Telephone</B></td><td>"+tele+"</td></tr>"+ "<tr><td><B>TeleFax</B></td><td>"+fax+"</td></tr></table>" ); pw.println("<form name=form1 action='index.html' method=get><input type=submit value='Back'></form></center></body></html>"); } } catch (Exception E) { System.out.println(E); } } }
  • 48. Compiled by Y R Nagesh 48 Index.html <html> <head><script language="JavaScript"> function randomnumber() { var r=Math.floor(Math.random()*1111) if (r!=0) document.form1.rand.value=r; } </script> </head> <body bgcolor=#eeeff8 onLoad="javascript:randomnumber();"> <center><hr><h1>Enter the Vendor Number</h1><hr> </center><form name=form1 action="NameSeenByUser.do" method=post> <center><input type=text name=vendno> <input type=submit value="Submit"> <input type=hidden name="rand"></center> </form></body></html>
  • 49. Compiled by Y R Nagesh 49 Output
  • 50. Compiled by Y R Nagesh 50 Output