Skip to content

ERPConnect.Utils.ABAPCode

Namespace: ERPConnect.Utils
Assembly: ERPConnectStandard20.dll

ABAPCode is a class, that can be used to execute ABAP code on the fly and retrieve the result.

public class ABAPCode

Inheritance

objectABAPCode

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Constructors

ABAPCode(R3Connection)

initializes a ABAPCode object that can be used to execute dynmic ABA code A valid SAP connection

public ABAPCode(R3Connection Con)

Parameters

Con R3Connection

ABAPCode()

initializes a ABAPCode object that can be used to execute dynmic ABA code

public ABAPCode()

Properties

Connection

The R3Connection object which the ABAPCode object is assigned to.

public R3Connection Connection { get; set; }

Property Value

R3Connection

LastABAPSyntaxError

Returns the ABAP error message in case the programm is syntacly incorrect. The method Execute returns false.

public string LastABAPSyntaxError { get; }

Property Value

string

ResultLineCount

Returns the number of lines that a retrieved a report output.

public int ResultLineCount { get; }

Property Value

int

Methods

AddCodeLine(string)

Adds a new line of ABAP code.

public void AddCodeLine(string CodeLine)

Parameters

CodeLine string

Line of ABAP code to append

Execute()

Executes ABAP code on the fly.

public bool Execute()

Returns

bool

true / false depends if the program could have been executed without a syntax error.

Remarks

The following code shows, how to set some ABAP code (located in textBox1), execute it and write the list result in another TextBox. You'll find this samples in the directory AbapPad. [C#]

  private void button1_Click(object sender, System.EventArgs e)
  {
     ERPConnect.R3Connection con = new ERPConnect.R3Connection();
     if(!con.AskUserAndOpen(true))
                     return;
     ERPConnect.Utils.ABAPCode code = new ERPConnect.Utils.ABAPCode();

     code.Connection = con;

     foreach(string s in textBox1.Lines)
     code.AddCodeLine(s);

     if (code.Execute())
     {
for(int i=0; i  code.ResultLineCount; i++)
         textBox2.Text += code.GetResultLine(i) + "\r\n";
     }
     else
         textBox2.Text = "ABAP Error: " + code.LastABAPSyntaxError;
 }

[VB]

  Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
    Dim con As New ERPConnect.R3Connection
    If Not con.AskUserAndOpen(True) Then
        Exit Sub
    End If

    Dim code = New ERPConnect.Utils.ABAPCode
    code.Connection = con

    Dim s As String
    For Each s In textBox1.Lines
        code.AddCodeLine(s)
    Next

    Dim i As Integer
    If code.Execute() Then
        For i = 0 To code.ResultLineCount - 1
            textBox2.Text += code.GetResultLine(i) + vbCrLf
        Next
    Else
        textBox2.Text = "ABAP Error: " + code.LastABAPSyntaxError
    End If
End Sub

GetResultLine(int)

Returns a single at the given position the resultset of the abap report

public string GetResultLine(int Index)

Parameters

Index int

Index of the result line

Returns

string

Result line of the report output

ResetCode()

Deletes the current code lines.

public void ResetCode()

Last update: January 4, 2024