Results 1 to 6 of 6

Thread: VBA and SAP

  1. #1

    VBA and SAP

    kindly help trying to call the BAPI and it is working fine but the thing is the show data method is not working fine
    oApplHelp.Views.Add UserForm1.SAPTableView1.Object this line gives an error saying that object doesn't support this property or method
    so kindly help Badly stuck

    Public Sub callBAPI()

    Dim BAPISHELP As Object
    Dim oIAstnr As Object, oIAstna As Object 'Input parameters
    Dim oReturn As Object, oMessages As Table

    If Not CheckSAPConnection Then
    Exit Sub
    End If

    'Make an instance of SAP object

    Set BAPISHELP = objBAPIControl.GetSAPObject("ZPCCHELP")

    'Get a reference to the output parameters so they can be consulted
    'after calling the BAPI
    Set oApplHelp = objBAPIControl.DimAs(BAPISHELP, "ApplicantHelp", "APPLHELP")
    Set oMessages = objBAPIControl.DimAs(BAPISHELP, "ApplicantHelp", "MESSAGES")
    Set oReturn = objBAPIControl.DimAs(BAPISHELP, "ApplicantHelp", "RETURN")

    'Call object's method with applicant name *Care*
    BAPISHELP.ApplicantHelp _
    IAstnr:=frmApplicant.txtApplicantNo, _
    IAstna:=frmApplicant.txtApplicantName, _
    ApplHelp:=oApplHelp, _
    MESSAGES:=oMessages, _

    If oApplHelp.RowCount > 0 Then
    Call ShowData
    'MsgBox "Data found"
    On Error Resume Next
    MsgBox "Errors."
    End If

    End Sub

    -------------------------------------Show Data Method-------------------------------------------------------

    Private Sub ShowData()
    Dim Col As Object

    'Connect Table object with the Table View

    oApplHelp.Views.Add UserForm1.SAPTableView1.Object

    'Table Update

    Set Col = UserForm1.SAPTableView1
    'Loop at table columnsFor Each Col In oApplHelp.Columns
    For Each Col In oApplHelp.Columns
    UserForm1.SAPTableView1.Columns(Col.Index).Name = Col.Name
    UserForm1.SAPTableView1.Columns(Col.Index).Protection = True
    Next Col

    'Column Headings
    UserForm1.SAPTableView1.Columns("I_ASTNR").Header = "Applicant No"
    UserForm1.SAPTableView1.Columns("I_ASTNA").Header = "Applicant Name"

    'Automatically adopt column width to contents
    UserForm1.SAPTableView1.ColumnAutoWidth 1, UserForm1.SAPTableView1.ColumnCount

    End Sub


  2. #2
    VBAX Master stanl's Avatar
    Jan 2005
    perhaps if you

    [vba]Dim oApplHelp As Object[/vba] it will be more understandable in the Private Sub


  3. #3

    SAP and VBA


    Actually i tried what you sugessted but the thing is i m able to retrieve the data from SAP end i.e the the entire data is pulled in the oApplHelp object but i m finding it difficult to display the data part on to the grid or SAP table view could you just suggest me with any other way wherein i can display my data that is in the oApplHelp object
    This object contains Data,Views, and other paramateres
    but i just need to display the Data part of the oApplHelp object
    Kidnly suggest very badly stuck


  4. #4
    VBAX Regular
    Aug 2007
    Hungary Budapest
    Hello Priya,

    why you want to see the data in a form and not for example in a sheet?
    I think it's more simple like what u try now.
    'write headers
    Col = 1
    For Each c In Me.SAPTableView1.Columns
    Cells(1, Col) = c.Name
    Col = Col + 1
    Next c
    'write datas
    mrow = 2
    For Each r In Me.SAPTableView1.Rows
    For mcol = 1 To Col - 1
    Cells(mrow, mcol) = r.Value(mcol)
    Next c
    mrow = mrow + 1
    Next r
    MsgBox "done"
    Last edited by Paul_Hossler; 04-18-2018 at 07:22 PM.

  5. #5
    Thanks for the tip! Works like a charm.

  6. #6
    VBAX Sage
    Apr 2007
    United States
    Quote Originally Posted by Marius Titul View Post
    Thanks for the tip! Works like a charm.
    FYI - that's an 11 year old post

    But we like to leave them around since even the old ones can be helpful


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts