on 02-24-2005 5:29 PM
Hello
I'm a newbie and I'm trying to connect to SAP with this simple application I took from SAP help but I got an error message. Below is the code. At the bottom is the error message I get. It seems like the public Connect1 is not a type or must be decleared first.I tried doing that but the problem still persist.Could any body show me how to get ride of this problem? Thank you all.
import com.sap.mw.jco.*;
public class JcoTest {
JCO.Client mConnection;
public Connect1() {
try{
mConnection = JCO.createClient("300",//SAP Cleint
"<Test>",//userid
"test2",//password
"EN",//language
"<sap6>",//host name
"00");// system number
mConnection.connect();
System.out.println(mConnection.getAttributes());
mConnection.disconnect();
}
catch (Exception ex){
ex.printStackTrace();
System.exit(1);
}
}
public static void main(String args[]) {
Connect1 app = new Connect1();
}
}
ERROR MESSAGE STARTS HERE:
java.lang.Error: Unresolved compilation problems:
Connect1 cannot be resolved or is not a type
Connect1 cannot be resolved or is not a type
at JcoTest.main(JcoTest.java:40)
Exception in thread "main"
I have fixed that. The new code looks like this:
import com.sap.mw.jco.*;
public class TutorialConnect1 {
JCO.Client mConnection;
public TutorialConnect1() {
try{
mConnection = JCO.createClient("300",//SAP Cleint
"<Test>",//userid
"test2",//password
"EN",//language
"<sap6>",//host name
"00");// system number
mConnection.connect();
System.out.println(mConnection.getAttributes());
mConnection.disconnect();
}
catch (Exception ex){
ex.printStackTrace();
System.exit(1);
}
}
public static void main(String args[]) {
TutorialConnect1 app = new TutorialConnect1();
}
}
Thank you all.
BUT NOW I GOT THE FOLLOWING ERRORS. ANY HELP WILL BE HIGHLY APPRECIATED.
java.lang.ExceptionInInitializerError: JCO.classInitialize(): Could not load middleware layer 'com.sap.mw.jco.rfc.MiddlewareRFC'
JCO.nativeInit(): Could not initialize dynamic link library sapjcorfc [C:\j2sdk1.4.2_06\jre\lib\ext\sapjcorfc.dll: Can't find dependent libraries]. java.library.path [C:\j2sdk1.4.2_06\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\j2sdk1.4.2_06\bin;C:\sapjco;C:\oracle\ora92\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem]
at com.sap.mw.jco.JCO.<clinit>(JCO.java:735)
at TutorialConnect1.<init>(TutorialConnect1.java:28)
at TutorialConnect1.main(TutorialConnect1.java:40)
Exception in thread "main"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
PS:Sorry I posted this in the wrong category.Now here it is:
Hello,
I am still having problems connecting to sap. Could any one tell me where to down load these dlls? MSVCR71.DLL and MSVCP71.DLL ?
More over I'm using WIN XP as my OS and the librfc32.dll is onle 4.82 MB
and the initial librfc32.dll(the one that was initially there) is 7.42MB(does this means that this is a newer version?)
When ever I replace the initial dll(librfc32.dll in XP which is 7.42MB) with the jco dll (librfc32.dll with 4.82MB)which comes with jco, the SAP GUI installed in my PC doesn't start any more. It does start only if I replace the jco dll file with the XP dll (librfc32.dll with 7.42 MB)
Is there any where with a jco installation for WIN XP?
After reading the pdf file which comes with jco I need a dll file "jRFC12.dll". I'm using java 2. Could any one tel me where to download this file also?
Thank you all.
Could any body please help me out? I'm a newbie ready to learn sir!
Hello folks,
After having successfully connected to SAP using a Java application after some problems here and there, I decided to commit my self for a well detailed Tutorial that will help others.
<b>BELOW IS A WELL OUTLINED TUTORIAL ON HOW TO INSTALL SAPJCO version 2.1.5 ON WINDOWS 2000 and WINDOWS XP AND CONNECT TO SAP USING A JAVA APPLICATION.</b>
SAP-JCO Middleware Installation and Configuration Guide on WINDOWS 2000 & WINDOWS XP
1) Download SAPJCO from http://service.sap.com/connectors
Make sure you got a login account (username + password)
2) Create a directory e.g. C:\jco and unzip the JCO zip
file into this directory. Copy the librfc32.dll found
in C:\JCO to C:\WINNT\SYSTEM32
3) Copy sapjco.jar and sapjcorfc.dll to the class path of
your Run Time Environment that want to use Java. I my
case I copied it to. C:\j2sdk1.4.2_06\jre\lib\ext.
4) Find and download these two dlls described in
SAP Note Nr. 684106, found in SAP Service
Marketplace.Without them you won't be able to connect.
5) Copy MSCVR71.dll and MSCVP71.dll to C:\WINN\system32
(These dlls doesnt come with SAPJCO. You have to
download them from SAP Marketplace and install them
extra. To install the missing DLLs(MSCVR71.dll and
MSCVP71.dll), download and unpack the archive attached
to "Note 684106" with sapcar and
execute "R3DLLINS.EXE".(SAPCAR is a compress utility
similar to winzip, tar, etc., that is used by SAP to
compress and decompress nearly all delivered files.)
OR you can download sapcar at
http://service.sap.com/patches
<b>6) Setting the Environment Variables.</b>
Right Click on my Computer on the Desktop and click
on Properties.
Select the Advance Tab and then Environment
Variables. Look for Path in the System Variables.If
you're not sure where to add the path, add it to the
right end of the Path in the System Variables.A
typical value for PATH is: C:\Jco\sapjco.jar;
After setting and configuring SAPJCO Middleware, you can now use your java application and connect to SAP. Make sure your user has got enough privileges to connect to SAP. I hope this will help. Please Post your feedbacks HERE.THANK!
Hi together,
as you described in your small guide we have installed SAP Jco, installed the DLL's with R3DLLINS.EXE, add the path in the System Variables.
But still we got the following error if we call the BAPI "BAPI_DOCUMENT_CHECKOUTVIEW2":
java.lang.NullPointerException
at com.untersee.test.TestDokument.main(TestDokument.java:27)
I::001 Win32 error 2: Das System kann die angegebene Date
Exception in thread "main"
Here is our source-code (it's only a test):
import com.sap.mw.jco.*;
public class ReadDocument {
public final String[][] getDocuments( String prmUsr, String prmPwd,
String prmSapSystem, String prmMandant,
String prmDocumenttyp, String prmDocumentnumber, String prmDocumentpart,
String prmDocumentversion, String prmOriginalpath)
{
JCO.Client mConnection;
IRepository mRepository;
String[][] ssRet = null;
int i;
// Check parameters:
if( null == prmUsr || 0 >= prmUsr.length() ||
null == prmPwd || 0 >= prmPwd.length() ||
null == prmSapSystem || 0 >= prmSapSystem.length() )
return null;
if( null == prmMandant || 0 >= prmMandant.length() )
prmMandant = "100";
if( null == prmDocumenttyp || 0 >= prmDocumenttyp.length() )
prmDocumenttyp = "0";
if( 0 <= (i = prmSapSystem.indexOf( '(' )) )
{
prmSapSystem = prmSapSystem.substring( i+1 );
if( 0 <= (i = prmSapSystem.indexOf( ')' )) )
prmSapSystem = prmSapSystem.substring( 0, i );
}
prmSapSystem = prmSapSystem.trim();
if( 0 >= prmSapSystem.length() )
return null;
JCO.setMiddlewareProperty("jco.middleware.allow_start_of_programs",
"ftp;sapftp;sapftpa;sapkprotp;http;saphttp;saphttpa");
// Connect to SAP:
try {
mConnection =
JCO.createClient( prmMandant, // SAP client = Mandant
prmUsr, // userid = Benutzer
prmPwd, // password = Kennwort
"DE", // language = Sprache
prmSapSystem, // host name = Group/Server
"00" ); // system number
mConnection.connect();
mRepository = new JCO.Repository( "MyRepository", mConnection );
// -
-
BAPI_DOCUMENT_CHECKOUTVIEW2 -
-
JCO.Function function = this.createFunction( mRepository, "BAPI_DOCUMENT_CHECKOUTVIEW2" );
if (function == null) { // (createFunction(): see below)
System.out.println( "BAPI_DOCUMENT_CHECKOUTVIEW2" + " not found in SAP." );
return null;
}
// -
-
listRecordContents BAPI_DOCUMENT_CHECKOUTVIEW2 -
-
function.getImportParameterList().setValue( prmDocumenttyp, "DOCUMENTTYPE" );
function.getImportParameterList().setValue( prmDocumentnumber, "DOCUMENTNUMBER" );
function.getImportParameterList().setValue( prmDocumentpart, "DOCUMENTVERSION" );
function.getImportParameterList().setValue( prmDocumentversion, "DOCUMENTVERSION" );
function.getImportParameterList().setValue( prmOriginalpath, "ORIGINALPATH" );
mConnection.execute( function );
try
{
JCO.Structure returnStructure = function.getExportParameterList().getStructure( "RETURN" );
if( !(returnStructure.getString("TYPE").equals("") ||
returnStructure.getString("TYPE").equals("S")) )
{
System.out.println( returnStructure.getString( "MESSAGE" ) );
return null;
}
}
catch( Exception ex )
{
ex.printStackTrace();
return null;
}
// -
-
DOCUMENTFILES -
-
JCO.Table tblDoc = function.getTableParameterList().getTable( "DOCUMENTFILES" );
if( null == tblDoc )
{
System.out.println( "Error: no DOCUMENTFILES !" );
return null;
}
ssRet = new String[tblDoc.getNumRows()+1][7];
ssRet[0][0] = "Löschkennzeichen";
ssRet[0][1] = "Dokumentart";
ssRet[0][2] = "Dokumentnummer";
ssRet[0][3] = "Teildokument";
ssRet[0][4] = "Dokumentversion";
ssRet[0][5] = "Originalnummer";
ssRet[0][6] = "Original zu Dokument";
for( i=0; i<tblDoc.getNumRows(); i++ )
{
tblDoc.setRow( i );
ssRet[i+1][0] = tblDoc.getString( "DELETEVALUE" );
ssRet[i+1][1] = tblDoc.getString( "DOCUMENTTYPE" );
ssRet[i+1][2] = tblDoc.getString( "DOCUMENTNUMBER" );
ssRet[i+1][3] = tblDoc.getString( "DOCUMENTPART" );
ssRet[i+1][4] = tblDoc.getString( "DOCUMENTVERSION" );
ssRet[i+1][5] = tblDoc.getString( "ORIGINALTYPE" );
ssRet[i+1][6] = tblDoc.getString( "DOCFILE" );
}
}
catch( Exception ex ) {
ex.printStackTrace();
return null;
}
return ssRet;
}
private JCO.Function createFunction( IRepository mRepository, String name )
{
try {
return mRepository.getFunctionTemplate( name.toUpperCase() ).getFunction();
} catch( Exception ex ) {}
return null;
}
}
Have anyone an idea what the problem is?
regards Thomas
Hi Lionel,
when you say proxies ,you should have two proxies,one on the sender side application called as client proxy and receiver side with server proxy.
As per your question.
JavaApplication(client proxy)----
>SAP RFC(server proxy)where your client proxy will provide the necessary input data to the RFC.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.