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: 

Problem In Inserting Multiple Values In Ztable

Former Member
0 Kudos

Hi,

I had developed a table in which i am inserting the data from the BSEG table and the problem is if there are multiple values wr.t. GL AAccount ID(HKONT) it is picking up only the last value of it as i want to store all of them.

I had searched in SDN first but not able to get the desierd help.

Here is the code which i had developed for it..



Report ztest.

TABLES : BSEG.

TYPES : BEGIN OF ITAB,
        MANDT TYPE BSEG-MANDT ,  "client"
        BUKRS TYPE BSEG-BUKRS,   "company code"
        GJAHR TYPE BSEG-GJAHR,   "fiscal Year"
        HKONT TYPE BSEG-HKONT,   "G/L account No"
        SHKZG TYPE BSEG-SHKZG,   "Debit/ Credit Indicator"
        TAMT   TYPE I,
        END OF ITAB.

DATA : W_ITAB TYPE ITAB ,
       T_ITAB TYPE ITAB OCCURS 0.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE T1.
SELECT-OPTIONS : PBUKRS FOR BSEG-BUKRS, PGJAHR FOR BSEG-GJAHR,PVALUT FOR BSEG-VALUT.
SELECTION-SCREEN END OF BLOCK B1.

 DATA  :  BEGIN OF itab1 OCCURS 0.
          INCLUDE STRUCTURE Ztab21.
DATA  :   END OF itab1.

SELECT MANDT BUKRS GJAHR HKONT SHKZG PSWBT
       FROM BSEG
       INTO TABLE itab1
  WHERE BUKRS IN PBUKRS AND GJAHR IN PGJAHR AND VALUT IN PVALUT.

SORT ITAB1 BY HKONT.

LOOP AT ITAB1.

INSERT INTO ZTAB21 VALUES itab1.

WRITE:/ ITAB1-HKONT,ITAB1-SHKZG,ITAB1-TAMT.

ENDLOOP.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Please try to elaborate your Query whther during the select having any Probelm...

If you are getiing problem during insert,last value only getting updated,then check your Primary Keys -GL Acoount should not be in Primary Keys because in Insert it will not upadte and only last value will be inserted.

Intead of insert start using Modify statement.

Regards.

Arbind

5 REPLIES 5

Former Member
0 Kudos

Hi,

Please try to elaborate your Query whther during the select having any Probelm...

If you are getiing problem during insert,last value only getting updated,then check your Primary Keys -GL Acoount should not be in Primary Keys because in Insert it will not upadte and only last value will be inserted.

Intead of insert start using Modify statement.

Regards.

Arbind

Former Member
0 Kudos

hi nav009,

can u share ur ztable structure with primary keys u have given in that table.

because if ur multiple row data for the combination of key fields is same then u have to increase the key filds.

and the combination of all key fields should be unique, then only it will update the multiple fields, if it is not then it will not upload.

hope it will help u.

regards,

vicky.

0 Kudos

Hi Nav,

I m also agree with vicky. Check ur key fields in Ztable

Former Member
0 Kudos

Hi,

First of all , dont write database update statements inside LOOP


SELECT MANDT BUKRS GJAHR HKONT SHKZG PSWBT
       FROM BSEG
       INTO TABLE itab1
  WHERE BUKRS IN PBUKRS AND GJAHR IN PGJAHR AND VALUT IN PVALUT.
 
SORT ITAB1 BY HKONT.
 
LOOP AT ITAB1.
 
INSERT INTO ZTAB21 VALUES itab1.   " should be before loop
 
WRITE:/ ITAB1-HKONT,ITAB1-SHKZG,ITAB1-TAMT.
 
ENDLOOP.

For using same itab for direct insert, Custom table ZTAB21 should have field names same as BSEG.

Else, you have to write as below:


LOOP AT ITAB1.
wa_ztab21-tfield1 = itab1-bukrs.
append wa_ztab21 to i_ztab21.
WRITE:/ ITAB1-HKONT,ITAB1-SHKZG,ITAB1-TAMT. 
ENDLOOP.

MODIFY ZTAB21 FROM TABLE i_ztab21.

Regards,

Nisha Vengal.

0 Kudos

Hi,

Thanks all of you for your valueable response and i had made the primary key fields of ZTABLE similar to the BSEG table and it is storing the right data into it and yes i had modified the code as you had said...