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: 

How to create table type field in dynamic internal table

Former Member
0 Kudos

we can create simple field of any abap type in the dynamic internal table but

i have requirement from user that hot spot will be  on specific cell not on entire column so i need to create one field which has the table type  "lvc_t_styl"

so how to create table type field which has the type lvc_t_styl  so i can achieve my requirement ?

please guide ......

9 REPLIES 9

vinoth_aruldass
Contributor
0 Kudos

hi,

in dynamic internal table you cannot specify the lvc_t_styl . you have to define the structure separately and process it for single field.

Regards,

vinoth

0 Kudos

vinoth aruldass wrote:

in dynamic internal table you cannot specify the lvc_t_styl .

IMO i think this is not correct. As has mentioned you can create the dynamic structure (and then internal table) using RTTI classes.

BR,

Suhas

reachdebopriya
Active Participant
0 Kudos

Hi Vijay,

Try this code.... It is an example. Do according to the below code. It will work.

*----------------------------------------------------------------------*

*       CLASS respond_events DEFINITION

*----------------------------------------------------------------------*

*

*----------------------------------------------------------------------*

CLASS respond_events DEFINITION FINAL .

  PUBLIC SECTION .

    METHODS : respond_hotspot_click FOR EVENT hotspot_click

              OF cl_gui_alv_grid

                IMPORTING e_row_id.

ENDCLASS .                    "respond_events definition

*----------------------------------------------------------------------*

*       CLASS respond_events IMPLEMENTATION

*----------------------------------------------------------------------*

* Implementation of the custom class for hotspot

*----------------------------------------------------------------------*

CLASS respond_events IMPLEMENTATION .

  METHOD respond_hotspot_click  .
    CLEAR gs_final.
    READ TABLE gt_final INTO gs_final INDEX e_row_id .
    IF sy-subrc EQ 0 .
      SET PARAMETER ID 'TNR' FIELD gs_final-tknum.
      CALL TRANSACTION 'VT03N' AND SKIP FIRST SCREEN .
    ENDIF .
  ENDMETHOD .            "respond_hotspot_click

ENDCLASS .               "respond_events implementation

DATA: glr_respond_events TYPE REF TO respond_events  .

In PBO

*-- Create grid with defaule container type object

    CREATE OBJECT gr_grid

      EXPORTING

        i_parent = cl_gui_container=>default_screen.

    CREATE OBJECT glr_respond_events.

    CALL METHOD gr_grid->set_table_for_first_display

      EXPORTING

        is_variant           = gs_variant

        i_save               = lc_a

        is_layout            = gs_layout

        it_toolbar_excluding = gt_exclude

      CHANGING

        it_outtab            = gt_final[]

        it_fieldcatalog      = gt_fieldcat[].

    SET HANDLER glr_respond_events->respond_hotspot_click FOR gr_grid.

Regards,

Debopriya Ghosh

0 Kudos

thank you,

but this will display hotspot on entire column not for specific cell,

i want hotspot only for some specific cell which satisfy some condition.

0 Kudos

This code is for static cases irrelevant here

mangesh_sonawane
Participant
0 Kudos

Hi ,

U can use field symbols for dynamic create internal table type.

Field-Symbols : <fs_tab> type Any /table.

Regards,

Mangesh Sonawane

Former Member
0 Kudos

Hi,

You just need to define a structure with your static fields (or only your field that will handle styles if all fields have to be dynamic), and then use RTTS classes to build the final table...

You should find plenty of sample here on how to achieve this!

Cheers,

Manu.

Former Member
0 Kudos

Yes at run time u can dynamically create a table type no problem but then u need to craete a table type

with lvc_t_styl..

Now I can not see how RTTS classes can help no ways

0 Kudos

Hi there,

Now I can not see how RTTS classes can help no ways

Ok, so let me show you how

* Structure for dynamic table creation (fixed fields)

TYPES: BEGIN OF ts_data,

                key1 TYPE c,

                data TYPE string,   

                t_styl TYPE lvc_t_styl,

              END OF ts_data.

DATA:

    l_sdescr       TYPE REF TO cl_abap_structdescr,

    l_sdescr_new   TYPE REF TO cl_abap_structdescr,

    l_tdescr       TYPE REF TO cl_abap_tabledescr,

    l_handle       TYPE REF TO data,

    l_component    TYPE abap_compdescr,

    ls_comp        TYPE abap_componentdescr,

    lt_components  TYPE abap_component_tab,

FIELD-SYMBOLS: <t_data> TYPE ANY TABLE,

                               <data> TYPE ANY.

  l_sdescr ?= cl_abap_typedescr=>describe_by_name( 'TS_DATA' ).

* Get all fixed components
  LOOP AT l_sdescr->components INTO l_component.
    ls_comp-type = l_sdescr->get_component_type( l_component-name ).
    ls_comp-name = l_component-name.
    APPEND ls_comp TO lt_components.

  ENDLOOP.

* Add the dynamic fields

* ...

  ls_comp-name = 'DYN1'.

  ls_comp-type = cl_abap_elemdescr=>get_string( ).

  APPEND ls_comp TO lt_components.

* ...

  ls_comp-name = 'DYN2'.

  ls_comp-type = cl_abap_elemdescr=>get_i( ).

  APPEND ls_comp TO lt_components.

* Create the dynamic table and header

  l_sdescr_new  = cl_abap_structdescr=>create( lt_components ).

  l_tdescr      = cl_abap_tabledescr=>create( l_sdescr_new ).

  CREATE DATA l_handle TYPE HANDLE l_tdescr.
  ASSIGN l_handle->* TO <t_data>.

  CREATE DATA l_handle TYPE HANDLE l_sdescr_new.
  ASSIGN l_handle->* TO <data>.

Cheers,

Manu.