Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
Showing results for 
Search instead for 
Did you mean: 

Deep structure having field name with '-'

0 Kudos

Hi Guys,

I have a requirement to created deep structure (JSON to external system) like below :

Body: { "name" : "user id",

"email" : "email address",

"description" : "user display name",

"remote-name" : "id in the remote system",

"screen-reader" : "true/false",

"roles" : [ "role1", "role2", ...] }

SAP does not allow to '-' in the field name, I was able to create dynamic internal table with field names having '-' using cl_alv_table_create=>create_dynamic_table but not sure how create a deep structure to add "roles".

Please guide.



Active Contributor

It's bad practice to use cl_alv_table_create=>create_dynamic_table as explained here: Alternative to CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE | SAP Blogs.

For information, dynamic variable creation should use RTTS, creating variables with "-" is supported only if CREATE is called with P_STRICT = abap_false.

Better use /UI2/CL_JSON. There's built-in dynamic creation (not sure how to handle both dynamic creation and names containing "-").

0 Kudos

Thanks Sandra for your inputs.

I will able to create dynamic_table using RTTS with field name '-' and then added a similar code below to create a deep structure.

2.1 Creating the Deep strcuture field

DATA: lo_tab TYPE REF TO cl_abap_tabledescr.


lo_tab ?= cl_abap_typedescr=>describe_by_name( 'LVC_T_SCOL' ).

la_comp-name = 'COLOR_TAB'.

la_comp-type = lo_tab.

APPEND la_comp TO lt_tot_comp.

CLEAR: la_comp.

Active Contributor
0 Kudos

Just to complete my previous comment, these are the lines which I was referring to, in my blog post:

        lp_struc_descr = cl_abap_structdescr=>create(
                          p_components = lt_comp
                          p_strict     = ' ' ).

As you can see, it's p_strict = ' ' so the class is ready for supporting names with a dash/hyphen.