ABAP table control practice Accumulation

Source: Internet
Author: User

Table control is a structure,

Assume that the TC name we define isZtest_tc(For detailed structure, refer to: scxtab_control)

So we define ZTEST_TC-CURENT_LINE, ZTEST_TC-LINES and so on all make sense, we can understand it as a deep structure.

       General TC attributes: |                    Column attributes

 1. fixed_cols lines top_line current_line... |Cols|Index selected vislength invisible ..

|

2. screen

                                               | 

 3.Name group1... group4 required input output intensified... invisible length active display_3d value_help request...

 1 is an overall table control structure

 2 is the structure of the ZTEST_TC-COLS content that we often use loop at screen... endloop.

 3. It is the attribute of the screen structure.

So what is the purpose of this?

I. The current requirements are as follows (the instances I have encountered in the actual project ):

On the selection screen, the content of Database Table A is displayed. A has an approval field. If this approval field is checked (char4 (icon_d)Type fieldStorage content: @ 01 @ is automatically checked and displayed by the system.In table control, the newly added data that has not been approved can be modified.

Generate with navigationCodeFor example: PbO

The name of the output table in my custom TC isT_ztest workspace wa_ztest

 ProcessBeforeOutput.
* & Spwizard:PbOFlowLogicForTablecontrol'Ztest _ TC'

Module Ztest_tc_change_tc_attr.
* & Spwizard:ModuleZtesttc_change_col_attr.
Loop At T_ztest
Into Wa_ztest
With Control Ztest_tc
Cursor ZTEST_TC-CURRENT_LINE .
Module Ztest_tc_get_lines.
* & Spwizard:  ModuleZtesttc_change_field_attr
Endloop .
Module Status_8000.

 

 When I first came into contact with ABAP, I saw such a loop statement. It cannot be used in other places except PBO.

Here, we add each row of data we display on the screen to the wa_test.

With Control Ztest_tc indicates that the process of this loop is to bind the cursor ZTEST_TC-CURRENT_LINE to the TC loop.. Based on the structure listed above, let's go inModule Add a piece of code in ztest_tc_get_lines:

Loop at screen.

If screen-name CS 'wa _ ztest' and WA_ZTEST-STATUS EQ '@ 01 @'.

If SY-SUBRC EQ 0.

Screen-input EQ 0.

Modify screen.

Endif.

Endif

 Cursor Is the cursor position in the control. At this time, the cursor position is the data of the current row of the loop.

 The entire logic is as follows: first, we can set a data record in the loop, and then bind it to TC. Then, loop at screen. At this time, TC will only operate on the attributes of the current_line row. If the flag of this line is mailto: â @ 01 @ â then it cannot be entered (the entire line is dimmed). If no flag is entered, it will be normal. Due to the role of cursor, the properties of each row of TC are operated row by row.

2. How to obtain the updated data in TC (TC-> Table Control)

Add some code to the template code of Pai.

Loop At T_ztest.
Chain.
Field WA_ZTEST-VKORG.
Field WA_ZTEST-VKBUR.
Field WA_ZTEST-KUNNR Module Kunnr_text On Input .
Field WA_ZTEST-MATNR Module Matnr_text On Input .
Field WA_ZTEST-ZYEAR.
.......
Module Zhgxs_xsjh_tc_modify On Chain-request.
Endchain.

     Field WA_ZHGXS_XSJH-SEL
      Module Zhgxs_xsjh_tc_markOn Request.

  Endloop.

     

 

Field ....Moudle...On Input indicates that the field is not empty and will trigger this on input... Module

When the input operation is enabledModule ....On Request (response module ).  

Also:Module Zhgxs_xsjh_tc_modifyOn Chain-request.

The role of this Moudle is chain after Pai is triggered .. If the endchain data changes, TC will trigger this module and then update the latest value of the latest row.
Source codeAs follows:  Modify T_ztest
           From Wa_ztest Index ZTEST_TC-CURRENT_LINE.

So we use this place to cleverly define an internal table for storing and updating data, and then

Modify Update internal table statistics
             From Wa_ztest Index ZTEST_TC-CURRENT_LINE.

In this way, after all the changes, the data worth the change will appear in the internal table,

The table in decribe knows how many rows are updated.

The internal table of TC is always the data after the operation and is very accurate.

Because each of his Pai's loops and modify changes the value of the original inner table.

So there is a question. What will happen when you delete a row?

Suppose I am using the-(Delete row) operation generated by the navigation itself, so in Pai, although we see that this row of data is gone, however, loop check of PAI triggers a mark position operation, and then adds the sel of the inner table to X. WhenProgramWhen the event is triggered by the insr control of PAI, data of SEL = 'X' is deleted from the internal table.

Therefore, the pai chain will only loop the data before the existing operation, and will not reduce the data in the internal table. The main essence is

Module... on request is under control.

3. Analyze the classic dynamic code of some table control.

Field -Symbols <TC> Type Cxtab_control.
Field -Symbols <Table> Type Standard Table .
Field -Symbols <Lines> Type I .
* & Spwizard:EndOfLocalData ------------------------------------------*

   Assign (P_tc_name)To <TC>.

* & spwizard: Get the table, which belongs to the tc *
concatenate p_table_name '[] ' into l_table_name. "Table body
assign (rochelle table_name) to

"not headerline

.

* & spwizard: Get looplines of tablecontrol *
concatenate 'G _ ' p_tc_name ' _ lines' into l_lines_name.
assign (l_lines_name) to .

* & Spwizard:GetCurrentLine                                          *
Get Cursor Line Rochelle.
If SY-SUBRC <> 0 . "AppendLineToTable
Rochelle = <TC>- Lines + 1 .
* & Spwizard:SetTopLine                                              *
If Rochelle > <Lines>.
<TC>-top_line = Rochelle - <Lines> + 1 .
Else .
<TC>-top_line = 1 .
Endif .
Else . "InsertLineIntoTable
Rochelle = <TC>-top_line + Rochelle - 1 .
Rochelle lastline = <TC>-top_line

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.