10-04-2009 4:05 PM
Hi all again.
I'm practicing JOBS, and I have a program that insert 3 records in a Z table What I do is:
1. Loop to my internal table and then record by record I user the clause INSERT, if sy-subrc eq 0, then COMMIT and write:/ Record added, ELSE. rollback work and write:/ Record not added.
2. When i execute the job via SUBMIT clause, and then I go to the SM37 trx, I can't see the spool list. This happens when I try to add records which were added previously, but if there are new records, I can see the spool list and I don't have problems.
Whys is this happening? I assume that the insert is not possible when the record exist in the Z Table, but I have the rollback and the write, why I can't see the writes?
Can someone explain to me, and let me know how I can solve it?
Thanks
Gaby
10-04-2009 4:56 PM
Hi,
The insert statement fails if the table already contains a row with the same primary key as that you define in the condition of the insert statement. Since you have written the else part as 'Records not added' , it should have been executed if you were trying to insert the already existing records. Try executing the report in foreground and check the sy-subrc value when you try to insert already available records. Also i dont see the use of rollback here since in the else part no record will be inserted. Remove that also and check
Regards,
Vikranth
10-04-2009 4:56 PM
Hi,
The insert statement fails if the table already contains a row with the same primary key as that you define in the condition of the insert statement. Since you have written the else part as 'Records not added' , it should have been executed if you were trying to insert the already existing records. Try executing the report in foreground and check the sy-subrc value when you try to insert already available records. Also i dont see the use of rollback here since in the else part no record will be inserted. Remove that also and check
Regards,
Vikranth
10-04-2009 6:47 PM
Hi Vikranth,
I tried deleting the rollback line. And when I use that in a loop works fine, but when I use this line:
INSERT ztabla_vuelos FROM TABLE ti_vuelos.
if there is a duplicate record so then I see the dump, I debugged the code, and when the point is on the INSERT line, after pressing F5 I see the dump error, and tells me that I',m triying to add a duplicate record -which is true- but i don't know how can avoid that, I would like to show a line like this:
INSERT ztabla_vuelos FROM TABLE ti_vuelos.
IF sy-subrc EQ 0.
COMMIT WORK.
WRITE 😕 'OK '.
ELSE.
WRITE: / 'failed'.
ENDIF.
But i can't get it. How can I solve that?
Thanks
10-04-2009 7:16 PM
If the primary key set already exist, there is not way u can insert another entry with the same key(set). Modify would look if the key exist, if not it will add a new row else.. it will modify the data releavent to that data (primary key)
modify ztabla_vuelos FROM TABLE ti_vuelos.
IF sy-subrc EQ 0.
COMMIT WORK.
WRITE 😕 'OK '.
ELSE.
WRITE: / 'failed'.
ENDIF.
10-04-2009 8:18 PM
I see that. So, I only can use the INSERT clause, when I'm sure that there are no duplicates rows, right? If I'm not sure, I should use Modify clause ?
10-05-2009 12:51 AM
>insert: checks duplicate key entry : if duplicate present : fails
>modify: checks duplicate key entry : if duplicate present : modifies, else: inserts.
hope this helps to clarify
10-05-2009 2:33 AM
10-04-2009 5:01 PM
inspite you want the new values to be updated in the Ztable u can use MODIFY statement. Hit an F1 on modify and look for the help on how to use it.