Sunteți pe pagina 1din 12

SAP Java Connector (JCO)

Swati Bhayana
INTRODUCTION
Aim
SAP Java Connector (SAP JCo) is a middleware component that enables the
development of SAP-compatible components and applications in Java. SAP JCo
supports communication with the SAP Server in both directions: inbound calls (Java
calls AAP) and outbound calls (AAP calls Java).!his white paper provides an
overview of the SAP "#$ %nterprise& different inte'ration interfaces e(posed b) it and
inte'ration of an application with SAP "#$ usin' Java platform. !his paper assumes
that )ou alread) *now Java. +nowled'e of SAP is not desirable& but after readin' this
)ou should be able to 'et some basics of SAP as well.
Intended Audience
!his document is intended for developer(s)#architect(s) embar*in' on pro,ects
involvin' inte'ration with SAP "#$. !he) will find this document suitable for obtainin'
a -uic* overview of the SAP "#$ %nterprise and different inte'ration interfaces
e(posed b) the same. .t will also 'ive them a -uic* overview of the SAP/s Java
Connector& with some details on the issues involved in such inte'ration pro,ects.
SAP R/3 ENTERPRISE
Overview
SAP/s "#$ S)stem has set new norms for standard software that can be universall)
implemented. "#$ uses advanced development techni-ues to achieve comprehensive
inte'ration of business administration and data processin'. .t combines state-of-the-
art technolo') with comprehensive business administration functionalit) to provide a
full) inte'rated business solution for an enterprise.
SAP stands for Systems Applications and Products for data processing.
Architecture
SAP "#$ is SAP0s inte'rated software solution for client#server and distributed open
s)stems. SAP0s "#$ is the world0s most-used standard business software for
client#server computin'. "#$ meets the needs of a customer from the small 'rocer
with $ users to the multi-billion dollar companies !he software is hi'hl) customi1able
usin' SAP0s proprietar) pro'rammin' lan'ua'e& AAP#2. "#$ is scalable and hi'hl)
suited for man) t)pes and si1es of or'ani1ations.
!he "#$ architecture is comprised of application and database servers. !he
application servers house the software and the databases servers handle document
updates and master file databases. !he s)stem can support an unlimited number of
servers and a variet) of hardware confi'urations. SAP "#$ is based on various
hardware and software architectures& runnin' on most t)pes of 34.5& on 6indows
4! and OS#277.
SAP "#$ is event-driven transaction processin' software for business events in an
or'ani1ation/s primar) value chain. !ransaction processin' s)stems supported b)
enterprise software are most concerned with the da)-to-da) needs of a business in
conductin' its on-'oin' activities.
R/3 Modules
"#$0s applications are modules. !he) can be used either alone or combined with other
solutions. !he inte'ration capabilit) of these applications increases the benefits derived for
an) compan).

o!istics - 8o'istics comprises all processes involved in purchasin'& materials mana'ement&
manufacturin'& warehousin'& -ualit) mana'ement& plant maintenance& service mana'ement
and sales and distribution. All applications access a shared consistent database& supported b)
production data mana'ement.
SD" S#les $ Distri%ution S9 activel) supports sales and distribution activities with
outstandin' functions for pricin'& prompt order processin'& and on-time deliver)&
interactive variant confi'uration& and a direct interface to profitabilit) anal)sis and
production.
PP" Production Pl#nnin! #nd Control PP provides comprehensive process for
all t)pes of manufacturin': from repetitive& ma*e-to-order& and assemble-to-order
production& throu'h process& lot and ma*e-to-stoc* manufacturin'& to inte'rated
suppl) chain mana'ement with functions e(tended :"P.
PS" Pro&ect S'stem PS coordinates and controls all phases of a pro,ect& in direct
cooperation with Purchasin' and Controllin'& from -uotation to desi'n and approval& to
resource mana'ement and cost settlement.
MM" M#teri#ls M#n#!ement :: optimi1es all purchasin' processes with
wor*flow-driven processin' functions& enables automated supplier evaluation& lowers
Sales & Sales &
Distribution Distribution
SD SD
MM MM
PP PP
QM QM
PM PM
HR HR
CO CO
AM AM
PS PS
WF WF
IS IS
Materials Materials
Management Management
Production Production
Planning Planning
Quality Quality
Management Management
Plant Plant
Maintenance Maintenance
Human Resources Human Resources
Financial Financial
Accounting Accounting
Controlling Controlling
Asset Asset
Management Management
or!"low or!"low
#ndustry Solutions #ndustry Solutions


SAP
SAP
R/3
R/3
Pro$ect Pro$ect
Systems Systems
FI FI
procurement adn warehousin' costs with accurate inventor) and warehouse
mana'ement& and inte'rates invoice verification.
(M" (u#lit' M#n#!ement ;: monitors& captures& and mana'es all processes
relevant to -ualit) assurance alon' the entire suppl) chain& coordinates inspection
processin'& initiates corrective measures& and inte'rates laborator) information
s)stems.
PM" Pl#nt M#inten#nce P: provides plannin'& control& and processin' of
scheduled maintenance& inspection& dama'e-related maintenance& and service
mana'ement to ensure availabilit) of operational s)stems& includin' plants and
e-uipment delivered to customers.
SM" Service M#n#!ement S: provides hi'hl) inte'rated customer service
functionalit) to compete in toda)0s 'lobal mar*ets.
PDM" Product D#t# M#n#!ement P9: supports in creatin' and mana'in'
product data throu'hout the product life c)cle.
)in#nci#ls - <inancials is a suite of inte'rated financial application components
encompasses all aspects of financial accountin'& investment mana'ement& controllin'&
treasur) mana'ement& and enterprise controllin'.
)I" )in#nci#l Accountin! <. collects all the data in compan) relevant to
accountin'& providin' complete documentation and comprehensive information& and is
at the same an up-to-the-minute basis for enterprise-wide control and plannin'.
CO" Controllin! CO is a complete arra) of compatible plannin' and control
instruments for compan)-wide controllin' s)stems& with a uniform reportin' s)stem
for coordinatin' the contents and procedures of compan)0s internal processes.
IM" Investment M#n#!ement .: offers inte'rated mana'ement and processin'
of investment measures and pro,ects from plannin' to settlement& includin' pre-
investment anal)sis and depreciation simulation.
TR" Tre#sur' !" is a complete solution for efficient financial mana'ement that
ensures the li-uidit) of worldwide compan)& its structures& financial assets& profitabilit)
and minimi1es ris*s.
EC" Enter*rise Controllin! %C continuousl) monitors compan)0s success factors
and performance indicators on the basis of speciall) prepared mana'ement
information.
+um#n Resources - =" provides solutions plannin' and mana'in' compan)0s human
resources& usin' inte'rated applications that cover all personnel mana'ement tas*s and help
simplif) and speed the process.
PM" Personnel M#n#!ement P: is a complete solution for personnel
administration& recruitment mana'ement& travel mana'ement& benefits administration
and salar) administration.
OM" Or!#ni,#tion#l M#n#!ement O: assists in maintainin' an accurate
picture of or'ani1ation0s structure& no matter how fast it chan'es. .t is s)stematic and
forward plannin' tool that considers the final effects of all personnel events thus it0s
complete solution for personnel cost plannin'.
PA" P#'roll Accountin! PA addresses pa)roll functions from a 'lobal point-of-
view and 'ives the capabilit) to centrali1e pa)roll processin' or decentrali1e the data
based on countr) or le'al entities.
TM" Time M#n#!ement !: is inte'rated with pa)roll accountin'& controllin'&
production plannin'& plant maintenance& pro,ect s)stem& e(ternal services and shift
plannin'. .t provides with a variet) of standard reports that will assist in trac*in' and
anal)1in' emplo)ee time with completeness and accurac).
PD" Personnel Develo*ment P9 assists with plannin'& monitorin'& and
anal)1in' scheduled seminars& trainin' courses& and business events& re'istration and
boo*in'& price determination and invoicin'.
SAP Inte!r#tion Inter-#ces
Remote )unction C#lls .R)C/
A "emote <unction Call ("<C) is the call of function module in a partner s)stem. !he
caller is the "<C client and the called partner is the "<C server. "<C is based on the
*nown "PC model from the 34.5-!CP#.P environment. "<C in SAP environment is
based on a CP.-C interface implemented b) SAP.
!he remote call of a function module is easier for an application pro'rammer to use
than pro'ram-to-pro'ram communication& because data is e(chan'ed onl) usin'
predefined parameters.
SAP 0O1 0OR #nd 0API
SAP usiness Ob,ects (O)
usiness model ob,ects for the real world (for e(ample& emplo)ees& customer orders&
and so on) are reproduced in "#$ as business ob,ects. A business ob,ect
encapsulates the business processes and the data lin*ed to it. !hese ob,ects can be
seen as bein' multi-la)ered.
!he innermost la)er is made up of the actual data and its structures. !he second la)er
maintains inte'rit). .t represents the business lo'ic of the ob,ect and describes the business
rules and limitations for the business ob,ect. !he interface la)er describes the implementation
and structure of the ob,ect. !he interface la)er allows access to the attributes& methods& and
events that are defined for the ob,ect.
SAP 0usiness O%&ect Re*ositor' .0OR/
!he usiness Ob,ect "epositor) (O") contains the SAP business ob,ect t)pes and SAP
interface t)pes as well as their components& such as methods& attributes& and events.
!he O" has the followin' functions:
> %nables an ob,ect-oriented view of the "#$ S)stem data and processes.
> Arran'es the various interfaces in accordance with the component
hierarch).
> :ana'es AP.s in release updates.
SAP 0usiness A**lic#tion Pro!r#mmin! Inter-#ce .0API/
SAP AP.s provide developers with stable& reliable interfaces for accessin' the functionalit)
offered b) SAP business ob,ects. AP.s can reduce the development cost b) providin' built-in
functionalit) throu'h predefined methods of the SAP business ob,ects. !hese methods can
reduce pro'rammin' time in deplo)ment pro,ects.
A**lic#tion in2 En#%lin! .AE/ #nd IDocs
Application 8in* %nablin' (A8%) is an important middleware tool in SAP/s usiness <ramewor*
Architecture. A8% is the e(chan'e of messa'es controlled from a business point of view. .t can
inte'rate business processes between "#$ s)stems and non-"#$ s)stems as well as between
"#$ s)stems. Application s)stems are loosel) coupled in an A8% inte'rated s)stem. 9ata is
e(chan'ed as)nchronousl)& whereb) the data arrives in the receiver s)stem& even if the
receiver s)stem cannot be connected to at the time the data is sent. A8% uses s)nchronous
communication for receivin' data onl).
An .ntermediate 9ocument (.9oc) is a container for e(chan'in' data between "#$&
"#? and non-SAP s)stems. 4on SAP-s)stems can use .9ocs as the standard interface
for data transfer. !he .9oc interface consists of the definition of a data structure and
the processin' lo'ic for this data structure.
SAP 3A4A CONNECTOR .3CO/
SAP Java Connector (SAP JCo) is a middleware component that enables the
development of SAP-compatible components and applications in Java. SAP JCo
supports communication with the SAP Server in both directions: inbound calls (Java
calls AAP) and outbound calls (AAP calls Java).
SAP/s ,ava middleware& the SAP Java Connector (JCo) allows SAP customers and
partners to easil) build SAP-enabled components and applications in Java. .t enables
communication between SAP S)stem and Java (supports communication with SAP
"#?& "#$ $.@ and later).
SAP JCo offers the followin' functions for creatin' SAP-compliant Java applications:

SAP JCo has "<C middleware based on the J4. (Java 4ative .nterface).
.t supports SAP ("#$) s)stems from "elease $.@= upwards& and other m)SAP
components that have AP.s or "<:s ("emote <unction :odules).
Aou can e(ecute function calls inbound (Java client calls AP. or "<:) and
outbound (AAP calls Java Server).
6ith SAP JCo& )ou can use s)nchronous& transactional& and -ueued "<C.
Connection poolin' (important for 6eb servers)
SAP JCo can be used on different platforms
%(tensive code pa'e handlin'& includin' multi-b)te lan'ua'es.
SAP 3Co Architecture .St#nd#lone 4ersion/
!he followin' dia'ram shows the technical schema of data conversion in the SAP JCo
(standalone version). Startin' from a Java application& a Java method is forwarded
via the JCo Java AP. (Application Pro'rammin' .nterface) and an additional
:iddleware .nterface to "<C :iddleware& where it is converted to an "<C (AAP) call
usin' the J4.(Java 4ative .nterface) la)er& and sent to the SAP s)stem. 3sin' the
same method in the other direction& an "<C Call is converted to Java and forwarded
to the Java application.

Downlo#din! 3Co
Aou need to be an SAP customer or partner (with a valid SAPnet (OSS) userid) to download
JCo. Bo to http:##service.sap.com#connectors and follow the download instructions. Aou will
also find the complete list of supported platforms here.
Inst#llin! 3Co
JCo ?.7 is available with SAP asis "elease C.?7. JCo ?.7 does not support J9+ @.@
an)more& but re-uires Java ? (J9+ @.? and later). .f )ou still need to use J9+ @.@&
please *eep usin' JCo @.@ (@.@.7$ or later).
!he followin' instructions appl) to 6indows $? platforms. !he instructions for
installin' JCo on other platforms are contained in the appropriate JCo download.
@. Create a director)& e.'.& c:DJCo& and un1ip the JCo 1ip file to that director)&
*eepin' the director) structure intact.
?. Cop) the librfc$?.dll file from )our JCo root director) to C:D6.44!DSAS!%:$?
unless the version )ou alread) have there is newer than the one supplied with JCo.
$. :a*e sure that sap,co.,ar (found in )our JCo root director)) is in the class path of
an) pro,ect that wants to use JCo. <or production deplo)ment& the followin' files
from the JCo 1ip file are re-uired:
5 s#*&co6&#r
5 li%r-c376dll
5 s#*&cor-c6dll
Alon' with this )ou also 'et followin' in downloaded 1ip file E
!he docs director) contains the Javadocs for JCo. Start with the inde(.html
file.
!he demo director) contains some sample pro'rams& includin'& but not
limited to&the samples discussed in this te(t.
CONNECTIN8 TO SAP
JCo supports two pro'rammin' models for connectin' to SAP: direct connections&
which )ou create and hold on to as lon' as )ou want& and connection *ools& from
which )ou ta*e a connection when )ou need it and to which )ou return it as soon as
possible so that others can use it. !hese two models can be combined in one
application. .f )ou are buildin' web server applications& )ou definitel) want to use
connection pools& but the) can also be used in des*top applications.
Direct Connection
elow are the attributes that needs to be defined in the pro'ram to connect to SAP in
case of 9irect Connection.
@. .ntroduce 4ew classes -
3CO9 - !he main class of the SAP Java Connector.
3CO : Attributes Attributes of a connection& e.'.& the release of the SAP s)stem.
?. .mport statements -An) pro'ram usin' JCo should contain the followin' import
statement: im*ort com6s#*6mw6&co6;F Otherwise& )ou have to full) -ualif) each
JCo class and interface which is ver) inconvenient.
$.9efinin' a connection variable - 3CO6Client mConnectionF A connection with SAP
is handled b) an ob,ect of class JCO.Client. Since the term client means a lo'ical
partition of an SAP s)stem (and has to be entered when )ou lo' on to SAP& for
e(ample)& this te(t calls an ob,ect of class JCO.Client a connection.
2. Creatin' a JCO.Client ob,ect-
// Change the logon information to your own system/user
mConnection = JCO.createClient("001", // SA client
"!useri"#", // useri"
"$$$$", // %asswor"
"&'", // language (null for the "efault language(
"!hostname#", // a%%lication ser)er host name
"00"(* // system num+er
3se the createClient() method of class JCO to create JCO.client ob,ect. !here are
several overloaded versions of this method to support:
G Connections to a specific application server
G Connections to a load balancin' server 'roup&
G Connections based on the information in a ,ava.util.Properties ob,ect.
H. Openin' the connection - Creatin' the JCO.Client ob,ect does not connect to SAP&
but a subse-uent call to connect() will accomplish this:
try {
mConnection.connect();
}
catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
C. Callin' a function -4ow we are read) to call functions in SAP. <or testin' the
connection ,ust print out the "<C attributes for our connection.
S'stem6out6*rintln.mConnection6!etAttri%utes.//<
.I. Closin' the connection -After we have accomplished whatever it was we wanted
to do (call one AP. or a few hundred)& eventuall) we want to disconnect a'ain:
mConnection6disconnect./<
As opposed to usin' connection pools & where )ou want to return the connection to
the pool as soon as possible& for direct connections it is not a 'ood idea to
connect to SAP& call one function& and disconnect a'ain for ever) function call. !here
is some overhead involved in lo''in' on to SAP and therefore we should sta)
connected until we are finished or until we *now that there will be no further activit)
for -uite some time.
Connection Pools
.n (web) server applications& at least to some e(tent 'eneric userids are used to lo' on to
SAP. .n that case it ma*es sense to use connection poolin'. A JCo connection pool is identified
b) its name and is 'lobal within the Java Jirtual :achine (JJ:). All connections in a pool use
the same s)stem#userid#client information.!here can be as man) pools as )ou need& thou'h.
elow are the attributes that needs to be defined in the pro'ram to connect to SAP in
case of connection Pools E
@. 4ew classes introduced -
3CO6Pool - "epresents one connection pool.
3CO6PoolM#n#!er - :ana'es all connection pools within one JJ:.
?. Selectin' a pool name -
static final String POOL_NAME = "Pool";
As far as JCo is concerned& )ou can use an) pool name. Just remember that a pool is
'lobal within the JJ:& so different applications runnin' in the same JJ: need to follow
some namin' standard to avoid unpleasant surprises.
$. 9oes the pool e(ist alread)K E
JCO.Pool pool JCO.!etClientPool"ana!er().!etPool(POO#$%&"E);
i' (pool n(ll) {
All pools are mana'ed b) the 'lobal JCo PoolManager ob,ect (a sin'leton)& which can be
access via the getClientPoolManager() method of class JCO. !he getPool() method
tries to access a pool with the specific pool name. null is returned if no such pool e(ists.
2. Creatin' a connection pool E
Or)ere)Properties lo!onProperties
Or)ere)Properties.loa)(*+lo!on.properties*);
JCO.a))ClientPool(POO#$%&"E, ++ pool name
-, ++ maxim(m n(m.er o' connections
lo!onProperties); ++ properties
!o create a new connection pool& use method addClientPool(). !he ma(imum number of
connections specified can never be increased& so choose a number lar'e enou'h for
application. Several overloaded versions of addClientPool() allows to specif) lo'on information
in different wa)s. .n the code above& we have chosen to use a Properties ob,ect. An) other
wa) of creatin' a Properties ob,ect could have been used instead.
!he followin' is a sample lo'on.properties file:
/co.client.client001
/co.client.(ser(seri)
/co.client.pass1)2222
/co.client.ashosthostname
/co.client.sysnr00
6henever we need an actual connection from the pool& we will borrow (ac-uire) it& ma*e
one or more calls to SAP& and finall) return (release) the connection to the pool.
.f all connections in the pool are in use and the pool has reached its ma(imum si1e& JCo will
wait for a certain time. .f no connection has become available in the meantime& JCo will throw
an e(ception.
As lon' as our application is stateless E as far as SAP is concerned E we will alwa)s release the
connection bac* to the pool as soon as we have finished with the SAP calls connected to one
activit). 4ot necessaril) after each SAP call& thou'h. .n other words& if )ou need to call
multiple "<:s in a se-uence& uninterrupted b) user or other e(ternal interaction& )ou should
*eep the connection& and return it after all )our calls are done.
4ote that when )ou use a connection pool& )ou never call the connect() or disconnect()
methods of JCO.Client. !he PoolManager ta*es care of all this as appropriate.
REATED CONTENT
%
? http:##service.sap.com
$ www.sdn.sap.com
2 www.sap-im'.com
H www.erp'enie.com

S-ar putea să vă placă și