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

MODIFY statement does not work

Former Member
0 Likes
8,469

Hi,

I am using

MODIFY <DB Table> FROM TABLE <ITAB>.

ITAB has a single line that does not exist in DB table. But still it does not create a new record in DB table.

The sy-subrc is 0.

COuld some one please help me figure out why this is not working.

Thank you.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
5,540

A single line - are you sure it's in the table and not just the header?

Rob

15 REPLIES 15
Read only

Former Member
0 Likes
5,540

itab is the same structure/type as the database table? itab contains the client/mandt value? Always works for me...

Read only

0 Likes
5,540

Hi,

I have the MANDT field in the table and ITAB.

ITAB is of the type as that of the internal table. So no type difference.

I have even tried specifying CLIENT SPECIFIED.

The sy-subrc is ZERO but this record does not get inserted...

Any thoughts...

Thank you.

Read only

0 Likes
5,540

F1 Help excerpt:

Alternative 2 ... FROM TABLE itab

Effect

If an itab internal table is specified, the system processes all lines in the internal table according to the rules for the wa work area. The line type of the internal table has to meet the requirements for use in Open SQL statements.

If the change to a line in the internal table would lead to a double entry in a unique secondary index, the corresponding line is not inserted and sy-subrc is set to 4. If the internal table is empty, sy-subrc is set to 0. The sy-dbcnt system field is always set to the number of lines that were actually processed.

Also check the sy-dbcnt?

Kind regards,

Robert

Read only

Former Member
5,540

'MODIFY' statement checks if there is an entry with the same primary key in the database table and makes corresponding changes. If the primary key value exists, it replaces, if not, it creates one. Make sure your primary key has proper values in internal table.

Read only

0 Likes
5,540

Thank you. That solved my issue as well.

Read only

Former Member
0 Likes
5,541

A single line - are you sure it's in the table and not just the header?

Rob

Read only

0 Likes
5,540

This is the code that I am trying to execute:

DATA: gt_temp LIKE TABLE OF ztemp,

wa_temp TYPE ztemp.

wa_temp-mandt = sy-mandt.

wa_temp-zplatformkey = 'AT'.

wa_temp-zplatformacctid = '597'.

wa_temp-lifnr = '0013650035'.

APPEND wa_temp TO gt_temp.

BREAK-POINT.

MODIFY ztemp FROM TABLE gt_temp .

BREAK-POINT.

This record does not exist in the table but still, it does not get updated.

SY-SUBRC is 0. SY-DBCNT is 1 and SY-TABIX is 1.

There is another keyfield which I am sending it as BLANK. There are entries with field as blank in the table, but we do not have this key combination record in the table.

Read only

0 Likes
5,540
BREAK-POINT.

MODIFY ztemp FROM TABLE gt_temp .

" add this:
COMMIT WORK.

BREAK-POINT.

Regards, Sebastian

Read only

0 Likes
5,540

If sy-subrc = 0 and sy-dbcnt = 1, then a record was created. Go to SE16 and search the table with

zplatformkey = 'AT'. There should be something there.

Rob

Read only

0 Likes
5,540

I had this in my mind, but I was like "NO NEED TO COMMIT AFTER A MODIFY TABLE" as I have never done this in my 5 years of ABAP development.

I was wrong...

Thank you Sebastian... COMMIT work helped...

But isnt this weird?????????????????

My apologies if I sound like a fool.. But I have never done a commit after a modify table in my life...

Read only

0 Likes
5,540

No Rob, no records in the table... COMMIT worked... really freaked out now..

Read only

0 Likes
5,540

WEre you looking at the table in SE16 after the break-point, but before the program finished??

Rob

Read only

0 Likes
5,540

No Rob, I was very careful. I had a friend of mine look into this as well.

Any idea why I have to specify a COMMIT work explicitly?

Thank you.

Read only

Former Member
0 Likes
5,540

Hi,

Try reading the itab into work area.

Then modify DB Tab from work area.

Regards,

Read only

former_member196064
Active Participant
0 Likes
5,540

hmmm... I don't use Modify. I use Update <dbtabname> from <workarea>