开发:报表公共单元(二)ALV表格显示
FUNCTION ZLXS_ALV .
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(I_TITLE) TYPE STRING
*" REFERENCE(FIELD_LIST) TYPE STRING
*" VALUE(SORT_FIELD) TYPE STRING OPTIONAL
*" VALUE(IS_VARI) TYPE SLIS_VARI OPTIONAL
*" VALUE(IS_IMPORT) TYPE STRING DEFAULT 'X'
*" TABLES
*" I_ITAB
*"----------------------------------------------------------------------
*表头字段名和中文描述处理定义
DATA: T_STR(2048) TYPE C,
S_TMP(100) TYPE C,
STR_EN(30) TYPE C,
STR_CH(50) TYPE C,
S_I TYPE I,
S_E TYPE I,
S_POS TYPE I.
*ALV 表格变量定义
DATA: M_TITLE TYPE LVC_TITLE,
MV TYPE I,
MSTR(6) TYPE C.
M_TITLE = I_TITLE.
MV = LINES( I_ITAB ).
MOVE MV TO MSTR.
SHIFT MSTR LEFT DELETING LEADING SPACE.
IF SY-LANGU = '1'.
CONCATENATE M_TITLE '(' MSTR '条记录)' INTO M_TITLE.
ELSE.
CONCATENATE M_TITLE '(' MSTR ' Record)' INTO M_TITLE.
ENDIF.
TYPE-POOLS SLIS.
DATA POS TYPE I.
DATA: I_FIELDCAT_ALV TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
I_LAYOUT TYPE SLIS_LAYOUT_ALV, "alv的格式
I_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
W_REPID LIKE SY-REPID.
* 定义排序字段
DATA IT_SORT TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE.
IF SORT_FIELD IS NOT INITIAL AND SORT_FIELD <> ''.
IT_SORT-FIELDNAME = SORT_FIELD.
IT_SORT-TABNAME = I_ITAB.
APPEND IT_SORT.
ENDIF.
I_LAYOUT-ZEBRA = 'X'.
I_LAYOUT-DETAIL_POPUP = 'X'.
W_REPID = SY-REPID.
I_LAYOUT-F2CODE = '&ETA'.
I_LAYOUT-NO_VLINE = ''.
I_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
I_LAYOUT-DETAIL_INITIAL_LINES = 'X'.
IF SY-LANGU = '1'.
I_LAYOUT-DETAIL_TITLEBAR = '详细内容'.
ELSE.
I_LAYOUT-DETAIL_TITLEBAR = 'Details'.
ENDIF.
*输出字段定义
REFRESH I_FIELDCAT_ALV.
POS = 1.
CLEAR I_FIELDCAT.
*表头字段与中文描述, 必须按以下格式填写
T_STR = FIELD_LIST.
S_I = STRLEN( T_STR ) .
DO.
SEARCH T_STR FOR '|'.
IF SY-FDPOS = 0.
EXIT.
ENDIF.
" 截取字符, 返回 A,B
S_POS = SY-FDPOS.
S_TMP = T_STR+0(S_POS).
" 去除已截取部份
S_POS = SY-FDPOS + 1.
* T_STR = T_STR+S_POS(S_I).
T_STR = T_STR+S_POS. " ADD BY LH 20180927
" 分离 A,B 字符
SEARCH S_TMP FOR ','.
S_POS = SY-FDPOS.
STR_EN = S_TMP+0(S_POS).