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

how to loop on table control

Former Member
0 Likes
7,621

hi experts,

i have changed something in my table control with wizard. and i am trying to move all the contents from my table control to internal table. how to do that. plz resolve my pbm.

thnaks in advance,

1 ACCEPTED SOLUTION
Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
3,289

Hi Himabindu,

Say you have a table control on screen 1010.

On the screen, for table control keep the names of the input/ouput fields as 'itab-field_1', 'itab-field_2' and so on (in the same way the internal table holds the records).

In the flow logic of screen 1010, write:-


PROCESS BEFORE OUTPUT.
  MODULE status_1010.

  LOOP WITH CONTROL po_tab. "po_tab is the name of the table control on the screen 1010
    MODULE pass_data. "module for writing data into the table control
  ENDLOOP.

PROCESS AFTER INPUT.
  MODULE user_command_1010.

  LOOP WITH CONTROL po_tab. "po_tab is the name of the table control on the screen 1010
    MODULE modify_data. "module used to modify data from table control into the internal table
  ENDLOOP.

For PBO, in the module 'pass_data', write code:-


MODULE pass_data OUTPUT.
  READ TABLE itab INDEX po_tab-current_line. "do display records in each line
ENDMODULE.

For PAI, in the module 'modify_data', write code:-


MODULE modify_data INPUT.
  MODIFY itab INDEX po_tab-current_line. "used to modify the data from table control on screen into the internal table
ENDMODULE.                 " DISPLAY_DATA  INPUT

This will make modification from the table control into the internal table.

Then, you can use this internal table as per your requirements.

Hope this solves your problem.

Thanks & Regards

Tarun Gambhir

9 REPLIES 9
Read only

Former Member
0 Likes
3,289

If you have created Table control through wizard it must have already created a LOOP AT tab_control. ENLOOP. in the PBO.

Each line in table_control can be looped through in PBO as well as PAI through LOOP / ENDLOOP.

Read only

Former Member
0 Likes
3,289

LOOP [AT itab INTO wa CURSOR top_line FROM n1 TO n2]

WITH CONTROL contrl.

...

ENDLOOP.

Read only

Former Member
0 Likes
3,289

Hi

In PBO

loop at itab with control tc.

endloop.

in PAI

loop at itab.

module modify_itab.

endloop

in program

module modify_itab.

describe table itab lines tc-lines.

if tc-current_line > tc-lines

append itab.

else.

modify itab index tc-current_line.

endif.

endmodule.

Please make sure the fields(internal table) you declared on the screen and the internal table declared in the program are one and same ( otherwise you need to pass the data explicitly)

Regards

Ramc

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
3,290

Hi Himabindu,

Say you have a table control on screen 1010.

On the screen, for table control keep the names of the input/ouput fields as 'itab-field_1', 'itab-field_2' and so on (in the same way the internal table holds the records).

In the flow logic of screen 1010, write:-


PROCESS BEFORE OUTPUT.
  MODULE status_1010.

  LOOP WITH CONTROL po_tab. "po_tab is the name of the table control on the screen 1010
    MODULE pass_data. "module for writing data into the table control
  ENDLOOP.

PROCESS AFTER INPUT.
  MODULE user_command_1010.

  LOOP WITH CONTROL po_tab. "po_tab is the name of the table control on the screen 1010
    MODULE modify_data. "module used to modify data from table control into the internal table
  ENDLOOP.

For PBO, in the module 'pass_data', write code:-


MODULE pass_data OUTPUT.
  READ TABLE itab INDEX po_tab-current_line. "do display records in each line
ENDMODULE.

For PAI, in the module 'modify_data', write code:-


MODULE modify_data INPUT.
  MODIFY itab INDEX po_tab-current_line. "used to modify the data from table control on screen into the internal table
ENDMODULE.                 " DISPLAY_DATA  INPUT

This will make modification from the table control into the internal table.

Then, you can use this internal table as per your requirements.

Hope this solves your problem.

Thanks & Regards

Tarun Gambhir

Read only

Former Member
0 Likes
3,289

Hi,

Just go through this link.This is exactly what you want.

http://help.sap.com/erp2005_ehp_04/helpdata/EN/fc/eb381a358411d1829f0000e829fbfe/frameset.htm

Regards:

Alok Bansal

Read only

Former Member
0 Likes
3,289

HI,

suppose u have a table control on the screen 9000.

and the name name of the table is TABCOl ok

boldPBO


LOOP WITH CONTROL TABCOl.
    MODULE PASS_DATA.
    
  ENDLOOP.

*bold*PAI

LOOP WITH CONTROL TABCOl.

MODULE modify_data.

 ENDLOOP.



MODULE modify_data INPUT.
  MODIFY itab INDEX tabcol-current_line. "used to modify the data from table control on screen into the internal table
ENDMODULE.                 " DISPLAY_DATA

Read only

Former Member
0 Likes
3,289

This message was moderated.

Read only

Former Member
0 Likes
3,289

Hello,

To loop on internal table in the flow logic of the screen where you have created your table control,

You have to write:

In PBO Event write:

Loop with control (table control name).

create one module here to read the data from internal table into the table control i.e,

Module itab_Data.

Endloop.

This module itab_data will read the records from the internal table into each index of table control when we write

Read table itab index (table control name)-current_line,

inside that module.

here current line works like the each index value of the table control,

and itab is the internal table created which is populated with the contents from the database table.

In the PAI Event write:

Loop with Control (table control name).

Module Modify .

Endloop.

In the module modify,

You have to modify the contents of your itab according to the operations performed on your table control.

i.e,

In this module you have to write:

Modify itab index (table control name)-current_line,

with this itab contents are modified with respect to your table control operations.

Hope this solves your problem .

Thanks

Read only

Former Member
0 Likes
3,289

Hi,

check this code for reference

CONTROLS flights TYPE TABLEVIEW USING SCREEN 100.

DATA: ok_code TYPE sy-ucomm,

save_ok TYPE sy-ucomm.

DATA: itab TYPE TABLE OF demo_conn,

fill TYPE i.

TABLES demo_conn.

DATA: lines TYPE i,

limit TYPE i.

SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE itab.

CALL SCREEN 100.

MODULE status_0100 OUTPUT.

SET PF-STATUS 'SCREEN_100'.

DESCRIBE TABLE itab LINES fill.

flights-lines = fill.

ENDMODULE.

MODULE fill_table_control OUTPUT.

READ TABLE itab INTO demo_conn INDEX flights-current_line.

ENDMODULE.

MODULE cancel INPUT.

LEAVE PROGRAM.

ENDMODULE.

MODULE read_table_control INPUT.

lines = sy-loopc.

MODIFY itab FROM demo_conn INDEX flights-current_line.

ENDMODULE.

MODULE user_command_0100 INPUT.

save_ok = ok_code.

CLEAR ok_code.

CASE save_ok.

WHEN 'NEXT_LINE'.

flights-top_line = flights-top_line + 1.

limit = fill - lines + 1.

IF flights-top_line > limit.

flights-top_line = limit.

ENDIF.

WHEN 'PREV_LINE'.

flights-top_line = flights-top_line - 1.

IF flights-top_line < 0.

flights-top_line = 0.

ENDIF.

WHEN 'NEXT_PAGE'.

flights-top_line = flights-top_line + lines.

limit = fill - lines + 1.

IF flights-top_line > limit.

flights-top_line = limit.

ENDIF.

WHEN 'PREV_PAGE'.

flights-top_line = flights-top_line - lines.

IF flights-top_line < 0.

flights-top_line = 0.

ENDIF.

WHEN 'LAST_PAGE'.

flights-top_line = fill - lines + 1.

WHEN 'FIRST_PAGE'.

flights-top_line = 0.

ENDCASE.

ENDMODULE.

A resizable table control called FLIGHTS is defined. The fields of the table control are transferred from the structure DEMO_CONN in the ABAP Dictionary. The first two columns are lead columns. The corresponding fields are output fields. A title bar, column headers, and a selection column are created. The component MARK of type character with length 1 from structure DEMO_CONN is assigned to the selection column. You can select one column and several lines.

It has the following flow logic:

PROCESS BEFORE OUTPUT.

MODULE status_0100.

LOOP WITH CONTROL flights.

MODULE fill_table_control.

ENDLOOP.

PROCESS AFTER INPUT.

MODULE cancel AT EXIT-COMMAND.

LOOP WITH CONTROL flights.

MODULE read_table_control.

ENDLOOP.

MODULE user_command_0100.