Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Updating database table with DUPLICATE keys

i have an internal table having data as follows.

emp_id name date proj_id activity_id Hours Remarks

101 Pavan 09.10.2007 123 1 2.00 Coding

101 Pavan 09.10.2007 124 2 1.00 Documentation

102 Raj 09.10.2007 123 3 6.00 Testing

Now i need to update a Ztable with above mentioned data.

The structure of the Ztable is as follows.

Mandt emp_id name date proj_id activity_id Hours Remarks

NOte: i have ticked both check boxes for the field MANDT in table.

Rest didnt select the check boxes.

I believe now the field MANDT alone is a primary key for the z-table.

NOw i have tried with UPDATE/INSERT statments to update the database table.

But instead of inserting all the rows, the system is over writing on the same emp_id row.

Even tried with the statments like INSERT INTO <Ztable> values <Internal table> ACCEPTING DUPLICATE KEYS.

But its not getting inserted as a separate row in the table.

Requirement is to insert the multiple rows in the database table without any over writing activity.

Can anyone give me the code to do this?

Regards

Pavan

Tags:
Former Member
Former Member replied

Hi Pavan,

Please let me know what are the key fields in your Ztable. Try with below code it may help you. change the "Ztablename" as your database table name and I_INTERNAL TABLE as your internal table name. still you are facing the problem please let me know.

  • lock the custom table before updating the table.

CALL FUNCTION 'ENQUEUE_E_TABLE'

EXPORTING

  • MODE_RSTABLE = 'E'

TABNAME = 'ZTABLENAME'

  • VARKEY =

  • X_TABNAME = ' '

  • X_VARKEY = ' '

  • _SCOPE = '2'

  • _WAIT = ' '

  • _COLLECT = ' '

EXCEPTIONS

FOREIGN_LOCK = 1

SYSTEM_FAILURE = 2

OTHERS = 3

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ELSE.

INSERT ZTABLENAME FROM TABLE I_INTERNALTABLE ACCEPTING DUPLICATE KEYS.

COMMIT WORK.

ENDIF.

  • unlock after updating the custom table After updation is done.

CALL FUNCTION 'DEQUEUE_E_TABLE'

EXPORTING

  • MODE_RSTABLE = 'E'

TABNAME = 'ZTABLENAME'

  • VARKEY =

  • X_TABNAME = ' '

  • X_VARKEY = ' '

  • _SCOPE = '3'

  • _SYNCHRON = ' '

  • _COLLECT = ' '

.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question