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

insert Statement

Former Member
0 Likes
3,863

Hi All,

I am having a problem regarding Insert Statement.

I am getting data in the ITAB but when I insert this data in the Ztable it is not inserting in the table..

The same logic I have implemented in other program and it is working, I mean it inserts data in the ztable.

But in this case it is not inserting.

Any idea about this?

LOOP AT it_work.

   it_final_scheme-schno   = v_schnumber.

   it_final_scheme-advstar = it_work-advstar.

   it_final_scheme-perend  = it_work-perend.

   it_final_scheme-amount  = it_work-amount.

   it_final_scheme-percent = it_work-percent.

APPEND it_final_scheme.

INSERT INTO /vcrebate/schtab VALUES it_final_scheme.

COMMIT WORK.

*IF sy-subrc = 0.

*  MESSAGE 'S' TYPE 'S'.

*  ENDIF.

ENDLOOP.

38 REPLIES 38
Read only

former_member187748
Active Contributor
0 Likes
3,810

Hi Yash,

what is this /vcrebate/schtab, is this your table, simply use

INSERT your ztable FROM it_final_scheme.

Read only

0 Likes
3,810

Hi Sanjeev.

  /vcrebate/ is namespace..

But this is not the issue.


I am using Table control and the data is populated from the same in the ITAB.


I Did the same as you said, the issue is when the data is inserted for the first time, the data gets inserted but when I run the transaction for second time or third time , the data is not getting inserted.

Read only

0 Likes
3,810

Hi Yash,

always use work area instead , because it will be easy to do updation by use of work area,

once you insert your data through work area, just clear your work area.

See this code

CLEAR : your work area.

LOOP AT internal table INTO  work area.

fetch your data.

INSERT Ztable FROM work area.

IF sy-SUBRC eq 0.

       MESSAGE 'Data has been save sucessfully' TYPE 'S'.

     ENDIF.

   ENDLOOP.

   CLEAR work area.

REFRESH  INTERNAL TABLE[].

Just do one thing before your loop statement, just clear your internal table (it_final).

Read only

0 Likes
3,810

Thank You Sanjeev.

I am doing by this way..

But getting error of "Unicode Convertible"


LOOP AT it_work INTO wa_work.

     wa_final_scheme-schno   = v_schnumber.

     wa_final_scheme-advstar = wa_work-advstar.

     wa_final_scheme-perend  = wa_work-perend.

     wa_final_scheme-amount  = wa_work-amount.

     wa_final_scheme-percent = wa_work-percent.

     APPEND wa_final_scheme TO it_final_scheme.

     INSERT  zschtab FROM wa_final_scheme.

     COMMIT WORK.

     IF sy-subrc = 0.

       MESSAGE 'S' TYPE 'S'.

     ENDIF.

   ENDLOOP.

Read only

0 Likes
3,810

Yash,

then there is problem in your table structure , you have declared in top most of your program,

Keep it as your data base table is, please see each field and its declaration in your program and table

for data consistency.

Read only

0 Likes
3,810

Sanjeev I have declared like this..

So is it correct??


data : it_work TYPE TABLE OF ty_work,

        wa_work LIKE LINE OF it_work,

        it_final_scheme TYPE TABLE OF ty_work,

        wa_final_scheme like LINE OF it_final_scheme.

Read only

0 Likes
3,810

Hi Yash,

i means to say that please check where you have written your TYPES structure

types : begin of ty_final,

data type your data base table-data,

...check your data types here also

...

end of ty_final.

data : it_final type standard table of ty_final,

         wa_final type ty_final.

Read only

0 Likes
3,810

TYPES : BEGIN OF ty_scheme,

         schno   TYPE zschtab-schno  ,

         advstar TYPE zschtab-advstar ,

         perend  TYPE zschtab-perend ,

         amount  TYPE zschtab-amount ,

         percent TYPE zschtab-percent,

         END OF ty_scheme.

DATA : it_scheme          TYPE TABLE OF ty_scheme,

        wa_scheme          LIKE LINE  OF it_scheme,

        it_work            TYPE TABLE OF ty_scheme,

        wa_work            LIKE LINE  OF it_scheme,

        it_final_scheme    TYPE TABLE OF ty_scheme,

        wa_final_scheme    LIKE LINE  OF it_scheme.


See I am doing this as you said...

Still getting the same error.


Read only

0 Likes
3,810

Hi ,

please use  and see , is it still giving error ?

DATA : it_scheme          TYPE STANDARD TABLE OF ty_scheme,

        wa_scheme          TYPE it_scheme,

        it_work            TYPE STANDARD TABLE OF ty_scheme,

        wa_work           TYPE it_scheme,

        it_final_scheme    TYPE STANDARD TABLE OF ty_scheme,

        wa_final_scheme     TYPE it_scheme.

Read only

0 Likes
3,810

Yes Sanjeev I did the same..

Used standard table also.. But the same error.

Read only

0 Likes
3,810

Hi Yash,

please uncheck (UNICODE CHECKS ACTIVE ) as shown in screenshot here in the attribute in SE38

if still having problem ,please attach your whole code

Read only

0 Likes
3,810

Hi Yash,

if you have used like this, then please change your code as shown below

LOOP AT it_work INTO wa_work.

     wa_final_scheme-schno   = v_schnumber.

     wa_final_scheme-advstar = wa_work-advstar.

     wa_final_scheme-perend  = wa_work-perend.

     wa_final_scheme-amount  = wa_work-amount.

     wa_final_scheme-percent = wa_work-percent.

  

     INSERT  zschtab FROM wa_final_scheme.

     CLEAR wa_final_scheme.

 

     IF sy-subrc = 0.

       MESSAGE 'S' TYPE 'S'.

     ENDIF.

   ENDLOOP.

Read only

0 Likes
3,810

I did this also..

Same Result....

Read only

0 Likes
3,810

After unchecking this the program gave an error of Unicode.

So i checked it.

Read only

0 Likes
3,810

Its problem in the declarations, plz check your data throughtly

Read only

0 Likes
3,810

I copied and pasted all the fields from the database itself.

Read only

0 Likes
3,810

Error solved.

I added MANDT in this ITAB.

Another runtime error generated Error in internal table in screen

Read only

0 Likes
3,810

Hi Yash,

i told you earlier that please check your data consistency with your databse table,

now what is the issue with screen

Read only

0 Likes
3,810

Thanks a lot Sanjeev.

But still the data is not been inserted in the table. Error is solved. But I cant understand what is the issue in this.

Read only

0 Likes
3,810

Hi Yash,

where you have populated data, please put debugger and see that data is passing or not,

please add mandt field also where you are populating data indatabase table (your final internal table

must have been fetched with mandt field ).

Please check that data is passing in wa_final_scheme or not.

Read only

0 Likes
3,810

I added mandt field in the wa.

But still the sy-subrc becomes 4 when the insert command is triggered.

Read only

Former Member
0 Likes
3,810

Hi Yash,

Please read help on INSERT statement.

The work area must be of Line Type of the table used in INSERT statement.

Declare the work area as that of ZTABLE.

Data : IT_TAB type standard table of ZTABLE,

          wa_tab type ZTABLE.

Populate the workarea with the data and then use INSERT statement.

INSERT ZTABLE from workarea.

or INSERT INTO  ZTABLE values IT_TAB.

Hope it helps....

Cheers,

Sumit

Read only

0 Likes
3,810

Sunit, If I use INSERT INTO  ZTABLE values IT_TAB system gives me an error "you cannot use internal table as workarea" .. what should i do??

LOOP AT it_work INTO wa_work.

     wa_final_scheme-mandt   = sy-mandt.

     wa_final_scheme-schno   = v_schnumber.

     wa_final_scheme-advstar = wa_work-advstar.

     wa_final_scheme-perend  = wa_work-perend.

     wa_final_scheme-amount  = wa_work-amount.

     wa_final_scheme-percent = wa_work-percent.

     APPEND wa_final_scheme to it_final_scheme.

     INSERT INTO zschtab VALUES it_final_scheme.

*    clear wa_final_scheme.

     IF sy-subrc = 0.

     ENDIF.

     COMMIT WORK.

     CLEAR wa_final_scheme.

   ENDLOOP.

Read only

0 Likes
3,810

Hi Yash,

you have passed your work area data, so use like this

LOOP AT it_work INTO wa_work.

     wa_final_scheme-mandt   = sy-mandt.

     wa_final_scheme-schno   = v_schnumber.

     wa_final_scheme-advstar = wa_work-advstar.

     wa_final_scheme-perend  = wa_work-perend.

     wa_final_scheme-amount  = wa_work-amount.

     wa_final_scheme-percent = wa_work-percent.

   

     INSERT INTO zschtab VALUES wa_final_scheme.

Read only

0 Likes
3,810

yes Sanjeev.. I did..

But the question is the sy-subrc remains 4 throught out the looping process but when i see the itab and work area the value is transfered in the final work area....

Do you think this would be causing the problem?

Read only

0 Likes
3,810

Dear Yash,

Try with this variant.

INSERT dbtab FROM TABLE itab.

please check source and target table must have same line type.

Read only

Former Member
0 Likes
3,810

One more thing.

Is it possible that at the starting of the loop the sy-subrc will be equal to 4?

I noticed this at this time that the subrc = 4. though the data is getting appended in the ITAB.

Read only

Former Member
0 Likes
3,810

Hi Yash,

I think the problem with u is in the ztable which u created . First try to enter some data manually in that ztable and check weather data is updating to table. Normally if data element is not properly assigned this type of problem occurs. So i recommend to enter 4 to 5 data in the table from SE11 and check if that update properly.

Regards

Rouank

Read only

0 Likes
3,810

You are right Rounak.

I tried to insert data in the table directly.. System gives me message that

A data record with the specified key already exists

.. Though i tried completely different datas and entered in it... Any solution?????

Read only

0 Likes
3,810

data elements are also properly assigned to the table.. I mean there is not any error in it... otherwise system would have generated some error while activating them.

Read only

0 Likes
3,810

Hi Yash,

Check the following in SE11 where you have created your Table,

In Delivery and Maintenance Tab you have properly assigned Data browser /  Table View Maint .  : As  Display / Maintenance Allowed.

Also make sure you have generated TMG .

Hope this will solve your issue Your Coding doesn't have any problem ... Just work on your table that will solve your issue.

Regards

Rounak.

Read only

0 Likes
3,810

Rounak

Table ZSCHTAB is extendable without limits

Got this warning message

And in the TMG (SM30) I am able to see any fields in which I can insert data...

Read only

0 Likes
3,810

Sorry Correction:

I am NOT able to see any fields in which I can insert data...

Read only

0 Likes
3,810

Can you paste the Screen shot of you table fields?

Read only

0 Likes
3,810

Hi Yash,

Just go through the link and check you have followed the proper procedure while creating your customize table.

Creating Tables -  ABAP Dictionary - SAP Library

Hope by this u can solve ur issue.

Regards

Rounak

Read only

0 Likes
3,810

Thank You Rounak. Actually I made this table in hurry so made this mistake.. But yes I will definitely go through you link.

Read only

0 Likes
3,810

Great Yash.

Congratzz for finding Solution

Have a great Day

Regards

Rounak

Read only

Former Member
0 Likes
3,810

Issue Solved!!!!!!!!!!!

The problem was with the primary key.

let me explain.

When the only primary key was mandt and when I was trying to insert data in the table, system was checking for the primary key and it would remain the same for the client. So I added Scheme number as a primary key and then tried. It is solved.

Thank You guys for your time and guidance..