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: 

Table Type in cl_alv_table_create=>create_dynamic_table

ionut
Explorer
0 Kudos

Hi guys,

The method create_dynamic_table from  cl_alv_table_create has as exporting parameter a fielcatalog table. I want to insert a table type in this table, basically the field INTTYPE from LVC_S_FCAT can do that if u put the value 'h' in it. But I notice, that in method implementations all the cases are considered:

CCharacter String
NCharacter String with Digits Only
DDate (Date: YYYYMMDD)
TTime (Time: HHMMSS)
XByte Sequence (heXadecimal)
IInteger number (4-byte integer with sign)
b1-byte integer, integer number <= 254
s2-byte integer, only for length field before LCHR or LRAW
PPacked number
FFloating point number to accuracy of 8 bytes

and other, but not 'h'.

Does anybody knows how create a dynamic table with a table type inside ? The table type has the structure from data dictionary  lvc_t_scol.

Ionut.

1 ACCEPTED SOLUTION

former_member202818
Active Contributor
0 Kudos

Hi Ionut,

I had come across such a requirement recently, My requirement was to add a cell coloring field(type internal table) for ALV.

I solved this by the below code.. This is very easy....

CLEAR gwa_fldcat_2.

gwa_fldcat_2-fieldname = 'TCOLOR'.

gwa_fldcat_2-tech      = abap_true.                  " Technical Field

gwa_fldcat_2-ref_field = 'SCOL'.                  " A Field in /BEV2/ED_DETAILS_MATBEL_ALV.SCOL type LVC_T_SCOL(Table Type).

gwa_fldcat_2-ref_table = '/BEV2/ED_DETAILS_MATBEL_ALV'. " A Structure

APPEND gwa_fldcat_2 TO git_fldcat_2.

The Field  TCOLOR accrue the type of field SCOL in /BEV2/ED_DETAILS_MATBEL_ALV.

Regards

Sreekanth

14 REPLIES 14

SharathSYM
Contributor
0 Kudos

Alternate & better option to create dynamic table is using RTTS class, search for the class cl_abap_tabledescr in SCN you will find many documents.

Thanks,

Sharath

0 Kudos

Hi,

I search in SCN but I didn't find nothing like that, in fact, I found a similar question with no answer.

I use cl_abap_tabledescr. This is the code and it is working.:

FORM create_dynamic_tables USING wa.

   DATA: ref_table_des    TYPE REF TO cl_abap_structdescr,

         ref_table_alv    TYPE REF TO cl_abap_structdescr,

         lt_details       TYPE abap_compdescr_tab,

         ls_field_catalog TYPE lvc_s_fcat,

         ls_details       TYPE abap_compdescr,

         ls_dynline       TYPE REF TO data,

         lt_dyntable      TYPE REF TO data,

         l_tabix          TYPE i,

         l_tabix_cf       TYPE i,

         l_tabname        TYPE dd03l-tabname,

         l_decimals       TYPE dd03l-decimals,

         l_intlen         TYPE dd03l-intlen.

   REFRESH lt_details.

   ref_table_alv ?=

   cl_abap_typedescr=>describe_by_data( wa ).

   lt_details[] = ref_table_alv->components[].

   CLEAR l_tabix.

   LOOP AT lt_details INTO ls_details.

     CLEAR ls_field_catalog.

     ADD 1 TO l_tabix.

     CLEAR ls_field_catalog.

     MOVE: ls_details-name      TO ls_field_catalog-fieldname,

           ls_details-type_kind TO ls_field_catalog-inttype,

           ls_details-decimals  TO ls_field_catalog-decimals,

           ls_details-length    TO ls_field_catalog-dd_outlen.

     CASE ls_details-name.

       WHEN 'PASTRTERM' OR 'PAENDTERM' OR 'ENSTEHDAT'

         OR 'PRUEFLOS' OR 'LOSMENGE' OR 'MENGENEINH'

         OR 'ART' OR 'HERKUNFT' OR 'SLWBEZ'

         OR 'MATNR' OR 'SELWERKS' OR 'CHARG'

         OR 'KTEXTLOS' OR 'KTEXTMAT' OR 'SELWERK'.

         MOVE 'QALS' TO: l_tabname,

                         ls_field_catalog-tabname.

         PERFORM select_text USING ls_field_catalog-scrtext_s

                                   ls_field_catalog-scrtext_m

                                   ls_field_catalog-scrtext_l

                                   ls_field_catalog-reptext

                                   ls_field_catalog-rollname

                                   ls_field_catalog-domname

                                   l_tabname

                                   ls_details-name.


.....

......

ENDCASE.

     MOVE l_tabix TO ls_field_catalog-col_pos.

     ls_field_catalog-no_merging = ''.

     APPEND ls_field_catalog TO gt_alv_s_fcat.


ENDLOOP.

   CALL METHOD cl_alv_table_create=>create_dynamic_table

     EXPORTING

       it_fieldcatalog = gt_alv_s_fcat

     IMPORTING

       ep_table        = gt_dyntab.

   ASSIGN gt_dyntab->* TO <dyn_table_output>.

   CREATE DATA ls_dynline LIKE LINE OF <dyn_table_output>.

   ASSIGN ls_dynline->* TO <dyn_wa_output>.


Now, i want to put a table type in <dyn_table_output>..


Ionut.

0 Kudos

cl_alv_table_create=>create_dynamic_table( ) is no longer recommended to build dynamic tables.

RTTC classes are very intuitive and quite easy to maintain.

  1. DATA:
  2.       gt_struct_fields TYPE cl_abap_structdescr=>component_table,
  3.       gwa_struct_field TYPE cl_abap_structdescr=>component.
  4. DATA:
  5.       goref_table TYPE REF TO cl_abap_tabledescr,
  6.       gdref_table TYPE REF TO data.
  7. FIELD-SYMBOLS <gt_dynamic> TYPE STANDARD TABLE.
  8. TRY.
  9. *   f1 TYPE c LENGTH 10
  10.     gwa_struct_field-name = `F1`.
  11.     gwa_struct_field-type = cl_abap_elemdescr=>get_c( 10 ).
  12.     APPEND gwa_struct_field TO gt_struct_fields.
  13.     CLEAR gwa_struct_field.
  14. *   f2 TYPE bukrs
  15.     gwa_struct_field-name = `F2`.
  16.     gwa_struct_field-type ?= cl_abap_typedescr=>describe_by_name( `BUKRS` ).
  17.     APPEND gwa_struct_field TO gt_struct_fields.
  18.     CLEAR gwa_struct_field.
  19. *   f3 TYPE flighttab
  20.     gwa_struct_field-name = `F3`.
  21.     gwa_struct_field-type ?= cl_abap_typedescr=>describe_by_name( `FLIGHTTAB` ).
  22.     APPEND gwa_struct_field TO gt_struct_fields.
  23.     CLEAR gwa_struct_field.
  24. *   Use the structure object to build the table
  25.     goref_table = cl_abap_tabledescr=>get(
  26.                   cl_abap_structdescr=>get( gt_struct_fields )
  27.                   ).
  28.     CREATE DATA gdref_table TYPE HANDLE goref_table.
  29.     ASSIGN gdref_table->* TO <gt_dynamic>.
  30.   CATCH ##no_handler
  31.     cx_sy_struct_creation
  32.     cx_parameter_invalid_range
  33.     cx_sy_table_creation.
  34. ENDTRY.

BR,

Suhas

0 Kudos

In staid of gwa_struct_field-type = cl_abap_elemdescr=>get_c( 10 ).

I need gwa_struct_field-type = cl_abap_elemdescr=>get_h ????.

I now that I can create with CL_ABAP_STRUCTDESCR=>CREATE ( ... ) but how I insert a table type ? Not a char of 10 ?

I know this cases:

*      WHEN 'STRING'.  ls_typ = cl_abap_elemdescr=>get_string( ).

*      WHEN 'XSTRING'. ls_typ = cl_abap_elemdescr=>get_xstring( ).

*      WHEN 'I'.       ls_typ = cl_abap_elemdescr=>get_i( ).

*      WHEN 'F'.       ls_typ = cl_abap_elemdescr=>get_f( ).

*      WHEN 'D'.       ls_typ = cl_abap_elemdescr=>get_d( ).

*      WHEN 'T'.       ls_typ = cl_abap_elemdescr=>get_t(  ).

*      WHEN 'C'.       ls_typ = cl_abap_elemdescr=>get_c( p_length = ls_details-length ).

*      WHEN 'N'.       ls_typ = cl_abap_elemdescr=>get_n( p_length = ls_details-length ).

*      WHEN 'X'.       ls_typ = cl_abap_elemdescr=>get_x( p_length = ls_details-length ).

*      WHEN 'P'.       ls_typ = cl_abap_elemdescr=>get_p( p_length = ls_details-length p_decimals = ls_details-decimals ).


Where is table type ?

Ionut.

0 Kudos

That is what i have mentioned:


*   f3 TYPE flighttab

    gwa_struct_field-name = `F3`.

    gwa_struct_field-type ?= cl_abap_typedescr=>describe_by_name( `FLIGHTTAB` ).

    APPEND gwa_struct_field TO gt_struct_fields.

    CLEAR gwa_struct_field.

FLIGHTTAB is a table type. Did you even see it?

0 Kudos

Hi,

31.*   Use the structure object to build the table
32.    goref_table = cl_abap_tabledescr=>get(
33.                  cl_abap_structdescr=>get( gt_struct_fields )
34.                  ).

On what release are you ?

I am using cl_abap_tabledescr=>create 

Regards.

0 Kudos

On what release are you ?

I am working with ABAP release 740 (SP02).

The GET( ) methods have been part of the ABAP release 7.0 EhP2 - ABAP Keyword Documentation .

If you are on the relevant ABAP release then i think you should use GET( ) and not CREATE( ). Here's the reason why - .

BR,

Suhas

0 Kudos

Hi,

I am not there yet .

I do have a question:

DATA: it_component TYPE abap_component_tab .
DATA: st_component LIKE LINE OF it_component .

st_component-name = 'PAYMENTSUM'.
st_component-type ?= cl_abap_elemdescr=>describe_by_name( 'S_SUM' ).

* I like the headings... 
* Is it possible at this point to change the length of the field ?
 
APPEND st_component TO it_component .

Regards.

0 Kudos

Hello Eitan,

Sorry for the late reply


* I like the headings... 

* Is it possible at this point to change the length of the field ?

I don't understand what do you mean? Can you please explain in detail?

BR,

Suhas

0 Kudos

Hi,

Some time ago I wrote this program http://scn.sap.com/community/abap/blog/2013/12/26/sdbadbc--the-program

that utilize cl_sql_connection and the rest of the gang .

In this program I used cl_alv_table_create=>create_dynamic_table .

Now I want to move to RTTS.

Since I am using lvc_s_fcat I was able to increase the field size when using SQL sum function.

The original definition of "Weight of Luggage" (S_LUGWEIGH) is quite small to be a target of sum but using this trick I can have this:


How I can do this with RTTS ? I want to modify the result of cl_abap_elemdescr=>describe_by_name( 'S_LUGWEIGH' ).

Regards.

0 Kudos

Ahh, gotcha.

I think you can change the value of the attribute LENGTH for "S_LUGWEIGH" RTTI object. I have never tried it, but worth a shot!

The attribute is public, read-only so cannot be changed. My bad

BR,

Suhas

0 Kudos

Thanks.

Best regard.

Eitan

former_member202818
Active Contributor
0 Kudos

Hi Ionut,

I had come across such a requirement recently, My requirement was to add a cell coloring field(type internal table) for ALV.

I solved this by the below code.. This is very easy....

CLEAR gwa_fldcat_2.

gwa_fldcat_2-fieldname = 'TCOLOR'.

gwa_fldcat_2-tech      = abap_true.                  " Technical Field

gwa_fldcat_2-ref_field = 'SCOL'.                  " A Field in /BEV2/ED_DETAILS_MATBEL_ALV.SCOL type LVC_T_SCOL(Table Type).

gwa_fldcat_2-ref_table = '/BEV2/ED_DETAILS_MATBEL_ALV'. " A Structure

APPEND gwa_fldcat_2 TO git_fldcat_2.

The Field  TCOLOR accrue the type of field SCOL in /BEV2/ED_DETAILS_MATBEL_ALV.

Regards

Sreekanth

0 Kudos

Thanks a lot.