Skip to Content
0

How can I log on SAP 730 and download fbl3n data in excel vba

Nov 17, 2016 at 08:31 AM

143

avatar image

Hi experts!

I currently trying to create a macro that should log on on SAP 730 and connect to fbl3n t-cod and download data in excel... I m searching for 3 days but nothing can be found on internet related this topic.

Could you please be help me? I really appreciate if anyone already use this kind of macro to give me some idea .

Below I wrote my code, but it seems to be blocked , dosen t works!

Sub sap()
    Dim oBook As Workbook
    Dim oSheet As Worksheet
    Dim oBapiCtrl As Object
    Dim oBapiLogon As Object
    Dim oDocumentNo As Object
    Dim oPK As Object
    Dim oReferenceKey1 As Object
    Dim oCoCod As Object
    Dim iIndex As Integer
     
     
    Set oBook = Application.ActiveWorkbook
    Set oSheet = oBook.Worksheets(1)
     
    Set oBapiCtrl = CreateObject("sap.bapi.1")
    Set oBapiLogon = CreateObject("sap.logoncontrol.1")
 
    oBapiCtrl.Connection = oBapiLogon.NewConnection
    oBapiCtrl.Connection.ApplicationServer = "000.000.000"
    oBapiCtrl.Connection.System = "test"
    oBapiCtrl.Connection.client = "000"
    oBapiCtrl.Connection.User = ""
    oBapiCtrl.Connection.Password = ""
    oBapiCtrl.Connection.Language = ""
    oBapiCtrl.Connection.SystemNumber = ""
     
   If oBapiCtrl.Connection.logon(0, True) <> True Then
    MsgBox "not connected", vbInformation, "SAP Logon"
    Exit Sub
    Else
    MsgBox "Connected!"
   End If
     
   If oBapiCtrl.Connection.IsConnected Then
   
  Set SapGuiAuto = GetObject("SAPGUI")  'Get the SAP GUI Scripting object
  Set SAPApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
  Set SAPCon = SAPApp.Children(0) 'Get the first system that is currently connected
  Set session = SAPCon.Children(0) 'Get the first session (window) on that connection

'there should be the code for smooth login SAP and open FBL3N and extract data

End Sub


10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Aecorsoft Inc Feb 08, 2017 at 09:41 PM
0

You better read from the underlying SAP table and RFC result programmatically, instead of reading from t-code result. Even you manage to make it work, the program's result may not be as structured (to parse easily) as you expect.

Share
10 |10000 characters needed characters left characters exceeded