The class ABAPCode offers nearly unlimited possibilities.
You can execute ABAP code on the fly and retrieve the result in a string array.
The following sample shows how to create a simple ABAP interpreter that executes a dynamic SQL statement, see screenshot below.
Creating an ABAP Interpreter #
- Open a client connection to the R/3 system using R3Connection.
- Add a new line of code to the dynamic report using AddCodeLine.
- Execute the report using Execute.
- Read the result set (regarding the ABAP list) using GetResultLine.
private void button1_Click(object sender, System.EventArgs e)
{
using (R3Connection con = new R3Connection("SAPServer", 00, "SAPUser", "Password", "EN", "800"))
{
ERPConnect.LIC.SetLic("LicenseNumber");
con.Open(false);
ERPConnect.Utils.ABAPCode code = new ERPConnect.Utils.ABAPCode();
code.Connection = con;
foreach (string s in txtABAPCode.Lines)
{
code.AddCodeLine(s);
}
if (code.Execute())
{
for (int i = 0; i < code.ResultLineCount; i++)
txtResult.Text += code.GetResultLine(i) + "\r\n";
}
else
{
txtResult.Text = "ABAP Error: " + code.LastABAPSyntaxError;
}
}
}