{"id":234,"date":"2007-01-26T23:07:00","date_gmt":"2007-01-26T15:07:00","guid":{"rendered":"http:\/\/j178.mtgbb.com\/102"},"modified":"2007-01-26T23:07:00","modified_gmt":"2007-01-26T15:07:00","slug":"calling-bapis-from-vb6","status":"publish","type":"post","link":"https:\/\/j178.mtgbb.com\/?p=234","title":{"rendered":"Calling BAPIs from VB6"},"content":{"rendered":"<p>\u8cc7\u6599\u4f86\u6e90: <a href=\"http:\/\/help.sap.com\/saphelp_46c\/helpdata\/en\/76\/4a42f7f16d11d1ad15080009b0fb56\/content.htm\" target=\"_blank\">SAP\u5b98\u65b9\u7db2\u7ad9<\/a><br \/>\n&nbsp;<br \/>\nThis example illustrates a BAPI call in Visual Basic using the BAPI ActiveX Control. This report uses the service BAPI BapiService.MessageGetDetail(), to display the short text and the long text of error messages.<\/p>\n<p><!--more--><\/p>\n<pre lang=\"VB\" line=\"1\">\n' Visual BASIC 5.0\n' Copyright SAP AG Walldorf Juli 1998\n'\n\n' read a message short and longtext using the BAPI\n' BAPI_MESSAGE_GETDETAIL of the object BapiService\n\n' constant for user identification\n\nConst cstrMUsrClient As String = \"000\"\nConst cstrMUsrUser As String = \"MYUSER\"\nConst cstrMUsrPassword As String = \"MYPASS\"\nConst cstrMUsrLanguage As String = \"EN\"\n' constant for system identification\n\nConst cstrMSysSystem As String = \"P45\"\nConst cstrMSysMessageServer As String = \"p45main.wdf.sap-ag.de\"\nConst cstrMSysGroupName As String = \"PUBLIC\"\n\n'\n' constant values for reading message texts\n\nConst cstrMMsgId As String = \"SX\"\nConst cstrMMsgNumber As String = \"101\"\nConst cstrMMsgVariable1 As String = \"var1\"\nConst cstrMMsgVariable2 As String = \"var2\"\nConst cstrMMsgVariable3 As String = \"var3\"\nConst cstrMMsgVariable4 As String = \"var4\"\nConst cstrMMsgLanguage As String = \"DE\"\n\n' other constant\nConst cstrMPathfile As String = \"D:Asaptext.rtf\"\n\n' password for login in R\/3\nDim strMUsrPassword As String\n\n' react on button START\nPrivate Sub cmdMsgStart_Click()\n\n' define object for BAPI ActiveX control\nDim oBAPICtrl As Object\n\n' define object for R\/3 logon control\nDim oLogonCtrl As Object\n\n' business object BapiService\nDim boBapiSercice As Object\n\n' for BAPI: BapiService.MessageGetDetail\nDim oMsgReturn As Object\nDim oMsgText As Object\nDim intCounter As Integer\n\n' to open the file you need a file channel\nDim intChannel As Integer\n\n' create BAPI ActiveX control object\nSet oBAPICtrl = CreateObject(\"SAP.BAPI.1\")\n\n' create R\/3 logon control object\nSet oLogonCtrl = CreateObject(\"SAP.Logoncontrol.1\")\n\n' connection object is part of the BAPI ActiveX Control object\nSet oBAPICtrl.Connection = oLogonCtrl.NewConnection\n\n' fill logon parameters for system to use\noBAPICtrl.Connection.System = txtSysSystem\noBAPICtrl.Connection.MessageServer = txtSysMessageServer\noBAPICtrl.Connection.GroupName = txtSysGroupName\n\n' fill logon parameter for user\noBAPICtrl.Connection.Client = txtUsrClient\noBAPICtrl.Connection.User = txtUsrUser\noBAPICtrl.Connection.Password = strMUsrPassword\noBAPICtrl.Connection.Language = txtUsrLanguage\n\n' user logon to R\/3\nIf oBAPICtrl.Connection.Logon(frmStart.hWnd, False) = False Then\n\nMsgBox \"R\/3 connection failed\"\n\nEnd\n\nEnd If\n\n' create BAPI service object\nSet boBapiService = oBAPICtrl.GetSAPObject(\"BapiService\")\n\n' call method of BapiService\nboBapiService.MessageGetDetail id:=txtMsgId, _\nNumber:=txtMsgNumber, _\nLanguage:=txtMsgLanguage, _\nTextformat:=cboMsgTextformat.Text, _\nmessage:=strMsgShorttext, _\nReturn:=oMsgReturn, _\nText:=oMsgText\n\n' fill field in form\n' If txtMsgShorttext = \"\" Then\n' MsgBox \"No message read\"\n' End If\n\n' user logoff from R\/3\noBAPICtrl.Connection.Logoff\n\n' error handling check if RETURN parameter is not empty and react\nIf oMsgReturn.Value(\"TYPE\") &lt;&gt; \"\" Then\n\nlblReturn.Caption = oMsgReturn.Value(\"TYPE\") + _\n\". \" + _\noMsgReturn.Value(\"ID\") + _\n\". \" + _\noMsgReturn.Value(\"NUMBER\") + _\n\". \" + _\noMsgReturn.Value(\"MESSAGE\") + _\n\". \" + _\noMsgReturn.Value(\"MESSAGE_V1\") + _\n\". \" + _\noMsgReturn.Value(\"MESSAGE_V2\") + _\n\". \" + _\noMsgReturn.Value(\"MESSAGE_V3\") + _\n\". \" + _\noMsgReturn.Value(\"MESSAGE_V4\") + _\n\". \" + _\noMsgReturn.Value(\"LOG_NO\") + _\n\". \" + _\noMsgReturn.Value(\"LOG_MSG_NO\")\nElse\n\n' fill form fields\ntxtMsgShorttext = strMsgShorttext\narrayText = oMsgText.Data\n\n' handling of non RTF texts\nIf cboMsgTextformat.Text &lt;&gt; \"RTF\" Then\n\nFor intCounter = 1 To oMsgText.RowCount\nIf intCounter = 1 Then\nrtfMsgLongtext.Text = arrayText(intCounter, 1)\nElse\nrtfMsgLongtext.Text = rtfMsgLongtext.Text + _\nC hr(13) + C hr(10) + _\narrayText(intCounter, 1)\nEnd If\nNext intCounter\nEnd If\n\n' handling of RTF texts\nIf cboMsgTextformat.Text = \"RTF\" Then\n' save text as rtf file\nintChannel = FreeFile\n\nOpen cstrMPathfile For Output As #intChannel\n\nFor intCounter = 1 To oMsgText.RowCount\nPrint #intChannel, arrayText(intCounter, 1)\n\nNext intCounter\n\nClose #intChannel\n\nrtfMsgLongtext.LoadFile cstrMPathfile, rtfRTF\n\nEnd If\n\nEnd If\n\nEnd Sub\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8cc7\u6599\u4f86\u6e90: SAP\u5b98\u65b9\u7db2\u7ad9 &nbsp; This example illustrates a BAPI ca &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[58,31],"class_list":["post-234","post","type-post","status-publish","format-standard","hentry","category-php","tag-sap","tag-vb6"],"_links":{"self":[{"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/posts\/234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=234"}],"version-history":[{"count":0,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/posts\/234\/revisions"}],"wp:attachment":[{"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}