2014 Feb 16 6:31 PM
Hi ,
I have the requirement to convert Columns into row in table:
Input file
------------
Col1 Col2 Col3 Col4 .... .... Coln
101 102 103 104 --- ---- ----
201 202 203 204 -----------
301 302 303 304 -----------
401 402 403 404 ------------
.....
-----
In the table out put should be
Col1
101
201
301
401
Col2
102
202
302
402
Col3
103
203
303
403
Col4
104
204
304
404
---
----
Please suggest/advise how to achieve this in ABAP
2014 Feb 16 9:03 PM
Hi Rajiv,
1. First get all field names of internal table - Use runtime service class given below example
2. Loop FIELD Names and Assign component of internal table to field symbol.
Sample Code -
DATA: wa_type TYPE mara,
t_table TYPE TABLE OF mara,
struct_descr TYPE REF TO cl_abap_structdescr,
t_component type ABAP_COMPONENT_TAB,
wa_comp like LINE OF t_component.
FIELD-SYMBOLS <fs_value> TYPE any.
SELECT * FROM mara INTO TABLE t_table.
struct_descr ?= cl_abap_structdescr=>describe_by_name( 'MARA' ).
CALL METHOD struct_descr->get_components
RECEIVING
p_result = t_component.
LOOP AT t_component INTO wa_comp.
WRITE / : wa_comp-name.
LOOP AT t_table INTO wa_type.
ASSIGN COMPONENT wa_comp-name OF STRUCTURE wa_type TO <fs_value>.
IF <fs_value> IS ASSIGNED.
WRITE /: <fs_value>.
ENDIF.
ENDLOOP.
ENDLOOP.
Note - In above example , table type of MARA. Use this example as base
Thanks & Regards,
Arun
Message was edited by: Aruna Kumara K I have changed the example. Please paste code in dev system and debug. It will display the data as you want. Thanks & Regards,
2014 Feb 17 9:45 AM
Hi Aruna,
Thank you for your reply, but still I am not able to get how this will be stored as row in custom table
2014 Feb 17 9:54 AM
Hi,
I have changed the code and try this sample code in your dev system and debug it . It will work as you need.
Thanks & Regards,
aRUN
2014 Feb 17 11:10 AM
2014 Feb 17 11:19 AM
Hi Rajiv
I think this will help :
loop at itab into wa .
index = sy-tabix.
wa-col1 = col2 .
append wa to itab.
wa-col1 = col3 .
append wa to itab.
wa-col1 = col4.
append wa to itab.
clear wa.
modify itab from wa transporting col2 col3 col4 index index.
endloop.
regards
Vaibhav
2014 Feb 17 11:21 AM
Hi,
DATA: wa_type TYPE mara,
t_table TYPE TABLE OF mara,
struct_descr TYPE REF TO cl_abap_structdescr,
t_component type ABAP_COMPONENT_TAB,
wa_comp like LINE OF t_component.
FIELD-SYMBOLS <fs_value> TYPE any.
SELECT * FROM mara up to 5 rows INTO TABLE t_table.
struct_descr ?= cl_abap_structdescr=>describe_by_name( 'MARA' ).
CALL METHOD struct_descr->get_components
RECEIVING
p_result = t_component.
LOOP AT t_component INTO wa_comp.
WRITE / : wa_comp-name.
LOOP AT t_table INTO wa_type.
ASSIGN COMPONENT wa_comp-name OF STRUCTURE wa_type TO <fs_value>.
IF <fs_value> IS ASSIGNED.
WRITE /: <fs_value>.
ENDIF.
ENDLOOP.
ENDLOOP.
Regards,
Arun
2014 Feb 17 11:55 AM
Hi Rajiv,
Do u want to have a table with one column and multiple rows(as per input file) ?.
if so..then
data : wa_char type char20,
itab like table of wa_char.
loop at it_tab into wa .
wa_char = wa-field1 .
appemd wa_char into itab .
wa_char = wa-field2 .
appemd wa_char into itab .
wa_char = wa-field3 .
appemd wa_char into itab .
wa_char = wa-field4 .
appemd wa_char into itab .
....
endloop.
Else if u want to have a table with all the field values as table fields of the table. then
use CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
* I_STYLE_TABLE =
IT_FIELDCATALOG = t_flcat
* I_LENGTH_IN_BYTE = 'X'
IMPORTING
EP_TABLE = t_newtable
* E_STYLE_FNAME =
EXCEPTIONS
GENERATE_SUBPOOL_DIR_FULL = 1
others = 2
.
2014 Feb 17 1:28 PM
Hi All,
Thank you for your response, here I have to mention one point:
1. In my input file columns are dynamic (col1,col2,....coln) and for each column I need to take sum and needs to average:
My Output table will be
Value average
------- -----------
Col1
101 101/1004(sum of 101+201+301+401)
201 201/1004
301 301/1004
401 401/1004
Col2
102 102/1008
202 202/1008
302 etc...
402
Col3
103
203
303
403
Col4
104
204
304
404
---
----
2014 Feb 17 5:15 PM
Hi ,
Do like this...
TYPES: BEGIN OF TY_TAB,
FIELD type char20,
VALUE TYPE INT1,"(TYPE OF FIELD VALUE)
END OF TY_TAB .
data : wa_CHAR type TY_TAB,
itab like table of wa_char.
loop at it_tab into wa . "IT_TAB - INTERNAL TABLE HAVING DATA ,WA-WORK AREA OF "SAME TYPE
wa_char-FIELD = wa-field1 . "(101)
WA_CHAR-VALUE = WA-FIELD1 / ( wa-field1 + wa-field2 + wa-field3 + wa-field4 )
append wa_char into itab .
wa_char-FIELD = wa-field2 . "(201)
WA_CHAR-VALUE = WA-FIELD2 / ( wa-field1 + wa-field2 + wa-field3 + wa-field4 )
append wa_char into itab .
wa_char-FIELD = wa-field3 . "(301)
WA_CHAR-VALUE = WA-FIELD3 / ( wa-field1 + wa-field2 + wa-field3 + wa-field4 )
append wa_char into itab .
wa_char-FIELD = wa-field4 . "(401)
WA_CHAR-VALUE = WA-FIELD4 / ( wa-field1 + wa-field2 + wa-field3 + wa-field4 )
append wa_char into itab .
....
endloop.
final output
field value
101 101/1004
201 201/1004
301 301/1004
401 401/1004 and so on..
Regards
2014 Feb 18 8:48 AM
2014 Feb 18 9:07 AM
Hi Dieter,
Thank you for your reply, but here my Input source file having dynamic columns , some times it is having 4 and other time 10 columns, so in this case how I can define my Internal table .
2014 Feb 18 9:25 AM
Hi Rajiv,
For Dynamic creation of an Internal table use the below code,
FIELD-SYMBOLS : <it_dyntable> TYPE STANDARD TABLE,"Dynamic intenal table
<wa_dyntable> , "Dynamic work area
<wa> , "Dynamic work area
<fs_fvalue> TYPE any. "Component in work area
DATA : r_newtable TYPE REF TO data,
r_newtable_wa TYPE REF TO data,
*Now You should fill ur field catlog table with all required fields(Column),
and use he method.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
* i_style_table =
it_fieldcatalog = git_fldcat_2 "Field catlog of type lvc_t_fcat
* i_length_in_byte =
IMPORTING
ep_table = r_newtable " r_newtable TYPE REF TO data,
* e_style_fname =
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ASSIGN r_newtable->* TO <it_dyntable>. "Dynamic Internal Table
CREATE DATA r_newtable_wa LIKE LINE OF <it_dyntable>.
ASSIGN r_newtable_wa->* TO <wa_dyntable>. "Dynamic Work Area
Regards
Sreekanth
2014 Feb 18 4:23 PM
Hi Rajiv,
i don't where you get the Information how many columns you Need. But if you have the Information
you can try this to create a internal Itab dynamicly (like some have allready mentioned):
Regards, Dieter
2014 Feb 17 1:00 PM
2014 Feb 17 1:06 PM
2014 Feb 20 11:02 AM
Hi Group,
Sorry for the delay in the response:
My requirement is following: Here COL 's are indefinate COL0001,COL0002,COL0003.....COLnnnn
| Year Period Type Cc COL0001 COL0002 COL0003 | ||
| 2013 10 DCT 100774 0.002301374 0.002301374 0.002152929 | ||
| 2013 10 DCT 100306 0.002259948 0.002259948 0.002610926 | ||
| 2013 10 DCT 100204 0.004002861 0.004002861 0.004082154 |
2013 10 DCT 100372 0.002159194 0.002159194 0.002020573
2013 10 DCT 100301 0.003722206 0.003722205 0.004145894
2013 10 DCT 100185 0.002433672 0.002433672 0.002374354
2013 10 DCT 100637 0.002041811 0.002041811 0.001920717
2013 10 DCT 100005 0.004306849 0.004306849 0.004253312
Output
------
| Year Period Type CC | Col Name | Value Avg |
------------------------------------------------------------------------
2013 10 DCT 100774 COL0001 0.002301374 value/sum
2013 10 DCT 100306 COL0001 0.002259948
2013 10 DCT 100204 COL0001 0.004002861
2013 10 DCT 100372 COL0001 0.002159194
2013 10 DCT 100301 COL0001 0.003722206
2013 10 DCT 100185 COL0001 0.002433672
2013 10 DCT 100637 COL0001 0.002041811
2013 10 DCT 100005 COL0001 0.004306849
2013 10 DCT 100774 COL0002 0.002301374 value/sum
2013 10 DCT 100306 COL0002 0.002259948
2013 10 DCT 100204 COL0002 0.004002861
2013 10 DCT 100372 COL0002 0.002159194
2013 10 DCT 100301 COL0002 0.003722206
2013 10 DCT 100185 COL0002 0.002433672
2013 10 DCT 100637 COL0002 0.002041811
2013 10 DCT 100005 COL0002 0.004306849
2013 10 DCT 100774 COL0003 0.002152929 value/sum
2013 10 DCT 100306 COL0003 0.002610926
2013 10 DCT 100204 COL0003 0.004082154
2013 10 DCT 100372 COL0003 0.002020573
2013 10 DCT 100301 COL0003 0.004145894
2013 10 DCT 100185 COL0003 0.002374354
2013 10 DCT 100637 COL0003 0.001920717
| 2013 10 DCT 100005 COL0003 0.004253312 |
2014 Feb 22 5:08 AM
Hi,
follow the below logic..
Suppose, ITAB is you internal table having data..
and IT_FINAL for final output .
let ITAB has data as below...
| Year Period Type Cc COL0001 COL0002 COL0003 | ||
| 2013 10 DCT 100774 0.002301374 0.002301374 0.002152929 | ||
| 2013 10 DCT 100306 0.002259948 0.002259948 0.002610926 | ||
| 2013 10 DCT 100204 0.004002861 0.004002861 0.004082154 |
As the columns in ITAB are dynamic, set some counter while creating dynamic field in ITAB .
suppose counter = 3 (Total number of dynamic fields..i.e- col001,col002,col003) .
DATA : WA_COUNT TYPE I ,
pos_count type I VALUE 4 . (number of non-dynamic fields. i.e-year,period,type,cc)
FIELD-SYMBOLS: <wa> TYPE ANY,
<comp> TYPE ANY.
ASSIGN WA_TAB TO <WA> .
LOOP AT ITAB INTO WA_TAB .
WA_FINAL-YEAR = WA_TAB-YEAR .
WA_FINAL-PERIOD = WA_TAB-PERIOD .
WA_FINAL-TYPE = WA_TAB-TYPE .
WA_FINAL-CC = WA_TAB-CC .
DO COUNTER TIMES .
WA_COUNT = WA_COUNT + 1 .
POS_COUNT = POS_COUNT + 1
********Put logic for creating column name dynamically,,
********as it is done before for ITAB**********like ...
CONCATENATE 'COL' WA_COUNT INTO WA_FINAL-COL_NAME .
ASSIGN COMPONENT POS_COUNT OF STRUCTURE <WA> TO <COMP>.
WA_FINAL-VALUE = <COMP> .
APPEND WA_FINAL TO IT_FINAL .
ENDDO .
CLEAR WA_COUNT .
POS_COUNT = 4 .
ENDLOOP .
In above logic..for one loop at ITAB ,, three records will be inserted into IT_FINAL
as below...
YEAR PERIOD TYPE CC COLUMN VALUE
2013 10 DCT 100774 COL1 0.002301374
| 2013 | 10 | DCT | 100774 | COL2 | 0.002301374 |
| 2013 | 10 | DCT | 100774 | COL3 | 0.002152929 |
and so on ....
for every CC number you will get three records(number of dynamic fields)...after completion of loop you will get
the required output, then for AVERAGE, it's not a difficult task to do .
Regards
DJ
2014 Feb 22 9:57 AM
HI DJ,
Thank you for your response,but still this logic not working for me, Here I am attaching my code along with Input and output:
Code
----------
*&---------------------------------------------------------------------*
*& Report ZTEST11
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZTEST11.
TYPES: begin of ty_item,
col1(20) type c ,
col2(20) type c ,
col3(20) type c,
col4(20) type c,
col5(20) type c,
col6(20) type c,
col7(20) type c,
end of ty_item.
TYPES: begin of ty_item_final,
col1(20) type c ,
col2(20) type c ,
col3(20) type c,
col4(20) type c,
col5(20) type c,
col6(20) type c,
end of ty_item_final.
DATA: lwa_item type ty_item,
wa_final type ty_item_final,
lt_item type standard table of ty_item,
lt_item_final type standard table of ty_item_final.
DATA : WA_COUNT TYPE I ,
wa_count1(3) TYPE c,
pos_count type I VALUE 4 .
FIELD-SYMBOLS: <wa> TYPE ANY,
<comp> TYPE ANY.
lwa_Item-col1 = 'YEAR'.
lwa_item-col2 = 'PERIOD'.
lwa_item-col3 = 'TYPE'.
lwa_item-col4 = 'CC'.
lwa_item-col5 = 'COL00001'.
lwa_item-col6 = 'COL0002'.
lwa_item-col7 = 'COL0003'.
append lwa_item to lt_item.
lwa_Item-col1 = '2013'.
lwa_item-col2 = '10'.
lwa_item-col3 = 'DCT'.
lwa_item-col4 = '10074'.
lwa_item-col5 = '0.002301374'.
lwa_item-col6 = '0.002301374'.
lwa_item-col7 = '0.002152929'.
append lwa_item to lt_item.
lwa_Item-col1 = '2013'.
lwa_item-col2 = '10'.
lwa_item-col3 = 'DCT'.
lwa_item-col4 = '100306'.
lwa_item-col5 = '0.002259948'.
lwa_item-col6 = '0.002259948'.
lwa_item-col7 = '0.002610926'.
append lwa_item to lt_item.
lwa_Item-col1 = '2013'.
lwa_item-col2 = '10'.
lwa_item-col3 = 'DCT'.
lwa_item-col4 = '10074'.
lwa_item-col5 = '0.002301374'.
lwa_item-col6 = '0.002301374'.
lwa_item-col7 = '0.002152929'.
append lwa_item to lt_item.
lwa_Item-col1 = '2013'.
lwa_item-col2 = '14'.
lwa_item-col3 = 'AMT'.
lwa_item-col4 = '100204'.
lwa_item-col5 = '0.004002861'.
lwa_item-col6 = '0.004002861'.
lwa_item-col7 = '0.004082154'.
append lwa_item to lt_item.
clear lwa_item.
LOOP at lt_item into lwa_item.
ASSIGN lwa_item TO <WA> .
WA_FINAL-col1 = lwa_item-col1 .
WA_FINAL-col2 = lwa_item-col2.
WA_FINAL-col3 = lwa_item-col3 .
WA_FINAL-col4 = lwa_item-col4 .
DO 3 times.
WA_COUNT = WA_COUNT + 1 .
wa_count1 = wa_count.
POS_COUNT = POS_COUNT + 1.
CONCATENATE 'COL' WA_COUNT1 INTO WA_FINAL-COL5 .
ASSIGN COMPONENT POS_COUNT OF STRUCTURE <WA> TO <COMP>.
WA_FINAL-col6 = <COMP> .
APPEND WA_FINAL TO lT_item_FINAL .
enddo.
clear:wa_count,wa_count1.
pos_count = 4.
endloop.
loop at lt_item_final into wa_final.
write:/ wa_final-col1,wa_final-col2,wa_final-col3,wa_final-col4,wa_final-col5.
endloop.
OUTPUT:
--------
YEAR PERIOD TYPE CC COL 1
YEAR PERIOD TYPE CC COL 2
YEAR PERIOD TYPE CC COL 3
2013 10 DCT 10074 COL 1
2013 10 DCT 10074 COL 2
2013 10 DCT 10074 COL 3
2013 10 DCT 100306 COL 1
2013 10 DCT 100306 COL 2
2013 10 DCT 100306 COL 3
2013 10 DCT 10074 COL 1
2013 10 DCT 10074 COL 2
2013 10 DCT 10074 COL 3
2013 14 AMT 100204 COL 1
2013 14 AMT 100204 COL 2
2013 14 AMT 100204 COL 3
2014 Feb 22 10:31 AM
Hi,
check the changes i made, and required output..
*&---------------------------------------------------------------------*
*& Report ZDJ_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZDJ_TEST.
* REPORT ZTEST11.
TYPES: begin of ty_item,
col1(20) type c ,
col2(20) type c ,
col3(20) type c,
col4(20) type c,
col5(20) type c,
col6(20) type c,
col7(20) type c,
end of ty_item.
TYPES: begin of ty_item_final,
col1(20) type c ,
col2(20) type c ,
col3(20) type c,
col4(20) type c,
col5(20) type c,
col6(20) type c,
end of ty_item_final.
DATA: lwa_item type ty_item,
wa_final type ty_item_final,
lt_item type standard table of ty_item,
lt_item_final type standard table of ty_item_final.
DATA : WA_COUNT TYPE I ,
wa_count1(3) TYPE c,
pos_count type I VALUE 4 .
FIELD-SYMBOLS: <wa> TYPE ANY,
<comp> TYPE ANY.
*lwa_Item-col1 = 'YEAR'.
*
*lwa_item-col2 = 'PERIOD'.
*
*lwa_item-col3 = 'TYPE'.
*
*lwa_item-col4 = 'CC'.
*
*lwa_item-col5 = 'COL00001'.
*
*lwa_item-col6 = 'COL0002'.
*
*lwa_item-col7 = 'COL0003'.
*append lwa_item to lt_item.
lwa_Item-col1 = '2013'.
lwa_item-col2 = '10'.
lwa_item-col3 = 'DCT'.
lwa_item-col4 = '10074'.
lwa_item-col5 = '0.002301374'.
lwa_item-col6 = '0.002301374'.
lwa_item-col7 = '0.002152929'.
append lwa_item to lt_item.
lwa_Item-col1 = '2013'.
lwa_item-col2 = '10'.
lwa_item-col3 = 'DCT'.
lwa_item-col4 = '100306'.
lwa_item-col5 = '0.002259948'.
lwa_item-col6 = '0.002259948'.
lwa_item-col7 = '0.002610926'.
append lwa_item to lt_item.
lwa_Item-col1 = '2013'.
lwa_item-col2 = '10'.
lwa_item-col3 = 'DCT'.
lwa_item-col4 = '10074'.
lwa_item-col5 = '0.002301374'.
lwa_item-col6 = '0.002301374'.
lwa_item-col7 = '0.002152929'.
append lwa_item to lt_item.
lwa_Item-col1 = '2013'.
lwa_item-col2 = '14'.
lwa_item-col3 = 'AMT'.
lwa_item-col4 = '100204'.
lwa_item-col5 = '0.004002861'.
lwa_item-col6 = '0.004002861'.
lwa_item-col7 = '0.004082154'.
append lwa_item to lt_item.
clear lwa_item.
LOOP at lt_item into lwa_item.
ASSIGN lwa_item TO <WA> .
WA_FINAL-col1 = lwa_item-col1 .
WA_FINAL-col2 = lwa_item-col2.
WA_FINAL-col3 = lwa_item-col3 .
WA_FINAL-col4 = lwa_item-col4 .
DO 3 times.
WA_COUNT = WA_COUNT + 1 .
wa_count1 = wa_count.
POS_COUNT = POS_COUNT + 1.
CONCATENATE 'COL' WA_COUNT1 INTO WA_FINAL-COL5 .
ASSIGN COMPONENT POS_COUNT OF STRUCTURE <WA> TO <COMP>.
WA_FINAL-col6 = <COMP> .
APPEND WA_FINAL TO lT_item_FINAL .
enddo.
clear:wa_count,wa_count1.
pos_count = 4.
endloop.
loop at lt_item_final into wa_final.
write:/ wa_final-col1,wa_final-col2,wa_final-col3,wa_final-col4,wa_final-col5,wa_final-col6.
endloop.
output...
Regards
DJ
2014 Feb 20 11:18 AM
DATA : BEGIN OF IT1 OCCURS 0,
C1(2) TYPE C,
END OF IT1.
IT-C1 = 'AA'.
IT-C2 = 'BB'.
IT-C3 = 'CC'.
APPEND IT.
LOOP AT IT.
IT1-C1 = IT-C1.
APPEND IT1.
IT1-C1 = IT-C2.
APPEND IT1.
IT1-C1 = IT-C3.
APPEND IT1.
ENDLOOP.
data: l_idx type i.
field-symbols: <fs> type any.
loop at it.
l_idx = 0.
do.
l_idx = l_idx + 1.
assign component l_idx of structure it to <fs>.
if sy-subrc eq 0.
move <fs> to it1-c1.
append it1.
else.
exit.
endif.
enddo.
endloop.
2014 Feb 20 12:29 PM
Hi Avirat,
The above logic will not work in my case as columns are dynamic.
Group, can any body suggest.
2014 Feb 20 12:36 PM
You already were introduced to the solution using CL_ABAP_STRUCTDESCR (post by Aruna).
If your structure is dynamic, then just change method DESCRIBE_BY_NAME to the method DESCRIBE_BY_DATA and you are there.
2014 Feb 20 1:21 PM
HI Jozef,
Aruna's suggestion will not work in my case , because I am reading it from Input file which is having dynamic columns.
2014 Feb 20 1:45 PM
Hi Rajiv,
i think you'v a lot of good answers.
Can you please tell us what you have tried by yourselve.
Please Show your abap, than it's better to help.
Second can you give an example for your input-file in several cases (with different fields)
and tell us how do you read the external file (UPLOAD?).
Regards, Dieter
2014 Feb 20 2:12 PM
Did you read my previous post till it's end? Aruna's suggestion will work for every case, RTTS (RTTI) is primarily aimed at the situations where your structure is dynamic.
2014 Feb 21 9:52 AM
Hi Dieter,
Thank you for your resposne, I am reading all rows in to string , then using SPLIT I am taking in to each column, I defined Internal table maximum of 100 columns , but after that I am not getting correct logic.
2014 Feb 21 6:43 PM
2014 Feb 22 5:15 AM
Hi,
follow the below logic..
Suppose, ITAB is you internal table having data..
and IT_FINAL for final output .
let ITAB has data as below...
| Year Period Type Cc COL0001 COL0002 COL0003 | ||
| 2013 10 DCT 100774 0.002301374 0.002301374 0.002152929 | ||
| 2013 10 DCT 100306 0.002259948 0.002259948 0.002610926 | ||
| 2013 10 DCT 100204 0.004002861 0.004002861 0.004082154 |
As the columns in ITAB are dynamic, set some counter while creating dynamic field in ITAB .
suppose counter = 3 (Total number of dynamic fields..i.e- col001,col002,col003) .
DATA : WA_COUNT TYPE I ,
pos_count type I VALUE 4 . (number of non-dynamic fields. i.e-year,period,type,cc)
FIELD-SYMBOLS: <wa> TYPE ANY,
<comp> TYPE ANY.
ASSIGN WA_TAB TO <WA> .
LOOP AT ITAB INTO WA_TAB .
WA_FINAL-YEAR = WA_TAB-YEAR .
WA_FINAL-PERIOD = WA_TAB-PERIOD .
WA_FINAL-TYPE = WA_TAB-TYPE .
WA_FINAL-CC = WA_TAB-CC .
DO COUNTER TIMES .
WA_COUNT = WA_COUNT + 1 .
POS_COUNT = POS_COUNT + 1
********Put logic for creating column name dynamically,,
********as it is done before for ITAB**********like ...
CONCATENATE 'COL' WA_COUNT INTO WA_FINAL-COL_NAME .
ASSIGN COMPONENT POS_COUNT OF STRUCTURE <WA> TO <COMP>.
WA_FINAL-VALUE = <COMP> .
APPEND WA_FINAL TO IT_FINAL .
ENDDO .
CLEAR WA_COUNT .
POS_COUNT = 4 .
ENDLOOP .
In above logic..for one loop at ITAB ,, three records will be inserted into IT_FINAL
as below...
YEAR PERIOD TYPE CC COLUMN VALUE
2013 10 DCT 100774 COL1 0.002301374
| 2013 | 10 | DCT | 100774 | COL2 | 0.002301374 |
| 2013 | 10 | DCT | 100774 | COL3 | 0.002152929 |
and so on ....
for every CC number you will get three records(number of dynamic fields)...after completion of loop you will get
the required output, then for AVERAGE, it's not a difficult task to do .
Regards
DJ
2014 Feb 22 10:35 AM
2014 Feb 22 4:39 PM
HI DJ,
Thank you ,your logic works ,but Here I have doubt , for initial step of getting data in into ITAB do I need to ITAB column with some maximum number (say 100) because I do not know how many columns will some in source file.
2014 Feb 22 5:45 PM
2014 Feb 22 7:11 PM
HI Dj,
Thank you for ur response, but for counter also we need to assume one max number of columns isn't it?
and one more point , in your for Col5 your making it dynamic in the code, but I want to read this directly from first line/header line of the file:(I m refering this line:CONCATENATE 'COL' WA_COUNT1 INTO WA_FINAL-COL5 .)