‎2006 Nov 02 5:11 PM
Hello all,
I've gone through previous posts but i think what i want is different.
What i want is to create a dynamic internal table.
for example,
if on selection screen I enter 3, I should get and internal table with 3 columns and so on.
Input:-
p_input = 3.
Ouput:-
col1 col2 col3
Is this dynamic nature possible? If yes, how do I fill these 3 columns with data from some other internal table.
Thanks and Regards,
Anup
Message was edited by: Anup Deshpande
‎2006 Nov 02 6:16 PM
Hi,
DATA: re_head TYPE REF TO DATA.
FIELD-SYMBOLS: <gt_head>.
CREATE DATA re_head LIKE LINE OF <gt_table>.
ASSIGN re_head->* TO <gt_head>.
FIELD-SYMBOLS: <FS>.
LOOP AT ITAB.
ASSIGN COMPONENT SY-TABIX OF STRUCTURE <gt_head>
to <FS>.
<FS> = itab-item.
ENDLOOP.
APPEND <gt_head> to <gt_table>.
Thanks,
Naren
‎2006 Nov 02 5:30 PM
Hi,
Check this example..
PARAMETERS: p_input TYPE i OBLIGATORY.
START-OF-SELECTION.
DATA: v_fieldname TYPE char30.
DATA: v_char TYPE numc4.
DATA: it_fldcat TYPE lvc_t_fcat.
DATA: wa_it_fldcat LIKE LINE OF it_fldcat.
DATA: gp_table TYPE REF TO data.
FIELD-SYMBOLS: <gt_table> TYPE table.
DO p_input TIMES.
v_fieldname = 'COL'.
v_char = sy-index.
CONCATENATE v_fieldname v_char INTO v_fieldname.
CONDENSE v_fieldname.
CLEAR wa_it_fldcat.
wa_it_fldcat-fieldname = v_fieldname.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-outputlen = 5.
wa_it_fldcat-intlen = 5.
APPEND wa_it_fldcat TO it_fldcat .
ENDDO.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING it_fieldcatalog = it_fldcat
IMPORTING ep_table = gp_table.
ASSIGN gp_table->* TO <gt_table>.
CHECK sy-subrc = 0.
Thanks,
Naren
‎2006 Nov 02 5:34 PM
To follow up on Naren's solution, you will need to create a separate working area as the table created has no header. This can be done with:
DATA: re_head TYPE REF TO DATA.
FIELD-SYMBOLS: <gt_head>.
CREATE DATA re_head LIKE LINE OF <gt_table>.
ASSIGN re_head->* TO <gt_head>.
You can then move data to <gt_head> and append <gt_head> to <gt_table>.
‎2006 Nov 02 5:59 PM
Hello,
Thanks a lot for your replies. I am struggling with the next part. Now suppose i've one internal table (which is also generated according to input parameter). So when input = 3, internal table will be like this
sy-tabix item value
(=p_input)
1 10 10.00
2 20 20.00
3 30 30.00
an I've a dynamic internal table <gt_table> (as created by the code). I want to move value corresponding to sy-tabix 1 into col1 of <gt_table> and so on.
so output with write statement will be something like this.
col1 col2 col3
10 20 30
I am not able to play around with <gt_table> properly.
‎2006 Nov 02 6:16 PM
Hi,
DATA: re_head TYPE REF TO DATA.
FIELD-SYMBOLS: <gt_head>.
CREATE DATA re_head LIKE LINE OF <gt_table>.
ASSIGN re_head->* TO <gt_head>.
FIELD-SYMBOLS: <FS>.
LOOP AT ITAB.
ASSIGN COMPONENT SY-TABIX OF STRUCTURE <gt_head>
to <FS>.
<FS> = itab-item.
ENDLOOP.
APPEND <gt_head> to <gt_table>.
Thanks,
Naren
‎2006 Nov 02 7:12 PM