Chinaunix首页 | 论坛 | 博客
  • 博客访问: 717167
  • 博文数量: 158
  • 博客积分: 6010
  • 博客等级: 准将
  • 技术积分: 1643
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-11 14:37
个人简介

人法地,地法天,天法道,道法自然

文章分类

全部博文(158)

文章存档

2022年(1)

2020年(3)

2016年(1)

2014年(7)

2013年(4)

2010年(5)

2009年(86)

2008年(25)

2007年(26)

我的朋友

分类:

2009-05-14 21:07:51

Table Control(With Wizard)设计

事先定义一个内表,字段包括MARK,用来标识w/SelColumn,设置选项.

tables:mara.

data:begin of itab occurs 0.
      
include structure mara.
      
data:mark type char1.
data:end of itab.

 

设置步骤如下:

第一、选定Table Control向导控件

第二、控件名称:MYTC

 

第三、选定内表itab

第四、定义列字段

第五、设置相关属性,列可输入或仅输出(这里设置为Input control),带表头的列,要如果设置全选或取消全选按钮,那Line sel设置Multiple,指定的Selection col.fldMARK,MARK是内表ITAB中已定义好的。设置完毕后,其w/SelColumn的设置表现为:ITAB-MARK.

 

第六、增加一些功能按钮如,全选与取消全选,插入与删除行,上下翻页(滚动)。

 

第七、设置生成的功能模块名称

第八、完成激活。

输出结果:

 

完整程序代码如下:

 

 

 

 

*&---------------------------------------------------------------------*
*& Report  ZMYP_TC
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZMYP_TC.


tables:mara.

data:begin of itab occurs 0.
      
include structure mara.
      
data:mark type char1.
data:end of itab.

DATA:     OK_CODE LIKE SY-UCOMM,
          S_OK_CODE 
LIKE SY-UCOMM.

select * from mara into corresponding fields of table itab .

*&SPWIZARD: DECLARATION OF TABLECONTROL 'MYTC' ITSELF
CONTROLS: MYTC TYPE TABLEVIEW USING SCREEN 0120.

*&SPWIZARD: LINES OF TABLECONTROL 'MYTC'
DATA:     G_MYTC_LINES  LIKE SY-LOOPC.

CALL SCREEN 120.   "调用屏幕    ,需要自己增加

*&SPWIZARD: OUTPUT MODULE FOR TC 'MYTC'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: UPDATE LINES FOR EQUIVALENT SCROLLBAR
MODULE MYTC_CHANGE_TC_ATTR OUTPUT.
  
DESCRIBE TABLE ITAB LINES MYTC-lines.
ENDMODULE.

*&SPWIZARD: OUTPUT MODULE FOR TC 'MYTC'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: GET LINES OF TABLECONTROL
MODULE MYTC_GET_LINES OUTPUT.
  G_MYTC_LINES = SY-LOOPC.
ENDMODULE.

*&SPWIZARD: INPUT MODULE FOR TC 'MYTC'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: MODIFY TABLE
MODULE MYTC_MODIFY INPUT.
  
MODIFY ITAB
    
INDEX MYTC-CURRENT_LINE.
ENDMODULE.

*&SPWIZARD: INPUT MODUL FOR TC 'MYTC'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: MARK TABLE
MODULE MYTC_MARK INPUT.
  
DATA: g_MYTC_wa2 like line of ITAB.
    
if MYTC-line_sel_mode = 1
    
and ITAB-MARK = 'X'.
     
loop at ITAB into g_MYTC_wa2
       
where MARK = 'X'.
       g_MYTC_wa2-MARK = 
''.
       
modify ITAB
         
from g_MYTC_wa2
         
transporting MARK.
     
endloop.
  
endif.
  
MODIFY ITAB
    
INDEX MYTC-CURRENT_LINE
    
TRANSPORTING MARK.
ENDMODULE.

*&SPWIZARD: INPUT MODULE FOR TC 'MYTC'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: PROCESS USER COMMAND
MODULE MYTC_USER_COMMAND INPUT.
  OK_CODE = SY-UCOMM.
  
PERFORM USER_OK_TC USING    'MYTC'
                              
'ITAB'
                              
'MARK'
                     
CHANGING OK_CODE.
  SY-UCOMM = OK_CODE.
ENDMODULE.

*----------------------------------------------------------------------*
*   INCLUDE TABLECONTROL_FORMS                                         *
*----------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Form  USER_OK_TC                                               *
*&---------------------------------------------------------------------*
 
FORM USER_OK_TC USING    P_TC_NAME TYPE DYNFNAM
                          P_TABLE_NAME
                          P_MARK_NAME
                 
CHANGING P_OK      LIKE SY-UCOMM.

*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
   
DATA: L_OK              TYPE SY-UCOMM,
         L_OFFSET          
TYPE I.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

*&SPWIZARD: Table control specific operations                          *
*&SPWIZARD: evaluate TC name and operations                            *
   
SEARCH P_OK FOR P_TC_NAME.
   
IF SY-SUBRC <> 0.
     
EXIT.
   
ENDIF.
   L_OFFSET = 
STRLEN( P_TC_NAME ) + 1.
   L_OK = P_OK+L_OFFSET.
*&SPWIZARD: execute general and TC specific operations                 *
   
CASE L_OK.
     
WHEN 'INSR'.                      "insert row
       
PERFORM FCODE_INSERT_ROW USING    P_TC_NAME
                                         P_TABLE_NAME.
       
CLEAR P_OK.

     
WHEN 'DELE'.                      "delete row
       
PERFORM FCODE_DELETE_ROW USING    P_TC_NAME
                                         P_TABLE_NAME
                                         P_MARK_NAME.
       
CLEAR P_OK.

     
WHEN 'P--' OR                     "top of list
          
'P-'  OR                     "previous page
          
'P+'  OR                     "next page
          
'P++'.                       "bottom of list
       
PERFORM COMPUTE_SCROLLING_IN_TC USING P_TC_NAME
                                             L_OK.
       
CLEAR P_OK.
*     WHEN 'L--'.                       "total left
*       PERFORM FCODE_TOTAL_LEFT USING P_TC_NAME.
*
*     WHEN 'L-'.                        "column left
*       PERFORM FCODE_COLUMN_LEFT USING P_TC_NAME.
*
*     WHEN 'R+'.                        "column right
*       PERFORM FCODE_COLUMN_RIGHT USING P_TC_NAME.
*
*     WHEN 'R++'.                       "total right
*       PERFORM FCODE_TOTAL_RIGHT USING P_TC_NAME.
*
     
WHEN 'MARK'.                      "mark all filled lines
       
PERFORM FCODE_TC_MARK_LINES USING P_TC_NAME
                                         P_TABLE_NAME
                                         P_MARK_NAME   .
       
CLEAR P_OK.

     
WHEN 'DMRK'.                      "demark all filled lines
       
PERFORM FCODE_TC_DEMARK_LINES USING P_TC_NAME
                                           P_TABLE_NAME
                                           P_MARK_NAME .
       
CLEAR P_OK.

*     WHEN 'SASCEND'   OR
*          'SDESCEND'.                  "sort column
*       PERFORM FCODE_SORT_TC USING P_TC_NAME
*                                   l_ok.

   
ENDCASE.

 
ENDFORM.                              " USER_OK_TC

*&---------------------------------------------------------------------*
*&      Form  FCODE_INSERT_ROW                                         *
*&---------------------------------------------------------------------*
 
FORM fcode_insert_row
               
USING    P_TC_NAME           TYPE DYNFNAM
                        P_TABLE_NAME             .

*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
   
DATA L_LINES_NAME       LIKE FELD-NAME.
   
DATA L_SELLINE          LIKE SY-STEPL.
   
DATA L_LASTLINE         TYPE I.
   
DATA L_LINE             TYPE I.
   
DATA L_TABLE_NAME       LIKE FELD-NAME.
   
FIELD-SYMBOLS                  TYPE CXTAB_CONTROL.
   
FIELD-SYMBOLS 

              TYPE STANDARD TABLE.
   
FIELD-SYMBOLS               TYPE I.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

   
ASSIGN (P_TC_NAME) TO .

*&SPWIZARD: get the table, which belongs to the tc                     *
   
CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body
   
ASSIGN (L_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: get current line                                           *
   
GET CURSOR LINE L_SELLINE.
   
IF SY-SUBRC <> 0.                   " append line to table
     L_SELLINE = -
LINES + 1.
*&SPWIZARD: set top line                                               *
     
IF L_SELLINE > .
       -TOP_LINE = L_SELLINE -  + 
1 .
     
ELSE.
       -TOP_LINE = 
1.
     
ENDIF.
   
ELSE.                               " insert line into table
     L_SELLINE = -TOP_LINE + L_SELLINE - 
1.
     L_LASTLINE = -TOP_LINE +  - 
1.
   
ENDIF.
*&SPWIZARD: set new cursor line                                        *
   L_LINE = L_SELLINE - -TOP_LINE + 
1.

*&SPWIZARD: insert initial line                                        *
   
INSERT INITIAL LINE INTO 
 INDEX L_SELLINE.
   -
LINES = -LINES + 1.
*&SPWIZARD: set cursor                                                 *
   
SET CURSOR LINE L_LINE.

 
ENDFORM.                              " FCODE_INSERT_ROW

*&---------------------------------------------------------------------*
*&      Form  FCODE_DELETE_ROW                                         *
*&---------------------------------------------------------------------*
 
FORM fcode_delete_row
               
USING    P_TC_NAME           TYPE DYNFNAM
                        P_TABLE_NAME
                        P_MARK_NAME   .

*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
   
DATA L_TABLE_NAME       LIKE FELD-NAME.

   
FIELD-SYMBOLS          TYPE cxtab_control.
   
FIELD-SYMBOLS 
      TYPE STANDARD TABLE.
   
FIELD-SYMBOLS .
   
FIELD-SYMBOLS .
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

   
ASSIGN (P_TC_NAME) TO .

*&SPWIZARD: get the table, which belongs to the tc                     *
   
CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body
   
ASSIGN (L_TABLE_NAME) TO 
.                "not headerline

*&SPWIZARD: delete marked lines                                        *
   
DESCRIBE TABLE 
 LINES -LINES.

   
LOOP AT 
 ASSIGNING .

*&SPWIZARD: access to the component 'FLAG' of the table header         *
     
ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE  TO .

     
IF  = 'X'.
       
DELETE 
 INDEX SYST-TABIX.
       
IF SY-SUBRC = 0.
         -
LINES = -LINES - 1.
       
ENDIF.
     
ENDIF.
   
ENDLOOP.

 
ENDFORM.                              " FCODE_DELETE_ROW

*&---------------------------------------------------------------------*
*&      Form  COMPUTE_SCROLLING_IN_TC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_TC_NAME  name of tablecontrol
*      -->P_OK       ok code
*----------------------------------------------------------------------*
 
FORM COMPUTE_SCROLLING_IN_TC USING    P_TC_NAME
                                       P_OK.
*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
   
DATA L_TC_NEW_TOP_LINE     TYPE I.
   
DATA L_TC_NAME             LIKE FELD-NAME.
   
DATA L_TC_LINES_NAME       LIKE FELD-NAME.
   
DATA L_TC_FIELD_NAME       LIKE FELD-NAME.

   
FIELD-SYMBOLS          TYPE cxtab_control.
   
FIELD-SYMBOLS       TYPE I.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

   
ASSIGN (P_TC_NAME) TO .
*&SPWIZARD: get looplines of TableControl                              *
   
CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_TC_LINES_NAME.
   
ASSIGN (L_TC_LINES_NAME) TO .


*&SPWIZARD: is no line filled?                                         *
   
IF -LINES = 0.
*&SPWIZARD: yes, ...                                                   *
     L_TC_NEW_TOP_LINE = 
1.
   
ELSE.
*&SPWIZARD: no, ...                                                    *
     
CALL FUNCTION 'SCROLLING_IN_TABLE'
          
EXPORTING
               ENTRY_ACT             = -TOP_LINE
               ENTRY_FROM            = 
1
               ENTRY_TO              = -
LINES
               LAST_PAGE_FULL        = 
'X'
               LOOPS                 = 
               OK_CODE               = P_OK
               OVERLAPPING           = 
'X'
          
IMPORTING
               ENTRY_NEW             = L_TC_NEW_TOP_LINE
          
EXCEPTIONS
*              NO_ENTRY_OR_PAGE_ACT  = 01
*              NO_ENTRY_TO           = 02
*              NO_OK_CODE_OR_PAGE_GO = 03
               
OTHERS                = 0.
   
ENDIF.

*&SPWIZARD: get actual tc and column                                   *
   
GET CURSOR FIELD L_TC_FIELD_NAME
              AREA  L_TC_NAME.

   
IF SYST-SUBRC = 0.
     
IF L_TC_NAME = P_TC_NAME.
*&SPWIZARD: et actual column                                           *
       
SET CURSOR FIELD L_TC_FIELD_NAME LINE 1.
     
ENDIF.
   
ENDIF.

*&SPWIZARD: set the new top line                                       *
   -TOP_LINE = L_TC_NEW_TOP_LINE.


 
ENDFORM.                              " COMPUTE_SCROLLING_IN_TC

*&---------------------------------------------------------------------*
*&      Form  FCODE_TC_MARK_LINES
*&---------------------------------------------------------------------*
*       marks all TableControl lines
*----------------------------------------------------------------------*
*      -->P_TC_NAME  name of tablecontrol
*----------------------------------------------------------------------*
FORM FCODE_TC_MARK_LINES USING P_TC_NAME
                               P_TABLE_NAME
                               P_MARK_NAME.
*&SPWIZARD: EGIN OF LOCAL DATA-----------------------------------------*
  
DATA L_TABLE_NAME       LIKE FELD-NAME.

  
FIELD-SYMBOLS          TYPE cxtab_control.
  
FIELD-SYMBOLS 
      TYPE STANDARD TABLE.
  
FIELD-SYMBOLS .
  
FIELD-SYMBOLS .
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

  
ASSIGN (P_TC_NAME) TO .

*&SPWIZARD: get the table, which belongs to the tc                     *
   
CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body
   
ASSIGN (L_TABLE_NAME) TO 
.                "not headerline

*&SPWIZARD: mark all filled lines                                      *
  
LOOP AT 
 ASSIGNING .

*&SPWIZARD: access to the component 'FLAG' of the table header         *
     
ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE  TO .

      = 
'X'.
  
ENDLOOP.
ENDFORM.                                          "fcode_tc_mark_lines

*&---------------------------------------------------------------------*
*&      Form  FCODE_TC_DEMARK_LINES
*&---------------------------------------------------------------------*
*       demarks all TableControl lines
*----------------------------------------------------------------------*
*      -->P_TC_NAME  name of tablecontrol
*----------------------------------------------------------------------*
FORM FCODE_TC_DEMARK_LINES USING P_TC_NAME
                                 P_TABLE_NAME
                                 P_MARK_NAME .
*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
  
DATA L_TABLE_NAME       LIKE FELD-NAME.

  
FIELD-SYMBOLS          TYPE cxtab_control.
  
FIELD-SYMBOLS 
      TYPE STANDARD TABLE.
  
FIELD-SYMBOLS .
  
FIELD-SYMBOLS .
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

  
ASSIGN (P_TC_NAME) TO .

*&SPWIZARD: get the table, which belongs to the tc                     *
   
CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body
   
ASSIGN (L_TABLE_NAME) TO 
.                "not headerline

*&SPWIZARD: demark all filled lines                                    *
  
LOOP AT 
 ASSIGNING .

*&SPWIZARD: access to the component 'FLAG' of the table header         *
     
ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE  TO .

      = SPACE.
  
ENDLOOP.
ENDFORM.                                          "fcode_tc_mark_lines

 

阅读(2014) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~