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: 

alv grid colon names

k_gjergja
Participant
0 Kudos

Hello ,

I have to write a rapport with  'REUSE_ALV_GRID_DISPLAY'  fm . The list has to show all users and the roles that are assigned to each of them .

The list has to look something like below

User   | role_A  | role_b |  role_123 | role_54 | role_11 |  role_56 |

user1      X             X                           X                           X

user2                               X

user3             X                                          X

I have to pick all roles from system ( agr_define) and use their names as a colon name . Please can someone explain how I can transfer each value from

table to column name  of internal table that will be displayed .

Thanks

Chris

Moderator message: Not enough research before posting. Please refer to concept dynamic internal tables.

Message was edited by: Kesavadas Thekkillath

1 REPLY 1

Former Member
0 Kudos

Hi,

Do something like this.

Create a dynamic internal table to hold the values.

FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,  “ Dynamic internal table name

               <fs_dyntable>,                     “ Field symbol to create work area

               <fs_fldval> type any.              “ Field symbol to assign values

DATA:   t_newtable TYPE REF TO data,

        t_newline  TYPE REF TO data,

        t_fldcat   TYPE slis_t_fldcat_alv,

        t_fldcat   TYPE lvc_t_fcat,

        wa_it_fldcat TYPE lvc_s_fcat,

        wa_colno(2) TYPE n,

        wa_flname(5) TYPE c.


    wa_it_fldcat-fieldname = 'USR'. " Add the User field first

    wa_it_fldcat-datatype = 'CHAR'.

    wa_it_fldcat-intlen = 12.

    APPEND wa_it_fldcat TO t_fldcat.

LOOP AT gt_agr_define INTO wa. " Add roles to the internal table structure

wa_it_fldcat-fieldname = wa-agr_name.

wa_it_fldcat-datatype = 'CHAR'.

wa_it_fldcat-intlen = 1.

READ TABLE t_fldcat WITH KEY fieldname = wa-agr_name TRANSPORTING NO FIELDS.

IF sy-subrc  NE 0.

APPEND wa_it_fldcat TO t_fldcat.

ENDIF.

ENDLOOP.

CALL METHOD cl_alv_table_create=>create_dynamic_table

    EXPORTING

      it_fieldcatalog = t_fldcat

    IMPORTING

      ep_table        = t_newtable.

  ASSIGN t_newtable->* TO <t_dyntable>.  " Dynamic internal table

* Create dynamic work area and assign to FS

  CREATE DATA t_newline LIKE LINE OF <t_dyntable>.

  ASSIGN t_newline->* TO <fs_dyntable> " This is your dynamic work area.

* Filling Data to the new dynamic table

LOOP AT gt_agr_define INTO wa.

ASSIGN COMPONENT wa-agr_name OF STRUCTURE <fs_dyntable> TO <fs_fldval>.

IF sy-subrc = 0.

<fs_fldval> = 'X'.

ENDIF.

ENDLOOP.

You will need to work with this as base and modify accordingly.

This may have syntax errors, because I dont have access to SAP now.

Thanks,

Shambu