-
Notifications
You must be signed in to change notification settings - Fork 0
ABAP Integration
The main purpose of ABAP Lisp is to be able to interact with an ABAP application server. To achieve this, a number of built-in procedures and types are provided to consume function modules and classes (this is still a work in progress).
All symbols beginning with ab-
are related to ABAP integration.
To create a new piece of data, the ab-data
procedure is used. It takes as its first argument the name of an ABAP type. It returns an element that contains a data reference to the created ABAP data. In addition, it can take an optional second parameter, which is the value with which the data is initialized (2015-07-09 currently only elementary types).
(ab-data "MANDT")
To access data values, the built-ins ab-get
and ab-set
are provided. These functions work with any kind of ABAP data: elementary types, structures, tables and function module interfaces.
When used on elementary types of data, the ab-get
function will return the immediate value of the data as either a number or string, depending on the type of the ABAP data. Using ab-set
, the first argument will be used to set the value. For example:
(define mandt (ab-data "MANDT")) ;; Declares a field of type MANDT
(ab-set mandt "100") ;; Sets value of mandt to "100"
(ab-get mandt) ;; Returns value of mandt
When used on any complex types, i.e. structures, tables or function module interfaces, the second argument to ab-get
or ab-set
must be an identifier to access the necessary part of the data. In the case of structures or function module interfaces, the argument, either a string or symbol, identifies the field name or parameter respectively. The following example shows accessing structure fields:
(define t005g (ab-data "T005G"))
(ab-set t005g "LAND1" "ZA") ;; Set field "LAND1" to "ZA"
(ab-get t005g "LAND1") ;; Return the value of field "LAND1"
In the case of a table, the identifier argument is used to access an existing row of the table. In the case of standard tables, a numeric argument will read the corresponding table entry by index. A hash-map value will be used to form a WHERE
clause to read the table. In the case of a sorted table, a hash-map identifier will be used to read the table by key. (2015-07-09 only reading standard table by index works at this point).
Two other functions exist for setting and getting ABAP data. These are ab-set-value
and ab-get-value
. In contrast to the ab-get
and ab-set
functions, these functions map ABAP data to LISP structures and vice versa. (They also do not support function parameters; not yet anyway). While elementary values are mapped with basic types, structures are mapped to single-level lists with values in the sequence of the structure element, while tables are represented by nested lists, with the inner lists representing rows of the table.
(define t005g (ab-data "T005G"))
(ab-set-value t005g '("000" "ZA" "ABC" "JHB")) ;; Set values of T005G as a list with sequence of fields
(ab-get-value t005g) ;; Return values of T005G as a list
The ab-set-value
and ab-get-value
are not recommended for large structures or tables with many rows.
The following code shows an example of calling a function module and accessing its parameters:
(define bapi-userdetail (ab-function "BAPI_USER_GET_DETAIL")) ;; Assign interface of BAPI_USER_GET_DETAIL to a symbol
(ab-set bapi-userdetail "USERNAME" (ab-get ab-sy "UNAME")) ;; Set parameter "USERNAME" to current user
(bapi-userdetail) ;; Call the function
(define profiles (ab-get bapi-userdetail "PROFILES")) ;; Assign parameter "PROFILES" to a symbol
(define profile (ab-get profiles 1)) ;; Assign first row of "PROFILES" to a symbol
(ab-get profile "BAPIPROF") ;; Get field "BAPIPROF" of first row
As the example shows, the procedure ab-function
is used, with a function module name as its argument, to create a value of type <ABAP function>
that represents a function module interface, which can be called like an ABAP Lisp procedure or lambda.
The parameters of the function interface can be accessed with ab-get
and ab-set
as described above. To call the function, the function value is interpreted as the first element in a list. It can optionally take a hash map representing the parameter values (not yet implemented - 2015-07-09).
** Under Development **
The SY-variables which are accessible in ABAP programs are provided as the predefined symbol ab-sy
in ABAP Lisp. So for example, the following code will return the current user ID:
(ab-get ab-sy "UNAME")