Application Development 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: 

report-database insert

former_member202957
Contributor
0 Kudos

hi experts,

i have a requirement to insert data in data base table from internatal table.

it_totstk1 is internal table.

zstock1 is my database table.

please check out the loop condition below i am unable to insert all the records in the database table it is inserting only the last reocrd. my requiment is to insert montly stock i hv taken date from 1.6.2006 to 30.6.2006. in data base it is showing the reocord dated 30.6.06 only i have tried differnt examples but it is inserting only one record. where is the probelem would be? pleae help me.. is there any problem in database table or my report i am unable to understand.

LOOP AT it_totstk1.

totqty = opqty + it_totstk1-pmenge.

clqty = totqty - it_totstk1-defkimg - it_totstk1-sfkimg .

WRITE : /2(10) it_totstk1-month1 NO-ZERO ,sy-vline,

15(15) opqty NO-ZERO,sy-vline,32(15) it_totstk1-pmenge

NO-ZERO,sy-vline,

50(15) totqty NO-ZERO,sy-vline,67(15) it_totstk1-sfkimg

NO-ZERO,sy-vline,

85(15) it_totstk1-defkimg NO-ZERO,sy-vline,

102(15) clqty NO-ZERO ,sy-vline,

120(15) it_totstk1-sexbas NO-ZERO,sy-vline,

137(15) it_totstk1-sexbed NO-ZERO,sy-vline,

155(15) it_totstk1-secs NO-ZERO,sy-vline,

172(15) it_totstk1-sexaddtax1 NO-ZERO,sy-vline,

190(15) it_totstk1-brtwr NO-ZERO,sy-vline,

210(15) it_totstk1-cpmenge NO-ZERO ,sy-vline,

227(15) it_totstk1-cpexbas NO-ZERO,sy-vline,

245(15) it_totstk1-cpimenge NO-ZERO,sy-vline,

262(15) it_totstk1-cpiexbas NO-ZERO,sy-vline.

opqty = clqty.

AT END OF month1.

ULINE AT /(300).

ENDAT.

AT LAST.

SUM.

temptot = tempop + it_totstk1-pmenge.

tempcl = temptot - it_totstk1-sfkimg - it_totstk1-defkimg.

FORMAT COLOR 5.

WRITE : /2 'Total:..',15(15) tempop NO-ZERO,sy-vline,

32(15) it_totstk1-pmenge NO-ZERO,sy-vline,

50(15) temptot ,sy-vline NO-ZERO,

67(15) it_totstk1-sfkimg NO-ZERO,sy-vline,

85(15) it_totstk1-defkimg NO-ZERO,sy-vline,

102(15) tempcl NO-ZERO,sy-vline,

120(15) it_totstk1-sexbas NO-ZERO,sy-vline,

137(15) it_totstk1-sexbed NO-ZERO,sy-vline,

155(15) it_totstk1-secs NO-ZERO,sy-vline,

172(15) it_totstk1-sexaddtax1 NO-ZERO,sy-vline,

190(15) it_totstk1-brtwr NO-ZERO,sy-vline,

210(15) it_totstk1-cpmenge NO-ZERO,sy-vline,

227(15) it_totstk1-cpexbas NO-ZERO,sy-vline,

245(15) it_totstk1-cpimenge NO-ZERO,sy-vline,

262(15) it_totstk1-cpiexbas NO-ZERO,sy-vline.

FORMAT COLOR OFF.

ULINE AT /(300).

ENDAT.

move-corresponding it_totstk1 to zstock1.

zstock1-mandt = sy-mandt.

modify zstock1.

ENDLOOP.

CLEAR : opqty,clqty,totqty,tempop,tempcl,temptot.

CLEAR : it_sales[],it_sales1[],it_totstk1[],

it_prod[],it_prod1[],it_corder[],it_corder1[].

CLEAR : it_sales,it_sales1,it_totstk1,

it_prod,it_prod1,it_corder,it_corder1.

in debuggin i have seen that internal table values are passing to zstock1 but only one record is showing in the database.

i have used differnt insert statements also such as.

1.INSERT INTO ZSTOCK1 VALUES IT_TOTSTK1.

COMMIT WORK.

2.INSERT ZSTOCK1 FROM IT_TOTSTK1

but it is inserting only one reocrd..

<b>useful answers rewarded</b>

Thanx & Regards,

sunil kumar.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

INSERT ZSTOCK1 FROM <b>TABLE</b> IT_TOTSTK1

Your code was transferring the header line to the database table, not the contenets of the table itself.

6 REPLIES 6

Former Member
0 Kudos

hi Sunil,

<b>just check the primary keys of the table & the records from the internal table.</b>

reply back.

With Rgds,

S.Barani

0 Kudos

hi bharani,

thaks for your quick reply.

here primary key is mandt field. The same sourece code is running sucessfully for other report but for my record it is inserting only last record. Here the modify key word is not working properly.

Thanks & Regards,

sunil kumar.

Former Member
0 Kudos

INSERT ZSTOCK1 FROM <b>TABLE</b> IT_TOTSTK1

Your code was transferring the header line to the database table, not the contenets of the table itself.

0 Kudos

Hai Chris,

Thanks for ur reply,

If i am using INSERT ZSTOCK1 FROM TABLE IT_TOTSTK1.

it is giving syntax erros, such as

The type of the database table and work area (or internal table) "IT_TOTSTK1" are not unicode Convertible.

What is this mean???

Thanks & Regards,

Sunil kumar.

0 Kudos

Hi

it_totsk1 must be same as ZSTOCK1.

For ex it_totski type standard table of ZSTOCK1.

Former Member
0 Kudos

Hi,

When you are using internal table use

insert dbtab from table itab.