SAP soll JavaMethode aufrufen

Rund um Java und SAP®.

Postby Jolin2218 » Wed Jul 14, 2004 1:56 pm

Hi Steffi,

offensichtlich läuft im Server etwas falsch, da die Methode 'serverExceptionOccurred' aufgerufen wird, die dann eine Exception wirft. Was sagt den der stackTrace? Den kannst Du in der Methode ja ausgeben oder ggf. in ein File schreiben (z.B.: FileWriter). Wenn Du den hier postest, kommt man evtl. der Sache auf die Schliche.

Gruss,

Jens
Jolin2218
...
...
 
Posts: 105
Joined: Mon Dec 02, 2002 2:28 pm

Postby William4545 » Wed Jul 14, 2004 2:07 pm

hi,
ich bin dem Fehler ein stück näher gekommen.

in meiner "function" ist null drin!
Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. protected JCO.Function getFunction(String function_name)
  2.     {
  3.       JCO.Function function = super.getFunction(function_name);
  4.       System.out.println("getFunction: " + function );
  5.       return function;
  6.     }
  7.  
GeSHi ©


function_name hat den Wert: FUNCTION_SM

Die Umsetzung klappt also nicht!
steffi
William4545
..
..
 
Posts: 55
Joined: Tue Jul 13, 2004 11:40 am

Postby Alva1590 » Wed Jul 14, 2004 2:32 pm

Hi Steffi,

die Methode:

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. protected JCO.Function getFunction(String function_name)
  2.     {
  3.       JCO.Function function = super.getFunction(function_name);
  4.       System.out.println("getFunction: " + function );
  5.       return function;
  6.     }
  7.  
GeSHi ©

musst Du nicht überschreiben, das ist nicht notwendig.

Was Du allerdings machen musst, ist ein Repository zu erzeugen und dort die Funktion entsprechend zu definieren (siehe auch Beispiel 5 aus dem Tutorial).
Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1.     repository = new Repository("TestRepository");
  2.  
  3.     // non-unicode definition of functions. The server with this repository can
  4.     // dispatch calls only from non-unicode systems
  5.  
  6.     //------------------------------------------------------------------------------
  7.     //  Add function 'STFC_CONNECTION'
  8.     //------------------------------------------------------------------------------
  9.     JCO.MetaData fmeta = new JCO.MetaData("STFC_CONNECTION");
  10.     fmeta.addInfo("REQUTEXT", JCO.TYPE_CHAR, 255,   0,  0, JCO.IMPORT_PARAMETER, null);
  11.     fmeta.addInfo("ECHOTEXT", JCO.TYPE_CHAR, 255,   0,  0, JCO.EXPORT_PARAMETER, null);
  12.     fmeta.addInfo("RESPTEXT", JCO.TYPE_CHAR, 255,   0,  0, JCO.EXPORT_PARAMETER, null);
  13.     repository.addFunctionInterfaceToCache(fmeta);
  14.  
  15.  
GeSHi ©


Ich vermute mal, dass in der Definition des Repository etwas nicht stimmt, da bei Dir function 'null' ist.

Gruss,

Jens
Alva1590
.....
.....
 
Posts: 4387
Joined: Mon Dec 02, 2002 3:01 pm

*FREU*

Postby William4545 » Wed Jul 14, 2004 2:46 pm

Ja!!! Das war es!!!
Endlich funkitoniert alles so, wie es soll :lol: :lol:
Danke an alle
William4545
..
..
 
Posts: 55
Joined: Tue Jul 13, 2004 11:40 am

Postby Jolin2218 » Wed Jul 14, 2004 2:48 pm

Hi Steffi,

na also, geht doch ;-)
Kannst Du mal Dein Coding hier posten?
Danke.

Gruss,

Jens
Jolin2218
...
...
 
Posts: 105
Joined: Mon Dec 02, 2002 2:28 pm

Postby William4545 » Wed Jul 14, 2004 2:51 pm

Alles ... also von SAP und JAVA??
William4545
..
..
 
Posts: 55
Joined: Tue Jul 13, 2004 11:40 am

Postby Jolin2218 » Wed Jul 14, 2004 2:53 pm

Hi,

wenn es Dich nicht zuviel Zeit kostet, wäre das klasse. Dann wäre hier ein schönes Beispiel für andere, die sich an dieser Ecke evtl. noch abmühen ;-)

Gruss und Danke,

Jens
Jolin2218
...
...
 
Posts: 105
Joined: Mon Dec 02, 2002 2:28 pm

Postby William4545 » Wed Jul 14, 2004 3:05 pm

Mögliche Lösung:
ich lasse mir einfach eine Textdatei erstellen.

Anlegen einer TCP/IP-Verbindung auf den Namen JAVARFC
Es muss kein Funktionsbaustein 'FUNCTION_SM' existieren
Aufruf in SAP:
Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. REPORT  zsm_0001 MESSAGE-ID at.
  2. DATA: mess(128).
  3.  
  4. CALL FUNCTION 'FUNCTION_SM' DESTINATION 'JAVARFC'
  5.   EXCEPTIONS
  6.     communication_failure = 1  MESSAGE mess
  7.     system_failure        = 2  MESSAGE mess
  8.     OTHERS                = 3.
  9.  
  10. IF sy-subrc <> 0.
  11.   WRITE: 'Fehler: ', mess.
  12.   WRITE: 'Alles OK'.
  13.  
GeSHi ©


JAVA
angeleht an das Beispiel Nr. 5
Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. import java.io.FileOutputStream;
  2. import java.util.GregorianCalendar;
  3.  
  4. import com.sap.mw.jco.*;
  5.  
  6. //***********************************************************
  7. public class TestServer implements JCO.ServerExceptionListener, JCO.ServerStateChangedListener
  8. &#123;
  9. //***********************************************************
  10.  
  11.   public static GregorianCalendar cal = new GregorianCalendar&#40;&#41;;
  12.    
  13.   static public class Repository extends JCO.BasicRepository implements IRepository &#123;
  14.     public Repository&#40;String name&#41;
  15.     &#123;
  16.       super&#40;name&#41;;
  17.     &#125;
  18.   &#125;
  19.  
  20.   protected static IRepository repository;
  21.  
  22.   static &#123;
  23.  
  24.     repository = new Repository&#40;"TestRepository"&#41;;
  25.    
  26.     JCO.MetaData fmeta1 = new JCO.MetaData&#40;"FUNCTION_SM"&#41;;
  27.     fmeta1.addInfo&#40;"REQUTEXT", JCO.TYPE_CHAR, 255,   0,  0, JCO.IMPORT_PARAMETER, null&#41;;
  28.     fmeta1.addInfo&#40;"ECHOTEXT", JCO.TYPE_CHAR, 255,   0,  0, JCO.EXPORT_PARAMETER, null&#41;;
  29.     fmeta1.addInfo&#40;"RESPTEXT", JCO.TYPE_CHAR, 255,   0,  0, JCO.EXPORT_PARAMETER, null&#41;;
  30.     repository.addFunctionInterfaceToCache&#40;fmeta1&#41;;
  31.  
  32.     JCO.MetaData fmeta = new JCO.MetaData&#40;"STFC_CONNECTION"&#41;;
  33.     fmeta.addInfo&#40;"REQUTEXT", JCO.TYPE_CHAR, 255,   0,  0, JCO.IMPORT_PARAMETER, null&#41;;
  34.     fmeta.addInfo&#40;"ECHOTEXT", JCO.TYPE_CHAR, 255,   0,  0, JCO.EXPORT_PARAMETER, null&#41;;
  35.     fmeta.addInfo&#40;"RESPTEXT", JCO.TYPE_CHAR, 255,   0,  0, JCO.EXPORT_PARAMETER, null&#41;;
  36.     repository.addFunctionInterfaceToCache&#40;fmeta&#41;;
  37.  
  38.     fmeta = new JCO.MetaData&#40;"STFC_STRUCTURE"&#41;;
  39.     fmeta.addInfo&#40;"IMPORTSTRUCT", JCO.TYPE_STRUCTURE, 144, 0, 0, JCO.IMPORT_PARAMETER, "RFCTEST"&#41;;
  40.     fmeta.addInfo&#40;"ECHOSTRUCT",   JCO.TYPE_STRUCTURE, 144, 0, 0, JCO.EXPORT_PARAMETER, "RFCTEST"&#41;;
  41.     fmeta.addInfo&#40;"RESPTEXT",     JCO.TYPE_CHAR,      255, 0, 0, JCO.EXPORT_PARAMETER,  null    &#41;;
  42.     fmeta.addInfo&#40;"RFCTABLE",     JCO.TYPE_TABLE,     144, 0, 0, 0,                    "RFCTEST"&#41;;
  43.     repository.addFunctionInterfaceToCache&#40;fmeta&#41;;
  44.  
  45.     JCO.MetaData smeta  = new JCO.MetaData&#40;"RFCTEST"&#41;;
  46.     smeta.addInfo&#40;"RFCFLOAT",  JCO.TYPE_FLOAT,  8,  0, 0&#41;;
  47.     smeta.addInfo&#40;"RFCCHAR1",  JCO.TYPE_CHAR,   1,  8, 0&#41;;
  48.     smeta.addInfo&#40;"RFCINT2",   JCO.TYPE_INT2,   2, 10, 0&#41;;
  49.     smeta.addInfo&#40;"RFCINT1",   JCO.TYPE_INT1,   1, 12, 0&#41;;
  50.     smeta.addInfo&#40;"RFCICHAR4", JCO.TYPE_CHAR,   4, 13, 0&#41;;
  51.     smeta.addInfo&#40;"RFCINT4",   JCO.TYPE_INT,    4, 20, 0&#41;;
  52.     smeta.addInfo&#40;"RFCHEX3",   JCO.TYPE_BYTE,   3, 24, 0&#41;;
  53.     smeta.addInfo&#40;"RFCCHAR2",  JCO.TYPE_CHAR,   2, 27, 0&#41;;
  54.     smeta.addInfo&#40;"RFCTIME",   JCO.TYPE_TIME,   6, 29, 0&#41;;
  55.     smeta.addInfo&#40;"RFRDATE",   JCO.TYPE_DATE,   8, 35, 0&#41;;
  56.     smeta.addInfo&#40;"RFCDATA1",  JCO.TYPE_CHAR,   50,43, 0&#41;;
  57.     smeta.addInfo&#40;"RFCDATA2",  JCO.TYPE_CHAR,   50,93, 0&#41;;
  58.     repository.addStructureDefinitionToCache&#40;smeta&#41;;
  59.   &#125;
  60.  
  61.   static public class Server extends JCO.Server &#123;
  62.  
  63.     /**
  64.      *  Create an instance of my own server
  65.      *  @param gwhost the gateway host
  66.      *  @param gwserv the gateway service number
  67.      *  @param progid the program id
  68.      *  @param repository the repository used by the server to lookup the definitions of an inc
  69.      */
  70.     public Server&#40;String gwhost, String gwserv, String progid, IRepository repository&#41;
  71.     &#123;
  72.       super&#40;gwhost,gwserv,progid,repository&#41;;
  73.     &#125;
  74.  
  75.     /**********************************************************
  76.      *  handleRequest      
  77. ***********************************************************/
  78.     protected void handleRequest&#40;JCO.Function function&#41; throws Exception
  79.     &#123;
  80.       JCO.ParameterList input  = function.getImportParameterList&#40;&#41;;
  81.       JCO.ParameterList output = function.getExportParameterList&#40;&#41;;
  82.       JCO.ParameterList tables = function.getTableParameterList&#40;&#41;;
  83.  
  84.       System.out.println&#40;"getImportParameterList:" + input&#41;;
  85.  
  86.      
  87.       if &#40;function.getName&#40;&#41;.equals&#40;"FUNCTION_SM"&#41;&#41; &#123;
  88.          writeFile&#40;"Hallo Test" + cal.getTime&#40;&#41;&#41;;
  89.       &#125;
  90.      
  91.       else if &#40;function.getName&#40;&#41;.equals&#40;"STFC_CONNECTION"&#41;&#41; &#123;
  92.         output.setValue&#40;input.getString&#40;"REQUTEXT"&#41;,"ECHOTEXT"&#41;;
  93.         output.setValue&#40;"This is a response from TestServer.java","RESPTEXT"&#41;;
  94.       &#125;
  95.       else if &#40;function.getName&#40;&#41;.equals&#40;"STFC_STRUCTURE"&#41;&#41; &#123;
  96.         JCO.Structure sin  = input.getStructure&#40;"IMPORTSTRUCT"&#41;;
  97.         JCO.Structure sout = &#40;JCO.Structure&#41;sin.clone&#40;&#41;;
  98.         try &#123;
  99.           System.out.println&#40;sin&#41;;
  100.         &#125;
  101.         catch &#40;Exception ex&#41; &#123;
  102.           System.out.println&#40;ex&#41;;
  103.         &#125;
  104.         output.setValue&#40;sout,"ECHOSTRUCT"&#41;;
  105.         output.setValue&#40;"This is a response from TestServer.java","RESPTEXT"&#41;;
  106.       &#125;//if
  107.      
  108.     &#125;
  109.   &#125;
  110.  
  111.   /** List of servers */
  112.   JCO.Server srv[] = new JCO.Server[1];
  113.  
  114.   /**
  115.    *  Constructor
  116.    */
  117.   public TestServer&#40;&#41;
  118.   &#123;
  119.     // Yes, we're interested in server exceptions
  120.    JCO.addServerExceptionListener&#40;this&#41;;
  121.  
  122.    // And we also want to know when the server&#40;s&#41; change their states
  123.    JCO.addServerStateChangedListener&#40;this&#41;;
  124.  &#125;
  125.  
  126.  /**
  127.   *  Start the server
  128.   */
  129.  public void startServers&#40;&#41;
  130.  &#123;
  131.   // hier bitte die entsprechenden Daten eintragen!!!  
  132.   srv[0] = new Server&#40;"IP Server", "System",
  133. "JAVARFC",repository&#41;;
  134.  
  135.     for &#40;int i = 0; i < srv.length; i++&#41; &#123;
  136.      try &#123;
  137.        srv[i].setTrace&#40;true&#41;;
  138.        srv[i].start&#40;&#41;;
  139.      &#125;
  140.      catch &#40;Exception ex&#41; &#123;
  141.        System.out.println&#40;"Could not start server " + srv[i].getProgID&#40;&#41; + ":\n" + ex&#41;;
  142.      &#125;//try
  143.    &#125;//for
  144.  &#125;
  145.  
  146.  /**
  147.   *  Simply prints the text of the exception and a stack trace
  148.   */
  149.  public void serverExceptionOccurred&#40;JCO.Server server, Exception ex&#41;
  150.  &#123;
  151.    System.out.println&#40;"Exception in server " + server.getProgID&#40;&#41; + ":\n" + ex&#41;;
  152.    ex.printStackTrace&#40;&#41;;
  153.  &#125;
  154.  
  155.  /**
  156.   *  Simply prints server state changes
  157.   */
  158.  public void serverStateChangeOccurred&#40;JCO.Server server, int old_state, int new_state&#41;
  159.  &#123;
  160.  &#125;
  161.  
  162.  public static void writeFile&#40;String s&#41;
  163.  &#123;
  164.   byte buffer[] = new byte[80];
  165.   try
  166.   &#123;      
  167.      FileOutputStream fos = new FileOutputStream&#40; "c:/_SM/text.txt" &#41;;
  168.       fos.write&#40; s.getBytes&#40;&#41; &#41;;
  169.       fos.close&#40;&#41;;
  170.    &#125;
  171.    catch &#40; Exception e &#41; &#123; System.out.println&#40;e&#41;; &#125;
  172.   &#125;
  173.  
  174.  public static void main&#40;String[] argv&#41;
  175.  &#123;
  176.     TestServer obj = new TestServer&#40;&#41;;
  177.    obj.startServers&#40;&#41;;
  178.  &#125;
  179. &#125;
  180.  
GeSHi ©



So, ich denke mal, dass dieser Beitrag den Suchenden hilft :lol:

Liebe Grüße
Steffi[/b]
William4545
..
..
 
Posts: 55
Joined: Tue Jul 13, 2004 11:40 am

Postby Emre397 » Wed Jul 14, 2004 3:30 pm

Klasse danke!
Emre397
...
...
 
Posts: 141
Joined: Mon Dec 09, 2002 1:53 pm

Postby Jolin2218 » Wed Jul 14, 2004 3:39 pm

Danke :D
Jolin2218
...
...
 
Posts: 105
Joined: Mon Dec 02, 2002 2:28 pm

Previous

Return to Java & SAP®

Who is online

Users browsing this forum: No registered users and 5 guests