ALV GRID(1) 例子

ALV GRID 应该是最常用的显示方式了,下面我举一个例子:查询物料描述及物料组

 1 REPORT  ZTEST01.
 2 
 3 tables:mara,makt.
 4 
 5 type-pools:slis.
 6 
 7 types:begin of typ_mara,
 8   matnr type mara-matnr,
 9   maktx type makt-maktx,
10   matkl type mara-matkl,
11   end of typ_mara.
12 data:gt_mara type standard table of typ_mara.
13 
14 select-options:s_matnr for mara-matnr.
15 
16 start-of-selection.
17   perform sub_get_data.
18   perform sub_alv_data.
19 
20 *&---------------------------------------------------------------------*
21 *&      Form  sub_get_data
22 *&---------------------------------------------------------------------*
23 *       text
24 *----------------------------------------------------------------------*
25 form sub_get_data.
26   select mara~matnr makt~maktx mara~matkl
27     into corresponding fields of table gt_mara
28     from mara
29     left join makt
30     on mara~matnr = makt~matnr and makt~spras = sy-langu
31     where mara~matnr in s_matnr.
32 endform.                    "sub_get_data
33 
34 *&---------------------------------------------------------------------*
35 *&      Form  sub_alv_data
36 *&---------------------------------------------------------------------*
37 *       text
38 *----------------------------------------------------------------------*
39 form sub_alv_data.
40 
41   data: ltd_cat type standard table of slis_fieldcat_alv,
42         lth_cat type slis_fieldcat_alv.
43 
44   data: ls_lay type slis_layout_alv.  "alv布局
45   ls_lay-colwidth_optimize = 'X'.
46 
47   lth_cat-fieldname = 'MATNR'.
48   lth_cat-seltext_s = '物料编码'.
49   append lth_cat to ltd_cat.
50   clear lth_cat.
51   lth_cat-fieldname = 'MAKTX'.
52   lth_cat-seltext_s = '描述'.
53   append lth_cat to ltd_cat.
54   clear lth_cat.
55   lth_cat-fieldname = 'MATKL'.
56   lth_cat-seltext_s = '物料组'.
57   append lth_cat to ltd_cat.
58   clear lth_cat.
59 
60   call function 'REUSE_ALV_GRID_DISPLAY'
61     EXPORTING
62       i_callback_program      = sy-repid
63       i_grid_title            = '批量查询'
64       i_callback_user_command = 'USER_COMMAND'
65       is_layout               = ls_lay  "gth_lay
66       it_fieldcat             = ltd_cat
67       i_save                  = 'A'
68     TABLES
69       t_outtab                = gt_mara.
70 
71 endform.                    "sub_alv_data
72 
73 
74 *&---------------------------------------------------------------------*
75 *&      Form  sub_command
76 *&---------------------------------------------------------------------*
77 *       text
78 *----------------------------------------------------------------------*
79 *      -->I_UCOMM    text
80 *      -->I_SELFIELD text
81 *----------------------------------------------------------------------*
82 form USER_command using i_ucomm like sy-ucomm
83                          i_selfield type slis_selfield.
84 
85   if i_ucomm = '&IC1'.
86     case i_selfield-fieldname.
87       when 'MATNR'.
88         set parameter id 'MAT' field I_selfield-value.
89         call transaction 'MM03' and skip first screen.
90     endcase.
91   endif.
92 
93 endform.                    "user_command

 

posted on 2016-04-05 18:09  ydream  阅读(358)  评论(0)    收藏  举报

导航