*&---------------------------------------------------------------------*
*& 包括 ZXCO1U01
*&---------------------------------------------------------------------*
***生产订单关键参数修改日志记录
IF HEADER_TABLE-AUTYP = '' AND HEADER_TABLE-VBKZ <> 'I' AND SY-TCODE <> 'COHV'. "10-PP生产订单
*--------------------------------------------------------------------*
* 数据定义
*--------------------------------------------------------------------*
TABLES:ZPPCO02_LOG. DATA:IT_CO02LOG TYPE STANDARD TABLE OF ZPPCO02_LOG,
IT_CO02LOGN TYPE STANDARD TABLE OF ZPPCO02_LOG,
IW_CO02LOG TYPE ZPPCO02_LOG,
IW_CO02LOGN TYPE ZPPCO02_LOG. DATA:IPX TYPE MSXXLIST-HOSTADR,
IP TYPE ZPPCO02_LOG-CHIPA,
HOST TYPE ZPPCO02_LOG-CHHST. DATA:VI_OPNUM TYPE ZPPCO02_LOG-CHNUM,
VS_STR TYPE STRING. DATA:V_ARBPL_OLD LIKE CRHD-ARBPL,
V_ARBPL_NEW LIKE CRHD-ARBPL. DATA:L_DATUM TYPE SY-DATUM,
L_RATE TYPE P DECIMALS ,
L_RATE1 TYPE P DECIMALS . *--------------------------------------------------------------------*
* 宏定义
*--------------------------------------------------------------------* DEFINE DEL_ZERO_R.
SHIFT & RIGHT DELETING TRAILING ''.
SHIFT & RIGHT DELETING TRAILING '.'.
CONDENSE & NO-GAPS.
END-OF-DEFINITION. DEFINE ULOG_LINE.
* &1:表名
* &2:表名差异部分
* &3:字段名
* &4:变更对象类型
* &5:变更对象的描述
IF &-& <> &1_&-&.
CLEAR IW_CO02LOG.
VI_OPNUM = VI_OPNUM + . "记录本次操作的流水编码(自增1)
IW_CO02LOG-CHNUM = VI_OPNUM. "记录本次操作的流水编码 IW_CO02LOG-CHTYP = 'U'. "操作类型:U-更新
IW_CO02LOG-OBJTP = '&4'. "操作对象类型(抬头、组件、工艺等)
IW_CO02LOG-OBJNM = '&5'. "操作对象描述
IW_CO02LOG-VLOLD = &1_&-&. "操作对象的旧值
IW_CO02LOG-VLNEW = &-&. "操作对象的新值 APPEND IW_CO02LOG TO IT_CO02LOG. "追加记录
ENDIF.
END-OF-DEFINITION. DEFINE ULOG_ITAB.
* ---------------------------------------------------
* &1:记录新值的内表名称
* &2:记录旧值的内表名称与新表的差异部分(通常为OLD)
* &3:比较的字段名称
* &4:操作对象类型
* &5:操作对象描述
* &6:操作对象唯一行标记描述
* &7:操作对象唯一行标记字段名
* &8:操作对象辅助行标记描述
* &9:操作对象辅助行标记字段名
* ---------------------------------------------------
IF &-& <> &1_&-&.
CLEAR IW_CO02LOG.
VI_OPNUM = VI_OPNUM + . "记录本次操作的流水编码(自增1)
IW_CO02LOG-CHNUM = VI_OPNUM. "记录本次操作的流水编码
IW_CO02LOG-CHTYP = 'U'. "操作类型:U-更新 IW_CO02LOG-OBJTP = '&4'. "操作对象类型(抬头、组件、工艺等)
IW_CO02LOG-OBJNM = '&5'. "操作对象描述 * -------------------------------------------
* 操作对象唯一行标记,例如:预留项目号(1)
* 唯一行标记一般前台不可见,但唯一且不可更改
* -------------------------------------------
IW_CO02LOG-OBJLU = &-&. "操作对象唯一行标记的值(例如:0001) SHIFT IW_CO02LOG-OBJLU LEFT DELETING LEADING ''. "去除前置0 CONCATENATE '&6' '(' IW_CO02LOG-OBJLU ')' INTO IW_CO02LOG-OBJLU. "拼写描述 * -------------------------------------------
* 操作对象辅助行标记,例如:BOM项目号(0010)
* 辅助行标记一般不唯一或可修改,但最常用
* -------------------------------------------
IW_CO02LOG-OBJLA = &-&. "操作对象辅助行标记的值(例如:0010)
CONCATENATE '&8' '(' IW_CO02LOG-OBJLA ')' INTO IW_CO02LOG-OBJLA. "拼写描述 IW_CO02LOG-VLOLD = &1_&-&. "操作对象的旧值
IW_CO02LOG-VLNEW = &-&. "操作对象的新值 APPEND IW_CO02LOG TO IT_CO02LOG. "追加记录
ENDIF. END-OF-DEFINITION. *--------------------------------------------------------------------*
*订单抬头修改
*--------------------------------------------------------------------*
IF HEADER_TABLE-VBKZ = 'U'.
ULOG_LINE: HEADER_TABLE OLD GAMNG 订单抬头 订单总数量 ,
HEADER_TABLE OLD GASMG 订单抬头 订单废品数量 ,
HEADER_TABLE OLD GLTRP 订单抬头 基本完成日期 ,
HEADER_TABLE OLD GSTRP 订单抬头 基本开始日期 ,
HEADER_TABLE OLD FHORI 订单抬头 计划边际码 ,
HEADER_TABLE OLD DISPO 订单抬头 MRP控制者 ,
HEADER_TABLE OLD FEVOR 订单抬头 生产调度员 .
ENDIF. *--------------------------------------------------------------------*
* 订单收货库存地点更改
*--------------------------------------------------------------------*
IF POSITION_TABLE-VBKZ = 'U'. ULOG_LINE: POSITION_TABLE OLD LGORT 订单项目 收货库存地点. ENDIF. *--------------------------------------------------------------------*
* 订单组件更改
*--------------------------------------------------------------------*
LOOP AT COMPONENT_TABLE WHERE NOT VBKZ IS INITIAL. CASE COMPONENT_TABLE-VBKZ.
* ---------------------------
* 记录组件的新增日志
* ---------------------------
WHEN 'I'.
CLEAR:IW_CO02LOG.
VI_OPNUM = VI_OPNUM + . "记录本次操作的流水编码(自增1)
IW_CO02LOG-CHNUM = VI_OPNUM. "记录本次操作的流水编码 IW_CO02LOG-CHTYP = 'I'. "操作类型:I-新增
IW_CO02LOG-OBJTP = '订单组件'. "操作对象类型(抬头、组件、工艺等)
IW_CO02LOG-OBJNM = '订单组件(新增)'. "操作对象描述 * -------------------------------------------
* 操作对象唯一行标记,例如:预留项目号(1)
* 唯一行标记一般前台不可见,但唯一且不可更改
* -------------------------------------------
IW_CO02LOG-OBJLU = COMPONENT_TABLE-RSPOS. "预留项目号(例如:0001) SHIFT IW_CO02LOG-OBJLU LEFT DELETING LEADING ''. "去除前置0 CONCATENATE '预留项目号(' IW_CO02LOG-OBJLU ')' INTO IW_CO02LOG-OBJLU. "拼写描述 * -------------------------------------------
* 操作对象辅助行标记,例如:BOM项目号(0010)
* 辅助行标记一般不唯一或可修改,但最常用
* -------------------------------------------
IW_CO02LOG-OBJLA = COMPONENT_TABLE-POSNR. "BOM项目号(例如:0010)
CONCATENATE 'BOM项目号(' IW_CO02LOG-OBJLA ')' INTO IW_CO02LOG-OBJLA. "拼写描述 * ------------------------------------------
* 将新增组件的所有信息组合为一行存入NEW字段
* ------------------------------------------
VS_STR = COMPONENT_TABLE-ERFMG. DEL_ZERO_R VS_STR. SHIFT COMPONENT_TABLE-MATNR LEFT DELETING LEADING ''.
CONCATENATE '物料号:' COMPONENT_TABLE-MATNR
',需求数量:' VS_STR '(' COMPONENT_TABLE-ERFME ')'
',工厂:' COMPONENT_TABLE-WERKS INTO IW_CO02LOG-VLNEW. IF NOT COMPONENT_TABLE-LGORT IS INITIAL.
CONCATENATE IW_CO02LOG-VLNEW ',库存地点:' COMPONENT_TABLE-LGORT INTO IW_CO02LOG-VLNEW.
ENDIF. IF NOT COMPONENT_TABLE-RGEKZ IS INITIAL.
CONCATENATE IW_CO02LOG-VLNEW ',反冲:' COMPONENT_TABLE-RGEKZ INTO IW_CO02LOG-VLNEW.
ENDIF. APPEND IW_CO02LOG TO IT_CO02LOG. "追加记录
* ---------------------------
* 记录组件的修改日志
* ---------------------------
WHEN 'U'.
* --------------------------------
* 根据预留及项目查询更改前的信息
* --------------------------------
READ TABLE COMPONENT_TABLE_OLD
WITH KEY RSNUM = COMPONENT_TABLE-RSNUM
RSPOS = COMPONENT_TABLE-RSPOS. CHECK SY-SUBRC = . SHIFT COMPONENT_TABLE_OLD-MATNR LEFT DELETING LEADING ''.
SHIFT COMPONENT_TABLE-MATNR LEFT DELETING LEADING ''.
SHIFT COMPONENT_TABLE_OLD-LIFNR LEFT DELETING LEADING ''.
SHIFT COMPONENT_TABLE-LIFNR LEFT DELETING LEADING ''. ULOG_ITAB: COMPONENT_TABLE OLD POSNR 订单组件 BOM项目号 预留项目号 RSPOS BOM项目号 POSNR,
COMPONENT_TABLE OLD MATNR 订单组件 物料号 预留项目号 RSPOS BOM项目号 POSNR,
COMPONENT_TABLE OLD ERFMG 订单组件 需求数量 预留项目号 RSPOS BOM项目号 POSNR,
COMPONENT_TABLE OLD ERFME 订单组件 计量单位 预留项目号 RSPOS BOM项目号 POSNR,
COMPONENT_TABLE OLD WERKS 订单组件 工厂 预留项目号 RSPOS BOM项目号 POSNR,
COMPONENT_TABLE OLD LGORT 订单组件 库存地点 预留项目号 RSPOS BOM项目号 POSNR,
COMPONENT_TABLE OLD RGEKZ 订单组件 反冲标识 预留项目号 RSPOS BOM项目号 POSNR,
COMPONENT_TABLE OLD SOBKZ 订单组件 特殊库存 预留项目号 RSPOS BOM项目号 POSNR,
COMPONENT_TABLE OLD LIFNR 订单组件 供应商(特殊库存) 预留项目号 RSPOS BOM项目号 POSNR,
COMPONENT_TABLE OLD XLOEK 订单组件 已删除标识 预留项目号 RSPOS BOM项目号 POSNR.
WHEN 'D'.
CLEAR:IW_CO02LOG.
VI_OPNUM = VI_OPNUM + . "记录本次操作的流水编码(自增1)
IW_CO02LOG-CHNUM = VI_OPNUM. "记录本次操作的流水编码 IW_CO02LOG-CHTYP = 'D'. "操作类型:I-新增
IW_CO02LOG-OBJTP = '订单组件'. "操作对象类型(抬头、组件、工艺等)
IW_CO02LOG-OBJNM = '订单组件(删除)'. "操作对象描述 * -------------------------------------------
* 操作对象唯一行标记,例如:预留项目号(1)
* 唯一行标记一般前台不可见,但唯一且不可更改
* -------------------------------------------
IW_CO02LOG-OBJLU = COMPONENT_TABLE-RSPOS. "预留项目号(例如:0001) SHIFT IW_CO02LOG-OBJLU LEFT DELETING LEADING ''. "去除前置0 CONCATENATE '预留项目号(' IW_CO02LOG-OBJLU ')' INTO IW_CO02LOG-OBJLU. "拼写描述 * -------------------------------------------
* 操作对象辅助行标记,例如:BOM项目号(0010)
* 辅助行标记一般不唯一或可修改,但最常用
* -------------------------------------------
IW_CO02LOG-OBJLA = COMPONENT_TABLE-POSNR. "BOM项目号(例如:0010)
CONCATENATE 'BOM项目号(' IW_CO02LOG-OBJLA ')' INTO IW_CO02LOG-OBJLA. "拼写描述
* ------------------------------------------
* 将新增组件的所有信息组合为一行存入NEW字段
* ------------------------------------------
VS_STR = COMPONENT_TABLE-ERFMG. DEL_ZERO_R VS_STR. SHIFT COMPONENT_TABLE-MATNR LEFT DELETING LEADING ''.
CONCATENATE '物料号:' COMPONENT_TABLE-MATNR
',需求数量:' VS_STR '(' COMPONENT_TABLE-ERFME ')'
',工厂:' COMPONENT_TABLE-WERKS INTO IW_CO02LOG-VLNEW. IF NOT COMPONENT_TABLE-LGORT IS INITIAL.
CONCATENATE IW_CO02LOG-VLNEW ',库存地点:' COMPONENT_TABLE-LGORT INTO IW_CO02LOG-VLNEW.
ENDIF. IF NOT COMPONENT_TABLE-RGEKZ IS INITIAL.
CONCATENATE IW_CO02LOG-VLNEW ',反冲:' COMPONENT_TABLE-RGEKZ INTO IW_CO02LOG-VLNEW.
ENDIF. APPEND IW_CO02LOG TO IT_CO02LOG. "追加记录
ENDCASE. ENDLOOP. *--------------------------------------------------------------------*
* 订单工序更改
*--------------------------------------------------------------------*
LOOP AT OPERATION_TABLE WHERE NOT VBKZ IS INITIAL. CASE OPERATION_TABLE-VBKZ.
* ---------------------------
* 记录工序的新增日志
* ---------------------------
WHEN 'I'. VI_OPNUM = VI_OPNUM + . "记录本次操作的流水编码(自增1)
IW_CO02LOG-CHNUM = VI_OPNUM. "记录本次操作的流水编码 IW_CO02LOG-CHTYP = 'I'. "操作类型:I-新增
IW_CO02LOG-OBJTP = '订单工序'. "操作对象类型(抬头、组件、工艺等)
IW_CO02LOG-OBJNM = '订单工序(新增)'. "操作对象描述 * -------------------------------------------
* 操作对象唯一行标记,例如:预留项目号(1)
* 唯一行标记一般前台不可见,但唯一且不可更改
* -------------------------------------------
IW_CO02LOG-OBJLU = OPERATION_TABLE-APLZL. "工序计数器(例如:00000001) SHIFT IW_CO02LOG-OBJLU LEFT DELETING LEADING ''. "去除前置0 CONCATENATE '工序计数器(' IW_CO02LOG-OBJLU ')' INTO IW_CO02LOG-OBJLU. "拼写描述 * -------------------------------------------
* 操作对象辅助行标记,例如:BOM项目号(0010)
* 辅助行标记一般不唯一或可修改,但最常用
* -------------------------------------------
IW_CO02LOG-OBJLA = OPERATION_TABLE-VORNR. "工序号(例如:0010)
CONCATENATE '工序号(' IW_CO02LOG-OBJLA ')' INTO IW_CO02LOG-OBJLA. "拼写描述 * -------------------------------------------------------------------
* 将新增工序的所有信息组合为一行存入NEW字段
* 由于ALV的列宽最大为128字符,所以将工时部分组合为一行存入NEW2字段
* -------------------------------------------------------------------
CLEAR V_ARBPL_NEW.
SELECT SINGLE ARBPL
FROM CRHD
INTO V_ARBPL_NEW
WHERE OBJTY = 'A' AND
OBJID = OPERATION_TABLE-ARBID.
IF SY-SUBRC = .
CONCATENATE '工作中心:' V_ARBPL_NEW ',' INTO IW_CO02LOG-VLNEW.
ENDIF. CONCATENATE IW_CO02LOG-VLNEW
'工厂:' OPERATION_TABLE-WERKS
',控制码:' OPERATION_TABLE-STEUS INTO IW_CO02LOG-VLNEW. IF NOT OPERATION_TABLE-KTSCH IS INITIAL.
CONCATENATE IW_CO02LOG-VLNEW ',标准文本码:' OPERATION_TABLE-KTSCH INTO IW_CO02LOG-VLNEW.
ENDIF. CONCATENATE IW_CO02LOG-VLNEW ',工序短文本:' OPERATION_TABLE-LTXA1 INTO IW_CO02LOG-VLNEW. * ------------------------
* 工时部分存入NEW2字段
* ------------------------
IF NOT OPERATION_TABLE-VGW01 IS INITIAL.
VS_STR = OPERATION_TABLE-VGW01.
DEL_ZERO_R VS_STR.
CONCATENATE IW_CO02LOG-VLNE2 ',准备工时:' VS_STR '(' OPERATION_TABLE-VGE01 ')' INTO IW_CO02LOG-VLNE2.
ENDIF. IF NOT OPERATION_TABLE-VGW02 IS INITIAL.
VS_STR = OPERATION_TABLE-VGW02.
DEL_ZERO_R VS_STR.
CONCATENATE IW_CO02LOG-VLNE2 ',机器工时:' VS_STR '(' OPERATION_TABLE-VGE02 ')' INTO IW_CO02LOG-VLNE2.
ENDIF. IF NOT OPERATION_TABLE-VGW03 IS INITIAL.
VS_STR = OPERATION_TABLE-VGW03.
DEL_ZERO_R VS_STR.
CONCATENATE IW_CO02LOG-VLNE2 ',人工工时:' VS_STR '(' OPERATION_TABLE-VGE03 ')' INTO IW_CO02LOG-VLNE2.
ENDIF. IF NOT OPERATION_TABLE-PREIS IS INITIAL.
VS_STR = OPERATION_TABLE-PREIS.
CONCATENATE IW_CO02LOG-VLNE2 ',外协价格:' VS_STR '(' OPERATION_TABLE-WAERS ')/' INTO IW_CO02LOG-VLNE2.
VS_STR = OPERATION_TABLE-PEINH.
CONCATENATE IW_CO02LOG-VLNE2 VS_STR '(' OPERATION_TABLE-MEINH ')' INTO IW_CO02LOG-VLNE2.
ENDIF. SHIFT IW_CO02LOG-VLNE2 LEFT DELETING LEADING ','.
CONDENSE IW_CO02LOG-VLNE2 NO-GAPS. APPEND IW_CO02LOG TO IT_CO02LOG. "追加记录
CLEAR IW_CO02LOG. * ---------------------------
* 记录工序的修改日志
* ---------------------------
WHEN 'U'.
* ----------------------------------------------
* 根据工艺路线号及计数器查询更改前的信息(AFVC)
* ----------------------------------------------
READ TABLE OPERATION_TABLE_OLD_AFVC
WITH KEY AUFPL = OPERATION_TABLE-AUFPL
APLZL = OPERATION_TABLE-APLZL. IF SY-SUBRC = .
* -------------------------------------
* 可直接记录更改的参数(工序基本信息)
* -------------------------------------
ULOG_ITAB: OPERATION_TABLE OLD_AFVC VORNR 订单工序 工序号 工序计数器 APLZL 工序号 VORNR,
OPERATION_TABLE OLD_AFVC WERKS 订单工序 工厂 工序计数器 APLZL 工序号 VORNR,
OPERATION_TABLE OLD_AFVC STEUS 订单工序 控制码 工序计数器 APLZL 工序号 VORNR,
OPERATION_TABLE OLD_AFVC KTSCH 订单工序 标准文本码 工序计数器 APLZL 工序号 VORNR,
OPERATION_TABLE OLD_AFVC LTXA1 订单工序 工序短文本 工序计数器 APLZL 工序号 VORNR.
* -------------------------------------
* 可直接记录更改的参数(外协价格信息)
* -------------------------------------
ULOG_ITAB: OPERATION_TABLE OLD_AFVC PREIS 订单工序 外协价格 工序计数器 APLZL 工序号 VORNR,
OPERATION_TABLE OLD_AFVC WAERS 订单工序 外协价格货币 工序计数器 APLZL 工序号 VORNR,
OPERATION_TABLE OLD_AFVC PEINH 订单工序 外协价格单位(每) 工序计数器 APLZL 工序号 VORNR. * ---------------------------------------------
* 比较工作中心是否修改,因未直接记录工作中心,
* 只能根据AFVC-ARBID查找工作中心并比较
* ---------------------------------------------
IF OPERATION_TABLE-ARBID <> OPERATION_TABLE_OLD_AFVC-ARBID.
* ----------------------------------------
* 根据AFVC-ARBID查询工作中心的原值与新值
* ----------------------------------------
CLEAR: V_ARBPL_OLD,V_ARBPL_NEW. SELECT SINGLE ARBPL
FROM CRHD
INTO V_ARBPL_OLD
WHERE OBJTY = 'A' AND
OBJID = OPERATION_TABLE_OLD_AFVC-ARBID. SELECT SINGLE ARBPL
FROM CRHD
INTO V_ARBPL_NEW
WHERE OBJTY = 'A' AND
OBJID = OPERATION_TABLE-ARBID.
* ----------------------------------------
* 如果工作中心的原值与新值不同则记录
* ----------------------------------------
IF V_ARBPL_OLD <> V_ARBPL_NEW.
VI_OPNUM = VI_OPNUM + . "记录本次操作的流水编码(自增1)
IW_CO02LOG-CHNUM = VI_OPNUM. "记录本次操作的流水编码 IW_CO02LOG-CHTYP = 'U'. "操作类型:U-更新
IW_CO02LOG-OBJTP = '订单工序'. "操作对象类型(抬头、组件、工艺等)
IW_CO02LOG-OBJNM = '工作中心'. "操作对象描述 * -------------------------------------------
* 操作对象唯一行标记,例如:预留项目号(1)
* 唯一行标记一般前台不可见,但唯一且不可更改
* -------------------------------------------
IW_CO02LOG-OBJLU = OPERATION_TABLE-APLZL. "工序计数器(例如:00000001) SHIFT IW_CO02LOG-OBJLU LEFT DELETING LEADING ''. "去除前置0 CONCATENATE '工序计数器(' IW_CO02LOG-OBJLU ')' INTO IW_CO02LOG-OBJLU. "拼写描述 * -------------------------------------------
* 操作对象辅助行标记,例如:BOM项目号(0010)
* 辅助行标记一般不唯一或可修改,但最常用
* -------------------------------------------
IW_CO02LOG-OBJLA = OPERATION_TABLE-VORNR. "工序号(例如:0010)
CONCATENATE '工序号(' IW_CO02LOG-OBJLA ')' INTO IW_CO02LOG-OBJLA. "拼写描述 IW_CO02LOG-VLOLD = V_ARBPL_OLD. "操作对象的旧值
IW_CO02LOG-VLNEW = V_ARBPL_NEW. "操作对象的新值 APPEND IW_CO02LOG TO IT_CO02LOG. "追加记录
CLEAR IW_CO02LOG.
ENDIF. ENDIF. ENDIF. * ----------------------------------------------
* 根据工艺路线号及计数器查询更改前的信息(AFVV)
* ----------------------------------------------
READ TABLE OPERATION_TABLE_OLD_AFVV
WITH KEY AUFPL = OPERATION_TABLE-AUFPL
APLZL = OPERATION_TABLE-APLZL. IF SY-SUBRC = .
* ---------------------------------------------
* 可直接记录更改的参数(工时信息)
* ---------------------------------------------
ULOG_ITAB: OPERATION_TABLE OLD_AFVV VGW01 订单工序 准备工时(数值) 工序计数器 APLZL 工序号 VORNR,
OPERATION_TABLE OLD_AFVV VGE01 订单工序 准备工时(单位) 工序计数器 APLZL 工序号 VORNR,
OPERATION_TABLE OLD_AFVV VGW02 订单工序 机器工时(数值) 工序计数器 APLZL 工序号 VORNR,
OPERATION_TABLE OLD_AFVV VGE02 订单工序 机器工时(单位) 工序计数器 APLZL 工序号 VORNR,
OPERATION_TABLE OLD_AFVV VGW03 订单工序 人工工时(数值) 工序计数器 APLZL 工序号 VORNR,
OPERATION_TABLE OLD_AFVV VGE03 订单工序 人工工时(单位) 工序计数器 APLZL 工序号 VORNR,
OPERATION_TABLE OLD_AFVV MEINH 订单工序 作业的计量单位 工序计数器 APLZL 工序号 VORNR. ENDIF.
WHEN 'D'.
VI_OPNUM = VI_OPNUM + . "记录本次操作的流水编码(自增1)
IW_CO02LOG-CHNUM = VI_OPNUM. "记录本次操作的流水编码 IW_CO02LOG-CHTYP = 'D'. "操作类型:I-新增
IW_CO02LOG-OBJTP = '订单工序'. "操作对象类型(抬头、组件、工艺等)
IW_CO02LOG-OBJNM = '订单工序(删除)'. "操作对象描述 * -------------------------------------------
* 操作对象唯一行标记,例如:预留项目号(1)
* 唯一行标记一般前台不可见,但唯一且不可更改
* -------------------------------------------
IW_CO02LOG-OBJLU = OPERATION_TABLE-APLZL. "工序计数器(例如:00000001) SHIFT IW_CO02LOG-OBJLU LEFT DELETING LEADING ''. "去除前置0 CONCATENATE '工序计数器(' IW_CO02LOG-OBJLU ')' INTO IW_CO02LOG-OBJLU. "拼写描述 * -------------------------------------------
* 操作对象辅助行标记,例如:BOM项目号(0010)
* 辅助行标记一般不唯一或可修改,但最常用
* -------------------------------------------
IW_CO02LOG-OBJLA = OPERATION_TABLE-VORNR. "工序号(例如:0010)
CONCATENATE '工序号(' IW_CO02LOG-OBJLA ')' INTO IW_CO02LOG-OBJLA. "拼写描述 * -------------------------------------------------------------------
* 将新增工序的所有信息组合为一行存入NEW字段
* 由于ALV的列宽最大为128字符,所以将工时部分组合为一行存入NEW2字段
* -------------------------------------------------------------------
CLEAR: V_ARBPL_NEW,
IW_CO02LOG-VLNEW. SELECT SINGLE ARBPL
FROM CRHD
INTO V_ARBPL_NEW
WHERE OBJTY = 'A' AND
OBJID = OPERATION_TABLE-ARBID.
IF SY-SUBRC = .
CONCATENATE '工作中心:' V_ARBPL_NEW ',' INTO IW_CO02LOG-VLNEW.
ENDIF. CONCATENATE IW_CO02LOG-VLNEW
'工厂:' OPERATION_TABLE-WERKS
',控制码:' OPERATION_TABLE-STEUS INTO IW_CO02LOG-VLNEW. IF NOT OPERATION_TABLE-KTSCH IS INITIAL.
CONCATENATE IW_CO02LOG-VLNEW ',标准文本码:' OPERATION_TABLE-KTSCH INTO IW_CO02LOG-VLNEW.
ENDIF. CONCATENATE IW_CO02LOG-VLNEW ',工序短文本:' OPERATION_TABLE-LTXA1 INTO IW_CO02LOG-VLNEW. * ------------------------
* 工时部分存入NEW2字段
* ------------------------
IF NOT OPERATION_TABLE-VGW01 IS INITIAL.
VS_STR = OPERATION_TABLE-VGW01.
DEL_ZERO_R VS_STR.
CONCATENATE IW_CO02LOG-VLNE2 ',准备工时:' VS_STR '(' OPERATION_TABLE-VGE01 ')' INTO IW_CO02LOG-VLNE2.
ENDIF. IF NOT OPERATION_TABLE-VGW02 IS INITIAL.
VS_STR = OPERATION_TABLE-VGW02.
DEL_ZERO_R VS_STR.
CONCATENATE IW_CO02LOG-VLNE2 ',机器工时:' VS_STR '(' OPERATION_TABLE-VGE02 ')' INTO IW_CO02LOG-VLNE2.
ENDIF. IF NOT OPERATION_TABLE-VGW03 IS INITIAL.
VS_STR = OPERATION_TABLE-VGW03.
DEL_ZERO_R VS_STR.
CONCATENATE IW_CO02LOG-VLNE2 ',人工工时:' VS_STR '(' OPERATION_TABLE-VGE03 ')' INTO IW_CO02LOG-VLNE2.
ENDIF. IF NOT OPERATION_TABLE-PREIS IS INITIAL.
VS_STR = OPERATION_TABLE-PREIS.
CONCATENATE IW_CO02LOG-VLNE2 ',外协价格:' VS_STR '(' OPERATION_TABLE-WAERS ')/' INTO IW_CO02LOG-VLNE2.
VS_STR = OPERATION_TABLE-PEINH.
CONCATENATE IW_CO02LOG-VLNE2 VS_STR '(' OPERATION_TABLE-MEINH ')' INTO IW_CO02LOG-VLNE2.
ENDIF. SHIFT IW_CO02LOG-VLNE2 LEFT DELETING LEADING ','.
CONDENSE IW_CO02LOG-VLNE2 NO-GAPS. APPEND IW_CO02LOG TO IT_CO02LOG. "追加记录
CLEAR IW_CO02LOG. ENDCASE. ENDLOOP. *--------------------------------------------------------------------*
* 更新到数据库表
*--------------------------------------------------------------------*
IF NOT IT_CO02LOG[] IS INITIAL. * -----------------------------------
* 获取客户端IP地址(16进制)、主机名
* -----------------------------------
CALL FUNCTION 'TH_USER_INFO'
IMPORTING
HOSTADDR = IPX "IP地址(16进制)
TERMINAL = HOST. "主机名 * --------------------------------------
* 转换IP地址(16进制转换为10进制字符串)
* --------------------------------------
CALL FUNCTION 'GWY_IPADR2STRING'
EXPORTING
IPADR = IPX
IMPORTING
STRING = IP. "IP地址(10进制字符串) * ------------------------------------
* 补充日志内表的公共部分
* ------------------------------------
GET TIME. "获取最新的时间 IW_CO02LOG-AUFNR = HEADER_TABLE-AUFNR. "订单编码
SHIFT IW_CO02LOG-AUFNR LEFT DELETING LEADING ''.
IW_CO02LOG-CHDAT = SY-DATUM. "操作日期(服务器)
IW_CO02LOG-CHTIM = SY-UZEIT. "操作时间(服务器)
IW_CO02LOG-TCODE = SY-TCODE. "事务代码
IW_CO02LOG-CHUSR = SY-UNAME. "操作客户端用户名
IW_CO02LOG-CHIPA = IP. "操作客户端IP地址
IW_CO02LOG-CHHST = HOST. "操作客户端主机名 MODIFY IT_CO02LOG FROM IW_CO02LOG
TRANSPORTING AUFNR CHDAT CHTIM TCODE CHUSR CHIPA CHHST
WHERE AUFNR IS INITIAL. "全部更新 *--------------------------------------------------------------------*
* 读生产计划数据时 特殊处理
*--------------------------------------------------------------------*
SORT IT_CO02LOG DESCENDING BY CHTYP.
CLEAR:IW_CO02LOG.
LOOP AT IT_CO02LOG INTO IW_CO02LOG.
CONDENSE:IW_CO02LOG-VLNEW NO-GAPS,
IW_CO02LOG-VLOLD NO-GAPS.
IF IW_CO02LOG-CHTYP <> 'D'.
APPEND IW_CO02LOG TO IT_CO02LOGN.
ELSE.
DELETE IT_CO02LOGN WHERE AUFNR = IW_CO02LOG-AUFNR
AND CHTYP = 'I'
AND CHDAT = IW_CO02LOG-CHDAT
AND CHTIM = IW_CO02LOG-CHTIM
AND OBJTP = IW_CO02LOG-OBJTP
AND VLNEW = IW_CO02LOG-VLNEW
AND VLNE2 = IW_CO02LOG-VLNE2
.
IF SY-SUBRC <> .
APPEND IW_CO02LOG TO IT_CO02LOGN.
ENDIF.
ENDIF. ENDLOOP.
*--------------------------------------------------------------------*
* 订单总需求量变更时,只记录总需求量的变更,删除组件的同比例变更记录
*--------------------------------------------------------------------*
SORT IT_CO02LOGN BY CHNUM.
LOOP AT IT_CO02LOGN INTO IW_CO02LOGN.
* * 订单总需求量变更时,只记录总需求量的变更,删除组件的同比例变更记录
IF IW_CO02LOGN-OBJTP = '订单抬头' AND IW_CO02LOGN-OBJNM = '订单总数量'
AND IW_CO02LOGN-CHTYP = 'U' AND IW_CO02LOGN-VLNEW <> '0.000'.
CLEAR: L_RATE.
L_RATE = IW_CO02LOGN-VLOLD / IW_CO02LOGN-VLNEW.
ENDIF. IF IW_CO02LOGN-OBJTP = '订单组件' AND IW_CO02LOGN-OBJNM = '需求数量'
AND IW_CO02LOGN-CHTYP = 'U' AND IW_CO02LOGN-VLNEW <> '0.000'.
CLEAR: L_RATE1.
L_RATE1 = IW_CO02LOGN-VLOLD / IW_CO02LOGN-VLNEW.
IF L_RATE = L_RATE1 AND L_RATE <> .
DELETE TABLE IT_CO02LOGN FROM IW_CO02LOGN.
ENDIF.
ENDIF.
ENDLOOP. IF IT_CO02LOGN IS INITIAL.
IW_CO02LOG-CHNUM = ''.
IW_CO02LOG-CHTYP = 'U'.
IW_CO02LOG-OBJTP = '读生产主数据'.
IW_CO02LOG-OBJNM = '组件、工序均未变更,可能是重读主数据'.
CLEAR:IW_CO02LOG-OBJLU,
IW_CO02LOG-OBJLA,
IW_CO02LOG-VLNEW,
IW_CO02LOG-VLNE2.
APPEND IW_CO02LOG TO IT_CO02LOGN.
ENDIF.
* ---------------------------
* 将日志保存至数据库
* ---------------------------
INSERT ZPPCO02_LOG FROM TABLE IT_CO02LOGN ACCEPTING DUPLICATE KEYS. "忽略索引相同的记录 * ---------------------------
* 删除过早历史数据
* ---------------------------
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
DATE = SY-DATUM
DAYS =
MONTHS =
SIGNUM = '-'
YEARS =
IMPORTING
CALC_DATE = L_DATUM
.
DELETE FROM ZPPCO02_LOG WHERE CHDAT <= L_DATUM. ENDIF. ENDIF.
----------------凑字数-------------------------
励志美文、《抉择》
人的一生常处于抉择之中,如:念哪一间大学?选哪一种职业?娶哪一种女子?……等等伤脑筋的事情。一个人抉择力的有无,可以显示其人格成熟与否。
倒是哪些胸无主见的人,不受抉择之苦。因为逢到需要决定的时候,他总是求询别人说:"嘿,你看怎么做?"
大凡能够成大功业的人,都是抉择力甚强的人。他知道事之成败,全在乎已没有人可以代劳,更没有人能代你决定。
在抉择的哪一刻,成败实已露出端倪。
*&---------------------------------------------------------------------*
** 程序名称:Z
** 程序描述:
** 创建人 :
** 创建日期:
*&---------------------------------------------------------------------*
** 修改记录: REPORT Z. TYPE-POOLS: SLIS.
TABLES: AFKO,USR02,ZPPCO02_LOG. TYPES: BEGIN OF LINE_LOG. "输出日志的结构
INCLUDE STRUCTURE ZPPCO02_LOG. "包含结构ZCO02_LOG_TABLE
TYPES: DDTEXT LIKE DD07T-DDTEXT, "更新类型描述
NAME_TEXT LIKE ADRP-NAME_TEXT,
END OF LINE_LOG. DATA: IT_LOG TYPE STANDARD TABLE OF LINE_LOG WITH HEADER LINE,
BEGIN OF IT_USER OCCURS ,
BNAME LIKE USR21-BNAME,
NAME_TEXT LIKE ADRP-NAME_TEXT,
END OF IT_USER. ************************************************************************
* SELECTION-SCREEN
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK FLAG1 WITH FRAME TITLE TEXT-.
SELECT-OPTIONS:
R_AUFNR FOR AFKO-AUFNR OBLIGATORY MEMORY ID ANR,
R_OPDAT FOR SY-DATUM,
R_OPTIM FOR SY-UZEIT,
R_OPTYP FOR ZPPCO02_LOG-CHTYP,
R_OPUSR FOR USR02-BNAME MATCHCODE OBJECT USER_COMP,
R_CHIPA FOR ZPPCO02_LOG-CHIPA,
R_CHHST FOR ZPPCO02_LOG-CHHST LOWER CASE.
SELECTION-SCREEN END OF BLOCK FLAG1. ************************************************************************
* Initialization
************************************************************************
INITIALIZATION. ************************************************************************
* AT SELECTION-SCREEN
************************************************************************
AT SELECTION-SCREEN. ************************************************************************
* START-OF-SELECTION
************************************************************************
START-OF-SELECTION. PERFORM FRM_GET_DATA.
PERFORM FRM_DISPLAY_ALV. *&--------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&--------------------------------------------------------------------*
* 主程序
*---------------------------------------------------------------------*
FORM FRM_GET_DATA. LOOP AT R_AUFNR.
SHIFT R_AUFNR-LOW LEFT DELETING LEADING ''.
MODIFY R_AUFNR.
ENDLOOP. SELECT *
FROM ZPPCO02_LOG
LEFT JOIN DD07T ON ZPPCO02_LOG~CHTYP = DD07T~DOMVALUE_L AND
DD07T~DDLANGUAGE = SY-LANGU AND
DD07T~AS4LOCAL = 'A' AND
DD07T~DOMNAME = 'VERBUCHER'
INTO CORRESPONDING FIELDS OF TABLE IT_LOG
WHERE AUFNR IN R_AUFNR AND
CHDAT IN R_OPDAT AND
CHTIM IN R_OPTIM AND
CHTYP IN R_OPTYP AND
CHUSR IN R_OPUSR AND
CHIPA IN R_CHIPA AND
CHHST IN R_CHHST.
IF SY-SUBRC <> .
MESSAGE S001() WITH '变更日志不存在' DISPLAY LIKE 'E'.
LEAVE TO TRANSACTION SY-TCODE.
ENDIF. SELECT A~BNAME B~NAME_TEXT
INTO TABLE IT_USER
FROM USR21 AS A
JOIN ADRP AS B ON A~PERSNUMBER = B~PERSNUMBER
FOR ALL ENTRIES IN IT_LOG
WHERE BNAME = IT_LOG-CHUSR.
IF SY-SUBRC = .
LOOP AT IT_LOG.
READ TABLE IT_USER WITH KEY BNAME = IT_LOG-CHUSR.
IF SY-SUBRC = .
IT_LOG-NAME_TEXT = IT_USER-NAME_TEXT.
MODIFY IT_LOG.
ENDIF.
ENDLOOP.
ENDIF. * IT_LOG-DDTEXT = '删除'.
* MODIFY IT_LOG TRANSPORTING DDTEXT WHERE OBJNM = '组件删除'.
SORT IT_LOG BY CHDAT DESCENDING CHTIM DESCENDING CHNUM ASCENDING. ENDFORM. "SUB_MAIN *&--------------------------------------------------------------------*
*& Form FRM_DISPLAY_ALV
*&--------------------------------------------------------------------*
* 输出
*---------------------------------------------------------------------*
FORM FRM_DISPLAY_ALV. DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE, "ALV列属性
GT_LAYOUT TYPE SLIS_LAYOUT_ALV, "ALV布局设置
ALV_TITLE TYPE LVC_TITLE. "ALV表头 GT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'. "ALV布局设置为自动优化列宽
GT_LAYOUT-ZEBRA = 'X'. DEFINE GT_TITLE .
GT_FIELDCAT-FIELDNAME = '&1'. "字段ID
GT_FIELDCAT-JUST = '&2'. "对齐方式
GT_FIELDCAT-EMPHASIZE = & . "列颜色
* GT_FIELDCAT-NO_ZERO = &4 . "不输出前置0
GT_FIELDCAT-KEY = & .
GT_FIELDCAT-NO_OUT = & . "不输出标识
GT_FIELDCAT-SELTEXT_L = '&6'. "字段描述 APPEND GT_FIELDCAT.
CLEAR GT_FIELDCAT.
END-OF-DEFINITION. GT_TITLE:
AUFNR C ' ' 'X' '' 生产订单号,
CHDAT C ' ' 'X' '' 操作日期,
CHTIM C ' ' 'X' '' 操作时间,
CHTYP C 'C600' '' 'X' 更新标志,
DDTEXT C ' ' 'X' '' 操作类型,
CHNUM C 'C410' 'X' '' 流水编号,
CHUSR C 'C300' '' '' SAP用户名,
NAME_TEXT C '' '' '' 姓名,
CHIPA L ' ' '' '' 客户端IP地址,
CHHST L ' ' '' '' 客户端主机名,
OBJTP L 'C300' '' '' 操作对象类别,
OBJNM L 'C300' '' '' 操作对象,
OBJLU L ' ' '' '' 行标记(唯一),
OBJLA L ' ' '' '' 行标记(辅助),
VLOLD L 'C300' '' '' 操作对象原值,
VLNEW L 'C500' '' '' 操作对象新值,
VLNE2 L 'C500' '' '' 操作对象新值(补充),
TCODE C 'C300' '' '' 事务代码. DESCRIBE TABLE IT_LOG[] LINES ALV_TITLE.
CONDENSE ALV_TITLE NO-GAPS. CONCATENATE '生产订单变更日志' '(' ALV_TITLE 'ROWS )' INTO ALV_TITLE
SEPARATED BY SPACE. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'FRM_STATUS_SET'
IT_FIELDCAT = GT_FIELDCAT[]
IS_LAYOUT = GT_LAYOUT
I_SAVE = 'A'
I_GRID_TITLE = ALV_TITLE "表头信息
TABLES
T_OUTTAB = IT_LOG
EXCEPTIONS
PROGRAM_ERROR =
OTHERS = . IF SY-SUBRC <> .
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. ENDFORM. " DISPLAY
*&---------------------------------------------------------------------*
*& FORM FRM_STATUS_SET
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM FRM_STATUS_SET USING EXTAB TYPE SLIS_T_EXTAB. SET PF-STATUS 'ZPPR0052_GS'.
ENDFORM.