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

Inserting values into DDIC table from program

Former Member
0 Likes
3,148

Hello Experts,

I'm trying to insert the values into Data Dictionary table from a program.

It is allowing only first row.

When I try to add the second row it is not taking the values.

I'm using the statement as

INSERT INTO ZANX1 <table name> VALUES W_ANNXR <work area>.

After this statement sy-subrc = 4.

Please help me.

Thank you..

Satya

5 REPLIES 5
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
1,432

Hi Satya

What is key field ZANX1 if key field is same in both iteration it will not allow.

Nabheet

Read only

0 Likes
1,432

Nabheet and Sivasamy..

Thank you for your immediate solution..

Read only

arivazhagan_sivasamy
Active Contributor
0 Likes
1,432

Hi Satya,

Use MODIFY <table name> FROM <work area.

If records are already exist, it will change otherwise it will create new record.

Arivazhagan S

Read only

Former Member
0 Likes
1,432

Hii Satya,

Seems that the data base table contains the same records with the key fields.

So, before using insert statement , first sort your internal table with the key fields.Then delete duplicate records from internal table by using DELETE ADJACENT DUPLICATES FROM <itab COMPARING <keyfields by which sorted itab>.

NOTE: If your database table ZANSX1 has two key fields then while sorting the internal table specify all those key fields.

then finally use INSERT statement.

Alternate Suggestion:

As you are inserting data one by one at a time into database table from work area by looping your internal table into work area, you can insert all rows in a single INSERT statement by the below statement.

INSERT ZANX1 FROM TABLE <your internal table name>.

If you doubt  about the duplicates entries, then you can add ACCEPTING DUPLICATE KEYS.

You can also go with MODIFY statement as it will work as a dual.

If the records exist with same keys then it will modify the rows otherwise will insert new row into the database table.

regards

Syed

Read only

Former Member
0 Likes
1,432

If your second record has the same key field values it will fail due to primary key duplication. Using MODIFY will allow you to insert the record with same primary key but will edit the first record with second in the table.