cancel
Showing results for 
Search instead for 
Did you mean: 

JCo Calling BAPI and generate htm and xml page in output

Former Member
0 Kudos

Friends,

I am developing an Application in Java using JCO. The requirement there is a list of BAPI's are available for the selection, once the user select the BAPI , it will dynamically generates the screen of input parameters and than result will be stored in .htm and .xml file. It works for many BAPI's, but for few of that it won't work. Will you help me out why its gng to create problem for other BAPI's.

e.g.

BAPI_SALESORDER_GETLIST

BAPI_PO_GETITEMS

BAPI_MATERIAL_GET_DETAIL and few more...

It doesn't generate the proper output of these BAPI's.

Thanks.

HItesh Shah

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Can u please post ur code...

Regards,

Tanveer.

Former Member
0 Kudos

Tanveer,

There are many files so i wont be able to put the codes but let me tell u how i m doing.

1) Giving the options to user in which server they want to connect.

2) After connection has been established there is a plain text file available which consists the list of BAPI's which will be displayed in the list box.

3) After user select any BAPI and press a button named 'DETAILS' it will display the Import/Export/Tables list.

4) After clicking on Next , i m generating a dynamic screen for input parameters.

5)Here is this step also one problem is that i have to write all the zeros, can u tell me if i want to pad the zeroes automatically what i will do.Becz every time the input parameters of each BAPI would be different.

6) After getting input parameters i will generate the .htm and .xml file using writeXML and writeHTML function.

7) I want to show them generated xml and html file in iexplore using clicking button...Can u tell me how to achieve that.

Here is the code through which my xml and htm file will be generated.

import com.sap.mw.jco.*;

import java.io.*;

import java.util.*;

import java.math.*;

import java.util.Iterator;

// Quick imports

import com.jxml.quick.QDoc;

import com.jxml.quick.Quick;

class RFCG {

static final String SID = "R3";

String conDetails []=new String[6];

String ErrorMsg;

int i=0;

String LogonDetail;

int Rows;

IRepository repository;

String InputName[]=new String[200];

String InputType[]=new String[200];

String OutputName[]=new String[200];

String OutputType[]=new String[200];

String OutputINTTYPE[]=new String[200];

String OutputField[]=new String[200];

String TableName[]=new String[500];

String TableType[]=new String[500];

String TableINTTYPE[]=new String[500];

String FIELDNAME[]=new String[500];

//String FIELDNAME[]=new String[20];

String FIELDINTTYPE[]=new String[500];

String OutputFieldType[]=new String[200];

String OutputFieldINTTYPE[]=new String[200];

String InputParFieldName[][]=new String[200][200];

String InputParFieldDatatype[]=new String[200];

String InputParFieldIntType[]=new String[200];

int l,j,k,m,n,o,t,q;

/** public static void main(String [] args){

new RFCG("SAPR3.txt");

}*/

public RFCG(String LogonDetail,String BAPI)

{

this.LogonDetail=LogonDetail;

cleanUp();

try {

/* for xml */

// Initialize Quick

QDoc schema = PersonSchema.createSchema();

// Convert input XML to Java

QDoc doc = Quick.parse(schema, "input.xml");

// Get the result

Person person = (Person)Quick.getRoot(doc);

for (Iterator i = person.getClientList().iterator(); i.hasNext(); ) {

Client number = (Client)i.next();

// String type=number.getType();

//System.out.println(type);

// System.out.println(LogonDetail+"LOGO");

if(LogonDetail.equals(number.getType())){

//conDetails[0]=number.getType();

conDetails[0]=number.getSapclient();

conDetails[1]=number.getUserid();

conDetails[2]=number.getPassword();

conDetails[3]=number.getLanguage();

conDetails[4]=number.getHostname();

conDetails[5]=number.getSystemnumber();

//System.out.println(" Client Type(" + number.getType() + "):");

//System.out.println(" Sapclient " + number.getSapclient());

//System.out.println(" Userid " + number.getUserid());

//System.out.println(" Password " + number.getPassword());

//System.out.println(" Language " + number.getLanguage());

//System.out.println(" Hostname " + number.getHostname());

//System.out.println(" Systemnumber " + number.getSystemnumber());

//System.out.println(" \n ");

}

}

} catch (Exception e) {

e.printStackTrace();

}

Connect(LogonDetail);

zbapi(BAPI);

new BapiParameters1(InputName,InputType,OutputName,OutputType,TableName,TableType,BAPI,repository,OutputINTTYPE,FIELDNAME,FIELDINTTYPE,OutputField,OutputFieldType,OutputFieldINTTYPE,LogonDetail,InputParFieldName,InputParFieldDatatype,InputParFieldIntType);

for (int i = 0; i < 10; i++) {

//System.out.println("STRING***RFCG*******"InputName<i>'\t'+InputType<i>);

}

}

public void Connect(String LogonDetail){

//CustName=CustName;

/** try{

File myFile = new File(LogonDetail);

FileReader fr= new FileReader(myFile);

BufferedReader reader=new BufferedReader(fr);

String line=null;

while ((line=reader.readLine())!=null){

String[] result=line.split(":");

conDetails<i>=result[1];

System.out.println(conDetails<i>);

++i;

}

reader.close();

}catch(Exception ex){

ex.printStackTrace();

}*/

try {

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

10, // Max. number of connections

conDetails[0], // SAP client

conDetails[1], // userid

conDetails[2], // password

conDetails[3], // language

conDetails[4], // host name

conDetails[5] );

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

//System.out.println("Connected"+ repository);

}

catch (JCO.Exception ex) {

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

ErrorMsg=ex.toString();

//new Error(ex);

if (ErrorMsg!=null){

new Error(ErrorMsg);

}

}

}

protected void cleanUp() {

JCO.removeClientPool(SID);

}

public void zbapi(String BAPI)

{

JCO.Client client = null;

JCO.Table codes = null;

try {

// Get a function template from the repository

//FunctionTemplate ftemplate = repository.getFunctionTemplate(person.getRFCName());

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

// if the function definition was found in backend system

if(ftemplate != null) {

// Create a function from the template

JCO.Function function = ftemplate.getFunction();

// Get a client from the pool

client = JCO.getClient(SID);

// Fill in input parameters

JCO.ParameterList input = function.getImportParameterList();

input.setValue(BAPI, "FUNCNAME");

client.execute(function);

// Print return message

//JCO.Structure ret = function.getExportParameterList().getString("NAME1");

codes = function.getTableParameterList().getTable("PRMTAB");

//System.out.println("ROWS:"+codes.getNumRows());

this.Rows=codes.getNumRows();

//System.out.println(this.Rows);

//System.out.println("PTYPE" + '\t' + "PNAME" + '\t' + "FIELDNAME" + '\t' + "DATATYPE");

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

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

//codes.getString("NAME") + '\t'codes.getString("FIELDNAME")

//'t' +codes.getString("DATATYPE"));

if (codes.getString("PARAMTYPE").equals("1")){

InputName[j]=codes.getString("NAME");

InputType[j]=codes.getString("INTTYPE");

//InputINTTYPE[j]=codes.getString("INTTYPE");

++j;

}

else if(codes.getString("PARAMTYPE").equals("2")){

OutputName[k]=codes.getString("NAME");

OutputType[k]=codes.getString("DATATYPE");

OutputINTTYPE[k]=codes.getString("INTTYPE");

++k;

}

else if(codes.getString("PARAMTYPE").equals("3")){

TableName[l]=codes.getString("NAME");

TableType[l]=codes.getString("DATATYPE");

TableINTTYPE[l]=codes.getString("INTTYPE");

++l;

}

/**else if(codes.getString("PARAMTYPE").equals("5")){

//System.out.println("RFCGGGGG"+InputParFieldName[o]);

InputParFieldName[q][o]=codes.getString("FIELDNAME");

if(t==0){

t=1;

//System.out.println("RFCGGGGG"InputParFieldName[o]" "+t);

InputParFieldDatatype[o]=codes.getString("NAME");

}

else{

int w=o-1;

System.out.println("OoOoOooo"w"\t"+o);

if(InputParFieldDatatype[w].equals(InputParFieldDatatype[o])){

//System.out.println("RFCGGGGG"InputParFieldName[o]" "+t);

System.out.println("yes");

}

else{

InputParFieldDatatype[o]=codes.getString("NAME");

++q;

}

}

InputParFieldIntType[o]=codes.getString("INTTYPE");

++o;

}*/

else if(codes.getString("PARAMTYPE").equals("6")){

if(!codes.getString("NAME").equals("RETURN")){

//if(codes.getString("NAME").equals(TableName[]))

OutputField[n]=codes.getString("FIELDNAME");

//OutputFieldType[n]=codes.getString("DATATYPE");

OutputFieldINTTYPE[n]=codes.getString("INTTYPE");

++n;}

}

else if(codes.getString("PARAMTYPE").equals("7")){

FIELDNAME[m]=codes.getString("FIELDNAME");

FIELDNAME[m]=codes.getString("DATATYPE");

//System.out.println("TABLEFIELD"+FIELDNAME[m]);

FIELDINTTYPE[m]=codes.getString("INTTYPE");

++m;

}

}

}

else {

//System.out.println("Function not found" );

//new Error("Function not Found");

//System.out.println("Function BAPI_SALESORDER_GETLIST not found in backend system.");

}//if

}

catch (Exception ex) {

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

ErrorMsg=ex.toString();

//System.out.println("2222Caught an exception: \n" + ErrorMsg);

if (ErrorMsg!=null)

new Error(ErrorMsg);

// new Error(ex);

}

finally {

// Release the client to the pool

//System.out.println("2222Caught an exception: \n" + ErrorMsg);

JCO.releaseClient(client);

}

}

/**protected void cleanUp() {

JCO.removeClientPool(SID);

}*/

}

Thanks,

Hitesh

Former Member
0 Kudos

Hi Hitesh,

According to me you should check whether or not they are writting some special characters into the XML file like >, < etc because these are XML syntax tags and may be thats why the output doesn't seems to look proper.

Best regards,

Guru.

Former Member
0 Kudos

Gurvinder,

I am simply calling the JCO function to create html and xml output file. But for few BAPI's it will work and for others it won't work. I dont know why this is happening ?

Hitesh