"!
(c) Ralf Wenzel, Heuristika Unternehmensberatung, Hamburg
"! Bitte beachten Sie die Unit-Tests, die Beispielfälle demonstrieren "! sowie das Programm, das eine Einfachst-UI abbildet! CLASS ycl_brf_prototyp DEFINITION PUBLIC FINAL CREATE PUBLIC . PUBLIC SECTION. INTERFACES yif_brf_prototyp . TYPES _brfresult TYPE REF TO data. TYPES _import_parameter TYPE REF TO data. TYPES _brf_name TYPE if_fdt_types=>name. TYPES _function_id TYPE if_fdt_types=>id. TYPES _timestamp TYPE if_fdt_types=>timestamp. TYPES _parambindings TYPE abap_parmbind_tab. TYPES _parambind_value TYPE abap_parmbind-value. PROTECTED SECTION. PRIVATE SECTION. CLASS-DATA my_instance TYPE REF TO ycl_brf_prototyp. DATA result_data_object TYPE string VALUE '_V_RESULT' ##NO_TEXT. DATA brf_result TYPE _brfresult. DATA import_data_name TYPE if_fdt_types=>name. DATA import_data_id TYPE _function_id. DATA import_parameter TYPE _import_parameter . DATA brf_function TYPE if_fdt_types=>name. "! Holen der Datenobjekt-Referenz zum Ergebnis der BRF+ Funktion "! "! @parameter i_brf_function | Name der BRF-Funktion "! @parameter r_data_object_reference | Referenz auf Datenobjekt METHODS get_data_object_reference IMPORTING !i_brf_function TYPE _brf_name RETURNING VALUE(r_data_object_reference) TYPE REF TO data RAISING cx_fdt . "! 'Übersetzen' einer Message ins Format für BRF+ Ausnahmeklassen "! "! @parameter i_id | BRF+ ID "! @parameter i_object_type | BRF+ Objekttyp "! @parameter i_msgid | Arbeitsgebiet Meldungen "! @parameter i_msgty | Meldungstyp E/A/I/S/X "! @parameter i_msgno | Meldungsnummer im Arbeitsgebiet "! @parameter i_msgv1 | Meldungsvariable &1 "! @parameter i_msgv2 | Meldungsvariable &2 "! @parameter i_msgv3 | Meldungsvariable &3 "! @parameter i_msgv4 | Meldungsvariable &4 "! @parameter i_text | Meldungstext "! @parameter i_source | Stelle im Quelltext "! @parameter i_related_id | Beugnehmende ID "! @parameter i_t_path | ? "! @parameter i_r_ref | ? "! @parameter r_messages | Meldungstabelle für BRF+ Exception METHODS make_message4exc IMPORTING i_id TYPE if_fdt_types=>id i_object_type TYPE if_fdt_types=>object_type i_msgid TYPE symsgid i_msgty TYPE symsgty i_msgno TYPE symsgno i_msgv1 TYPE symsgv OPTIONAL i_msgv2 TYPE symsgv OPTIONAL i_msgv3 TYPE symsgv OPTIONAL i_msgv4 TYPE symsgv OPTIONAL i_text TYPE string OPTIONAL i_source TYPE string OPTIONAL i_related_id TYPE if_fdt_types=>id OPTIONAL i_t_path TYPE if_fdt_types=>t_object_id OPTIONAL i_r_ref TYPE REF TO data OPTIONAL RETURNING VALUE(r_messages) TYPE if_fdt_types=>t_message. "! Ermittlung der BRF+ UUID zu einem BRF+ Namen "! "! Achtung: Der Name ist technisch gesehen nicht eindeutig, "! es muss also organisatorisch sichergestellt sein, dass "! der Name richtig gewählt wird. Die Einschränkung auf "! den Objekttypen sollte dabei helfen. "! @parameter i_name | Name BRF+ "! @parameter i_object_type | Objekttyp BRF+ "! @parameter i_id | UUID BRF+ "! @raising cx_fdt_input | Fehlerhafte Eingabedaten METHODS get_uuid_from_name IMPORTING i_name TYPE if_fdt_types=>name i_object_type TYPE fdt_object_type RETURNING VALUE(r_id) TYPE fdt_uuid RAISING cx_fdt_input. "! Holen der BRF+ Funktions-ID (UUID) zum BRF+ Funktions-Namen "! "! @parameter i_brf_function | Name des BRF+ Objekts "! @parameter r_function_id | UUID des BRF+ Objekts "! @raising cx_fdt_input | Fehlerhafte Eingabedaten METHODS get_function_id_from_name IMPORTING !i_brf_function TYPE _brf_name RETURNING VALUE(r_function_id) TYPE _function_id RAISING cx_fdt_input. "! Holen der BRF+ Datenobjekts-ID (UUID) zum BRF+ Datenobjekts-Namen "! "! @parameter i_brf_dataname | Name des BRF+ Objekts "! @parameter r_function_id | UUID des BRF+ Objekts "! @raising cx_fdt_input | Fehlerhafte Eingabedaten METHODS get_data_id_from_name IMPORTING !i_brf_dataname TYPE _brf_name RETURNING VALUE(r_function_id) TYPE _function_id RAISING cx_fdt_input. "! Holen der UUID für Importdaten "! "! @parameter i_import_data_id | UUID der Importdaten METHODS get_import_data_id RETURNING VALUE(r_import_data_id) TYPE _function_id. "! Holt der Key-Value-Tabelle zu den Importdaten einer "! BRF+ Funktion "!(Die Methode ist noch unfertig!)
"! "! @parameter i_brf_function | Name der BRF-Funktion "! @parameter r_parambindings | Key-Value-Tabelle für Importparameter METHODS get_parambindings IMPORTING !i_brf_function TYPE _brf_name RETURNING VALUE(r_parambindings) TYPE _parambind_value. "! Hole Ergebnisdatenobjekt zur BRF+ Funktion "! "! @parameter r_result_data_object | Ergebnisdatenobjekt METHODS get_result_data_object RETURNING VALUE(r_result_data_object) TYPE string. "! Holen aktueller Zeitstempel "! "! @parameter r_timestamp | aktueller Zeitstempel METHODS get_timestamp RETURNING VALUE(r_timestamp) TYPE _timestamp. "! Hole Datenobjekt für Import-Parameter einer BRF+ Funktion "! "! @parameter i_brf_function | Name der BRF-Funktion "! @parameter r_parambindings | Value-Wert für Tabelle der Import-Parameter "! @raising cx_fdt_input | Ungültige Eingabedaten für BRF+ METHODS get_value IMPORTING !i_brf_function TYPE _brf_name RETURNING VALUE(r_value) TYPE _parambind_value RAISING cx_fdt_input. " Holen Name der Struktur für die Importdaten "! "! @parameter r_import_data_name | Name der Importdaten-Struktur METHODS get_import_data_name RETURNING VALUE(r_import_data_name) TYPE string. "! Holt der Key-Value-Tabelle zu den Importdaten einer "! BRF+ Funktion "! "! @parameter i_context_list | ??? "! @parameter r_parambindings | Key-Value-Tabelle für Importparameter METHODS make_params_from_context IMPORTING !i_context_list TYPE cl_fdt_function_process=>t_context_list RETURNING VALUE(r_parambindings) TYPE _parambind_value. ENDCLASS. CLASS ycl_brf_prototyp IMPLEMENTATION. METHOD get_data_object_reference. cl_fdt_function_process=>get_data_object_reference( EXPORTING iv_function_id = me->get_function_id_from_name( i_brf_function ) iv_data_object = CONV #( me->get_result_data_object( ) ) IMPORTING er_data = r_data_object_reference ). ENDMETHOD. METHOD get_function_id_from_name. " Es ist gar nicht so selten, dass man den Namen einer BRF+ Funktion kennt, " übergeben muss man allerdings die UUID. Man sollte aber beachten, " dass die Namen nicht eindeutig sind (weshalb es ja die UUIDs gibt) " " Freilich gibt es auch 1.001 andere Wege der Herleitung der UUID. r_function_id = me->get_uuid_from_name( i_name = i_brf_function i_object_type = me->yif_brf_prototyp~object_type-function ). ENDMETHOD. METHOD get_data_id_from_name. r_function_id = me->get_uuid_from_name( i_name = i_brf_dataname i_object_type = me->yif_brf_prototyp~object_type-data_object ). ENDMETHOD. METHOD get_import_data_id. r_import_data_id = me->import_data_id. ENDMETHOD. METHOD get_parambindings. cl_fdt_function_process=>get_context_list( EXPORTING iv_function_id = me->get_function_id_from_name( i_brf_function ) iv_timestamp = me->get_timestamp( ) iv_trace_generation = abap_true IMPORTING et_context_list = DATA(context_list) ). r_parambindings = make_params_from_context( context_list ). ENDMETHOD. METHOD get_result_data_object. r_result_data_object = me->result_data_object. ENDMETHOD. METHOD get_timestamp. GET TIME STAMP FIELD r_timestamp. ENDMETHOD. METHOD get_uuid_from_name. SELECT SINGLE id FROM fdt_admn_0000 INTO r_id WHERE name EQ i_name AND object_type EQ i_object_type AND version EQ ( SELECT MAX( version ) FROM fdt_admn_0000 WHERE name EQ i_name AND object_type EQ i_object_type ). IF sy-subrc NE 0. RAISE EXCEPTION TYPE cx_fdt_input EXPORTING mt_message = make_message4exc( i_id = r_id i_object_type = i_object_type i_msgid = 'FDT_CORE' i_msgty = 'E' i_msgno = '215' i_msgv1 = CONV #( i_name ) i_source = cx_fdt=>get_source_name( ) ). ENDIF. ENDMETHOD. METHOD get_value. DATA import_data TYPE REF TO data. DATA value TYPE REF TO data. cl_fdt_function_process=>move_data_to_data_object( EXPORTING ir_data = me->import_parameter "import_data iv_function_id = me->get_function_id_from_name( i_brf_function ) iv_data_object = me->get_import_data_id( ) iv_timestamp = me->get_timestamp( ) iv_trace_generation = abap_false iv_has_ddic_binding = abap_true IMPORTING er_data = value ). r_value = value. ENDMETHOD. METHOD get_import_data_name. r_import_data_name = me->import_data_name. ENDMETHOD. METHOD make_message4exc. MESSAGE ID i_msgid TYPE i_msgty NUMBER i_msgno WITH i_msgv1 i_msgv2 i_msgv3 i_msgv4 INTO DATA(messagetext). r_messages = ( VALUE #( ( id = i_id object_type = i_object_type msgid = i_msgid msgty = i_msgty msgno = i_msgno msgv1 = i_msgv1 msgv2 = i_msgv2 msgv3 = i_msgv1 msgv4 = i_msgv1 text = messagetext source = i_source related_id = i_related_id ) ) ). ENDMETHOD. METHOD make_params_from_context. DATA fdt_factory TYPE REF TO cl_fdt_factory. DATA fdt_data_object TYPE REF TO if_fdt_data_object. LOOP AT i_context_list ASSIGNING FIELD-SYMBOL(