With Release 7.40 ABAP supports so called constructor operators. Constructor operators are used in constructor expressions to create a result that can be used at operand positions. The syntax for constructor expressions is
... operator type( ... ) ...
operator is a constructor operator. type is either the explicit name of a data type or the character #. With # the data type can be dreived from the operand position if the operand type is statically known. Inside the parentheses specific parameters can be specified.
This is a short one but can become handy for some purposes.
The reference operator REF constructs a data reference at operand positions.
... REF dtype|#( dobj ) ...
results in a data reference pointing to dobj with the static type specified by type. With other words, REF is the short form for GET REFERENCE OF dobj INTO.
Where do you need it? Always when you have to pass data references to somewhere and don't want to create helper variables for that purpose.
Using REF for filling the parameter table:
CLASS class DEFINITION.
PUBLIC SECTION.
METHODS meth
IMPORTING p1 TYPE string
p2 TYPE i.
ENDCLASS.
CLASS class IMPLEMENTATION.
METHOD meth.
...
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA(arg1) = `blah`.
DATA(arg2) = 111.
DATA(ptab) = VALUE abap_parmbind_tab(
( name = 'P1' kind = cl_abap_objectdescr=>exporting value = REF #( arg1 ) )
( name = 'P2' kind = cl_abap_objectdescr=>exporting value = REF #( arg2 ) ) ).
DATA(oref) = NEW class( ).
CALL METHOD oref->('METH')
PARAMETER-TABLE ptab.
Parameter binding made easy!
DATA(key) = 'LH'.
DATA(sql) = NEW cl_sql_statement( ).
sql->set_param( REF #( sy-mandt ) ).
sql->set_param( REF #( key ) ).
DATA(result) = sql->execute_query(
`SELECT carrname ` &&
`FROM scarr ` &&
`WHERE mandt = ? AND carrid = ?` ).
DATA name TYPE scarr-carrname.
result->set_param( REF #( name ) ).
result->next( ).
Believe it or not: name contains the carrier name now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 |