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

Regarding modify statement in module pool

Former Member
0 Likes
1,566

hi,

i have table control with header and item data......i.e for 1 record in header data there will n number of items .....while updaing my ztable in data dictionary it is showing only the last record which i have entered in the table control along with the header data.

LOOP AT it_shpit INTO wa_shpit.

lv_tabix = sy-tabix.

CLEAR wa_update.

wa_update-mandt = sy-mandt.

  • READ TABLE it_shphd INTO wa_shphd INDEX lv_tabix.

  • if sy-subrc eq 0.

*header

wa_update-mtart = wa_shphd-mtart.

wa_update-lifnr = wa_shphd-lifnr.

wa_update-zperson = wa_shphd-zperson.

  • endif.

*item

wa_update-zshipno = wa_shpit-zshipno.

wa_update-ebeln = wa_shpit-ebeln.

wa_update-xblnr = wa_shpit-xblnr.

wa_update-bldat = wa_shpit-bldat.

wa_update-zunits = wa_shpit-zunits.

wa_update-rmwwr = wa_shpit-rmwwr.

wa_update-waers = wa_shpit-waers.

APPEND wa_update TO it_update.

MODIFY zmmship_track FROM TABLE it_update.

ENDLOOP.

can anyone explain where i m going wrong........

9 REPLIES 9
Read only

Former Member
0 Likes
1,160

Hi,

Just check whether all your table control data's are appended your internal table,

if not try this in the pai loop and endloop,

make a module in the pai with the loop and endloop.

IF NOT x_assignment-employee_id IS INITIAL AND NOT x_assignment-activity IS INITIAL.

MODIFY t_assignment FROM x_assignment INDEX tablecontrol-current_line.

IF sy-subrc NE 0.

APPEND x_assignment TO t_assignment.

ENDIF.

ENDIF.

ENDIF.

Read only

Former Member
0 Likes
1,160

Hi,

What are the keys in your database table ? Are they the same as in the UI and the Table Control ?

Also make a small addition to the modify statement in the code.

MODIFY zmmship_track FROM TABLE it_update ACCEPTING DUPLICATE KEYS.

This will insert the entries even they are duplicate. If the problem persists, then put a debug point in the code and check. Have a look at the MODIFY Syntax for a more detailed description.

Let me know if you need any more details.

Thanks,

Samantak.

Read only

Sm1tje
Active Contributor
0 Likes
1,160

It is kind of hard to say what is going wrong, but what strikes me as a bit odd is the fact that you are using the MODIFY statement WITHIN the LOOP - ENDLOOP. So in every loop pass your are appending the internal table and use this to modify the Z-table. It would be more logical (read: better) to do this outside of the LOOP after collecting all the items in the internal table.

Another thing, which might not even be a problem if the program does this check somewhere else, but what I'm also missing is the check if these items actually belong to the same header data. Normally, you LOOP over header data and retrieve via another loop at the item data, all ITEMS for particular HEADER.

Read only

Former Member
0 Likes
1,160

hi

before looping the internal table it_shpit find out the records in it

if it_shpit[] is not initial.

endif.

then try to modify or update the records into the database.

Regards

Read only

0 Likes
1,160

hi murali,

can you please explain it clearly like what i have to do exactly..........

if it_shpit[] is not initial.

describe table it_shpit[] lines line.

endif.

modify ztab from table it_shpit.

loop it_shpit........

endloop...

this is what you r expecting me to do?

Read only

0 Likes
1,160

If I am not wrong he is asking you to check if the internal table has got entries in it. If there are entries then modify the data to the database table else ignore it.

The best and the simplest way is to do a loop at the internal table take the records to the header line or the work area and then inside the loop Insert or Modify the records to the Database table.

Regards,

S.Dakshna Nagarnatam,

Read only

0 Likes
1,160

hi dakshna,

even i did in your way but the last record onli it is getting updated in database...........all the other records are not updating.........

Read only

0 Likes
1,160

Hello Jut Make the small changes to your existing code.

LOOP AT it_shpit INTO wa_shpit.

lv_tabix = sy-tabix.

CLEAR wa_update.

wa_update-mandt = sy-mandt.

  • READ TABLE it_shphd INTO wa_shphd INDEX lv_tabix.

  • if sy-subrc eq 0.

*header

wa_update-mtart = wa_shphd-mtart.

wa_update-lifnr = wa_shphd-lifnr.

wa_update-zperson = wa_shphd-zperson.

  • endif.

*item

wa_update-zshipno = wa_shpit-zshipno.

wa_update-ebeln = wa_shpit-ebeln.

wa_update-xblnr = wa_shpit-xblnr.

wa_update-bldat = wa_shpit-bldat.

wa_update-zunits = wa_shpit-zunits.

wa_update-rmwwr = wa_shpit-rmwwr.

wa_update-waers = wa_shpit-waers.

APPEND wa_update TO it_update.

MODIFY zmmship_track FROM wa_update. "changes done on this line

COMMIT WORK. " Added a new line

ENDLOOP.

Before modify just put this code if it doesn't work.

SELECT *

from zmmship_track

where primary key 1 = wa_update-<field1>

and primary key 2 = wa_update-<field2>.

if sy-subrc ne 0.

MODIFY zmmship_track FROM wa_update. "changes done on this line

COMMIT WORK. " Added a new line

else.

Message 'Record already Exits' type 'I'.

endif.

Hope this solves your issue.

Read only

Former Member
0 Likes
1,160

Hi,

The best and the simplest way to achive this would be; to take the values record by record from the table control keep it in a work area and then append it to the internal table.

After that you when the SAVE button is pressed, you can do a loop at that internal table take it to a work area and then Insert it or Modify it to the Database table.

consider the following is the code written in the PAI of the screen's flow logic.

PROCESS AFTER INPUT.

LOOP AT aloc_tab .

MODULE aloc_tab_mod.

ENDLOOP.

MODULE user_command_1000.

This is present in an include file for the program.

INCLUDE FILE.

MODULE aloc_tab_mod.

CLEAR wa_aloc.

wa_aloc-mandt = sy-mandt.

wa_aloc-empid = zaloc-empid.

wa_aloc-project = zproj-project.

APPEND wa_aloc TO aloc_tab.

ENDMODULE.

MODULE user_command_1000.

CASE SY-UCOMM.

WHEN 'F_SAVE'.

CLEAR wa_aloc.

LOOP AT aloc_tab INTO wa_aloc.

MODIFY zaloc FROM wa_aloc.

ENDLOOP.

ENDCASE.

ENDMODULE.

Thanks and Regards,

S.Dakshna Nagaratnam.