SAP PP 生产订单变更记录保存
*&---------------------------------------------------------------------* *& 包括 ZXCO1U01 *&---------------------------------------------------------------------* ***生产订单关键参数修改日志记录 IF HEADER_TABLE-AUTYP = '10' 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 5, L_RATE1 TYPE P DECIMALS 5. *--------------------------------------------------------------------* * 宏定义 *--------------------------------------------------------------------* DEFINE DEL_ZERO_R. SHIFT &1 RIGHT DELETING TRAILING '0'. SHIFT &1 RIGHT DELETING TRAILING '.'. CONDENSE &1 NO-GAPS. END-OF-DEFINITION. DEFINE ULOG_LINE. * &1:表名 * &2:表名差异部分 * &3:字段名 * &4:变更对象类型 * &5:变更对象的描述 IF &1-&3 <> &1_&2-&3. CLEAR IW_CO02LOG. VI_OPNUM = VI_OPNUM + 1. "记录本次操作的流水编码(自增1) IW_CO02LOG-CHNUM = VI_OPNUM. "记录本次操作的流水编码 IW_CO02LOG-CHTYP = 'U'. "操作类型:U-更新 IW_CO02LOG-OBJTP = '&4'. "操作对象类型(抬头、组件、工艺等) IW_CO02LOG-OBJNM = '&5'. "操作对象描述 IW_CO02LOG-VLOLD = &1_&2-&3. "操作对象的旧值 IW_CO02LOG-VLNEW = &1-&3. "操作对象的新值 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-&3 <> &1_&2-&3. CLEAR IW_CO02LOG. VI_OPNUM = VI_OPNUM + 1. "记录本次操作的流水编码(自增1) IW_CO02LOG-CHNUM = VI_OPNUM. "记录本次操作的流水编码 IW_CO02LOG-CHTYP = 'U'. "操作类型:U-更新 IW_CO02LOG-OBJTP = '&4'. "操作对象类型(抬头、组件、工艺等) IW_CO02LOG-OBJNM = '&5'. "操作对象描述 * ------------------------------------------- * 操作对象唯一行标记,例如:预留项目号(1) * 唯一行标记一般前台不可见,但唯一且不可更改 * ------------------------------------------- IW_CO02LOG-OBJLU = &1-&7. "操作对象唯一行标记的值(例如:0001) SHIFT IW_CO02LOG-OBJLU LEFT DELETING LEADING '0'. "去除前置0 CONCATENATE '&6' '(' IW_CO02LOG-OBJLU ')' INTO IW_CO02LOG-OBJLU. "拼写描述 * ------------------------------------------- * 操作对象辅助行标记,例如:BOM项目号(0010) * 辅助行标记一般不唯一或可修改,但最常用 * ------------------------------------------- IW_CO02LOG-OBJLA = &1-&9. "操作对象辅助行标记的值(例如:0010) CONCATENATE '&8' '(' IW_CO02LOG-OBJLA ')' INTO IW_CO02LOG-OBJLA. "拼写描述 IW_CO02LOG-VLOLD = &1_&2-&3. "操作对象的旧值 IW_CO02LOG-VLNEW = &1-&3. "操作对象的新值 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. "记录本次操作的流水编码(自增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'. "去除前置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 '0'. 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 = 0. SHIFT COMPONENT_TABLE_OLD-MATNR LEFT DELETING LEADING '0'. SHIFT COMPONENT_TABLE-MATNR LEFT DELETING LEADING '0'. SHIFT COMPONENT_TABLE_OLD-LIFNR LEFT DELETING LEADING '0'. SHIFT COMPONENT_TABLE-LIFNR LEFT DELETING LEADING '0'. 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. "记录本次操作的流水编码(自增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'. "去除前置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 '0'. 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. "记录本次操作的流水编码(自增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'. "去除前置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 = 0. 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 = 0. * ------------------------------------- * 可直接记录更改的参数(工序基本信息) * ------------------------------------- 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. "记录本次操作的流水编码(自增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'. "去除前置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 = 0. * --------------------------------------------- * 可直接记录更改的参数(工时信息) * --------------------------------------------- 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. "记录本次操作的流水编码(自增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'. "去除前置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 = 0. 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 '0'. 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 <> 0. 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 <> 0. DELETE TABLE IT_CO02LOGN FROM IW_CO02LOGN. ENDIF. ENDIF. ENDLOOP. IF IT_CO02LOGN IS INITIAL. IW_CO02LOG-CHNUM = '1'. 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 = 0 MONTHS = 3 SIGNUM = '-' YEARS = 0 IMPORTING CALC_DATE = L_DATUM . DELETE FROM ZPPCO02_LOG WHERE CHDAT <= L_DATUM. ENDIF. ENDIF.
----------------凑字数-------------------------
励志美文、《抉择》
人的一生常处于抉择之中,如:念哪一间大学?选哪一种职业?娶哪一种女子?……等等伤脑筋的事情。一个人抉择力的有无,可以显示其人格成熟与否。
倒是哪些胸无主见的人,不受抉择之苦。因为逢到需要决定的时候,他总是求询别人说:"嘿,你看怎么做?"
大凡能够成大功业的人,都是抉择力甚强的人。他知道事之成败,全在乎已没有人可以代劳,更没有人能代你决定。
在抉择的哪一刻,成败实已露出端倪。
1 *&---------------------------------------------------------------------* 2 ** 程序名称:Z 3 ** 程序描述: 4 ** 创建人 : 5 ** 创建日期: 6 *&---------------------------------------------------------------------* 7 ** 修改记录: 8 9 REPORT Z. 10 11 TYPE-POOLS: SLIS. 12 TABLES: AFKO,USR02,ZPPCO02_LOG. 13 14 TYPES: BEGIN OF LINE_LOG. "输出日志的结构 15 INCLUDE STRUCTURE ZPPCO02_LOG. "包含结构ZCO02_LOG_TABLE 16 TYPES: DDTEXT LIKE DD07T-DDTEXT, "更新类型描述 17 NAME_TEXT LIKE ADRP-NAME_TEXT, 18 END OF LINE_LOG. 19 20 DATA: IT_LOG TYPE STANDARD TABLE OF LINE_LOG WITH HEADER LINE, 21 BEGIN OF IT_USER OCCURS 0, 22 BNAME LIKE USR21-BNAME, 23 NAME_TEXT LIKE ADRP-NAME_TEXT, 24 END OF IT_USER. 25 26 27 ************************************************************************ 28 * SELECTION-SCREEN 29 ************************************************************************ 30 SELECTION-SCREEN BEGIN OF BLOCK FLAG1 WITH FRAME TITLE TEXT-001. 31 SELECT-OPTIONS: 32 R_AUFNR FOR AFKO-AUFNR OBLIGATORY MEMORY ID ANR, 33 R_OPDAT FOR SY-DATUM, 34 R_OPTIM FOR SY-UZEIT, 35 R_OPTYP FOR ZPPCO02_LOG-CHTYP, 36 R_OPUSR FOR USR02-BNAME MATCHCODE OBJECT USER_COMP, 37 R_CHIPA FOR ZPPCO02_LOG-CHIPA, 38 R_CHHST FOR ZPPCO02_LOG-CHHST LOWER CASE. 39 SELECTION-SCREEN END OF BLOCK FLAG1. 40 41 ************************************************************************ 42 * Initialization 43 ************************************************************************ 44 INITIALIZATION. 45 46 ************************************************************************ 47 * AT SELECTION-SCREEN 48 ************************************************************************ 49 AT SELECTION-SCREEN. 50 51 52 ************************************************************************ 53 * START-OF-SELECTION 54 ************************************************************************ 55 START-OF-SELECTION. 56 57 PERFORM FRM_GET_DATA. 58 PERFORM FRM_DISPLAY_ALV. 59 60 *&--------------------------------------------------------------------* 61 *& Form FRM_GET_DATA 62 *&--------------------------------------------------------------------* 63 * 主程序 64 *---------------------------------------------------------------------* 65 FORM FRM_GET_DATA. 66 67 LOOP AT R_AUFNR. 68 SHIFT R_AUFNR-LOW LEFT DELETING LEADING '0'. 69 MODIFY R_AUFNR. 70 ENDLOOP. 71 72 SELECT * 73 FROM ZPPCO02_LOG 74 LEFT JOIN DD07T ON ZPPCO02_LOG~CHTYP = DD07T~DOMVALUE_L AND 75 DD07T~DDLANGUAGE = SY-LANGU AND 76 DD07T~AS4LOCAL = 'A' AND 77 DD07T~DOMNAME = 'VERBUCHER' 78 INTO CORRESPONDING FIELDS OF TABLE IT_LOG 79 WHERE AUFNR IN R_AUFNR AND 80 CHDAT IN R_OPDAT AND 81 CHTIM IN R_OPTIM AND 82 CHTYP IN R_OPTYP AND 83 CHUSR IN R_OPUSR AND 84 CHIPA IN R_CHIPA AND 85 CHHST IN R_CHHST. 86 IF SY-SUBRC <> 0. 87 MESSAGE S001(00) WITH '变更日志不存在' DISPLAY LIKE 'E'. 88 LEAVE TO TRANSACTION SY-TCODE. 89 ENDIF. 90 91 SELECT A~BNAME B~NAME_TEXT 92 INTO TABLE IT_USER 93 FROM USR21 AS A 94 JOIN ADRP AS B ON A~PERSNUMBER = B~PERSNUMBER 95 FOR ALL ENTRIES IN IT_LOG 96 WHERE BNAME = IT_LOG-CHUSR. 97 IF SY-SUBRC = 0. 98 LOOP AT IT_LOG. 99 READ TABLE IT_USER WITH KEY BNAME = IT_LOG-CHUSR. 100 IF SY-SUBRC = 0. 101 IT_LOG-NAME_TEXT = IT_USER-NAME_TEXT. 102 MODIFY IT_LOG. 103 ENDIF. 104 ENDLOOP. 105 ENDIF. 106 107 * IT_LOG-DDTEXT = '删除'. 108 * MODIFY IT_LOG TRANSPORTING DDTEXT WHERE OBJNM = '组件删除'. 109 SORT IT_LOG BY CHDAT DESCENDING CHTIM DESCENDING CHNUM ASCENDING. 110 111 ENDFORM. "SUB_MAIN 112 113 114 *&--------------------------------------------------------------------* 115 *& Form FRM_DISPLAY_ALV 116 *&--------------------------------------------------------------------* 117 * 输出 118 *---------------------------------------------------------------------* 119 FORM FRM_DISPLAY_ALV. 120 121 DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE, "ALV列属性 122 GT_LAYOUT TYPE SLIS_LAYOUT_ALV, "ALV布局设置 123 ALV_TITLE TYPE LVC_TITLE. "ALV表头 124 125 GT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'. "ALV布局设置为自动优化列宽 126 GT_LAYOUT-ZEBRA = 'X'. 127 128 DEFINE GT_TITLE . 129 GT_FIELDCAT-FIELDNAME = '&1'. "字段ID 130 GT_FIELDCAT-JUST = '&2'. "对齐方式 131 GT_FIELDCAT-EMPHASIZE = &3 . "列颜色 132 * GT_FIELDCAT-NO_ZERO = &4 . "不输出前置0 133 GT_FIELDCAT-KEY = &4 . 134 GT_FIELDCAT-NO_OUT = &5 . "不输出标识 135 GT_FIELDCAT-SELTEXT_L = '&6'. "字段描述 136 137 APPEND GT_FIELDCAT. 138 CLEAR GT_FIELDCAT. 139 END-OF-DEFINITION. 140 141 GT_TITLE: 142 AUFNR C ' ' 'X' '' 生产订单号, 143 CHDAT C ' ' 'X' '' 操作日期, 144 CHTIM C ' ' 'X' '' 操作时间, 145 CHTYP C 'C600' '' 'X' 更新标志, 146 DDTEXT C ' ' 'X' '' 操作类型, 147 CHNUM C 'C410' 'X' '' 流水编号, 148 CHUSR C 'C300' '' '' SAP用户名, 149 NAME_TEXT C '' '' '' 姓名, 150 CHIPA L ' ' '' '' 客户端IP地址, 151 CHHST L ' ' '' '' 客户端主机名, 152 OBJTP L 'C300' '' '' 操作对象类别, 153 OBJNM L 'C300' '' '' 操作对象, 154 OBJLU L ' ' '' '' 行标记(唯一), 155 OBJLA L ' ' '' '' 行标记(辅助), 156 VLOLD L 'C300' '' '' 操作对象原值, 157 VLNEW L 'C500' '' '' 操作对象新值, 158 VLNE2 L 'C500' '' '' 操作对象新值(补充), 159 TCODE C 'C300' '' '' 事务代码. 160 161 DESCRIBE TABLE IT_LOG[] LINES ALV_TITLE. 162 CONDENSE ALV_TITLE NO-GAPS. 163 164 CONCATENATE '生产订单变更日志' '(' ALV_TITLE 'ROWS )' INTO ALV_TITLE 165 SEPARATED BY SPACE. 166 167 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' 168 EXPORTING 169 I_CALLBACK_PROGRAM = SY-REPID 170 I_CALLBACK_PF_STATUS_SET = 'FRM_STATUS_SET' 171 IT_FIELDCAT = GT_FIELDCAT[] 172 IS_LAYOUT = GT_LAYOUT 173 I_SAVE = 'A' 174 I_GRID_TITLE = ALV_TITLE "表头信息 175 TABLES 176 T_OUTTAB = IT_LOG 177 EXCEPTIONS 178 PROGRAM_ERROR = 1 179 OTHERS = 2. 180 181 IF SY-SUBRC <> 0. 182 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO 183 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. 184 ENDIF. 185 186 ENDFORM. " DISPLAY 187 *&---------------------------------------------------------------------* 188 *& FORM FRM_STATUS_SET 189 *&---------------------------------------------------------------------* 190 * TEXT 191 *----------------------------------------------------------------------* 192 * --> P1 TEXT 193 * <-- P2 TEXT 194 *----------------------------------------------------------------------* 195 FORM FRM_STATUS_SET USING EXTAB TYPE SLIS_T_EXTAB. 196 197 SET PF-STATUS 'ZPPR0052_GS'. 198 ENDFORM.