cancel
Showing results for 
Search instead for 
Did you mean: 

insert into sap r/3 table

Former Member
0 Kudos

hi,guruvulu

this is the program...............to insert the data into sap r/3 table

but record is not inserting....any commit i have to write in my program?

/*

  • Created on Feb 20, 2007

*

  • TODO To change the template for this generated file go to

  • Window - Preferences - Java - Code Style - Code Templates

*/

package comm;

/**

  • @author sapusr006

*

  • TODO To change the template for this generated type comment go to

  • Window - Preferences - Java - Code Style - Code Templates

*/

/**

  • Example2.java

  • Property of SAP AG, Walldorf

  • (c) Copyright SAP AG, Walldorf, 2000-2005.

  • All rights reserved.

*/

//import java.sql.Connection;

//import java.sql.PreparedStatement;

import com.sap.mw.jco.IFunctionTemplate;

import com.sap.mw.jco.IRepository;

import com.sap.mw.jco.JCO;

/**

  • @version 1.0

  • @author SAP AG, Walldorf

*/

public class Fm {

// The MySAP.com system we gonna be using

static final String SID = "R3";

// static String query="insert into BAPI_COMPANYCODE_GETLIST values(?,?)";

// The repository we will be using

IRepository repository;

//ESTABLISHING A CONNECTION TO SAP

public Fm()

{

try {

JCO.addClientPool( SID, // Alias for this pool

10, // Max. number of connections

"800", // SAP client

"RFCTEST", // userid

"welcome", // password

"EN", // language

"10.10.88.170", // host name

"01" );

// Create a new repository

// The repository caches the function and structure definitions

// to be used for all calls to the system SID. The creation of

// redundant instances cause performance and memory waste.

repository = JCO.createRepository("MYRepository", SID);

}

catch (JCO.Exception ex) {

System.out.println("Caught an exception: \n" + ex);

}

}

// RETRIEVES AND DISPLAY A ZHR INFOTYPE OPERATION

public void salesOrders()

{

JCO.Client client = null;

try {

// Get a function template from the repository

//System.out.println("goes to sales order");

IFunctionTemplate ftemplate = repository.getFunctionTemplate("ZHR_INFOTYPE_OPERATION");

System.out.println("hai");

if(ftemplate != null) {

// Create a function from the template

JCO.Function function = ftemplate.getFunction();

JCO.ParameterList paralist=function.getImportParameterList();

paralist.setValue("0000000011","PERNR");

paralist.setValue("UPD","ACTIO");

paralist.setValue("A","TCLAS");

System.out.println("hello");

paralist.setValue("20061215","BEGDA");

System.out.println("hello");

paralist.setValue("20061215","ENDDA");

paralist.setValue("1","OBJPS");

paralist.setValue("LTA","SUBTY");

System.out.println("SETTING VALUES");

// Get a client from the pool

client = JCO.getClient(SID);

System.out.println("goes to sales order");

//function.getImportParameterList().setValue("QUERY_TABLE","ZHRJ2EETEST");

//EXECUTING THE FUNCTION

client.execute(function);

System.out.println("after exeucting the function");

// NO OF IMPORT PARAMS IT DISPLAY

}

//STRUCTURE

JCO.Structure returnStructure =

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

String structure=returnStructure.toString();

System.out.println(structure);

JCO.Table sales_orders = function.getTableParameterList().getTable("PROPOSED_VALUES");

System.out.println("after function");

System.out.println("proposed111"+sales_orders.getNumRows());

sales_orders.firstRow();

sales_orders.appendRows(3);

sales_orders.setValue("0582","INFTY");

sales_orders.setValue("P0582-AMTEX","FNAME");

sales_orders.setValue("200.00","FVAL");

sales_orders.nextRow();

sales_orders.setValue("0582","INFTY");

sales_orders.setValue("P0582-JBGDT","FNAME");

sales_orders.setValue("20061215","FVAL");

sales_orders.nextRow();

sales_orders.setValue("0582","INFTY");

sales_orders.setValue("P0582-JENDT","FNAME");

sales_orders.setValue("20061215","FVAL");

System.out.println("proposed222"+sales_orders.getNumRows());

/*for (int i = 0; i <sales_orders.getNumRows(); i++) {

sales_orders.setRow(i);

System.out.println(sales_orders.getString("INFTY"));

}*/

JCO.Table sales_orders1 = function.getTableParameterList().getTable("MODIFIED_KEYS");

System.out.println("modified"+sales_orders1.getNumRows());

sales_orders1.setRow(1);

sales_orders1.appendRows(1);

sales_orders1.setValue("0000000011","PERNR");

sales_orders1.setValue("0582","INFTY");

sales_orders1.setValue("LTA","SUBTY");

sales_orders1.setValue("1","OBJPS");

sales_orders1.setValue("20061215","BEGDA");

sales_orders1.setValue("20061215","ENDDA");

System.out.println("modified222"+sales_orders1.getNumRows());

System.out.println("execute222"+sales_orders1.getNumRows());

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

sales_orders.setRow(i);

System.out.println("hia"+sales_orders1.getString("SUBTY"));

}

System.out.println("NO OF ROWS ARE:---"+ sales_orders.getNumRows());

String fieldName[]=new String[sales_orders.getFieldCount()];

System.out.println("THE COLUMNS IN THE TABLE ARE:--"+sales_orders.getFieldCount());

// sales_orders.firstRow();

//COLUMNS NAMES

System.out.println(fieldName.length);

for (int iCtrst = 0;iCtrst < sales_orders1.getFieldCount();iCtrst++) {

fieldName[iCtrst] = sales_orders1.getName(iCtrst);

System.out.println(fieldName[iCtrst]);

}

if (sales_orders.getNumRows() > 0) {

// Loop over all rows

do {

System.out.println("----


");

//int r=1;

// Loop over all columns in the current row

for (JCO.FieldIterator e = sales_orders.fields(); e.hasMoreElements();)

{

JCO.Field field = e.nextField();

String compcode=field.getString();

//pst.setString(r,compcode);

System.out.println(field.getName() + ":\t" + field.getString());

// r++;

}//for

// i=pst.executeUpdate();

} while(sales_orders.nextRow());

}

else {

System.out.println("No results found");

}

if (sales_orders1.getNumRows() > 0) {

// Loop over all rows

do {

System.out.println("----


");

//int r=1;

// Loop over all columns in the current row

for (JCO.FieldIterator e = sales_orders1.fields(); e.hasMoreElements();)

{

JCO.Field field1 = e.nextField();

//String compcode=field1.getString();

//pst.setString(r,compcode);

System.out.println(field1.getName() + ":\t" + field1.getString());

// r++;

}//for

// i=pst.executeUpdate();

} while(sales_orders1.nextRow());

}

else {

System.out.println("No results found");

}

System.out.println("modified"+sales_orders1.getNumRows());

System.out.println("modified"+sales_orders.getNumRows());

//if

/* if(i>=1)

{

System.out.println("\t\t\tUpdated ORACLE successfully");

} */

}

else {

System.out.println("FUNCTION MODULE not found in backend system.");

}//if

}

catch (JCO.AbapException ex) {

System.out.println("Caught an exception: \n" + ex);

}catch(Exception en){en.printStackTrace();}

finally {

JCO.releaseClient(client);

}

}

protected void cleanUp() {

JCO.removeClientPool(SID);

}

public static void main(String[] argv)

{

Fm e=new Fm();

// e.systemInfo();

e.salesOrders();

e.cleanUp();

}

}

output:

TABLE: MODIFIED_KEYS

TABLE: PROPOSED_VALUES

IMPORT ACTIO

IMPORT BEGDA

IMPORT DIALOG_MODE

IMPORT ENDDA

IMPORT LUW_MODE

IMPORT MASSN

IMPORT NO_ENQUEUE

IMPORT NO_EXISTENCE_CHECK

IMPORT OBJPS

IMPORT PERNR

IMPORT PERSG

IMPORT PERSK

IMPORT PLANS

IMPORT SEQNR

IMPORT SPRPS

IMPORT SUBTY

IMPORT TCLAS

IMPORT WERKS

EXPORT HR_RETURN

EXPORT RETURN

EXPORT RETURN1

appending

NO OF ROWS ARE:---3

THE COLUMNS IN THE TABLE ARE:--4

-


INFTY: 0582

FNAME: P0582-AMTEX

FVAL: 200.00

SEQNR: 00

-


INFTY: 0582

FNAME: P0582-JBGDT

FVAL: 20061215

SEQNR: 00

-


INFTY: 0582

FNAME: P0582-JENDT

FVAL: 20061215

SEQNR: 00

-


PERNR: 00000011

INFTY: 0582

SUBTY: LTA

OBJPS: 1

SPRPS:

ENDDA: 2006-12-15

BEGDA: 2006-12-15

SEQNR: 000

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi jagadesh,

ur code is very length to see.

see the following code ,

JCO.Function objFunction =
			this
				.objIRepository
				.getFunctionTemplate("BAPI_MATERIAL_AVAILABILITY")
				.getFunction();

		objFunction.getImportParameterList().setValue(strPlant, "PLANT");
		objFunction.getImportParameterList().setValue(strMaterial, "MATERIAL");
		objFunction.getImportParameterList().setValue(strQuantity, "UNIT");

		this.objClient.execute(objFunction);

		JCO.Structure ret =
			objFunction.getExportParameterList().getStructure("RETURN");
		String strRetMsg = ret.getString("MESSAGE");
 System.out.println(strRetMsg);  // it will tell whether record is inserted or not 
/*JCO.Function objFunction1 =
			this
				.objIRepository
				.getFunctionTemplate("BAPI_TRANSACTION_COMMIT")
				.getFunction();
objFunction1.setValue("",WAIT);

objClient.execute(objFunction1);*/

CHECK THE RETURN MSG .IT WILL TELL THE PROBLEM

give me points if it is useful

regards

Guru

Message was edited by:

Guruvulu Bojja

Message was edited by:

Guruvulu Bojja

Message was edited by:

Guruvulu Bojja

Answers (1)

Answers (1)

Former Member
0 Kudos

Tony,

Please STOP creating new threads for the same problem - you have about 10 open now asking the same thing and don't appear to be following up the suggestions or awarding points for answers. Numerous people have made suggestions and offered help but you just keep creating new threads.

Could you please revisit all of your threads and mark them as answered if appropriate and award points, then just leave 1 open.

Thanks,

Gareth.