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: 

length (tabledescr,structdescr)

Arslan1
Explorer
0 Kudos

Hi, I was able to print the column headers and types, but I could not print the length parameter, can you help me? I am leaving the final version of the code below.

 

DATA(lr_tabledescr) = CAST cl_abap_tabledescr( cl_abap_typedescr=>describe_by_data( lt_analok ) ).
DATA(lr_structdescr) = CAST cl_abap_structdescr( lr_tabledescr->get_table_line_type( ) ).

DATA(sutun_basliklari) = VALUE fieldname_tab( FOR ls IN lr_structdescr->components ( ls-name ) ).
DATA(sutun_type) = VALUE fieldname_tab( FOR ls IN lr_structdescr->components ( ls-type_kind ) ).
data(leng) = VALUE fieldname_tab( FOR ls IN lr_structdescr->components ( ls-length ) ).

DATA index TYPE i.
index = 1.

LOOP AT sutun_basliklari INTO DATA(ls_st).
  WRITE: / index,   ' ' ,  ls_st, ' ' , sutun_type[ index ]  , ' '  .
  index = index + 1.
ENDLOOP.


cl_demo_output=>display( ).

 

3 REPLIES 3

Sandra_Rossi
Active Contributor
0 Kudos

Your internal table LENG contains the lengths of all components. Basically, it works. So what is your actual problem?

"LS-LENGTH" and the row type of "LENG" are incompatible. Can you help me get an error?

Sandra_Rossi
Active Contributor
0 Kudos

So, you have the error

"LS-LENGTH" and the row type of "LENG" are incompatible.

at this line:

data(leng) = VALUE fieldname_tab( FOR ls IN lr_structdescr->components ( ls-length ) ).

You have defined LENG of type FIELDNAME_TAB, so it's an internal table with all lines of type 30 characters, and you're trying to initialize each line with LS-LENGTH which is numeric.

So you have to CONVERT the number to string, it has been asked hundreds of times in the forum as I can see by searching

abap convert number to character site:sap.com

Now, I doubt that you want LENG to be an internal table of field names, you probably want it to be an internal table of integers, here is how to declare a complete table type which you can use to declare LENG:

TYPES ty_integers TYPE STANDARD TABLE OF i WITH EMPTY KEY.