Tips and tricks for the Java connector

 

How to set and import parameter - Field
How to handle an import parameter - Table
How to handle an import parameter - Structure
How to handle an export parameter - Table
How to handle BAPI return table
Using COMMIT

 

 

How to set and import parameter - Field

Give the import parameter SALESDOCUMENT the value "00006973":

JCO.Field SalesDocumentField = jcoFunction.getImportParameterList().getField("SALESDOCUMENT");
SalesDocumentField.setValue("00006973");

 

How to handle an import parameter - Table

JCO.Table ORDER_PARTNERS = jcoFunction.getTableParameterList().getTable("ORDER_PARTNERS");
ORDER_PARTNERS.appendRow();
ORDER_PARTNERS.setValue("AG","PARTN_ROLE");
ORDER_PARTNERS.setValue("0000001032","PARTN_NUMB");

 

How to handle an import parameter - Structure

JCO.Structure order_header_inx = jcoFunction.getImportParameterList().getStructure("ORDER_HEADER_INX");
order_header_inx.setValue("I","UPDATEFLAG");
order_header_inx.setValue("X","DOC_TYPE");

 

How to handle an export parameter - Table

JCO.Table myTable = jcoFunction.getTableParameterList().getTable("STATUSINFO");

for (int i=0; i < myTable.getNumRows(); i++)
  myTable.setRow(i);
  // Retrieve the value of the field DOC_DATE 
  oDocDate = myTable.getField("DOC_DATE").getValue();

How to handle BAPI return table

Meesage type and message is stored in vector bapiReturn.
Vector bapiReturn;
JCO.Table jcoReturn = jcoFunction.getTableParameterList().getTable("RETURN");
    for (int i = 0; i < jcoReturn.getNumRows(); i++)
    { jcoReturn.setRow(i);
      String Message = jcoReturn.getField("TYPE").getValue() + " " +
                       jcoReturn.getField("MESSAGE").getValue();

      bapiReturn.setSize(i + 1);
      bapiReturn.setElementAt(new String(Message),i );
    }

 

Using COMMIT

    try
     { // Get a function template from the repository
       IFunctionTemplate ftemplate = mRepository.getFunctionTemplate("BAPI_TRANSACTION_COMMIT");

       // Create a function from the template
       jcoCommit = new JCO.Function(ftemplate);

       if ( jcoCommit == null )
         // Do something..;
     }
    catch (Exception mException)
     {  mException.printStackTrace(); }

    // Execute COMMIT
    try
     { sapConnection1.mConnection.execute(jcoCommit);
     }
    catch (Exception mException)
     { mException.printStackTrace(); }
Converted from CHM to HTML with chm2web Standard 2.7 (unicode)