2013 Aug 09 2:10 AM
Experts,
I am inserting multiple records into database as below,
INSERT DFKKOP FROM TABLE IT_DFKKOP.
Requirement is to capture SY-SUBRC for each record & display it to user(Note: If insert fails, then user wants to take action manually for the same)
One option, that I can think of is to insert 1 record at a time in Loop as below,
Loop at IT_DFKKOP into WA_DFKKOP.
Insert DFKKOP from WA_DFKKOP.
if sy-subrc ne 0.
----> " ls_errorinfo-message = 'Insertion Failed'.
append ls_errorinfo to lt_errorinfo.
else.
----> " ls_errorinfo-message = 'Inserted Successfully'.
append ls_errorinfo to lt_errorinfo.
endif.
Endloop.
Kindly guide me if there is a better efficient option that the above.
Regards,
Aspire
2013 Aug 11 7:14 PM
Hi,
You can capture all the data into the internal table and
You should always use the lock object,
below is the code
if li_DFKKOP is not initial.
call function 'ENQUEUE_E_TABLEE'
exporting
mode_rstable = 'E'
tabname = 'DFKKOP'
exceptions
foreign_lock = 1
system_failure = 2
others = 3.
.
modify DFKKOP from table li_DFKKOP.
call function 'DEQUEUE_E_TABLEE'
exporting
mode_rstable = 'E'
tabname = 'DFKKOP'.
endif.
Experts,
I am inserting multiple records into database as below,
INSERT DFKKOP FROM TABLE IT_DFKKOP.
Requirement is to capture SY-SUBRC for each record & display it to user(Note: If insert fails, then user wants to take action manually for the same)
One option, that I can think of is to insert 1 record at a time in Loop as below,
Loop at IT_DFKKOP into WA_DFKKOP.
Insert DFKKOP from WA_DFKKOP.
if sy-subrc ne 0.
----> " ls_errorinfo-message = 'Insertion Failed'.
append ls_errorinfo to lt_errorinfo.
else.
----> " ls_errorinfo-message = 'Inserted Successfully'.
append ls_errorinfo to lt_errorinfo.
endif.
Endloop.
Kindly guide me if there is a better efficient option that the above.
Regards,
Aspire
2013 Aug 09 3:20 AM
Hi Aspire,
Your method seems alright since you require SUBRC value for each record, but just a disclaimer, in case the Insertion leads to duplicates, the System will dump. If you are sure there won't be Duplicates, you can continue using INSERT else if there are records with same key field values but varied non-key field values, you can use MODIFY statement.
Hope this helps.
Regards,
Vijay
2013 Aug 09 3:24 AM
2013 Aug 09 3:54 AM
Hi Aspire,
I only have a point need share with you.
if the size not very big for DFKKOP, you can get data from DFKKOP again after insert or modify it.
SELECT OPBEL
OPUPW
OPUPK
OPUPZ
FROM DFKKOP
INTO TABLE LT_DFKKOP
FOR ALL ENTRIES IN IT_DFKKOP
WHERE OPBEL = IT_DFKKOP-OPBEL
AND OPUPW = IT_DFKKOP-OPUPW
AND OPUPK = IT_DFKKOP-OPUPK
AND OPUPZ = IT_DFKKOP-OPUPZ.
and now LT_DFKKOP it's successful table.
if you only need success data, then don't need LOOP.
Thinks more...
2013 Aug 11 4:11 PM
Dear Chang,
Thanks a lot for your reply. In my case I want success or error message for every single record. I have implemented the solution of loop thru my records & checking subrc for every single record for which I have shared the code in above thread.
Good Day!
Aspire
2013 Aug 09 4:07 AM
Hi Aspire WF,
Your code is ok.... you can proceed with this code...
Loop at IT_DFKKOP into WA_DFKKOP.
Insert DFKKOP from WA_DFKKOP.
if sy-subrc ne 0.
append ls_errorinfo to lt_errorinfo.
else.
append ls_errorinfo to lt_errorinfo.
endif.
clear WA_DFKKOP.
Endloop.
2013 Aug 09 4:12 AM
Hi.
As per my knowledge, one case where INSERT fails is when record with same primary key(s) is already existing in the table.
My suggestion is
select * from DFKKOP into table tmp_dfkkop for all entries in it_dfkkop
where primary key(s) = it_dfkkop-primary_key(s).
Now display these records for the end-user to take action.
Regards.
2013 Aug 09 4:54 AM
Arun & Ramesh,
Thanks a lot for your replies. As per all your suggestions, I have replaced insert with MODIFY statement. My code looks as below,
Loop at IT_DFKKOP assigning <FS_DFKKOP>.
WA_DFKKOP = <FS_DFKKOP>. " Work area to store old record
<FS_DFKKOP>-XXX = 'New Value'....
Modify DFKKOP from <FS_DFKKOP>.
IF SY-SUBRC EQ 0.
Ls_errorinfo-message = 'Update successful'.
append ls_errorinfo to lt_errorinfo.
Delete DFKKOP from WA_DFKKOP. " Delete Old record as modify statement in my case inserts a new record because I am changing the key field in DFKKOP
else.
Ls_errorinfo-message = 'Update Failed'.
append ls_errorinfo to lt_errorinfo.
endif.
Endloop.
Thanks,
Aspire
2013 Aug 11 7:14 PM
Hi,
You can capture all the data into the internal table and
You should always use the lock object,
below is the code
if li_DFKKOP is not initial.
call function 'ENQUEUE_E_TABLEE'
exporting
mode_rstable = 'E'
tabname = 'DFKKOP'
exceptions
foreign_lock = 1
system_failure = 2
others = 3.
.
modify DFKKOP from table li_DFKKOP.
call function 'DEQUEUE_E_TABLEE'
exporting
mode_rstable = 'E'
tabname = 'DFKKOP'.
endif.
2013 Aug 11 9:25 PM
Palash,
Thanks a lot for your reply. Is it mandatory to lock the table before modifying or inserting records. All these days I have been modifying without this extra check except when I update details for an employee using HR_INFOTYPE_OPERATION
Thanks
Aspire
2013 Aug 12 1:37 AM
It is not mandatory but just common sense.
And why are you writing data to a SAP standard table direcly via insert/modify?
Sougata.
2013 Aug 12 5:55 PM
Hi
Sougata It should be common practice to use lock object.Using lock object data will be consistent and this is rdms rule...
2013 Aug 12 6:07 PM
2013 Aug 13 1:14 AM
Palash,
I did not say its not a common practice to lock/unlock before/after database update - On the contrary, I pointed out that common sense should prevail before and after a programmatic database update. Lock and unlock are not mandatory but they are just good practices - programs still compile correctly if someone did not lock/unlock before database updates...hence it is not "mandatory".
But I still do not understand why a SAP standard table is directly written to via direct insert/modify statements. Is that a "common practice" too?
Sougata.
2013 Aug 13 5:19 AM
Sougata,
Thanks a lot for all your replies.
Actually I am trying to update DFKKLOCKS table & not DFKKOP as mentioned in this thread. I tried couple of standard FMs like Z_CFI_FKK_SAMPLE_1801 & BAPI_CTRACCONTRACTACCOUNT_CHNG to update lock records in DFKKLOCKS table. But,
Z_CFI_FKK_SAMPLE_1801 - Tried with a test program but is not updating the records correctly
BAPI_CTRACCONTRACTACCOUNT_CHNG - Obsolete FM so had to drop this FM
As a last option, I decided to update the standard table directly.
Thanks,
Aspire
2013 Aug 13 6:21 AM
Aspire,
Have you looked at the functions available under Function Group FKLOCK? Have you analysed the Function Module FKK_O_LOCK_METHOD_SAVE?
Sougata.
2013 Aug 13 6:31 AM
Sougata,
Thanks for your reply. I have not looked at it. Will check them now & keep you posted.
Good Day..!
Thanks,
Aspire
2013 Aug 28 12:40 AM
Sougata,
I used FM FKK_O_LOCK_METHOD_SAVE to insert a new record in DFKKLOCKS table. Since i am changing one of the key fields(TDATE), always it inserted a new record rather than updating existing record. So if insert was successful, I deleted the existing record using FKK_S_LOCK_DELETE.
Thanks a lot everyone for all your valuable inputs.
Aspire
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |