Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Populate database table from internal table

Former Member
0 Likes
965

Hi,

I have some data in an internal table which is structured as :

Account Entity Category value period1 value pd2

10 A C 100 200

Now I need to populate it into database table having structure

Account Entity Category period Value

10 A C 1 100

10 A C 1 100

i.e. if there are 12 periods they should correspond to 12 columns in database table.

How do I do this

Thanks

Ankit

5 REPLIES 5
Read only

ThomasZloch
Active Contributor
0 Likes
661

pseudo code for 12 periods:

loop at internal table.

do 12 times varying var_value from value_period1 next value_period2.

fill account, entity, category, period (from sy-index) and value (from var_value).

insert new db table entry.

enddo.

endloop.

Greetings

Thomas

Read only

Former Member
0 Likes
661

You need to be more clear, I cant really see a logic in the internal table.

Why does the period gets repeated in the database table? Do you see you are using repeated entries, and violating one of the principles of relational databases?

I guees you meant

10 A C 1 100

10 A C 2 200

Read only

Former Member
0 Likes
661

write as :

loop at itab.

do 12 times <-- corresponds to 12 columns in internal table.

varying val_period FROM itab-period1

NEXT itab-period2.

  • Insert into your table ..

if not val_period is initial.

move-corresponding itab to <table>.

<table>-period Value = val_period.

insert <table>.

endif.

enddo.

endloop.

Read only

Former Member
0 Likes
661

can u explain it more clearly....

Read only

Former Member
0 Likes
661

Hi ramiro,

I am a BW consultant and need to poulate this data in the format which is suitable for upload to BW.Thats why the repeated entries.

Hi Mr A,

Account Entity Category value period1 value pd2

10 A C 100 200

Now I need to populate it into database table having structure

Account Entity Category period Value

10 A C 1 100

10 A C 2 200

that means instead of having values of all the periods in the same row we insert a column period in the database table which means we denormalize the table and new rows are created for each entry.

Thanks 4 the help.

Ankit