Consulting

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, _
    RETURN:=oReturn

    If oApplHelp.RowCount > 0 Then
    Call ShowData
    'MsgBox "Data found"
    Else
    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
    oApplHelp.Refresh

    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


    Thanks
    Priya

  2. #2
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    perhaps if you

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

    Stan

  3. #3

    SAP and VBA

    Hi
    Stanl

    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

    Thanks
    priya

  4. #4
    VBAX Regular
    Joined
    Aug 2007
    Location
    Hungary Budapest
    Posts
    53
    Location
    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.
    L@ja

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

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    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
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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