cancel
Showing results for 
Search instead for 
Did you mean: 

Java connecting to SAP to retreive data

Former Member
0 Kudos

Hi Guys,

I want to ask if you can help me with my problem regarding connecting to SAP. I don't have any idea regarding BAPI, RFC and ABAP that's why I'm lost.

I want to connect my java program to SAP and get some data like document number and the some date but I cant figure out how will I start my program. I made some java programs before that has a connection feature but not in SAP.

Can you send me some simple program in java that connects in SAP and if ever what will be the use of BAPI or RFC in the java code? Is it direct connection to SAP or we should call some functions like BAPI or RFC?

If you have a simple code please send me a copy. My email add is tanski7@yahoo.com

thank you in advance.... 😃

Accepted Solutions (0)

Answers (2)

Answers (2)

kishorg
Advisor
Advisor
0 Kudos

Hi Christian,

BAPI , RFC those things are just like WebServices, that you can access from any programs.

RFC - which can be remotely accessed (Remote enabled function modules).

BAPI - which are remote enabled (just like RFC ), provided its wrapping some business objects(here comes the concept of objects). which also contain some interfaces to access this.

depending upon the application , u can decide.

SAP is providing standard BAPI's for most of the business processes.

if ur application need some basic data , u can go for RFC.

also one main think here is ..

depending upon the front end application(Java Application ), means WebDynpro , sapmle J2EE application , Portal Application or just a java application , u can decide.

if ur application is webdynpro , u can access RFC 's and BAPIs , as models (here the Proxy classes for RFC is generated automatically during modelcreation).

if u rgoing for JAva(JCO) or J2EE applican(JCO and webservice) .

IN SAp R/3 corresponding to each Remote enabled Function Modules (RFC and BAPI) , webservices are present.(wsdl files are present).

u can go in generic way using Webservice way.

if u r using JCO , its not much generic ,but what u have to do is , u have to create the entire code for

connection to R/3 , creating Function Templates, setting import params.. etc.

but proper API help is available so u can also choose this , as it is easy.

here im giving sample code to connect to R/3 -- and executing one RFC.

follow this ..

private static JCO.Client client;

private static JCO.Repository repository;

client =

JCO.createClient(

"<client num>",

"<user name>",

"<password>",

"en",

"<server ip or server name>",

"<instance number>");

client.connect();

repository = new JCO.Repository("REP", client);

try {

IFunctionTemplate m_read_container;

m_read_container =repository.getFunctionTemplate("<RFC Name>");

JCO.Function function_read_cont = m_read_container.getFunction();

JCO.ParameterList importparam =

function_read_cont.getImportParameterList();

importparam.setValue(<Your value to pass>, "<Import parameter name as in RFC>");

client.execute(function_read_cont);

JCO.ParameterList tables =

function_read_cont.getTableParameterList();

//For Tables

JCO.Table container = tables.getTable("<Your table Name from table parameter>");

for (int iCtr = 0; iCtr < container.getNumRows(); iCtr++) {

container.setRow(iCtr);

Strin value = container.getString("<Tale fieldName>");

}

JCO.ParameterList exp_abs_read =

function_read_cont.getExportParameterList();//For Export Params

JCO.Structure st_abs_read =

exp_abs_read.getStructure("<If structure using then give structure name>");

for (int iCtrst = 0;iCtrst < st_abs_read.getNumFields();

iCtrst++) {

// String str_field_val = st_abs_read.getString("<Structure Field Name>"));

String fieldName = st_abs_read.getName(iCtrst);

}

} catch (Exception e) {

}

full JCO API help

http://www.huihoo.org/openweb/jco_api/com/sap/mw/jco/JCO.html

Regards

Kishor Gopinathan

Former Member
0 Kudos

Hi Barretto,

You can retrieve data from SAP through java proxies and web services.

For creating Webservice

/people/thomas.jung3/blog/2004/11/15/bsp-150-a-developer146s-journal-part-xiii-developing-abap-webservices

Go thru the following links:

http://searchsap.techtarget.com/featuredTopic/0,290042,sid21_gci1056433,00.html?bucket=REF

http://searchsap.techtarget.com/topicETA/0,295498,sid21_tax299360_idx0_off50,00.html

hope these links answer ur doubts

Regards,

Anuradha.B

Former Member
0 Kudos

Thank you very much guys for the links and sample codes, i really appreciate it... hehehehe... I'll check the links.. heheheh 😃

By the way is there other alternative instead of using JCo? hehehehe...

Message was edited by: Christian Gabriel Barretto

Message was edited by: Christian Gabriel Barretto