Chinaunix首页 | 论坛 | 博客
  • 博客访问: 668244
  • 博文数量: 194
  • 博客积分: 7067
  • 博客等级: 少将
  • 技术积分: 2008
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-09 14:48
个人简介

我很好

文章分类

全部博文(194)

文章存档

2019年(1)

2018年(1)

2017年(3)

2015年(2)

2012年(2)

2011年(1)

2010年(27)

2009年(15)

2008年(142)

分类: WINDOWS

2008-04-29 10:40:41

0、创建数据库 ZPCO02
 
1、运行事务码 COMD
 
2、命名项目名称 ZCO02
 
3、短文描述,因为我们增强的程序与PPCO0001有关,所以描述为 PPCO0001
 
4、选择开发类及传输请求
 
5、选择红色部分,增强分配
 
6、在第一栏里输入 PPCO0001  这个就是我么要增强的程序,之后选择上面的按钮“组件
 
7、双击 EXIT_SAPLCOBT_001  进入到出口程序中
 
8、找到  INCLUDE ZXCO1U01. 双击进去,就是我们要写代码的地方了
 
9、把增强代码写入进来,调试、激活、传到服务器。
 
如下是代码部分:
  TABLES:caufv,resb.
DATABEGIN OF old_resb OCCURS 0"更改后未保存之RESB.
aufnr LIKE resb-aufnr,
posnr LIKE resb-posnr,
matnr LIKE resb-matnr,
rsnum LIKE resb-rsnum,
rspos LIKE resb-rspos,
xloek LIKE resb-xloek,
bdmng LIKE resb-bdmng,
objnr LIKE resb-objnr,
END OF old_resb.

DATABEGIN OF new_resb OCCURS 0"数据库中的RESB.
        INCLUDE STRUCTURE old_resb.
DATAEND OF new_resb.
DATABEGIN OF obj_resb OCCURS 0"插入的RESB
        INCLUDE STRUCTURE old_resb.
DATAEND OF obj_resb.

DATA: i_zpco02 LIKE zpco02 OCCURS 0 WITH HEADER LINE.
DATA: i_temp LIKE zpco02 OCCURS 0 WITH HEADER LINE.

DATA: iporg LIKE msxxlist-hostadr,
ipdec(16TYPE c,
host(18TYPE c.
DATA: char1(20TYPE c,
char2(20TYPE c.

DATA: inst_flg TYPE c VALUE 'N',
chan_had TYPE c VALUE 'N'.
* teco_flg TYPE c VALUE 'N',
* read_flg TYPE c .

*BREAK-POINT.

CHECK sy-tcode EQ 'CO02'.
** Get user IP,hostname
CALL FUNCTION 'TH_USER_INFO' " Get user IP,hostname
EXPORTING
client = sy-mandt
user = sy-uname
IMPORTING
hostaddr = iporg
terminal = host
EXCEPTIONS
OTHERS = 1.
**"Conv.IP addr to format 'xxx.xxx.xxx.xxx'
CALL FUNCTION 'GWY_IPADR2STRING' "Conv.IP addr
EXPORTING
ipadr = iporg
IMPORTING
string = ipdec.
***Common var.
MOVE: sy-mandt TO i_temp-mandt,
sy-uname TO i_temp-aenam,
sy-datum TO i_temp-laeda,
sy-uzeit TO i_temp-times,
sy-tcode TO i_temp-tcode,
ipdec TO i_temp-hostip,
host TO i_temp-host,
header_table-aufnr TO i_temp-aufnr.
***Check M/O header
**check if status eq 'TECO'.
*LOOP AT status_table WHERE objnr EQ header_table-objnr
* AND stat EQ 'I0045'.
*
* MOVE: 'Y' TO teco_flg.
*ENDLOOP.

*CHECK teco_flg NE 'Y'.
*CHECK read_flg NE 'Y'.

SELECT SINGLE gamng gltrp INTO (caufv-gamng, caufv-gltrp)
FROM caufv WHERE aufnr EQ header_table-aufnr.
**qty
IF header_table-gamng NE caufv-gamng.
  MOVE: caufv-gamng TO char1, header_table-gamng TO char2.
  MOVE-CORRESPONDING i_temp TO i_zpco02.
  MOVE'更改工单总数' TO i_zpco02-filed,
  'U' TO i_zpco02-chnid,
  char1 TO i_zpco02-value_old,
  char2 TO i_zpco02-value_new.
  APPEND i_zpco02.
  inst_flg = 'Y'.
  chan_had = 'Y'.
ENDIF.
**date
IF header_table-gltrp NE caufv-gltrp.
  MOVE-CORRESPONDING i_temp TO i_zpco02.
  MOVE'更改完成时间' TO i_zpco02-filed,
  'U' TO i_zpco02-chnid,
  caufv-gltrp TO i_zpco02-value_old,
  header_table-gltrp TO i_zpco02-value_new.
  APPEND i_zpco02.
  inst_flg = 'Y'.
ENDIF.

IF inst_flg = 'Y'.
  INSERT zpco02 FROM TABLE i_zpco02 ACCEPTING DUPLICATE KEYS.
  inst_flg = 'N'.
ENDIF.
*DELETE component_table WHERE vbkz EQ 'I'.
LOOP AT component_table WHERE vbkz EQ 'U'
OR vbkz EQ 'I'
OR vbkz EQ 'D'.
  CASE component_table-vbkz.
    WHEN 'I'.
      MOVE-CORRESPONDING i_temp TO i_zpco02.
      MOVE'新增组件' TO i_zpco02-filed,
      'I' TO i_zpco02-chnid,
      '' TO i_zpco02-value_old, "old_resb-matnr
      component_table-matnr TO i_zpco02-value_new,
      '新增的组件' TO i_zpco02-matnr,
* read_flg TO i_zpco02-readf,
      component_table-alpos TO i_zpco02-alpos,
      sy-tabix TO i_zpco02-loopid.
      APPEND i_zpco02.
      inst_flg = 'Y'.

    WHEN 'D'.
      MOVE-CORRESPONDING i_temp TO i_zpco02.
      MOVE'删除组件' TO i_zpco02-filed,
      'D' TO i_zpco02-chnid,
      resb-xloek TO i_zpco02-value_old,
      component_table-xloek TO i_zpco02-value_new,
      component_table-matnr TO i_zpco02-matnr,
* read_flg TO i_zpco02-readf,
      component_table-alpos TO i_zpco02-alpos,
      sy-tabix TO i_zpco02-loopid.
      APPEND i_zpco02.
      inst_flg = 'Y'.
    WHEN 'U'.
      SELECT SINGLE matnr bdmng INTO (resb-matnr, resb-bdmng)
      FROM resb WHERE aufnr EQ component_table-aufnr
      AND posnr EQ component_table-posnr
      AND matnr EQ component_table-matnr
      AND rsnum EQ component_table-rsnum
      AND rspos EQ component_table-rspos.
      IF component_table-matnr NE resb-matnr.
        MOVE-CORRESPONDING i_temp TO i_zpco02.
        MOVE'更改组件' TO i_zpco02-filed,
        'U' TO i_zpco02-chnid,
        resb-matnr TO i_zpco02-value_old,
        component_table-matnr TO i_zpco02-value_new,
        '更改的工单组件' TO i_zpco02-matnr,
* read_flg TO i_zpco02-readf,
        component_table-alpos TO i_zpco02-alpos,
        sy-tabix TO i_zpco02-loopid.
        APPEND i_zpco02.
        inst_flg = 'Y'.

      ELSEIF component_table-bdmng NE resb-bdmng.
        CHECK chan_had NE 'Y'.
        MOVE: component_table-bdmng TO char1, resb-bdmng TO char2.
        MOVE-CORRESPONDING i_temp TO i_zpco02.
        MOVE'需求数量' TO i_zpco02-filed,
        'U' TO i_zpco02-chnid,
        char2 TO i_zpco02-value_old,
        char1 TO i_zpco02-value_new,
        component_table-matnr TO i_zpco02-matnr,
* read_flg TO i_zpco02-readf,
        component_table-alpos TO i_zpco02-alpos,
        sy-tabix TO i_zpco02-loopid.
        APPEND i_zpco02.
        inst_flg = 'Y'.
      ENDIF.

  ENDCASE.
ENDLOOP.

IF inst_flg = 'Y'.
  INSERT zpco02 FROM TABLE i_zpco02 ACCEPTING DUPLICATE KEYS.
  IF sy-subrc EQ 0.
    inst_flg = 'N'.
    chan_had = 'N'.
* MESSAGE ID 'ZX' TYPE 'W'
* NUMBER '000' WITH 'SAP系统已记录您的更改!'.
  ENDIF.
ENDIF.
 
2008-10-05修改
  *&---------------------------------------------------------------------*
*&  包括                ZXCO1U01
*&---------------------------------------------------------------------*


TABLES:caufv,resb,jest.
DATABEGIN OF old_resb OCCURS 0"更改后未保存之RESB.
aufnr LIKE resb-aufnr,
posnr LIKE resb-posnr,
matnr LIKE resb-matnr,
rsnum LIKE resb-rsnum,
rspos LIKE resb-rspos,
xloek LIKE resb-xloek,
bdmng LIKE resb-bdmng,
objnr LIKE resb-objnr,
END OF old_resb.

DATABEGIN OF new_resb OCCURS 0"数据库中的RESB.
        INCLUDE STRUCTURE old_resb.
DATAEND OF new_resb.
DATABEGIN OF obj_resb OCCURS 0"插入的RESB
        INCLUDE STRUCTURE old_resb.
DATAEND OF obj_resb.

DATABEGIN OF obj_jest OCCURS 0"插入的RESB
        INCLUDE STRUCTURE jest.
DATAEND OF obj_jest.

DATA: i_zpco02 LIKE zpco02 OCCURS 0 WITH HEADER LINE.
DATA: i_temp LIKE zpco02 OCCURS 0 WITH HEADER LINE.

DATA: iporg LIKE msxxlist-hostadr,
ipdec(16TYPE c,
host(18TYPE c.
DATA: char1(20TYPE c,
char2(20TYPE c,
state(20TYPE c,
zindex TYPE int4.

DATA: inst_flg TYPE c VALUE 'N',
chan_had TYPE c VALUE 'N'.
* teco_flg TYPE c VALUE 'N',
* read_flg TYPE c .

*BREAK-POINT.

CHECK sy-tcode EQ 'CO02'.
** Get user IP,hostname
CALL FUNCTION 'TH_USER_INFO' " Get user IP,hostname
EXPORTING
client = sy-mandt
user = sy-uname
IMPORTING
hostaddr = iporg
terminal = host
EXCEPTIONS
OTHERS = 1.
**"Conv.IP addr to format 'xxx.xxx.xxx.xxx'
CALL FUNCTION 'GWY_IPADR2STRING' "Conv.IP addr
EXPORTING
ipadr = iporg
IMPORTING
string = ipdec.
***Common var.
MOVE: sy-mandt TO i_temp-mandt,
sy-uname TO i_temp-aenam,
sy-datum TO i_temp-laeda,
sy-uzeit TO i_temp-times,
sy-tcode TO i_temp-tcode,
ipdec TO i_temp-hostip,
host TO i_temp-host,
header_table-aufnr TO i_temp-aufnr.
SELECT MAX( zindex ) INTO zindex FROM zpco02.

SELECT * INTO CORRESPONDING FIELDS OF TABLE obj_jest
  FROM jest
  WHERE ( stat = 'I0002'  OR  stat = 'I0046' )
    AND objnr = header_table-objnr.
***Check M/O header
**check if status eq 'TECO'.
LOOP AT status_table WHERE objnr EQ header_table-objnr
 AND ( stat EQ 'I0046' OR stat EQ 'I0002' ) .
  READ TABLE obj_jest WITH KEY objnr = header_table-objnr  stat = status_table-stat.
  IF obj_jest-inact NE status_table-inact.
    zindex = zindex + 1.

    MOVE-CORRESPONDING i_temp TO i_zpco02.
    MOVE'更改状态' TO i_zpco02-filed,
    'U' TO i_zpco02-chnid,
    component_table-baugr TO i_zpco02-matnr,
    component_table-alpos TO i_zpco02-alpos,
    sy-tabix TO i_zpco02-loopid,
    zindex TO i_zpco02-zindex.

    CONCATENATE  obj_jest-stat obj_jest-inact INTO state.
    i_zpco02-value_old = state."   OBJ_JEST-STAT TO i_zpco02-value_old.

    state = ''.
    CONCATENATE  status_table-stat status_table-inact INTO state.
    i_zpco02-value_new = state.
    APPEND i_zpco02.
    inst_flg = 'Y'.
  ENDIF.
ENDLOOP.



SELECT SINGLE gamng gltrp INTO (caufv-gamng, caufv-gltrp)
FROM caufv WHERE aufnr EQ header_table-aufnr.
**qty
IF header_table-gamng NE caufv-gamng.
  zindex = zindex + 1.
  MOVE: caufv-gamng TO char1, header_table-gamng TO char2.
  MOVE-CORRESPONDING i_temp TO i_zpco02.
  MOVE'更改工单总数' TO i_zpco02-filed,
  'U' TO i_zpco02-chnid,
  component_table-baugr TO i_zpco02-matnr,
  char1 TO i_zpco02-value_old,
  char2 TO i_zpco02-value_new,
  zindex TO i_zpco02-zindex.

  APPEND i_zpco02.
  inst_flg = 'Y'.
  chan_had = 'Y'.
ENDIF.
**date
IF header_table-gltrp NE caufv-gltrp.
  zindex = zindex + 1.
  MOVE-CORRESPONDING i_temp TO i_zpco02.
  MOVE'更改完成时间' TO i_zpco02-filed,
  'U' TO i_zpco02-chnid,
  caufv-gltrp TO i_zpco02-value_old,
  header_table-gltrp TO i_zpco02-value_new,
  component_table-baugr TO i_zpco02-matnr,
  zindex TO i_zpco02-zindex.
  APPEND i_zpco02.
  inst_flg = 'Y'.
ENDIF.

IF inst_flg = 'Y'.
  INSERT zpco02 FROM  TABLE i_zpco02 ACCEPTING DUPLICATE KEYS.
  inst_flg = 'N'.
  REFRESH i_zpco02.
ENDIF.
*DELETE component_table WHERE vbkz EQ 'I'.
LOOP AT component_table WHERE vbkz EQ 'U'
OR vbkz EQ 'I'
OR vbkz EQ 'D'.
  zindex = zindex + 1.
  CASE component_table-vbkz.

    WHEN 'I'.
      MOVE-CORRESPONDING i_temp TO i_zpco02.
      MOVE'新增组件' TO i_zpco02-filed,
      'I' TO i_zpco02-chnid,
      '' TO i_zpco02-value_old, "old_resb-matnr
      component_table-matnr TO i_zpco02-value_new,
      '新增的组件' TO i_zpco02-matnr,
* read_flg TO i_zpco02-readf,
      component_table-alpos TO i_zpco02-alpos,
      sy-tabix TO i_zpco02-loopid,
      zindex TO i_zpco02-zindex.
      APPEND i_zpco02.
      inst_flg = 'Y'.

    WHEN 'D'.
      MOVE-CORRESPONDING i_temp TO i_zpco02.
      MOVE'删除组件' TO i_zpco02-filed,
      'D' TO i_zpco02-chnid,
      resb-xloek TO i_zpco02-value_old,
      component_table-xloek TO i_zpco02-value_new,
      component_table-matnr TO i_zpco02-matnr,
* read_flg TO i_zpco02-readf,
      component_table-alpos TO i_zpco02-alpos,
      sy-tabix TO i_zpco02-loopid,
      zindex TO i_zpco02-zindex.
      APPEND i_zpco02.
      inst_flg = 'Y'.
    WHEN 'U'.
      SELECT SINGLE matnr bdmng INTO (resb-matnr, resb-bdmng)
      FROM resb WHERE aufnr EQ component_table-aufnr
      AND posnr EQ component_table-posnr
      AND baugr EQ component_table-baugr
      AND rsnum EQ component_table-rsnum
      AND rspos EQ component_table-rspos.
      IF component_table-matnr NE resb-matnr.
        MOVE-CORRESPONDING i_temp TO i_zpco02.
        MOVE'更改组件' TO i_zpco02-filed,
        'U' TO i_zpco02-chnid,
        resb-matnr TO i_zpco02-value_old,
        component_table-matnr TO i_zpco02-value_new,
        component_table-baugr TO i_zpco02-matnr,
* read_flg TO i_zpco02-readf,
        component_table-alpos TO i_zpco02-alpos,
        sy-tabix TO i_zpco02-loopid,
        zindex TO i_zpco02-zindex.
        APPEND i_zpco02.
        inst_flg = 'Y'.

      ELSEIF component_table-bdmng NE resb-bdmng.
        CHECK chan_had NE 'Y'.
        MOVE: component_table-bdmng TO char1, resb-bdmng TO char2.
        MOVE-CORRESPONDING i_temp TO i_zpco02.
        MOVE'需求数量' TO i_zpco02-filed,
        'U' TO i_zpco02-chnid,
        char2 TO i_zpco02-value_old,
        char1 TO i_zpco02-value_new,
        component_table-matnr TO i_zpco02-matnr,
* read_flg TO i_zpco02-readf,
        component_table-alpos TO i_zpco02-alpos,
        sy-tabix TO i_zpco02-loopid,
        zindex TO i_zpco02-zindex.
        APPEND i_zpco02.
        inst_flg = 'Y'.
      ENDIF.

  ENDCASE.
ENDLOOP.

IF inst_flg = 'Y'.
  INSERT zpco02 FROM TABLE i_zpco02 ACCEPTING DUPLICATE KEYS.
  IF sy-subrc EQ 0.
    inst_flg = 'N'.
    chan_had = 'N'.
* MESSAGE ID 'ZX' TYPE 'W'
* NUMBER '000' WITH 'SAP系统已记录您的更改!'.
  ENDIF.
ENDIF.
 
阅读(3085) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~