Skip to Content

Hi , 

I am trying to connect to SAP PI System through JCO by passing ‘messageid’ and ‘version’  as a parameters to RFC ‘SXMB_GET_MESSAGE_DATA’  and trying to fetch some colums/rows where i’m getting convertion error please refer the below code and also find the error message that iam getting,and correct me whether my approach is correct or not .Could any one please help me on this  and let me know the solution .Thanking in advance

Thanks,

Ganesh.

SampleJco.java

import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
import com.sap.conn.jco.AbapException;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoMetaData;
import com.sap.conn.jco.JCoStructure;
import com.sap.conn.jco.JCoTable;
import com.sap.conn.jco.ext.DestinationDataProvider;

public class SampleJco {
  static String DESTINATION_NAME1 = “ABAP_AS_WITHOUT_POOL”;
     static String DESTINATION_NAME2 = “ABAP_AS_WITH_POOL”;
     static
     {
         Properties connectProperties = new Properties();
         connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, “mb5sap1008”);
         connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,  “00”);
         connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, “100”);
         connectProperties.setProperty(DestinationDataProvider.JCO_USER,   “P71DEV12”);
         connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, “devpas12”);
         connectProperties.setProperty(DestinationDataProvider.JCO_LANG,   “en”);
         createDestinationDataFile(DESTINATION_NAME1, connectProperties);
         connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, “3”);
         connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,    “10”);
        createDestinationDataFile(DESTINATION_NAME2, connectProperties);
     }
     static void createDestinationDataFile(String destinationName, Properties connectProperties)
     {
         File destCfg = new File(destinationName+”.jcoDestination”);
         try
         {
            FileOutputStream fos = new FileOutputStream(destCfg, false);
             connectProperties.store(fos, “for tests only !”);
             fos.close();
         }
         catch (Exception e)
        {
             throw new RuntimeException(“Unable to create the destination files”, e);
         }
     }
     public static void connect() throws JCoException
     {
         JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME1);
         System.out.println(“Attributes:”);
         System.out.println(destination.getAttributes());
         System.out.println();
     }
     public static void connectUsingPool() throws JCoException
     {
         JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME2);
         destination.ping();
         System.out.println(“Attributes:”);
         System.out.println(destination.getAttributes());
         System.out.println();
     }
  public static void simpleCall() throws JCoException
     {
      JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME2);
         JCoFunction function = destination.getRepository().getFunction(“SXMB_GET_MESSAGE_DATA”);
         if (function == null)   
         throw new RuntimeException(“SXMB_GET_MESSAGE_DATA not found in SAP.”);
        // function.getImportParameterList().setValue(“MSGGUID”, “BCA8B633-1FF2-493A-2A2F-C97D8C968145”);
        // function.getImportParameterList().setValue(“VERSION”, “000”);
         String messageId =”E20611A5ED88F1F19BECB8AC6F850182″;
         byte[] bytes = messageId.getBytes();
         function.getImportParameterList().setValue(“IM_MESSAGE_LIST”,bytes);
        // function.getImportParameterList().setValue(“IM_PIPELINE_LIST”, JCoMetaData.TYPE_NUM);
         System.out.println(“After import”+function.getImportParameterList());
         try
         {
             function.execute(destination);
         }
         catch (AbapException e)
         {
             System.out.println(e.toString());
             return;
         }
         JCoStructure returnStructure = function.getExportParameterList().getStructure(“RETURN”);
         //JCoStructure returnStructure = function.getExportParameterList().getStructure(“EX_MESSAGE_DATA_LIST”);
         if (! (returnStructure.getString(“TYPE”).equals(“”)||returnStructure.getString(“TYPE”).equals(“S”)) ||
                   returnStructure.getString(“TYPE”).equals(“W”) )  
         {
            throw new RuntimeException(returnStructure.getString(“MESSAGE”));
         }
         System.out.println(“returnStructure.toXML()…..”+returnStructure.toXML());
          }
    public static void workWithTable() throws JCoException
     {
         JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME2);
         JCoFunction function = destination.getRepository().getFunction(“SXMB_GET_MESSAGE_DATA”);
         if (function == null)
             throw new RuntimeException(“SXMB_GET_MESSAGE_DATA not found in SAP.”);
         try
         {
             function.execute(destination);
         }
         catch(AbapException e)
         {
             System.out.println(e.toString());
             return;
         }
         JCoStructure returnStructure = function.getExportParameterList().getStructure(“RETURN”);
         if (! (returnStructure.getString(“TYPE”).equals(“”)||returnStructure.getString(“TYPE”).equals(“S”)) ||
                   returnStructure.getString(“TYPE”).equals(“W”) )  
         {
            throw new RuntimeException(returnStructure.getString(“MESSAGE”));
         }
        
        JCoTable codes = function.getTableParameterList().getTable(“SXMSPVERS”);
        // for (int i = 0; i < codes.getNumRows(); i++)
        // {
        //     codes.setRow(i);
        //     System.out.println(codes.getString(“MSGGUID”) + ‘\t’ + codes.getString(“VERS”));
       //  }
         codes.firstRow();
         for (int i = 0; i < codes.getNumRows(); i++, codes.nextRow())
         {
             function = destination.getRepository().getFunction(“SXMB_GET_MESSAGE_DATA”);
             if (function == null)
                 throw new RuntimeException(“SXMB_GET_MESSAGE_DATA not found in SAP.”);
             //function.getImportParameterList().setValue(codes.getString(“MSGGUID”),”IM_MESSAGE_LIST”);
             function.getImportParameterList().setValue(“IM_MESSAGE_LIST”,”BCA8B6331FF2493A2A2FC97D8C968145″.getBytes());
             function.getImportParameterList().setValue(“IM_PIPELINE_LIST”,JCoMetaData.TYPE_BYTE);
             //function.getExportParameterList().setActive(“EX_MESSAGE_DATA_LIST”,false);
             try
             {
             function.execute(destination);
            
         }
         catch (AbapException e)
        {
                 System.out.println(e.toString());
                 return;
        }
        returnStructure = function.getExportParameterList().getStructure(“RETURN”);
             if (! (returnStructure.getString(“TYPE”).equals(“”) ||
                    returnStructure.getString(“TYPE”).equals(“S”) ||
                   returnStructure.getString(“TYPE”).equals(“W”)) )
             {
                throw new RuntimeException(returnStructure.getString(“MESSAGE”));
             }
            JCoStructure detail = function.getExportParameterList().getStructure(“EX_MESSAGE_DATA_LIST”);
             System.out.println(detail.getString(“MSGGUID”) + ‘\t’ +
                                detail.getString(“VERS”));
            
            
         }
     }
    
     public static void main( String [] args ) {
         System.out.println(“In main method”);
         try {
          System.out.println(“befor connect method”);
    connect();
    System.out.println(” afetr connectmethod”);
    connectUsingPool();
    System.out.println(“after connectUsingPool method”);
    //simpleCall();
    //System.out.println(“after step3SimpleCall method”);
    workWithTable();
   } catch (JCoException e) {
    e.printStackTrace();
   }
        
     }
}

Error :

after connectUsingPool method

Exception in thread “main” com.sap.conn.jco.ConversionException: (122) JCO_ERROR_CONVERSION: Cannot convert a value from type byte[] to TABLE at field IM_MESSAGE_LIST

at com.sap.conn.jco.rt.AbstractRecord.createConversionException(AbstractRecord.java:442)

at com.sap.conn.jco.rt.AbstractRecord.createConversionException(AbstractRecord.java:430)

at com.sap.conn.jco.rt.AbstractRecord.setValue(AbstractRecord.java:3653)

at com.sap.conn.jco.rt.AbstractRecord.setValue(AbstractRecord.java:4173)

at com.accenture.Controller.SampleJco.simpleCall(SampleJco.java:79)

at com.accenture.Controller.SampleJco.main(SampleJco.java:171)

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply