登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

原来为了你

我的人生就是要一次次的超越

 
 
 

日志

 
 
 
 

Table Controlr 的应用(利用向导创建)  

2011-06-30 18:10:15|  分类: ABAP屏幕操作 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

步骤:
1.se38创建程序:

report  ysxl01.

tableszstu.
databegin of gt_01 occurs 0,
        zsel
,
        zsno    
like zstu-sno,
        zsname  
like zstu-sname,
        zsex    
like zstu-ssex,
        zage    
like zstu-sage,
      
end of gt_01.
select into corresponding fields of table gt_01 from zstu.
call screen 1001.

2.双击1001建立屏幕,过程如下:

Table Controlr 的应用 - 2006057145 - 原来为了你1.Table Controlr 的应用 - 2006057145 - 原来为了你2.Table Controlr 的应用 - 2006057145 - 原来为了你3.Table Controlr 的应用 - 2006057145 - 原来为了你4.Table Controlr 的应用 - 2006057145 - 原来为了你5. 

之后,全部代码如下:
report  ysxl01.

tableszstu.
databegin of gt_01 occurs 0,
        zsel
,
        sno    
like zstu-sno,
        sname  
like zstu-sname,
        ssex   
like zstu-ssex,
        sage   
like zstu-sage,
      
end of gt_01.
select into corresponding fields of table gt_01 from zstu.
call screen 1001.

*&SPWIZARD: DECLARATION OF TABLECONTROL 'TABCTL1' ITSELF
controlstabctl1 type tableview using screen 1001.

*&SPWIZARD: LINES OF TABLECONTROL 'TABCTL1'
data:     g_tabctl1_lines  like sy-loopc.

data:     ok_code like sy-ucomm.

*&SPWIZARD: OUTPUT MODULE FOR TC 'TABCTL1'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: UPDATE LINES FOR EQUIVALENT SCROLLBAR
module tabctl1_change_tc_attr output.
  
describe table gt_01 lines tabctl1-lines.
endmodule.                    "TABCTL1_CHANGE_TC_ATTR OUTPUT

*&SPWIZARD: OUTPUT MODULE FOR TC 'TABCTL1'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: GET LINES OF TABLECONTROL
module tabctl1_get_lines output.
  g_tabctl1_lines 
sy-loopc.
endmodule.                    "TABCTL1_GET_LINES OUTPUT
*&SPWIZARD: INPUT MODULE FOR TC 'TABCTL1'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: MODIFY TABLE
module tabctl1_modify input.
  
datafld(20), val(20).
  
get cursor  field fld  value val ."利用fld val tabctl的相关处理
  
modify gt_01
    
from gt_01
    
index tabctl1-current_line.

  
if sy-subrc <> 0"是由于gt_01一开始是0行数据modify .. index 1是不可能的.
   
append gt_01.
  
endif
endmodule.                    "TABCTL1_MODIFY INPUT 
*&SPWIZARD: INPUT MODUL FOR TC 'TABCTL1'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: MARK TABLE
module tabctl1_mark input.
  
datag_tabctl1_wa2 like line of gt_01.
  
if tabctl1-line_sel_mode 1 "只允许单选
  
and gt_01-zsel 'X'.
    
loop at gt_01 into g_tabctl1_wa2
      
where zsel 'X'.
      g_tabctl1_wa2
-zsel ''.
      
modify gt_01
        
from g_tabctl1_wa2
        
transporting zsel.
    
endloop.
  
endif.
  
modify gt_01
    
from gt_01
    
index tabctl1-current_line
    
transporting zsel.
endmodule.                    "TABCTL1_MARK INPUT

*&SPWIZARD: INPUT MODULE FOR TC 'TABCTL1'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: PROCESS USER COMMAND
module tabctl1_user_command input.
  ok_code 
sy-ucomm.
  
perform user_ok_tc using    'TABCTL1'
                              
'GT_01'
                              
'ZSEL'
                     
changing ok_code.
  sy
-ucomm ok_code.
endmodule.                    "TABCTL1_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----------------------------------------*
  
datal_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 
strlenp_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 <tc>                 type cxtab_control.
  
field-symbols <table>              type standard table.
  
field-symbols <lines>              type i.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

  
assign (p_tc_nameto <tc>.

*&SPWIZARD: get the table, which belongs to the tc                     *
  
concatenate p_table_name '[]' into l_table_name"table body
  
assign (l_table_nameto <table>.                "not headerline

*&SPWIZARD: get looplines of TableControl                              *
  
concatenate 'G_' p_tc_name '_LINES' into l_lines_name.
  
assign (l_lines_nameto <lines>.

*&SPWIZARD: get current line                                           *
  
get cursor line l_selline.
  
if sy-subrc <> 0.                   " append line to table
    l_selline 
<tc>-lines 1.
*&SPWIZARD: set top line                                               *
    
if l_selline > <lines>.
      <tc>
-top_line l_selline <lines> + .
    
else.
      <tc>
-top_line 1.
    
endif.
  
else.                               " insert line into table
    l_selline 
<tc>-top_line + l_selline 1.
    l_lastline 
<tc>-top_line + <lines> 1.
  
endif.
*&SPWIZARD: set new cursor line                                        *
  l_line 
l_selline <tc>-top_line + 1.

*&SPWIZARD: insert initial line                                        *
  
insert initial line into <table> index l_selline.
  <tc>
-lines <tc>-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 <tc>         type cxtab_control.
  
field-symbols <table>      type standard table.
  
field-symbols <wa>.
  
field-symbols <mark_field>.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

  
assign (p_tc_nameto <tc>.

*&SPWIZARD: get the table, which belongs to the tc                     *
  
concatenate p_table_name '[]' into l_table_name"table body
  
assign (l_table_nameto <table>.                "not headerline

*&SPWIZARD: delete marked lines                                        *
  
describe table <table> lines <tc>-lines.

  
loop at <table> assigning <wa>.

*&SPWIZARD: access to the component 'FLAG' of the table header         *
    
assign component p_mark_name of structure <wa> to <mark_field>.

    
if <mark_field> 'X'.
      
delete <table> index syst-tabix.
      
if sy-subrc 0.
        <tc>
-lines <tc>-lines 1.
      
endif.
    
endif.
  
endloop.

endform.                              " FCODE_DELETE_ROW

*&---------------------------------------------------------------------*
*&      Form  COMPUTE_SCROLLING_IN_TC
*&---------------------------------------------------------------------*
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 <tc>         type cxtab_control.
  
field-symbols <lines>      type i.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

  
assign (p_tc_nameto <tc>.
*&SPWIZARD: get looplines of TableControl                              *
  
concatenate 'G_' p_tc_name '_LINES' into l_tc_lines_name.
  
assign (l_tc_lines_nameto <lines>.


*&SPWIZARD: is no line filled?                                         *
  
if <tc>-lines 0.
*&SPWIZARD: yes, ...                                                   *
    l_tc_new_top_line 
1.
  
else.
*&SPWIZARD: no, ...                                                    *
    
call function 'SCROLLING_IN_TABLE'
         
exporting
              entry_act             
<tc>-top_line
              entry_from            
1
              entry_to              
<tc>-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                                       *
  <tc>
-top_line l_tc_new_top_line.


endform.                              " COMPUTE_SCROLLING_IN_TC

*&---------------------------------------------------------------------*
*&      Form  FCODE_TC_MARK_LINES
*&---------------------------------------------------------------------*
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 <tc>         type cxtab_control.
  
field-symbols <table>      type standard table.
  
field-symbols <wa>.
  
field-symbols <mark_field>.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

  
assign (p_tc_nameto <tc>.

*&SPWIZARD: get the table, which belongs to the tc                     *
  
concatenate p_table_name '[]' into l_table_name"table body
  
assign (l_table_nameto <table>.                "not headerline

*&SPWIZARD: mark all filled lines                                      *
  
loop at <table> assigning <wa>.

*&SPWIZARD: access to the component 'FLAG' of the table header         *
    
assign component p_mark_name of structure <wa> to <mark_field>.

    <mark_field> 
'X'.
  
endloop.
endform.                                          "fcode_tc_mark_lines

*&---------------------------------------------------------------------*
*&      Form  FCODE_TC_DEMARK_LINES
*&---------------------------------------------------------------------*
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 <tc>         type cxtab_control.
  
field-symbols <table>      type standard table.
  
field-symbols <wa>.
  
field-symbols <mark_field>.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

  
assign (p_tc_nameto <tc>.

*&SPWIZARD: get the table, which belongs to the tc                     *
  
concatenate p_table_name '[]' into l_table_name"table body
  
assign (l_table_nameto <table>.                "not headerline

*&SPWIZARD: demark all filled lines                                    *
  
loop at <table> assigning <wa>.

*&SPWIZARD: access to the component 'FLAG' of the table header         *
    
assign component p_mark_name of structure <wa> to <mark_field>.

    <mark_field> 
space.
  
endloop.
endform.                                          "fcode_tc_mark_lines

*---以下代码是自已添加:
*&---------------------------------------------------------------------*
*&      Module  STATUS_1001  OUTPUT
*&---------------------------------------------------------------------*
module status_1001 output.
  
set pf-status 'STATUS_1001'.
endmodule.                 " STATUS_1001  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_1001  INPUT
*&---------------------------------------------------------------------*
module user_command_1001 input.
  
case ok_code.
    
when '&F03' or '&F12' or '&F15'.
      
leave program.
    
when '&DATA_SAVE'.
      
datalt_zstu type table of zstu with header line.
      
loop at gt_01.
        
move-corresponding gt_01 to lt_zstu.
        
append lt_zstu.
      
endloop.
      
modify zstu from table lt_zstu.
      
message '数据库已更新!' type 'I'.
  
endcase.
endmodule.                 " USER_COMMAND_1001  INPUT
*&---------------------------------------------------------------------*
*&      Module  FILL_TABCTL1  OUTPUT
*&---------------------------------------------------------------------*
module fill_tabctl1 output.
  
read table gt_01 index tabctl1-current_line.  "一行代码就实现了从内表到table control的数据传输
endmodule.                 " FILL_TABCTL1  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  READ_TABCTL1  INPUT
*&---------------------------------------------------------------------*
module read_tabctl1 input.
  
modify gt_01 index tabctl1-current_line.      "一行代码就实现了从table control到内表的数据传输
endmodule.                 " READ_TABCTL1  INPUT 

完整逻辑流如下:
process before 
output.
*&SPWIZARD: PBO FLOW LOGIC FOR TABLECONTROL 'TABCTL1'
  
module tabctl1_change_tc_attr.
*&SPWIZARD: MODULE TABCTL1_CHANGE_COL_ATTR.
  
loop at   gt_01
       
into gt_01
       
with control tabctl1
       
cursor tabctl1-current_line.

    
module tabctl1_get_lines.
    
module fill_tabctl1.      "自定义module,用内表数据填充table control
*&SPWIZARD:   MODULE TABCTL1_CHANGE_FIELD_ATTR
  
endloop.

  
module status_1001.
*
process after 
input.
*&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'TABCTL1'
  
loop at gt_01.
    chain
.
      
field gt_01-sno.
      
field gt_01-sname.
      
field gt_01-ssex.
      
field gt_01-sage.
      
module tabctl1_modify on chain-request.
    endchain
.
    
field gt_01-zsel
      
module tabctl1_mark on request.

    
module read_tabctl1.    "自定义module,table control数据来更新内表
  
endloop.
  
module tabctl1_user_command.
*&SPWIZARD: MODULE TABCTL1_CHANGE_TC_ATTR.
*&SPWIZARD: MODULE TABCTL1_CHANGE_COL_ATTR.

  
module user_command_1001.

 

删除表条目,tabctl-action 'D'
插入表条目,tabctl-action 'N'
插入后删除,tabctl-action 'X'

  评论这张
 
阅读(759)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018