cancel
Showing results for 
Search instead for 
Did you mean: 

How to insert the data to R3 tables using JCO API

Former Member
0 Kudos

Hi Frndz..

I want to know how we can insert the data to the R3 tables using JCO API( i am able to retrive the data from RFC using JCO API).

Am targeting to do an app using JCO API (for data submit n retrive)and integrating AJAX for client validations.

Thanks in Advance

Regards

Rajesh

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi ..

I got the ans..

import com.sap.mw.jco.*;

public class Bapi2 extends Object {

JCO.Client mConnection;

JCO.Repository mRepository;

public TutorialBapi2() {

try {

// Change the logon information to your own system/user

mConnection =

JCO.createClient("001", // SAP client

"<userid>", // userid

"****", // password

null, // language

"<hostname>", // application server host name

"00"); // system number

mConnection.connect();

mRepository = new JCO.Repository("ARAsoft", mConnection);

}

catch (Exception ex) {

ex.printStackTrace();

System.exit(1);

}

JCO.Function function = null;

JCO.Table codes = null;

try {

function = this.createFunction("BAPI_COMPANYCODE_GETLIST");

if (function == null) {

System.out.println("BAPI_COMPANYCODE_GETLIST" +

" not found in SAP.");

System.exit(1);

}

mConnection.execute(function);

JCO.Structure returnStructure =

function.getExportParameterList().getStructure("RETURN");

if (! (returnStructure.getString("TYPE").equals("") ||

returnStructure.getString("TYPE").equals("S")) ) {

System.out.println(returnStructure.getString("MESSAGE"));

System.exit(1);

}

codes =

function.getTableParameterList().getTable("COMPANYCODE_LIST");

codes.setRow(2);

codes.deleteRow();

codes.deleteRow(5);

codes.appendRow();

codes.setValue("XXXX", "COMP_CODE");

codes.setValue("Does not exist", "COMP_NAME");

codes.appendRows(2);

codes.setValue("YYYY", "COMP_CODE");

codes.setValue("Does not exist either", "COMP_NAME");

codes.nextRow();

codes.setValue("ZZZZ", "COMP_CODE");

codes.setValue("Nor does this", "COMP_NAME");

for (int i = 0; i < codes.getNumRows(); i++) {

codes.setRow(i);

System.out.println(codes.getString("COMP_CODE") + '\t' +

codes.getString("COMP_NAME"));

}

}

catch (Exception ex) {

ex.printStackTrace();

System.exit(1);

}

try {

codes.firstRow();

for (int i = 0; i < codes.getNumRows(); i++, codes.nextRow()) {

function = this.createFunction("BAPI_COMPANYCODE_GETDETAIL");

if (function == null) {

System.out.println("BAPI_COMPANYCODE_GETDETAIL" +

" not found in SAP.");

System.exit(1);

}

function.getImportParameterList().

setValue(codes.getString("COMP_CODE"), "COMPANYCODEID");

mConnection.execute(function);

JCO.Structure returnStructure =

function.getExportParameterList().getStructure("RETURN");

if (! (returnStructure.getString("TYPE").equals("") ||

returnStructure.getString("TYPE").equals("S") ||

returnStructure.getString("TYPE").equals("W")) ) {

System.out.println(returnStructure.getString("MESSAGE"));

}

JCO.Structure detail =

function.getExportParameterList().

getStructure("COMPANYCODE_DETAIL");

System.out.println(detail.getString("COMP_CODE") + '\t' +

detail.getString("COUNTRY") + '\t' +

detail.getString("CITY"));

}

}

catch (Exception ex) {

ex.printStackTrace();

System.exit(1);

}

mConnection.disconnect();

}

public JCO.Function createFunction(String name) throws Exception {

try {

IFunctionTemplate ft =

mRepository.getFunctionTemplate(name.toUpperCase());

if (ft == null)

return null;

return ft.getFunction();

}

catch (Exception ex) {

throw new Exception("Problem retrieving JCO.Function object.");

}

}

public static void main (String args[]) {

Bapi2 app = new Bapi2();

}

}

nikhil_bose
Active Contributor
0 Kudos

woooooooo great!

well done rajesh.

still I would say, we use a FM to access R/3 tables. And in the first post, you mentioned : "( i am able to retrive the data from RFC using JCO API)."

Anyway its good to hear you got the problem solved.

plz close thread.

Former Member
0 Kudos

Hi Nikil..

Thank u...ya earlier i know only how to retrive data usiing JCO API n i don't know how to insert data using JCO API. So i posted the question in SDN after by exploriing my self in SDN i found the code for inserting also

JCO.Structure detail =

function.getExportParameterList().

getStructure("COMPANYCODE_DETAIL");

System.out.println(detail.getString("COMP_CODE") + '\t' +

detail.getString("COUNTRY") + '\t' +

detail.getString("CITY"));

}

}

catch (Exception ex) {

ex.printStackTrace();

System.exit(1);

}

mConnection.disconnect();

Ragrds

Rajesh .

nikhil_bose
Active Contributor
0 Kudos

Dynpro for java can't directly access R/3 tables without a remote enabled FM but ABAP Dynpro does.

Create remote enabled Function Module and use JCo API for assigning parameters.

nikhil

former_member185086
Active Contributor
0 Kudos

Hi Rajesh

Check following thread it might help you

1.[SLD to Manage JCo|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/7a16201d-0d01-0010-07a6-a3c56470d8f4]

2.[Adaptive RFC- Troubleshooting Guide|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/7a16201d-0d01-0010-07a6-a3c56470d8f4]

3.[JCO API in NWDS|https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/access%252br3%252bsystem%252band%252bexecute%252brfc%252bfrom%252bany%252bof%252bthe%252bportal%252bcomponents%252busing%252bsap%252bjco%252bapi%252bin%252bnwds]

4.[JCO|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/fcadaf90-0201-0010-4091-bd0bcd7b7f6a]

Best Regards

Satish Kumar