Chinaunix首页 | 论坛 | 博客
  • 博客访问: 967269
  • 博文数量: 463
  • 博客积分: 10070
  • 博客等级: 上将
  • 技术积分: 4963
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-16 14:16
文章分类

全部博文(463)

文章存档

2011年(18)

2010年(144)

2009年(83)

2008年(218)

我的朋友

分类: IT职场

2008-07-22 16:08:44

*----------------------------------------------------------------------*
* Program Name: Z_KEVIN_TABLECONTROL
* Project     : N/A
* Author      : Kevin.Zhang
* Date        : 2007.1.1
* Module      : N/A
* Description : Template of Program
*
*
*
* Special features: N/A
*
*
*----------------------------------------------------------------------*
* Modifications:
* Author      Date     Commented as  Description
*-----------  --------  -----------  ----------------------------------*
*
*----------------------------------------------------------------------*

REPORT  Z_KEVIN_TABLECONTROL.
*$*$----------------------------------------------------------------$*$*
*$*$       Global Types, Data Statements, Ranges, Constants         $*$*
*$*$----------------------------------------------------------------$*$*

*-----------------------------------------------------------------------
*                        Types
*-----------------------------------------------------------------------
TYPESBEGIN OF T_ZKEVIN.
TYPESLINE TYPE C.
        
INCLUDE STRUCTURE ZKEVIN.
TYPESEND OF T_ZKEVIN.

TYPESBEGIN OF T_SAVE.
        
INCLUDE STRUCTURE ZKEVIN.
TYPESEND OF T_SAVE.

*-----------------------------------------------------------------------
*                    Internal Tables and Work Areas
*-----------------------------------------------------------------------
DATA GT_ZKEVIN TYPE STANDARD TABLE OF T_ZKEVIN.
DATA GS_ZKEVIN TYPE T_ZKEVIN.
DATA GT_DELE TYPE STANDARD TABLE OF T_ZKEVIN.
DATA GS_DELE TYPE T_ZKEVIN.
DATA GT_SAVE TYPE STANDARD TABLE OF T_SAVE.
DATA GS_SAVE TYPE T_SAVE.

*-----------------------------------------------------------------------
*                  Variables
*-----------------------------------------------------------------------
*&SPWIZARD: LINES OF TABLECONTROL 'ZTC'
DATA:     G_ZTC_LINES  LIKE SY-LOOPC.

DATA:     OK_CODE LIKE SY-UCOMM.

*-----------------------------------------------------------------------
*     Global GUI Controls Variables / Structures
*-----------------------------------------------------------------------
*&SPWIZARD: DECLARATION OF TABLECONTROL 'ZTC' ITSELF
CONTROLS: ZTC TYPE TABLEVIEW USING SCREEN 1000.

*$*$----------------------------------------------------------------$*$*
*$*$                          Main Program                          $*$*
*$*$----------------------------------------------------------------$*$*

*--------- START-OF-SELECTION ----------

SELECT *
  
FROM ZKEVIN
  
INTO CORRESPONDING FIELDS OF TABLE GT_ZKEVIN.

SORT GT_ZKEVIN BY ID.

CALL SCREEN 1000.

*--------- END-OF-SELECTION ----------

*$*$----------------------------------------------------------------$*$*
*$*$                         Subroutines                            $*$*
*$*$----------------------------------------------------------------$*$*

*&SPWIZARD: OUTPUT MODULE FOR TC 'ZTC'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: UPDATE LINES FOR EQUIVALENT SCROLLBAR
MODULE ZTC_CHANGE_TC_ATTR OUTPUT.
  
DESCRIBE TABLE GT_ZKEVIN LINES ZTC-LINES.
ENDMODULE.                    "ZTC_CHANGE_TC_ATTR OUTPUT

*&SPWIZARD: OUTPUT MODULE FOR TC 'ZTC'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: GET LINES OF TABLECONTROL
MODULE ZTC_GET_LINES OUTPUT.
  G_ZTC_LINES = SY-LOOPC.
ENDMODULE.                    "ZTC_GET_LINES OUTPUT

*&SPWIZARD: INPUT MODULE FOR TC 'ZTC'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: MODIFY TABLE
MODULE ZTC_MODIFY INPUT.
  
MODIFY GT_ZKEVIN
    
FROM GS_ZKEVIN
    
INDEX ZTC-CURRENT_LINE.
ENDMODULE.                    "ZTC_MODIFY INPUT

*&SPWIZARD: INPUT MODUL FOR TC 'ZTC'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: MARK TABLE
MODULE ZTC_MARK INPUT.
  
DATA: G_ZTC_WA2 LIKE LINE OF GT_ZKEVIN.
  
IF ZTC-LINE_SEL_MODE = 1
  
AND GS_ZKEVIN-LINE = 'X'.
    
LOOP AT GT_ZKEVIN INTO G_ZTC_WA2
      
WHERE LINE = 'X'.
      G_ZTC_WA2-
LINE = ''.
      
MODIFY GT_ZKEVIN
        
FROM G_ZTC_WA2
        
TRANSPORTING LINE.
    
ENDLOOP.
  
ENDIF.
  
MODIFY GT_ZKEVIN
    
FROM GS_ZKEVIN
    
INDEX ZTC-CURRENT_LINE
    
TRANSPORTING LINE.
ENDMODULE.                    "ZTC_MARK INPUT

*&SPWIZARD: INPUT MODULE FOR TC 'ZTC'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: PROCESS USER COMMAND
MODULE ZTC_USER_COMMAND INPUT.
  OK_CODE = SY-UCOMM.
  
PERFORM USER_OK_TC USING    'ZTC'
                              
'GT_ZKEVIN'
                              
'LINE'
                     
CHANGING OK_CODE.
  SY-UCOMM = OK_CODE.
ENDMODULE.                    "ZTC_USER_COMMAND INPUT

*----------------------------------------------------------------------*
*   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 <TABLE>              TYPE STANDARD TABLE.
  
FIELD-SYMBOLS <LINES>              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 <TABLE>.                "not headerline

*&SPWIZARD: get looplines of TableControl                              *
  
CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_LINES_NAME.
  
ASSIGN (L_LINES_NAME) TO <LINES>.

*&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 > <LINES>.
      -TOP_LINE = L_SELLINE - <
LINES> + 1 .
    
ELSE.
      -TOP_LINE = 
1.
    
ENDIF.
  
ELSE.                               " insert line into table
    L_SELLINE = -TOP_LINE + L_SELLINE - 
1.
    L_LASTLINE = -TOP_LINE + <
LINES> - 1.
  
ENDIF.
*&SPWIZARD: set new cursor line                                        *
  L_LINE = L_SELLINE - -TOP_LINE + 
1.

*&SPWIZARD: insert initial line                                        *
  
INSERT INITIAL LINE INTO <TABLEINDEX 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 <TABLE>      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 <TABLE>.                "not headerline

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

  
LOOP AT <TABLEASSIGNING .

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

    
IF  = 'X'.
      
DELETE <TABLEINDEX SYST-TABIX.
      
IF SY-SUBRC = 0.
        -
LINES = -LINES - 1.
        
READ TABLE <TABLEINTO GS_ZKEVIN INDEX SYST-TABIX.
        
CLEAR GS_ZKEVIN-LINE.
        
APPEND GS_ZKEVIN TO GT_DELE.
      
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 <LINES>      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 <LINES>.


*&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                 = <
LINES>
              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 <TABLE>      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 <TABLE>.                "not headerline

*&SPWIZARD: mark all filled lines                                      *
  
LOOP AT <TABLEASSIGNING .

*&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 <TABLE>      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 <TABLE>.                "not headerline

*&SPWIZARD: demark all filled lines                                    *
  
LOOP AT <TABLEASSIGNING .

*&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
*&---------------------------------------------------------------------*
*&      Module  STATUS_1000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_1000 OUTPUT.
  
SET PF-STATUS 'MAIN100'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_1000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_1000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_1000 INPUT.
  
CASE OK_CODE.
    
WHEN 'BACK'.
      
LEAVE TO SCREEN 0.
    
WHEN 'SAVE'.
      
LOOP AT GT_ZKEVIN INTO GS_ZKEVIN WHERE ID NE ''.
        GS_SAVE-
ID = GS_ZKEVIN-ID.
        GS_SAVE-NAME = GS_ZKEVIN-NAME.
        
APPEND GS_SAVE TO GT_SAVE.
        
CLEAR GS_SAVE.
      
ENDLOOP.

      
MODIFY ZKEVIN FROM TABLE GT_SAVE.
      
CLEAR GS_SAVE.
      
REFRESH GT_SAVE.
      
IF SY-SUBRC NE 0.
        
MESSAGE 'DATA UPDATE ERROR!' TYPE 'I'.
        
EXIT.
      
ELSE.
        
MESSAGE 'DATA UPDATE OK!' TYPE 'I'.
      
ENDIF.

      
LOOP AT GT_DELE INTO GS_DELE.
        GS_SAVE-
ID = GS_DELE-ID.
        GS_SAVE-NAME = GS_DELE-NAME.
        
APPEND GS_SAVE TO GT_SAVE.
        
CLEAR GS_SAVE.
      
ENDLOOP.
      
DELETE ZKEVIN FROM TABLE GT_SAVE.
      
CLEAR GS_SAVE.
      
REFRESH GT_SAVE.
      
IF SY-SUBRC NE 0.
        
MESSAGE 'DATA UPDATE ERROR!' TYPE 'I'.
      
ELSE.
        
MESSAGE 'DATA UPDATE OK!' TYPE 'I'.
      
ENDIF.
  
ENDCASE.
ENDMODULE.                 " USER_COMMAND_1000  INPUT
阅读(2527) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~