1 用CA02打开主机的工艺路线。
2 点击组件分配,显示主机装配层物料组件分配的情况。
3 先筛选项目没有分配物料,再按照排序字符串的工位进行筛选。
4 根据排序字符串工位信息将物料对应分配至对应工位。如:组件的排序字符串是101,则该物料分配至101工位。
5 按照排序字符串的信息,将物料新健分配。
TABLES:MAST,STKO,STPO,MAKT,MARC,MARA,MAPL,PLKO.
DATA: T_STB LIKE TABLE OF STPOX WITH HEADER LINE.
DATA: T_STB_TEMP LIKE TABLE OF STPOX WITH HEADER LINE.
DATA: G_MAT LIKE TABLE OF CSCMAT WITH HEADER LINE.
DATA: BDCMESS LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF ISHOW OCCURS 0,
MATNR LIKE MARC-MATNR,
WERKS LIKE MARC-WERKS,
MSG(200),
END OF ISHOW.
DATA: BEGIN OF LT_SORTF OCCURS 0,
SORTF LIKE STPO-SORTF,
END OF LT_SORTF.
DATA: BEGIN OF GT_MAST OCCURS 0,
MATNR LIKE MAST-MATNR,
WERKS LIKE MAST-WERKS,
STLAN LIKE MAST-STLAN,
STLNR LIKE MAST-STLNR,
STLAL LIKE MAST-STLAL,
END OF GT_MAST.
DATA: BEGIN OF GT_ROUTING OCCURS 0,
MATNR LIKE MAPL-MATNR,
WERKS LIKE MAPL-WERKS,
PLNTY LIKE MAPL-PLNTY,
PLNNR LIKE MAPL-PLNNR,
PLNAL LIKE MAPL-PLNAL,
END OF GT_ROUTING.
DATA: BEGIN OF LT_MAST OCCURS 0,
MATNR LIKE MAST-MATNR,
WERKS LIKE MAST-WERKS,
STLAN LIKE MAST-STLAN,
STLNR LIKE MAST-STLNR,
STLAL LIKE MAST-STLAL,
END OF LT_MAST.
DATA: BEGIN OF BDCDATA OCCURS 0.
INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDCDATA.
DATA: BEGIN OF MSG_WA,
MSGID LIKE SY-MSGID,
MSGNR LIKE SY-MSGNO,
MSGV1 LIKE SY-MSGV1,
MSGV2 LIKE SY-MSGV2,
MSGV3 LIKE SY-MSGV3,
MSGV4 LIKE SY-MSGV4,
END OF MSG_WA.
DATA : ERR(1).
DATA : G_ROUTING TYPE I.
DATA : G_BOM TYPE I.
DATA : L_ENTRY_ACT(10) TYPE C.
DATA : L_FVAL TYPE BDC_FVAL.
DATA : POS TYPE I,N(2) TYPE N,INDEX TYPE N.
DATA : L_VORNR TYPE VORNR,
L_PLNFL TYPE PLNFOLGE.
DATA : BDC_MODE(1), MSGTEXT(255).
DATA : T_TABIX LIKE SY-TABIX, BK_MODE(1), MSG(255).
*&---------------------------------------------------------------------*
*& 屏幕显示
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : P_MATNR FOR MARC-MATNR NO INTERVALS OBLIGATORY.
PARAMETERS : P_WERKS LIKE MARC-WERKS OBLIGATORY.
PARAMETERS : P_MASK TYPE CHAR1 OBLIGATORY DEFAULT '-'. "分隔符
PARAMETERS : P_STLAN LIKE MAST-STLAN OBLIGATORY DEFAULT '1'.
PARAMETERS : P_STLAL LIKE MAST-STLAL OBLIGATORY DEFAULT '01'.
PARAMETERS : P_MODE(1) OBLIGATORY DEFAULT 'A'.
SELECTION-SCREEN END OF BLOCK B1.
*&---------------------------------------------------------------------*
*& 程序执行
*&---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM CHECK_INPUT.
PERFORM CALL_BDC.
PERFORM SHOW.
*&---------------------------------------------------------------------*
*& Form check_input
*&---------------------------------------------------------------------*
FORM CHECK_INPUT .
IF P_MATNR-LOW IS INITIAL OR P_WERKS IS INITIAL.
MESSAGE '请输入物料和工厂数据!' TYPE 'E'.
STOP.
ENDIF.
ENDFORM. " check_input
*&---------------------------------------------------------------------*
*& Form bom_explode
*&---------------------------------------------------------------------*
FORM BOM_EXPLODE USING TEMP_MATNR.
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
CAPID = 'PP01'
DATUV = SY-DATUM
EMENG = '1'
MKTLS = 'X'
BREMS = 'X' "展开到虚拟件
MEHRS = 'X' "多层展开,'X'表示是,''表示否
MMORY = '1'
MTNRV = TEMP_MATNR
STLAL = P_STLAL
STLAN = P_STLAN
STPST = 0
SVWVO = 'X'
WERKS = P_WERKS
VRSVO = 'X'
TABLES
STB = T_STB
MATCAT = G_MAT
EXCEPTIONS
ALT_NOT_FOUND = 1
CALL_INVALID = 2
MATERIAL_NOT_FOUND = 3
MISSING_AUTHORIZATION = 4
NO_BOM_FOUND = 5
NO_PLANT_DATA = 6
NO_SUITABLE_BOM_FOUND = 7
CONVERSION_ERROR = 8
OTHERS = 9.
ENDFORM. "BOM_explode
*&---------------------------------------------------------------------*
*& Form call_bdc
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM CALL_BDC .
LOOP AT P_MATNR.
* *检查BOM
ERR = ''.
CLEAR GT_MAST.
REFRESH GT_MAST.
SELECT MATNR WERKS STLAN STLNR STLAL
INTO CORRESPONDING FIELDS OF TABLE GT_MAST
FROM MAST
WHERE MATNR = P_MATNR-LOW
AND WERKS = P_WERKS
AND STLAL = P_STLAL.
SORT GT_MAST BY STLAL ASCENDING.
DESCRIBE TABLE GT_MAST LINES G_BOM.
IF G_BOM = 0.
ISHOW-MATNR = P_MATNR-LOW.
ISHOW-WERKS = P_WERKS.
ISHOW-MSG = '无BOM'.
APPEND ISHOW.
CLEAR ISHOW.
CONTINUE.
ENDIF.
* 检查工艺
CLEAR GT_ROUTING.
REFRESH GT_ROUTING.
SELECT MATNR WERKS PLNTY PLNNR PLNAL
INTO CORRESPONDING FIELDS OF TABLE GT_ROUTING
FROM MAPL
WHERE MATNR = P_MATNR-LOW
AND WERKS = P_WERKS
AND PLNAL = P_STLAL.
SORT GT_ROUTING BY PLNAL ASCENDING.
DESCRIBE TABLE GT_ROUTING LINES G_ROUTING.
IF G_ROUTING = 0.
ISHOW-MATNR = P_MATNR-LOW.
ISHOW-WERKS = P_WERKS.
ISHOW-MSG = '无工艺'.
APPEND ISHOW.
CLEAR ISHOW.
CONTINUE.
ENDIF.
*得到组件
* 展开BOM
CLEAR : T_STB,T_STB[].
PERFORM BOM_EXPLODE USING P_MATNR-LOW.
*执行
READ TABLE GT_MAST INDEX 1.
READ TABLE GT_ROUTING INDEX 1.
*得到需要分配的字符串
CLEAR LT_SORTF.
REFRESH LT_SORTF.
* 找父MATNR
SORT T_STB BY IDNRK.
T_STB_TEMP[] = T_STB[].
SORT T_STB_TEMP BY IDNRK.
LOOP AT T_STB WHERE SORTF <> ''.
SEARCH T_STB-SORTF FOR P_MASK.
IF SY-SUBRC = 0.
LT_SORTF-SORTF = T_STB-SORTF.
APPEND LT_SORTF.
CLEAR LT_SORTF.
ENDIF.
ENDLOOP.
SORT LT_SORTF.
DELETE ADJACENT DUPLICATES FROM LT_SORTF.
IF LT_SORTF[] IS INITIAL.
ISHOW-MATNR = P_MATNR-LOW.
ISHOW-WERKS = P_WERKS.
ISHOW-MSG = '无更改'.
APPEND ISHOW.
CLEAR ISHOW.
ELSE.
* BDC
CLEAR BDCDATA.
REFRESH BDCDATA.
PERFORM BDC_DYNPRO USING 'SAPLCPDI' '1010'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RC27M-MATNR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=ALUE'.
PERFORM BDC_FIELD USING 'RC27M-MATNR'
P_MATNR-LOW.
PERFORM BDC_FIELD USING 'RC27M-WERKS'
P_WERKS.
* 选择工艺路线1,2
IF G_ROUTING > 1.
L_ENTRY_ACT = 1.
ELSE.
READ TABLE GT_ROUTING WITH KEY PLNAL = P_STLAL.
L_ENTRY_ACT = SY-TABIX.
ENDIF.
PERFORM BDC_DYNPRO USING 'SAPLCPDI' '1200'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'RC27X-ENTRY_ACT'
L_ENTRY_ACT.
* *点击工艺按钮
PERFORM BDC_DYNPRO USING 'SAPLCPDI' '1200'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=MATA'.
* 全部删除
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'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=FILT'.
PERFORM BDC_DYNPRO USING 'SAPLCM01' '1070'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'D1070-NOASS'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=PICK'.
PERFORM BDC_FIELD USING 'D1070-NOASS'
'X'.
* 判断有组件没有分配
LOOP AT LT_SORTF.
* 查找
PERFORM BDC_DYNPRO USING 'SAPLCMDI' '1000'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RCM01-MATNR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=FIND'.
PERFORM BDC_DYNPRO USING 'SAPLCM01' '1055'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'SEARCH_BY-SORTF'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=GOON'.
PERFORM BDC_FIELD USING 'SEARCH_BY-SORTF'
LT_SORTF-SORTF.
PERFORM BDC_FIELD USING 'FIRST_HIT'
''.
PERFORM BDC_FIELD USING 'SEARCH_BY-MARK_ALL'
'X'.
* 新建分配
CLEAR : L_VORNR,L_PLNFL.
SPLIT LT_SORTF-SORTF AT P_MASK INTO L_PLNFL L_VORNR.
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'
L_VORNR.
PERFORM BDC_FIELD USING 'RCM01-PLNFL'
L_PLNFL.
ENDLOOP.
PERFORM BDC_DYNPRO USING 'SAPLCMDI' '1000'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RCM01-MATNR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BU'.
BDC_MODE = P_MODE.
CALL TRANSACTION 'CA02' USING BDCDATA
UPDATE 'S' MODE BDC_MODE
MESSAGES INTO BDCMESS.
* bdc结束
CLEAR: MSG.
LOOP AT BDCMESS WHERE MSGTYP = 'E'
OR MSGTYP = 'A'
OR MSGTYP = 'S'.
IF BDCMESS-MSGID = 'CV' AND BDCMESS-MSGNR = '761'.
CONTINUE.
ENDIF.
CLEAR MSGTEXT.
MOVE-CORRESPONDING BDCMESS TO MSG_WA.
CALL FUNCTION 'TB_MESSAGE_BUILD_TEXT'
EXPORTING
LANGU = SY-LANGU
MSGID = MSG_WA-MSGID
MSGNO = MSG_WA-MSGNR
MSGV1 = MSG_WA-MSGV1
MSGV2 = MSG_WA-MSGV2
MSGV3 = MSG_WA-MSGV3
MSGV4 = MSG_WA-MSGV4
IMPORTING
TEXT = MSGTEXT.
CONCATENATE MSGTEXT '|' MSG INTO MSG.
CLEAR: BDCMESS, MSG_WA.
ENDLOOP.
IF MSG <> ''.
ISHOW-MATNR = P_MATNR-LOW.
ISHOW-WERKS = P_WERKS.
ISHOW-MSG = MSG. "'组件分配存在问题,请使用 A前台模式'.
APPEND ISHOW.
CLEAR ISHOW.
ELSE.
ISHOW-MATNR = P_MATNR-LOW.
ISHOW-WERKS = P_WERKS.
ISHOW-MSG = '组件分配成功!'.
APPEND ISHOW.
CLEAR ISHOW.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " call_bdc
*&---------------------------------------------------------------------*
*& Form bdc_dynpro
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM. "bdc_dynpro
*&---------------------------------------------------------------------*
*& Form bdc_dynpro
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDFORM. "bdc_field
*&---------------------------------------------------------------------*
*& Form SHOW
*&---------------------------------------------------------------------*
FORM SHOW .
TYPE-POOLS SLIS.
DATA: WS_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
WS_FIELDGROUPS_TAB TYPE SLIS_T_SP_GROUP_ALV,
WS_LAYOUT TYPE SLIS_LAYOUT_ALV,
WS_SORTFIELDS_TAB TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE,
WS_EVENTS TYPE SLIS_T_EVENT.
DATA: V_REPID LIKE SY-REPID.
DATA: NN TYPE I VALUE 0.
DATA: TITLE TYPE LVC_TITLE.
SORT ISHOW BY MATNR.
DEFINE HOUT.
NN = NN + 1.
WS_FIELDCAT-TABNAME = 'ISHOW'.
WS_FIELDCAT-FIELDNAME = '&1'.
WS_FIELDCAT-SELTEXT_M = &2.
WS_FIELDCAT-COL_POS = NN.
WS_FIELDCAT-OUTPUTLEN = &3.
WS_FIELDCAT-DATATYPE = '&4'.
WS_FIELDCAT-DO_SUM = '&5'.
WS_FIELDCAT-LZERO = 'X'.
APPEND WS_FIELDCAT.
CLEAR WS_FIELDCAT.
END-OF-DEFINITION.
HOUT WERKS '工厂' 6 CHAR ''.
HOUT MATNR '组件' 15 CHAR ''.
HOUT MSG '订单描述' 50 CHAR ''.
TITLE = '物料组件分配结果'.
WS_LAYOUT-ZEBRA = 'X'.
WS_LAYOUT-GET_SELINFOS = ''.
WS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
WS_LAYOUT-DETAIL_POPUP = 'X'.
WS_LAYOUT-NO_KEYFIX = 'X'.
V_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = V_REPID
* i_callback_pf_status_set = 'MENU_SET'
* i_callback_user_command = 'EXECUTE_COMMAND'
IS_LAYOUT = WS_LAYOUT
IT_FIELDCAT = WS_FIELDCAT[]
IT_SPECIAL_GROUPS = WS_FIELDGROUPS_TAB[]
IT_SORT = WS_SORTFIELDS_TAB[]
IT_EVENTS = WS_EVENTS[]
I_GRID_TITLE = TITLE
TABLES
T_OUTTAB = ISHOW
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM. " SHOW
展开BOM注意事项:
说明:设置展BOM函数的参数
CS_BOM_EXPL_MAT_V2 展BOM的参数,其中:
工厂(WERKS)、BOM有效期(DATUV)、BOM类型(CAPID)、物料号(MTNRV)
是必须填写的。
另外:
展虚拟件(MDMPS)和 展多层(MEHRS) 是 互相影响的,直接决定BOM是否一展到底、是否继续展开虚拟件至其下一层。
1) 虚拟件 MDMPS -
多层 MEHRS X
结果: 全展(显示包含虚拟件)
2)虚拟件 MDMPS X
多层 MEHRS X
结果: 展1或2层(下层遇虚拟件则展开至其下一层,显示包含虚拟件)
3) 虚拟件 MDMPS -
多层 MEHRS -
结果: 展一层(下层为虚拟件,不再向下展开)
4) 虚拟件 MDMPS X
多层 MEHRS -
结果:展一层 (同3,下层为虚拟件,不再向下展开)
即:MEHRS置空,不论MDMPS如何设置,都只展一层,并且如果下层就是虚拟件,不展开虚拟件至其更下一层,与2)要区别开来。