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

about LOOP statement in PAI when working on a table control

Former Member
0 Likes
4,881

I am working on a table control.

Here's the part of the logic.



LOOP AT gt_xxx_scr. "internal table related to the table control

    MODULE modify_data.

ENDLOOP.

MODULE modify_data is used to modify or append when the user makes some changes on TC.

The TC displayed correctly at the first place.

But after gt_xxx_scr was changed but make NO change on the TC,

the logic did go into the LOOP that makes the TC displayed incorrectly.

I think that it should not go into the loop when no change is made on the TC.

I am working on a table control.

Here's the part of the logic.



LOOP AT gt_xxx_scr. "internal table related to the table control

    MODULE modify_data.

ENDLOOP.

MODULE modify_data is used to modify or append when the user makes some changes on TC.

The TC displayed correctly at the first place.

But after gt_xxx_scr was changed but make NO change on the TC,

the logic did go into the LOOP that makes the TC displayed incorrectly.

I think that it should not go into the loop when no change is made on the TC.

21 REPLIES 21
Read only

Former Member
0 Likes
3,626

Hi Ming Yu,

For a table control, if you change or not it will always go into the loop when there is some user action that occurs and that is how module pool program works. So you need to do the appending and modifying data in a proper way.

Thanks,

Read only

0 Likes
3,626

For the first time that internal table gets the content, the system doesn't go into the LOOP logic.

And I have tried before(as far as I remembered), if you don't make any change on TC(like enter some values onto the TC), the logic will skip the LOOP.

Read only

Former Member
0 Likes
3,626

Hi

in module which you hae writen for midiying the TC write proper logic.

MODIFY t_tc FROM w_tc INDEX tbc-current_line [TRANSPORTING <f1> <f2> .. ].

    IF sy-subrc <> 0.

      APPEND w_tc TO t_tc.

    ENDIF.

regards

laxman

Read only

0 Likes
3,626

Yes, I write this in the MODULE modify_data.

But the problem is that when internal table's content is changed, the value of 't_tc' is last internal table's value.

That makes modify and append work incorrectly.

Read only

0 Likes
3,626

Perhaps you need to refresh the screen. Is it for some ALV module pool program or generic one. If its ALV module pool program then we do have system field to refresh the screen.

Read only

0 Likes
3,626

It's just a common Module Pool program.

Which confuses me is, after 'LOOP AT gt_xxx_scr'

the work area is not the first record of current gt_xxx_scr, but a certain record of last internal table's.

Read only

0 Likes
3,626

The loop at PAI is only loop through the records that you are currently seeing in table control.

So this is mandatory that you must specify index while modifying.

MODIFY it FROM wa INDEX tc-current_line.

IF sy-subrc <> 0.

APPEND wa TO it.

ENDIF.

Read only

0 Likes
3,626

Yes, I do specify the index.

But the point is, the internal table has already been changed and it doesn't need to go into the LOOP.

If it goes into the LOOP, and execute:

MODIFY it FROM wa INDEX tc-current_line.

IF sy-subrc <> 0.

APPEND wa TO it.

ENDIF.

This will change the content of the internal table and make display wrong after PBO.

Read only

0 Likes
3,626

So rather than modifying through table control you have another code for it?

Keep those piece of code after Loop... endloop.

And if you don't want this..

MODIFY it FROM wa INDEX tc-current_line.

IF sy-subrc <> 0.

APPEND wa TO it.

ENDIF.

comment them..

Read only

0 Likes
3,626

Hi, I have worked this out.

Actually, the change of the internal table should be run after LOOP.

Just like:

LOOP AT gt_xxx_scr. "internal table related to the table control

    MODULE modify_data.

ENDLOOP.

MODULE get_data_to_internal_table.

The LOOP here is different from common ones, it reads the line content from the table control rather than reads from the internal table.

Anyway, thank you for your help.

Read only

0 Likes
3,626

By the way, you can either write ' get_data_to_internal_table.' in PAI or in PBO, in this case, it is triggered by a button, so I wrote this in PAI.

Read only

0 Likes
3,626

May i ask, why do you want a additional module for modifying internal table? What is the purpose of table control?

Normally the records seeing in table control can be manipulated from loop at PBO(before display)

or loop at PAI(after display, to catch the changes made by user).

Read only

0 Likes
3,626

Hi,

Because there is a search criteria, every time the search criteria changes, the internal table should be changed also no matter if table control is changed or not.

It's like a RESET function, not just Modify or Add rows in the table control.

Read only

0 Likes
3,626

replace the loop inside MODULE get_data_to_internal_table with ....


do.

read it_tab into wa_tab index sy-index.

if sy-subrc = 0.

*****code to reset

else.

exit.

endif.

enddo.

Read only

0 Likes
3,626

But editing table control is also needed, if sy-subrc = 4 in your case, you don't know the new record is from the new internal table or it is just a new row from table control entered by a user.

Read only

former_member202818
Active Contributor
0 Likes
3,626

Hi Ming,

The Loop at PBO for putting data into TC from internal table.

The Loop at PAI  for getting data from TC into internal table.

For more ...

Regards

SP

Read only

Pavithra_madhu
Participant
0 Likes
3,626

Hi,

in screen use workarea.. then if only changes are there go inside MODULE IT_CARDLIST_MODIFY ON CHAIN-REQUEST

LOOP AT IT_CARD_LIST.

     CHAIN.

       FIELD WA_CARD_LIST-CB.

       FIELD WA_CARD_LIST-YMTCARD.

       FIELD WA_CARD_LIST-YMTNO.

       FIELD WA_CARD_LIST-MATNR.

       FIELD WA_CARD_LIST-MAKTX.

       FIELD WA_CARD_LIST-CHARG.

       MODULE IT_CARDLIST_MODIFY ON CHAIN-REQUEST.

     endchain.

   ENDLOOP.



In PAI


MODULE IT_CARDLIST_MODIFY INPUT.

    

***     if need condition add here before modify     

MODIFY IT_CARD_LIST

                 FROM WA_CARD_LIST

                 INDEX IT_CARDLIST-CURRENT_LINE.



ENDMODULE.



Is this u want.

Read only

0 Likes
3,626

Hi, does it mean only if table control has been changed, then go inside the LOOP?

But it seems that it still has some problems, if you change the internal table and table control both, yet you don't want LOOP is executed.

Read only

0 Likes
3,626

Hi,

if table control has been changed only go inside the MODULE IT_CARDLIST_MODIFY ON CHAIN-REQUEST. otherwise just go through the loop and nothing will be updated.

can you explain ur problem with coding or explain more ??

Read only

0 Likes
3,626

There is some search criteria and a button on the scree and after search criteria is changed and button is clicked, data is fetched from the database and go into the internal table.

This logic, as far as I consider, has nothing to do with the LOOP/chain.

Read only

0 Likes
3,626

I thought you want to update table control value ...

can you add screen shot?