PDA

View Full Version : VBA and SAP



priya_antony
08-09-2007, 08:59 PM
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

stanl
08-10-2007, 03:04 AM
perhaps if you

Dim oApplHelp As Object it will be more understandable in the Private Sub

Stan

priya_antony
08-11-2007, 08:35 AM
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

L@ja
10-12-2007, 07:51 AM
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"

Marius Titul
04-18-2018, 09:56 AM
Thanks for the tip! Works like a charm.

Paul_Hossler
04-18-2018, 07:24 PM
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