Application Development and Automation 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: 
Read only

Dynamic internal table (created after values in second table colon )

k_gjergja
Participant
0 Likes
537

Hi ,

I need to create dynamic internal table. But not after different structure that can be passed as parameter. Selection is done on the role table

AGR_USER . In this table the field AGR-NAME holds the name of the role. The number of  existing roles is changing constantly. Most of the time the new ones are added.

I have to create report showing the list with user name in one colon and the other colons have the role name in the title . If a user is assigned to the role in the field of respective role a ‘ X’ is displayed.

The problem is how to create output table having the structure that depends on the content of the agr-user-agr-name colon.Each time when new role is added the rapport has to have new colon with the name of the role in the colon title.

Please advice

Chris

Hi ,

I need to create dynamic internal table. But not after different structure that can be passed as parameter. Selection is done on the role table

AGR_USER . In this table the field AGR-NAME holds the name of the role. The number of  existing roles is changing constantly. Most of the time the new ones are added.

I have to create report showing the list with user name in one colon and the other colons have the role name in the title . If a user is assigned to the role in the field of respective role a ‘ X’ is displayed.

The problem is how to create output table having the structure that depends on the content of the agr-user-agr-name colon.Each time when new role is added the rapport has to have new colon with the name of the role in the colon title.

Please advice

Chris

2 REPLIES 2
Read only

Former Member
0 Likes
476

Hi

You can try something like this (in order to create a table with dynamic colunm):

PARAMETERS: P_ROLE TYPE I. "Number of role

DATA: LR_VALUE_DESCR  TYPE REF TO CL_ABAP_ELEMDESCR, "Single element

       COMPONENT       TYPE CL_ABAP_STRUCTDESCR=>COMPONENT.

DATA: FIELD_LEN       TYPE I.

*

DATA: LT_COMPONENTS   TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE. "Field structure

DATA: TYPE_STRUCT     TYPE REF TO CL_ABAP_STRUCTDESCR.

DATA: TYPE_TAB        TYPE REF TO CL_ABAP_TABLEDESCR.

*

DATA: DYN_TAB         TYPE REF TO DATA.

FIELD-SYMBOLS: <FS_TAB> TYPE TABLE.

FIELD-SYMBOLS: <FS_WA> TYPE ANY.

*

DATA: FIELD_INDEX(4)   TYPE N.

DO P_ROLE TIMES.

* Create single field:

     MOVE SY-INDEX TO FIELD_INDEX.

* Name:

     CONCATENATE 'AGR_NAME' FIELD_INDEX INTO COMPONENT-NAME.

* Type C

     MOVE CL_ABAP_ELEMDESCR=>GET_C( P_LENGTH = 30 )

       TO LR_VALUE_DESCR.

*

     COMPONENT-TYPE = LR_VALUE_DESCR.

     INSERT COMPONENT INTO TABLE LT_COMPONENTS.

   ENDDO.

* Define a structure dynamically:

   TYPE_STRUCT = CL_ABAP_STRUCTDESCR=>CREATE( P_COMPONENTS = LT_COMPONENTS

                                          P_STRICT     = 'X' ).

* Define an internal table based on structure

   TYPE_TAB = CL_ABAP_TABLEDESCR=>CREATE( P_LINE_TYPE = TYPE_STRUCT ).

* Create table

   CREATE DATA DYN_TAB TYPE HANDLE TYPE_TAB.

   ASSIGN DYN_TAB->* TO <FS_TAB>.

Max


Read only

Former Member
0 Likes
476

This topic has been addressed in many posts. Please do some research. Here is an example: http://wiki.sdn.sap.com/wiki/display/Snippets/Dynamic+Internal+Table