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 column based on the input

Former Member
0 Likes
1,665

Hi ,

I need to have dynamic column based on the given input . for eg if i give 3 as input then it should give me 3 column as the out put . Can any one solve it .

Regards

Abeehs

6 REPLIES 6
Read only

Sm1tje
Active Contributor
0 Likes
1,124

A lot of people can probably be of some help, but you do need to be a bit more specific.

1. Does your output (internal table for example), have a variable number of columns?

2. which columns need to be output, the first three, or just 3 random columns?

3. Is your output an ALV?

4. etc. etc.

In case of ALV for example it will be quite easy to set the number of columns to be output to 3.

Read only

Former Member
0 Likes
1,124

You can pass the selection screen parameter as (no. of coulumns) in brackets '()' to the variable which holds no. of columns.

It would automatically take the dynamic no. of columns entered.

Read only

Former Member
0 Likes
1,124

Hi,

Basically i suppose you mean that your internal table will be dynamic.

There are a lot of posts in SDN on how to create in internal table dynamically.

Basically you will have to make use of method CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE .

You will have to create a fieldcatalog which will contain details about the columns which you will need and that will help you in creating the dynamic internal table.

Regards,

Ankur Parab

Read only

Former Member
0 Likes
1,124

Hi all,

Thanks for ur reply ..

My task to display the column dynamically based on the user input given in the parameter for eg . Consider a parameter . the user enter the value 5 . Then it has to show 5 columns as out put how to solve it

Read only

0 Likes
1,124

But do you also have a dynamic table? In other words, is the number of columns of your internal table FIXED or not?

1. If FIXED, use the ALV grid as output, in which you can enter a column of the field catalog and set the NO_OUT to 'X' (column is not output).

2. If dynamic number of columns, just provide only those columns to your method corresponding to the number of columns to be output.

Again, you need to be a bit more specific about your requirement.

Read only

Former Member
0 Likes
1,124

Hi ,

You need to use FIELD-SYMBOLS to dynamically assign the columns.

Check the sample code -

PARAMETERS : P_ABC TYPE I.

FIELD-SYMBOLS : <FIELD> TYPE ANY.

TABLES : SCARR.

DATA : T_SCARR TYPE TABLE OF SCARR.
SELECT * FROM SCARR INTO TABLE T_SCARR.
LOOP AT T_SCARR INTO SCARR.
  DO P_ABC TIMES.
    ASSIGN COMPONENT SY-INDEX OF STRUCTURE SCARR TO <FIELD>.
    WRITE : <FIELD>.
  ENDDO.
  NEW-LINE.
ENDLOOP.

Note : Here I have displayed the columns of SCARR as an example.

Regards

Pinaki