BAPI_MATERIAL_MRP_LIST returns empty values in VBA - excel

I use an Excel macro to get values from SAP, especially for planned orders.
Function GetOrders(ByVal ProductNumber As String)
Dim OrderList As Object: Set OrderList = SAP.Add("BAPI_MATERIAL_MRP_LIST")
Dim OrderMat As Object: Set OrderMat = OrderList.Exports("MATERIAL")
Dim OrderPlant As Object: Set OrderPlant = OrderList.Exports("PLANT")
Dim OrderTable As Object: Set OrderTable = OrderList.Tables("MRP_IND_LINES")
OrderTable.FreeTable
OrderMat = ProductNumber
OrderPlant = "XXX"
OrderList.Call
Set GetOrders = OrderTable
Set OrderMat = Nothing
Set OrderPlant = Nothing
Set OrderTable = Nothing
End Function
I changed the OrderPlant for the question.
It's working on one PC but using the same SAP account on another one we get some empty values. Specifically all the numbers > 10k are not shown.
On my PC I get something like this as a result from the MRP_IND_LINES table:
P.cons 00XXXXXXXX/XXXXXX/XXXX -21.600.000
P.cons 00XXXXXXXX/XXXXXX/XXXX -3.600.000
On another PC I the -21.600.000 is empty so it shows like this:
P.cons 00XXXXXXXX/XXXXXX/XXXX
P.cons 00XXXXXXXX/XXXXXX/XXXX -3.600.000
The disappearing field is the "REC_REQD_QTY", number 16 of the table BAPI_MRP_IND_LINES (MRP: Single Lines of MRP Elements), Data Type: "QUAN"
The only difference between the PCs is the SAP logon GUI version, 720 on mine and 750 on the other PC.
This happens only on the big numbers. The other fields in the row are downloaded correctly.
I'm not using SAP GUI scripting, but I've created the SAP Object with the row
Set SAP = CreateObject("SAP.Functions.Unicode")

Related

Set a value from a collection to a variable

I am trying to do some debugging and I have a collection I created from several different strings. What I would like to do is go back and set another variable equal to the second item in the collection. Is this possible? See a very simplified example below:
Dim TagForms As New Collection
Dim TagForm1 As String
Dim TagForm2 As String
Dim TagForm3 As String
Dim Test As String
TagForm1 = "Cat"
TagForm2 = "Dog"
TagForm3 = "Pig"
Set TagForms = New Collection
TagForms.Add TagForm1
TagForms.Add TagForm2
TagForms.Add TagForm3
Test = TagForms(2) 'This doesn't work
Set Test = TagForms(2) 'This also doesn't work
As the variable 'Test' is a string, the last code line 'Set Test = TagForms(2)' does not work.
The correct code line is 'Test = TagForms(2)'. This code returns 'Dog'

Lotus scripts Set value(Unique Number) in each document from GetAllDocumentsByKey

From my code below try to Looping from "GetAllDocumentbyKey" and Set Unique number each document for to show in Folder View , but from my code it's not work.
How should I solve this problem?
Dim defect As Variant
defect = uidoc.FieldGetText("DefectMode")
keys( 0 ) =defect
Dim PartNo As Variant
partNo = uidoc.FieldGetText("PartNo")
keys( 1 ) = partNo
Set view = db.GetView("EmbedView2" )
Set dc = view.GetAllDocumentsByKey(keys,False)
Call dc.PutAllInFolder("EmbedFolder")
Do Until dc Is Nothing
call uidoc.FieldSetText("UniqueNo","number") // this code I try to set unique number to each document by number that's I plan to increase 1 , I have to set in "UniqueNo" Fieled
Loop
OK... There is a big part missing from your code.
uidoc is the currently open document and if I guess right, it has an embedded view in it called "EmbedFolder". The documents you want to modify all belong to a special DefectMode and a special PartNo (that of the currently open document)
I doubt that what you want makes sense, but I don't wanna go into that.
To make your code work you need to cycle through the document collection and set each documents value separately. This would simply look like this:
Dim intNumber as Integer
Dim doc as NotesDocument
intNumber = 1
Set doc = dc.GetFirstDocument()
Do until doc is Nothing
Call doc.ReplaceItemValue( "UniqueNo" , intNumber )
Call doc.Save( True, True, True )
Set doc = dc.GetNextDocument( doc )
Wend

Excel VBA - Get chart data range

I want to add data to a bunch of existing charts. Assume that each chart has a different number of data series and that the location of the raw data is somewhere in the same workbook. Here's what I'm starting with:
For iChart = 1 To iCount
ActiveSheet.ChartObjects("Chart " & iChart).Activate
intSeries = 1
Do Until ActiveChart.SeriesCollection(intSeries).Name = ""
Set rXVal = ActiveChart.SeriesCollection(intSeries).XValues '<- Object Required error
Set rXVal = Range(rXVal, rXVal.End(xlDown))
Set rYVal = ActiveChart.SeriesCollection(intSeries).Values
Set rYVal = Range(rYVal, rYVal.End(xlDown))
ActiveChart.SeriesCollection(intSeries).XValues = rXVal
ActiveChart.SeriesCollection(intSeries).Values = rYVal
intSeries = intSeries + 1
Loop
Next iChart
I know that ActiveChart...XValues = rXVal works, but I'm getting an "Object Required" error on the Set rXVal = ActiveChart....XValues line. I'm assuming that since a range went in to define the data series, I can get that range back out again and then add to it.
UPDATE
To clarify things a little, I have accelerometers in 8 places and FFT software setup to record peak vibration response in 4 separate frequency bands. This yields 32 data points per sample. When exporting, the software spits out an Excel workbook with 4 sheets; one for each frequency band. Each sheet has the accelerometer names going across and sample numbers going down.
I have succeeded using this syntax:
Dim rXVal() As Variant
rXVal = ActiveChart.SeriesCollection(intSeries).XValues
UPDATE
In this case you get an array, because your given statement (ActiveChart.SeriesCollection(intSeries).XValues) is an array and not a range. This is what you see in Locals window if you dig into Series object of ActiveChart.SeriesCollection(intSeries):
(in my dummy data I have rows named r1, r2, r3, r4.)
What I want to say, XValues does not have any property which would indicate its occupied range.
If you actually need a range, I would suggest getting it from the formula property. And the way I would suggest is replacing your error causing line with this one:
Set rXVal = Range(Split(ActiveChart.SeriesCollection(intSeries).Formula, ",")(1))
Next, I see you trying to get the range for Values. Similarly, use this:
Set rYVal = Range(Split(ActiveChart.SeriesCollection(intSeries).Formula, ",")(2))
Another thing.
The following lines will cause you an error finally:
intSeries = 1
Do Until ActiveChart.SeriesCollection(intSeries).Name = ""
...some code...
intSeries = intSeries + 1
Loop
Do change them with:
For intSeries = 1 To ActiveChart.SeriesCollection.Count
...some code...
Next
Yet another thing.
Consider using With and End With, as you repeat a lot ActiveChart.SeriesCollection(intSeries). Then your code will be much more readable, as you would just skip this long line! Wouldn't that be awesome???
This works fine for me:
Dim rXVal() As Variant
Dim rXValMin, rXValMax As Double
rXVal = ActiveChart.SeriesCollection(intSeries).XValues
rXValMin = WorksheetFunction.Min(rXVal)
rXValMax = WorksheetFunction.Max(rXVal)

Export SQL query results into a multi tabbed Excel spreadsheet

I want to write a set of 100 select queries in DB2 10.1 to return all rows in each table in the database and have the results exported to an excel spreadsheet with a new tab for each result set.
Is this possible and if so how can I do it?
At the moment the only way I can do this looks like to export each result set and then manually create the multi tabbed spreadsheet by copying each tab across.
Thanks
You can use EasyXLS API for Excel with scripting languages like VB Script.
The VBS code should be similar with this one:
'The class that exports result set to Excel file
Set xls = CreateObject("EasyXLS.ExcelDocument")
' The class used to format the cells
Dim xlsAutoFormat
set xlsAutoFormat = CreateObject("EasyXLS.ExcelAutoFormat")
xlsAutoFormat.InitAs(AUTOFORMAT_EASYXLS1)
For query = 1 To 100
' Add a new sheet
xls.easy_addWorksheet_2("Sheet" & query)
set xlsSheet = xls.easy_getSheetAt(query - 1)
' Create the record set object
Dim objResultSet
Set objResultSet = CreateObject("ADODB.Recordset")
objResultSet.Open queryString, objDBConnection
' Create the list that will store the values of the result set
Dim lstRows
Set lstRows = CreateObject("EasyXLS.Util.List")
' Add the header to the list
Dim lstHeaderRow
Set lstHeaderRow = CreateObject("EasyXLS.Util.List")
lstHeaderRow.addElement("Column 1")
lstHeaderRow.addElement("Column 2")
lstHeaderRow.addElement("Column 3")
lstRows.addElement(lstHeaderRow)
' Add the values from the database to the list
Do Until objResultSet.EOF = True
set RowList = CreateObject("EasyXLS.Util.List")
RowList.addElement("" & objResultSet("Column 1"))
RowList.addElement("" & objResultSet("Column 2"))
RowList.addElement("" & objResultSet("Column 3"))
lstRows.addElement(RowList)
' Move to the next record
objResultSet.MoveNext
Loop
xlsSheet.easy_insertList_2 lstRows, xlsAutoFormat
Next
' Export result sets to Excel file
xls.easy_WriteXLSFile("c:\Result sets.xls")
Check also this link about exporting lists of data to Excel.
If you will choose a non scripting language, the API has methods that insert data directly from the result set and the lists can be skiped. Check another sample here.

Filling BAPI import table parameter in EXCEL using VBA

I have a query for me which requires to clear. I am using excel 2003. the sheet contains 12 columns. I need to do export data from excel to SAP. Before exporting I need to check if the record is exist or not, if exist then delete and insert.
I have two BAPIs for this one is import table, which needs to be filled the parameters, after filling this table the BAPI searches for the relevant records.
The list will be displayed in a table. I need to search that table with values from excel then import one field value to excel.
I write this code but, it is not working the BAPI giving Error 0.
Public Function Import_Order() As Boolean
Dim oBAPIGetOrder As Object
Dim oBAPIVariant1 As Object
Dim oBAPIVariant2 As Object
Dim oBAPIVariant3 As Object
Dim oBAPIImpOrder As Variant
Dim oBAPIRet As Boolean
Dim oDoNothing As Variant
gBAPIPlanOrder = 0
Set oBAPIGetPlOrder = sBAPIControl.Add("PLANED_GET_DET_LIST") 'BAPI
Set oBAPIVariant1 = oBAPIGetPlOrder.exports.Item("SELECTIONCRITERIA") 'Internal table
Set oBAPIVariant2 = oBAPIGetPlOrder.Tables.Item("DETAILEDLIST") 'Table
oBAPIVariant1.Value("MATERIAL") = eMaterial
oBAPIVariant1.Value("PLANT") = ePlnPlant
lBAPIRet = oBAPIGetPlOrder.call
If lBAPIRet Then
'oBAPIImpOrder = oBAPIGetPlOrder.imports.Item("PLANNEDORDER_NUM")
a = oBAPIVariant2.Rows.Count
oBAPIImpOrder = oBAPIVariant2.Value("PLANNEDORDER_NUM")
Import_PlannedOrder = True
Else
oBAPIImpOrder = 0
Import_PlannedOrder = False
End If
End Function
Thanks in advance for any help...
please place the call function statement
lBAPIRet = oBAPIGetPlOrder.call
after directly the exports statement and before the tables and importstatements

Resources