2008 Jun 24 12:06 PM
Hello!
How can I start (=call) a java program from ABAP? I have only .class and .java files.
Thanks!
2008 Jun 24 12:08 PM
use this
FUNCTION ZJAVAFROMABAP.
*"----
""Local Interface:
*"----
DATA:
COMMAND TYPE STRING VALUE 'C:\j2sdk1.4.2_12\bin\javac',
COMMAND1 TYPE STRING VALUE 'C:\j2sdk1.4.2_12\bin\java',
DIR TYPE STRING VALUE 'C:\j2sdk1.4.2_12\bin\',
PARAMETER TYPE STRING VALUE 'HelloWorld.java',
PARAMETER1 TYPE STRING VALUE 'HelloWorld'.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
EXPORTING
APPLICATION = Command
PARAMETER = PARAMETER
DEFAULT_DIRECTORY = DIR
MAXIMIZED = 'X'
MINIMIZED = '' "If you need the DOS window to be minimized
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
BAD_PARAMETER = 3
FILE_NOT_FOUND = 4
PATH_NOT_FOUND = 5
FILE_EXTENSION_UNKNOWN = 6
ERROR_EXECUTE_FAILED = 7
OTHERS = 8.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
EXPORTING
APPLICATION = Command1
PARAMETER = PARAMETER1
DEFAULT_DIRECTORY = DIR
MAXIMIZED = ''
MINIMIZED = 'X' "If you need the DOS window to be minimized
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
BAD_PARAMETER = 3
FILE_NOT_FOUND = 4
PATH_NOT_FOUND = 5
FILE_EXTENSION_UNKNOWN = 6
ERROR_EXECUTE_FAILED = 7
OTHERS = 8.
write : 'After calling the java function'.
ENDFUNCTION.
Reward point if helpful
2008 Jun 24 12:08 PM
use this
FUNCTION ZJAVAFROMABAP.
*"----
""Local Interface:
*"----
DATA:
COMMAND TYPE STRING VALUE 'C:\j2sdk1.4.2_12\bin\javac',
COMMAND1 TYPE STRING VALUE 'C:\j2sdk1.4.2_12\bin\java',
DIR TYPE STRING VALUE 'C:\j2sdk1.4.2_12\bin\',
PARAMETER TYPE STRING VALUE 'HelloWorld.java',
PARAMETER1 TYPE STRING VALUE 'HelloWorld'.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
EXPORTING
APPLICATION = Command
PARAMETER = PARAMETER
DEFAULT_DIRECTORY = DIR
MAXIMIZED = 'X'
MINIMIZED = '' "If you need the DOS window to be minimized
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
BAD_PARAMETER = 3
FILE_NOT_FOUND = 4
PATH_NOT_FOUND = 5
FILE_EXTENSION_UNKNOWN = 6
ERROR_EXECUTE_FAILED = 7
OTHERS = 8.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
EXPORTING
APPLICATION = Command1
PARAMETER = PARAMETER1
DEFAULT_DIRECTORY = DIR
MAXIMIZED = ''
MINIMIZED = 'X' "If you need the DOS window to be minimized
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
BAD_PARAMETER = 3
FILE_NOT_FOUND = 4
PATH_NOT_FOUND = 5
FILE_EXTENSION_UNKNOWN = 6
ERROR_EXECUTE_FAILED = 7
OTHERS = 8.
write : 'After calling the java function'.
ENDFUNCTION.
Reward point if helpful
2008 Jun 25 11:04 AM
Thanks!
I see console appeared and very quick disapperared. I can't read anything... What can I write that I can see e.g. HelloWord??
2008 Jun 25 11:07 AM
put some wait in java code....
I don't know java ....
so can't help u on this....
Reward point if helpful
2008 Jun 25 11:33 AM
2008 Jun 25 12:58 PM
I have the code:
REPORT javaabap.
DATA:
command TYPE string VALUE 'C:\j2sdk1.4.2_13\bin\java',
parameter TYPE string VALUE 'c:\HelloWorld'.
CALL METHOD cl_gui_frontend_services=>execute
EXPORTING
application = command
parameter = parameter
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
bad_parameter = 3
file_not_found = 4
path_not_found = 5
file_extension_unknown = 6
error_execute_failed = 7
OTHERS = 8.
Where is error?
2008 Jun 25 1:16 PM
U have not use
DIR TYPE STRING VALUE 'C:\j2sdk1.4.2_12\bin\',
CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
EXPORTING
APPLICATION = Command
PARAMETER = PARAMETER
DEFAULT_DIRECTORY = DIR
MAXIMIZED = 'X'
MINIMIZED = '' "If you need the DOS window to be minimized
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
BAD_PARAMETER = 3
FILE_NOT_FOUND = 4
PATH_NOT_FOUND = 5
FILE_EXTENSION_UNKNOWN = 6
ERROR_EXECUTE_FAILED = 7
OTHERS = 8.
or first u run javac for compiling the .java file.....
Edited by: Amitava De on Jun 25, 2008 5:48 PM
2008 Jun 25 1:25 PM
Ok Thanks! All is ok!! I have deleted ...\dir. But I always see short-time console. I can't see anything. I have written .bat file and executed it.
Thanks! All function!!
2008 Jun 24 12:09 PM
Refer:
/people/vijayasarathy.raghunathan/blog/2005/12/28/java-editor-inside-abap
http://www.thespot4sap.com/Articles/SAP_Netweaver_Java_Connector.asp
Check out this blog...
/people/gregor.wolf3/blog/2004/08/26/setup-and-test-sap-java-connector-outbound-connection
2008 Jun 24 12:11 PM
Hi,
Using the SAP Java Connector
SAPu2019s new Java middleware, the SAP Java Connector (JCO) allows customers and partners to easily build SAP-enabled components in Java. JCO supports both inbound (Java calls ABAP) and outbound (ABAP calls Java) calls in desktop and server applications.
Sample program
Import statements: Any program using JCO should contain the following import statement:
import com.sap.mw.jco.*;
Otherwise, you have to fully qualify each class and interface which is very inconvenient.
Connecting to SAP
JCO.Client mConnection;
A connection (or session) with SAP is handled by class JCO.Client
try {
mConnection =
JCO.createClient("400", // SAP client
"c3026902", // userid
"********", // password
"EN", // language
"iwdf5020", // host name
"00"); // system number
mConnection.connect();
}
catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
"A Client object is created via a call to createClient(). You can use a specific application server (as in the above code) or a server group (load balancing)." REFER the JCO Javadoc for the overloaded createClient() method for the latter possibility.
"The Client class's connect () method tries to log on to SAP. If that fails for any reason, an exception is thrown. If the call succeeds, we can now stay connected for as long as we like. When we are done, we can call disconnect () to explicitly log off."
Hope this sample would help you..
Regards
Narin Nandivada
2008 Jun 25 1:08 PM
You might have to try with the code from Amitava De.
First you will need to make your java program 'HelloWorld.java'.
Then you might have to put your source 'HelloWorld.java' in directory 'C:\j2sdk1.4.2_12\bin\' before executing the Abap code.
Hope that helps,
Rolf