{"id":446,"date":"2011-07-19T11:40:41","date_gmt":"2011-07-19T09:40:41","guid":{"rendered":"http:\/\/www.capri-soft.de\/blog\/?p=446"},"modified":"2011-07-19T11:55:35","modified_gmt":"2011-07-19T09:55:35","slug":"vba-und-sap-funktionsbausteine-aufrufen","status":"publish","type":"post","link":"https:\/\/www.capri-soft.de\/blog\/?p=446","title":{"rendered":"VBA und SAP: Funktionsbausteine aufrufen"},"content":{"rendered":"<h1>Aufgabenstellung<\/h1>\n<p>Die Aufgabenstellung sowie der Ansatz ist identisch mit <a href=\"https:\/\/www.capri-soft.de\/blog\/?p=323\">diesem Artikel (Bitte zuerst lesen)<\/a>. <\/p>\n<h1>Pr\u00e4missen \/ Vorraussetzungen<\/h1>\n<p>Die Datei librfc32.dll muss im VBA Editor eingebunden werden (sie ist nach der Installation der SAPGUI verf\u00fcgbar). <\/p>\n<h1>L\u00f6sung<\/h1>\n<h3>Aufbau der Verbindung<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nPublic Function SAP_Logon(username As String, password As String) As Boolean\r\n&#039;*************************************************\r\n&#039;  ANMELDUNG AN SAP\r\n&#039;  ACHTUNG: USER MUSS BERECHTIGUNGEN HABEN!!!!\r\n&#039;*************************************************\r\n\r\n    Set FunctionCtrl = CreateObject(&quot;SAP.Functions&quot;)\r\n    &#039;Objekt f\u00fcr die SAP Verbindung\r\n\r\n    Set SapConnection = FunctionCtrl.Connection\r\n   \r\n    SapConnection.Client = &quot;100&quot;\r\n    SapConnection.User = username\r\n    SapConnection.Language = &quot;DE&quot;\r\n    SapConnection.password = password\r\n    \r\n     SapConnection.hostname = &quot;rechnername.firma.com&quot; &#039;nicht das kuerzel wie DE9\r\n    \r\n    SapConnection.systemnumber = &quot;0&quot;\r\n\r\n    If Not SapConnection.Logon(0, True) Then &#039;True silent - false offen\r\n        MsgBox &quot;Logon failed!!!&quot;, vbCritical\r\n        CMS_Logon = False\r\n    Else\r\n        CMS_Logon = True\r\n    End If\r\nEnd Function\r\n<\/pre>\n<h3>Abmelden<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nPublic Function SAP_Logoff() As Boolean\r\n    SapConnection.LogOff\r\nEnd Function\r\n<\/pre>\n<h3>Funktionbaustein bef\u00fcllen und aufrufen<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nPublic Function SAP_Create_Request() As Long\r\n&#039;******************************************************\r\n&#039;  Request erzeugen\r\n&#039;  Strukturen f\u00fcllen und \u00fcbergeben, dann Log ausgeben\r\n&#039;******************************************************\r\n\r\nOn Error GoTo ErrorMSG\r\n\r\n    Dim FunctionModule As Object\r\n    Dim e_EXPORTSTRUKTUR As Object\r\n    Dim T_TABELLENSTRUKTUR As Object\r\n    \r\n    Dim te_messtab As Object\r\n    \r\n    Dim lCnt As Long\r\n\r\n&#039;   Assign Function Module\r\n    Set FunctionModule = FunctionCtrl.Add(&quot;Z_FUBA&quot;)\r\n    \r\n&#039;   Set export Variables\r\n    Set e_EXPORTSTRUKTUR = FunctionModule.Exports(&quot;P_STRUKTURPARAMETER&quot;)\r\n\r\n&#039; Set structrue fields in export parameter\r\n    e_EXPORTSTRUKTUR (&quot;ZEXPORTPARAM1&quot;) = &quot;BLA&quot;\r\n    e_EXPORTSTRUKTUR (&quot;ZEXPORTPARAM1&quot;) = &quot;BLA2&quot;\r\n\r\n    Set T_TABELLENSTRUKTUR  = FunctionModule.Tables(&quot;T_ZMMMATANF8&quot;)\r\n    T_TABELLENSTRUKTUR.appendRow\r\n    T_TABELLENSTRUKTUR(1, &quot;SPALTE1&quot;) = 1\r\n    T_TABELLENSTRUKTUR(1, &quot;SPALTE2&quot;) = 2\r\n\r\n    T_TABELLENSTRUKTUR.appendRow\r\n    T_TABELLENSTRUKTUR(2, &quot;SPALTE1&quot;) = 3\r\n    T_TABELLENSTRUKTUR(2, &quot;SPALTE2&quot;) = 4\r\n\r\n&#039;   Call Function Aufruf\r\n    If FunctionModule.Call = True Then\r\n        Set te_messtab = FunctionModule.Tables(&quot;TE_MESSTAB&quot;)\r\n        &#039; Meldungen ausgeben:\r\n        \r\n        Dim intRow As Integer\r\n        For intRow = 1 To te_messtab.RowCount\r\n            If te_messtab(intRow, &quot;ARBGB&quot;) = &quot;ZMM0001&quot; And _\r\n                te_messtab(intRow, &quot;MSGNR&quot;) = &quot;003&quot; Then\r\n\r\n                &#039; ANForderung wurde erstellt.\r\n                CMS_Create_Request = Val(te_messtab(intRow, &quot;MSGV1&quot;))\r\n            End If\r\n            Debug.Print te_messtab(intRow, &quot;ARBGB&quot;)\r\n            Debug.Print te_messtab(intRow, &quot;MSGNR&quot;)\r\n            Debug.Print te_messtab(intRow, &quot;NATXT_DE&quot;)\r\n            sMSGTXT = te_messtab(intRow, &quot;NATXT_DE&quot;)\r\n            Debug.Print te_messtab(intRow, &quot;FLDNAME&quot;)\r\n            Debug.Print te_messtab(intRow, &quot;MSGV1&quot;)\r\n            Debug.Print te_messtab(intRow, &quot;MSGV2&quot;)\r\n            Debug.Print te_messtab(intRow, &quot;MSGV3&quot;)\r\n            Debug.Print te_messtab(intRow, &quot;MSGV4&quot;)\r\n            Debug.Print &quot;----------------------------------&quot;\r\n        Next\r\n    Else\r\n        CMS_Create_Request = 0\r\n         MsgBox &quot;Error creating the CMS Request.&quot; &amp; vbNewLine &amp; _\r\n                &quot;See Log for details&quot;, vbCritical\r\n    End If\r\nErrorMSG:\r\n  \r\nEnd Function\r\n<\/pre>\n<h3>Die Testfunktion<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nPublic Sub Start()\r\n&#039;*************************************************\r\n&#039;  TESTUMGEBUNG\r\n&#039;*************************************************\r\n    Dim RequestNo As Long\r\n    Dim username As String\r\n    Dim password As String\r\n    \r\n    username = &quot;BJOERN&quot;\r\n    password = &quot;ICHBINDERBESTE&quot;\r\n        \r\n    Call CMS_Logon(username, password)\r\n    RequestNo = SAP_Create_Request   \r\n    Call CMS_Logoff\r\nEnd Sub\r\n<\/pre>\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Fwww.capri-soft.de%2Fblog%2F%3Fp%3D446&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px;margin-top:5px;\"><\/iframe>","protected":false},"excerpt":{"rendered":"<p>Aufgabenstellung Die Aufgabenstellung sowie der Ansatz ist identisch mit diesem Artikel (Bitte zuerst lesen). Pr\u00e4missen \/ Vorraussetzungen Die Datei librfc32.dll muss im VBA Editor eingebunden werden (sie ist nach der Installation der SAPGUI verf\u00fcgbar). L\u00f6sung Aufbau der Verbindung Public Function SAP_Logon(username As String, password As String) As Boolean &#039;************************************************* &#039; ANMELDUNG AN SAP &#039; ACHTUNG: &hellip; <a href=\"https:\/\/www.capri-soft.de\/blog\/?p=446\" class=\"more-link\"><span class=\"screen-reader-text\">VBA und SAP: Funktionsbausteine aufrufen<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[9,12],"tags":[],"class_list":["post-446","post","type-post","status-publish","format-standard","hentry","category-sap","category-vba"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4yGeN-7c","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/446","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=446"}],"version-history":[{"count":8,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/446\/revisions"}],"predecessor-version":[{"id":448,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/446\/revisions\/448"}],"wp:attachment":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=446"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}