SAP Program:Approve PO

这是一个关于在SAP中使用T-code ZMMAP批准和发布采购文档的程序。程序涉及了状态处理、用户命令模块,并包括了数据表格、状态键、以及与释放选项相关的变量。此外,还包含了对价格变动的检查以及发送邮件附件到指定接收人的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

T-code: ZMMAP

 

Release (Approve) Purchasing Documents

 


PROCESS BEFORE OUTPUT.
  
MODULE status_0100.

*
PROCESS AFTER 
INPUT.
  
MODULE user_command_0100.

 

report zmm_rm06ef00 no standard page heading message-id me.
************************************************************************
*        Anzeigen Einkaufsbelege zur Belegnummer                       *
************************************************************************
* 125229, 10.11.199 MW : To calculate the correct 'open value'
*  change Standard date : 2012.9.17
*  greate date: 2012.9.17
* by greate : yayun
*----------------------------------------------------------------------*
*  Tabellen
*  Micah Qin     Jan 10 2013      Select Pur Group by User ID.
* M1  Jimmy         Mar 28 2013      SU3: M3 Approved send excel to G3
*----------------------------------------------------------------------*
include zmm_fm06lto1.
include zmm_fm06lcfr.
include zmm_selopt_cnt_call.

tables: t16fg, t16fs, t16fv, t16fe, rm06b, t160b,zekpo,mara,zbuyer.
data: begin of xekpo occurs 100.
        include structure ekpo.
data : eindt type eket-eindt.
*DATA: zdiff TYPE p DECIMALS 2,
*      zvmi TYPE c,
*      zitem(20) TYPE c. "若PO价大于last PO价,approve时必须要输入remark. (PO item -> item text)

data: end of xekpo.
*- Interne Tabelle der Zustände ---------------------------------------*
data: begin of zus occurs 10.
        include structure t16fv.
data: end of zus.
data: begin of zuskey,
         mandt like ekko-mandt,
         frggr like ekko-frggr,
         frgsx like ekko-frgsx,
      end of zuskey.
*****************************************************************************
types:begin of ts_ekko ,
          zcbox type c,
          ebeln like ekko-ebeln,
          bsart like ekko-bsart,
          lifnr like ekko-lifnr,
          name1 like lfa1-name1,     "Lfa1 ---   NAME1
          ekgrp like ekko-ekgrp,
          bedat like ekko-bedat,
          frggr like ekko-frggr,
          frgsx like ekko-frgsx,
          frgxt like t16ft-frgxt,"------------T16FT
          frgke like ekko-frgke,
*增加总金额
          zjine type decimals 4,
*ANZFM  “Release options
 "     zreje(10) TYPE c," Can be reject function and Reject Reason (Field 1) (PO header text). 拒绝描述
         zbuye(50type c,"Buyer can check the reject PO in the PO approve screen. Buyer
                        " Remark (Field 2) (PO header text).自己的描述
  end of ts_ekko.
types:begin of ts_ekpo,
        ebeln type ekko-ebeln,
        ebelp type ekpo-ebelp,
        ematn type ekpo-ematn,
        txz01 type ekpo-txz01,
        matkl type ekpo-matkl,
        werks type ekpo-werks,
        menge type ekpo-menge,
        meins type ekpo-meins,
        netpr type ekpo-netpr,
        waers type ekko-waers,"-----ekko
        peinh type ekpo-peinh,
        bprme type ekpo-bprme,
        zdiff type decimals 2,
*增加总价
        netwr type ekpo-netwr,
        zvmi type c,
        zitem(20type c, "若PO价大于last PO价,approve时必须要输入remark. (PO item -> item text)
  end of ts_ekpo.
*vmi
types:begin of ts_vmi,
  matnr like zmmt_info_rec-matnr,
  lifnr like zmmt_info_rec-lifnr,
  zzvmi like zmmt_info_rec-zzvmi,
  end of ts_vmi.

data: t_ekko type standard table of ztsekko with header line,
      t_ekpo type standard table of ztsekpo with header line,
      t_t16ft type standard table of t16ft with header line,
      t_lfa1 type standard table of lfa1 with header line,
      t_vmi  type standard table of ts_vmi  with header line.
*****************************************************************************
*add zekpo items data---------greate version number  v1 -----------save events.
data:t_zekpo type standard table of zekpo with header line,
     wa_zekpo type zekpo .
*Checking the PO price VS  last PO Price
data:l_ekpo  type standard table of ztsekpo with header line,
     lv_ekpo type standard table of ekpo with header line,
     lv_ekko type standard table of ekko with header line,
     l_ekko  type standard table of ekko with header line,
     t_ausp  type standard table of ausp with header line.
*** call alv
data: ls_fieldcat type slis_fieldcat_alv,
      e01_lt_fieldcat type slis_t_fieldcat_alv,
      g_tabname_header type slis_tabname,
      g_tabname_item   type slis_tabname.
data: gt_fieldcat type slis_t_fieldcat_alv,
      gs_layout   type slis_layout_alv,
      gs_keyinfo  type slis_keyinfo_alv,
      gt_sort     type slis_t_sortinfo_alv,
      gt_sp_group type slis_t_sp_group_alv,
      gt_events   type slis_t_event.

data: gt_list_top_of_page type slis_t_listheader.

constants:
           gc_formname_top_of_page type slis_formname value 'TOP_OF_PAGE'.
constants:
           user_command type slis_formname value 'USER_COMMAND'.
constants:
           set_pf_status type slis_formname value 'SET_PF_STATUS'.

data: g_repid like sy-repid.
data:       g_boxnam type slis_fieldname value  'BOX',
            g_expandname type slis_fieldname value  'EXPAND',
            p_f2code like sy-ucomm       value  '&ETA',
            p_lignam type slis_fieldname value  'LIGHTS',
            g_save(1type c,
*           g_default(1) type c,
            g_exit(1type c,
            gx_variant like disvariant,
            g_variant like disvariant.
**********************************************************************
*------- Hilfsfelder Berechtigungsprüfung ------------------
data:    xactvt like tact-actvt,       "Hilfsfeld Aktivität
         xactxt(10),                   "Hilfsfeld Aktivitätstext
         xobjekt(10),                  "Hilfsfeld Objekt
         xobjtxt(15),                  "Hilfsfeld Objekttext
         xfldtxt(15).                  "Hilfsfeld Feldtext

*M1 add
data: xls_content type solix_tab,
      xls_size    type so_obj_len.
constants: gc_crlf type value cl_bcs_convert=>gc_crlf. " ┐ New Line In XLS
data: begin of i_reclist occurs 0,
      receiver like somlreci1-receiver  ,
      end of i_reclist .
data: lv_subrc like sy-subrc.
data:it_zpoemail like standard table of zpoemail with header line .
*M1 End


*ENHANCEMENT-POINT RM06EF00_02 SPOTS ES_RM06EF00 STATIC .

*----------------------------------------------------------------------*
*  Parameter und Select-Options                                        *
*----------------------------------------------------------------------*
parameters:     p_frgco like t16fc-frgco obligatory memory id fab.

*PARAMETER :     P_EKGRP LIKE EKKO-EKGRP.   "add Jimmy  --- Del by Micah
select-options: s_frggr for ekko-frggr no-display,
                s_ekgrp for ekko-ekgrp.  "Jimmy add no-display --- Reuse by Micah
parameters:     p_frgse like rm06a-p_frgse default 'X' no-display,
                p_frgrs like rm06a-p_frgrs no-display,
                p_frgvo like rm06a-p_frgvo default 'X' no-display,
                p_mitpos like rm06a-p_mitpos  default 'X' no-display.
"    listu LIKE t160o-listu.
select-options: s_bstyp for ekko-bstyp,
                s_ekorg for ekko-ekorg ,
                s_ebeln for ekko-ebeln matchcode object mekk,
*                                      MEMORY ID BES,
                s_bsart for ekko-bsart,

                s_lifnr for ekko-lifnr matchcode object kred,
                s_reswk for ekko-reswk no-display,
                s_bedat for ekko-bedat,
                s_procst for ekko-procstat no-display.      "676504
*----------------------------------------------------------------------*
*  Hilfsfelder                                                         *
*----------------------------------------------------------------------*
include fm06lcek.
include zmm_events.
include zmm_from.
**********************************************************************
data: xfrg1 like ekko-frgzu,
      xfrg2 like ekko-frgzu.
data: xselkb like ekko-bstyp,
      xselkk like ekko-bstyp,
      xselkl like ekko-bstyp,
      xselka like ekko-bstyp.
field-symbols: <f1>.
data: hfdpos like sy-fdpos.
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
*  Intitialisierung                                                    *
*----------------------------------------------------------------------*
initialization.
  g_repid sy-repid.
  g_tabname_header 'T_EKKO'.
  g_tabname_item   'T_EKPO'.
* define keyinfo
  clear gs_keyinfo.
  gs_keyinfo-header01 'EBELN'.
  gs_keyinfo-item01   'EBELN'.

  perform e01_fieldcat_init using gt_fieldcat[].
  perform e03_eventtab_build using gt_events[].
  perform e06_t_sort_build   using gt_sort[].
  perform e07_sp_group_build using gt_sp_group[].
  perform e05_layout_build using gs_layout.     "wg. Parameters

  g_save 'A'.

  perform variant_init.
* Get default variant
  gx_variant g_variant.
  "* Get default variant
  "  gx_variant = g_variant.
  "  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
  "    EXPORTING
  "      i_save     = g_save
  "    CHANGING
  "      cs_variant = gx_variant
  "    EXCEPTIONS
  "      not_found  = 2.
  "  IF sy-subrc = 0.
  "    p_vari = gx_variant-variant.
  "  ENDIF.
  "**************************************************************************
*  PERFORM anforderungsbild(sapfm06l) USING xselkb xselkk
*                                           xselkl xselka.
  "listu = t160b-listu.
  s_bstyp-sign 'I'.
  s_bstyp-option 'EQ'.
  if xselkb ne space.
    s_bstyp-low 'F'.
    append s_bstyp.
  endif.
  if xselkk ne space.
    s_bstyp-low 'K'.
    append s_bstyp.
  endif.
  if xselkl ne space.
    s_bstyp-low 'L'.
    append s_bstyp.
  endif.
  if xselka ne space.
    s_bstyp-low 'A'.
    append s_bstyp.
  endif.
  if sy-calld ne space.                                     "330331
    read table s_bstyp index 1.
    case s_bstyp-low.
      when 'F'.
        get parameter id 'BES' field s_ebeln-low.
      when 'K'.
        get parameter id 'CTR' field s_ebeln-low.
        if s_ebeln-low is initial.
          get parameter id 'VRT' field s_ebeln-low.
        endif.
      when 'L'.
        get parameter id 'SAG' field s_ebeln-low.
        if s_ebeln-low is initial.
          get parameter id 'VRT' field s_ebeln-low.
        endif.
      when 'A'.
        get parameter id 'ANF' field s_ebeln-low.
    endcase.
    if not s_ebeln-low is initial.
      s_ebeln-sign 'I'.
      s_ebeln-option 'EQ'.
      append s_ebeln.
    endif.
  endif.                                                    "330331
  get parameter id 'FAB' field p_frgco.
* release just possible for one of the following status (same as ME29N):
  s_procst-sign 'I'.                                      "707850
  s_procst-option 'EQ'.                                   "707850
  s_procst-low space.                                     "707850
  append s_procst.                                          "707850
  s_procst-low '02'.                                      "707850
  append s_procst.                                          "707850
  s_procst-low '03'.                                      "707850
  append s_procst.                                          "707850
  s_procst-low '05'.                                      "707850
  append s_procst.                                          "707850


*----------------------------------------------------------------------*
*  Selektionsbild                                                      *
*----------------------------------------------------------------------*
*AT SELECTION-SCREEN ON listu.
*  PERFORM listumfang(sapfm06l) USING listu.  "change data 选择模式

at selection-screen on value-request for p_frgco.
  call function 'HELP_VALUES_FRGAB'
    exporting
      i_frgot '2'
    importing
      e_frgab p_frgco
    exceptions
      others  1.

at selection-screen.

  call function 'ME_REL_CHECK_MANY'
    exporting
      i_frgot '2'
      i_frgco p_frgco
    tables
      t_frggr s_frggr
      t_t16fv zus.

*----------------------------------------------------------------------*
*  Beginn der Selektion                                                *
*----------------------------------------------------------------------*
start-of-selection.
  "Add Check by Jimmy
*  refresh :S_EKGRP.
*  IF P_EKGRP IS NOT INITIAL.
*    S_EKGRP-SIGN = 'I'.
*    S_EKGRP-OPTION = 'EQ'.
*    S_EKGRP-LOW = P_EKGRP.
*    APPEND S_EKGRP.
*  ENDIF.
  if p_frgco+0(1<> 'B'.
*    SELECT * FROM  ZBUYER
*        WHERE ZUSER = SY-UNAME
*        AND ZRGCO = P_FRGCO
*        AND ZPGRP IN S_EKGRP.
*    ENDSELECT.
*  ELSE.
    select from  zbuyer
        where zuser sy-uname
        and zrgco p_frgco.
    endselect.
  endif.
  if sy-subrc ne 0.
    message i000(oowith 'You have not authority for this Release Code.'.
    exit.
  endif.
  "  Add End

  call function 'SAPGUI_PROGRESS_INDICATOR'
    exporting
      percentage 1
      text       'Data processing, please wait ...'.

  perform get_data.
  if not xekko[] is initial and xekpo[] is not initial.
    perform last_po_data.
    perform call_alv.
  else.
    message i000(oowith 'No suitable purchasing documents found'.
  endif.

at user-command.
  case sy-ucomm.
    when 'BACK' or 'CANC' or 'EXIT'.
      leave to screen 0.
  endcase.

end-of-selection.

*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form get_data.
*- Lesen Belegköpfe --------------------------------------------------*

  if p_frgco+0(1'B'.
    select from ekko inner join zbuyer on ekko~ekgrp zbuyer~zpgrp        "Add by Micah - 01/10/2013
        into corresponding fields of table xekko
                    for all entries in zus
                       where frgrl eq 'X'
                         and frggr eq zus-frggr
                         and frgsx eq zus-frgsx
                         and ebeln in s_ebeln
                         and bstyp in s_bstyp
                         and ekorg in s_ekorg
                         and lifnr in s_lifnr
                         and reswk in s_reswk
                         and bedat in s_bedat
                         and bsart in s_bsart
                         and ekgrp in s_ekgrp
                         and loekz eq space
                         and procstat in s_procst         "707850
                         or procstat is null )              "707850
                         and zbuyer~zuser sy-uname          "Add by Micah - 01/10/2013
                         and zbuyer~zrgco p_frgco.          "Add by Micah - 01/10/2013

    if p_frgrs ne space.
      select from ekko inner join zbuyer on ekko~ekgrp zbuyer~zpgrp        "Add by Micah - 01/10/2013
         into corresponding fields of table xekko
                    for all entries in zus
                         where frgrl eq space
                           and frggr eq zus-frggr
                           and frgsx eq zus-frgsx
                           and ebeln in s_ebeln
                           and bstyp in s_bstyp
                           and ekorg in s_ekorg
                           and lifnr in s_lifnr
                           and reswk in s_reswk
                           and bedat in s_bedat
                           and bsart in s_bsart
                           and ekgrp in s_ekgrp
                           and loekz eq space
                           and procstat in s_procst       "707850
                           or procstat is null )            "707850
                           and zbuyer~zuser sy-uname          "Add by Micah - 01/10/2013
                           and zbuyer~zrgco p_frgco.          "Add by Micah - 01/10/2013

    endif.
  else.
    select from ekko into corresponding fields of table xekko
                 for all entries in zus
                    where frgrl eq 'X'
                      and frggr eq zus-frggr
                      and frgsx eq zus-frgsx
                      and ebeln in s_ebeln
                      and bstyp in s_bstyp
                      and ekorg in s_ekorg
                      and lifnr in s_lifnr
                      and reswk in s_reswk
                      and bedat in s_bedat
                      and bsart in s_bsart
                      and ekgrp in s_ekgrp
                      and loekz eq space
                      and procstat in s_procst            "707850
                      or procstat is null ).                "707850

    if p_frgrs ne space.
      select from ekko into corresponding fields of table xekko
                    for all entries in zus
                         where frgrl eq space
                           and frggr eq zus-frggr
                           and frgsx eq zus-frgsx
                           and ebeln in s_ebeln
                           and bstyp in s_bstyp
                           and ekorg in s_ekorg
                           and lifnr in s_lifnr
                           and reswk in s_reswk
                           and bedat in s_bedat
                           and bsart in s_bsart
                           and ekgrp in s_ekgrp
                           and loekz eq space
                           and procstat in s_procst       "707850
                           or procstat is null ).           "707850
    endif.
  endif.
  sort xekko.
*- Check for EhP4-Switch and Central Contract
  if cl_ops_switch_check=>mm_sfws_p2pse'X'.
    delete xekko where bstyp eq 'K'
                 and   statu eq 'K'.
  endif.
*- Prüfen Freigabevoraussetzungen ------------------------------------*
  loop at xekko.
    move-corresponding xekko to zuskey.
    read table zus with key zuskey ."BINARY SEARCH.
    check sy-subrc eq 0.
    xfrg1 zus+9(8).
    xfrg2 xekko-frgzu.
    translate xfrg2 using 'X  +'.
    overlay xfrg1 with xfrg2 only '+'.
    search xfrg1 for 'X'.
*---- Keine Freigabezuständigkeit -------------------------------------*
    if sy-subrc ne 0.
      delete xekko.
      continue.
    else.
*---- Freigabestelle merken -------------------------------------------*
      hfdpos sy-fdpos.
      assign xfrg2+sy-fdpos(1to <f1>.
*---- Freigabe bereits erfolgt ----------------------------------------*
      if p_frgrs eq space and
         <f1> eq space.
        delete xekko.
        continue.
      else.
*---- Freigabe noch nicht erfolgt -------------------------------------*
        if p_frgse eq space and
           <f1> ne space.
          delete xekko.
          continue.
        else.
*---- Freigabevoraussetzung fehlt -------------------------------------*
          if xfrg1 ca '+' and
             p_frgvo ne space.
            delete xekko.
            continue.
          else.
            ekko xekko.
            perform frg_fekko_aufbauen(sapfm06lusing hfdpos.
          endif.
        endif.
      endif.
    endif.
*- Berechtigungsprüfung abhängig vom Bestelltyp -----------------------*
    case xekko-bstyp.
      when 'F'.  xobjekt 'M_BEST_'.
      when 'A'.  xobjekt 'M_ANFR_'.
      when 'L'.  xobjekt 'M_LPET_'.
      when 'K'.  xobjekt 'M_RAHM_'.
    endcase.
*- Einkäufergruppe ----------------------------------------------------*
    if xekko-ekgrp ne space.
      xobjekt+7(3'EKG'.
      xfldtxt text-512.
      authority-check object xobjekt
           id 'ACTVT' field '02'
           id 'EKGRP' field xekko-ekgrp.
      if sy-subrc ne space.
        delete xekko.
        continue.
      endif.
    endif.
*- Belegart -------------------------------------
    if xekko-bsart ne space.
      xobjekt+7(3'BSA'.
      xfldtxt text-510.
      authority-check object xobjekt
      id 'ACTVT' field '02'
      id 'BSART' field xekko-bsart.
      if sy-subrc ne space.
        delete xekko.
        continue.
      endif.
    endif.
*- Einkaufsorganisation -------------------------
    if xekko-ekorg ne space.
      xobjekt+7(3'EKO'.
      xfldtxt text-511.
      authority-check object xobjekt
      id 'ACTVT' field '02'
      id 'EKORG' field xekko-ekorg.
      if sy-subrc ne space.
        delete xekko.
        continue.
      endif.
    endif.
  endloop.
  sort xekko.
*************************************************************
  if not xekko[] is initial.
    select from ekpo join eket on ekpo~ebeln eket~ebeln
      and ekpo~ebelp eket~ebelp
      appending corresponding fields of table xekpo
      for all entries in xekko
      where ekpo~ebeln eq xekko-ebeln.
  endif.
endform.                    "get_data
*&---------------------------------------------------------------------*
*&      Form  last_po_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form last_po_data.
**********************************************************************
  data:p_netpr(16type decimals 4,
       p_zdiff(16type decimals 4,
       l_netpr(16type decimals 4 ,
       k1_netpr(16type decimals 4,
       k2_netpr(16type decimals 4,
       lv_netpr(16type decimals 4,
       lv_netpr1(16type decimals 4.
**********************************************************************
  if  not xekko[] is initial.
    select into corresponding fields of table t_lfa1
        from lfa1
*      FOR ALL ENTRIES IN XEKKO
*      WHERE LIFNR = XEKKO-LIFNR.
      .
    sort t_lfa1 by lifnr.
    select into corresponding fields of table t_t16ft
       from t16ft
      for all entries in xekko
      where spras 'E'
        and frggr xekko-frggr
        and frgsx xekko-frgsx.
    loop at xekko.
      move-corresponding xekko to t_ekko.
      read table t_lfa1 with key lifnr xekko-lifnr binary search.
      if sy-subrc 0.
        t_ekko-name1 t_lfa1-name1.
      endif.

      read table t_t16ft with key  frggr xekko-frggr frgsx xekko-frgsx.
      if sy-subrc 0.
        t_ekko-frgxt t_t16ft-frgxt.
      endif.
      append t_ekko.
      clear:t_ekko,xekko.
    endloop.
  endif.
*Checking the PO price VS  last PO Price
  if not xekpo[] is initial.
*  added by rudyzhang
    data : lt_ekpo like table of xekpo.
    lt_ekpo xekpo[].
    sort lt_ekpo by ematn.
    delete adjacent duplicates from lt_ekpo comparing ematn.
*  added end

    select into corresponding fields of table lv_ekpo
      from ekpo
      for all entries in lt_ekpo
      where ematn lt_ekpo-ematn
       and  loekz ''.  "Deleted indicator - Modified at 2013/2/27
    clear xekpo.
*delete load po data
    sort lv_ekpo by ematn ascending aedat descending .      "- added by rudyzhang
*    delete adjacent duplicates from LV_EKPO comparing EMATN."- added by rudyzhang

*    LOOP AT LV_EKPO .
*      read table XEKPO transporting no fields with key EBELN = LV_EKPO-EBELN.
*      if SY-SUBRC = 0 .
*        delete LV_EKPO where EBELN = LV_EKPO-EBELN.
*        continue.
*      else.
*      MOVE-CORRESPONDING LV_EKPO TO L_EKPO.             "- added by rudyzhang
*      APPEND L_EKPO.                                    "- added by rudyzhang
*      endif.
*    ENDLOOP.

*sort lv_ekpo
*    SORT LV_EKPO BY EMATN ASCENDING AEDAT DESCENDING .
*    DELETE ADJACENT DUPLICATES FROM LV_EKPO COMPARING EMATN.
    if  not lv_ekpo[] is initial.
*      LOOP AT LV_EKPO.                                 "- commented by rudyzhang
*        MOVE-CORRESPONDING LV_EKPO TO L_EKPO.
*        APPEND L_EKPO.
*      ENDLOOP.                                         "- commented by rudyzhang

*     added by rudyzhang
      data : lt_ekpo1 like table of lv_ekpo.
      lt_ekpo1 lv_ekpo[].
      sort lt_ekpo1 by ebeln.
      delete adjacent duplicates from lt_ekpo1 comparing ebeln.
*     added end

      select into corresponding fields of table lv_ekko
        from ekko
        for all entries in lt_ekpo1
        where ebeln lt_ekpo1-ebeln.

*      LOOP AT L_EKPO.
*        READ TABLE LV_EKKO WITH KEY EBELN = L_EKPO-EBELN.
*        IF SY-SUBRC = 0.
*          L_EKPO-WAERS = LV_EKKO-WAERS.
*          MODIFY L_EKPO TRANSPORTING WAERS.
*        ENDIF.
*      ENDLOOP.

*      LOOP AT LV_EKKO.
*        READ TABLE L_EKPO WITH KEY EBELN = LV_EKKO-EBELN.
*        IF SY-SUBRC = 0.
*          L_EKPO-WAERS = LV_EKKO-WAERS.
*          MODIFY L_EKPO TRANSPORTING WAERS WHERE EBELN = LV_EKKO-EBELN.
*        ENDIF.
*      ENDLOOP.

      clear:lv_ekpo,xekpo,l_ekpo.
    endif.
*vmi flag
    select
         matnr
         lifnr
         zzvmi
      into corresponding fields of table t_vmi
      from zmmt_info_rec
      for all entries in xekpo
      where matnr xekpo-matnr
        and lifnr xekko-lifnr.
****************************************************************
*get version-------------------
*    LOOP AT XEKPO.
*      SELECT * INTO CORRESPONDING FIELDS OF WA_ZEKPO
*        FROM ZEKPO
*        UP TO 1 ROWS
*      "  FOR ALL ENTRIES IN xekpo
*        WHERE EBELN = XEKPO-EBELN
*          AND EBELP = XEKPO-EBELP
*        ORDER BY EBELN EBELP ZVSIN DESCENDING.
*        APPEND WA_ZEKPO TO T_ZEKPO.
*        CLEAR: WA_ZEKPO,T_ZEKPO.
*      ENDSELECT.
*    ENDLOOP.

*   Modified by rudyzhang
    select distinct *
      from zekpo
      into corresponding fields of table t_zekpo
      for all entries in xekpo
      where ebeln xekpo-ebeln
      and   ebelp xekpo-ebelp.

    sort t_zekpo by ebeln ebelp zvsin descending.
    delete adjacent duplicates from t_zekpo comparing ebeln ebelp.

*  Modified end
*no check--------------------------
* If the vendor is customer or broker(炒料)vendor, will no check the price, sample PO zero price no check.
* (In the Vendor classification, the class type ‘010’, class ‘Z_VENDOR_FIELDS’,
*Characteristic ‘Supplier type’, the value ‘03’ for customer, the value ‘05’ for broker(炒料)).
*就不需要chack PO
*If the price is ‘0’, then the PO is sample PO, no need checking the price. 就不需要 chack PO
**********************************************************************
*check
*5. If the currency is same, will comparison the price with this currency.
*6. If the currency is not same, will need convert the price to local currency (HKD) for comparison.
*data item
    loop at xekpo.
      move-corresponding xekpo to t_ekpo.
      read table xekko with key ebeln xekpo-ebeln.
      if sy-subrc 0.
        t_ekpo-waers xekko-waers.
      endif.
*NO CHECK
      select into corresponding fields of table t_ausp
        from ausp as a
        join cabn as on a~atinn b~atinn
                      and a~adzhl b~adzhl
        where objek xekko-lifnr
          and a~atinn 'ZXK01_05'
          and a~klart '010'.
      if not t_ausp[] is initial.
        read table t_ausp with key  objek xekko-lifnr.
        if sy-subrc 0.
          if t_ausp-atwrt '03' or t_ausp-atwrt '05'.
            t_ekpo-zdiff 0.
          endif.
        endif.
      endif.
*no check
      if t_ekpo-zdiff is initial.
        if t_ekpo-netpr  0.
          t_ekpo-znetp 0.
          t_ekpo-zdiff 0.
        else.

          loop at lv_ekpo where ematn xekpo-ematn and aedat < xekko-aedat."get the last PO infor

            clear l_ekpo.
            move-corresponding lv_ekpo to l_ekpo.
            read table lv_ekko with key ebeln lv_ekpo-ebeln.
            if sy-subrc 0.
              l_ekpo-waers lv_ekko-waers.
            endif.

            if t_ekpo-waers l_ekpo-waers .
              perform currence_convert using t_ekpo-waers changing t_ekpo-netpr .
              perform currence_convert using l_ekpo-waers changing l_ekpo-netpr .
              "  IF t_ekpo-netpr = l_ekpo-netpr AND t_ekpo-peinh = l_ekpo-peinh.
              if t_ekpo-peinh 0.
                t_ekpo-peinh 1.
              endif.
              if l_ekpo-peinh 0.
                l_ekpo-peinh 1.
              endif.
              k1_netpr t_ekpo-netpr / t_ekpo-peinh."
              k2_netpr l_ekpo-netpr / l_ekpo-peinh."
*                t_ekpo-netpr = t_ekpo-netpr / t_ekpo-peinh.
*                l_ekpo-netpr = l_ekpo-netpr / l_ekpo-peinh.
              "  ENDIF.
              t_ekpo-znetp k1_netpr.
            else.
              call function 'CONVERT_TO_LOCAL_CURRENCY'
                exporting
                  date             xekko-bedat "Purchasing Document Date
                  foreign_amount   t_ekpo-netpr
                  foreign_currency t_ekpo-waers
                  local_currency   'HKD'
                  type_of_rate     'M'
                importing
                  local_amount     k1_netpr
                exceptions
                  no_rate_found    1
                  others           2.
*GET L_EKPO ----------L_EKKO DATA
              select into corresponding fields of table l_ekko
                from ekko
                where ebeln l_ekpo-ebeln.
              read table l_ekko index 1.
              call function 'CONVERT_TO_LOCAL_CURRENCY'
                exporting
                  date             l_ekko-bedat "Purchasing Document Date
                  foreign_amount   l_ekpo-netpr
                  foreign_currency l_ekpo-waers
                  local_currency   'HKD'
                  type_of_rate     'M'
                importing
                  local_amount     k2_netpr
                exceptions
                  no_rate_found    1
                  others           2.

              perform currence_convert using t_ekpo-waers changing t_ekpo-netpr .
              perform currence_convert using l_ekpo-waers changing l_ekpo-netpr .

              if t_ekpo-peinh 0.
                t_ekpo-peinh 1.
              endif.
              if l_ekpo-peinh 0.
                l_ekpo-peinh 1.
              endif.
              k1_netpr k1_netpr / t_ekpo-peinh." HKD Price
              k2_netpr k2_netpr / l_ekpo-peinh." HKD Price - Last PO

              t_ekpo-znetp t_ekpo-netpr / t_ekpo-peinh. " PO Price Order currcency
            endif.

            if not k1_netpr is initial and k2_netpr is not initial.
*              T_EKPO-ZNETP = K1_NETPR.
              l_netpr =  k2_netpr.
              p_netpr  k1_netpr k2_netpr.
            endif.
*
            if l_netpr > 0 .
              if p_netpr >= 0 .
                p_zdiff p_netpr * 100 / l_netpr.
                t_ekpo-zdiff ceilp_zdiff ).
              else.
                p_netpr =  absp_netpr ).
                p_zdiff p_netpr * 100 / l_netpr.
                t_ekpo-zdiff ceilp_zdiff * -) .
              endif.
            else.
              t_ekpo-zdiff 0.
              t_ekpo-znetp k1_netpr.
            endif.
            clear:l_netpr,p_netpr,p_zdiff,l_ekko,l_ekko[],l_ekpo,k1_netpr,k2_netpr.

            exit.
          endloop.
          if sy-subrc <> 0.
            "  判断没有的时候要重新计算
            perform currence_convert using t_ekpo-waers changing t_ekpo-netpr .
*          PERFORM currence_convert USING l_ekpo-waers CHANGING l_ekpo-netpr .
            if t_ekpo-peinh 0.
              t_ekpo-peinh 1.
            endif.
*            IF L_EKPO-PEINH = 0.
*              L_EKPO-PEINH = 1.
*            ENDIF.
            k1_netpr t_ekpo-netpr / t_ekpo-peinh."
*            K2_NETPR = L_EKPO-NETPR / L_EKPO-PEINH."
*            IF NOT K1_NETPR IS INITIAL AND K2_NETPR IS NOT INITIAL.
*              T_EKPO-ZNETP = K1_NETPR.
*              L_NETPR =  K2_NETPR.
*              P_NETPR  = K1_NETPR - K2_NETPR.
*            ENDIF.
**
*            IF L_NETPR > 0 .
*              IF P_NETPR >= 0 .
*                P_ZDIFF = P_NETPR * 100 / L_NETPR.
*                T_EKPO-ZDIFF = CEIL( P_ZDIFF ).
*              ELSE.
*                P_NETPR =  ABS( P_NETPR ).
*                P_ZDIFF = P_NETPR * 100 / L_NETPR.
*                T_EKPO-ZDIFF = CEIL( P_ZDIFF * -1 ) .
*              ENDIF.
*            ELSE.
            t_ekpo-zdiff 0.
            t_ekpo-znetp k1_netpr.
*            ENDIF.
            clear:l_netpr,p_netpr,p_zdiff,l_ekko,l_ekko[],k1_netpr.
          endif.
******************************************************************
*. Checking the PO price VS  last PO Price. (显示差额百分比). = (PO price  - Last PO price) / Last PO price *%.
*          read table L_EKPO with key EMATN = XEKPO-EMATN.
*          if SY-SUBRC = 0.
*            if T_EKPO-WAERS = L_EKPO-WAERS .
*              perform CURRENCE_CONVERT using T_EKPO-WAERS changing T_EKPO-NETPR .
*              perform CURRENCE_CONVERT using L_EKPO-WAERS changing L_EKPO-NETPR .
*              "  IF t_ekpo-netpr = l_ekpo-netpr AND t_ekpo-peinh = l_ekpo-peinh.
*              if T_EKPO-PEINH = 0.
*                T_EKPO-PEINH = 1.
*              endif.
*              if L_EKPO-PEINH = 0.
*                L_EKPO-PEINH = 1.
*              endif.
*              K1_NETPR = T_EKPO-NETPR / T_EKPO-PEINH."
*              K2_NETPR = L_EKPO-NETPR / L_EKPO-PEINH."
**                t_ekpo-netpr = t_ekpo-netpr / t_ekpo-peinh.
**                l_ekpo-netpr = l_ekpo-netpr / l_ekpo-peinh.
*              "  ENDIF.
*              T_EKPO-ZNETP = K1_NETPR.
*            else.
*              call function 'CONVERT_TO_LOCAL_CURRENCY'
*                exporting
*                  DATE             = XEKKO-BEDAT "Purchasing Document Date
*                  FOREIGN_AMOUNT   = T_EKPO-NETPR
*                  FOREIGN_CURRENCY = T_EKPO-WAERS
*                  LOCAL_CURRENCY   = 'HKD'
*                  TYPE_OF_RATE     = 'M'
*                importing
*                  LOCAL_AMOUNT     = K1_NETPR
*                exceptions
*                  NO_RATE_FOUND    = 1
*                  others           = 2.
**GET L_EKPO ----------L_EKKO DATA
*              select * into corresponding fields of table L_EKKO
*                from EKKO
*                where EBELN = L_EKPO-EBELN.
*              read table L_EKKO index 1.
*              call function 'CONVERT_TO_LOCAL_CURRENCY'
*                exporting
*                  DATE             = L_EKKO-BEDAT "Purchasing Document Date
*                  FOREIGN_AMOUNT   = L_EKPO-NETPR
*                  FOREIGN_CURRENCY = L_EKPO-WAERS
*                  LOCAL_CURRENCY   = 'HKD'
*                  TYPE_OF_RATE     = 'M'
*                importing
*                  LOCAL_AMOUNT     = K2_NETPR
*                exceptions
*                  NO_RATE_FOUND    = 1
*                  others           = 2.
*
*              perform CURRENCE_CONVERT using T_EKPO-WAERS changing T_EKPO-NETPR .
*              perform CURRENCE_CONVERT using L_EKPO-WAERS changing L_EKPO-NETPR .
*
*              if T_EKPO-PEINH = 0.
*                T_EKPO-PEINH = 1.
*              endif.
*              if L_EKPO-PEINH = 0.
*                L_EKPO-PEINH = 1.
*              endif.
*              K1_NETPR = K1_NETPR / T_EKPO-PEINH." HKD Price
*              K2_NETPR = K2_NETPR / L_EKPO-PEINH." HKD Price - Last PO
*
*              T_EKPO-ZNETP = T_EKPO-NETPR / T_EKPO-PEINH. " PO Price Order currcency
*            endif.
*
*            if not K1_NETPR is initial and K2_NETPR is not initial.
**              T_EKPO-ZNETP = K1_NETPR.
*              L_NETPR =  K2_NETPR.
*              P_NETPR  = K1_NETPR - K2_NETPR.
*            endif.
**
*            if L_NETPR > 0 .
*              if P_NETPR >= 0 .
*                P_ZDIFF = P_NETPR * 100 / L_NETPR.
*                T_EKPO-ZDIFF = CEIL( P_ZDIFF ).
*              else.
*                P_NETPR =  ABS( P_NETPR ).
*                P_ZDIFF = P_NETPR * 100 / L_NETPR.
*                T_EKPO-ZDIFF = CEIL( P_ZDIFF * -1 ) .
*              endif.
*            else.
*              T_EKPO-ZDIFF = 0.
*              T_EKPO-ZNETP = K1_NETPR.
*            endif.
*            clear:L_NETPR,P_NETPR,P_ZDIFF,L_EKKO,L_EKKO[],L_EKPO,K1_NETPR,K2_NETPR.
*
*          else.
**判断没有的时候要重新计算
*            perform CURRENCE_CONVERT using T_EKPO-WAERS changing T_EKPO-NETPR .
**          PERFORM currence_convert USING l_ekpo-waers CHANGING l_ekpo-netpr .
*            if T_EKPO-PEINH = 0.
*              T_EKPO-PEINH = 1.
*            endif.
**            IF L_EKPO-PEINH = 0.
**              L_EKPO-PEINH = 1.
**            ENDIF.
*            K1_NETPR = T_EKPO-NETPR / T_EKPO-PEINH."
**            K2_NETPR = L_EKPO-NETPR / L_EKPO-PEINH."
**            IF NOT K1_NETPR IS INITIAL AND K2_NETPR IS NOT INITIAL.
**              T_EKPO-ZNETP = K1_NETPR.
**              L_NETPR =  K2_NETPR.
**              P_NETPR  = K1_NETPR - K2_NETPR.
**            ENDIF.
***
**            IF L_NETPR > 0 .
**              IF P_NETPR >= 0 .
**                P_ZDIFF = P_NETPR * 100 / L_NETPR.
**                T_EKPO-ZDIFF = CEIL( P_ZDIFF ).
**              ELSE.
**                P_NETPR =  ABS( P_NETPR ).
**                P_ZDIFF = P_NETPR * 100 / L_NETPR.
**                T_EKPO-ZDIFF = CEIL( P_ZDIFF * -1 ) .
**              ENDIF.
**            ELSE.
*            T_EKPO-ZDIFF = 0.
*            T_EKPO-ZNETP = K1_NETPR.
**            ENDIF.
*            clear:L_NETPR,P_NETPR,P_ZDIFF,L_EKKO,L_EKKO[],K1_NETPR.
*          endif.
        endif.
      endif.
*******************************************************************
*vmi flag
      read table t_vmi with key matnr xekpo-matnr lifnr xekko-lifnr.
      if sy-subrc 0.
        t_ekpo-zvmi t_vmi-zzvmi.
      endif.
* convert price amount.
*      PERFORM currence_convert USING t_ekpo-waers CHANGING t_ekpo-ZNETP.
*      PERFORM currence_convert USING t_ekpo-waers CHANGING t_ekpo-zdiff.
      perform currence_convert using t_ekpo-waers changing t_ekpo-netwr.

      if xekpo-loekz 'L'.
        t_ekpo-menge 0.
        t_ekpo-netwr 0.
      endif.
      append t_ekpo.
      clear: xekpo,t_ekpo,l_ekpo.
    endloop.
*version
    if not t_zekpo[] is initial.
      loop at t_ekko.
        read table t_zekpo with key ebeln t_ekko-ebeln.
        if sy-subrc 0.
          t_ekko-zvsin t_zekpo-zvsin.
          modify t_ekko transporting zvsin.
        endif.
      endloop.
    endif .
    sort t_ekpo by ebeln ascending ebelp descending.
  endif.
  if not t_ekpo[] is initial .
* get lfa1
*    SELECT DISTINCT *
*      INTO CORRESPONDING FIELDS OF TABLE T_LFA1
*      FROM LFA1.
*
*    SORT T_LFA1 BY LIFNR.
    if not t_lfa1[] is initial.
      loop at t_ekpo where name1 is initial.
        read table t_lfa1 with key lifnr t_ekpo-mfrnr binary search.
        if  sy-subrc 0.
          t_ekpo-name1 t_lfa1-name1.
          modify t_ekpo transporting name1 where mfrnr t_ekpo-mfrnr.
        endif.
      endloop.
      clear t_lfa1[].
    endif.
  endif.
**************************************************************
*control fieldcat display status
  data:l_header type standard table of thead with header line,
       l_tdname type tdobname,
       l_lines_1  type standard table of tline with header line,
       l_lines_2  type standard table of tline with header line,
       l_lines_3  type standard table of tline with header line,
       l_lines_4  type standard table of tline with header line.
*control fieldcat display status
*buyer
* get text1
  loop at t_ekko .
    l_tdname t_ekko-ebeln.
    call function 'READ_TEXT'
      exporting
        id                      'F01'
        language                sy-langu
        name                    l_tdname
        object                  'EKKO'
      tables
        lines                   l_lines_1
      exceptions
        id                      1
        language                2
        name                    3
        not_found               4
        object                  5
        reference_check         6
        wrong_access_to_archive 7
        others                  8.
* get text2
    call function 'READ_TEXT'
      exporting
        id                      'F02'
        language                sy-langu
        name                    l_tdname
        object                  'EKKO'
      tables
        lines                   l_lines_2
      exceptions
        id                      1
        language                2
        name                    3
        not_found               4
        object                  5
        reference_check         6
        wrong_access_to_archive 7
        others                  8.
* get text 3
    call function 'READ_TEXT'
      exporting
        id                      'F03'
        language                sy-langu
        name                    l_tdname
        object                  'EKKO'
      tables
        lines                   l_lines_3
      exceptions
        id                      1
        language                2
        name                    3
        not_found               4
        object                  5
        reference_check         6
        wrong_access_to_archive 7
        others                  8.
*get text 4.
    call function 'READ_TEXT'
      exporting
        id                      'F04'
        language                sy-langu
        name                    l_tdname
        object                  'EKKO'
      tables
        lines                   l_lines_4
      exceptions
        id                      1
        language                2
        name                    3
        not_found               4
        object                  5
        reference_check         6
        wrong_access_to_archive 7
        others                  8.
*
    if not l_lines_1[] is initial or not l_lines_2[] is initial or not l_lines_3[] is initial
        or not l_lines_4[] is initial.
      t_ekko-zmark 'X'.
      modify t_ekko transporting zmark.
    endif.
    clear:l_lines_3,l_lines_3[],l_lines_1,l_lines_1[],l_lines_2,l_lines_2[],
          l_lines_4,l_lines_4[].
  endloop.
endform.                    "last_po_data
*&---------------------------------------------------------------------*
*&      Form  call_alv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form call_alv.
**************************************************************************************
*增加总金额到ekko
  sort t_ekko by ebeln.
  sort t_ekpo by ebeln.
  clear:t_ekpo, t_ekko.
  loop at t_ekko.
    loop at t_ekpo where ebeln t_ekko-ebeln.
      t_ekko-zjine t_ekpo-netwr + t_ekko-zjine.
    endloop.
    modify t_ekko transporting zjine.
    clear:t_ekpo, t_ekko.
  endloop.
******************************************************************************************
  call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
       exporting
            i_callback_program       g_repid
*           I_CALLBACK_PF_STATUS_SET = ' '
*           I_CALLBACK_USER_COMMAND  = ' '
            is_layout                gs_layout
            it_fieldcat              gt_fieldcat[]
*           IT_EXCLUDING             =
            it_special_groups        gt_sp_group[]
            it_sort                  gt_sort[]
*           IT_FILTER                =
*           IS_SEL_HIDE              =
*           I_SCREEN_START_COLUMN    = 0
*           I_SCREEN_START_LINE      = 0
*           I_SCREEN_END_COLUMN      = 0
*           I_SCREEN_END_LINE        = 0
*           i_default                = g_default
            i_save                   g_save
            is_variant               g_variant
            it_events                gt_events[]
*           IT_EVENT_EXIT            =
            i_tabname_header         g_tabname_header
            i_tabname_item           g_tabname_item
            is_keyinfo               gs_keyinfo
*           IS_PRINT                 =
*      IMPORTING
*           E_EXIT_CAUSED_BY_CALLER  =
       tables
            t_outtab_header          t_ekko
            t_outtab_item            t_ekpo.
endform.                    "call_alv

 

*&---------------------------------------------------------------------*
*&  Include           ZMM_FM06LTO1
*&---------------------------------------------------------------------*

TABLES: EKKO,                          "Einkaufsbelegkopf
        EKPO,                          "Einkaufsbelegposition
        RM06E,                         "Hilfsfelder
       *EKPO,
        EKET,                          "Einkaufsbelegeinteilung
        EKES,                          "Bestellbestätigungen
        EKKN,                          "Einkaufsbelegkontierung
        T160S,                         "Selektionsparameter
        T160T,
        EKDY,
        SSCRFIELDS.
"ENHANCEMENT-POINT EHP_RM06EL00_06 SPOTS /SAPPSPRO/ES_RM06EL00 STATIC .

*---- WWW: zusätzliche Felder fürs Web-Reporting
DATA  G_SUBMIT_INFO LIKE RSSUBINFO.     " Laufzeitinfo

 

*&---------------------------------------------------------------------*
*&  Include           ZMM_FM06LCFR
*&---------------------------------------------------------------------*
***INCLUDE FM06LCFR.
************************************************************************
*        Common Part für Freigabeverfahren                             *
************************************************************************
DATA BEGIN OF COMMON PART fm06lcfr.
DATA: BEGIN OF xekko OCCURS 50.
        INCLUDE STRUCTURE ekko.
*DATA: zbox TYPE c,
*      zreje(10) TYPE c," Can be reject function and Reject Reason (Field 1) (PO header text). 拒绝描述
*      zbuye(10) TYPE c."Buyer can check the reject PO in the PO approve screen. Buyer
*                        " Remark (Field 2) (PO header text).自己的描述
DATA: END OF xekko.
DATA END OF COMMON PART fm06lcfr.

 

*&---------------------------------------------------------------------*
*&  Include           ZMM_SELOPT_CNT_CALL
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&  Include           SELOPT_CNT_CALL
*&---------------------------------------------------------------------*

* (Hidden) select options for call of report in workload count mode
* and/or for call from Purchasing Agent Portal
* - P_WLMEM  Memory-ID to pass workload to calling programm; also switch
*            for count mode (if not SPACE)
* - P_ALV    Flag to force display of results of selection as ALV grid
* - P_CNTLMT Upper limit for selection in workload count mode
* new for ERP 1.0 PA

PARAMETERS: p_wlmem  TYPE memory_id DEFAULT space NO-DISPLAY,
            p_alv    TYPE c         DEFAULT space NO-DISPLAY,
            p_cntlmt TYPE i         DEFAULT space NO-DISPLAY.

 

*eject
*----------------------------------------------------------------------*
*             COMMON DATA                                              *
*----------------------------------------------------------------------*
*             Datenfelder für die Listen der Einkaufsbelege            *
*----------------------------------------------------------------------*

DATA: BEGIN OF COMMON PART FM06LCEK.

*------------ Überschrift ---------------------------------------------*
DATA: BEGIN OF UEB,
          1(80),
          2(80),
          3(80),
          4(80),
          5(80),
      END OF UEB.

ENHANCEMENT-POINT FM06LCEK_02 SPOTS ES_FM06LCEK STATIC INCLUDE BOUND.
*$*$-Start: FM06LCEK_02-------------------------------------------------------------------------$*$*
ENHANCEMENT 1  MGV_MATNR_LAMA_FM06LCEK.    "active version
* Note 505380                                                   C5031265
* Extended Header
DATA: BEGIN OF UEB1,
          1(200),
          2(200),
          3(200),
          4(200),
          5(200),
      END OF UEB1.
ENDENHANCEMENT.
*$*$-End:   FM06LCEK_02-------------------------------------------------------------------------$*$*


ENHANCEMENT-POINT FM06LCEK_01 SPOTS ES_FM06LCEK STATIC INCLUDE BOUND.
*$*$-Start: FM06LCEK_01-------------------------------------------------------------------------$*$*
ENHANCEMENT 1  AD_MPN_MD_FM06LCEK.    "active version
*----------------------------------------------------------------------
* zusätzliche Felder für Herstellerteil Nummer
*----------------------------------------------------------------------
DATA:  MAT_LEN TYPE I,
       OFFSET TYPE I,
       PAD TYPE VALUE 3,
       I_MPNCNV LIKE V_MPNCNV OCCURS WITH HEADER LINE,
       MANUFACTURER_LEN TYPE I,
       OUTPUT_LINE_WIDTH TYPE I,
       POSITION TYPE I,
       LEN TYPE I.
ENDENHANCEMENT.
*$*$-End:   FM06LCEK_01-------------------------------------------------------------------------$*$*


ENHANCEMENT-POINT FM06LCEK_03 SPOTS ES_FM06LCEK STATIC INCLUDE BOUND .
*$*$-Start: FM06LCEK_03-------------------------------------------------------------------------$*$*
ENHANCEMENT 2  MGV_MATNR_LAMA_FM06LCEK.    "active version
DATA:  REPID_FLAG TYPE VALUE SPACE.
ENDENHANCEMENT.
*$*$-End:   FM06LCEK_03-------------------------------------------------------------------------$*$*

*------------ Hilfsfelder ---------------------------------------------*
DATA: REJECT.
DATA: LEERFLG.
DATA: NOT_FOUND.

DATA: END OF COMMON PART.

 

*&---------------------------------------------------------------------*
*&  Include           ZMM_EVENTS
*&---------------------------------------------------------------------*
FORM E01_FIELDCAT_INIT USING E01_LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
  DATA LS_CELLCOLOR TYPE LVC_S_SCOL .

  CALL FUNCTION 'SBUF_OBJ_RESET_OBJECT'
         EXPORTING
              BUFF_ID  0
              INV_CODE 'DEL_WORLD_GENERIC   '
* Achtung: Das Literal muss 20 Character lang sein!
              TABNAME  'EUINFO'
              KEY      '%F'
              KEY_L    2.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      I_PROGRAM_NAME     G_REPID
      I_INTERNAL_TABNAME G_TABNAME_HEADER
      I_STRUCTURE_NAME   'ZTSEKKO'
    CHANGING
      CT_FIELDCAT        E01_LT_FIELDCAT[].
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      I_PROGRAM_NAME     G_REPID
      I_INTERNAL_TABNAME G_TABNAME_ITEM
      I_STRUCTURE_NAME   'ZTSEKPO'
    CHANGING
      CT_FIELDCAT        E01_LT_FIELDCAT[].
*
  LOOP AT E01_LT_FIELDCAT INTO LS_FIELDCAT.
    IF LS_FIELDCAT-FIELDNAME 'EBELN' AND LS_FIELDCAT-TABNAME 'T_EKPO'.
      DELETE E01_LT_FIELDCAT.
    ENDIF.
    IF LS_FIELDCAT-FIELDNAME 'BSART' AND LS_FIELDCAT-TABNAME 'T_EKKO'.
      DELETE E01_LT_FIELDCAT.
    ENDIF.
    IF LS_FIELDCAT-FIELDNAME 'ZVSIN' AND LS_FIELDCAT-TABNAME 'T_EKPO'.
      DELETE E01_LT_FIELDCAT.
    ENDIF.
    CASE LS_FIELDCAT-FIELDNAME.
      WHEN 'ZCBOX'.
        LS_FIELDCAT-INPUT         'X'.
        LS_FIELDCAT-CHECKBOX      'X'.
        MODIFY E01_LT_FIELDCAT FROM LS_FIELDCAT.
      WHEN 'ZBUYE'.
        LS_FIELDCAT-INPUT        'X' .
        MODIFY E01_LT_FIELDCAT FROM LS_FIELDCAT.
      WHEN 'ZITEM'.
        LS_FIELDCAT-INPUT        'X' .
        MODIFY E01_LT_FIELDCAT FROM LS_FIELDCAT.
        DELETE E01_LT_FIELDCAT.
      WHEN 'PEINH' OR 'BPRME' OR 'MFRNR' OR 'MATKL' OR 'WERKS' OR 'NETPR'
           OR 'FRGGR' OR 'FRGSX' OR 'FRGKE' OR 'NETWR'.
        DELETE E01_LT_FIELDCAT.
      WHEN 'EINDT'.
        LS_FIELDCAT-REPTEXT_DDIC 'Deliv. Date'.
        LS_FIELDCAT-SELTEXT_L 'Deliv. Date'.
        LS_FIELDCAT-SELTEXT_M 'Deliv. Date'.
        LS_FIELDCAT-SELTEXT_S 'Deliv. Date'.
        CLEAR: LS_FIELDCAT-REF_TABNAME,
               LS_FIELDCAT-REF_FIELDNAME.
        MODIFY E01_LT_FIELDCAT FROM LS_FIELDCAT.
    ENDCASE.
    CLEAR LS_FIELDCAT.
  ENDLOOP.
ENDFORM.                    "E01_FIELDCAT_INIT
*&---------------------------------------------------------------------*
*&      Form  e03_eventtab_build
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->E03_LT_EVENTS  text
*----------------------------------------------------------------------*
FORM E03_EVENTTAB_BUILD USING E03_LT_EVENTS TYPE SLIS_T_EVENT.
  DATA: LS_EVENT TYPE SLIS_ALV_EVENT.
*
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      I_LIST_TYPE 1
    IMPORTING
      ET_EVENTS   E03_LT_EVENTS.
  READ TABLE E03_LT_EVENTS WITH KEY NAME SLIS_EV_TOP_OF_PAGE
                           INTO LS_EVENT.
  IF SY-SUBRC 0.
    MOVE GC_FORMNAME_TOP_OF_PAGE TO LS_EVENT-FORM.
    APPEND LS_EVENT TO E03_LT_EVENTS.
  ENDIF.
  READ TABLE E03_LT_EVENTS WITH KEY NAME SLIS_EV_USER_COMMAND
                           INTO LS_EVENT.
  IF SY-SUBRC 0.
    MOVE USER_COMMAND TO LS_EVENT-FORM.
    APPEND LS_EVENT TO E03_LT_EVENTS.
  ENDIF.
  READ TABLE E03_LT_EVENTS WITH KEY NAME =  SLIS_EV_PF_STATUS_SET
                           INTO LS_EVENT.
  IF SY-SUBRC 0.
    MOVE SET_PF_STATUS TO LS_EVENT-FORM.
    APPEND LS_EVENT TO E03_LT_EVENTS.
  ENDIF.

ENDFORM.                    "E03_EVENTTAB_BUILD
*&---------------------------------------------------------------------*
*&      Form  E06_T_SORT_BUILD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->E06_LT_SORT  text
*----------------------------------------------------------------------*
FORM E06_T_SORT_BUILD USING E06_LT_SORT TYPE SLIS_T_SORTINFO_ALV.
  DATA: LS_SORT TYPE SLIS_SORTINFO_ALV.
*
  CLEAR LS_SORT.
  LS_SORT-FIELDNAME 'EBELN'.
  LS_SORT-TABNAME   G_TABNAME_HEADER.
  LS_SORT-SPOS      1.
  LS_SORT-UP        'X'.
  APPEND LS_SORT TO E06_LT_SORT.
  CLEAR LS_SORT.
  LS_SORT-FIELDNAME 'EBELP'.
  LS_SORT-TABNAME   G_TABNAME_ITEM.
  LS_SORT-SPOS      2.
  " ls_sort-down      = 'X'.
  APPEND LS_SORT TO E06_LT_SORT.
ENDFORM.                    "E06_T_SORT_BUILD
*&---------------------------------------------------------------------*
*&      Form  E07_SP_GROUP_BUILD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->E07_LT_SP_GROUP  text
*----------------------------------------------------------------------*
FORM E07_SP_GROUP_BUILD USING E07_LT_SP_GROUP TYPE SLIS_T_SP_GROUP_ALV.
  DATA: LS_SP_GROUP TYPE SLIS_SP_GROUP_ALV.
*
  CLEAR  LS_SP_GROUP.
  LS_SP_GROUP-SP_GROUP 'A'.
  LS_SP_GROUP-TEXT     'Special columns'.                 " text-005.
  APPEND LS_SP_GROUP TO E07_LT_SP_GROUP.
ENDFORM.                    "E07_SP_GROUP_BUILD
*&---------------------------------------------------------------------*
*&      Form  VARIANT_INIT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM VARIANT_INIT.
*
  CLEAR G_VARIANT.
  G_VARIANT-REPORT G_REPID.
ENDFORM.                               " VARIANT_INIT


*&---------------------------------------------------------------------*
*&      Form  E05_LAYOUT_BUILD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->E05_LS_LAYOUT  text
*----------------------------------------------------------------------*
FORM E05_LAYOUT_BUILD USING E05_LS_LAYOUT TYPE SLIS_LAYOUT_ALV.
  E05_LS_LAYOUT-BOX_FIELDNAME 'ZCBOX'.
  E05_LS_LAYOUT-BOX_TABNAME   T_EKKO.
  E05_LS_LAYOUT-INFO_FIELDNAME 'LISTINFO'.
  E05_LS_LAYOUT-F2CODE            P_F2CODE.
ENDFORM.                    "E05_LAYOUT_BUILD

*&---------------------------------------------------------------------*
*&      Form  alv_refresh
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->_COL_STABLE  text
*      -->_ROW_STABLE  text
*      -->_REFRESH     text
*----------------------------------------------------------------------*
FORM ALV_REFRESH  CHANGING _COL_STABLE  _ROW_STABLE  _REFRESH.

  _COL_STABLE 'X'.
  _ROW_STABLE 'X'.
  _REFRESH 'X'.

ENDFORM.                    " alv_refresh

*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->R_UCOMM      text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM USER_COMMAND  USING R_UCOMM LIKE SY-UCOMM RS_SELFIELD TYPE SLIS_SELFIELD.
  CASE R_UCOMM.
    WHEN 'FRGR'. " CANCEL
      PERFORM CANCEL_APPROVAL.
      RS_SELFIELD-REFRESH 'X'.
    WHEN 'FRGU'. "APPOVERL
      PERFORM APPROVAL.
      RS_SELFIELD-REFRESH 'X'.
    WHEN 'XS'.
      "  PERFORM show_text.
      CALL SCREEN 0100 STARTING AT 10 5
                       ENDING AT 120 25.
    WHEN 'QX'.
      LOOP AT T_EKKO.
        T_EKKO-ZCBOX 'X'.
        MODIFY T_EKKO TRANSPORTING ZCBOX.
      ENDLOOP.
      RS_SELFIELD-REFRESH 'X'.
    WHEN 'FX'.
      LOOP AT T_EKKO.
        T_EKKO-ZCBOX ''.
        MODIFY T_EKKO TRANSPORTING ZCBOX.
      ENDLOOP.
      RS_SELFIELD-REFRESH 'X'.
    WHEN 'SAVE'.
      "  PERFORM save_data .
    WHEN 'BACK' OR 'CANC'.
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDFORM.                    "USER_COMMAND

*&---------------------------------------------------------------------*
*&      Form  set_pf_status
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->RT_EXTAB   text
*----------------------------------------------------------------------*
FORM SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
  SET PF-STATUS 'PF_STATUS_SET'.                "设置对象栏等
ENDFORM.                    "set_pf_status

*&---------------------------------------------------------------------*
*&      Form  repalce_AND_in_TEXT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LINE     text
*----------------------------------------------------------------------*
FORM REPALCE_AND_IN_TEXT CHANGING P_LINE.
  DATA RESULT_TAB TYPE MATCH_RESULT_TAB.
  CHECK P_LINE IS NOT INITIAL.
  FIND ALL OCCURRENCES OF '<(>' IN P_LINE RESULTS RESULT_TAB.
  IF SY-SUBRC 0.
    REPLACE ALL OCCURRENCES OF  '<(>' IN  P_LINE WITH ' '.
  ENDIF.
  FIND ALL OCCURRENCES OF '<)>' IN P_LINE RESULTS RESULT_TAB.
  IF SY-SUBRC 0.
    REPLACE ALL OCCURRENCES OF  '<)>' IN  P_LINE WITH ' '.
  ENDIF.
ENDFORM.                    "repalce_AND_in_TEXT

 

*&---------------------------------------------------------------------*
*&  Include           ZMM_FROM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  cancel_approval
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form cancel_approval.
  data: purchaseorder type bapimmpara-po_number,
        po_rel_code type bapimmpara-po_rel_cod.
  data:rel_status_new type bapimmpara-rel_status,
     rel_indicator_new type bapimmpara-po_rel_ind ,
  return type standard table of bapireturn with header line.
  data: wa_ekko type ztsekko.
************************************************************************
  data:p_frgc1 type t16fs-frgc1.
  loop at t_ekko into wa_ekko where zcbox 'X'.
*********************************************************************
    if wa_ekko-zbuye ' ' .
      message e000(oowith 'Cancel Approval Reject Reason'.
    else.
      purchaseorder wa_ekko-ebeln.
      select single frgc1 into p_frgc1 from t16fs
       where frggr t_ekko-frggr
         and frgsx t_ekko-frgsx.
      po_rel_code   p_frgc1 .
    endif.
    refresh return.
***********************************************************************
    call function 'BAPI_PO_RESET_RELEASE'
      exporting
        purchaseorder            purchaseorder
        po_rel_code              po_rel_code
      importing
        rel_status_new           rel_status_new
        rel_indicator_new        rel_indicator_new
      tables
        return                   return
      exceptions
        authority_check_fail     1
        document_not_found       2
        enqueue_fail             3
        prerequisite_fail        4
        release_already_posted   5
        responsibility_fail      6
        no_release_already       7
        no_new_release_indicator 8
        others                   9.
    if sy-subrc <> 0.
* Implement suitable error handling here
      read table return with key type 'E'.
      message return-message type 'I'.
      call function 'BAPI_TRANSACTION_ROLLBACK'.
    else.
      call function 'BAPI_TRANSACTION_COMMIT'
        exporting
          wait 'X'.
    endif.
*********************************************************************
    if wa_ekko-zbuye <> ' '.
* header text *ekko header text
      data:l_header type standard table of thead with header line,
           l_lines  type standard table of tline with header line,
           l_tdname type tdobname.
*read text
      l_tdname wa_ekko-ebeln.
      call function 'READ_TEXT'
        exporting
          id                      'F02'
          language                sy-langu
          name                    l_tdname
          object                  'EKKO'
        tables
          lines                   l_lines
        exceptions
          id                      1
          language                2
          name                    3
          not_found               4
          object                  5
          reference_check         6
          wrong_access_to_archive 7
          others                  8.
*save_text
      l_header-tdname wa_ekko-ebeln.
      l_header-tdid  'F02'.
      l_header-tdobject =  'EKKO'.
      l_header-tdspras sy-langu.
      append l_header.
      l_lines-tdformat '*'.
      l_lines-tdline wa_ekko-zbuye.
      append l_lines.
      call function 'SAVE_TEXT'
        exporting
          client          sy-mandt
          header          l_header
          savemode_direct 'X'
        tables
          lines           l_lines
        exceptions
          id              1
          language        2
          name            3
          object          4
          others          5.
    endif.
*********************************************************************
    "     MESSAGE i000(oo) WITH 'Cancel Approval Success' .
*DELETE CANCEL APPROVAL DATA
    read table return with key type 'E'.
    if sy-subrc ne 0.
      read table t_ekko with key ebeln wa_ekko-ebeln.
      if sy-subrc 0.
        delete t_ekko.
      endif.
      loop at t_ekpo where ebeln wa_ekko-ebeln.
        delete t_ekpo.
      endloop.
      clear wa_ekko.
    endif.
    clear: l_lines,l_lines[],t_ekpo,wa_ekko,return[].
  endloop.
endform.                    "cancel_approval

*&---------------------------------------------------------------------*
*&      Form  approval
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form approval.
  data: wa_ekko type ztsekko,
        p_netpr type ekpo-netpr,
        p_matnr type ekpo-matnr.
**********************************************************************
*APPROVAL
  data: purchaseorder type bapimmpara-po_number,
        po_rel_code type bapimmpara-po_rel_cod.
  data:rel_status_new type bapimmpara-rel_status,
       rel_indicator_new type bapimmpara-po_rel_ind ,
       ret_code  type sy-subrc ,
       return type standard table of bapireturn with header line.
  loop at t_ekko into wa_ekko where zcbox  'X'.
*    PERFORM check_data USING wa_ekko
*                      CHANGING purchaseorder
*                                po_rel_code.
    loop at t_ekpo where ebeln wa_ekko-ebeln and zvsin ''.
*判断相同的Po 不同的价格
      read table xekpo with key ebeln t_ekpo-ebeln ebelp t_ekpo-ebelp." 被删除的物料不参与比较
      check xekpo-loekz <> 'L'.

      if p_netpr and p_matnr ''."t_ekpo-matnr.
        p_netpr t_ekpo-netpr.
        p_matnr t_ekpo-ematn.
      elseif p_matnr t_ekpo-ematn.
        p_matnr t_ekpo-ematn.
        if p_netpr <> t_ekpo-netpr.
          message e000(oowith 'difference price, will cannot be approve, and issue an error'.
        endif.
      else.
        p_matnr t_ekpo-ematn.
        p_netpr t_ekpo-netpr.
      endif.
    endloop.
    clear: p_netpr,p_matnr.
*
    clear t_ekpo.
    loop at t_ekpo where ebeln wa_ekko-ebeln and zvsin ''.
      if t_ekpo-zdiff > 0.
        if wa_ekko-zbuye '' and p_frgco 'B1'.
          message e000(oowith 'Must remark for price raise'.
        else.
          exit.
        endif.
      endif.
    endloop.

    clear : purchaseorder,
            po_rel_code.
    purchaseorder wa_ekko-ebeln.
    po_rel_code  p_frgco.
    refresh return.
    if not purchaseorder is initial and po_rel_code is not initial.
      call function 'BAPI_PO_RELEASE'
        exporting
          purchaseorder          purchaseorder
          po_rel_code            po_rel_code
        importing
          rel_status_new         rel_status_new
          rel_indicator_new      rel_indicator_new
          ret_code               ret_code
        tables
          return                 return
        exceptions
          authority_check_fail   1
          document_not_found     2
          enqueue_fail           3
          prerequisite_fail      4
          release_already_posted 5
          responsibility_fail    6
          others                 7.
      if sy-subrc <> 0.
* Implement suitable error handling here
        read table return with key type 'E'.
        message return-message type 'I'.
        call function 'BAPI_TRANSACTION_ROLLBACK'.
      else.
        call function 'BAPI_TRANSACTION_COMMIT'
          exporting
            wait 'X'.
      endif.
**********************************************************************
*ekko header text
      if wa_ekko-zbuye <> ''.
        data:l_header type standard table of thead with header line,
             l_lines  type standard table of tline with header line,
             l_tdname type tdobname.
        read table xekko with key  ebeln wa_ekko-ebeln.
        if sy-subrc 0.
          if xekko-frgzu ''.
*read text
            l_tdname wa_ekko-ebeln.
            call function 'READ_TEXT'
              exporting
                id                      'F01'
                language                sy-langu
                name                    l_tdname
                object                  'EKKO'
              tables
                lines                   l_lines
              exceptions
                id                      1
                language                2
                name                    3
                not_found               4
                object                  5
                reference_check         6
                wrong_access_to_archive 7
                others                  8.
*save_text
            l_header-tdname wa_ekko-ebeln.
            l_header-tdid  'F01'.
            l_header-tdobject =  'EKKO'.
            l_header-tdspras sy-langu.
            append l_header.
            l_lines-tdformat '*'.
            l_lines-tdline wa_ekko-zbuye.
            append l_lines.
            call function 'SAVE_TEXT'
              exporting
                client          sy-mandt
                header          l_header
                savemode_direct 'X'
              tables
                lines           l_lines
              exceptions
                id              1
                language        2
                name            3
                object          4
                others          5.
          endif.
        endif.
      endif.
    endif.
*save
    read table return with key type 'E'.
    if sy-subrc ne 0.
*M1 add
      if wa_ekko-frgsx '10' or wa_ekko-frgsx '11'  or wa_ekko-frgsx '12')
           and  po_rel_code 'M3'.
        perform send_excel_email using wa_ekko-ebeln.
      endif.
*M1 End
      perform save_data using wa_ekko.
* delte approval data
      read table t_ekko with key ebeln purchaseorder.
      if sy-subrc 0.
        delete t_ekko.
      endif.
      loop at t_ekpo where ebeln purchaseorder.
        delete t_ekpo.
      endloop.
    endif.
    clear: wa_ekko.
    clear: l_lines,l_lines[],t_ekpo,wa_ekko,return[].
  endloop.
endform.                    "approval

*&---------------------------------------------------------------------*
*&      Form  save_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form save_data using s_ekko structure ztsekko.
* save version
  data: p_frgke type ekko-frgke.
  data: t_frgc0 like t16fs-frgc1.
  data: l_frgc0 like t16fs-frgc1.
  data: wa_t16fs type t16fs.
  data:p_zvsin type zekpo-zvsin.
*
  data:s_ekpo type standard table of zekpo with header line,
       ls_ekko type standard table of zekko with header line.
*  SELECT SINGLE frgke INTO p_frgke
*       FROM ekko
*    WHERE ebeln = s_ekko-ebeln.
  select single into  wa_t16fs
    from t16fs
    where frggr s_ekko-frggr and frgsx s_ekko-frgsx.
*
  do times varying t_frgc0 from wa_t16fs-frgc1 next wa_t16fs-frgc2.
    if t_frgc0 ''.
      exit.
    endif.
    l_frgc0 t_frgc0.
  enddo.
  if p_frgco l_frgc0.
*get max version numbar
    loop at t_zekpo where ebeln s_ekko-ebeln.
      if p_zvsin 0.
        p_zvsin t_zekpo-zvsin.
      elseif t_zekpo-zvsin > p_zvsin .
        p_zvsin t_zekpo-zvsin.
      endif.
    endloop.
    loop at t_ekpo where ebeln s_ekko-ebeln and zvsin ''.
      read table t_zekpo with key ebeln t_ekpo-ebeln ebelp t_ekpo-ebelp.
      if sy-subrc 0.
        if t_ekpo-menge <> t_zekpo-menge or t_ekpo-netpr <> t_zekpo-netpr.
          s_ekpo-ebeln t_ekpo-ebeln.
          s_ekpo-ebelp t_ekpo-ebelp.
*更改物料(保存)
          call function 'CONVERSION_EXIT_MATN1_INPUT'
            exporting
              input  t_ekpo-ematn
            importing
              output s_ekpo-ematn.
          "    s_ekpo-ematn = t_ekpo-ematn.
          s_ekpo-txz01 t_ekpo-txz01.
          s_ekpo-mfrpn t_ekpo-mfrpn.
          s_ekpo-mfrnr t_ekpo-mfrnr.
          s_ekpo-name1 t_ekpo-name1.
          s_ekpo-matkl t_ekpo-matkl.
          s_ekpo-werks t_ekpo-werks.
          s_ekpo-menge t_ekpo-menge.
          s_ekpo-old_menge t_zekpo-menge.
          s_ekpo-meins t_ekpo-meins.
          s_ekpo-netpr t_ekpo-netpr.
          s_ekpo-old_netpr t_zekpo-netpr.
          s_ekpo-znetp t_ekpo-znetp.
          s_ekpo-waers t_ekpo-waers.
          s_ekpo-peinh t_ekpo-peinh.
          s_ekpo-bprme t_ekpo-bprme.
          s_ekpo-zdiff t_ekpo-zdiff.
          s_ekpo-zvmi t_ekpo-zvmi.
          s_ekpo-zvsin p_zvsin + 1.
          s_ekpo-budat sy-datum.
          append s_ekpo.
        endif.
      else.
        s_ekpo-ebeln t_ekpo-ebeln.
        s_ekpo-ebelp t_ekpo-ebelp.
*更改物料(保存)
        call function 'CONVERSION_EXIT_MATN1_INPUT'
          exporting
            input  t_ekpo-ematn
          importing
            output s_ekpo-ematn.
        "   s_ekpo-ematn = t_ekpo-ematn.
        s_ekpo-txz01 t_ekpo-txz01.
        s_ekpo-matkl t_ekpo-matkl.
        s_ekpo-mfrpn t_ekpo-mfrpn.
        s_ekpo-mfrnr t_ekpo-mfrnr.
        s_ekpo-name1 t_ekpo-name1.
        s_ekpo-werks t_ekpo-werks.
        s_ekpo-menge t_ekpo-menge.
        s_ekpo-meins t_ekpo-meins.
        s_ekpo-netpr t_ekpo-netpr.
        s_ekpo-znetp t_ekpo-znetp.
        s_ekpo-waers t_ekpo-waers.
        s_ekpo-peinh t_ekpo-peinh.
        s_ekpo-bprme t_ekpo-bprme.
        s_ekpo-zdiff t_ekpo-zdiff.
        s_ekpo-zvmi t_ekpo-zvmi.
        s_ekpo-zvsin =  '000'.
        s_ekpo-budat sy-datum.
        append s_ekpo.
      endif.
      clear s_ekpo.
    endloop.
    if not s_ekpo[] is initial.
      insert zekpo from table s_ekpo.
      commit work.
    endif.
    if sy-subrc <> 0.
* Implement suitable error handling here
    endif.
    clear:s_ekpo,s_ekpo[],s_ekko,t_t16ft,t_t16ft[],p_frgke,p_zvsin.
  endif.
endform.                    "save_data

*&---------------------------------------------------------------------*
*&      Form  show_text
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form show_text.
*read_text
  data:l_header type standard table of thead with header line,
     l_tdname type tdobname,
     l_lines_1  type standard table of tline with header line,
     l_lines_2  type standard table of tline with header line,
     l_lines_3  type standard table of tline with header line,
     l_lines_4  type standard table of tline with header line.
* get text1
  loop at t_ekko where zcbox 'X'.
    l_tdname t_ekko-ebeln.
    call function 'READ_TEXT'
      exporting
        id                      'F01'
        language                sy-langu
        name                    l_tdname
        object                  'EKKO'
      tables
        lines                   l_lines_1
      exceptions
        id                      1
        language                2
        name                    3
        not_found               4
        object                  5
        reference_check         6
        wrong_access_to_archive 7
        others                  8.
* get text2
    call function 'READ_TEXT'
      exporting
        id                      'F02'
        language                sy-langu
        name                    l_tdname
        object                  'EKKO'
      tables
        lines                   l_lines_2
      exceptions
        id                      1
        language                2
        name                    3
        not_found               4
        object                  5
        reference_check         6
        wrong_access_to_archive 7
        others                  8.
* get text 3
    call function 'READ_TEXT'
      exporting
        id                      'F03'
        language                sy-langu
        name                    l_tdname
        object                  'EKKO'
      tables
        lines                   l_lines_3
      exceptions
        id                      1
        language                2
        name                    3
        not_found               4
        object                  5
        reference_check         6
        wrong_access_to_archive 7
        others                  8.
* get text 4
    call function 'READ_TEXT'
      exporting
        id                      'F04'
        language                sy-langu
        name                    l_tdname
        object                  'EKKO'
      tables
        lines                   l_lines_4
      exceptions
        id                      1
        language                2
        name                    3
        not_found               4
        object                  5
        reference_check         6
        wrong_access_to_archive 7
        others                  8.
*
    if not l_lines_1[] is initial or not l_lines_2[] is initial
      or not l_lines_3[] is initial or  l_lines_4[] is  not initial.
      uline.
      write:/(10'Po Number' color col_heading.
      write: t_ekko-ebeln color col_heading.
      skip.
    endif.
    if not l_lines_1[] is initial.
      write:/(10'Buyer:' color col_heading.
      loop at l_lines_1.
        perform repalce_and_in_text changing l_lines_1-tdline.
        if sy-tabix 1.
          write:  12 l_lines_1-tdline color col_normal intensified off.
        else.
          write: /12 l_lines_1-tdline color col_normal intensified off.
        endif.
      endloop.
      skip.
    endif.
    if not l_lines_2[] is initial.
      write:/(10'Manager:' color col_heading.
      loop at l_lines_2.
        perform repalce_and_in_text changing l_lines_2-tdline.
        if sy-tabix 1.
          write:  12 l_lines_2-tdline color col_normal intensified off.
        else.
          write: /12 l_lines_2-tdline color col_normal intensified off.
        endif.
      endloop.
      skip.
    endif.
    if not l_lines_3[] is initial.
      write:/(10'Vendor:' color col_heading.
      loop at l_lines_3.
        perform repalce_and_in_text changing l_lines_3-tdline.
        if sy-tabix 1.
          write:  12 l_lines_3-tdline color col_normal intensified off.
        else.
          write: /12 l_lines_3-tdline color col_normal intensified off.
        endif.
      endloop.
      skip.
    endif.
    if not l_lines_4[] is initial.
      write:/(10'Change:' color col_heading.
      loop at l_lines_4.
        perform repalce_and_in_text changing l_lines_4-tdline.
        if sy-tabix 1.
          write:  12 l_lines_4-tdline color col_normal intensified off.
        else.
          write: /12 l_lines_4-tdline color col_normal intensified off.
        endif.
      endloop.
      skip.
    endif.
    clear: l_lines_3,l_lines_3[],l_lines_1,l_lines_1[],l_lines_2,l_lines_2[]
          ,l_lines_4,l_lines_4[].
  endloop.

  leave to list-processing.
  leave to screen 0.
endform.                    "show_text

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module status_0100 output.
  set pf-status 'MM_0100'.
*  SET TITLEBAR 'xxx'.
  suppress dialog.

  perform show_text.
endmodule.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module user_command_0100 input.
  data:save_ok type sy-ucomm,
       ok_code type sy-ucomm.
  clear save_ok.
  save_ok ok_code.
  clear ok_code.
  case sy-ucomm.
    when 'BACK' or 'CANC' or 'EXIT'.
      leave to screen 0.
  endcase.
endmodule.                 " USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*&      Form  CURRENCE_CONVERT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_T_EKPO_WAERS  text
*      <--P_T_EKPO_NETPR  text
*----------------------------------------------------------------------*
form currence_convert  using    p_waers
                       changing p_amount.
  data : lv_amount type bapicurr-bapicurr.

  check p_waers is not initial
  and p_waers <> 'HKD' and p_waers <> 'CNY'
  and p_waers <>'USD' and p_waers <>'EUR'.

  check p_amount is not initial.

  call function 'BAPI_CURRENCY_CONV_TO_EXTERNAL'
    exporting
      currency        p_waers
      amount_internal p_amount
    importing
      amount_external lv_amount.
  p_amount lv_amount.
  clear lv_amount.
endform.                    " CURRENCE_CONVERT
*M1 add
*&---------------------------------------------------------------------*
*&      Form  SEND_EXCEL_EMAIL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WA_EKKO_EBELN  text
*----------------------------------------------------------------------*
form send_excel_email  using    p_ebeln.
  clear:it_zpoemail,it_zpoemail[],lv_subrc,i_reclist,i_reclist[],xls_content,xls_size.
  perform get_email changing lv_subrc.
  if lv_subrc eq 0.
    perform foramt_xls  using  p_ebeln.
    if  xls_content is not initial.
      perform send_mail_via_bcs using p_ebeln  changing lv_subrc.
      if lv_subrc eq 0.
        it_zpoemail-ebeln p_ebeln.
        it_zpoemail-aedat sy-datum.
        it_zpoemail-aezet sy-uzeit.
        it_zpoemail-aenam sy-uname.
        it_zpoemail-isfail ''.
        it_zpoemail-msgds 'Send eMail Success.'.
        append it_zpoemail.
      else.
        it_zpoemail-ebeln p_ebeln.
        it_zpoemail-aedat sy-datum.
        it_zpoemail-aezet sy-uzeit.
        it_zpoemail-aenam sy-uname.
        it_zpoemail-isfail 'X'.
        it_zpoemail-msgds 'Send eMail Failing.'.
         append it_zpoemail.
      endif.
    else.
      it_zpoemail-ebeln p_ebeln.
      it_zpoemail-aedat sy-datum.
      it_zpoemail-aezet sy-uzeit.
      it_zpoemail-aenam sy-uname.
      it_zpoemail-isfail 'X'.
      it_zpoemail-msgds 'eMail Transfer format error.'.
       append it_zpoemail.
    endif.
  else.
    it_zpoemail-ebeln p_ebeln.
    it_zpoemail-aedat sy-datum.
    it_zpoemail-aezet sy-uzeit.
    it_zpoemail-aenam sy-uname.
    it_zpoemail-isfail 'X'.
    it_zpoemail-msgds 'eMail address No Maintain.'.
     append it_zpoemail.
  endif.
  modify zpoemail from table it_zpoemail[].
endform.                    " SEND_EXCEL_EMAIL
*&---------------------------------------------------------------------*
*&      Form  GET_EMAIL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form get_email changing p_subrc .
  select  distinct zemal as  receiver
    into table i_reclist
    from zbuyer
    where zrgco 'G2'.
  p_subrc sy-subrc.
endform.                    " GET_EMAIL

*&---------------------------------------------------------------------*
*&      Form  FORAMT_XLS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      Format XLS file as attachment
*----------------------------------------------------------------------*
form foramt_xls  using    p_ebeln  .
  data : begin of lt_xls occurs 0,
         matnr type ekpo-matnr, "Vtech Part No.
         ebeln type ekpo-ebeln, " PO#
         ebelp type ekpo-ebelp, " Line#
         mfrpn type mara-mfrpn, "Vendor Ordering No.
         mfrnr type ekpo-mfrnr, " Manufacturer
         kdmat type knmt-kdmat, "Customer P/N
         menge type ekpo-menge, "Order Qty.
         netpr type ekpo-netpr, "Unit Price
         waers type ekko-waers, "Currency
         eindt type eket-eindt, "Delivery Date(DD/MM/YYYY)
         aedat type ekko-aedat, "PO Creation Date
         netwr type ekpo-netwr,
         price(20),             "Unit Price
         qty(20),               "Order Qty.
         dldat(10),             "Delivery Date(DD/MM/YYYY)
         crdat(10),             "PO Creation Date(DD/MM/YYYY)
         meins type ekpo-meins,
         loekz type ekpo-loekz,
         peinh type ekpo-peinh,
         kunnr type lfa1-kunnr,
         amount(20),             "Unit Price,
         end of lt_xls.

  data : ls_xls like lt_xls,
         lv_len type i,
         lv_lines type i,
         lv_index type i,
         lv_total like ekpo-netwr,
         lv_amont like ekpo-netwr,
         lv_price like ekpo-netpr,
         lv_total_c(20) .

  data : begin of it_text occurs 0,
         text(255),
         end of it_text.
* get data
  select *
    from ekko as join ekpo as on a~ebeln b~ebeln
    join eket as on c~ebeln b~ebeln and c~ebelp b~ebelp
    left join mara as on d~matnr b~matnr
    left join lfa1 as on a~lifnr e~lifnr
    into corresponding fields of table lt_xls
    where a~ebeln p_ebeln.

* TXT Header
  concatenate  'Vtech Part No.' ',' "GC_TAB
               'PO#' ',' "GC_TAB
               'Line#' ',' "GC_TAB
               'Vendor Ordering No.' ',' "GC_TAB
               'Manufacturer' ',' "GC_TAB
               'Customer P/N' ',' "GC_TAB
               'Order Qty.' ',' "GC_TAB
               'Unit Price' ',' "GC_TAB
               'Amount' ',' "GC_TAB
               'Currency' ',' "GC_TAB
               'Delivery Date(DD/MM/YYYY)' ',' "GC_TAB
               'PO Creation Date(DD/MM/YYYY)' "CL_ABAP_CHAR_UTILITIES=>NEWLINE "GC_CRLF "
               into it_text-text.
  append it_text.
  clear  it_text.

  describe table lt_xls lines lv_lines.
  clear lv_index.
* XLS Lines
  loop at lt_xls into ls_xls.
    lv_index lv_index + 1.
    perform convert_price using ls_xls-netpr ls_xls-peinh ls_xls-waers changing ls_xls-price.
    if ls_xls-loekz <> 'L'.
      move ls_xls-menge to ls_xls-qty .
      condense ls_xls-qty.
    else.
      ls_xls-qty '0'.
    endif.
    lv_price ls_xls-price .
    lv_amont ls_xls-menge * lv_price.
    ls_xls-amount lv_amont.
    condense ls_xls-amount.
    lv_total lv_total +  lv_amont .

*    WRITE LS_XLS-AEDAT TO LS_XLS-CRDAT DD/MM/YYYY.
    perform convert_date_format using ls_xls-eindt changing ls_xls-dldat.
    perform convert_date_format using ls_xls-aedat changing ls_xls-crdat.

    if ls_xls-kunnr is not initial."Vendor also is customer
      select single kdmat into ls_xls-kdmat from knmt where matnr ls_xls-matnr and kunnr ls_xls-kunnr.
    endif.

    perform convert_matnr_foramt changing ls_xls-matnr.
    concatenate
                  ls_xls-matnr ',' "GC_TAB
                  ls_xls-ebeln ',' "GC_TAB
                  ls_xls-ebelp ',' "GC_TAB
                  ls_xls-mfrpn ',' "GC_TAB
                  ls_xls-mfrnr ',' "GC_TAB
                  ls_xls-kdmat ',' "GC_TAB
                  ls_xls-qty   ',' "GC_TAB
                  ls_xls-price ',' "GC_TAB
                  ls_xls-amount ','
                  ls_xls-waers ',' "GC_TAB
                  ls_xls-dldat ',' "GC_TAB
                  ls_xls-crdat "CL_ABAP_CHAR_UTILITIES=>NEWLINE "GC_CRLF "
                  into it_text-text.

    append it_text.
    clear it_text.
  endloop.
  lv_total_c lv_total  .
  condense lv_total_c .
  concatenate
                ''   ',' "GC_TAB
                '' ',' "GC_TAB
                '' ',' "GC_TAB
                '' ',' "GC_TAB
                '' ',' "GC_TAB
                '' ',' "GC_TAB
                ''  ',' "GC_TAB
                'Total' ',' "GC_TAB
                lv_total_c ','
                '' ',' "GC_TAB
                ''  ',' "GC_TAB
                ''  "CL_ABAP_CHAR_UTILITIES=>NEWLINE "GC_CRLF "
                into it_text-text.
  append it_text.
  clear it_text.
  it_text-text gc_crlf.
  append it_text.
  clear it_text.

  call function 'SCMS_TEXT_TO_BINARY'
    exporting
      mimetype      'TXT'
    importing
      output_length lv_len
    tables
      text_tab      it_text
      binary_tab    xls_content
    exceptions
      failed        1
      others        2.
  if sy-subrc <> 0.
  endif.
  xls_size lv_len 1."Remove the last blank line
endform.                    " FORAMT_XLS


*&---------------------------------------------------------------------*
*&      Form  SEND_MAIL_VIA_BCS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_SUBRC    text
*----------------------------------------------------------------------*
form send_mail_via_bcs using p_eblen  changing p_subrc.
* BCS data
  data  send_request       type ref to cl_bcs.
  data  text               type bcsy_text.
  data  document           type ref to cl_document_bcs.
  data  recipient          type ref to if_recipient_bcs.
  data  bcs_exception      type ref to cx_bcs.
  data  sent_to_all        type os_boolean.
  data  mailto             type adr6-smtp_addr.
  data  subject            type sood-objdes.
  data  subject_title      type sood-objdes.
  data  lv_send         type ad_smtpadr value 'cms-fax@vtech.com '.
  data  lo_sender         type ref to if_sender_bcs.

  p_subrc 4.


  concatenate 'Purchase order #' p_eblen 'waiting you approve' into subject_title separated by space.

  concatenate 'Purchase order' p_eblen into subject separated by space.

  append 'Dear Sirs/Madams' to text.
  append initial line to text.
  append '  This PO waiting you to approve, attachment of the PO detail for you reference.' to text.
  append initial line to text.
  append 'Thanks & regards' to text.
* end
  try.
*   ---------- create persistent send request ----------------------
      send_request cl_bcs=>create_persistent).

*   ---------- add document ----------------------------------------
      document cl_document_bcs=>create_document(
            i_type    'RAW'
            i_text    text
            i_subject subject_title ).

      if xls_content is not initial.
        document->add_attachment(
                   i_attachment_type 'CSV'
                   i_attachment_subject subject
                   i_attachment_size    xls_size
                   i_att_content_hex xls_content ).
      endif.

*   add document to send request
      send_request->set_documentdocument ).
*   add seng (e-mail address)
*-Sender(v_address = You can have static EMAIL Address for  sender or different EMAIL addresses )
      "gv_send = 'cms-fax@vtech.com '.
      lo_sender cl_cam_address_bcs=>create_internet_addresslv_send ).
      "Set sender
      send_request->set_senderlo_sender ).
*   ---------- add recipient (e-mail address) ----------------------
      loop at i_reclist.
        mailto i_reclist-receiver.
        recipient cl_cam_address_bcs=>create_internet_address(
            i_address_string mailto ).
*       ADD recipient TO send REQUEST
        send_request->add_recipienti_recipient recipient ).
      endloop.

*   ---------- send document ---------------------------------------
      sent_to_all send_request->send(
          i_with_error_screen 'X' ).

      if sent_to_all 'X'.
        p_subrc 0.
      endif.

*   ---------- explicit 'commit work' is mandatory! ----------------
      commit work.
* ------------------------------------------------------------------
* *            exception handling
* ------------------------------------------------------------------
* * replace this very rudimentary exception handling
* * with your own one !!!
* ------------------------------------------------------------------
    catch cx_bcs into bcs_exception.
      exit.
  endtry.
endform.                    " SEND_MAIL_VIA_BCS
*&---------------------------------------------------------------------*
*&      Form  CONVERT_DATE_FORMAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form convert_date_format  using    pi_date type sy-datum
                          changing pe_date.
  check pi_date is not initial.
  concatenate pi_date+6(2pi_date+4(2pi_date+0(4into pe_date separated by '/'.

endform.                    " CONVERT_DATE_FORMAT
*&---------------------------------------------------------------------*
*&      Form  CONVERT_MATNR_FORAMT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_LS_XLS_MATNR  text
*----------------------------------------------------------------------*
form convert_matnr_foramt  changing p_matnr.
  call function 'CONVERSION_EXIT_MATN1_OUTPUT'
    exporting
      input  p_matnr
    importing
      output p_matnr.

endform.                    " CONVERT_MATNR_FORAMT
*&---------------------------------------------------------------------*
*&      Form  CONVERT_PRICE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form convert_price  using    pi_netpr
                             pi_peinh
                             pi_waers
                    changing pe_price.
  data : lv_amount type bapicurr-bapicurr,
         lv_price(20).

  if pi_waers <> 'HKD' or pi_waers <> 'USD' or
     pi_waers <> 'CNY' or pi_waers <> 'EUR'.
    call function 'BAPI_CURRENCY_CONV_TO_EXTERNAL'
      exporting
        currency        pi_waers
        amount_internal pi_netpr
      importing
        amount_external lv_amount.
  else.
    lv_amount =  pi_netpr.
  endif.

  if pi_peinh <> 0.
    lv_amount lv_amount / pi_peinh.
  endif.

*  WRITE LV_AMOUNT TO LV_PRICE.
  move lv_amount to lv_price.
  condense lv_price.

  pe_price lv_price.
  condense pe_price.
endform.                    " CONVERT_PRICE
*M1 End


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值