how to create BRF function via code

简介: how to create BRF function via code

REPORT zceate_app_function.

DEFINE write_errors.

 IF &1 IS NOT INITIAL.

 LOOP AT &1 ASSIGNING .

 WRITE: -text.

 ENDLOOP.

 RETURN.

 ENDIF.

END-OF-DEFINITION.

START-OF-SELECTION.

 DATA: lo_factory     TYPE REF TO if_fdt_factory,

       lo_application TYPE REF TO if_fdt_application,

       lt_message     TYPE if_fdt_types=>t_message,

       lv_boolean     TYPE abap_bool.

 FIELD-SYMBOLS:  TYPE if_fdt_types=>s_message.

 lo_factory = cl_fdt_factory=>if_fdt_factory~get_instance( ).

 lo_application = lo_factory->get_application( ).

 lo_application->if_fdt_transaction~enqueue( ).

 lo_application->set_development_package( '$TMP' ).

 lo_application->if_fdt_admin_data~set_name( 'PRICING2' ).

 lo_application->if_fdt_admin_data~set_texts(

 iv_short_text = 'Pricing2' ).

 lo_application->if_fdt_transaction~activate(

     IMPORTING et_message           = lt_message

               ev_activation_failed = lv_boolean ).

 write_errors lt_message.

 lo_application->if_fdt_transaction~save( ).

 lo_application->if_fdt_transaction~dequeue( ).

 lo_factory = cl_fdt_factory=>if_fdt_factory~get_instance(

 iv_application_id = lo_application->mv_id ).

 BREAK-POINT.

 WRITE:/ lo_application->mv_id.

 DATA: lo_function    TYPE REF TO if_fdt_function,

       lts_context_id TYPE if_fdt_types=>ts_object_id,

       lv_result_id   TYPE if_fdt_types=>id.

 lo_function ?= lo_factory->get_function( ).

 lo_function->if_fdt_transaction~enqueue( ).

 lo_function->if_fdt_admin_data~set_name( 'price_calculation' ).

 lo_function->if_fdt_admin_data~set_texts(

 iv_short_text = 'price calculation' ).

 lo_function->set_function_mode( if_fdt_function=>gc_mode_event ).

* WE NEED TO CREATE DATA OBJECT AND ASSIGN IT TO CONTEXT

 DATA lo_element TYPE REF TO if_fdt_element.

* CREATION: get new element via factory

 lo_element ?= lo_factory->get_data_object(

 iv_data_object_type = if_fdt_constants=>gc_data_object_type_element ).

 lo_element->if_fdt_transaction~enqueue( ).

 lo_element->if_fdt_admin_data~set_name( 'customer' ).

 lo_element->if_fdt_admin_data~set_texts( iv_short_text = 'customer' ).

 lo_element->set_element_type( if_fdt_constants=>gc_element_type_text ).

 lo_element->set_element_type_attributes( iv_length = 30 ).

 INSERT lo_element->mv_id INTO TABLE lts_context_id.

* CREATE RESULT DATA OBJECT

 lo_element ?= lo_factory->get_data_object(

     iv_data_object_type = if_fdt_constants=>gc_data_object_type_element ).

 lo_element->if_fdt_transaction~enqueue( ).

 lo_element->if_fdt_admin_data~set_name( 'final_price' ).

 lo_element->if_fdt_admin_data~set_texts( iv_short_text = 'final price' ).

 lo_element->set_element_type( if_fdt_constants=>gc_element_type_number ).

 lo_element->set_element_type_attributes(

     iv_length        = 7

     iv_decimals      = 2

     iv_only_positive = abap_true ).

 lv_result_id     = lo_element->mv_id.

* WE NEED TO ASSIGN PROPERTY CONTEXT TO FUNCTION INSTANCE

 lo_function->set_context_data_objects( lts_context_id ).

 lo_function->set_result_data_object( lv_result_id ).

 lo_function->if_fdt_transaction~activate(

    EXPORTING

       iv_deep              = abap_true

    IMPORTING

       et_message           = lt_message

       ev_activation_failed = lv_boolean ).

 write_errors lt_message.

 lo_function->if_fdt_transaction~save(

      EXPORTING iv_deep = abap_true ).

 lo_function->if_fdt_transaction~dequeue(

      EXPORTING iv_deep = abap_true ).

function name通过set_name设置:



image.png

report里创建了一个data element customer和一个result element final_price:


image.png


image.png

点击PRICE_CALCULATION的超链接进入function的detail page:


能找到function的technical ID和signature, event mode:


image.png

相关文章
|
5月前
SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘thinkphp.test‘ don‘t exsit
SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘thinkphp.test‘ don‘t exsit
92 0
【已解决】Error: Element type is invalid: expected a string (for built-in components) or a class/function
Error: Element type is invalid: expected a string (for built-in components) or a class/function
2306 0
【已解决】Error: Element type is invalid: expected a string (for built-in components) or a class/function
|
10月前
|
关系型数据库 MySQL C++
Error:E0415 no suitable constructor exists to convert from “int“ to “Rational“
Error:E0415 no suitable constructor exists to convert from “int“ to “Rational“
120 0
SAP WM 为Storage Type 004激活SUM报错 - Storage types without pick-point stor.type require partial pallet
SAP WM 为Storage Type 004激活SUM报错 - Storage types without pick-point stor.type require partial pallet
SAP WM 为Storage Type 004激活SUM报错 - Storage types without pick-point stor.type require partial pallet
|
测试技术
SAP IDoc 报错- Function module not allowed SPEIDOC_INPUT_DESADV1 –
SAP IDoc 报错- Function module not allowed SPEIDOC_INPUT_DESADV1 –
SAP IDoc 报错- Function module not allowed SPEIDOC_INPUT_DESADV1 –
SAP IDoc Post不成功,报错 - A company code cannot be determined for LI 0000100061 –
SAP IDoc Post不成功,报错 - A company code cannot be determined for LI 0000100061 –
SAP IDoc Post不成功,报错 - A company code cannot be determined for LI 0000100061 –
Fiori Elements detail table data request logic
Fiori Elements detail table data request logic
100 0
Fiori Elements detail table data request logic
how to create BRF application via code
使用如下代码自动创建新的BRF application:
107 0
how to create BRF application via code
How to create unit test for product determination function module
How to create unit test for product determination function module
116 0
How to create unit test for product determination function module