10-24-2011 4:35 PM
Hi,
I was hoping someone could help me out.
I have an internal table with fields EINDT, MENGE, MEINS, STAT.
I have to convert this to an internal table of the kind:
EINDT1
MENGE1
MEINS1
STAT1
EINDT2
MENGE2
MEINS2
STAT2
EINDT3
MENGE3
MEINS3
STAT3
EINDT4
MENGE4
MEINS4
STAT4
EINDT5
MENGE5
MEINS5
STAT5
So, every line of the second internal table exists of 5 of the lines of the original internal table.
So what I was doing is
loop at internal table1.
case sy-tabix.
when 1.
wa_line-eindt1 = tdelivdata-eindt.
wa_line-menge1 = tdelivdata-menge.
wa_line-meins1 = tdelivdata-meins.
wa_line-stat1 = tdelivdata-stat.
when 2.
wa_line-eindt2 = tdelivdata-eindt.
................
And I would do an append at the fifth line.
The problem is, that it is possible that the original internal table only has 3 lines, or maybe 12.
So then appending on every fifth tabix wouldn't work.
So how do I solve this?
THANK YOU!
10-24-2011 5:08 PM
Hi,
You can use the MODULO to achieve this..
loop at internal table1.
l_idx = sy-tabix MOD 5.
case sy-tabix.
when 1.
wa_line-eindt1 = tdelivdata-eindt.
wa_line-menge1 = tdelivdata-menge.
wa_line-meins1 = tdelivdata-meins.
wa_line-stat1 = tdelivdata-stat.
when 2.
wa_line-eindt2 = tdelivdata-eindt.
................
endcase.
IF l_idx = 0.
APPEND wa_line TO itab2.
ENDIF.
endloop.
IF l_idx NE 0.
APPEND wa_line TO itab2.
ENDIF.
Kr,
Manu.
Edited by: Manu D'Haeyer on Oct 24, 2011 6:10 PM
10-24-2011 5:24 PM
Hey, that could actually work...
I'm going to try. Will reward points afterwards. Thanks!
10-24-2011 5:43 PM
Hi
The link of Maruthi is good, but actually it's better to use the a [RTTI solution|http://wiki.sdn.sap.com/wiki/display/Snippets/CreatingFlatandComplexInternalTablesDynamicallyusingRTTI] instead of solution based on method CREATE_DYNAMIC_TABLE
Max
10-24-2011 5:23 PM
Hi ,
Please use the Dynamic Internal Table concept .
Go throug the below sample code .
http://wiki.sdn.sap.com/wiki/display/ABAP/DynamicInternaltable
Regards
Maruthi