2014 Mar 08 5:11 AM
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.
2014 Mar 08 6:37 AM
Hi Yash,
what is this /vcrebate/schtab, is this your table, simply use
INSERT your ztable FROM it_final_scheme.
2014 Mar 08 6:40 AM
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.
2014 Mar 08 6:44 AM
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).
2014 Mar 08 7:00 AM
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.
2014 Mar 08 7:05 AM
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.
2014 Mar 08 7:09 AM
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.
2014 Mar 08 7:14 AM
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.
2014 Mar 08 7:24 AM
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.
2014 Mar 08 7:29 AM
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.
2014 Mar 08 7:31 AM
Yes Sanjeev I did the same..
Used standard table also.. But the same error.
2014 Mar 08 7:37 AM
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
2014 Mar 08 7:43 AM
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.
2014 Mar 08 7:47 AM
2014 Mar 08 7:48 AM
After unchecking this the program gave an error of Unicode.
So i checked it.
2014 Mar 08 7:49 AM
Its problem in the declarations, plz check your data throughtly
2014 Mar 08 7:57 AM
I copied and pasted all the fields from the database itself.
2014 Mar 08 8:20 AM
Error solved.
I added MANDT in this ITAB.
Another runtime error generated Error in internal table in screen
2014 Mar 08 8:39 AM
Hi Yash,
i told you earlier that please check your data consistency with your databse table,
now what is the issue with screen
2014 Mar 08 8:43 AM
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.
2014 Mar 08 8:47 AM
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.
2014 Mar 10 9:07 AM
I added mandt field in the wa.
But still the sy-subrc becomes 4 when the insert command is triggered.
2014 Mar 08 8:33 AM
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
2014 Mar 10 9:06 AM
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.
2014 Mar 10 9:09 AM
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.
2014 Mar 10 9:22 AM
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?
2014 Mar 10 9:31 AM
Dear Yash,
Try with this variant.
INSERT dbtab FROM TABLE itab.
please check source and target table must have same line type.
2014 Mar 10 9:12 AM
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.
2014 Mar 10 9:20 AM
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
2014 Mar 10 9:29 AM
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?????
2014 Mar 10 9:31 AM
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.
2014 Mar 10 9:40 AM
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.
2014 Mar 10 10:10 AM
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...
2014 Mar 10 10:13 AM
Sorry Correction:
I am NOT able to see any fields in which I can insert data...
2014 Mar 10 10:27 AM
2014 Mar 10 10:35 AM
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
2014 Mar 10 10:49 AM
Thank You Rounak. Actually I made this table in hurry so made this mistake.. But yes I will definitely go through you link.
2014 Mar 10 10:54 AM
Great Yash.
Congratzz for finding Solution
Have a great Day
Regards
Rounak
2014 Mar 10 10:33 AM
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..