Example of ABAP Table Control

Source: Internet
Author: User

[From] http://blog.csdn.net/lhx20/article/details/3039909
Table control is used to display data in a table on screen. In table control, you can use table elements, keywords, templates, radio buttons, radio button groups, and pushbuttons. A row can have 255 columns. Each column can have a title. Table control can be used to display single structured lines. Table control features:

L resizable table for displaying and Editing data

L The user or program can change the column width and position and save them for the next call.

L check column for marking lines, marked lines are highlighted in a different color

L Line Selection single lines multiple lines all lines and deselection

L column headings double as pushbuttons for Marking columns

L scroll bars for horizontal and vertical scrolling

L any number of key columns can be set

L cell attributes are variable at runtime

Table control can store display variants.

Table control actions that are fully run on the client include:

L horizontal scrolling

L swapping Columns

L changing column width

L selecting Columns

L selecting lines

Both scroll vertically and save user configuration trigger Pai processing block

In addition to name start poison on screen and static size, table control has many special attributes that determine the table type and display options of table control and whether you can configure table control. The loopc and stepl fields of structure syst record the loop processing information of table control. If table control is used to input data, set table type to entry table. If you want to select or transmit data or only display mode, you can set table type to selection table. To Create Table Control, you must create table control area and table control fields. To create a table control area, follow these steps:

L drag Table Control Area object to screen in screen

L maintain the name of Table Control in the name attribute, define a structure with the same name in the ABAP program, and set controls and type to tableview (corresponding to cxtab_control in type group) declare a complex data object. During running, this variable stores the static attributes of table control.

L you maintain the initial value in screen painter, and use using screen to determine that the screen's initial values will be used. You can use the statement refresh control <Ctrl> from screen <Scr> to initialize table control. <Scr> it is not the initial screen of table control.

You can use dict/program fields to Create Table control fields. The main steps are as follows:

L select the structure of the fields you want to display

L select the fields you want to display in the filed list

L then drag them to table control area. If field has data element texts, it will act as column heading.

You can also drag a separate input/output field to table control area as a column.

When you create table control, the system automatically creates a selection column for propose. Selection column has the same function as check box. The field must be of the char type and have a length of 1. The field name must be input in the Table Control name attribute. Selection column is used to pass selection information between screen and ABAP program. Table control attributes is stored in the structure declared by the control statement in the ABAP program. These attributes can be divided into general attributes and column attributes. General Attributes contains the overall information of table control, such as the number of fixed columns. Column attributes is stored in an internal table. Each column contains the complete attributes of screen structure, and column position, selection indicator, visibility indicator, and visible length are also used. You can modify the attribute of table control dynamically by modifying the field of table control structure declared in the program. The table control structure field also contains user interaction information, such as the specific column selected by the user.

How table control works:

In terms of performance, the content to be displayed in table control should be retrieved from the database and put into the internal table at a time. The system fills the content in the internal table into the table control. Before you can display the content in an internal table to table control, you should first retrieve the content to be displayed from the database, but note that each PbO should not retrieve the number in the database, when the key fields changes, take the number in the database. To handle the table control system, you need to know the scroll height in the vertical direction. You can use the describe statement to obtain the number of records in the internal table, and then assign this attribute to table control. There is only one work area to process records in table control. In PbO and PAI, loop is required for each table control... Endloop structure. In PbO, each loop needs to fill in the corresponding records in the internal table into table control. Similarly, in Pai, you need to pass the modified records through table control back to each corresponding record in the internal table. During Processing, you must know which rows of table control target the entire screen.

PbO

Module fill_itab.

Loop ....

Read line by line from the internal table

Endloop.

Pai

Loop...

Update the internal table line by line.

Endloop.

Module fill_itab output.

If wa_spfli-carrid new key_scarr-carrid.

Move-corresponding wa_spfli to key_scarr.

Selelct... Into Table itab_spfli

Where...

 

Describe table itab_spfli

Line my_control-lines.

Endif.

Endmodule.

Three steps to display the internal table data on table control:

L The system loops every row of table control on screen

L for each row, the system will read a row in the corresponding internal table and put it in the work area.

L for each row, the system copies the content in the work area to the corresponding row in table control.

Process before output

Loop at itab_spfli into wa_spfli

With control my_control.

Module move_to_tc.

Endloop.

Process after input.

Module move_to_tc output.

Move-corresponding wa_spfli to sdyn_conn.

Endmodule.

If the work area and Table Control Area fields have the same structure, the content in the work area will be automatically transmitted to the fields of table control, otherwise, you need to add a module between the loop endloop to transmit the value in the work area to the structure of table control fields. When you perform scroll table control, the system calculates <Ctrl>-top_line. After table control is used on screen, the field transport sequence between screen and program changes. In the PBo processing block, data in each loop process is transmitted from ABAP program to screen. The remaining screen fields are transmitted at the end of PBO. After the modified data is passed back to the internal table of the program, there are also three steps:

L every row of system loop Table Control

L for each row, the system returns the content of the row to the Work Area of the internal table

L The Work Area content must be written back to the internal table

Program block loop at <itab> endloop. Used to process each row in table control.

If the structure name of the table control is the same as the work area of the internal table, you need to update the content in the work area to the corresponding row in the internal table, you can get the corresponding row through the my_tabcontrol-current_line. If it does not have the same name as the work area of the internal table, first copy the structure of the table control to the Work Area of the internal table. Field transport sequence in PAI:

Screen fields that do not belong to table control and field statement are first transmitted to the ABAP program. The content in table control is transmitted to the work area in a row in the corresponding loop. As in general, the screen fields of the field statement is transmitted to the ABAP program before the statement.

When the monetary data is transmitted by screen to the ABAP program, the system program will perform additional formatting. The system will point to the corresponding reference field and the corresponding ABAP field, if the reference field does not have the corresponding currency, an error will occur. The sequence of Data Transport is related to the position on the screen. You do not need to consider the specific technical details of data transport. In the flow logic code, ensure that the feidl transfer order is correct (amounts is transferred after the reference field ). To do this, the field statement can be used to delay the transmission of amount field.

You can use table control Wizard to create table control. All objects created through the wizard are inactive.

You can modify the structure created by the control statement to change the attribute of table control. If you want to temporarily change the attribute of a table control cell, you can modify the screen table content of the row in the loop endloop of PBO. In the loop, the system will obtain the static attribute set of Table Control in screen painter, and temporarily modify these attributes by calling module in the loop. You can use selected field to determine whether a column is selected. To change the attribute of a column in table control, you must change the value of the corresponding row in the <table_control>-cols table. This internal table has no header line, so you must define the work area. It also contains information about user interaction.

PbO or Pai

Module change_table_control_2.

The data; Wa like line of my_control-cols.

Module change_table_control_2.

Loop at my_control-cols into WA.

If wa-index between 1 and 3.

Wa-screen-intensified = 1.

Else.

Wa-screen-intensified = 0.

Endif

Modify my_control-cols from Wa ..

Endloop.

Endmodule.

In the loop processing of Table Control in PbO, the system copies some attributes of table control structure to the screen of the system table. All fields in a row in table control are copied. Each row displayed by table ocntrol is copied (the number of rows is determined by the size of the current screen ). You can temporarily change the attribute of table control fields. This change is only valid for the current processing. You can change the attribute of the current row in the loop processing of table control,

Loop at itab between D sdyn_conn.

Module mdodify_screen.

Endloop.

Module modify_screen.

Check spfli-mark = 'x '.

Loop at screen.

If screen-group1 = 'sel '.

Screen-intensified = 1.

Endif.

Modify screen.

Endloop.

Endmodule.

You can sort the content of table control by using the following attributes of table control: <wa_cols>-selected and <wa_cols>-screen-name. It should be clear that <wa_cols>-screen-name is the name of screen field rather than the name of internal table column.

Controls my_control type tableview using screen 200.

Data wa like line of my_control-cols.

 

Module user_command_0200 input.

Case OK _code.

When 'stru '.

Read Table my_control-cols

With key selected = 'X' into WA.

'If sy-subrc = 0.

Sort itab by (wa-screen-name + 10 ).

Else.

Message i055 (bc410 ).

Endif.

Endcase.

Endmoudle.

Determine the position of the table control where the mouse is located;

You can use the get cursor statement to determine the cursor position in table control. Set cusor is used to set the cursor position: Set cursor field <field> line <line> offset <OFFSET>

Get the cursor position:

Data: selline type sy-stepl,

Tabix type sy-tabix.

Get cusor line selline.

Tabix = my_control-TOP_LINE + selelin-1.

Read Table spfli_itab index tabix.

Example of ABAP 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.