Skip to Content
author's profile photo Former Member
Former Member

JCO from Message Mapping in XI

I'm trying to create a function in XI Message Mapping that saves some information in a XI DB table using JCO.

I've created DB table ZEDI with Fields A,B,C,D. My function is following:

imports:java.lang.String;java.io.ByteArrayInputStream;java.io.InputStream;com.sap.mw.jco.*;

public String WriteTable(String ISA,String GS,Container container){

//write your code here

String DBTABLE = "ZEDI";

String sapClient = "200";

String hostName = "10.1.10.81";

String systemNumber = "00";

String userName = "DBuser";

String password = "DBpass";

String language = "EN";

int i = 0;

JCO.Repository mRepository;

JCO.Client mConnection = JCO.createClient(

sapClient,

userName,

password,

language,

hostName,

systemNumber );

// connect to SAP

mConnection.connect();

// create repository

mRepository = new JCO.Repository( "GenericLookup", mConnection );

// create function template to select data from any table

JCO.Function function = null;

IFunctionTemplate ft = mRepository.getFunctionTemplate("ZEDI");

function = ft.getFunction();

//JCO.ParameterList lookupFieldPos = function.getImportParameterList();

JCO.Table FieldPos = function.getTableParameterList().getTable("ZEDI");

// Pass function parameters

FieldPos.setValue(ISA,"A");

FieldPos.setValue(GS,"B");

mConnection.execute(function );

mConnection.disconnect();

return ISA;

Message Mapping test returns Exception:[java.lang.NullPointerException].

Do you have any idea what do I need to change to make it working?

Thanks!

Naycho

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 17, 2008 at 11:39 AM

    Hi Naycho

    You have created a SAP table, but you have to create ABAP Function Module (RFC) with import /export parameters to access tables via JCO.

    The null pointer exception is because - IFunctionTemplate ft = mRepository.getFunctionTemplate("ZEDI");

    is searching for a function not table name.

    hope this helps

    Regards

    Prahllad

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 15, 2008 at 11:10 PM

    My mapping is working fine without this function.

    Is JDBC better option?

    Regards

    Naycho

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      >>Is JDBC better option?

      Definitely. It is the approach recommended by SAP.

      Some reason behind this is you dont need to hard code user id, pwd in the UDF. You can feel the advantage of this when you transport the objects to QA and then to Prod. JDBC lookups internally uses JCO, but since it is designed by SAP it can be a better option in terms of performance.

      Regards,

      Jai Shankar

  • author's profile photo Former Member
    Former Member
    Posted on Jan 15, 2008 at 10:36 PM

    Hi Stoitsov,

    Just to make sure that the null pointer exception is coming for this field only just disable the target field whereever you using in your mapping and give a try once again and see whether you have the same error or not.

    Also I would suggest to make a JDBC lookup directly instead of JCO.

    Regards,

    ---Satish

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 16, 2008 at 01:19 PM

    I've decided to to use ABAP function in XI for DB calls.

    So I just need to popule function parameters from my message mapping.

    Thanks for your help here.

    Regards

    Naycho

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.