
" data declarations and some syntax details ommited
" for readability and code is pseudified
method send_my_document.
api = create_api_client_instance( ).
context = prepare_document_context( ).
doc = create_my_document(
i_params = doc_specific_params
i_context = context ).
" The specific code,
" the document class can be different
" params can be different
" but note the conext which is created inside
result = api->send( doc ).
post_process_result( result ).
endmethod.
interface lif_my_doc.
method create_doc
importing
i_context type ...
returning
value(r_doc) type ...
endinterface.
interface lif_lambda.
methods run
importing
i_workset type any
changing
c_result type any.
endinterface.
method run.
field-symbol <context> type ty_context.
field-symbol <result> type ref to zcl_my_document.
assign i_workset to <context>.
assign c_result to <result>.
<result> = create_my_document(
i_params = doc_specific_params
i_context = <context> ).
endmethod.
interface lif_lambda.
methods run
importing
i_workset type any optional
returning
value(ri_result) type ref to lif_lambda_result.
endinterface.
interface lif_lambda_result.
methods str returning value(r_val) type string.
methods int returning value(r_val) type i.
methods obj returning value(r_val) type ref to object.
methods struc changing cs_struc type any.
methods tab changing ct_tab type any table.
...
endinterface.
class lcl_lambda_result definition final.
public section.
interfaces lif_lambda_result.
data mr_data type ref to data.
endclass.
class lcl_lambda_result implementation.
method lif_lambda_result~obj.
field-symbols <val> type any.
data l_type type c.
assign mr_data->* to <val>.
describe field <val> type l_type.
if l_type ca 'r'. " object
r_val = <val>.
endif.
endmethod.
" ... other unwrappers here
endclass.
li_lambda->run( some_params )->str( ).
li_lambda->run( some_params )->obj( ).
...
class lcl_lambda_result definition final.
public section.
interfaces lif_lambda_result.
class-methods wrap " instantiation method
importing
i_result type any
returning
value(ri_result) type ref to lif_lambda_result.
private section.
data mr_data type ref to data. " Hide the ref
endclass.
class lcl_lambda_result implementation.
method wrap.
data lo_result type ref to lcl_lambda_result.
create object lo_result.
data l_type type c.
describe field i_result type l_type.
if l_type = 'r'. " object
create data lo_result->mr_data type ref to object.
else.
create data lo_result->mr_data like i_result.
endif.
field-symbols <val> type any.
assign lo_result->mr_data->* to <val>.
<val> = i_result. " Just copy the incoming value into a data ref
ri_result = lo_result.
endmethod.
" all the rest
endclass.
" callback for document creation
method run.
field-symbol <context> type ty_context.
assign i_workset to <context>.
" wrap any result with one line !
ri_result = lcl_lambda_result=>wrap(
create_my_document( doc_specific_params, <context> ) ).
endmethod.
" and the calling code would be
method send_my_document.
api = create_api_client_instance( ).
context = prepare_document_context( ).
" receive the result converting to the expected type
doc = ii_doc_callback->run( context )->obj( ).
result = api->send( doc ).
post_process_result( result ).
endmethod.
CHAR_W_WRAPPER 0,034402
CHAR_WO_WRAPPER 0,009170
STRING_W_WRAPPER 0,036532
STRING_WO_WRAPPER 0,009457
INT_W_WRAPPER 0,031680
INT_WO_WRAPPER 0,008231
OBJ_W_WRAPPER 0,073308
OBJ_WO_WRAPPER 0,039072
STRUC_W_WRAPPER 0,044464
STRUC_WO_WRAPPER 0,012494
TAB_W_WRAPPER 0,054196
TAB_WO_WRAPPER 0,021800
class lcl_callback1 definition final.
public section.
interfaces lif_lambda.
class-methods new
importing
io_this type ref to zcl_parent_global_class
returning
value(ro_instance) type ref to lcl_callback1.
private section.
data mo_this type ref to zcl_parent_global_class.
endclass.
class zcl_parent_global_class definition local friends lcl_callback1.
class lcl_callback1 definition final.
methods new.
create object ro_instance.
ro_instance->mo_this = io_this.
endmethod.
method lif_lambda~run.
" do something with mo_this - the parent class
endmethod.
endclass.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 |