ZPPR031:Update BOM Component Explosion type

本文介绍了一个用于更新物料清单(BOM)组件爆炸类型的程序,该程序能够检查特定条件下物料A1的子物料A12的爆炸类型,并依据检查结果进行相应修改。

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

*&---------------------------------------------------------------------*
*& Progarm      :  ZPPR031                        Author : Jimmy Wong
*& Created      :  29 Nov 2012                    App    : PP
*& Title        :  Update BOM Component Explosion type
*& Description  :     获取当某一物料A1的子物料A12(都不是ZLGP),检查子物料A12是否在另一个ZLGP的物料B12中,
*&                    检查这ZLGP的物料B12作为子物料B12是否存在另一个物料B1(非ZLGP),
*&                    如果存在,检查ZLGP的物料B12中的子物料A12的 Usage prob。
*&                两种情况需要修改
*&                1、  当子物料A12 的Explosion type <> 1  and B12 中A12 Usage prob 存在不等于100
*&                      则把子物料A12 的Explosion type修改成 1
*&                2、  当子物料A12 的Explosion type = 1 and B12 中A12 Usage prob 都是 100
*&                      则把子物料A12 的Explosion type修改成 space
*&---------------------------------------------------------------------*
*&  Version       Author      Date        description
*&                Jimmy       04 Dec 2012 the first version
*&  the last update time  2012.12.04 16:00
*&---------------------------------------------------------------------*

report  zppr031 no standard page heading.

tables:mast,mara.
data:begin of it_matnr occurs 0,
    werks like mast-werks,
    matnr like mast-matnr,
    mtart like mara-mtart,
    idnrk like mast-matnr,
    posnr like stpo-posnr,
    mtart_s like mara-mtart,
    dspst like stpo-dspst,
    dspst_new like stpo-dspst,
    gp_matnr type c length 255,
    stlan like mast-stlan,
    datuv like stko-datuv,
    stlnr like stpo-stlnr,
    stlty like stpo-stlty,
    end of it_matnr.

data:begin of it_100 occurs 0,
    werks like mast-werks,
    matnr like mast-matnr,
    mtart like mara-mtart,
    idnrk like mast-matnr,
    mtart_s like mara-mtart,
    ewahr like stpo-ewahr,
    end of it_100.
data: it_no100 like it_100 occurs 0 with header line.

data:begin of it_mara occurs 0,
    matnr like mara-matnr,
    mtart like mara-mtart,
    end of it_mara.
data:begin of it_idnrk occurs 0,
    werks like mast-werks,
    idnrk like mast-matnr,
    end of it_idnrk.
data:it_matnr1 like it_matnr occurs 0 with header line.
data:itab like it_matnr occurs 0 with header line.
data:it_log like zpp031 occurs 0 with header line.
type-pools: slis.
data: fc_hier type slis_t_fieldcat_alv,
      wa_hier type slis_fieldcat_alv .
data:lv_total_line type i,
   lv_line type p decimals 3.
data: it_bdcmsg like bdcmsgcoll occurs 0 with header line,
      bdcdata like bdcdata occurs 0 with header line,
      it_return like  bapiret2 occurs 0 with header line.
data: begin of ltb occurs 0.
        include structure stpov.
data: end of ltb.
data:lv_matnr like mara-matnr.

selection-screen begin of block 1 with frame title text-001.
select-options : s_werks for mast-werks  default '8101'.
select-options : s_matnr for mast-matnr .
select-options : s_smatnr for mast-matnr.
select-options : s_mtart for mara-mtart.
parameters: p_datuv like stko-datuv default sy-datum .
parameters: pr_mode  type ctu_mode default 'N' obligatory .
selection-screen skip.
parameters p_test as checkbox default 'X' .
selection-screen end of block 1.

*&---------------------------------------------------------------------*
* start of process
*&---------------------------------------------------------------------*
start-of-selection.

  if p_datuv is initial.
    p_datuv = sy-datum.
  endif.
  perform get_data.
  if itab[] is initial .
    message 'No Record Found' type 'I'.
    exit.
  endif.
  if p_test = 'X'.
    perform display_data.
  else.
    perform process_data_bdc.
  endif.
  perform write_log.
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_data .
  call function 'SAPGUI_PROGRESS_INDICATOR'
    exporting
      text = 'Getting Data........'.
  if s_matnr[] is not initial.
    select distinct m~werks p~idnrk
        into corresponding fields of table it_idnrk
      from stpo as p inner join stko as k  on p~stlnr = k~stlnr and p~stlty = k~stlty
                  inner join mast as m on m~stlnr = k~stlnr and m~stlal = k~stlal
                  inner join mara as a on a~matnr = m~matnr
                  inner join mara as b on b~matnr = p~idnrk
      where m~matnr in s_matnr
        and m~werks in s_werks
        and a~mtart in s_mtart
        and a~mtart ne 'ZLGP'
        and p~idnrk in s_smatnr
        and p~postp = 'L'
        and p~datuv >=  p_datuv
        and k~datuv >=  p_datuv
        and k~loekz = space.
    if it_idnrk[] is not initial.
      sort it_idnrk by werks idnrk.
      select  m~matnr m~werks p~idnrk p~ewahr b~mtart a~mtart as mtart_s
          into corresponding fields of table  it_100
          from stpo as p
            inner join stko as k on p~stlnr = k~stlnr and p~stlty = k~stlty
            inner join mast as m on m~stlnr = k~stlnr and m~stlal = k~stlal
            inner join mara as a on a~matnr = p~idnrk
            inner join mara as b on b~matnr = m~matnr
          for all entries in it_idnrk
          where b~mtart = 'ZLGP'
            and m~werks = it_idnrk-werks
            and p~idnrk = it_idnrk-idnrk
            and a~mtart ne 'ZLGP'
            and p~postp = 'L'
            and p~ewahr = 100
            and k~loekz = space
            and p~datuv >=  p_datuv
            and k~datuv >=  p_datuv.

      select m~matnr m~werks p~idnrk p~ewahr b~mtart a~mtart as mtart_s
         into corresponding fields of table  it_no100
         from stpo as p
           inner join stko as k on p~stlnr = k~stlnr and p~stlty = k~stlty
           inner join mast as m on m~stlnr = k~stlnr and m~stlal = k~stlal
           inner join mara as a on a~matnr = p~idnrk
           inner join mara as b on b~matnr = m~matnr
          for all entries in it_idnrk
         where b~mtart = 'ZLGP'
           and m~werks = it_idnrk-werks
           and p~idnrk = it_idnrk-idnrk
           and a~mtart ne 'ZLGP'
           and p~postp = 'L'
           and p~ewahr ne 100
           and k~loekz = space
           and p~datuv >=  p_datuv
           and k~datuv >=  p_datuv.
    endif.

  else.
    select distinct m~matnr m~werks p~idnrk p~ewahr b~mtart a~mtart as mtart_s
     into corresponding fields of table  it_100
     from stpo as p
       inner join stko as k on p~stlnr = k~stlnr and p~stlty = k~stlty
       inner join mast as m on m~stlnr = k~stlnr and m~stlal = k~stlal
       inner join mara as a on a~matnr = p~idnrk
       inner join mara as b on b~matnr = m~matnr
     where b~mtart = 'ZLGP'
       and m~werks in s_werks
       and p~idnrk in s_smatnr
       and a~mtart ne 'ZLGP'
       and p~postp = 'L'
       and p~ewahr = 100
       and k~loekz = space
       and p~datuv >=  p_datuv
       and k~datuv >=  p_datuv.

    select distinct m~matnr m~werks p~idnrk p~ewahr b~mtart a~mtart as mtart_s
     into corresponding fields of table  it_no100
     from stpo as p
       inner join stko as k on p~stlnr = k~stlnr and p~stlty = k~stlty
       inner join mast as m on m~stlnr = k~stlnr and m~stlal = k~stlal
       inner join mara as a on a~matnr = p~idnrk
       inner join mara as b on b~matnr = m~matnr
     where b~mtart = 'ZLGP'
       and m~werks in s_werks
       and p~idnrk in s_smatnr
       and a~mtart ne 'ZLGP'
       and p~postp = 'L'
       and p~ewahr ne 100
       and k~loekz = space
       and p~datuv >=  p_datuv
       and k~datuv >=  p_datuv.
  endif.
  "check 100 的记录是否再 ne 100里面,在的话删除
  loop at it_100.
    read table it_no100 with  key  werks = it_100-werks idnrk = it_100-idnrk .
    if sy-subrc eq 0.
      delete it_100.
    endif.
  endloop.


  if it_100[] is not initial.
    sort it_100 by werks idnrk .

    select m~matnr  m~werks p~idnrk  a~mtart p~dspst a~mtart  as mtart_s p~posnr
           m~stlan k~datuv  k~stlnr k~stlty
        into corresponding fields of table it_matnr
      from stpo as p inner join stko as k  on p~stlnr = k~stlnr and p~stlty = k~stlty
                  inner join mast as m on m~stlnr = k~stlnr and m~stlal = k~stlal
                  inner join mara as a on a~matnr = m~matnr
                  inner join mara as b on b~matnr = p~idnrk
      for all entries in it_100
      where m~matnr in s_matnr
        and m~werks = it_100-werks
        and a~mtart in s_mtart
        and a~mtart ne 'ZLGP'
        and p~idnrk  = it_100-idnrk
        and p~postp = 'L'
        and p~dspst = '1'
        and p~datuv >=  p_datuv
        and k~datuv >=  p_datuv
        and k~loekz = space.
    if it_matnr[] is not initial.
      loop at it_100.
        read table it_matnr with  key idnrk = it_100-idnrk   werks = it_100-werks.
        if sy-subrc ne 0.
          delete it_100.
        endif.
      endloop.
      "判断zlgp的 是否存在不是zlgp的物料里面
      perform get_check_zlgp_data tables it_100.

      loop at it_matnr .
        read table it_100 with  key idnrk = it_matnr-idnrk   werks = it_matnr-werks.
        if sy-subrc ne 0.
          delete it_matnr.
        else.
          if p_test = 'X'.
            loop at it_100 where werks = it_matnr-werks and idnrk = it_matnr-idnrk .
              perform tranfer_material using it_100-matnr changing lv_matnr.
              if it_matnr-gp_matnr is initial.
                it_matnr-gp_matnr = lv_matnr.
              else.
                concatenate   it_matnr-gp_matnr lv_matnr into it_matnr-gp_matnr separated by ','.
              endif.
              clear:lv_matnr.
            endloop.
            modify it_matnr transporting gp_matnr.
          endif.
        endif.
      endloop.
    else.
      refresh it_100.
    endif.
  endif.


  if it_no100[] is not initial.
    sort it_no100 by werks idnrk .
    select m~matnr  m~werks p~idnrk  a~mtart p~dspst   a~mtart  as mtart_s p~posnr
           m~stlan  k~datuv  k~stlnr k~stlty
        into corresponding fields of table it_matnr1
      from stpo as p inner join stko as k  on p~stlnr = k~stlnr and p~stlty = k~stlty
                  inner join mast as m on m~stlnr = k~stlnr and m~stlal = k~stlal
                  inner join mara as a on a~matnr = m~matnr
                  inner join mara as b on b~matnr = p~idnrk
      for all entries in it_no100
      where m~matnr in s_matnr
        and m~werks = it_no100-werks
        and a~mtart in s_mtart
        and a~mtart ne 'ZLGP'
        and p~idnrk  = it_no100-idnrk
        and p~postp = 'L'
        and p~dspst ne '1'
        and p~datuv >=  p_datuv
        and k~datuv >=  p_datuv
        and k~loekz = space.
    if it_matnr1[] is not initial.
      loop at it_no100.
        read table it_matnr1 with  key idnrk = it_no100-idnrk   werks = it_no100-werks.
        if sy-subrc ne 0.
          delete it_no100.
        endif.
      endloop.
      perform get_check_zlgp_data tables it_no100.
      loop at it_matnr1 .
        read table it_no100 with  key idnrk = it_matnr1-idnrk   werks = it_matnr1-werks.
        if sy-subrc ne 0.
          delete it_matnr1.
        else.
          it_matnr1-dspst_new = '1'.
          if p_test = 'X'.
            loop at it_no100 where werks = it_matnr1-werks and idnrk = it_matnr1-idnrk .
              perform tranfer_material using it_no100-matnr changing lv_matnr.
              if it_matnr1-gp_matnr is initial.
                it_matnr1-gp_matnr = lv_matnr.
              else.
                concatenate   it_matnr1-gp_matnr lv_matnr into it_matnr1-gp_matnr separated by ','.
              endif.
              clear:lv_matnr.
            endloop.
            modify it_matnr1 transporting dspst_new gp_matnr.
          else.
            modify it_matnr1 transporting dspst_new gp_matnr.
          endif.
        endif.
      endloop.
      sort it_matnr1 by werks matnr idnrk.
    else.
      refresh it_no100.
    endif.
  endif.

  append lines of it_matnr to itab.
  append lines of it_matnr1 to itab.
  sort itab by matnr werks stlan datuv.

endform.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  TRANFER_MATERIAL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_ITAB_MATNR  text
*      <--P_ITAB_MATNR_C  text
*----------------------------------------------------------------------*
form  tranfer_material using    p_old
                       changing p_new  .
  translate p_old to upper case.
  call function 'CONVERSION_EXIT_MATN1_OUTPUT'
    exporting
      input        = p_old
    importing
      output       = p_new
    exceptions
      length_error = 1
      others       = 2.
  if sy-subrc <> 0.
    p_new = p_old.
  endif.
endform.                    "tranfer_material

*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
form bdc_dynpro using program dynpro.
  clear bdcdata.
  bdcdata-program  = program.
  bdcdata-dynpro   = dynpro.
  bdcdata-dynbegin = 'X'.
  append bdcdata.
endform.                    "BDC_DYNPRO

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
form bdc_field using fnam fval.
  clear bdcdata.
  bdcdata-fnam = fnam.
  bdcdata-fval = fval.
  append bdcdata.
endform.                    "BDC_FIELD
*&--------------------------------------------
*&---------------------------------------------------------------------*
*&      Form  WRITE_LOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form write_log .
  if not it_log[] is initial.
    modify zpp031 from table it_log.
    refresh it_log.
    free:it_matnr,it_log,itab,it_matnr1,it_100,it_no100,it_mara.
  endif.
endform.                    " WRITE_LOG
*&---------------------------------------------------------------------*
*&      Form  GET_USED_MATERIAL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_IT_MATNR_IDNRK  text
*      -->P_IT_MATNR_WERKS  text
*      <--P_LTB  text
*----------------------------------------------------------------------*
form get_used_material  using    p_matnr
                                 p_erks
                        changing p_subrc .
  data:pm_datub like stpo-datuv,
         pm_datuv like stpo-datuv,
         pm_postp like stpo-postp,
         pm_stlan like stzu-stlan ,
         pm_idnrk like stpo-idnrk,                          "YHG078090
         pm_werks like marc-werks .
  data: begin of selpool.
          include structure mc29s.
  data: end of selpool.
*  data: begin of ltb occurs 0.
*          include structure stpov.
*  data: end of ltb.
  data: begin of equicat  occurs 0.
          include structure cscequi.
  data: end of equicat .
  data: begin of kndcat   occurs 0.
          include structure cscknd.
  data: end of kndcat  .
  data: begin of matcat   occurs 0.
          include structure cscmat.
  data: end of matcat  .

  data: begin of stdcat   occurs 0.
          include structure cscstd.
  data: end of stdcat  .
  data: begin of tplcat   occurs 0.
          include structure csctpl.
  data: end of tplcat  .

  pm_datuv  = sy-datum.
  pm_idnrk = p_matnr.
  pm_werks  = p_erks.

  call function 'CS_WHERE_USED_MAT_ANY'
    exporting
      datub                      = pm_datub
      datuv                      = pm_datuv
      matnr                      = pm_idnrk
      postp                      = pm_postp
      stlan                      = pm_stlan
      werks                      = pm_werks
    importing
      topmat                     = selpool
    tables
      wultb                      = ltb
      equicat                    = equicat
      kndcat                     = kndcat
      matcat                     = matcat
      stdcat                     = stdcat
      tplcat                     = tplcat
    exceptions
      call_invalid               = 1
      material_not_found         = 2
      no_where_used_rec_found    = 3
      no_where_used_rec_selected = 4
      no_where_used_rec_valid    = 5
      others                     = 6.
  p_subrc = sy-subrc.
endform.                    " GET_USED_MATERIAL
*&---------------------------------------------------------------------*
*&      Form  PROCESS_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form process_data_bdc .
  data:lv_dat(10) type c.
  describe table itab lines lv_total_line.
  loop at itab.
    lv_line =  sy-tabix  / lv_total_line * 100.
    call function 'SAPGUI_PROGRESS_INDICATOR'
      exporting
        percentage = lv_line
        text       = 'Changing BOM........'.
    it_log-bldat = sy-datum.
    it_log-aezet = sy-uzeit.
    it_log-werks = itab-werks.
    it_log-matnr = itab-matnr.
    it_log-idnrk = itab-idnrk.
    it_log-dspst_old = itab-dspst.
    it_log-dspst_new = itab-dspst_new.
    it_log-posnr = itab-posnr.
    it_log-stlnr = itab-stlnr.
    it_log-stlty = itab-stlty.
    it_log-stlan = itab-stlan.
    it_log-datuv = itab-datuv.

    perform bdc_dynpro      using 'SAPLCSDI' '0100'.
    perform bdc_field       using 'BDC_CURSOR' 'RC29N-STLAN'.
    perform bdc_field       using 'BDC_OKCODE' '/00'.
    perform bdc_field       using 'RC29N-MATNR' it_log-matnr.
    perform bdc_field       using 'RC29N-WERKS' it_log-werks.
    perform bdc_field       using 'RC29N-STLAN' it_log-stlan.
    perform bdc_field       using 'RC29N-STLAL'  '01'. "PRD default '01' no '02' '03'
    perform change_date_format using itab-datuv changing lv_dat.
    perform bdc_field       using 'RC29N-DATUV'
                                  lv_dat.

    perform bdc_dynpro      using 'SAPLCSDI' '0150'.
    perform bdc_field       using 'BDC_CURSOR' 'RC29P-POSNR(01)'.
    perform bdc_field       using 'BDC_OKCODE' '=SETP'.


    perform bdc_dynpro      using 'SAPLCSDI' '0708'.
    perform bdc_field       using 'BDC_OKCODE' '=CLWI'.
    perform bdc_field       using 'BDC_CURSOR' 'RC29P-SELID'.
    perform bdc_field       using 'RC29P-SELID' it_log-idnrk.
    perform bdc_field       using 'RC29P-SELPO' it_log-posnr.


    perform bdc_dynpro      using 'SAPLCSDI' '0150'.
    perform bdc_field       using 'BDC_CURSOR'   'RC29P-AUSKZ(01)'.
    perform bdc_field       using 'BDC_OKCODE' '=PALL'.
    perform bdc_field       using 'RC29P-AUSKZ(01)' 'X'.

 

    perform bdc_dynpro      using 'SAPLCSDI' '2130'.
    perform bdc_field       using 'BDC_OKCODE' '=FCBU'.
    perform bdc_field       using 'BDC_CURSOR'  'RC29P-DSPST'.
*    perform bdc_field       using 'RC29P-POSNR'
*                                  record-posnr_007.
*    perform bdc_field       using 'RC29P-IDNRK'
*                                  record-idnrk_008.
*    perform bdc_field       using 'RC29P-MENGE'
*                                  record-menge_009.
*    perform bdc_field       using 'RC29P-MEINS'
*                                  record-meins_010.
    perform bdc_field       using 'RC29P-DSPST' it_log-dspst_new.

    call transaction 'CS02'
             using bdcdata
             mode pr_mode "Background performance
             update 'S' "local updata
             messages into it_bdcmsg. "all message table

    call function 'CONVERT_BDCMSGCOLL_TO_BAPIRET2'
      tables
        imt_bdcmsgcoll = it_bdcmsg
        ext_return     = it_return.

    read table it_return with key type = 'E'.
    if sy-subrc eq 0.
      it_log-msgds = it_return-message.
    else.
      read table it_return with key type = 'S' id = '29' number = '031'.
      if sy-subrc eq 0.
        it_log-msgds  =  'OK'.
      else.
        loop at  it_return.
          if it_log-msgds  is initial.
            it_log-msgds =  it_return-message .
          else.
            concatenate it_log-msgds  it_return-message into it_log-msgds  separated by space.
          endif.
        endloop.
      endif.
    endif.
    append it_log.
    clear:it_log.
  endloop.
endform.                    " PROCESS_DATA
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form display_data .
  define alv_field.
    clear:wa_hier.
    wa_hier-fieldname = &1.
    wa_hier-seltext_m = &2.
    wa_hier-seltext_l = &3.
    wa_hier-outputlen = &4.
    wa_hier-just = &5.
    wa_hier-do_sum = &6.
    wa_hier-ref_tabname = &7 .
    wa_hier-ref_fieldname = &8 .
    append wa_hier to fc_hier.
  end-of-definition.
  refresh: fc_hier.
  alv_field  'WERKS' 'Plant' '' '5' 'L' '' '' ''.
  alv_field  'MTART' '' 'Material Type' '10' 'L' '' '' ''.
  alv_field  'MATNR' '' 'Material' '18' 'L' '' 'MARA' 'MATNR'.
  alv_field  'STLAN' '' 'BOM Usage' '6' 'L' '' '' ''.
  alv_field  'IDNRK' '' 'Component' '18' 'L' '' 'MARA' 'MATNR'.
  alv_field  'GP_MATNR' '' 'Logic Group' '40' 'L' '' '' ''.
  alv_field  'DSPST' '' 'Old Explosion type' '15' 'L' ''  '' ''.
  alv_field  'DSPST_NEW' '' 'New Explosion type' '15' 'L' ''  '' ''.

  free:it_matnr,it_matnr1,it_100,it_no100,it_mara.

  call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      it_fieldcat        = fc_hier[]
      i_save             = 'A'
      i_callback_program = sy-repid
    tables
      t_outtab           = itab[]
    exceptions
      program_error      = 1
      others             = 2.

endform.                    " DISPLAY_DATA

" GET_CHECK_ZLGP_DATA
*&---------------------------------------------------------------------*
*&      Form  GET_CHECK_ZLGP_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_IT_100  text
*----------------------------------------------------------------------*
form get_check_zlgp_data  tables   p_100 structure it_100.
  data:u_subrc like sy-subrc.
  sort p_100 by werks matnr idnrk.

  loop at  p_100.
    perform get_used_material using p_100-matnr p_100-werks
                              changing u_subrc .

    if u_subrc  eq 0.
      if ltb[] is not initial.
        select matnr mtart
          into corresponding fields of table it_mara
          from mara
          for all entries in ltb
          where matnr = ltb-matnr
            and mtart ne 'ZLGP'.
        if sy-subrc ne 0.
          delete p_100.
        endif.
      else.
        delete p_100.
      endif.
    else.
      delete p_100.
    endif.
    clear:ltb, it_mara.
    refresh:ltb, it_mara.
  endloop.
endform.                    " GET_CHECK_ZLGP_DATA
*&---------------------------------------------------------------------*
*&      Form  CHANGE_DATE_FORMAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_<GT_OUT>_DATUV  text
*      <--P_LV_DAT  text
*      <--P_PERFORM  text
*      <--P_BDC_FIELD  text
*      -->P_0208   text
*      -->P_<GT_OUT>_DATUV  text
*----------------------------------------------------------------------*
form change_date_format  using pi_date changing pt_date.
  call function 'CONVERT_DATE_TO_EXTERNAL'
    exporting
      date_internal            = pi_date
    importing
      date_external            = pt_date
    exceptions
      date_internal_is_invalid = 1
      others                   = 2.
  if sy-subrc <> 0.
    message 'Date Format Error' type 'E'.
  endif.
endform.                    " CHANGE_DATE_FORMAT

 

循环处理

loop at it_matnr.
    lv_tabix sy-tabix.
    read table it_bom with key werks_h it_matnr-werks_h matnr_h it_matnr-matnr_h matnr_m it_matnr-matnr_m .
    if sy-subrc eq 0.
      if p_test is initial.
        perform bdc_dynpro      using 'SAPLCSDI' '0100'.
        perform bdc_field       using 'BDC_CURSOR' 'RC29N-STLAN'.
        perform bdc_field       using 'BDC_OKCODE' '/00'.
        perform bdc_field       using 'RC29N-MATNR' it_matnr-matnr_m.
        perform bdc_field       using 'RC29N-WERKS' it_matnr-werks_h.
        perform bdc_field       using 'RC29N-STLAN' '1'.
        perform bdc_field       using 'RC29N-STLAL'  '01'. "PRD default '01' no '02' '03'
        perform change_date_format using sy-datum 'X' changing lv_dat.  "itab-datuv
        perform bdc_field       using 'RC29N-DATUV'
                                      lv_dat.
        loop at  it_bom where  werks_h it_matnr-werks_h and matnr_h it_matnr-matnr_h and  matnr_m it_matnr-matnr_m .

          perform bdc_dynpro      using 'SAPLCSDI' '0150'.
          perform bdc_field       using 'BDC_CURSOR' 'RC29P-POSNR(01)'.
          perform bdc_field       using 'BDC_OKCODE' '=SETP'.


          perform bdc_dynpro      using 'SAPLCSDI' '0708'.
          perform bdc_field       using 'BDC_OKCODE' '=CLWI'.
          perform bdc_field       using 'BDC_CURSOR' 'RC29P-SELID'.
          perform bdc_field       using 'RC29P-SELID' it_bom-matnr_l.
          perform bdc_field       using 'RC29P-SELPO'  it_bom-posnr.


          perform bdc_dynpro      using 'SAPLCSDI' '0150'.
          perform bdc_field       using 'BDC_CURSOR'   'RC29P-AUSKZ(01)'.
          perform bdc_field       using 'BDC_OKCODE' '=PALL'.
          perform bdc_field       using 'RC29P-AUSKZ(01)' 'X'.



          perform bdc_dynpro      using 'SAPLCSDI' '2130'.
          perform bdc_field       using 'BDC_OKCODE' '/EBACK'.
          perform bdc_field       using 'BDC_CURSOR'  'RC29P-DSPST'.
          perform bdc_field       using 'RC29P-DSPST' p_dispo.
        endloop.

        perform bdc_dynpro      using 'SAPLCSDI' '0150'.
        perform bdc_field       using 'BDC_CURSOR' 'RC29P-POSNR(01)'.
        perform bdc_field       using 'BDC_OKCODE'  '=FCBU'.

        call transaction 'CS02'
           using bdcdata
           mode p_mode  "Background performance
           update 'S' "local updata
           messages into it_bdcmsg. "all message table


        call function 'CONVERT_BDCMSGCOLL_TO_BAPIRET2'
          tables
            imt_bdcmsgcoll it_bdcmsg
            ext_return     it_return.

        read table it_return with key type 'E'.
        if sy-subrc eq 0.
          it_matnr-message it_return-message.
        else.
          read table it_return with key type 'S' id '29' number '031'.
          if sy-subrc eq 0.
            it_matnr-message =  'OK'.
          else.
            loop at  it_return.
              if it_matnr-message is initial.
                it_matnr-message =  it_return-message .
              else.
                concatenate it_matnr-message  it_return-message into it_matnr-message  separated by space.
              endif.
            endloop.
          endif.
        endif.
        clear: it_return,it_return[],it_bdcmsg,it_bdcmsg[],bdcdata,bdcdata[].
      endif.
    else.
      it_matnr-message 'Material no exists or no explosion BOM.'.
    endif.
    modify it_matnr index lv_tabix .
    clear:it_matnr-message ,lv_dat.
  endloop.

*&---------------------------------------------------------------------* *& Report ZPPR0010 *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zppr0010. *----------------------------------------------------------------------- * TYPE-POOLS *----------------------------------------------------------------------- TYPE-POOLS:truxs,slis. TABLES:afko. *----------------------------------------------------------------------- * Structures *----------------------------------------------------------------------- TYPES: BEGIN OF ty_data, aufnr TYPE afko-aufnr, posnr TYPE afpo-posnr, old_menge TYPE bapi_network_comp_detail-entry_quantity, new_menge TYPE bapi_network_comp_detail-entry_quantity, status_text TYPE bapi_network_comp_detail-status_text, message TYPE string, END OF ty_data. TYPES:BEGIN OF ty_afko, check(1), aufnr TYPE afko-aufnr, text TYPE string, END OF ty_afko. *--------------------------------------------------------------------* * Tables *--------------------------------------------------------------------* DATA: it_data TYPE STANDARD TABLE OF ty_data, wa_data TYPE ty_data. DATA: it_afko TYPE STANDARD TABLE OF ty_afko, wa_afko TYPE ty_afko. DATA: it_zco001 TYPE STANDARD TABLE OF zco001, wa_zco001 TYPE zco001. DATA: it_zco002 TYPE STANDARD TABLE OF zco002, wa_zco002 TYPE zco002. DATA: it_zco003 TYPE STANDARD TABLE OF zco003, wa_zco003 TYPE zco003. DATA: it_zco004 TYPE STANDARD TABLE OF zco004, wa_zco004 TYPE zco004. DATA: it_components_detail LIKE TABLE OF bapi_network_comp_detail, wa_components_detail LIKE bapi_network_comp_detail. DATA: it_components_change LIKE TABLE OF bapi_network_comp_change, wa_components_change LIKE bapi_network_comp_change. DATA: it_components_change_update LIKE TABLE OF bapi_network_comp_cng_upd, wa_components_change_update LIKE bapi_network_comp_cng_upd. DATA: wa_return LIKE bapiret2, it_message_table LIKE TABLE OF bapi_meth_message, wa_message_table LIKE bapi_meth_message. DATA: it_fieldcat TYPE slis_t_fieldcat_alv. DATA: wa_fieldcat TYPE LINE OF slis_t_fieldcat_alv. DATA: it_fieldcat_afko TYPE slis_t_fieldcat_alv. DATA: wa_fieldcat_afko TYPE LINE OF slis_t_fieldcat_alv. DATA: it_layout TYPE slis_layout_alv. DATA: it_variant TYPE disvariant. DATA: it_sort TYPE slis_t_sortinfo_alv, wa_sort TYPE LINE OF slis_t_sortinfo_alv. DATA: it_resb TYPE STANDARD TABLE OF resbdget. DATA: l_number LIKE bapi_network_list-network, l_entry_quantity LIKE bapi_network_comp_detail-entry_quantity, l_original_quantity LIKE bapi_network_comp_detail-original_quantity. * tresbd LIKE resbdget OCCURS 0 WITH HEADER LINE, *--------------------------------------------------------------------* * SELECTION-SCREEN *--------------------------------------------------------------------* SELECT-OPTIONS: s_aufnr FOR afko-aufnr. *PARAMETERS: p_y *--------------------------------------------------------------------* * Initialization *--------------------------------------------------------------------* INITIALIZATION. *--------------------------------------------------------------------* * AT SELECTION-SCREEN *--------------------------------------------------------------------* AT SELECTION-SCREEN OUTPUT. *--------------------------------------------------------------------* * START-OF-SELECTION *--------------------------------------------------------------------* START-OF-SELECTION. PERFORM frm_get_data. *--------------------------------------------------------------------* * START-OF-SELECTION *--------------------------------------------------------------------* END-OF-SELECTION. PERFORM frm_alv_fieldcat_afko. PERFORM frm_layout. PERFORM frm_display_afko . *&---------------------------------------------------------------------* *& Form FRM_GET_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_get_data . SELECT * INTO CORRESPONDING FIELDS OF TABLE it_afko FROM afko WHERE aufnr IN s_aufnr. * IF it_afko[] IS INITIAL. * MESSAGE '没有查询到可用数据!' TYPE 'S' DISPLAY LIKE 'E'. * LEAVE LIST-PROCESSING. * ENDIF. SELECT * INTO CORRESPONDING FIELDS OF TABLE it_zco001 FROM zco001. SELECT * INTO CORRESPONDING FIELDS OF TABLE it_zco002 FROM zco002. SELECT * INTO CORRESPONDING FIELDS OF TABLE it_zco003 FROM zco003 FOR ALL ENTRIES IN it_afko WHERE aufnr = it_afko-aufnr. SELECT * INTO CORRESPONDING FIELDS OF TABLE it_zco004 FROM zco004 FOR ALL ENTRIES IN it_afko WHERE aufnr = it_afko-aufnr. LOOP AT it_afko INTO wa_afko. READ TABLE it_zco004 INTO wa_zco004 WITH KEY aufnr = wa_afko-aufnr. IF sy-subrc = 0. wa_afko-text = '此订单损耗已经被计算过。'. ENDIF. MODIFY it_afko FROM wa_afko. CLEAR: wa_afko, wa_zco004. ENDLOOP. ENDFORM. " FRM_GET_DATA *&---------------------------------------------------------------------* *& FORM FRM_ALV_FIELDCAT *&---------------------------------------------------------------------* * TEXT *----------------------------------------------------------------------* FORM frm_alv_fieldcat . CLEAR:it_fieldcat. DATA: pos TYPE i. CLEAR wa_fieldcat. pos = pos + 1. wa_fieldcat-col_pos = pos. wa_fieldcat-fieldname = 'AUFNR'. wa_fieldcat-ref_fieldname = 'AUFNR'. wa_fieldcat-ref_tabname = 'AFKO'. APPEND wa_fieldcat TO it_fieldcat. CLEAR wa_fieldcat. pos = pos + 1. wa_fieldcat-col_pos = pos. wa_fieldcat-fieldname = 'POSNR'. wa_fieldcat-ref_fieldname = 'POSNR'. wa_fieldcat-ref_tabname = 'AFPO'. APPEND wa_fieldcat TO it_fieldcat. CLEAR wa_fieldcat. pos = pos + 1. wa_fieldcat-col_pos = pos. wa_fieldcat-fieldname = 'OLD_MENGE'. wa_fieldcat-ref_fieldname = 'ENTRY_QUANTITY'. wa_fieldcat-ref_tabname = 'BAPI_NETWORK_COMP_DETAIL'. APPEND wa_fieldcat TO it_fieldcat. CLEAR wa_fieldcat. pos = pos + 1. wa_fieldcat-col_pos = pos. wa_fieldcat-fieldname = 'NEW_MENGE'. wa_fieldcat-seltext_s = '修正数量'. APPEND wa_fieldcat TO it_fieldcat. CLEAR wa_fieldcat. pos = pos + 1. wa_fieldcat-col_pos = pos. wa_fieldcat-fieldname = 'STATUS_TEXT'. wa_fieldcat-seltext_s = '状态'. APPEND wa_fieldcat TO it_fieldcat. CLEAR wa_fieldcat. pos = pos + 1. wa_fieldcat-col_pos = pos. wa_fieldcat-fieldname = 'MESSAGE'. wa_fieldcat-seltext_s = '说明'. APPEND wa_fieldcat TO it_fieldcat. ENDFORM. "FRM_ALV_FIELDCAT *&---------------------------------------------------------------------* *& FORM FRM_LAYOUT *&---------------------------------------------------------------------* * TEXT *----------------------------------------------------------------------* FORM frm_layout . it_layout-zebra = 'X'. it_layout-colwidth_optimize = 'X'. ENDFORM. " FRM_LAYOUT *&---------------------------------------------------------------------* *& FORM FRM_DISPLAY *&---------------------------------------------------------------------* * TEXT *----------------------------------------------------------------------* FORM frm_display . it_variant-handle = '2'. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = sy-repid * i_callback_pf_status_set = 'FRM_SETSTATUS' i_save = 'A' is_layout = it_layout it_fieldcat = it_fieldcat * i_grid_title = title it_sort = it_sort * i_callback_user_command = 'FRM_USER_COMMAND' is_variant = it_variant TABLES t_outtab = it_data EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ENDFORM. "FRM_DISPLAY *&---------------------------------------------------------------------* *& Form frm_user_command *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->LP_UCOMM text * -->LS_SELFIELD text *----------------------------------------------------------------------* FORM frm_user_command USING lp_ucomm TYPE sy-ucomm ls_selfield TYPE slis_selfield. DATA: l_row TYPE i. DATA: l_field TYPE char30, l_value TYPE char30. DATA:gr_alvgrid TYPE REF TO cl_gui_alv_grid. CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING e_grid = gr_alvgrid. CALL METHOD gr_alvgrid->check_changed_data. CASE lp_ucomm. WHEN '&SAVE'. PERFORM frm_deal_data. PERFORM frm_alv_fieldcat. * PERFORM frm_layout. PERFORM frm_display . WHEN 'ALL'. LOOP AT it_afko INTO wa_afko. wa_afko-check = 'X'. MODIFY it_afko FROM wa_afko. ENDLOOP. WHEN 'SAL'. LOOP AT it_afko INTO wa_afko. wa_afko-check = ''. MODIFY it_afko FROM wa_afko. ENDLOOP. WHEN '&CHAN'. LOOP AT it_afko INTO wa_afko WHERE check = 'X'. wa_afko-text = '删除成功.'. DELETE FROM zco004 WHERE aufnr = wa_afko-aufnr. MODIFY it_afko FROM wa_afko. ENDLOOP. ENDCASE. ls_selfield-refresh = 'X'. ENDFORM. "frm_user_command *&---------------------------------------------------------------------* *& Form fRM_setstatus *&---------------------------------------------------------------------* * 鎷疯礉绋嬪簭SAPLKKBL涓殑'STANDARD' GUI status *----------------------------------------------------------------------* * -->PT_EXTAB text *----------------------------------------------------------------------* FORM frm_setstatus USING pt_extab TYPE slis_t_extab. "鍥哄畾鍙傛暟 SET PF-STATUS 'STANDARD'. ENDFORM. "setstatus *&---------------------------------------------------------------------* *& Form FRM_DEAL_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_deal_data . SORT it_zco001 BY matnr. SORT it_zco002 BY matkl. SORT it_zco003 BY aufnr. SORT it_zco004 BY component aufnr posnr. CLEAR:it_data. LOOP AT it_afko INTO wa_afko WHERE check = 'X'. l_number = wa_afko-aufnr. CALL FUNCTION 'BAPI_NETWORK_COMP_GETDETAIL' EXPORTING number = l_number TABLES e_components_detail = it_components_detail. IF it_components_detail[] IS NOT INITIAL. LOOP AT it_components_detail INTO wa_components_detail. CLEAR:wa_zco001, wa_zco002, wa_zco003, wa_zco004, l_entry_quantity, wa_components_change_update, wa_components_change. READ TABLE it_zco004 INTO wa_zco004 WITH KEY component = wa_components_detail-component aufnr = wa_components_detail-network posnr = wa_components_detail-item_number BINARY SEARCH. IF sy-subrc = 0. wa_data-message = '此行数据已经更新过。'. ELSE. "优先考虑特殊损耗ZCO001 READ TABLE it_zco001 INTO wa_zco001 WITH KEY matnr = wa_components_detail-material BINARY SEARCH. IF sy-subrc = 0. l_entry_quantity = ceil( wa_components_detail-entry_quantity * ( 1 + wa_zco001-zrate ) ). l_original_quantity = ceil( wa_components_detail-original_quantity * ( 1 + wa_zco001-zrate ) ). ELSE. READ TABLE it_zco002 INTO wa_zco002 WITH KEY matkl = wa_components_detail-matl_group BINARY SEARCH. IF sy-subrc = 0. l_entry_quantity = ceil( wa_components_detail-entry_quantity * ( 1 + wa_zco002-zrate ) ). l_original_quantity = ceil( wa_components_detail-original_quantity * ( 1 + wa_zco002-zrate ) ). * ELSE. * CONTINUE. ENDIF. ENDIF. IF l_entry_quantity IS NOT INITIAL. wa_components_change-component = wa_components_detail-component. IF l_original_quantity <> 0. wa_components_change-original_quantity = l_original_quantity. wa_components_change-entry_quantity = l_entry_quantity. ELSE. wa_components_change-entry_quantity = l_entry_quantity. ENDIF. APPEND wa_components_change TO it_components_change. wa_components_change_update-component = wa_components_detail-component. IF l_original_quantity <> 0. wa_components_change_update-original_quantity = 'X'. wa_components_change_update-entry_quantity = 'X'. ELSE. wa_components_change_update-entry_quantity = 'X'. ENDIF. APPEND wa_components_change_update TO it_components_change_update. wa_data-message = '更新完成'. wa_zco004-component = wa_components_detail-component. wa_zco004-activity = wa_components_detail-activity. wa_zco004-aufnr = wa_components_detail-network. wa_zco004-posnr = wa_components_detail-item_number. wa_zco004-new_menge = l_entry_quantity. wa_zco004-old_menge = wa_components_detail-entry_quantity. MODIFY zco004 FROM wa_zco004. ELSE. wa_data-message = '不满足更新条件'. wa_zco004-component = wa_components_detail-component. wa_zco004-activity = wa_components_detail-activity. wa_zco004-aufnr = wa_components_detail-network. wa_zco004-posnr = wa_components_detail-item_number. wa_zco004-new_menge = l_entry_quantity. wa_zco004-old_menge = wa_components_detail-entry_quantity. ENDIF. ENDIF. MOVE-CORRESPONDING wa_zco004 TO wa_data. wa_data-status_text = wa_components_detail-status_text. APPEND wa_data TO it_data. CLEAR:wa_zco004,wa_data. ENDLOOP. IF it_components_change[] IS NOT INITIAL. CALL FUNCTION 'BAPI_NETWORK_COMP_CHANGE' EXPORTING number = l_number IMPORTING return = wa_return TABLES i_components_change = it_components_change i_components_change_update = it_components_change_update e_message_table = it_message_table. IF wa_return-type <> 'E'. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. ELSE. LOOP AT it_data INTO wa_data WHERE aufnr = wa_components_detail-network. wa_data-message = '订单组件数量修改不被允许。'. MODIFY it_data FROM wa_data. ENDLOOP. DELETE FROM zco004 WHERE aufnr = wa_components_detail-network. ENDIF. ENDIF. ENDIF. CLEAR:l_number, wa_components_change, wa_components_change_update, wa_afko, wa_return, it_components_change[], it_components_change_update[], it_message_table[], it_components_detail[]. ENDLOOP. ENDFORM. " FRM_DEAL_DATA *&---------------------------------------------------------------------* *& Form FRM_ALV_FIELDCAT_AFKO *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_alv_fieldcat_afko . DATA: pos TYPE i. CLEAR wa_fieldcat_afko. pos = pos + 1. wa_fieldcat_afko-col_pos = pos. wa_fieldcat_afko-fieldname = 'CHECK'. wa_fieldcat_afko-checkbox = 'X'. wa_fieldcat_afko-edit = 'X'. APPEND wa_fieldcat_afko TO it_fieldcat_afko. CLEAR wa_fieldcat_afko. pos = pos + 1. wa_fieldcat_afko-col_pos = pos. wa_fieldcat_afko-fieldname = 'AUFNR'. wa_fieldcat_afko-ref_fieldname = 'AUFNR'. wa_fieldcat_afko-ref_tabname = 'AFKO'. APPEND wa_fieldcat_afko TO it_fieldcat_afko. CLEAR wa_fieldcat_afko. pos = pos + 1. wa_fieldcat_afko-col_pos = pos. wa_fieldcat_afko-fieldname = 'TEXT'. wa_fieldcat_afko-seltext_s = '备注'. APPEND wa_fieldcat_afko TO it_fieldcat_afko. ENDFORM. " FRM_ALV_FIELDCAT_AFKO *&---------------------------------------------------------------------* *& Form FRM_DISPLAY_AFKO *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_display_afko . it_variant-handle = '1'. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = sy-repid i_callback_pf_status_set = 'FRM_SETSTATUS' i_save = 'A' is_layout = it_layout it_fieldcat = it_fieldcat_afko * i_grid_title = title it_sort = it_sort i_callback_user_command = 'FRM_USER_COMMAND' is_variant = it_variant TABLES t_outtab = it_afko EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ENDFORM. " FRM_DISPLAY_AFKO
最新发布
07-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值