com.sap.conn.jco.ConversionException: (122) JCO_ERROR_CONVERSION : String to Date field

3.6k views Asked by At

I am working on SAP JCo and getting exception while setting date 12.16.2016:

com.sap.conn.jco.ConversionException: (122) JCO_ERROR_CONVERSION: Cannot convert a value of '12.16.2016' from type java.lang.String to STRUCTURE at field DATE.

My code is

public static void YP_ECA_VIN(String date, String plant) throws Exception {
  try {
    JCoDestination destination;
    JCoRepository sapRepository;
    destination = JCoDestinationManager.getDestination(DST1);
    JCoDestinationManager.getDestination(DST1);     
    JCoContext.begin(destination);
    sapRepository = destination.getRepository();        
    if (sapRepository == null) {
      System.out.println("Couldn't get repository!");
      JCoContext.end(destination);
      System.exit(0);
    } 
    JCoFunctionTemplate template = sapRepository.getFunctionTemplate("YP_ECA_VIN");     
    if (template == null) {
      System.out.println("Couldn't get template for YP_ECA_VIN!");
    } else {
      JCoFunction function = template.getFunction();
      function.getImportParameterList().setValue("DATE", "12.16.2016");
      function.getImportParameterList().setValue("PLANT", plant);
      function.execute(destination);
      int numTRows = 0;
      int numTCoulmns = 0;
      JCoTable table = function.getExportParameterList().getTable("OUTPUT");
      // some code
    }
2

There are 2 answers

2
Pritam On

All parameters in JCO.Functions should be strings. Try to set date-values as strings too. In SAP the format for date-strings is "yyyyMMdd" like "20161223".

0
Trixx On

The RFM import parameter named DATE is obviously not of a date type but a structure type instead. In this case you would have to use a JCoStructure instance at JCo side and not a String.

But I'd rather assume that you made a mistake when defining the remote function module interface YP_ECA_VIN at ABAP side and you would like this import parameter DATE to be really of an ABAP date type instead.