In this tutorial we combine some VB.NET functions (sending an e-mail) with the calling up of SAP GUI scripting.
We want to send some order data (transaction VA03) as a short overview per e-mail:

First we add a new pushbutton that will process an InputScript:

pushbutton (3,22) "@J8\QSend order as e-mail@Send order as e-mail " process="send_email_order_va03.txt"

InputScript send_email_order_va03.txt:

// Copy to
Set
V[ccRef] "pascal@synactive.com"

// Send order overview as e-mail
callvbasync
tutorials.utilities.send_order_html "&F[Order]" "office@synactive.com" "Synactive employee" "ccRef" "Order &F[Order]"


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: