Note: For reading the items of the order we use the
guinet.dll interface (SAP GUI scripting) and therefore need to call the
asynchronous version of the command callVB: callVBAsync.
Implementing the function "send_order":
(You can download the full source code here:
send_order.txt)
Step no. 1: Add a reference to
guinet.dll to the VB.NET project. This file is shipped with the GuiXT
setup.
Step no. 2: Create an object of type guinet.guixt:
' Create instance of guixt
Dim g
As
New guinet.guixt
Step no. 3: Read in the required data:
(Please have a look the the documentation for a complete list of all
possible commands:
Synactive
docu -> GUI
Scripting in VB)
' Start transaktion VA03
g.GuiSession.Enter("/nVA03")
' Enter number of order
g.GuiSession.SetField("VBAK-VBELN",
orderno)
g.GuiSession.Enter()
' Get some data of order
HTML &= "Nettowert: " &
g.GuiSession.GetField("VBAK-NETWR")
& " "
HTML &= g.GuiSession.GetField("VBAK-WAERK")
& "<br>"
Step no. 4: You can easily read complete tables. We will do so with the command g.GuiSession.ReadTable
for the items of the order:
' Define table for ReadTable()
Dim dt
As DataTable
= New
DataTable("Orders")
dt.Columns.Add("POSNR")
dt.Columns.Add("MABNR")
' Read table with guinet.dll (SAP GUI Scripting)
g.GuiSession.ReadTable(dt)
Step no. 5: The data type of the table read is DataTable and
needs to be converted to HTML so it can be displayed in an e-mail:
' Format table with HTML
For i = 0 To dt.Rows.Count
- 1
HTML &= "<tr>"
HTML &= "<td>" & dt.Rows(i)(0)
& "</td>"
HTML &= "<td>" & dt.Rows(i)(1)
& "</td>"
HTML &= "</tr>"
Next
Step no. 6: Now we can send the HTML string as an e-mail:
' Send e-mail with SMTP
Dim e
As
New email
e.send_order(toEmail, toName, ccRef, subject, HTML)
Result:
|