Application Development 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: 

Modify Statement not making new entry in Custom Table

former_member214915
Participant
0 Kudos

Hello Experts,

         

                    I am getting problem with modify statement, i am modifying the table from internal table ,as i am changing the value of primary key field and keeping all fields of work area as it is so the modify statement not making new entry in Custom table created in data dictionary.

i am pasting my Code as below

data : it_final type table of zschd,

          wa_final type zschd,

          wa_schd type schd.

*it_final contains 4 records so i am changing s_date field which is primary key by t_date

  LOOP AT it_final INTO wa_final'.

        wa_schd-mandt     = sy-mandt.

        wa_schd-s_date  = t_date.

        wa_schd-gewrk     = wa_final-gewrk..

        wa_schd-appt   = wa_final-appt.

.

      

        t_date = t_date + 1.

        APPEND wa_schd TO it_mod.

      ENDLOOP.

     MODIFY  zschd FROM TABLE it_mod .

But after executing this statement sy-subrc becoming 4 and new record is not going to be created,

i am not understanding what is the problem. Please provide solutions.

Regards,

Shahezad

1 ACCEPTED SOLUTION

ThomasZloch
Active Contributor
0 Kudos

ABAP documentation is speaking of SY-SUBRC = 4 in case a unique secondary key would be violated by the MODIFY operation. Is there a unique secondary index for table ZSCHD?


Thomas

16 REPLIES 16

Former Member
0 Kudos

Hi,

What is the initial value of field t_date? I hope the table ZSCHD is having one key field which is S_DATE.

For testing purpose, put a break point on MODIFY statement and check the value of the internal table it_mod and the database table ZSCHD.

Cheers

~Niranjan

bharat_rathod2
Active Participant
0 Kudos

Dear,

please give complete code so we can check and also send table ( zschd )screenshot.

edgar_nagasaki
Contributor
0 Kudos

Hi Muhammad,

Ensure you don't have doubled entries in your internal table it_mod (you can use SORT/DELETE ADJACENT DUPLICATES for this).

Regards,

Edgar

ThomasZloch
Active Contributor
0 Kudos

ABAP documentation is speaking of SY-SUBRC = 4 in case a unique secondary key would be violated by the MODIFY operation. Is there a unique secondary index for table ZSCHD?


Thomas

Former Member
0 Kudos

This message was moderated.

former_member205060
Active Participant
0 Kudos

Dear Shahezad,

I am unable the structure of it_mod. Do the following as mention below :-

1. Define it with same structure as zschd.

2. clear all work area after append structure. (Clear: wa_schd, wa_final)

3. t_date is a screen field or default sate ? t_date data element should same as zschd-s_date. (Hope it has been define with type as dats in domain and not char type )  .

4. Use function module to add days to date.

Regards,

Rahul Singh


prakashjasti
Contributor
0 Kudos

Hi,

Here you have mentioned the type of  wa_schd as,

   wa_schd type schd.

No proper information on it_mod.

APPEND wa_schd TO it_mod.

But i understood that you were trying to modify zschd from it_mod which is of different type

with different key field combination.

MODIFY  zschd FROM TABLE it_mod .

Please check the code.

Regards,

Prakash.

Prakash J

Former Member
0 Kudos

This message was moderated.

former_member288351
Participant
0 Kudos

Dear muhammad,

Please remove TABLE from your modify statement and check

     MODIFY  zschd FROM it_mod .

in place of
     MODIFY  zschd FROM TABLE it_mod .

with regards

vikas pandey

0 Kudos

Hi Vikas,

He is updating the DB Table through internal table, That why he is using "TABLE" Statement . What you have suggested id to modify work area.

Regards,

Rahul Singh

Former Member
0 Kudos

Hi Muhammad.

please try :

LOOP AT it_final INTO wa_final'.

        wa_schd-mandt     = sy-mandt.

        wa_schd-s_date  = t_date.

        wa_schd-gewrk     = wa_final-gewrk..

        wa_schd-appt   = wa_final-appt.

.

     

        t_date = t_date + 1.

        APPEND wa_schd TO it_mod.

          MODIFY  zschd From wa_schd tranporting t_date .

          commit work

      ENDLOOP.

close the thread if issue is resolved.

     regards

     vaibhav

Former Member
0 Kudos

LOOP AT i_tab. 

        i_tab-field = false.  

        MODIFY i_tab.     

ENDLOOP.

since you are modifying within the loop you dont need any addition to the modify statement.

if it were from outside the loop (for some reason) then you need to pass either the index of the record to be updated or the keys to the record.

0 Kudos

Hi Krishna,

The code you mention is to update internal table and he need to update the DB table.

Regards,

Rahul Singh

Clemenss
Active Contributor
0 Kudos

Hi Muhammad,

you can not use MODIFY TABLE to change any existing primary key. In your case I expect the new records (changed primary key) to be inserted, the existing records to remain there. This is a relational database concept: Primary key is always unique and never changed.

Correct way is to first INSERT all records with primary key not existing yet and then delete all records with primary key not wanted.

And, by the way, CLIENT = SY-MANDT is totally useless if the table is client-dependant (First key field is CLIENT(data type CLNT). The database interface will always supply CLIENT = SY-MANDT for all database operations unless addition CLIENT SPECIFIED is given for SELECT/UPDATE/INSERT/MODYFY statement.

Regards

Clemens

former_member214915
Participant
0 Kudos

Hi ,

Thanks to all , i have solved my problem,actually in custom table to which i am updating or modifying ,actually there is one field in custom table which is unique other than primary key

that field value say for e.g. 32 chars long which i have generated automatically for each record in table,so when i am updating custom table from internal table i again need to generate unique value for that field in my program so than that record gets update or modified and sy-subrc becomes 0 after executing modify statement.

so the problem was the field value and uniqueness.

for eg

  LOOP AT it_final INTO wa_final'.

        wa_schd-mandt     = sy-mandt.

        wa_schd-s_date  = t_date.

        wa_schd-gewrk     = wa_final-gewrk..

        wa_schd-appt   = wa_final-appt. "This field has unique value which i have genrated by calling method

.

     

        t_date = t_date + 1.

        APPEND wa_schd TO it_mod.

      ENDLOOP.

     MODIFY  zschd FROM TABLE it_mod .

0 Kudos

So by studying ABAP online help you would have solved this much sooner, see my earlier reply. Please consider this for next time.


Thomas