‎2008 Jul 17 8:49 PM
Gurus,
I have to split data in an internal table based on a condition.
record type
H
L
L
L
H
L
L
L
I have to split this data and group as HLLL and HLLL.
H,L denotes header and line items..
Any ideas on how can we do it....
Thanks.
‎2008 Jul 17 8:54 PM
Mayank,
If I understood it correctly do you want to arrange the rows in the internal table like this?
Header record 1st row
Item record 2nd row
Item record 3rd row
Item record 4th row
Header record 5th row
Item record 6th row
Item record 7th row
Item record 8th row
................................
or do you want to merge each header and its items in to one row?
Let me know.
‎2008 Jul 17 8:54 PM
Mayank,
If I understood it correctly do you want to arrange the rows in the internal table like this?
Header record 1st row
Item record 2nd row
Item record 3rd row
Item record 4th row
Header record 5th row
Item record 6th row
Item record 7th row
Item record 8th row
................................
or do you want to merge each header and its items in to one row?
Let me know.
‎2008 Jul 17 8:56 PM
Thats correct....
Thats the way i want it.....separate rows...
Thanks.
Edited by: Mayank Sharma on Jul 17, 2008 9:56 PM
‎2008 Jul 17 9:00 PM
Mayank,
In your program where from are you pulling those header and item records? And how and where are they stored?
Paste the definition of the header and item structures here.
Thanks,
Naren
‎2008 Jul 17 9:01 PM
If you are reading this data from a file on the application server,
then you need to use the open dataset, read dataset and close dataset statements.
If you are reading the file from presentation server, you need to use the function module 'GUI_UPLOAD'.
This FM will load the data into an internal table. It will create exactly the same number of rows in the internal table as those present in the file.
Loop at the internal table, check the first character, if its 'H' it means header, else line item.
cheers,
Sushil Joshi
‎2008 Jul 17 9:15 PM
U can achieve it by using nested internal table means table with table..like:
types: ty_item type standard table of itemdata.
types: begin of ty_data,
header type headerdata,
item type ty_item, << it is an internal table
end of ty_data.
data: i_data type standard table of ty_data. << Nested table
data: w_data type ty_data.
data: w_item type itemdata.
say i_file contains header and line item data.
loop at i_final into w_final.
if w_final-rectyp = 'H'.
if sy-tabix <> 1.
append w_data to i_data.
endif.
l_rectyp = w_final-rectyp.
w_data-header = w_final-headerdata.
else.
w_item = w_final-itemdata.
append w_item to w_data-item.
endif.
endloop.
append w_data to i_data.
Regards,
Joy.