Chinaunix首页 | 论坛 | 博客
  • 博客访问: 286399
  • 博文数量: 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-07-05 11:03:27

REPORT z_scm_po_2 .
 
INCLUDE z_scm_top.
 
TABLES: mara,a003,konp.
DATA: maxdatetime TYPE timeend ,
      per_date TYPE date,
      per_time TYPE time,
      new_date TYPE date,
      new_time TYPE time.
DATA: BEGIN OF itab_cdhdr OCCURS 0,
        objectid LIKE cdhdr-objectid,
        changenr LIKE cdhdr-changenr,
        udate    LIKE cdhdr-udate,
        utime    LIKE cdhdr-utime,
      END OF itab_cdhdr.
DATA: BEGIN OF itab_cdpos OCCURS 0,
        objectid   LIKE cdhdr-objectid,
        changenr   LIKE cdpos-changenr,
        udate      LIKE cdhdr-udate,
        utime      LIKE cdhdr-utime,
        tabname    LIKE cdpos-tabname,
        fname      LIKE cdpos-fname,
        value_new  LIKE cdpos-value_new,
      END OF itab_cdpos.
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,
        agency_flag(1) TYPE c,
      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,
          memo(132) TYPE c,
          retpo LIKE ekpo-retpo,
          add_date(8) TYPE c,
          modify_date(8) TYPE c,
          cancel_date(8) TYPE c,
          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,
          agency_flag(1) TYPE c,
          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,
          memo(132) TYPE c,
          retpo LIKE ekpo-retpo,
          add_date(8) TYPE c,
          modify_date(8) TYPE c,
          cancel_date(8) TYPE c,
          zzrepairpo LIKE ekko-zzrepairpo,
     END OF itab_temp.
DATA: BEGIN OF itab_release OCCURS 0,
        ebeln LIKE ekko-ebeln,
      END OF itab_release.
DATA: incom      TYPE meico,
      inpreissim TYPE meprck,
      expreissim TYPE mepro.
DATA: net_price LIKE ekpo-netpr.
DATA: knumh LIKE a017-knumh.
DATA: kbetr LIKE konp-kbetr.
DATA: total_price LIKE ekpo-netpr.
DATA:BEGIN OF itab_zpo2po_log OCCURS 0.
        INCLUDE STRUCTURE zpo2po_log.
DATA: END OF itab_zpo2po_log.
DATA: tline LIKE tline OCCURS 0 WITH HEADER LINE.
DATA: tebeln(70) TYPE c.
***订单取消通知
DATA: BEGIN OF itab_cancel OCCURS 0,
        lang TYPE c ,
        ebeln LIKE ekko-ebeln, "订单编号
        udate LIKE cdhdr-udate,"取消日期
        utime LIKE cdhdr-utime,"取消时间
      END OF itab_cancel.
***PO主档
DATA: BEGIN OF itab_ekko OCCURS 0,
        lang,
        werks LIKE ekpo-werks,
        bukrs LIKE ekko-bukrs,
        lifnr LIKE ekko-lifnr,
        bsart LIKE ekko-bsart,
        bebln LIKE ekko-ebeln,
        aedat LIKE ekko-aedat,
        eindt LIKE eket-eindt,
        time(6) TYPE c,
        eindt2 LIKE eket-eindt,
        ernam LIKE ekko-ernam,
        ernam2 LIKE ekko-ernam,
        waers LIKE ekko-waers,
        werks1 LIKE ekpo-werks, "LC
        ebeln1 LIKE ekko-ebeln, "LC
        sum,
        longtext,
        retpo LIKE ekpo-retpo,
        date1(8),
        date2(8),
        date3(8),
        zzrepairpo LIKE ekko-zzrepairpo,
      END OF itab_ekko.
***PO明细
DATA: BEGIN OF itab_ekpo OCCURS 0,
        lang TYPE c,
        ebeln LIKE ekpo-ebeln,
      END OF itab_ekpo.
***物流订单退货通知
DATA: BEGIN OF itab_logistic_rtv OCCURS 0,
        lang TYPE c,
        ebeln LIKE ekko-ebeln, "订单编号
        date  TYPE date,       "通知日期
      END OF itab_logistic_rtv.
***PO保存
DATA: BEGIN OF itab_po_save OCCURS 0.
        INCLUDE STRUCTURE zscm_po_send_his.
DATA: END OF itab_po_save.
PARAMETER: p_date TYPE syst-datum,
           p_time TYPE syst-uzeit.
INCLUDE z_scm_common_subroutine.
 
START-OF-SELECTION.
*  PERFORM get_number.
  IF p_date IS INITIAL .
    p_date = sy-datum.
  ENDIF.
  CONCATENATE sy-datum sy-uzeit INTO datetime.
  CONCATENATE workdir  '/OUT/BILL/BILL0100009999'
              datetime '.TXT' INTO dname.
  CONCATENATE 'BILL00009999' datetime INTO tarfilename.
  CONCATENATE tarfilename '.tar.gz' INTO gzfilename.
  PERFORM get_po.
  PERFORM save_po.
  PERFORM todataset.
  PERFORM zipanddel USING 'BILL'
                        tarfilename.
  PERFORM toftp USING 'SAP'
                      gzfilename.
 
*&---------------------------------------------------------------------*
*&      Form  get_po
*&---------------------------------------------------------------------*
FORM get_po.
  SELECT MAX( period ) FROM zscm_po_read INTO maxdatetime.
  per_date = maxdatetime+0(8).
  per_time = maxdatetime+8(6).
  new_time = sy-uzeit.
  new_time+4(2) = '00'.
  IF per_date = sy-datum.
    SELECT cdhdr~objectid cdhdr~changenr cdhdr~udate cdhdr~utime
    INTO CORRESPONDING FIELDS OF TABLE itab_cdhdr
    FROM cdhdr
    WHERE cdhdr~objectclas = 'EINKBELEG' AND
          cdhdr~udate = per_date AND
          cdhdr~utime > per_time AND
          cdhdr~utime <= new_time .
  ELSE.
    SELECT cdhdr~objectid cdhdr~changenr cdhdr~udate cdhdr~utime
    INTO CORRESPONDING FIELDS OF TABLE itab_cdhdr
    FROM cdhdr
    WHERE cdhdr~objectclas = 'EINKBELEG' AND
          cdhdr~udate  >=  per_date AND
          cdhdr~udate <=  p_date.
    DELETE itab_cdhdr WHERE udate = per_date AND utime <= per_time.
    DELETE itab_cdhdr WHERE udate = p_date AND utime > new_time.
  ENDIF.
  SELECT objectid changenr tabname fname value_new
  INTO CORRESPONDING FIELDS OF TABLE itab_cdpos
  FROM cdpos
  FOR ALL ENTRIES IN itab_cdhdr
  WHERE objectclas = 'EINKBELEG' AND
        objectid   = itab_cdhdr-objectid AND
        changenr   = itab_cdhdr-changenr.
  DELETE itab_cdpos WHERE tabname <> 'EKKO' OR fname <> 'FRGZU'.
  SORT itab_cdhdr BY objectid changenr udate utime .
  LOOP AT itab_cdpos.
    READ TABLE itab_cdhdr WITH KEY objectid = itab_cdpos-objectid
                                   changenr = itab_cdpos-changenr
                                                    BINARY SEARCH.
    itab_cdpos-udate = itab_cdhdr-udate.
    itab_cdpos-utime = itab_cdhdr-utime.
    MODIFY itab_cdpos.
  ENDLOOP.
  SORT itab_cdpos BY objectid udate utime DESCENDING.
  DELETE ADJACENT DUPLICATES FROM itab_cdpos COMPARING objectid.
  LOOP AT itab_cdpos.
    IF itab_cdpos-value_new = 'X'.
      itab_release-ebeln = itab_cdpos-objectid.
      APPEND itab_release.
    ELSE.
      itab_cancel-lang = '1'.
      itab_cancel-ebeln = itab_cdpos-objectid.
      itab_cancel-udate = itab_cdpos-udate.
      itab_cancel-utime = itab_cdpos-utime.
      APPEND itab_cancel.
    ENDIF.
  ENDLOOP.
  CHECK NOT itab_release[] IS INITIAL.
  CHECK NOT itab_cancel[] 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.
*代销标记为“K”表示代销,“T”表示经销
*并取长文本字段
  LOOP AT itab_temp.
    IF itab_temp-pstyp = '2' .
      itab_temp-agency_flag = 'K'.
    ELSE.
      itab_temp-agency_flag = 'T'.
    ENDIF.
    tebeln = itab_temp-ebeln.
    CALL FUNCTION 'READ_TEXT'
         EXPORTING
              id                      = 'F01'
              language                = sy-langu
              name                    = tebeln
              object                  = 'EKKO'
         TABLES
              lines                   = tline
         EXCEPTIONS
              id                      = 1
              language                = 2
              name                    = 3
              not_found               = 4
              object                  = 5
              reference_check         = 6
              wrong_access_to_archive = 7
              OTHERS                  = 8.
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    LOOP AT tline.
      CONCATENATE itab_temp-memo  tline-tdline INTO itab_temp-memo.
    ENDLOOP.
    MODIFY itab_temp.
    CLEAR tline.
    REFRESH tline.
  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.
  SORT itab_head BY ebeln.
  DELETE ADJACENT DUPLICATES FROM itab_head COMPARING ebeln .
ENDFORM.                    " get_po
 
*&---------------------------------------------------------------------*
*&      Form  save_po
*&---------------------------------------------------------------------*
FORM save_po.
  itab_po_save-udate = datetime+0(8).
  itab_po_save-utime = datetime+8(6).
  itab_po_save-kind = 'PO_R'.
  itab_po_save-zipfile = tarfilename.
  LOOP AT itab_release.
    itab_po_save-kindnumber = itab_release-ebeln.
    APPEND itab_po_save.
  ENDLOOP.
  itab_po_save-kind = 'PO_C'.
  itab_po_save-zipfile = tarfilename.
  LOOP AT itab_cancel.
    itab_po_save-kindnumber = itab_cancel-ebeln.
    APPEND itab_po_save.
  ENDLOOP.
*  DELETE FROM zscm_po_send_his WHERE udate = sy-datum.
  INSERT zscm_po_send_his FROM TABLE itab_po_save.
ENDFORM.                    " save_po
 
*---------------------------------------------------------------------*
*       FORM todataset                                                *
*---------------------------------------------------------------------*
*       Save to Application server                                    *
*---------------------------------------------------------------------*
FORM todataset.
  dname+number(2) = '01'.
  PERFORM itabtodataset TABLES itab_head[]     USING dname .
  dname+number(2) = '02'.
  PERFORM itabtodataset TABLES itab_item[]     USING dname .
  dname+number(2) = '03'.
  PERFORM itabtodataset TABLES itab_cancel[]     USING dname .
ENDFORM.
阅读(1800) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~