cancel
Showing results for 
Search instead for 
Did you mean: 

JavaConnector (JCo) RFC call of function module BDS_BUSINESSDOCUMENT_CRE_O_URL does not work

mario_fliegner
Explorer
0 Kudos

Hi,

I'm trying to execute the fm BDS_BUSINESSDOCUMENT_CRE_O_URL via RFC but always get the following error:

com.sap.conn.jco.AbapException: (126) ERROR_DP: ERROR_DP Message 027 of class SBDS type W, Par[1]: 1
	at com.sap.conn.jco.rt.MiddlewareJavaRfc$JavaRfcClient.execute(MiddlewareJavaRfc.java:1875)
	at com.sap.conn.jco.rt.ClientConnection.execute(ClientConnection.java:1120)
	at com.sap.conn.jco.rt.ClientConnection.execute(ClientConnection.java:953)
	at com.sap.conn.jco.rt.RfcDestination.execute(RfcDestination.java:1465)
	at com.sap.conn.jco.rt.RfcDestination.execute(RfcDestination.java:1435)
	at com.sap.conn.jco.rt.AbapFunction.execute(AbapFunction.java:300)


If I try to execute the fm in SE37 with the same values, it works fine. Can anyone tell my what this error message mean? I just find that might be a "data provider issue". So I assume it's related to my Java code?

Attached is the class that I'm using.

Does anyone know or see what I'm doing wrong?package com.company;

package com.company;

import com.sap.conn.jco.*;
import com.sap.conn.jco.ext.DestinationDataProvider;

import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;

public class RFCTest {

    public static void main(String[] args) throws Exception {
        executeFunctionModule();
    }
    static String DESTINATION_SAP1 = "SAPSYSTEM1";
    static String DESTINATION_SAP2 = "SAPSYSTEM2";
    static
    {
        //SAP System 1
        Properties connectProperties = new Properties();
        connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "IPAddressSAP1");
        connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,  "20");
        connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "800");
        connectProperties.setProperty(DestinationDataProvider.JCO_USER,   "admin");
        connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "admin");
        connectProperties.setProperty(DestinationDataProvider.JCO_LANG,   "en");
        createDestinationDataFile(DESTINATION_SAP1, connectProperties);

        //SAP System 2
        connectProperties = new Properties();
        connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "IPAddressSAP2");
        connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,  "22");
        connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "220");
        connectProperties.setProperty(DestinationDataProvider.JCO_USER,   "admin1");
        connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "mypassword2");
        connectProperties.setProperty(DestinationDataProvider.JCO_LANG,   "en");
        createDestinationDataFile(DESTINATION_SAP2, 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);
        }
    }

    /////////////////////////////
    // now create any method, to invoke the SAP function.
    public static void executeFunctionModule() throws JCoException
    {
        /**
         * SE37 => BDS_BUSINESSDOCUMENT_CRE_O_URL
         *"-----------------------------------------------------
         * FUNCTION bds_businessdocument_cre_o_url.
         *"*"Local interface:
         *"  IMPORTING
         *"     VALUE(LOGICAL_SYSTEM) LIKE  BAPIBDS01-LOG_SYSTEM OPTIONAL
         *"     VALUE(CLASSNAME) LIKE  BAPIBDS01-CLASSNAME
         *"     VALUE(CLASSTYPE) LIKE  BAPIBDS01-CLASSTYPE
         *"     VALUE(CLIENT) LIKE  BAPIBDS01-CLIENT DEFAULT SY-MANDT
         *"     VALUE(OBJECT_KEY) LIKE  BAPIBDS01-OBJKEY OPTIONAL
         *"     VALUE(URL) LIKE  BAPIBDS01-URI
         *"     VALUE(BINARY_FLAG) LIKE  BAPIBDS01-X DEFAULT 'X'
         *"     VALUE(MIMETYPE) LIKE  BAPIBDS01-MIMETYPE
         *"  EXPORTING
         *"     VALUE(DOC_ID) LIKE  BAPIBDS01-DOC_ID
         *"     VALUE(DOC_VER_NO) LIKE  BAPIBDS01-DOC_VER_NO
         *"     VALUE(DOC_VAR_ID) LIKE  BAPIBDS01-DOC_VAR_ID
         *"  TABLES
         *"      PROPERTIES STRUCTURE  BAPIPROPER OPTIONAL
         *"  EXCEPTIONS
         *"      NOTHING_FOUND
         *"      PARAMETER_ERROR
         *"      NOT_ALLOWED
         *"      ERROR_KPRO
         *"      INTERNAL_ERROR
         *"      NOT_AUTHORIZED
         *"      ERROR_DP
         */

        final String functionModule = "BDS_BUSINESSDOCUMENT_CRE_O_URL";
        JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_SAP1);
        JCoFunction function = destination.getRepository().getFunction(functionModule);
        if (function == null)
            throw new RuntimeException("<"+functionModule+"> not found in SAP.");

        destination.getRepository().getFunction(functionModule);
        JCoTable testTable = function.getTableParameterList().getTable("PROPERTIES");
        System.out.println("testTable.getNumColumns(): "  + testTable.getNumColumns() + " - NumRows: " +testTable.getNumRows());
        testTable.appendRow();
        testTable.setValue("PROP_NAME", "DESCRIPTION");
        testTable.setValue("PROP_VALUE", "This links to ALF");
        System.out.println("testTable.getValue(0): " + testTable.getValue(0));
        System.out.println("testTable.getValue(1): " + testTable.getValue(1));

        System.out.println("Connecting to SAP system: " + destination.getDestinationName());
        System.out.println("functionModule " + functionModule);

        JCoParameterList jcoImports = function.getImportParameterList();
        JCoParameterFieldIterator itr = jcoImports.getParameterFieldIterator();
        System.out.println("Import parameter list length: " + jcoImports.getFieldCount());
        for (JCoParameterFieldIterator iter = jcoImports.getParameterFieldIterator(); iter.hasNextField(); ) {
            JCoParameterField jcoParam = iter.nextParameterField();
            System.out.println("  - " + jcoParam.getName() + " (Default: <"+jcoParam.getDefault()+">): " + jcoParam.getValue() + " (classname of value = "+jcoParam.getClassNameOfValue()+")");
            jcoParam.getName();
        }

        JCoParameterList jcoTable = function.getTableParameterList();
        System.out.println("Table parameter length: " + jcoTable.getFieldCount());
        for (JCoParameterFieldIterator iter = jcoTable.getParameterFieldIterator(); iter.hasNextField(); ) {
            JCoParameterField jcoParam = iter.nextParameterField();
            System.out.println("  - " + jcoParam.getName() + "\n" + jcoParam.getValue() + "\n (classname of value = "+jcoParam.getClassNameOfValue()+")");
        }

        function.getImportParameterList().setValue("LOGICAL_SYSTEM", "MYSAPID1");  //OPTIONAL
        function.getImportParameterList().setValue("CLASSNAME", "BKPF");
        function.getImportParameterList().setValue("CLASSTYPE", "BO");
        function.getImportParameterList().setValue("CLIENT", "800");
        function.getImportParameterList().setValue("OBJECT_KEY", "100001000000022014");
        function.getImportParameterList().setValue("URL", "www.mywebsite.com");
        function.getImportParameterList().setValue("BINARY_FLAG", "");
        function.getImportParameterList().setValue("MIMETYPE", "TEXT/PLAIN");

        try {
            function.execute(destination);
        }
        catch(JCoException e) {
            e.printStackTrace();
        }
    }
}

PS: I'm not able to add the Java code as TXT attachment (even TXT seems to be allowed to add...) It says: This attachment is not permitted because the file type is invalid.

Accepted Solutions (0)

Answers (0)