现在的位置: 首页 > 综合 > 正文

使用动态内表——ALV输出

2013年10月03日 ⁄ 综合 ⁄ 共 6801字 ⁄ 字号 评论关闭

最近开发在执海关合同维护系统时,对进口料件的汇总,由于栏位显示与出口成品的品种多少相关,所以显示的栏位是不确定的,为此研究了一番。

同样,在报关时,不管是对出口成品还是进口料件报关,栏位显示都与出口成品品种或进口料件品种相关。在同一行上显示所有的出口成品或进口料件,对于操作人员来说都是一件易操作的表现。

 

程序设计要注意事项:

第一、  
每一张合同中出口成品品种数量的多少确定;

第二、  
每一种或每类出口成品共同属性是否具有相同性,比如在进口料件汇总表中对于每一类出口成品都有单耗、损耗,数量,耗边料数特性。

第三、  
进口料件汇总表固定列位确定。

第四、  
动态创建内表区域。

 

动态创建报关数量登记表:

 perform container_free_2.
 
perform create_structure_1 USING len '进口料件'.
 
perform create_table_display_2.
 
perform ctable_for_atci.

 

form container_free_2.
   
if not g_custom_container_2 is initial .
     
call method  g_custom_container_2->free.
     
clear g_custom_container_2.
   
endif.
endform.

 

form create_structure_1 USING II mtart.  "报关出口成品相关处理

  DATA : ERTXT TYPE string,
         ERTTX 
TYPE string,
         ERNUM 
TYPE string,
         ERIND 
TYPE I.

  clear it_structure[].

  wa_structure-fieldname = 'BGDHA'.  第一列列名      报关单号
  wa_structure-col_pos   = 
1.       表示第一列
  wa_structure-inttype = 
'C'.       数据类型
  wa_structure-intlen = 
18.          长度
  wa_structure-
decimals = 0 .
  wa_structure-ref_table = 
'' .
  wa_structure-ref_field = 
'' .
  wa_structure-coltext = 
'报关单号' .
  wa_structure-seltext = 
'报关单号' .
  wa_structure-just = 
'C' .
  wa_structure-
edit = 'X' .
  wa_structure-outputlen = 
18 .
  wa_structure-fix_column = 
'X' .
  
APPEND wa_structure TO it_structure.

  wa_structure-fieldname = 'BUDAT'.             "报关日期
  wa_structure-col_pos   = 
2.
  wa_structure-inttype = 
'D'.
  wa_structure-intlen = 
18.
  wa_structure-
decimals = 0 .
  wa_structure-ref_table = 
'ZSD19ATCI' .
  wa_structure-ref_field = 
'BUDAT' .
  wa_structure-coltext = 
'日期' .
  wa_structure-seltext = 
'日期' .
  wa_structure-just = 
'C' .
  wa_structure-
edit = 'X' .
  wa_structure-outputlen = 
12 .
  wa_structure-fix_column = 
'X' .
  
APPEND wa_structure TO it_structure.

  erind = 2 .
  
DO II TIMES.
    ernum = ernum + 
1 .
    erind = erind + 
1.
    
CONCATENATE 'ERFMG' ernum into ERTXT.
    
CONCATENATE mtart ernum into ERTTX.
    
CONDENSE ERTXT NO-GAPS.
    
CONDENSE ERTTX NO-GAPS.
    wa_structure-fieldname = ERTXT.             
"报关数量,对应每一个出口成品
    wa_structure-col_pos   = erind.
    wa_structure-inttype = 
'P'.
    wa_structure-intlen = 
13.
    wa_structure-
decimals = 3 .
    wa_structure-ref_table = 
'ZSD19ATCI' .
    wa_structure-ref_field = 
'ERFMG' .
    wa_structure-coltext = ERTTX .
    wa_structure-seltext = ERTTX .
    wa_structure-just = 
'R' .
    wa_structure-
edit = 'X' .
*    wa_structure-do_sum = 'X'.
    wa_structure-outputlen = 
13 .
    wa_structure-fix_column = 
'' .
    
APPEND wa_structure TO it_structure.
  
ENDDO.
endform.

 

 

form create_table_display_2.
  
create object g_custom_container_2
         
exporting container_name = g_container_2.
  
create object g_grid
         
exporting i_parent = g_custom_container_2.
endform.

 

form ctable_for_atci.
   
data: gs_layout type lvc_s_layo.

   data: lt_exclude type ui_functions.
   
data: retxt type string,
         renum 
type string.

   clear gt_fieldcat[] .
   
clear it_fieldcat[].

   perform exclude_tb_functions changing lt_exclude.
   
perform cfield_atci using '' changing gt_fieldcat it_fieldcat.
   
perform f4_alv_field.

   assign new_table->* to <l_table>.
   
create data new_line like line of <l_table>.
   
assign new_line->* to <l_line>.
   
clear <l_table>[].
   
create data old_table like <l_table>.
   
assign old_table->* to <old_table>.

*   <l_table>[] = t_sunh[] .

   loop at r_atci.

      ASSIGN COMPONENT 'BGDHA' OF STRUCTURE <l_line> TO <l_field>.
      <l_field> = r_atci-bgdha.

      ASSIGN COMPONENT 'BUDAT' OF STRUCTURE <l_line> TO <l_field>.
      <l_field> = r_atci-budat.

      loop at t_atci where hname = r_atci-hname and bgdha = r_atci-bgdha and budat = r_atci-budat.
          
clear s_atci.
          
read table s_atci with key hname = t_atci-hname extwg = t_atci-extwg.
          renum = sy-tabix.
          
concatenate 'ERFMG' renum into retxt.

          ASSIGN COMPONENT retxt OF STRUCTURE <l_line> TO <l_field>.
          <l_field> = t_atci-erfmg.
      
endloop.
      
INSERT <l_line> INTO TABLE <l_table>.
   
endloop.

   set handler z_receiver->handle_before_user_command for g_grid.
   
set handler z_event_double->handle_onf4 for g_grid.

   call method g_grid->register_edit_event
           
exporting
               i_event_id = cl_gui_alv_grid=>mc_evt_enter.

   call method g_grid->register_f4_for_fields
      
exporting
        it_f4 = lt_f4.

   call method g_grid->set_table_for_first_display
      
exporting
       is_layout            = gs_layout
       it_toolbar_excluding = lt_exclude
       i_save                        = 
'A'
*       i_buffer_active               = 'X'
      
changing
*      IT_SORT          = GB_SORTFLD
       it_outtab            = <l_table>[]
       it_fieldcatalog      = gt_fieldcat[]
       it_sort              = gt_sort .

  call method g_grid->set_ready_for_input "处于非编辑状态
          
exporting
            i_ready_for_input = 
1.
     
call method cl_gui_control=>set_focus    "设置焦点在go_grid 
         
exporting
           
control = g_grid .
          <old_table>[] = <l_table>[].

  CALL METHOD cl_gui_cfw=>flush
    
EXCEPTIONS
      cntl_system_error = 
1
      cntl_error        = 
2.

endform.         "ctable_for_atci

 

form cfield_atci using dab changing pt_fieldcat type lvc_t_fcat ft_fieldcat type lvc_t_fcat.

 data : stnum type i.

 clear lf_fieldcat[].

 loop at it_structure into wa_structure.
 “

   m_fieldcat wa_structure-fieldname wa_structure-ref_table  wa_structure-ref_field wa_structure-coltext wa_structure-just wa_structure-
edit wa_structure-outputlen wa_structure-fix_column.

 endloop.

 loop at lf_fieldcat.
   
if lf_fieldcat-fieldname = 'BGDHA' OR lf_fieldcat-fieldname = 'BUDAT' . "设置关键字段
       lf_fieldcat-
key = 'X' .
       lf_fieldcat-F4AVAILABL = 
'X'.
       
modify lf_fieldcat index sy-tabix.
   
endif.
   
if lf_fieldcat-ref_field = 'ERFMG'.
       lf_fieldcat-do_sum = 
'X' .           "汇总求和
       lf_fieldcat-no_zero = 
'X' .          "隐藏零
       
modify lf_fieldcat index sy-tabix.
   
endif.
   
if lf_fieldcat-fieldname = 'ERFMO'.
        lf_fieldcat-coltext = dab.
        lf_fieldcat-emphasize = 
'C601' .     "红色
       
modify lf_fieldcat index sy-tabix.
   
endif.
   
if lf_fieldcat-fieldname = 'ZJLYL'.
        lf_fieldcat-emphasize = 
'C601' .     "红色
       
modify lf_fieldcat index sy-tabix.
   
endif.
   
if lf_fieldcat-fieldname+0(4) = 'FLAG'.
        lf_fieldcat-emphasize = 
'C61' .     "深红色
       
modify lf_fieldcat index sy-tabix.
   
endif.
 
endloop.

 append lines of lf_fieldcat to pt_fieldcat.

 clear lf_fieldcat[].
 
loop at it_structure into wa_structure.
   st_fieldcat wa_structure-fieldname wa_structure-col_pos wa_structure-inttype wa_structure-intlen  wa_structure-
decimals.
 
endloop.

 append lines of lf_fieldcat to ft_fieldcat .

 clear new_table .
 
call method cl_alv_table_create=>create_dynamic_table
      
exporting
        it_fieldcatalog = it_fieldcat
      
importing
        ep_table        = new_table.
endform.                  "cfield_atci

转自:http://blog.chinaunix.net/u1/50618/showart_1915346.html

抱歉!评论已关闭.