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.
cancel
Showing results for 
Search instead for 
Did you mean: 

Deep structure having field name with '-'

johnmjd
Explorer
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.

Thanks!

3 REPLIES 3

Sandra_Rossi
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 "-").

johnmjd
Explorer
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.

Sandra_Rossi
Active Contributor
0 Kudos

Just to complete my previous comment, these are the lines which I was referring to, in my blog post: https://github.com/sandraros/ZCL_ALV_TABLE_CREATE_RTTC/blob/4fe1113b091fe3b2b29114a3bb59bdbdb57765ef...:

        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.