0

i have a SAP-DLL to enable communication between a Programming interface and the SAP Programm.

I have following example Code for c# in combination with the dll-File:

var loggerService = LoggerService.GetLoggerService("FileLogger");
var itasProxy = SapProxyFactory.CreateSapProxy(SapSystem.Example, loggerService, "Example_User", StringExtension.CreateSecureString("Example_Password")); 
var funcResult = sapProxy.SearchSapAddress(clientNo);

if (funcResult.Successfull)
{
    funcResult.ReturnValue = withFormatting
        ? AddressFormatter.SplitStreetHouseNo(funcResult.ReturnValue)
        : funcResult.ReturnValue;
}

Now i want the same functionality to be transferred to java. I have absolutely no clue how to do that. I tried the following with Loggerservice as a starter, but it doesn't work:

public class SAPConnector {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        connectSAP();
    }
    public void connectSAP()
    {
        System.load("C://Temp//SapConnector.dll");
        Object loggerService = getLoggerService("FileLogger");
    }
    public native Object getLoggerService(String lcLogger);
}

i just need some kind of information how to call the Functions from the dll or an example how to transfer the C# Code to working Code in Java.

Greetings,

Kevin

6
  • @john: no it isn't the thread you posted is based on an entirely different dll-Problem Commented Dec 15, 2017 at 8:11
  • Fine, I'll delete my duplicate suggestions. You are, however, looking for a way to call C# code from Java, are you not? If that is not the case, you should re-word your question. Commented Dec 15, 2017 at 8:13
  • I can´t see what those two snippets have in common. From my opinion they are completely different. Anyway when you write "doesn´t work", what does that mean? Show exactlx what you´ve tried and what problems you got on doing so. This includes your current cide and every error/exception/unexpected behaviour/unexpected results you get. Commented Dec 15, 2017 at 8:16
  • yes, i am, but you have to read my text. It is a special case, i already tried several things that i read at stackoverflow, nothing work, because i can't get the right syntax for the native support. My dll uses it's own classes and data types and i have no idea how to get java to recognize these functions and data types, i just need one example from my code i posted so that i can find a solution Commented Dec 15, 2017 at 8:17
  • @HimBromBeere with the code i have now i get the error UnsatisfiedClassLink on the line 10 in my java code.... and like i said, the first snippet is the working c# Code in combination with the dll, now i need that same code with same functionality to be working in java :) Commented Dec 15, 2017 at 8:19

1 Answer 1

3

DLL is Microsoft format. Java is cross-platform, thus can't acknowledge anything operating-system specific, such as DLL.

One way around that is to use JNI (Java Native Interface), but that's usually not a good solution, as it makes your program platform-dependent.

Instead, I would look for a JAR from SAP, that provides a similar interface. Maybe something along SAP JCO.

You can see some actual code examples using JCO here, and some technical information on step-by-step download and configure here.

Sign up to request clarification or add additional context in comments.

10 Comments

thanks for the comment, i already searched for it, but for now i have to get this working... like you saw, i tried JNI, but i think i made a mistake or forgot something, it's the first time i use it ...another solution i had in mind is make the code with vbs and call the vbs script from java, but that's not a good solution as well...
Although Java is plattform-independent - as .NET also (see stackoverflow.com/questions/3656721/is-net-platform-independent) - this doesn´t mean every java-code can be run on any OS. There exist many such programs that only run on windows-machines. Having said this JNI is exactly what OP needs and calling a .NET-assembly from JAVA is absolutely okay.
@HimBromBeere is my syntax ok? or did i miss something to get this working?
Yeah, well, I agree it is very much dependent on your business scenario. I would be very surprised if SAP don't supply the same thing in a JAR, though. They are more Java-Oriented than many other companies. @KevinBarz if you do go with JNI, maybe the Tutorial in the link can help you. Did you follow the same steps?
@YoavGur i already tried several things, that's why i was looking for an answer, but i will try again with your tutorial
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.