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: 

How to fill a tablecontrol from internal table

Former Member
0 Kudos

Hi,

i have a dynpro with a table control called INPUT_LIST.

It is possible to enter data manually.

Under this table controll i have a button "FILL". The coding behind this button reads a database table into an internal table.

At the moment this button is clicked i want to display the content of this internal table in the table control.

How could i fill the tablecontrol using ABAP?

Thank you.

Kind regards

Manfred

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Manfred,

This can be achieved by designing the table control with the fields having the same names as that of the fields used in the structure. While designing your table control in the screen painter, press F6 and specify the name of the structure of the internal table that you use in your program and press Get from Program button, you'll get a list of all the elements used in the program. Select the fields that are to be present in the table control and click 'OK' .

You will have to be doing these things.

Suppose if your table control is in screen 9000 and the name of the table control is tabctrl do as shown.

PROCESS BEFORE OUTPUT.
LOOP AT t_tabctrl into x_tabctrl WITH CONTROL tabctrl.
  
ENDLOOP.
*MODULE STATUS_9000.

"where t_tabctrl is the internal table and x_tabctrl is the structure of the internal table.

PROCESS AFTER INPUT.

LOOP AT t_tabctrl.
 
ENDLOOP.
*MODULE USER_COMMAND_9000.

Hope this is helpful.

Cheers,

Vivek.

2 REPLIES 2

former_member184578
Active Contributor
0 Kudos

Hi Mannif.,

pls refer the below program.,

*REPORT demo_dynpro_tabcont_loop_at.*

*CONTROLS flights TYPE TABLEVIEW USING SCREEN 100.*
*DATA: cols LIKE LINE OF flights-cols,*
*lines TYPE i.*

*DATA: ok_code TYPE sy-ucomm,*
      *save_ok TYPE sy-ucomm.*

*DATA: itab TYPE TABLE OF demo_conn.*

      *TABLES demo_conn.*

*SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE itab.*

*LOOP AT flights-cols INTO cols WHERE index GT 2.*
  *cols-screen-input = '0'.*
  *MODIFY flights-cols FROM cols INDEX sy-tabix.*
*ENDLOOP.*

*CALL SCREEN 100.*

*MODULE status_0100 OUTPUT.*
  *SET PF-STATUS 'SCREEN_100'.*
*DESCRIBE TABLE itab LINES lines.*
*flights-lines = lines.*
*ENDMODULE.*

*MODULE cancel INPUT.*
  *LEAVE PROGRAM.*
*ENDMODULE.*

*MODULE read_table_control INPUT.*
  *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 'TOGGLE'.*
      *LOOP AT flights-cols INTO cols WHERE index GT 2.*
        *IF  cols-screen-input = '0'.*
          *cols-screen-input = '1'.*
        *ELSEIF  cols-screen-input = '1'.*
          *cols-screen-input = '0'.*
      *ENDIF.*
  *MODIFY flights-cols FROM cols INDEX sy-tabix.*
*ENDLOOP.*
    *WHEN 'SORT_UP'.*
      *READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.*
      *IF sy-subrc = 0.*
        *SORT itab STABLE BY (cols-screen-name+10) ASCENDING.*
        *cols-selected = ' '.*
  *MODIFY flights-cols FROM cols INDEX sy-tabix.*
      *ENDIF.*
    *WHEN 'SORT_DOWN'.*
      *READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.*
      *IF sy-subrc = 0.*
        *SORT itab STABLE BY (cols-screen-name+10) DESCENDING.*
        *cols-selected = ' '.*
  *MODIFY flights-cols FROM cols INDEX sy-tabix.*
      *ENDIF.*
    *WHEN 'DELETE'.*
      *READ TABLE flights-cols INTO cols* 
                              *WITH KEY screen-input = '1'.*
      *IF sy-subrc = 0.*
        *LOOP AT itab INTO demo_conn WHERE mark = 'X'.*
          *DELETE itab.*
*ENDLOOP.*
      *ENDIF.*
*ENDCASE.*
*ENDMODULE.*

**=== this need to add in module pool flow logic*

*PROCESS BEFORE OUTPUT.*
  *MODULE status_0100.*
  *LOOP AT itab INTO demo_conn WITH CONTROL flights.*
*ENDLOOP.*

*PROCESS AFTER INPUT.*
  *MODULE cancel AT EXIT-COMMAND.*
  *LOOP AT itab.*
    *MODULE read_table_control.*
*ENDLOOP.*
  *MODULE user_command_0100.*

hope this ll help u., reply if u need some more clarifications.,

Thanks & Regards

Kiran

Former Member
0 Kudos

Hi Manfred,

This can be achieved by designing the table control with the fields having the same names as that of the fields used in the structure. While designing your table control in the screen painter, press F6 and specify the name of the structure of the internal table that you use in your program and press Get from Program button, you'll get a list of all the elements used in the program. Select the fields that are to be present in the table control and click 'OK' .

You will have to be doing these things.

Suppose if your table control is in screen 9000 and the name of the table control is tabctrl do as shown.

PROCESS BEFORE OUTPUT.
LOOP AT t_tabctrl into x_tabctrl WITH CONTROL tabctrl.
  
ENDLOOP.
*MODULE STATUS_9000.

"where t_tabctrl is the internal table and x_tabctrl is the structure of the internal table.

PROCESS AFTER INPUT.

LOOP AT t_tabctrl.
 
ENDLOOP.
*MODULE USER_COMMAND_9000.

Hope this is helpful.

Cheers,

Vivek.