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: 

Table Control

Former Member
0 Kudos
152

Dear all,

I have a table control congaing 4 rows, now, if I select one row on that table control, that row have to add to my ITAB.

Could anybody send me the sample code please?

Regards,

Joshu.

3 REPLIES 3

Former Member
0 Kudos
34

On the PBO:

loop at itab with control tabella cursor tabella-current_line.

module get_looplines.

endloop.

On the PAI:

loop at itab.

field itab-mark module modify_itab on request.

endloop.

Module 'modify_itab' contain this code:

modify itab index tabella-current_line.

Gianluca

Former Member
0 Kudos
34

Hi,

Check this link for sample code for Table Control

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.highlightedcontent?documenturi=...CodeSamples/TableControlin+ABAP.pdf

Regards,

Anjali

jayanthi_jayaraman
Active Contributor
0 Kudos
34

Hi,

Check these links.

http://members.aol.com/_ht_a/skarkada/sap/table_control/table_control.htm

http://www.sappoint.com/abap/dptc1.pdf

This is sample code for table control.

The following example processes a table control with LOOP with parallel loop using an internal table. By using function codes you can sort columns and delete rows from the internal table. The ready for input status of the table control fields is controlled using a function code.

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.

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, columns 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 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.

A loop is executed at PBO and PAI using the table control FLIGHTS and is also executed using the internal table ITAB of the ABAP program. During the PBO loop, no module is called to fill the table control from table ITAB of the ABAP program. However, during the PAI loop, a module is called to modify table ITAB.

At PBO the component LINES of control structure FLIGHTS is filled explicitly with the current number of rows of the internal table before the PBO loop to install the scroll bar of the table control.

During the PBO loop, in the module FILL_TABLE_CONTROL the work area DEMO_CONN is filled with values from the internal table, where the row index corresponds to the current row of the table control.

During the PAI loop, the rows of the internal table, whose row index corresponds to the current row of the table control, are overwritten with the contents of the work area DEMO_CONN. User input is transferred from the input fields of the control to the internal table. In particular, the internal table also contains a flag in the column MARK to indicate whether the row of the table control is selected or not.

After the PAI loop, user input is processed in the module USER_COMMAND. The GUI status SCREEN_100 provides the appropriate function codes.

When the program is called not all of the fields in the table control are ready for input. The static specifications of the table control in the Screen Painter are modified before CALL SCREEN in the program. The system uses the table COLS in control structure FLIGHTS. All columns with a column position larger than two are set to not ready for input status in a loop using the table FLIGHT-COLS. By choosing the function code TOGGLE, you can change the ready for input status of the columns.

The function codes SORT_UP and SORT_DOWN allow you to sort selected columns of the internal table ITAB ascending or descending. The static settings of the table control allow you to select only a single column. The selected column is derived from the internal table FLIGHT-COLS. The name of the sort criteria in the SORT statement is determined dynamically from the component COLS-SCREEN-NAME. The prefix DEMO_CONN- must be removed using an offset specification. After sort the selection is undone, and the component SELECTED in table FLIGHT-COLS is assigned a blank character.

You can delete selected rows from the internal table ITAB using the function code DELETE. First the system checks whether the fields of the table control are ready for input. Then all selected rows are deleted in a loop using the internal table ITAB. Since the table control is read again from the internal table in the PBO loop, the rows on the screen are deleted.

Hope this helps.

Regards,

J.Jayanthi