on 01-05-2006 9:35 AM
Hi,
I want to know the procedure to access Function module which is remote enabled in SAP through java. Can any one help me in this regard.
Thanks,
suresh.
Look into SAP-JCo Tutorials.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Suresh,
The process in nutshell is as follows :
1. Set up a RFC connection using Visual Administrator.
2. Set up a JRA connection in code for that particular RFC .
Eg of code
Interaction interaction=null;
jraConn =new JRAConnection("<remote method name>", null);
// create new structure for given RFC-Function
MappedRecord input = jraConn.getInput();
interaction = jraConn.getInteraction();
input.put("<input field>", name);
MappedRecord output =(MappedRecord) interaction.execute(null, input);
javax.resource.cci.ResultSet output =(ResultSet) output.get("<output field>");
Regards,
Parminder
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Suresh,
there is another solution to access to a Function module (that must be flagged as Remote), using JCA connection. Here an example:
- Get the system alias set into portalapp.xml and request
IPortalComponentRequest request = (IPortalComponentRequest) this.getRequest();
IPortalComponentContext compContext = request.getComponentContext();
IPortalComponentProfile userProfile = compContext.getProfile();
userProfile.getProperty("System");
- get the Connector Gateway Service and connection object
Object connectorservice = PortalRuntime.getRuntimeResources().getService(IConnectorService.KEY);
IConnectorGatewayService cgService = (IConnectorGatewayService) connectorservice;
connection = cgService.getConnection(sapSystem, request);
- Get the Interaction interface for executing the command
IInteraction ix = connection.createInteractionEx();
IInteractionSpec ixspec = ix.getInteractionSpec();
ixspec.setPropertyValue("Name", functionName);
RecordFactory rf = ix.getRecordFactory();
MappedRecord input = rf.createMappedRecord("input");
- Call the Remote Function module
MappedRecord output = (MappedRecord) ix.execute(ixspec, input);
.....
I hope this can help you.
we can acces the rfc's in sap system via java connector JCo .
the procedure is like normal calling an rfc's in other languages like c etc.
first you make connection to the system and then login to the system using valid login and password. and then make a call to that rfc.
here is a sample code you can try and understood it. this application uses classes in JCo to call a BAPI(which includes an rfc) to create purchase order in the SAP system
import com.sap.mw.jco.*;
import java.util.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class BAPITip extends Frame implements ActionListener
{
//Global Declarations
int i = 0;
char flag = 'a';
Label doc_type,co_code,purch_org,pur_group,vendor;
Label po_item,pur_mat,plant,unit,net_price,deliv_date,quantity;
TextField DOC_TYPE,CO_CODE,PURCH_ORG,PUR_GROUP,VENDOR;
TextField PO_ITEM[],PUR_MAT[],PLANT[],UNIT[],NET_PRICE[],DELIV_DATE[],QUANTITY[];
Panel pan_hdr,pan_itm,pan_bs,pan_st;
Button bt = null,bc = null,br = null,bd = null;
TextArea status = null;
JCO.Client mConnection = null;
JCO.Pool pool = null;
static final String POOL_NAME = "MyPool";
static JCO.Repository mRepository;
String msg = "";
public BAPITip()
{
setLocation(0,0);
setSize(800,800);
setVisible(true);
bt = new Button("Submit");
bc = new Button("Connect");
br = new Button("Reset");
bd = new Button("Disconnect");
bt.addActionListener(this);
bc.addActionListener(this);
br.addActionListener(this);
bd.addActionListener(this);
status = new TextArea("Status",4,30);
status.setEditable(false);
//Instantiating header labels
doc_type = new Label("Document Type");
co_code = new Label("Company Code");
purch_org = new Label("Purchasing Organization");
pur_group = new Label("Purchasing Group");
vendor = new Label("Vendor");
//Instantiating line item labels
po_item = new Label(" Item number");
pur_mat = new Label(" Material");
plant = new Label(" Plant");
unit = new Label(" Unit");
net_price = new Label(" Net price");
deliv_date = new Label(" Delivery date");
quantity = new Label(" Quantity");
//Instantiating header text fields
DOC_TYPE = new TextField();
CO_CODE = new TextField();
PURCH_ORG = new TextField();
PUR_GROUP = new TextField();
VENDOR = new TextField();
//Instantiating line item textfields
PO_ITEM = new TextField[5];
PUR_MAT = new TextField[5];
PLANT = new TextField[5];
UNIT = new TextField[5];
NET_PRICE = new TextField[5];
DELIV_DATE = new TextField[5];
QUANTITY = new TextField[5];
//Instantiating panels
pan_hdr = new Panel();
pan_itm = new Panel();
//Setting layout for applet and adding component-panels to applet
setLayout(new GridLayout(4,1));
//Setting layout for header panel and adding components
GridLayout gl1 = new GridLayout(5,2);
pan_hdr.setLayout(gl1);
pan_hdr.add(doc_type);
pan_hdr.add(DOC_TYPE);
pan_hdr.add(co_code);
pan_hdr.add(CO_CODE);
pan_hdr.add(purch_org);
pan_hdr.add(PURCH_ORG);
pan_hdr.add(pur_group);
pan_hdr.add(PUR_GROUP);
pan_hdr.add(vendor);
pan_hdr.add(VENDOR);
add(pan_hdr);
//Setting layout for line item panel and adding components
GridLayout gl2 = new GridLayout(7,7);
pan_itm.setLayout(gl2);
pan_itm.add(po_item);
pan_itm.add(pur_mat);
pan_itm.add(plant);
pan_itm.add(unit);
pan_itm.add(net_price);
pan_itm.add(deliv_date);
pan_itm.add(quantity);
for(i = 0; i < 5; i++)
{
PO_ITEM<i> = new TextField();
PUR_MAT<i> = new TextField();
PLANT<i> = new TextField();
UNIT<i> = new TextField();
NET_PRICE<i> = new TextField();
DELIV_DATE<i> = new TextField();
QUANTITY<i> = new TextField();
pan_itm.add(PO_ITEM<i>);
pan_itm.add(PUR_MAT<i>);
pan_itm.add(PLANT<i>);
pan_itm.add(UNIT<i>);
pan_itm.add(NET_PRICE<i>);
pan_itm.add(DELIV_DATE<i>);
pan_itm.add(QUANTITY<i>);
}
pan_itm.add(bc);
pan_itm.add(bt);
pan_itm.add(br);
pan_itm.add(bd);
add(pan_itm);
add(status);
}
public void actionPerformed(ActionEvent ae)
{
msg = "";
if (ae.getSource() == bt)
this.submitToSAP();
else if (ae.getSource() == bc)
this.connectDirectToSAP();
else if (ae.getSource() == br)
this.resetValues();
else if (ae.getSource() == bd)
this.disconnectFromSAP();
}
private void connectDirectToSAP()
{
// Change the logon information to your own system/user
mConnection =
JCO.createClient("210", // SAP client
"DEV07", // userid
"dra", // password
"EN", // language (null for the default language)
"10.111.16.26", // application server host name
"00"); // system number
try {
mConnection.connect();
msg = "Connection successfully established";
this.setStatus();
System.out.println("Connection successfully established");
}
catch (Exception ex) {
msg = ex.getMessage();
this.setStatus();
System.exit(1);
}
}
private void resetValues()
{
DOC_TYPE.setText("");
PURCH_ORG.setText("");
PUR_GROUP.setText("");
CO_CODE.setText("");
VENDOR.setText("");
status.setText("");
for (int i = 0; i < 5; i++)
{
PO_ITEM<i>.setText("");
PUR_MAT<i>.setText("");
PLANT<i>.setText("");
UNIT<i>.setText("");
NET_PRICE<i>.setText("");
DELIV_DATE<i>.setText("");
QUANTITY<i>.setText("");
}
}
private void submitToSAP()
{
msg = "Please wait...";
this.setStatus();
System.out.println("Please wait...");
//creation of Repository object and object for the BAPI
if(mConnection == null)
{
msg = "Please conect first to the SAP system";
this.setStatus();
System.out.println(msg);
//System.exit(0);
}
mRepository = new JCO.Repository("ARAsoft", mConnection);
JCO.Function function = null;
function = BAPITip.createFunction("BAPI_PO_CREATE");
//setting the import parameters
JCO.Structure PO_HDR = function.getImportParameterList()
.getStructure("PO_HEADER");
JCO.Table PO_LITEMS = function.getTableParameterList().getTable("PO_ITEMS");
JCO.Table PO_ITM_SCH = function.getTableParameterList().getTable("PO_ITEM_SCHEDULES");
PO_HDR.setValue(DOC_TYPE.getText(),"DOC_TYPE");
PO_HDR.setValue(CO_CODE.getText(),"CO_CODE");
PO_HDR.setValue(PURCH_ORG.getText(),"PURCH_ORG");
PO_HDR.setValue(PUR_GROUP.getText(),"PUR_GROUP");
PO_HDR.setValue(VENDOR.getText(),"VENDOR");
for(int i = 0; i < 5; i++)
{
if (PO_ITEM<i>.getText() != "")
{
PO_LITEMS.appendRow();
PO_LITEMS.setValue(PO_ITEM<i>.getText(),"PO_ITEM");
PO_LITEMS.setValue(PUR_MAT<i>.getText(),"PUR_MAT");
PO_LITEMS.setValue(PLANT<i>.getText(),"PLANT");
PO_LITEMS.setValue(UNIT<i>.getText(),"UNIT");
PO_LITEMS.setValue(NET_PRICE<i>.getText(),"NET_PRICE");
PO_ITM_SCH.appendRow();
PO_ITM_SCH.setValue(PO_ITEM<i>.getText(),"PO_ITEM");
PO_ITM_SCH.setValue(new Date(),"DELIV_DATE");
PO_ITM_SCH.setValue(QUANTITY<i>.getText(),"QUANTITY");
}
}
//executing the BAPI
mConnection.execute(function);
//accessing export parameters
JCO.Table returnTable =
function.getTableParameterList().getTable("RETURN");
if(returnTable.getNumRows() != 0)
{
for (int i = 0; i < returnTable.getNumRows(); i++)
{
returnTable.setRow(i);
if (! (returnTable.getString("TYPE").equals("") ||
returnTable.getString("TYPE").equals("S") ||
returnTable.getString("TYPE").equals("W")) )
{
if (i == 0)
status.setText("");
msg = returnTable.getString("MESSAGE");
System.out.println(returnTable.getString("MESSAGE"));
}
}
}
String PO_NUM = function.getExportParameterList().
getString("PURCHASEORDER");
if (PO_NUM != null)
{
flag = 'a';
msg = "Purchase order " + PO_NUM + " created successfully!";
this.setStatus();
System.out.println(msg);
}
}
private void disconnectFromSAP()
{
mConnection.disconnect();
msg = "Disconnected from SAP system...";
this.setStatus();
System.out.println("Disconnected from SAP system...");
}
public static JCO.Function createFunction(String name)
{
IFunctionTemplate ft =
mRepository.getFunctionTemplate(name.toUpperCase());
if (ft == null)
return null;
return ft.getFunction();
}
private void setStatus()
{
status.setText("");
status.setText(msg);
}
private void appendStatus()
{
status.append(" " + msg);
}
public static void main(String args[])
{
BAPITip fb = new BAPITip();
}
regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.