Chinaunix首页 | 论坛 | 博客
  • 博客访问: 286392
  • 博文数量: 62
  • 博客积分: 2966
  • 博客等级: 少校
  • 技术积分: 615
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-07 23:16
个人简介

Be a simple man

文章分类

全部博文(62)

文章存档

2012年(6)

2011年(15)

2010年(6)

2009年(3)

2008年(5)

2007年(27)

我的朋友

分类:

2007-06-27 10:01:22

REPORT z_jason_test887 .
TABLES: mara,a003,konp.
DATA: BEGIN OF itab_release OCCURS 0,
        ebeln LIKE ekpo-ebeln,
      END OF itab_release.
DATA: BEGIN OF itab_add OCCURS 0 ,
        ebeln LIKE ekpo-ebeln,
        bonba LIKE ekpo-bonba,
      END OF itab_add.

DATA: BEGIN OF itab_ekpo2 OCCURS 0.
        INCLUDE STRUCTURE ekpo.
DATA: END OF itab_ekpo2.
DATA: BEGIN OF itab_item OCCURS 0,
        spras LIKE ekko-spras,
        ebeln LIKE ekko-ebeln,
        ebelp LIKE ekpo-ebelp,
        matnr LIKE ekpo-matnr,
        meins LIKE ekpo-meins,
        umrez LIKE ekpo-umrez,
        netpr LIKE eine-effpr,
        dispr LIKE ekpo-netpr,
        menge LIKE ekpo-menge,
        qtynr TYPE ekpo-menge,
        bonba LIKE ekpo-bonba,
        pstyp LIKE ekpo-pstyp,
      END OF itab_item.
DATA: BEGIN OF itab_head OCCURS 0,
          spras LIKE ekko-spras,
          werks LIKE ekpo-werks,
          bukrs LIKE ekko-bukrs,
          lifnr LIKE ekko-lifnr,
          bsart LIKE ekko-bsart,
          ebeln LIKE ekko-ebeln,
          aedat LIKE ekko-aedat,
          eindt LIKE eket-eindt,
          candt LIKE eket-eindt,
          ernam LIKE ekko-ernam,
          ernam2 LIKE ekko-ernam,
          waers LIKE ekko-waers,
          werks2 LIKE ekpo-werks,
          ebeln2 LIKE ekko-ebeln,
          total_price LIKE ekpo-bonba,
*          long_text
          retpo LIKE ekpo-retpo,
*          ADD_DATE
*          MODIFY_DATE
*          CANCEL_DATE
          zzrepairpo LIKE ekko-zzrepairpo,
      END OF itab_head.
DATA: BEGIN OF itab_temp OCCURS 0,
          spras LIKE ekko-spras,
          ebeln LIKE ekko-ebeln,
          ebelp LIKE ekpo-ebelp,
          matnr LIKE ekpo-matnr,
          meins LIKE ekpo-meins,
          umrez LIKE ekpo-umrez,
          netpr LIKE eine-netpr,
          dispr LIKE ekpo-netpr,
          menge LIKE ekpo-menge,
          qtynr TYPE ekpo-menge,
          mwskz LIKE ekpo-mwskz,
          bonba LIKE ekpo-bonba,
          brtwr LIKE ekpo-brtwr,
          pstyp LIKE ekpo-pstyp,
          werks LIKE ekpo-werks,
          bukrs LIKE ekko-bukrs,
          lifnr LIKE ekko-lifnr,
          bsart LIKE ekko-bsart,
          aedat LIKE ekko-aedat,
          ekorg LIKE ekko-ekorg,
          infnr LIKE ekpo-infnr,
          eindt LIKE eket-eindt,
          candt LIKE eket-eindt,
          ernam LIKE ekko-ernam,
          ernam2 LIKE ekko-ernam,
          waers LIKE ekko-waers,
          werks2 LIKE ekpo-werks,
          ebeln2 LIKE ekko-ebeln,
          total_price LIKE ekpo-bonba,
*          long_text
          retpo LIKE ekpo-retpo,
*          ADD_DATE
*          MODIFY_DATE
*          CANCEL_DATE
          zzrepairpo LIKE ekko-zzrepairpo,
      END OF itab_temp.
DATA:BEGIN OF itab_eine OCCURS 0.
        INCLUDE STRUCTURE eine.
DATA:END OF itab_eine.
DATA:BEGIN OF itab_zpo2po_log OCCURS 0.
        INCLUDE STRUCTURE zpo2po_log.
DATA: END OF itab_zpo2po_log.
DATA: BEGIN OF incom OCCURS 0.
        INCLUDE STRUCTURE meico.
DATA: END OF incom.
DATA: BEGIN OF inpreissim OCCURS 0 .
        INCLUDE STRUCTURE meprck.
DATA: END OF inpreissim.
DATA: BEGIN OF expreissim OCCURS 0.
        INCLUDE STRUCTURE mepro.
DATA: END OF expreissim.
*PARAMETER: p_date TYPE syst-datum,
*           p_time TYPE syst-uzeit.
DATA: knumh LIKE a017-knumh.
DATA: kbetr LIKE konp-kbetr.
DATA: total_price LIKE ekpo-netpr.

PERFORM get_data.
PERFORM write_data.
*---------------------------------------------------------------------*
*       FORM get_data                                                 *
*---------------------------------------------------------------------*
FORM get_data.
  DATA: incom      TYPE meico,
        inpreissim TYPE meprck,
        expreissim TYPE mepro.
  DATA: net_price LIKE ekpo-netpr.
*incom-esokz = '2'.
*incom-ekorg = 'B000' .
*incom-werks = '1001'.
*incom-lifnr = '0000100000'.
*incom-matnr = '000000000001000532'.
*
*inpreissim-simng = 1.
*inpreissim-simme = 'EA'.
*inpreissim-sidat = '20070622' .
*inpreissim-bwsv1 = '3'.

*测试数据
  itab_release-ebeln =  '0100003269' .
  APPEND itab_release.
  itab_release-ebeln =  '0100003270' .
  APPEND itab_release.
*  itab_release-ebeln =  '0100003272' .
*  APPEND itab_release.
*  itab_release-ebeln =  '0100003273' .
*  APPEND itab_release.
*  itab_release-ebeln =  '0100003274' .
*  APPEND itab_release.
  CHECK NOT itab_release[] IS INITIAL.
  SELECT *
  INTO CORRESPONDING FIELDS OF TABLE itab_temp
  FROM ekpo INNER JOIN ekko ON ekpo~ebeln = ekko~ebeln
            INNER JOIN eket ON ekpo~ebeln = eket~ebeln AND
                               ekpo~ebelp = eket~ebelp
  FOR ALL entries IN itab_release
  WHERE ekpo~ebeln = itab_release-ebeln
  .
*如果为代销K,则从info recode取净价 * 税额,
*如果为经销,从EKPO取单价 * 税额 得到税后单价
  CHECK NOT itab_temp[] IS INITIAL.
  LOOP AT itab_temp .
    IF itab_temp-pstyp = '2' .
      incom-esokz = itab_temp-pstyp.
      incom-ekorg = itab_temp-ekorg .
      incom-werks = itab_temp-werks.
      incom-lifnr = itab_temp-lifnr.
      incom-matnr = itab_temp-matnr.
      inpreissim-simng = 1.
      inpreissim-simme = itab_temp-meins.
      inpreissim-sidat = itab_temp-aedat.
      inpreissim-bwsv1 = '3'.
      CALL FUNCTION 'ME_READ_INFORECORD'
           EXPORTING
                incom             = incom
                inpreissim        = inpreissim
           IMPORTING
                expreissim        = expreissim
           EXCEPTIONS
                bad_comin         = 1
                bad_material      = 2
                bad_materialclass = 3
                bad_supplier      = 4
                not_found         = 5
                OTHERS            = 6.
      net_price = expreissim-preis / expreissim-peinh .
      SELECT SINGLE * FROM a003
      WHERE aland = 'CN' AND mwskz = expreissim-mwskz.
      SELECT SINGLE * FROM konp
      WHERE knumh = a003-knumh.
      IF sy-subrc = 0.
        itab_temp-netpr = net_price  * ( 1 + konp-kbetr / 1000 ).
        itab_temp-candt = itab_temp-eindt + 3 .
        itab_temp-qtynr = itab_temp-umrez * itab_temp-menge .
        itab_temp-dispr = itab_temp-netpr .
        itab_temp-bonba = itab_temp-dispr * itab_temp-menge .
        MODIFY itab_temp.
      ENDIF.
    ELSE.
      itab_temp-candt = itab_temp-eindt + 3 .
      itab_temp-qtynr = itab_temp-umrez * itab_temp-menge .
      itab_temp-dispr = itab_temp-bonba / itab_temp-menge .
      SELECT SINGLE * FROM a003
      WHERE aland = 'CN' AND mwskz = itab_temp-mwskz.
      SELECT SINGLE * FROM konp
      WHERE knumh = a003-knumh.
      itab_temp-netpr = itab_temp-netpr * ( 1 + konp-kbetr / 1000 ).
      MODIFY itab_temp.
    ENDIF.
  ENDLOOP.
*PO如果为CROSS-STOCKING型,则从ZPO2PO_LOG取得原订单号,
*并从EKPO取得原订单门店
  CHECK NOT itab_temp[] IS INITIAL.
  SELECT * FROM zpo2po_log
  INTO CORRESPONDING FIELDS OF TABLE itab_zpo2po_log
  FOR ALL ENTRIES IN itab_temp
  WHERE zpo2po_log~vponr = itab_temp-ebeln .
  LOOP AT itab_temp.
    READ TABLE itab_zpo2po_log WITH KEY vponr = itab_temp-ebeln .
    IF sy-subrc = 0.
      itab_temp-ebeln2 = itab_zpo2po_log-lponr .
      MODIFY itab_temp.
    ENDIF.
  ENDLOOP.
  SELECT * FROM ekpo
  INTO CORRESPONDING FIELDS OF TABLE itab_ekpo2
  FOR ALL ENTRIES IN itab_temp
  WHERE  ekpo~ebeln = itab_temp-ebeln.
  LOOP AT itab_temp.
    READ TABLE itab_ekpo2 WITH KEY ebeln = itab_temp-ebeln2.
    IF sy-subrc = 0.
      itab_temp-werks2 = itab_ekpo2-werks .
      MODIFY itab_temp.
    ENDIF.
  ENDLOOP.
*相同PO累加ITEM金额,取得该PO的总额
*itab_add 为临时处理内表
  SORT itab_temp BY ebeln ebelp.
  DELETE ADJACENT DUPLICATES FROM itab_temp .
  LOOP AT itab_temp.
    MOVE-CORRESPONDING itab_temp TO itab_add.
    COLLECT itab_add.
  ENDLOOP.
  LOOP AT itab_temp.
    READ TABLE itab_add WITH KEY ebeln = itab_temp-ebeln .
    IF sy-subrc = 0 .
      itab_temp-total_price = itab_add-bonba.
      MODIFY itab_temp.
    ENDIF.
  ENDLOOP.
*move itab_temp to itab_head and itab_item.
  LOOP AT itab_temp.
    MOVE-CORRESPONDING itab_temp TO itab_head.
    MOVE-CORRESPONDING itab_temp TO itab_item.
    APPEND itab_head.
    APPEND itab_item.
  ENDLOOP.
ENDFORM.                    " get_data
*---------------------------------------------------------------------*
*       FORM WRITE_DATA                                               *
*---------------------------------------------------------------------*
FORM write_data.
  LOOP AT itab_temp.
    WRITE:/ itab_temp.
  ENDLOOP.
ENDFORM.
阅读(4480) | 评论(0) | 转发(0) |
0

上一篇:SAP权限管理

下一篇:SCM PO Interface

给主人留下些什么吧!~~