输出数据,分别用子程序处理ALV 相关的Fieldcat 及Layout. 最后调用REUSE_ALV_GRID_DISPLAY输出ALV:
其中:
i_callback_user_command = 'USER_COMMAND' 及
I_CALLBACK_PF_STATUS_SET = 'PF_STATUS_SET'有点特别,请见后。
布局部分:
ALV中,欲保存布局,须在REUSE_ALV_GRID_DISPLAY函数中添加I_SAVE参数。I_SAVE定义为C数据类型,值如下:
‘ ‘ = display variants cannot be saved
Defined display variants (e.g. delivered display variants) can be selected for presentation independently of this flag. Changes can not be saved.
‘X’ = standard save
Display variants can be saved as standard display variants. User-specific saving is not possible.
‘U’ = only user-specific saving
The user can only save display variants user-specifically
‘A’ = standard and user-specific saving
The user can save a display variant user-specifically and as standard display variant. The user chooses in the display variant save popup.
为了进一步管理布局,则需要加入IS_VARIANT参数,其数据结构参考DISVARIANT,一般需要定义其中的REPORT=SY-REPID,VARIANT为布局保存格式。有三个有用函数供调用保存的格式布局,分别为:
REUSE_ALV_VARIANT_DEFAULT_GET 读取默认的布局
REUSE_ALV_VARIANT_EXISTENCE 检测指定布局是否存在
REUSE_ALV_VARIANT_F4 显示布局格式选择对话窗
FORM output_data.
PERFORM addfield.
PERFORM layout.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_user_command = 'USER_COMMAND'
* I_CALLBACK_PF_STATUS_SET = 'PF_STATUS_SET'
* I_GRID_TITLE = G_TITLE
it_fieldcat = gt_fieldcat[]
is_layout = gs_layout
is_variant = g_variant ”可调用变式
i_save = 'A' “这是保存变式
TABLES
t_outtab = gt_out[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. "OUTPUT_DATA
ALV 相关的Fieldcat : 对一些字段要求相同的,用FILED_TYPE区别:
FORM addfield.
PERFORM e01_fieldcat_init USING:
'INFNR' 'Info record NO.' 6 '' '' 'Q' '' '',
'LIFNR' 'Vendor' 6 '' '' 'Q' '' 'X',
'MATNR' 'Material NO.' 6 '' '' ' ' '' 'X',
'EKORG' 'Purchasing Org.' 10 '' '' ' ' '' '',
'WERKS' 'Plant' 25 '' '' ' ' '' '',
'ESOKZ' 'Infotype' 10 '' '' ' ' '' '',
'MEINS' 'PO Unit' 25 '' '' ' ' '' '',
'UMREZ' 'Numerator for conversion' 10 '' '' ' ' '' '',
'UMREN' 'Denominator for conversion' 10 '' '' ' ' '' '',
'VABME' 'Var. PO Unit Active' 10 '' '' ' ' '' '',
'NETPR' 'Net price' 10 '' '' 'C' '' '',
'WAERS' 'Currency' 10 '' '' ' ' '' '',
'PEINH' 'Price unit' 6 '' '' ' ' '' '',
'BPRME' 'Order Price Unit' 18 '' '' ' ' '' '',
*{ SAPCI-2801 Start
'MM_NETPR' text-h01 10 space space 'C' space space,
'MM_PEINH' text-h02 6 space space space space space,
'LMEIN' text-h03 6 space space space space space,
*} SAPCI-2801 End
'DATAB' 'Valid From' 35 '' '' ' ' '' '',
'DATBI' 'Valid To' 18 '' '' ' ' '' '',
'MWSKZ' 'Tax Code' 13 '' '' ' ' '' '',
'MFRNR' 'Manufacturer' 13 '' '' ' ' '' '',
'EKGRP' 'Pur. Group' 10 '' '' '' '' '',
'APLFZ' 'Planned Delivery Days' 10 '' '' ' ' '' '',
'MINBM' 'Minimum PO Quantity' 6 '' '' ' ' '' '',
'NORBM' 'Standard PO Quantity' 13 '' '' ' ' '' '',
'INCO1' 'Incoterms1' 10 '' '' ' ' '' '',
'INCO2' 'Incoterms2' 6 '' '' ' ' '' '',
'IDNLF' 'Vendor Material' 13 '' '' ' ' '' '',
'MFR_CODE' 'Mfr Code' 13 '' '' ' ' '' '',
'MFR_NAME' 'Mfr Name' 35 '' '' ' ' '' '',
'MPN_NO' 'MPN number' 20 '' '' ' ' '' '',
'MFRPN' 'Mfr Part Number' 40 '' '' ' ' '' '',
'BRAND' 'Brand' 15 '' '' ' ' '' '',
'BRAND_TYP' 'Brand Type' 45 '' '' ' ' '' '',
'AENAM' 'Changed By' 12 '' '' ' ' '' '',
'AEDAT' 'Changed On' 18 '' '' ' ' '' '',
'AETIM' 'Time of Last Change' 18 '' '' ' ' '' '',
'RELIF' 'Regular Vendor' 20 '' '' ' ' '' '',
'POTXT' 'PO text' 13 '' '' ' ' '' '',
'KSTBM' 'Scale Quantity' 13 '' '' ' ' '' '',
'KBETR' 'Scale Amount' 10 '' '' 'C' '' '',
'URZLA' 'country of origin' 13 '' '' ' ' '' '',
'TELF1' 'telephone' 13 '' '' ' ' '' '',
'LOEKZ' 'Deletion flag of Purch.org.' 13 '' '' ' ' '' '',
'LOEVM_KO' 'Deletion flag of Condition' 13 '' '' ' ' '' '',
'MMSTA' 'Plant-Specific Material Status' 13 '' '' ' ' '' '',
'KNUMH' 'Condition record no.' 10 '' '' ' ' '' '',
'KOPOS' 'Sequential number of the condition' 3 '' '' ' ' '' ''.
* 'VOLEH ' 'Volume Unit' 13 '' '' 'Q' '' '',
* 'KWMENG2' 'SO Qty in CAR' 13 '' '' 'Q' '' '',
* 'MENGE3' 'STO2 Qty in CAR (3200)' 20 '' '' 'Q' '' '',
* 'VOLUM' 'SO Volume' 10 '' '' '' '' ''.
ENDFORM. "ADDFIELD
中间e01_fieldcat_init部分:Field_type = Q or C or V 或其他分别给值:
no_zero 如果取值为零,则为空,既不输出零;
just: 对其方式,R 右对齐
no_convext,Do not consider conversion exit for output
qfieldname 参考计量单位的字段名称
qtabname Qfieldname 对应的输出内表名
对销售单位及体积单位给了值:
ALV FIELDCAT详细字段值可叁考:分类讲得很详细。
https://blog.csdn.net/champaignwolf/article/details/79662527
FORM e01_fieldcat_init
USING field_name TYPE c
field_text TYPE c
field_lenth TYPE i
field_edit TYPE c
field_checkbox TYPE c
field_type TYPE c
field_key TYPE c
fix_column TYPE c.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = field_name.
ls_fieldcat-seltext_l = field_text.
IF field_type EQ 'Q'.
ls_fieldcat-just = 'R'.
ls_fieldcat-no_zero = 'X'.
ls_fieldcat-qtabname = 'VBDPA'.
ls_fieldcat-qfieldname = 'VRKME'.
ELSEIF field_type EQ 'C'.
ls_fieldcat-just = 'R'.
ls_fieldcat-no_zero = 'X'.
ELSEIF field_type EQ 'V'.
ls_fieldcat-just = 'R'.
ls_fieldcat-no_zero = 'X'.
ls_fieldcat-qtabname = 'VBDPA'.
ls_fieldcat-qfieldname = 'VOLEH'.
ELSE.
ls_fieldcat-no_convext = 'X'.
ls_fieldcat-just = 'L'.
ENDIF.
* LS_FIELDCAT-CHECKBOX = FIELD_CHECKBOX.
ls_fieldcat-outputlen = field_lenth.
ls_fieldcat-edit = field_edit.
ls_fieldcat-key = field_key.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
ENDFORM. "E01_FIELDCAT_INIT
LAYOUT只是给了优化列宽设置及使ALV表格按斑马线间隔条码方式显示:
FORM layout.
gs_layout-colwidth_optimize = 'X'.
gs_layout-zebra = 'X'.
* GS_LAYOUT-BOX_FIELDNAME = 'SEL'.
* GS_LAYOUT-COLTAB_FIELDNAME = 'COLOR'.
ENDFORM. "layout
I_CALLBACK_PF_STATUS_SET:ALV工具栏Subroutine(子程序)
I_CALLBACK_USER_COMMAND:ALV User Command Subroutine(子程序),实现对应菜单项及相应事件功能
详细请参考,非常不错:https://www.cnblogs.com/hcmy00/p/6524107.html
热点链接
热点链接,即 Fieldcat中 的 hotspot 属性;
设置之后,当用户点击带有热点的字段时,就会触发 Subroutine(FRM_USER_COMMAND)中的动作;对于热点链接,所对应的FCode为 “&IC1“;
FORM user_command USING r_ucomm TYPE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&IC1'.
CASE rs_selfield-fieldname.
WHEN 'B_NETPR1'.
CALL FUNCTION 'DSYS_SHOW_FOR_F1HELP'
EXPORTING
* APPLICATION = 'SO70'
dokclass = 'TX'
doklangu = 'E'
dokname = 'Z_B_NETPR1'
* DOKTITLE = ' '
* HOMETEXT = ' '
* OUTLINE = ' '
* VIEWNAME = 'STANDARD'
* Z_ORIGINAL_OUTLINE = ' '
* CALLED_FROM_SO70 = ' '
* SHORT_TEXT = ' '
* APPENDIX = ' '
* IMPORTING
* APPL =
* PF03 =
* PF15 =
* PF12 =
EXCEPTIONS
class_unknown = 1
object_not_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDCASE.
ENDCASE.
ENDFORM. "USER_COMMAND
如上逻辑仅在点击字段 Base Net Unit Price时弹出如下框给出说明:
对于屏幕上的field,我们通常可以使用f1调出它对应的data element的documention,要维护data element的文本可在data element修改状态勾选那个 change document checkbox,然后点击documentation就可以修改了。
但是我们如何针对屏幕上面任意一个field去调用f1 help文档呢?
首先当然要创建f1 help文挡,在se61创建TX document class的文挡并且指定语言
https://blog.csdn.net/feijibin/article/details/9107161