2012 Sep 28 1:50 PM
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
2012 Sep 28 2:22 PM
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
2012 Sep 28 4:18 PM
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
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |