cancel
Showing results for 
Search instead for 
Did you mean: 

Join Internal table column headers separated by #(tab)?

sh4il3sh
Participant
0 Kudos

Hello Experts,

I have an internal table which is of Dynamic Type created as below:


METHOD BUILD_LOG:
FIELD-SYMBOLS: <lt_tabinput> TYPE ANY TABLE.
ASSIGN (iv_tabname) TO <lt_tabinput>. "iv_taname is importing param of method.
ENDMETHOD.

above makes <lt_tabinput> like GT_GENERAL (which is global table in class)

and looks like:



I want to create a string line which goes like:
FLGDEFAULT_ADR12#URI_ADDR#URI_TYPE#TELNR_LONG#COUNTRY_ADR2#R3_USER#DFT_RECEIV

I tried utilising DDIF_FIELDINFO_GET but entered into a runtime error because I think this internal table doesn't relate to any repository object?

Need some advice to achieve this or I'll have to rewrite lots of logic.

Regards,
Shailesh

Sandra_Rossi
Active Contributor

To create dynamically or read type descriptions of ABAP data objects (variables, internal tables, etc.) at runtime, use Run Time Type Services (RTTS) = cl_abap_typedescr and so on.

Accepted Solutions (1)

Accepted Solutions (1)

raymond_giuseppi
Active Contributor

Did you try to use some RTS class such as CL_ABAP_TABLEDESCR or CL_ABAP_STRUCTDESCR and not DDIC FM to get information on table / structure?

sh4il3sh
Participant
0 Kudos

@Raymond.giuseppi
Thanks, I was looking into this but many methods and superclass methods intimidated me with no documentation in class.

on a side node, could you pls clarify below for me?:
why is there a ?= for this, normal ways don't work? what's so special about '?=' ?

if I use = instead of ?=, I get warning message as "The result type of the functional method cannot be converted into the type of LO_TABLEDESCR".

"My Way and it works
DATA(lt_type) = cl_abap_tabledescr=>describe_by_data( <lt_tabinput> ).

"Code in where used list and this works too:
DATA lo_tabledescr TYPE REF TO cl_abap_tabledescr.
lo_tabledescr ?= cl_abap_tabledescr=>describe_by_data( <lt_tabinput> ).
"Gives Error: The result type of the functional method cannot be converted into the type of LO_TABLEDESCR.
DATA blo_tabledescr TYPE REF TO cl_abap_tabledescr.
blo_tabledescr = cl_abap_tabledescr=>describe_by_data( <lt_tabinput> ).

raymond_giuseppi
Active Contributor

Check class & methods definitions;

Basically CL_ABAP_TABLEDESCR->DESCRIBE_BY_DATA returns a 'generic' CL_ABAP_TYPEDESCR type data.

  • sub-class CL_ABAP_TABLEDESCR superclass is CL_ABAP_COMPLEXDESCR
  • sub-class CL_ABAP_COMPLEXDESCR superclass is CL_ABAP_DATADESCR
  • sub-class CL_ABAP_DATADESCR superclass is CL_ABAP_TYPEDESCR

So the ?= downcast (also widening cast) operator assign the specific sub-class variable to a more general superclass variable (like truck class to vehicle class in Abap course)

Answers (1)

Answers (1)

jack_graus2
Active Contributor
lv_string = REDUCE #(
  INIT lv_tabinput = ``
  FOR <ls_component> IN 
    CAST cl_abap_structdescr(
      CAST cl_abap_tabledescr(
        cl_abap_tabledescr=>describe_by_data( <lt_tabinput> ) )->get_table_line_type( )
      )->get_components( )
  INDEX INTO lv_index
  NEXT lv_tabinput &&= COND #( WHEN lv_index GT 1 THEN `#` ) && <ls_component>-name ).
sh4il3sh
Participant
0 Kudos

WOW! Amazing.
I didnt know we could cast inside FOR LOOP.
new syntax is beautiful, gotta share this with my peers.

haha, I had a solo loop running over get_table_line_type( )-component.