有些情况下,要展示的内表的字段实在是太多,一个一个去处理fieldcat非常麻烦,可以使用下面的思路根据传入的数据内表结构动态生成fieldcat,并对特别有需要的字段进行自定义处理。简单、便捷。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
form fm_fldcat tables pt_fieldcat structure lvc_s_fcat using pt_table type any table. data: lr_tabdescr type ref to cl_abap_structdescr, lr_data type ref to data, lt_dfies type ddfields, ls_dfies type dfies, ls_fieldcat type lvc_s_fcat, lv_period type c length 2. clear pt_fieldcat. create data lr_data like line of pt_table. lr_tabdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ). lt_dfies = cl_salv_data_descr=>read_structdescr( lr_tabdescr ). delete lt_dfies where fieldname eq 'MANDT'. loop at lt_dfies into ls_dfies. clear ls_fieldcat. move-corresponding ls_dfies to ls_fieldcat. case ls_fieldcat-fieldname. when 'ICONNAME'. ls_fieldcat-scrtext_m = '状态'. ls_fieldcat-scrtext_s = '状态'. ls_fieldcat-scrtext_l = '状态'. ls_fieldcat-reptext = '状态'. when 'ZMESG'. ls_fieldcat-scrtext_m = '消息'. ls_fieldcat-scrtext_s = '消息'. ls_fieldcat-scrtext_l = '消息'. ls_fieldcat-reptext = '消息'. ls_fieldcat-key = 'X'. when 'BELNR'. ls_fieldcat-hotspot = 'X'. ls_fieldcat-key = 'X'. when 'BUDAT'. ls_fieldcat-key = 'X'. when 'RSTGR'. ls_fieldcat-scrtext_m = '流量码'. ls_fieldcat-scrtext_s = '流量码'. ls_fieldcat-scrtext_l = '流量码'. ls_fieldcat-reptext = '流量码'. when 'BUKRS'. ls_fieldcat-ref_field = 'BUKRS'. ls_fieldcat-ref_table = 'T001'. when 'NPS'. if p01 = 'X'. ls_fieldcat-edit = 'X'. endif. when 'STBLG'. ls_fieldcat-scrtext_m = '冲销凭证'. ls_fieldcat-scrtext_s = '冲销凭证'. ls_fieldcat-scrtext_l = '冲销凭证'. ls_fieldcat-reptext = '冲销凭证'. when 'STBDT'. ls_fieldcat-scrtext_m = '冲销日期'. ls_fieldcat-scrtext_s = '冲销日期'. ls_fieldcat-scrtext_l = '冲销日期'. ls_fieldcat-reptext = '冲销日期'. when 'STBTM'. ls_fieldcat-scrtext_m = '冲销时间'. ls_fieldcat-scrtext_s = '冲销时间'. ls_fieldcat-scrtext_l = '冲销时间'. ls_fieldcat-reptext = '冲销时间'. when 'STBUS'. ls_fieldcat-scrtext_m = '冲销账号'. ls_fieldcat-scrtext_s = '冲销账号'. ls_fieldcat-scrtext_l = '冲销账号'. ls_fieldcat-reptext = '冲销账号'. when 'NPH'. ls_fieldcat-no_out = 'X'. when 'NPACS'. ls_fieldcat-no_out = 'X'. when others. endcase. append ls_fieldcat to pt_fieldcat. endloop. if p01 = 'X'. delete pt_fieldcat[] where fieldname eq 'STBLG'. delete pt_fieldcat[] where fieldname eq 'STBDT'. delete pt_fieldcat[] where fieldname eq 'STBTM'. delete pt_fieldcat[] where fieldname eq 'STBUS'. delete pt_fieldcat[] where fieldname eq 'STGRD'. endif. endform. |
然后直接调用该FORM生成fieldcat内表即可。
1 2 3 4 5 6 7 8 9 |
*-----新ALV输出参数. data: go_grid type ref to cl_gui_alv_grid. field-symbols: <fs_table> type standard table. data:gt_fcat type lvc_t_fcat, gs_fcat type lvc_s_fcat, gt_styls type lvc_t_styl. perform fm_fldcat tables gt_fcat using <fs_table> . |
本文作者: GavinDong
版权属于: GavinDong博客
文章链接: https://gavindong.com/3142.html
如果使用过程中遇到问题,可 **点击此处** 交流沟通。
版权所有,转载时必须以链接形式注明作者和原始出处及本声明。