cancel
Showing results for 
Search instead for 
Did you mean: 

JCo Call RFC

Former Member
0 Kudos

I have defined a RFC and call it via JCo.

The RFC is used to fill data to my table.

The problem is the data can be fill via the import parameter, but the table parameter is not work. I have tested the RFC in function builder and it work.

Here is my RFC:

FUNCTION Z_FYP_BAPI_ORDER_CREATEFROMDAT.

*"----


""Local interface:

*" IMPORTING

*" VALUE(PLACEORDER_IMPORT) TYPE ZFYP_ORDER

*" EXPORTING

*" VALUE(RETURN) TYPE BAPIRETURN

*" VALUE(ORDERID_EXPORT) TYPE ZFYP_ORDER-ORDERID

*" TABLES

*" ORDERITEM_IMPORT STRUCTURE ZFYP_ORDERITEM

*"----


DATA: RC LIKE INRI-RETURNCODE,

NUMBER(10) TYPE C,

ITEMID TYPE I.

TABLES: ZFYP_ORDER.

TABLES: ZFYP_ORDERITEM.

DATA WA_ORDERITEM LIKE LINE OF ORDERITEM_IMPORT.

CALL FUNCTION 'NUMBER_GET_NEXT'

EXPORTING

OBJECT = 'ZFYP_OR'

NR_RANGE_NR = '1'

IMPORTING

RETURNCODE = RC

NUMBER = NUMBER.

PLACEORDER_IMPORT-ORDERID = NUMBER.

ORDERID_EXPORT = NUMBER.

INSERT INTO ZFYP_ORDER VALUES PLACEORDER_IMPORT.

ITEMID = 0.

LOOP AT ORDERITEM_IMPORT INTO WA_ORDERITEM.

WA_ORDERITEM-ORDERID = NUMBER.

WA_ORDERITEM-ORDERITEMID = ITEMID.

INSERT INTO ZFYP_ORDERITEM VALUES WA_ORDERITEM.

ITEMID = ITEMID + 1.

ENDLOOP.

ENDFUNCTION.

Accepted Solutions (0)

Answers (1)

Answers (1)

kishorg
Advisor
Advisor
0 Kudos

Hi Chun,

just follow this code.

-


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 tables =

function_read_cont.getTableParameterList();

//For Tables

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

<b>// specified number of empty rows at the end of the table

table.appendRows(<Enter the number of expected rows>);

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

{

// Moves the row pointer to the next row

table.nextRow();

// public void setValue(<Data Type> value,java.lang.String fieldName)

// set the field values . must have a look at the data type of the field to be set.

// Here can use table.getNumColumns() .. to find out the number of of columns in the table , and loop through this...

table.setValue(<use type casted data value>,<fieldName>);

}</b>

// Execute the RFC

client.execute(function_read_cont);

}

} catch (Exception e) {

}

For function details just refer these links.

JCO API

-


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

JCO.Table

-


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

Regards

Kishor Gopinathan