Thursday, 22 August 2013

SAP Com Objects and .GetType/.GetProperties

SAP Com Objects and .GetType/.GetProperties

I'm trying to access the table that is returned from BAPI function calls.
They don't return a normal status/error message but a table called
BAPIRET1. The table is then stored in a COM Object called Bapi_return.
I've been desperately trying to get the data out of this COM Object, but
to no avail. I've seen someone use Reflections with .GetType and
.GetProperties in C#. The relevant parts of his code look like this:
Type type = bapiReturn.GetType();
PropertyInfo[] infos = type.GetProperties();
foreach (PropertyInfo info in infos)
{
switch (info.Name.ToUpper())
{
case "TYPE":
myType = (string)info.GetValue(bapiReturn, null);
break;
...
Source
I've tried to do the same in VB .NET:
...
'Code that returns the Table
CO13 = R3.add("BAPI_PRODORDCONF_CANCEL")
CO13.exports("CONFIRMATION") = confirmationnr
CO13.exports("CONFIRMATIONCOUNTER") = cnfrmcnt
Bapi_return = CO13.imports("RETURN")
BapiService.Transactioncommit()
'Trying to access the table data via GetProperties
Dim type As Type
Dim infos As Reflection.PropertyInfo()
type = Bapi_return.GetType()
infos = type.GetProperties()
This is where I am stuck though. GetProperties only returns a generic COM
Object with which I can't really do anything and leaves the array "infos"
empty. There is a workaround to get the proper type with InvokeMember:
type = Bapi_return.GetType().InvokeMember("Type",
System.Reflection.BindingFlags.GetProperty, Nothing, Bapi_return,
Nothing)
This returns the correct type (BAPIRET1) but can't be assigned to the
variable type because "BAPIRET1" is returned as a string. I would assume
that VB .NET simply doesn't know the BAPIRET1 and therefore my method
can't work, but the website I have the C# code from successfully uses
.GetType and .GetProperty on BAPIRET1. So there must be a way.
Any help on my specific problem or help on reading BAPIRET1 tables in VB.
NET would be greatly appreciated!

No comments:

Post a Comment