‎2008 May 26 12:07 PM
Hi,
I have an internal table having a structure like below.
Account Entity Category period1value pd2value
10 A C 100 200.
where account corresponds to 10
entity A
category C
period1 value = 100
period2 value = 200.
period3 value =300
Now I need to populate it into a database table having structure like
Account Entity Category period Value
10 A C 1 100
10 A C 2 200.
10 A C 3 300
If u see this carefully a new column, period is added in the database table and thus for each row there will be only 1value.
Instead of period1 value and period2 value being in the same row they will come in different rows.One row will be like the value for period1 and next for value like period2.
Pleadse help
Ankit
‎2008 May 26 12:17 PM
Hi,
As per your requirement, in the table first three fields are to be primary key.
While looping the internal table INSERT the records by giving period value using counter.
counter = 1.
loop at itab into wa_itab.
counter = counter + 1.
wa_itab1-Account = wa_itab-Account.
wa_itab1-Entity = wa_itab-Entity.
wa_itab1-Category = wa_itab-Category.
wa_itab1-period = counter.
wa_itab1-Value = wa_itab-period1.
INSERT <your table name> from wa_itab1.
if wa_itab-period2 is not initial.
counter = counter + 1.
clear wa_itab1.
wa_itab1-Account = wa_itab-Account.
wa_itab1-Entity = wa_itab-Entity.
wa_itab1-Category = wa_itab-Category.
wa_itab1-period = counter.
wa_itab1-Value = wa_itab-period2.
INSERT <your table name> from wa_itab1.
endif.
clear : wa_itab, wa_itab1.
endloop.Regards,
Raghu
‎2008 May 26 12:16 PM
Hi,
do like this
loop at itab.
ztable-Account = itab-Account.
ztable-Entity = itab-Entity.
ztable-Category = itab-Category.
ztable-period_Value = itab-period_Value1.
insert ztable.
if itab-period_Value2 is not initial.
ztable-period_Value = itab-period_Value2.
insert ztable.
endif.
if itab-period_Value3 is not initial.
ztable-period_Value = itab-period_Value3.
insert ztable.
endif.
endloop.
rgds,
bharat.
‎2008 May 26 12:17 PM
Hi,
As per your requirement, in the table first three fields are to be primary key.
While looping the internal table INSERT the records by giving period value using counter.
counter = 1.
loop at itab into wa_itab.
counter = counter + 1.
wa_itab1-Account = wa_itab-Account.
wa_itab1-Entity = wa_itab-Entity.
wa_itab1-Category = wa_itab-Category.
wa_itab1-period = counter.
wa_itab1-Value = wa_itab-period1.
INSERT <your table name> from wa_itab1.
if wa_itab-period2 is not initial.
counter = counter + 1.
clear wa_itab1.
wa_itab1-Account = wa_itab-Account.
wa_itab1-Entity = wa_itab-Entity.
wa_itab1-Category = wa_itab-Category.
wa_itab1-period = counter.
wa_itab1-Value = wa_itab-period2.
INSERT <your table name> from wa_itab1.
endif.
clear : wa_itab, wa_itab1.
endloop.Regards,
Raghu
‎2008 May 26 12:19 PM
hi Ankit...
ur qstn is a very tricky one.... u want to populate from the same row ....... this wil be trouble.
i dont think this is possible. but if u have different rows for the three values, then it is possible.
use two workareas and use nested loops.
like:
loop itab into wa1.
loop itab into wa2.
insert into DBTAB values wa2-val1 wa2-val2.....
endloop.
endloop.
this will help but in the case that i hav mentioned above.
otherwise.... m not sure...