From b91f75fb726dba6441cc7ac29898b8e5915ceeaa Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Mon, 25 Dec 2023 11:23:30 +0100 Subject: [PATCH 1/7] CALL TRANSFORMATION, suppress initial components --- ..._call_transformation.clas.testclasses.abap | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/kernel/call_transformation/kernel_call_transformation.clas.testclasses.abap b/src/kernel/call_transformation/kernel_call_transformation.clas.testclasses.abap index bb42086e..a78d24cb 100644 --- a/src/kernel/call_transformation/kernel_call_transformation.clas.testclasses.abap +++ b/src/kernel/call_transformation/kernel_call_transformation.clas.testclasses.abap @@ -106,6 +106,7 @@ CLASS ltcl_call_transformation DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATI METHODS obj_static_attr FOR TESTING RAISING cx_static_check. METHODS dynamic_source FOR TESTING RAISING cx_static_check. METHODS dynamic_source_ixml FOR TESTING RAISING cx_static_check. + METHODS suppress1 FOR TESTING RAISING cx_static_check. ENDCLASS. CLASS ltcl_call_transformation IMPLEMENTATION. @@ -881,4 +882,23 @@ CLASS ltcl_call_transformation IMPLEMENTATION. ENDMETHOD. + METHOD suppress1. + + DATA: BEGIN OF ls_foo, + field TYPE i, + END OF ls_foo. + + DATA lv_xml TYPE string. + + CALL TRANSFORMATION id + OPTIONS initial_components = 'suppress' + SOURCE foo = ls_foo + RESULT XML lv_xml. + + cl_abap_unit_assert=>assert_char_cp( + act = lv_xml + exp = '**' ). + + ENDMETHOD. + ENDCLASS. \ No newline at end of file From 20537bf355069599167b99aeef7130bff004448c Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Mon, 25 Dec 2023 11:48:09 +0100 Subject: [PATCH 2/7] parse options --- .../kernel_call_transformation.clas.abap | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/kernel/call_transformation/kernel_call_transformation.clas.abap b/src/kernel/call_transformation/kernel_call_transformation.clas.abap index e3966eb1..45fbb682 100644 --- a/src/kernel/call_transformation/kernel_call_transformation.clas.abap +++ b/src/kernel/call_transformation/kernel_call_transformation.clas.abap @@ -1,11 +1,18 @@ CLASS kernel_call_transformation DEFINITION PUBLIC. * handling of ABAP statement CALL TRANSFORMATION PUBLIC SECTION. - CLASS-METHODS call IMPORTING input TYPE any. + CLASS-METHODS call + IMPORTING + name TYPE any + options TYPE any. PRIVATE SECTION. CLASS-DATA mi_doc TYPE REF TO if_ixml_document. CLASS-DATA mi_writer TYPE REF TO if_sxml_writer. + CLASS-DATA: BEGIN OF ms_options, + initial_components TYPE string, + END OF ms_options. + CLASS-METHODS parse_xml IMPORTING iv_xml TYPE string. @@ -19,6 +26,9 @@ CLASS kernel_call_transformation DEFINITION PUBLIC. iv_ref TYPE REF TO data RETURNING VALUE(rv_type) TYPE string. + + CLASS-METHODS parse_options + IMPORTING options TYPE any. ENDCLASS. CLASS kernel_call_transformation IMPLEMENTATION. @@ -46,6 +56,8 @@ CLASS kernel_call_transformation IMPLEMENTATION. WRITE '@KERNEL lv_name.set(INPUT.name.toUpperCase());'. ASSERT lv_name = 'ID'. + parse_options( options ). + * Handle input SOURCE WRITE '@KERNEL if (INPUT.sourceXML?.constructor.name === "ABAPObject") this.mi_doc.set(INPUT.sourceXML);'. WRITE '@KERNEL if (INPUT.sourceXML?.constructor.name === "String") lv_source.set(INPUT.sourceXML);'. @@ -164,6 +176,24 @@ CLASS kernel_call_transformation IMPLEMENTATION. ENDMETHOD. + METHOD parse_options. + DATA lv_name TYPE string. + DATA lv_value TYPE string. + + FIELD-SYMBOLS TYPE string. + + + WRITE '@KERNEL for (const name in INPUT.options || {}) {'. + WRITE '@KERNEL lv_name.set(name);'. + WRITE '@KERNEL lv_value.set(INPUT.options[name]);'. + ASSIGN COMPONENT lv_name OF STRUCTURE ms_options TO . + IF sy-subrc = 0. + = lv_value. + ENDIF. + WRITE '@KERNEL }'. + + ENDMETHOD. + METHOD traverse_write_type. DATA lo_type TYPE REF TO cl_abap_typedescr. lo_type = cl_abap_typedescr=>describe_by_data( iv_ref->* ). From 12f7426a0dffe8624ba9c17968ef9678d0423618 Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Mon, 25 Dec 2023 11:58:27 +0100 Subject: [PATCH 3/7] more --- .../kernel_call_transformation.clas.abap | 21 ++++++++++++------- ...l_call_transformation.clas.locals_imp.abap | 11 +++++++--- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/kernel/call_transformation/kernel_call_transformation.clas.abap b/src/kernel/call_transformation/kernel_call_transformation.clas.abap index 45fbb682..b19bd836 100644 --- a/src/kernel/call_transformation/kernel_call_transformation.clas.abap +++ b/src/kernel/call_transformation/kernel_call_transformation.clas.abap @@ -1,17 +1,22 @@ CLASS kernel_call_transformation DEFINITION PUBLIC. * handling of ABAP statement CALL TRANSFORMATION PUBLIC SECTION. + TYPES: BEGIN OF ty_options, + initial_components TYPE string, + END OF ty_options. + + CONSTANTS: BEGIN OF gc_options, + suppress TYPE string VALUE 'suppress', + END OF gc_options. + CLASS-METHODS call IMPORTING name TYPE any options TYPE any. PRIVATE SECTION. - CLASS-DATA mi_doc TYPE REF TO if_ixml_document. - CLASS-DATA mi_writer TYPE REF TO if_sxml_writer. - - CLASS-DATA: BEGIN OF ms_options, - initial_components TYPE string, - END OF ms_options. + CLASS-DATA mi_doc TYPE REF TO if_ixml_document. + CLASS-DATA mi_writer TYPE REF TO if_sxml_writer. + CLASS-DATA ms_options TYPE ty_options. CLASS-METHODS parse_xml IMPORTING @@ -103,7 +108,9 @@ CLASS kernel_call_transformation IMPLEMENTATION. WRITE '@KERNEL }'. IF lv_result = abap_true. lv_result = ''. - CREATE OBJECT lo_data_to_xml. + CREATE OBJECT lo_data_to_xml + EXPORTING + is_options = ms_options. WRITE '@KERNEL if (INPUT.source.constructor.name === "Object") {'. WRITE '@KERNEL for (const name in INPUT.source) {'. WRITE '@KERNEL lv_name.set(name);'. diff --git a/src/kernel/call_transformation/kernel_call_transformation.clas.locals_imp.abap b/src/kernel/call_transformation/kernel_call_transformation.clas.locals_imp.abap index 023de6f4..4420f345 100644 --- a/src/kernel/call_transformation/kernel_call_transformation.clas.locals_imp.abap +++ b/src/kernel/call_transformation/kernel_call_transformation.clas.locals_imp.abap @@ -10,14 +10,15 @@ CLASS lcl_heap DEFINITION. VALUE(rv_xml) TYPE string. PRIVATE SECTION. DATA mv_counter TYPE i. - DATA mv_data TYPE string. + DATA mv_data TYPE string. ENDCLASS. CLASS lcl_data_to_xml DEFINITION. PUBLIC SECTION. METHODS constructor IMPORTING - io_heap TYPE REF TO lcl_heap OPTIONAL. + is_options TYPE kernel_call_transformation=>ty_options OPTIONAL + io_heap TYPE REF TO lcl_heap OPTIONAL. METHODS run IMPORTING @@ -30,7 +31,8 @@ CLASS lcl_data_to_xml DEFINITION. RETURNING VALUE(rv_xml) TYPE string. PRIVATE SECTION. - DATA mo_heap TYPE REF TO lcl_heap. + DATA mo_heap TYPE REF TO lcl_heap. + DATA ms_options TYPE kernel_call_transformation=>ty_options. ENDCLASS. CLASS lcl_heap IMPLEMENTATION. @@ -110,6 +112,8 @@ CLASS lcl_data_to_xml IMPLEMENTATION. ELSE. mo_heap = io_heap. ENDIF. + + ms_options = is_options. ENDMETHOD. METHOD serialize_heap. @@ -127,6 +131,7 @@ CLASS lcl_data_to_xml IMPLEMENTATION. FIELD-SYMBOLS TYPE ANY TABLE. FIELD-SYMBOLS TYPE any. + lo_type = cl_abap_typedescr=>describe_by_data( iv_ref->* ). CASE lo_type->kind. From b7cf60a94ae096306d0ac95eae10be99d85f4026 Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Mon, 25 Dec 2023 12:00:45 +0100 Subject: [PATCH 4/7] first test running --- .../kernel_call_transformation.clas.locals_imp.abap | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/kernel/call_transformation/kernel_call_transformation.clas.locals_imp.abap b/src/kernel/call_transformation/kernel_call_transformation.clas.locals_imp.abap index 4420f345..72039b18 100644 --- a/src/kernel/call_transformation/kernel_call_transformation.clas.locals_imp.abap +++ b/src/kernel/call_transformation/kernel_call_transformation.clas.locals_imp.abap @@ -139,6 +139,12 @@ CLASS lcl_data_to_xml IMPLEMENTATION. lo_struc ?= lo_type. lt_comps = lo_struc->get_components( ). ASSIGN iv_ref->* TO . + + IF ms_options-initial_components = kernel_call_transformation=>gc_options-suppress AND IS INITIAL. + rv_xml = rv_xml && |<{ iv_name }/>|. + RETURN. + ENDIF. + rv_xml = rv_xml && |<{ iv_name }>|. LOOP AT lt_comps INTO ls_compo. ASSIGN COMPONENT ls_compo-name OF STRUCTURE TO . From 0875a1130e3d24ec429be918ae2f77b6b520bc00 Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Mon, 25 Dec 2023 12:05:06 +0100 Subject: [PATCH 5/7] add testcase --- ...l_call_transformation.clas.locals_imp.abap | 4 ++++ ..._call_transformation.clas.testclasses.abap | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/kernel/call_transformation/kernel_call_transformation.clas.locals_imp.abap b/src/kernel/call_transformation/kernel_call_transformation.clas.locals_imp.abap index 72039b18..17796455 100644 --- a/src/kernel/call_transformation/kernel_call_transformation.clas.locals_imp.abap +++ b/src/kernel/call_transformation/kernel_call_transformation.clas.locals_imp.abap @@ -155,6 +155,10 @@ CLASS lcl_data_to_xml IMPLEMENTATION. ENDLOOP. rv_xml = rv_xml && ||. WHEN cl_abap_typedescr=>kind_elem. + IF ms_options-initial_components = kernel_call_transformation=>gc_options-suppress AND iv_ref->* IS INITIAL. + RETURN. + ENDIF. + IF lo_type->type_kind = cl_abap_typedescr=>typekind_string AND iv_ref->* IS INITIAL. rv_xml = rv_xml && |<{ iv_name }/>|. ELSE. diff --git a/src/kernel/call_transformation/kernel_call_transformation.clas.testclasses.abap b/src/kernel/call_transformation/kernel_call_transformation.clas.testclasses.abap index a78d24cb..8cbbd438 100644 --- a/src/kernel/call_transformation/kernel_call_transformation.clas.testclasses.abap +++ b/src/kernel/call_transformation/kernel_call_transformation.clas.testclasses.abap @@ -107,6 +107,7 @@ CLASS ltcl_call_transformation DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATI METHODS dynamic_source FOR TESTING RAISING cx_static_check. METHODS dynamic_source_ixml FOR TESTING RAISING cx_static_check. METHODS suppress1 FOR TESTING RAISING cx_static_check. + METHODS suppress2 FOR TESTING RAISING cx_static_check. ENDCLASS. CLASS ltcl_call_transformation IMPLEMENTATION. @@ -901,4 +902,26 @@ CLASS ltcl_call_transformation IMPLEMENTATION. ENDMETHOD. + METHOD suppress2. + + DATA: BEGIN OF ls_foo, + field1 TYPE i, + field2 TYPE i, + END OF ls_foo. + + DATA lv_xml TYPE string. + + ls_foo-field2 = 2. + + CALL TRANSFORMATION id + OPTIONS initial_components = 'suppress' + SOURCE foo = ls_foo + RESULT XML lv_xml. + + cl_abap_unit_assert=>assert_char_cp( + act = lv_xml + exp = '*2*' ). + + ENDMETHOD. + ENDCLASS. \ No newline at end of file From 114750446acaa3192ed82dc04095a7f10587b8ae Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Mon, 25 Dec 2023 12:10:18 +0100 Subject: [PATCH 6/7] add testcase --- ...el_call_transformation.clas.locals_imp.abap | 6 ++++++ ...l_call_transformation.clas.testclasses.abap | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/kernel/call_transformation/kernel_call_transformation.clas.locals_imp.abap b/src/kernel/call_transformation/kernel_call_transformation.clas.locals_imp.abap index 17796455..f9b26350 100644 --- a/src/kernel/call_transformation/kernel_call_transformation.clas.locals_imp.abap +++ b/src/kernel/call_transformation/kernel_call_transformation.clas.locals_imp.abap @@ -169,6 +169,12 @@ CLASS lcl_data_to_xml IMPLEMENTATION. ENDIF. WHEN cl_abap_typedescr=>kind_table. ASSIGN iv_ref->* TO
. + + IF ms_options-initial_components = kernel_call_transformation=>gc_options-suppress AND
IS INITIAL. + rv_xml = rv_xml && |<{ iv_name }/>|. + RETURN. + ENDIF. + rv_xml = rv_xml && |<{ iv_name }>|. LOOP AT
ASSIGNING . GET REFERENCE OF INTO lv_ref. diff --git a/src/kernel/call_transformation/kernel_call_transformation.clas.testclasses.abap b/src/kernel/call_transformation/kernel_call_transformation.clas.testclasses.abap index 8cbbd438..7048a95a 100644 --- a/src/kernel/call_transformation/kernel_call_transformation.clas.testclasses.abap +++ b/src/kernel/call_transformation/kernel_call_transformation.clas.testclasses.abap @@ -108,6 +108,7 @@ CLASS ltcl_call_transformation DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATI METHODS dynamic_source_ixml FOR TESTING RAISING cx_static_check. METHODS suppress1 FOR TESTING RAISING cx_static_check. METHODS suppress2 FOR TESTING RAISING cx_static_check. + METHODS suppress3 FOR TESTING RAISING cx_static_check. ENDCLASS. CLASS ltcl_call_transformation IMPLEMENTATION. @@ -924,4 +925,21 @@ CLASS ltcl_call_transformation IMPLEMENTATION. ENDMETHOD. + METHOD suppress3. + + DATA lt_foo TYPE STANDARD TABLE OF i WITH DEFAULT KEY. + DATA lv_xml TYPE string. + + + CALL TRANSFORMATION id + OPTIONS initial_components = 'suppress' + SOURCE foo = lt_foo + RESULT XML lv_xml. + + cl_abap_unit_assert=>assert_char_cp( + act = lv_xml + exp = '**' ). + + ENDMETHOD. + ENDCLASS. \ No newline at end of file From 289663397a9122cdac1bef3e9ef24c13fb36db1b Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Mon, 25 Dec 2023 12:10:59 +0100 Subject: [PATCH 7/7] add link --- .../call_transformation/kernel_call_transformation.clas.abap | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/kernel/call_transformation/kernel_call_transformation.clas.abap b/src/kernel/call_transformation/kernel_call_transformation.clas.abap index b19bd836..876976c2 100644 --- a/src/kernel/call_transformation/kernel_call_transformation.clas.abap +++ b/src/kernel/call_transformation/kernel_call_transformation.clas.abap @@ -184,6 +184,8 @@ CLASS kernel_call_transformation IMPLEMENTATION. ENDMETHOD. METHOD parse_options. +* https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapcall_transformation_options.htm + DATA lv_name TYPE string. DATA lv_value TYPE string.