on 07-19-2005 6:46 AM
Hi all,
I am trying to connect to R/3 and call an RFC.
I have included the following line of code :-
IConnectorGatewayService cgservice = PortalRuntime.getRuntimeResources().getService(IConnectorGatewayService);
But it gives a compilation error saying "IConnectorGatewayService cannot be resolved".
Can some one tell me what is the right PAR file which i need to include in my build path to avoid this problem.
It will be really helpful if some one can give me any example showing how we connect to R/3 and call an RFC.
Thanks in advance.
Regards,
Narahari
Hi Narahari,
You need to include the jar file called
com.sap.portal.ivs.connectorserviceapi.jar
Here is some example code which explains the steps you need to take to connect to R/3 and execute a BAPI or RFC:
//1. get connector gateway service
IConnectorGatewayService cgs=PortalRuntime.getRuntimeResources.getService(IConnectorGatewayService.KEY);
//2. get a connection
IConnection conn=cgs.getConnection("SAP",request);
//or
ConnectionProperties cp=new ConnectionProperties(request.getLocale(),request.getUser());
IConnection conn=cgs.getConnection("SAP",cp);
//3. get interaction
IInteraction ix=conn.getInteractionEx();
//4. get ineractionspec;
IInteractionSpec ixspec=ix.getInteractionSpec();
ixspec.setPropertyValue("NAME","BAPI..");
//5. fill input parameters
//input field
RecordFactory rf=ix.getRecordFactory();
MappedRecord input=rf.createMappedRecord("input");
input.put("INPUT_FIELD",value);
//input structure
IFunction function=conn.getFunctionsMetaData().getFunction("BAPI..");
IStructureFactory sf=ix.retrieveStructureFactory();
IRecord structure=(IRecord) sf.getStructure(function.getParameter("INPUT_STRUCTURE").getStructure());
structure.setString("veld1", value1);
structure.setString("veld2",value2);
input.put("INPUT_STRUCTURE",structure);
//input table
IFunction function=conn.getFunctionsMetaData().getFunction("RFC..");
IStructureFactory sf=ix.retrieveStructureFactory();
IRecordSet table=(IRecordSet) sf.getStructure(function.getParameter("INPUT_TABLE").getStructure());
table.insertRow();
table.setString("veld1",value1_1);
table.setString("veld2",value1_2);
table.insertRow();
table.setString("veld1",value2_2);
...
input.put("INPUT_TABLE",table);
//6. execute function
MappedRecord output=(MappedRecord) ix.execute(ixspec, input);
//7. retrieve results
Object result=output.get("outputtable");
//8. cast result to appropriate type, for instance IRecordSet, and use the contents in your application
Regards,
Johan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Thank you for ur response.
Could you please show me how to handle the result also(using RecordMetaDeta etc.) including handling internal table ouput and also normal values(coming from R/3)??
This will of great help for me.
Regards,
Narahari
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
103 | |
6 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.