ZPPR031:Update BOM Component Explosion type

38 篇文章 2 订阅

*&---------------------------------------------------------------------*
*& 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值