Personal Insights
JSON2ABAPType – thank you for contribution
Some time ago I’ve posted on github a code of the program which helps to create an ABAP type on a base of JSON structure. Such program is very useful when you work with web-services or web-hooks, as you can automate the creation of the types for your coding. The program you can install using abapGIT and git repository found at https://github.com/fidley/JSON2ABAPType.
But I do not write this post to let you know about this program, I write it because lately https://people.sap.com/marspark added some additional features to it, like keeping the original sequence of the fields, or keeping the parameters for the conversion always on the screen, making it more user friendly.
Such contributions to any of the code I’ve published so far, makes me feel really good and it’s even more enjoyable to see others contributing to your work, than publishing it yourself.
Thank you for your contribution https://people.sap.com/marspark and keep up good work!
Thumbs up for his work! This is one of the brief moments to see the future of the SAP ecosystem: crowdsourcing, open source and other things becoming more important. No one can master every technology, so we all need to work more together.
I cannot agree more!
Thank you, I am very honored. I also agree with the comment of Michael. An open ecosystem will be better, because it makes everyone easier to contribute their ideas and work.
You've deserved it!
Thanks for sharing, btw, I found a bug and try to impove it as below, the method should be consider the node level and sorting
METHOD create_types.
DATA: components TYPE string.
LOOP AT hierarchy ASSIGNING FIELD-SYMBOL(<h>).
IF <h>-structure EQ abap_true AND <h>-type NE 'g'.
<h>-final_type = |{ <h>-name } type t_{ <h>-name }{ <h>-id }|.
<h>-type_definition = |types: begin of t_{ <h>-name }{ <h>-id },{ cl_abap_char_utilities=>newline }{ c_components }end of t_{ <h>-name }{ <h>-id }.|.
ELSEIF <h>-structure EQ abap_true.
<h>-final_type = |{ <h>-name } type t_{ <h>-name }{ <h>-id }|.
get_internal_types( CHANGING c_type = <h> ).
<h>-type_definition = |types: t_{ <h>-name }{ <h>-id } type { <h>-absolute_type }.|.
ELSEIF <h>-table EQ abap_true.
<h>-final_type = |{ <h>-name } type tt_{ <h>-name }{ <h>-id }|.
<h>-type_definition = |types: tt_{ <h>-name }{ <h>-id } type standard table of t_{ <h>-name }{ <h>-id } with default key.|.
ELSE.
get_internal_types( CHANGING c_type = <h> ).
ENDIF.
ENDLOOP.
* LOOP AT hierarchy ASSIGNING <h> GROUP BY ( parent = <h>-parent ).
* CLEAR components.
* LOOP AT GROUP <h> ASSIGNING FIELD-SYMBOL(<g>).
* components = components && <g>-final_type && ',' && cl_abap_char_utilities=>newline.
* ENDLOOP.
* ASSIGN hierarchy[ absolute_type = <h>-parent ] TO FIELD-SYMBOL(<parent>).
* IF sy-subrc EQ 0.
* REPLACE ALL OCCURRENCES OF c_components IN <parent>-type_definition WITH components.
* ENDIF.
* ENDLOOP.
DATA(lt_hierarchy_parent) = hierarchy[].
LOOP AT hierarchy ASSIGNING <h> WHERE structure EQ abap_true
OR table EQ abap_true.
r_definition = r_definition && <h>-type_definition && cl_abap_char_utilities=>newline.
ENDLOOP.
ENDMETHOD.
Here my testing json
Thanks for the info!
Would you be so kind and create the pull request with the needed changes? https://github.com/fidley/JSON2ABAPType
Cheers
Łukasz
Opps..I'm afraid Im not able to pull the code into the github due to the network setting by our security team. Pulling above code or not, all depends on your own willing now, go ahead~ 🙂