工艺路线当日创建或修改自动分配物料组件

*&---------------------------------------------------------------------*
*& Report  Z_CA01_BACKGROUND
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

工艺路线当日如果有新建或修改,将会重新分配物料.

程序定义成了后台作业.

前提是BOM中每个物都维护的排序字符串,排序字符串和工序的简称相同.作为自动分配组件的原则

report  z_ca01_background.

*AEDAT          2010.11.24
*AEUZEIT        15:10:11
*今日创建修改的工艺路线(PLKZ)
data: begin of i_matnr occurs 0,
      werks like mapl-werks,
      matnr like mapl-matnr,
      end of i_matnr.

 data subrc type sy-subrc.
data messtab like  bdcmsgcoll occurs 0.

data: matnr_001 type bdcdata-fval.
data: werks_002 type bdcdata-fval.
data: p_model type c.
data: w_msg(200) type c.


parameters  p_model1 type c radiobutton group r1.
parameters  p_model2 type c radiobutton group r1.
parameters  p_tag type c as checkbox.

 

if p_model1 eq 'X'.
  p_model = 'N'.
else.
  p_model = 'A'.

endif.


select distinct werks matnr
into corresponding fields of table i_matnr
from mapl
inner join plkz  on  mapl~plnnr = plkz~plnnr
where plkz~aedat eq sy-datum and loekz eq space and mapl~plnty = 'N'.

 

  loop at i_matnr.

 

  matnr_001 = i_matnr-matnr.

  werks_002 = i_matnr-werks.

 

  call function 'ZCA02'
   exporting
*   CTU                 = 'X'
   mode                = p_model
*   UPDATE              = 'L'
*   GROUP               = GROUP
*   USER                = USER
*   KEEP                = KEEP
*   HOLDDATE            = HOLDDATE
*   NODATA              = '/'
     matnr_001           = matnr_001
     werks_002           = werks_002
*   PLNNR_003           = '10008203'
*   STTAG_004           = '2010.11.08'
*   PLNAL_005           = ''
*   ENTRY_ACT_006       = '1'
*   SORTF_007           = 'X'
*   SORTF_008           = 'ai'
*   VORNR_009           = '0010'
*   PLNFL_010           = '0'
*   SORTF_011           = 'X'
*   SORTF_012           = 'dip'
*   VORNR_013           = '0020'
*   PLNFL_014           = '0'
   p_tag = p_tag
   importing
     subrc               = subrc
 tables
   messtab             = messtab
            .

endloop.

function zca02.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(CTU) LIKE  APQI-PUTACTIVE DEFAULT 'X'
*"     VALUE(MODE) LIKE  APQI-PUTACTIVE DEFAULT 'N'
*"     VALUE(UPDATE) LIKE  APQI-PUTACTIVE DEFAULT 'L'
*"     VALUE(GROUP) LIKE  APQI-GROUPID OPTIONAL
*"     VALUE(USER) LIKE  APQI-USERID OPTIONAL
*"     VALUE(KEEP) LIKE  APQI-QERASE OPTIONAL
*"     VALUE(HOLDDATE) LIKE  APQI-STARTDATE OPTIONAL
*"     VALUE(NODATA) LIKE  APQI-PUTACTIVE DEFAULT '/'
*"     VALUE(MATNR_001) LIKE  BDCDATA-FVAL DEFAULT '120201355'
*"     VALUE(WERKS_002) LIKE  BDCDATA-FVAL DEFAULT '1000'
*"     VALUE(PLNNR_003) LIKE  BDCDATA-FVAL DEFAULT '10008203'
*"     VALUE(STTAG_004) LIKE  BDCDATA-FVAL DEFAULT '2010.11.08'
*"     VALUE(PLNAL_005) LIKE  BDCDATA-FVAL DEFAULT ''
*"     VALUE(ENTRY_ACT_006) LIKE  BDCDATA-FVAL DEFAULT '1'
*"     VALUE(SORTF_007) LIKE  BDCDATA-FVAL DEFAULT 'X'
*"     VALUE(SORTF_008) LIKE  BDCDATA-FVAL DEFAULT 'ai'
*"     VALUE(VORNR_009) LIKE  BDCDATA-FVAL DEFAULT '0010'
*"     VALUE(PLNFL_010) LIKE  BDCDATA-FVAL DEFAULT '0'
*"     VALUE(SORTF_011) LIKE  BDCDATA-FVAL DEFAULT 'X'
*"     VALUE(SORTF_012) LIKE  BDCDATA-FVAL DEFAULT 'dip'
*"     VALUE(VORNR_013) LIKE  BDCDATA-FVAL DEFAULT '0020'
*"     VALUE(PLNFL_014) LIKE  BDCDATA-FVAL DEFAULT '0'
*"     VALUE(P_TAG) TYPE  C1 OPTIONAL
*"  EXPORTING
*"     VALUE(SUBRC) LIKE  SYST-SUBRC
*"  TABLES
*"      MESSTAB STRUCTURE  BDCMSGCOLL OPTIONAL
*"----------------------------------------------------------------------

  data wa_messatab like bdcmsgcoll.
  data i_capp_com like table of capp_com with header line.
 data: begin of i_stb occurs 0.
         include structure stpox.
 data: end of i_stb.
 data: l_werks like marc-werks.
 data: wa_zca02_log like zca02_log.

  data: w_msg(200) type c.

 

*定义工序信息,
  data i_opr like table of capp_opr with header line.
  data i_opr_bom like table of capp_opr with header line.

  tables  mapl.
  data: wa_matnr like mara-matnr.

    data: l_matnr like mara-matnr.

 

*查找物料的工序信息放入内标。

  select single * from mapl
  where matnr = matnr_001 and werks = werks_002 and loekz = space.


  call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
    exporting
      input  = mapl-matnr
    importing
      utput = wa_matnr.

  l_werks = werks_002.

  call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input  = wa_matnr
    importing
      utput = l_matnr.

 


  call function 'CARO_ROUTING_READ'
    exporting
*   DATE_FROM                  = '19000101'
*   DATE_TO                    = '99991231'
      plnty                      = mapl-plnty
      plnnr                      = mapl-plnnr
      plnal                      = mapl-plnal
     matnr                      = l_matnr
*   BUFFER_DEL_FLG             = 'X'
*   DELETE_ALL_CAL_FLG         = 'X'
*   ADAPT_FLG                  = 'X'
*   IV_CREATE_ADD_CHANGE       = ' '
   tables
*   TSK_TAB                    = TSK_TAB
*   SEQ_TAB                    = SEQ_TAB
     opr_tab                    = i_opr
*   PHASE_TAB                  = PHASE_TAB
*   SUBOPR_TAB                 = SUBOPR_TAB
*   REL_TAB                    = REL_TAB
*   com_tab                    = i_capp_com
*   REFERR_TAB                 = REFERR_TAB
*   REFMIS_TAB                 = REFMIS_TAB
   exceptions
     not_found                  = 1
     ref_not_exp                = 2
     not_valid                  = 3
            .
*需要先关联到BOM表取排序字符串

*    IF LINES( i_capp_com ) *      CLEAR w_msg.
*      CONCATENATE  '物料:'  matnr_001+9(9) '工厂:'   werks_002 '没有组件' INTO w_msg.
*      WRITE :/ w_msg COLOR COL_NEGATIVE.
*      EXIT.
*    ENDIF.

*通过展BOM来获取排序字符串
    call function 'CS_BOM_EXPL_MAT_V2'
     exporting
          capid  = 'PP01'
          datuv  = sy-datum          "BOM用效日期.
          ehndl  = '1'
          emeng  = 1
          mtnrv  = l_matnr
          mehrs  = 'X'             "多层BOM展开标记.
          mmory  = '1'
*          stlal  = '1'              "代用BOM.
*          stlan  = w_stlan "s_stlan-low           "BOM用途.
          stpst  = '99'
          werks  = l_werks           "P_WERKS.
*       importing
*            topmat = selpool
*            dstst  = dstst_flg
     tables
          stb    = i_stb              "存放BOM项目.
*          matcat = matcat
      exceptions
         alt_not_found         =  4
         call_invalid          =  8
         material_not_foun     = 12
*         OBJECT_NOT_FOUND      = 12
         missing_authorization = 16
         no_bom_found          = 20
         no_plant_data         = 24
         no_suitable_bom_found = 28
         conversion_error      = 32.

sort i_stb by sortf.
delete adjacent duplicates from i_stb comparing sortf.


loop at i_stb.
  if i_stb-sortf ne space.
    i_opr_bom-ktsch =  i_stb-sortf.
    append i_opr_bom.
  endif.
endloop.


*  SELECT sortf AS ktsch
*    FROM stpo
*   INTO CORRESPONDING FIELDS OF TABLE i_opr_bom
*    FOR ALL ENTRIES IN i_capp_com
*    WHERE stlnr = i_capp_com-stlnr AND stlkn =  i_capp_com-stlkn.
*比较工序中文本和BOM中文本,如果BOM中文本和工序中不同,则退出不做。
  loop at i_opr_bom.

    read table i_opr with key ktsch =  i_opr_bom-ktsch.
    if sy-subrc ne 0.
      clear w_msg.
      concatenate  '物料:'  matnr_001+9(9) '工厂:'   werks_002 'BOM排序字符串:'  i_opr_bom-ktsch '在工序中不存在' INTO w_msg.
      WRITE :/ w_msg COLOR COL_NEGATIVE.
      CLEAR WA_ZCA02_LOG.
      WA_ZCA02_LOG-DATUM = SY-DATUM.
      WA_ZCA02_LOG-UZEIT = SY-UZEIT.
      WA_ZCA02_LOG-MATNR = matnr_001.
      WA_ZCA02_LOG-WERKS = WERKS_002.
      WA_ZCA02_LOG-MSG = W_MSG.
       WA_ZCA02_LOG-SUCC_TAG = '失败'.

      INSERT ZCA02_LOG FROM WA_ZCA02_LOG.
      REJECT.
    ENDIF.

  ENDLOOP.

 

 

 

  subrc = 0.
  IF LINES( i_opr ) > 0.

    PERFORM. bdc_nodata      USING nodata.

    PERFORM. open_group      USING group user keep holddate ctu.

    PERFORM. bdc_dynpro      USING 'saplcpdi' '1010'.
    PERFORM. bdc_field       USING 'bdc_cursor'
                                  'rc27m-werks'.
    PERFORM. bdc_field       USING 'bdc_okcode'
                                  '/00'.
    PERFORM. bdc_field       USING 'rc27m-matnr'
                                  matnr_001+9(9).
    PERFORM. bdc_field       USING 'rc27m-werks'
                                  werks_002.
    PERFORM. bdc_field       USING 'rc271-plnnr'
                                  mapl-plnnr.
    PERFORM. bdc_field       USING 'rc271-sttag'
                                  sy-datum.                 "sttag_004.
    PERFORM. bdc_field       USING 'rc271-plnal'
                                  plnal_005.
    PERFORM. bdc_dynpro      USING 'saplcpdi' '1400'.
    PERFORM. bdc_field       USING 'bdc_cursor'
                                  'rc27x-entry_act'.
    PERFORM. bdc_field       USING 'bdc_okcode'
                                  '=mata'.
    PERFORM. bdc_field       USING 'rc27x-entry_act'
                                  entry_act_006.
    PERFORM. bdc_dynpro      USING 'saplcmdi' '1000'.
    PERFORM. bdc_field       USING 'bdc_cursor'
                                  'rcm01-matnr'.
    PERFORM. bdc_field       USING 'bdc_okcode'
                                  '=mara'.
    PERFORM. bdc_dynpro      USING 'saplcmdi' '1000'.
    PERFORM. bdc_field       USING 'bdc_cursor'
                                  'rcm01-matnr'.
    PERFORM. bdc_field       USING 'bdc_okcode'
                                  '=del'.
    PERFORM. bdc_dynpro      USING 'saplspo1' '0100'.
    PERFORM. bdc_field       USING 'bdc_okcode'
                                  '=yes'.
    PERFORM. bdc_dynpro      USING 'saplcmdi' '1000'.
    PERFORM. bdc_field       USING 'bdc_cursor'
                                  'rcm01-matnr'.


    LOOP AT i_opr.

*排序字符串过滤条件
      PERFORM. bdc_field       USING 'bdc_okcode'
                                    '=filt'.
      PERFORM. bdc_dynpro      USING 'saplcm01' '1070'.
      PERFORM. bdc_field       USING 'bdc_cursor'
                                    'd1070-sortf'.
      PERFORM. bdc_field       USING 'bdc_okcode'
                                    '=pick'.
      PERFORM. bdc_field       USING 'd1070-sortf'
                                    sortf_007.
      PERFORM. bdc_dynpro      USING 'saplcm01' '1080'.
      PERFORM. bdc_field       USING 'bdc_cursor'
                                    'stpo-sortf'.
      PERFORM. bdc_field       USING 'bdc_okcode'
                                    '/00'.
      PERFORM. bdc_field       USING 'stpo-sortf'
                                    i_opr-ktsch.
      PERFORM. bdc_dynpro      USING 'saplcmdi' '1000'.
      PERFORM. bdc_field       USING 'bdc_cursor'
                                    'rcm01-matnr'.
      PERFORM. bdc_field       USING 'bdc_okcode'
                                    '=mara'.
      PERFORM. bdc_dynpro      USING 'saplcmdi' '1000'.
      PERFORM. bdc_field       USING 'bdc_cursor'
                                    'rcm01-matnr'.
      PERFORM. bdc_field       USING 'bdc_okcode'
                                    '=new'.
      PERFORM. bdc_dynpro      USING 'saplcm01' '1090'.
      PERFORM. bdc_field       USING 'bdc_cursor'
                                    'rcm01-vornr'.
      PERFORM. bdc_field       USING 'bdc_okcode'
                                    '=goon'.
      PERFORM. bdc_field       USING 'rcm01-vornr'
                                    i_opr-vornr.
      PERFORM. bdc_field       USING 'rcm01-plnfl'
                                    plnfl_010.
      PERFORM. bdc_dynpro      USING 'saplcmdi' '1000'.
      PERFORM. bdc_field       USING 'bdc_cursor'
                                    'rcm01-matnr'.


*perform. bdc_field       using 'BDC_OKCODE'
*                              '=FILT'.
*perform. bdc_dynpro      using 'SAPLCM01' '1070'.
*perform. bdc_field       using 'BDC_CURSOR'
*                              'D1070-SORTF'.
*perform. bdc_field       using 'BDC_OKCODE'
*                              '=PICK'.
*perform. bdc_field       using 'D1070-SORTF'
*                              SORTF_011.
*perform. bdc_dynpro      using 'SAPLCM01' '1080'.
*perform. bdc_field       using 'BDC_CURSOR'
*                              'STPO-SORTF'.
*perform. bdc_field       using 'BDC_OKCODE'
*                              '/00'.
*perform. bdc_field       using 'STPO-SORTF'
*                              SORTF_012.
*perform. bdc_dynpro      using 'SAPLCMDI' '1000'.
*perform. bdc_field       using 'BDC_CURSOR'
*                              'RCM01-MATNR'.
*perform. bdc_field       using 'BDC_OKCODE'
*                              '=MARA'.
*perform. bdc_dynpro      using 'SAPLCMDI' '1000'.
*perform. bdc_field       using 'BDC_CURSOR'
*                              'RCM01-MATNR'.
*perform. bdc_field       using 'BDC_OKCODE'
*                              '=NEW'.
*perform. bdc_dynpro      using 'SAPLCM01' '1090'.
*perform. bdc_field       using 'BDC_CURSOR'
*                              'RCM01-VORNR'.
*perform. bdc_field       using 'BDC_OKCODE'
*                              '=GOON'.
*perform. bdc_field       using 'RCM01-VORNR'
*                              VORNR_013.
*perform. bdc_field       using 'RCM01-PLNFL'
*                              PLNFL_014.
*perform. bdc_dynpro      using 'SAPLCMDI' '1000'.
*perform. bdc_field       using 'BDC_CURSOR'
*                              'RCM01-MATNR'.


    ENDLOOP.

    PERFORM. bdc_field       USING 'bdc_okcode'
                                 '=bu'.

 

*提交
    PERFORM. bdc_transaction TABLES messtab
    USING                         'ca02'
                                  ctu
                                  mode
                                  update.
    IF sy-subrc 0.
      subrc = sy-subrc.
*      EXIT.
    ENDIF.

 

  ENDIF.
  IF subrc NE 0.
    LOOP AT messtab INTO wa_messatab ."WHERE  msgtyp NE 's'.
      CLEAR w_msg.
      CONCATENATE  '物料:'  matnr_001+9(9) '工厂:'   werks_002 '分配组件失败  '  wa_messatab-msgv1   wa_messatab-msgv2  wa_messatab-msgv3   wa_messatab-msgv4 INTO w_msg.
      WRITE :/ w_msg COLOR COL_NEGATIVE.
       CLEAR WA_ZCA02_LOG.
      WA_ZCA02_LOG-DATUM = SY-DATUM.
      WA_ZCA02_LOG-UZEIT = SY-UZEIT.
      WA_ZCA02_LOG-MATNR = matnr_001.
      WA_ZCA02_LOG-WERKS = WERKS_002.
      WA_ZCA02_LOG-MSG = W_MSG.
       WA_ZCA02_LOG-SUCC_TAG = '失败'.

      INSERT ZCA02_LOG FROM WA_ZCA02_LOG.

    ENDLOOP.

  ELSE.
    IF p_tag EQ space.
      CLEAR w_msg.
      CONCATENATE :  '物料:'  matnr_001+9(9) '工厂:' werks_002 '分配组件成功' INTO w_msg .

      WRITE :/  w_msg COLOR COL_POSITIVE.
      CLEAR WA_ZCA02_LOG.
      WA_ZCA02_LOG-DATUM = SY-DATUM.
      WA_ZCA02_LOG-UZEIT = SY-UZEIT.
      WA_ZCA02_LOG-MATNR = matnr_001.
      WA_ZCA02_LOG-WERKS = WERKS_002.
      WA_ZCA02_LOG-MSG = W_MSG.
       WA_ZCA02_LOG-SUCC_TAG = '成功'.
      INSERT ZCA02_LOG FROM WA_ZCA02_LOG.


    ENDIF.
  ENDIF.
  ULINE.

  PERFORM. close_group USING     ctu.


ENDFUNCTION.
INCLUDE bdcrecxy .

 

 

上一篇:驱动第九天


下一篇:C#修改文件或文件夹的权限,为指定用户、用户组添加完全控制权限