*&---------------------------------------------------------------------*
*& Report ZMMI005
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Sub-system : MM
* Program ID : ZMMI005
* Program Name : 分类特性批量导入
* Transaction : ZMMI005
*----------------------------------------------------------------------*
* <Summary>
* 特性主数据的创建或已经创建数据的更改
*----------------------------------------------------------------------*
* <Update Rec>
* Update Date No. Updater Content
* ----------- ---- ------------ -------------------------------*
*----------------------------------------------------------------------*
REPORT ZMMI005.
*----------------------------------------------------------------------*
* TYPE DEF
*----------------------------------------------------------------------*
TYPES:
BEGIN OF TYP_DATA,
* no1 TYPE char2,
* class TYPE char10,
* matkl TYPE matkl,
* wgbez TYPE wgbez,
BOX(1),
CHARACT_NAME TYPE STRING, "特征
DESCRIPTION TYPE STRING, "特性描述
DESCRIPTION_E TYPE STRING, "特性描述
* charact_group TYPE string, "特性组
VALUE_S TYPE STRING, "单一值
VALUE_M TYPE STRING, "多值
DATA_TYPE TYPE STRING, "数据类型
LENGTH TYPE STRING, "字符数
DECIMALS TYPE STRING, "小数位
EINHE TYPE STRING, "单位
*
* atint TYPE string, "允许间隔值
* atvor TYPE string, "允许负值
ENTRY_REQUIRED TYPE STRING, "必需输入
ATSON TYPE STRING, "附加值
DEFAULT_VALUE TYPE STRING, "是否默认值
VALUE_CHAR TYPE STRING, "特性值
ATWTB TYPE STRING, "特性值描述
ATWTB_E TYPE STRING, "特性值描述
LIGHT TYPE C1, "红黄绿灯 1 红灯 2 黄灯 3 绿灯
STYLE TYPE LVC_T_STYL, "FOR DISABLE
MSG(200), "消息内容
END OF TYP_DATA.
*常量定义
CONSTANTS:CNS_TEMPNAME LIKE WWWDATA-OBJID VALUE 'ZMMI004', "服务器模板名称
CNS_PATH LIKE RLGRAP-FILENAME VALUE 'C:\SAPTMP\', "本地处理临时文件夹
CNS_MACRO TYPE CHAR256 VALUE 'AUTOFILL'. "Excel宏名称
*----------------------------------------------------------------------*
* INTERNAL TABLE DEF
*----------------------------------------------------------------------*
DATA: GT_ITAB TYPE TABLE OF TYP_DATA WITH HEADER LINE,
GS_ITAB TYPE TABLE OF TYP_DATA WITH HEADER LINE,
GB_ITAB TYPE TABLE OF TYP_DATA WITH HEADER LINE,
GL_ITAB TYPE TABLE OF TYP_DATA WITH HEADER LINE.
DATA:
TD_DATA TYPE TABLE OF TYP_DATA, "input数据
TD_DATA_ERR TYPE TABLE OF TYP_DATA, "错误数据
TD_DATA_BAK TYPE TABLE OF TYP_DATA, "备份数据
TD_DESCR TYPE TABLE OF BAPICHARACTDESCR, "特性描述
TD_NUM TYPE TABLE OF BAPICHARACTVALUESNUM, "许可的 NUM 字符值
TD_CHAR TYPE TABLE OF BAPICHARACTVALUESCHAR, "许可的 CHAR 字符值
TD_CURR TYPE TABLE OF BAPICHARACTVALUESCURR, "许可的 CURR 字符值
TD_SDESCR TYPE TABLE OF BAPICHARACTVALUESDESCR, "特性值描述
TD_RETURN TYPE TABLE OF BAPIRET2. "返回参数
* td_ztcharact TYPE TABLE OF ztcharact.
DATA: BEGIN OF GG_ITAB OCCURS 0,
CLASS(18), "类
KLART(3), "类类型
KLBEZ(40), "类描述
STATU(1), "状态
ATNAM(30), "特性
VWSTL(1), "可用于物料清单
MEINS(2), "基本计量单位
POTPR(1), "结果项目类别
FLAG(1),
END OF GG_ITAB.
*----------------------------------------------------------------------*
* WORK DEF
*----------------------------------------------------------------------*
DATA:
TH_DATA TYPE TYP_DATA,
ST_DETAIL TYPE BAPICHARACTDETAIL,
W_NUM_ALL TYPE I, "总件数
W_NUM_OK TYPE I, "成功件数
W_NUM_ERR TYPE I. "失败件数
*----------------------------------------------------------------------*
* CONSTANTS DEF
*----------------------------------------------------------------------*
CONSTANTS:
CNS_FLG_ON(1) TYPE C VALUE 'X',
CNS_STATUS_1(1) TYPE C VALUE '1', "已发布
CNS_SPRAS_ZH TYPE SPRAS VALUE '1', "语言代码:ZH
CNS_ATBEW_S TYPE ATBEW VALUE 'S', "单值
CNS_ATBEW_M TYPE ATBEW VALUE 'M', "多值
CNS_ATUDF_C TYPE ATUDF VALUE '字符', "数据类型:CHAR
CNS_ATUDF_M TYPE ATUDF VALUE '数值'. "数据类型:CURR
DATA: CL_DESCR TYPE REF TO CL_ABAP_STRUCTDESCR.
FIELD-SYMBOLS:<FS_COMP> TYPE ABAP_COMPDESCR.
FIELD-SYMBOLS:<FS_NAME> TYPE ANY.
DATA: GV_FILENAME TYPE RLGRAP-FILENAME.
DATA: GV_OBJID LIKE WWWDATA-OBJID.
DATA: GV_STRING TYPE STRING.
DATA: GV_ERROR TYPE C.
DATA: GV_FLAG(1).
*定义ALV输出所需要的保存列名的内表和结构
TYPE-POOLS: SLIS.
DATA: GV_POS TYPE I.
DATA: LT_FIELDCAT TYPE LVC_S_FCAT OCCURS 0.
DATA: LS_FIELDCAT TYPE LVC_S_FCAT.
DATA: LS_LAYOUT TYPE LVC_S_LAYO.
DATA: LT_SORT TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE.
DATA: LT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
DATA: LS_EDIT TYPE LVC_S_STYL,
LT_EDIT TYPE LVC_T_STYL,
LT_GLAY TYPE LVC_S_GLAY.
DATA: REF_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA: GV_LIGHT TYPE LVC_CIFNM VALUE 'LIGHT'. "红黄绿灯
*----------------------------------------------------------------------*
* PARAMTER DEF(SELECT-OPTION etc.)
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK FNAME WITH FRAME TITLE TEXT-T01.
PARAMETERS:
P_FILE TYPE RLGRAP-FILENAME OBLIGATORY,
P_DOWN AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK FNAME.
*SELECTION-SCREEN BEGIN OF BLOCK MODE WITH FRAME TITLE TEXT-T02.
*PARAMETERS:
* RB_NEW RADIOBUTTON GROUP G1,
* RB_M RADIOBUTTON GROUP G1.
*
*SELECTION-SCREEN END OF BLOCK MODE.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_INPUT
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM FRM_FILENAME_GET.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
* 全局变量的初始化
PERFORM FRM_SET_INIT.
IF P_DOWN <> 'X'.
* 数据的取得
PERFORM FRM_UPDATE_DATA.
* 特性的删除
* PERFORM FRM_CALL_CU02.
PERFORM SUB_SHOW_ALV.
ELSE.
PERFORM EXCELTEMP_DOWN.
ENDIF.
*&---------------------------------------------------------------------*
*& Form FRM_SET_INIT
*&---------------------------------------------------------------------*
* 全局变量的初始化
*----------------------------------------------------------------------*
FORM FRM_SET_INIT .
REFRESH:
TD_DATA, "input数据
TD_DATA_ERR, "错误数据
TD_DATA_BAK,
TD_DESCR, "特性描述
TD_NUM, "许可的 NUM 字符值
TD_CHAR, "许可的 CHAR 字符值
TD_CURR, "许可的 CURR 字符值
TD_SDESCR, "特性值描述
TD_RETURN. "返回参数
CLEAR:
TH_DATA,
ST_DETAIL,
W_NUM_ALL, "总件数
W_NUM_OK, "成功件数
W_NUM_ERR. "失败件数
ENDFORM. " FRM_SET_INIT
*&---------------------------------------------------------------------*
*& Form FRM_FILENAME_GET
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_FILENAME_GET .
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_PATH = 'c:\ '
IMPORTING
FILENAME = P_FILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
STOP.
ENDIF.
ENDFORM. " FRM_FILENAME_GET
*&---------------------------------------------------------------------*
*& Form FRM_UPDATE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_UPDATE_DATA .
DATA: BEGIN OF IT_HEADER OCCURS 0,
COL LIKE ALSMEX_TABLINE-COL,
FIELD(20),
END OF IT_HEADER.
DATA: W_IDX TYPE I.
FIELD-SYMBOLS: <FS>.
DATA: L_INTERN TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA: C_ROW TYPE I VALUE 3, "读EXCEL第3行开始
C_COL TYPE I VALUE 1, "读EXCEL第1列开始
L_INDEX TYPE I,
L_MSG(60) TYPE C,
G_MOD TYPE D,
L_ROW(5) TYPE N,
LI_LEN TYPE SY-TABIX,
L_CSTR(4).
GV_FILENAME = P_FILE.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = GV_FILENAME
I_BEGIN_COL = C_COL
I_BEGIN_ROW = C_ROW
I_END_COL = 103
I_END_ROW = 50000
TABLES
INTERN = L_INTERN
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
SORT L_INTERN BY ROW COL.
L_ROW = C_ROW.
LOOP AT L_INTERN.
IF L_INTERN-ROW = 1.
IT_HEADER-COL = L_INTERN-COL.
CONDENSE L_INTERN-VALUE.
IT_HEADER-FIELD = L_INTERN-VALUE.
APPEND IT_HEADER.
ELSE.
MOVE L_INTERN-COL TO L_INDEX.
* READ TABLE IT_HEADER INDEX L_INDEX.
READ TABLE IT_HEADER WITH KEY COL = L_INDEX.
IF SY-SUBRC = 0.
ASSIGN COMPONENT IT_HEADER-FIELD OF STRUCTURE GS_ITAB TO <FS>.
IF SY-SUBRC = 0.
MOVE L_INTERN-VALUE TO <FS>.
ENDIF.
ENDIF.
AT END OF ROW.
MOVE-CORRESPONDING GS_ITAB TO GT_ITAB.
APPEND GT_ITAB.
CLEAR: GT_ITAB, GS_ITAB.
L_ROW = L_ROW + 1.
ENDAT.
ENDIF.
ENDLOOP.
"单元格是否可编辑设置
W_IDX = 0.
LOOP AT GT_ITAB.
REFRESH: LT_EDIT.
CLEAR: GS_ITAB.
W_IDX = W_IDX + 1.
CL_DESCR ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( GS_ITAB ).
LOOP AT CL_DESCR->COMPONENTS ASSIGNING <FS_COMP>.
* WRITE: / <fs_comp>-name, "字段名称
* <fs_comp>-type_kind, "字段类型
* <fs_comp>-length, "字段长度
* <fs_comp>-decimals. "字段小数位
IF <FS_COMP>-NAME <> 'BOX'.
LS_EDIT-FIELDNAME = <FS_COMP>-NAME.
LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
LS_EDIT-STYLE2 = SPACE.
LS_EDIT-STYLE3 = SPACE.
LS_EDIT-STYLE4 = SPACE.
LS_EDIT-MAXLEN = <FS_COMP>-LENGTH / 2.
INSERT LS_EDIT INTO TABLE LT_EDIT.
ENDIF.
ENDLOOP.
INSERT LINES OF LT_EDIT INTO TABLE GS_ITAB-STYLE.
MODIFY GT_ITAB INDEX W_IDX FROM GS_ITAB TRANSPORTING STYLE .
ENDLOOP.
SORT GT_ITAB BY CHARACT_NAME. "特征
ENDFORM. " FRM_UPDATE_DATA
*&---------------------------------------------------------------------*
*& Form FRM_CREATE_CHARACT
*&---------------------------------------------------------------------*
* 特性的登录
*----------------------------------------------------------------------*
FORM FRM_CREATE_CHARACT.
DATA:
LTH_DATA TYPE TYP_DATA.
LOOP AT GT_ITAB INTO GS_ITAB.
TH_DATA = GS_ITAB.
AT NEW CHARACT_NAME.
* 总件数
W_NUM_ALL = W_NUM_ALL + 1.
* 特性属性的设定
PERFORM FRM_SET_DETAIL.
ENDAT.
* 特性值的编辑
PERFORM FRM_SET_VALUES.
* 数据备份
APPEND TH_DATA TO TD_DATA_BAK.
AT END OF CHARACT_NAME.
* 特性的登录BAPI执行
PERFORM FRM_CALL_BAPI.
ENDAT.
ENDLOOP.
* INSERT ztcharact FROM TABLE ltd_charact ACCEPTING DUPLICATE KEYS.
ENDFORM. " FRM_CREATE_CHARACT
*&---------------------------------------------------------------------*
*& Form FRM_SET_F4_P_INPUT
*&---------------------------------------------------------------------*
* 文件路径的F4
*----------------------------------------------------------------------*
* <-- O_NAME 文件路径
*----------------------------------------------------------------------*
FORM FRM_SET_F4_P_INPUT CHANGING O_NAME TYPE RLGRAP-FILENAME.
DATA:
LW_FILE_NAME TYPE IBIPPARMS-PATH.
* CALL F4_FILENAME
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
IMPORTING
FILE_NAME = LW_FILE_NAME.
O_NAME = LW_FILE_NAME.
ENDFORM. " FRM_SET_F4_P_INPUT
*&---------------------------------------------------------------------*
*& Form FRM_SET_DETAIL
*&---------------------------------------------------------------------*
* 特性属性的设定
*----------------------------------------------------------------------*
FORM FRM_SET_DETAIL .
DATA:
LTH_CHARACTDESCR TYPE BAPICHARACTDESCR.
* bapi用全局变量的初始化
CLEAR:
ST_DETAIL.
REFRESH:
TD_DATA_BAK,
TD_DESCR,
TD_NUM,
TD_CHAR,
TD_CURR,
TD_SDESCR,
TD_RETURN.
* 特性属性的设定
ST_DETAIL-CHARACT_NAME = TH_DATA-CHARACT_NAME. "特征名称
IF TH_DATA-DATA_TYPE = 'CHAR'.
ST_DETAIL-DATA_TYPE = 'CHAR'. "数据类型
ENDIF.
IF TH_DATA-DATA_TYPE = 'CURR' .
ST_DETAIL-CURRENCY = 'CNY'. "货币码
ST_DETAIL-DATA_TYPE = 'CURR'.
ST_DETAIL-DECIMALS = 2. "小数位
ELSE.
ST_DETAIL-DECIMALS = TH_DATA-DECIMALS. "小数位
ENDIF.
IF TH_DATA-DATA_TYPE = 'NUM'.
ST_DETAIL-UNIT_OF_MEASUREMENT = TH_DATA-EINHE. "单位
ST_DETAIL-DATA_TYPE = 'NUM'.
ENDIF.
ST_DETAIL-LENGTH = TH_DATA-LENGTH. "字符数(数字)
* 值分配的判定
IF TH_DATA-VALUE_S IS NOT INITIAL.
ST_DETAIL-VALUE_ASSIGNMENT = CNS_ATBEW_S. "值分配: 单值
ELSE.
ST_DETAIL-VALUE_ASSIGNMENT = CNS_ATBEW_M. "值分配: 多值
ENDIF.
* st_detail-interval_allowed = th_data-atint. "允许的间隔值
* st_detail-with_sign = th_data-atvor. "区分大小写 允许负值
ST_DETAIL-ENTRY_REQUIRED = TH_DATA-ENTRY_REQUIRED. "所需的输入
* st_detail-charact_group = th_data-charact_group. "特征组
ST_DETAIL-STATUS = CNS_STATUS_1. "特性状态
IF TH_DATA-ATSON IS NOT INITIAL.
ST_DETAIL-ADDITIONAL_VALUES = 'X'.
ELSE.
ST_DETAIL-ADDITIONAL_VALUES = ''.
ENDIF.
* 特性描述的设定
LTH_CHARACTDESCR-LANGUAGE_INT = CNS_SPRAS_ZH.
LTH_CHARACTDESCR-DESCRIPTION = TH_DATA-DESCRIPTION. "特性描述
APPEND LTH_CHARACTDESCR TO TD_DESCR.
IF TH_DATA-DESCRIPTION_E IS NOT INITIAL.
LTH_CHARACTDESCR-LANGUAGE_INT = 'E'.
LTH_CHARACTDESCR-DESCRIPTION = TH_DATA-DESCRIPTION_E. "E特性描述
APPEND LTH_CHARACTDESCR TO TD_DESCR.
ENDIF.
ENDFORM. " FRM_SET_DETAIL
*&---------------------------------------------------------------------*
*& Form FRM_SET_VALUES
*&---------------------------------------------------------------------*
* 特性值的编辑
*----------------------------------------------------------------------*
FORM FRM_SET_VALUES .
DATA:
LTH_NUM TYPE BAPICHARACTVALUESNUM,
LTH_CHAR TYPE BAPICHARACTVALUESCHAR, "许可的 CHAR 值
LTH_CURR TYPE BAPICHARACTVALUESCURR,
LTH_SDESCR TYPE BAPICHARACTVALUESDESCR.
CASE ST_DETAIL-DATA_TYPE.
WHEN 'CHAR'."数据类型:CHAR
*---- 许可的 CHAR 值
LTH_CHAR-VALUE_CHAR = TH_DATA-VALUE_CHAR. "特性值
LTH_CHAR-DEFAULT_VALUE = TH_DATA-DEFAULT_VALUE. "默认值
APPEND LTH_CHAR TO TD_CHAR.
*---- 特性值描述
IF TH_DATA-ATWTB IS NOT INITIAL.
LTH_SDESCR-LANGUAGE_INT = CNS_SPRAS_ZH. "语言代码
LTH_SDESCR-VALUE_CHAR = TH_DATA-VALUE_CHAR. "特性值
LTH_SDESCR-DESCRIPTION = TH_DATA-ATWTB. "特性值文本
APPEND LTH_SDESCR TO TD_SDESCR.
ENDIF.
IF TH_DATA-ATWTB_E IS NOT INITIAL.
LTH_SDESCR-LANGUAGE_INT = 'E'. "语言代码
LTH_SDESCR-VALUE_CHAR = TH_DATA-VALUE_CHAR. "特性值
LTH_SDESCR-DESCRIPTION = TH_DATA-ATWTB_E. "特性值文本
APPEND LTH_SDESCR TO TD_SDESCR.
ENDIF.
WHEN 'CURR'."数据类型:CURR
*---- 许可的 CURR 值
LTH_CURR-VALUE_FROM = TH_DATA-VALUE_CHAR. "内部浮点自:特性值
LTH_CURR-DEFAULT_VALUE = TH_DATA-DEFAULT_VALUE. "默认值
APPEND LTH_CURR TO TD_CURR.
WHEN 'NUM'. "数据类型:DATE NUM TIME
*---- 许可的 DATA/NUM/TIME 值
LTH_NUM-VALUE_FROM = TH_DATA-VALUE_CHAR. "内部浮点自:特性值
LTH_NUM-DEFAULT_VALUE = TH_DATA-DEFAULT_VALUE. "默认值
APPEND LTH_NUM TO TD_NUM.
ENDCASE.
ENDFORM. " FRM_SET_VALUES
*&---------------------------------------------------------------------*
*& Form FRM_CALL_BAPI
*&---------------------------------------------------------------------*
* 特性的登录BAPI执行
*----------------------------------------------------------------------*
FORM FRM_CALL_BAPI .
DATA:
LW_MESSAGE TYPE STRING,
LTH_DATA TYPE TYP_DATA,
LTH_RETURN TYPE BAPIRET2,
LTD_DETAIL TYPE TABLE OF BAPICHARACTDETAIL.
APPEND ST_DETAIL TO LTD_DETAIL.
* 创建/更改的判定
* IF RB_NEW IS NOT INITIAL.
* 特性创建
CALL FUNCTION 'BAPI_CHARACT_CREATE'
EXPORTING
CHARACTDETAIL = ST_DETAIL
TABLES
CHARACTDESCR = TD_DESCR
CHARACTVALUESNUM = TD_NUM
CHARACTVALUESCHAR = TD_CHAR
CHARACTVALUESCURR = TD_CURR
CHARACTVALUESDESCR = TD_SDESCR
RETURN = TD_RETURN.
* ELSE.
** 特性更改
* CALL FUNCTION 'BAPI_CHARACT_CHANGE'
* EXPORTING
* CHARACTNAME = ST_DETAIL-CHARACT_NAME
* TABLES
* CHARACTDETAILNEW = LTD_DETAIL
* CHARACTDESCRNEW = TD_DESCR
* CHARACTVALUESNUMNEW = TD_NUM
* CHARACTVALUESCHARNEW = TD_CHAR
* CHARACTVALUESCURRNEW = TD_CURR
* CHARACTVALUESDESCRNEW = TD_SDESCR
* RETURN = TD_RETURN.
*
* ENDIF.
* 错误信息的编辑
LOOP AT TD_RETURN INTO LTH_RETURN
WHERE TYPE = 'A' OR
TYPE = 'E' OR
TYPE = 'X'.
CONCATENATE LTH_RETURN-MESSAGE LW_MESSAGE
INTO LW_MESSAGE SEPARATED BY SPACE.
ENDLOOP.
IF LW_MESSAGE IS NOT INITIAL.
* ROLLBACK
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
* 错误信息的设定
LTH_DATA-MSG = LW_MESSAGE.
LTH_DATA-CHARACT_NAME = ST_DETAIL-CHARACT_NAME.
LTH_DATA-LIGHT = '1'.
MODIFY GT_ITAB
FROM LTH_DATA
TRANSPORTING MSG LIGHT
WHERE CHARACT_NAME = LTH_DATA-CHARACT_NAME.
W_NUM_ERR = W_NUM_ERR + 1.
ELSE.
* COMMIT
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = CNS_FLG_ON.
LTH_DATA-MSG = '导入成功!'.
LTH_DATA-CHARACT_NAME = ST_DETAIL-CHARACT_NAME.
LTH_DATA-LIGHT = '3'.
MODIFY GT_ITAB
FROM LTH_DATA
TRANSPORTING MSG LIGHT
WHERE CHARACT_NAME = LTH_DATA-CHARACT_NAME.
W_NUM_ERR = W_NUM_ERR + 1.
ENDIF.
ENDFORM. " FRM_CALL_BAPI
*&---------------------------------------------------------------------*
*& Form FRM_BUILD_FDCAT
*&---------------------------------------------------------------------*
* 根据业务类型确定AVL字段内容
*----------------------------------------------------------------------*
FORM FRM_BUILD_FDCAT
USING ALV_OUTTYPE TYPE C. "业务类型
REFRESH: LT_FIELDCAT.
"字段名 字段描述 数值0不显示 列宽 参考表 参考宽段 小数位 F4 BOX
CASE ALV_OUTTYPE.
WHEN 'A'. "分类特性导入
PERFORM FRM_ALV_FIELDCAT USING:
'BOX' '选择' '' '2' '' '' '' '' 'X',
'MSG' '消息' '' '20' '' '' '' '' '',
'CHARACT_NAME' '特征' '' '20' '' '' '' '' '',
'DESCRIPTION' '特性描述' '' '20' '' '' '' '' '',
'VALUE_S' '单一值' '' '2' '' '' '' '' '',
'VALUE_M' '多值' '' '2' '' '' '' '' '',
'DATA_TYPE' '数据类型' '' '5' '' '' '' '' '',
'LENGTH' '字符数' '' '3' '' '' '' '' '',
'DECIMALS' '小数位' '' '3' '' '' '' '' '',
'EINHE' '单位' '' '3' '' '' '' '' '',
'ENTRY_REQUIRED' '必需输入' '' '2' '' '' '' '' '',
'ATSON' '附加值' '' '2' '' '' '' '' '',
'VALUE_CHAR' '特性值' '' '20' '' '' '' '' '',
'ATWTB' '特性值描述' '' '20' '' '' '' '' ''.
WHEN OTHERS.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_ALV_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM FRM_ALV_FIELDCAT
USING PR_FNAME
PR_SCRTEXT_M
PR_NO_ZERO
PR_OUTLEN
PR_REF_TABLE
PR_REF_FIELD
PR_DECIMALS
PR_F4AVAILABL
PR_CHECKBOX.
CLEAR:LS_FIELDCAT.
GV_POS = GV_POS + 1.
LS_FIELDCAT-COL_POS = GV_POS.
LS_FIELDCAT-FIELDNAME = PR_FNAME. "字段名
LS_FIELDCAT-SCRTEXT_M = PR_SCRTEXT_M. "字段中描述
LS_FIELDCAT-NO_ZERO = PR_NO_ZERO. "数值为0 不显示
LS_FIELDCAT-OUTPUTLEN = PR_OUTLEN. "列的字符宽度
LS_FIELDCAT-REF_TABLE = PR_REF_TABLE. "参考表
LS_FIELDCAT-REF_FIELD = PR_REF_FIELD. "参考字段
LS_FIELDCAT-DECIMALS = PR_DECIMALS. "小数位
LS_FIELDCAT-F4AVAILABL = PR_F4AVAILABL. "F4帮助
LS_FIELDCAT-CHECKBOX = PR_CHECKBOX. "CHECKBOX
APPEND LS_FIELDCAT TO LT_FIELDCAT.
ENDFORM. " FRM_ALV_FIELDCAT
*&---------------------------------------------------------------------*
*& Form SUB_SHOW_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SUB_SHOW_ALV .
PERFORM FRM_BUILD_FDCAT USING: 'A'.
************************************************************
*为ALV结构赋值
"LS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'. "优化宽度
LS_LAYOUT-ZEBRA = 'X'. "斑马线输出
LS_LAYOUT-SEL_MODE = 'A'. "单元格的选择,可以多选单元格 多行,多列,任何单元格多选 用户可以使用最左边的选择按钮来选择多行
LS_LAYOUT-STYLEFNAME = 'STYLE'.
LS_LAYOUT-EXCP_FNAME = GV_LIGHT.
LS_LAYOUT-EXCP_LED = 'X'.
LS_LAYOUT-EDIT_MODE = 'X'.
LS_LAYOUT-EDIT = 'X'.
************************************************************
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT_LVC = LS_LAYOUT
IT_FIELDCAT_LVC = LT_FIELDCAT
I_CALLBACK_USER_COMMAND = 'MYCOMMAND' "alv 交互(双击、回车)事件
I_CALLBACK_PF_STATUS_SET = 'MYSTATUS' "alv 上加自定义按纽
I_CALLBACK_HTML_TOP_OF_PAGE = 'ALV_TOP_OF_PAGE' "自定义ALV表头
TABLES
T_OUTTAB = GT_ITAB
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " SUB_SHOW_ALV
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form MYSTATUS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM MYSTATUS USING
RT_EXTAB TYPE SLIS_T_EXTAB."定义GUI状态必须写
SET PF-STATUS 'MYSTATUS1'.
ENDFORM. "MYSTATUS
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form ALV_TOP_OF_PAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->CL_DD text
* -->p2 text
*----------------------------------------------------------------------*
FORM ALV_TOP_OF_PAGE USING CL_DD TYPE REF TO CL_DD_DOCUMENT.
DATA: M_P TYPE I.
DATA: M_BUFF TYPE STRING.
*表头其实完全可以是一个html文件,自己使用html语言进行格式控制
M_BUFF = '<html>'.
CALL METHOD CL_DD->HTML_INSERT
EXPORTING
CONTENTS = M_BUFF
CHANGING
POSITION = M_P.
M_BUFF = '<center><H4>分类特性导入检查</H4></center>'.
CALL METHOD CL_DD->HTML_INSERT
EXPORTING
CONTENTS = M_BUFF
CHANGING
POSITION = M_P.
CONCATENATE '<table width="1200"><tr><td>操作日期:' SY-DATUM ' </td><td><div align="right">操作用户:'
SY-UNAME'</div></td></tr></table>' INTO M_BUFF.
CALL METHOD CL_DD->HTML_INSERT
EXPORTING
CONTENTS = M_BUFF
CHANGING
POSITION = M_P.
ENDFORM. "ALV_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form MYCOMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM MYCOMMAND
USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
DATA: L_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA: W_STBL TYPE LVC_S_STBL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = L_GRID.
CALL METHOD L_GRID->CHECK_CHANGED_DATA.
CASE R_UCOMM.
WHEN 'CREATE'.
PERFORM FRM_CREATE_CHARACT.
WHEN 'UPDATE'.
PERFORM FRM_CREATE_CHARACT.
WHEN 'REFRESH'.
LOOP AT GT_ITAB INTO GS_ITAB WHERE BOX = 'X'.
GS_ITAB-BOX = ''.
GS_ITAB-MSG = ''.
GS_ITAB-LIGHT = ''.
MODIFY GT_ITAB FROM GS_ITAB.
ENDLOOP.
REFRESH: GT_ITAB.
CLEAR: GT_ITAB.
PERFORM FRM_UPDATE_DATA.
WHEN '&IC1'.
WHEN 'ALL'.
LOOP AT GT_ITAB INTO GS_ITAB.
GS_ITAB-BOX = 'X'.
MODIFY GT_ITAB FROM GS_ITAB.
ENDLOOP.
WHEN 'SAL'.
LOOP AT GT_ITAB INTO GS_ITAB.
GS_ITAB-BOX = ''.
MODIFY GT_ITAB FROM GS_ITAB.
ENDLOOP.
ENDCASE.
"稳定刷新
W_STBL-ROW = 'X'." 基于行的稳定刷新
W_STBL-COL = 'X'." 基于列稳定刷新
CALL METHOD L_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = W_STBL.
ENDFORM. "MYCOMMAND
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form EXCELTEMP_DOWNLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM EXCELTEMP_DOWN .
DATA: LS_WWWDATATAB LIKE WWWDATATAB,
LV_SUBRC LIKE SY-SUBRC.
CLEAR LS_WWWDATATAB.
GV_OBJID = CNS_TEMPNAME.
SELECT SINGLE * FROM WWWDATA INTO CORRESPONDING FIELDS OF LS_WWWDATATAB
WHERE RELID = 'MI' AND OBJID = GV_OBJID AND SRTF2 = 0.
IF SY-SUBRC <> 0.
MESSAGE '模板文件不存在,请通过SMW0上传模板文件' TYPE 'E' RAISING OTHERS.
ELSE.
CONCATENATE CNS_PATH CNS_TEMPNAME '.xls' INTO GV_FILENAME.
GV_FILENAME = P_FILE.
CLEAR: LV_SUBRC,GV_STRING.
GV_STRING = GV_FILENAME.
* CALL METHOD cl_gui_frontend_services=>file_delete
* EXPORTING
* filename = g_string
* CHANGING
* rc = lv_subrc.
"调用DOWNLOAD_WEB_OBJECT 函数下载模板到路径下
CLEAR LV_SUBRC.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
KEY = LS_WWWDATATAB
DESTINATION = GV_FILENAME
IMPORTING
RC = LV_SUBRC.
IF LV_SUBRC NE 0.
MESSAGE '模板文件下载失败,请联系系统管理员' TYPE 'E' RAISING OTHERS.
ENDIF.
ENDIF.
ENDFORM. " EXCELTEMP_DOWNLOAD
SAP-MM-分类特性批量导入
最新推荐文章于 2024-08-16 22:09:40 发布