Various attributes and events in Table Control

Source: Internet
Author: User

[From] http://blog.csdn.net/hackai886/article/details/7935366

In SAP, table control is one of the most widely used controls in screen. It can edit multiple rows of data.
To put it simply, table control is a set of screen elements that appear repeatedly on the screen. This is the difference between table control and normal screen elements.
If we define an internal table as itab for a table control, the working area is wa. In PbO, the system will take a line of itab To wa one by one, and then convert the content of wa to a screen element, that is, a row of table control.
In other words, each row of table control interacts with Wa and has no direct association with itab.
In Pai, the system extracts data row by row to WA based on table control input (provided that the content of this row is not empty ), then we can modify or add a row of records to itab Based on wa content.

1. How to set the number of TC rows
If we define the TC name as tc_0100, the TC Wizard will generate the following line of code:
Controls: tc_0100 type tableview using screen 0100.
Debugging shows that tc_0100 is a deep structure with many attributes. It encapsulates all attributes of the table control.
Here we will first introduce the property: lines. Lines indicates the total number of rows in the table control that can be viewed or input by users.
If you are viewing the status, you can assign lines (itab) to it ). If it is in the editing status, in order to allow users to add entries, the number of lines must be greater than that of the itab.
What if TC's attribute is smaller than the number of rows in the inner table? Only the first few rows in the internal table can be displayed, and the subsequent content will not appear in the screen, of course, we will not perform this operation in reality.

2. How to edit a cell in TC?
For common screen elements, we know that loop at screen can be used. The same is true for TC.
The TC wizard generates the following screen flow logic:
Loop at itab into WA with control tc_0100 cursor tc_0100-current_line.
Module tc_0100_change_field_attr.
Endloop.
What does this mean? In fact, if we set tc_0100-lines = 50, the module will be executed 50 times.
Therefore, you only need to add loop at screen in tc_0100_change_field_attr, as shown below:

Module tc_0100_change_field_attr output.
Loop at screen.
Case screen-name.
When 'itab-keyfeld '.
If tc_0100-current_line> db_num.
Screen-input = '1 ′.
Else.
Screen-input = '0 ′.
Endif.
When others.
Endcase.
Modify screen.
Endloop.
Endmodule.

3. How to update data in our internal table
As mentioned above, during Pai's processing, the system will read TC data row by row and fill the data in WA. However, our itab and screen elements are not directly related, therefore, you can write the following code:
Module tc_0100_modify input.
If tc_0100-current_line <= lines (itab ).
Modify itab from Wa index tc_0100-current_line.
Else.
Append wa to itab.
Endif.
Endmodule.

As mentioned earlier, if the tc_0100-lines is 50, module tc_0100_change_field_attr will be executed 50 times.
So the module tc_0100_modify here is also 50 times? The answer is <= 50. This is because if a row in TC is completely empty, the system cannot call tc_0100_modify. In other words, this row in TC will be treated as nonexistent.

4. Scroll to a column in a row
If we want to display the top or left column in the table content in front of the user after the screen, we should modify the values of the top_line and left_col variables. Generally, you can set it in tc_0100_change_tc_attr of PBO:
Tc_0100-top_line = 3.
Tc_0100-left_col = 3.
The premise behind the left_col statement is that there are many fields in the internal table, resulting in insufficient table control width, and it is necessary to scroll left and right.

5. Obtain the cursor position
Use the get cursor statement, for example
Data: l_line type I,
Rochelle Field Type Screen-name.
Get cursor field l_field line l_line.

In this way, the row and field name of the table inside the mouse are obtained. Note that if you want to map to itab, do not forget top_line. The statement that correctly reads the row of data corresponding to the table where the cursor is located is:
Get cursor line l_line.
L_line = l_line + tc_0100-top_line-1.
Read Table itab into WA index l_line.
Similarly, if you want to move the cursor to a cell in the internal table, the statement is set cursor field l_field line l_line.

6. set fixed columns and select rows.
Sometimes we want several columns on the left of Table Control (generally keyword segments), which are fixed on the screen and can be easily read by users. How can I set it? First of all, we will definitely find the field attribute, but unfortunately we did not find it.
In fact, this is an attribute of table control itself. We can only define certain columns on the far left that cannot be rolled. In screen layout, double-click the upper-right corner of table control and the "Table Control" attribute is displayed:

Here we can also see that we have set the row selection of the table control to allow multiple choices, and whether the selected information is updated to the mark field of WA, Mark is generally defined as C (1 ).

7. How to hide a column
To hide a screen field, we must first think of loop at screen and set the field value of active or invisible. Unfortunately, the test fails. The correct method is to programmatically modify the visible length of a field in tabctrl-cols.

Data: l_hide type C,
Ls_col like line of tc_0100-cols.
Loop at tc_0100-cols into ls_col where screen-name = 'wa-field2 ′.
If l_hide is initial.
Ls_col-vislength = 6.
Else.
Ls_col-vislength = 0.
Endif.
Modify tc_0100-cols from ls_col.
Endloop.

Various attributes and events in Table Control

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.