Report Zty_MM_0018 Message-ID ZWWWERRORS. * Program Name: Package Distribution Table (Zty_MM_0018) * Function Description: Automatic Assign Packaging Material Stock * Program Establishment Date: 2004-09-14 * Last modified Date Perform Print-Header.Tables: MAKT , "Material Management Mkol," Supplier Special Inventory MARD, "Mara, Ekpo," Purchase Order Bank Project Ekko, "Purchase Order Head T023T," Material Group Description Eket, "Planning Program , "Quota file: Title EQUP," quota file: project RESB, "Subdeal / related demand JEST," Object status AUFK, "Order Main Data AFPO," Order Item LFA1. "Supplier Main Data Data: BEGIN OF ITEM OCCURS 0 Matkl Like Ekpo-Matkl, "Material Group WGBEZ LIKE T023T-WGBEZ," Material Group Description Matnr Like Makt-Matnr, "Material Code Maktx Like Makt-Maktx," Material Description Fullname (50) Type C, "Supplier Combination WPONUM Like Ekpo-Menge, "Supplier Unmissions Order W GeneTer Like Ekpo-Menge," Supplier Suppliers SLABS LIKE MKOL-SLABS, "Bass Stock Labst Like Mard-Labst," Applied Online Stock Lifnr Like Lfa1-Lifnr, " Supplier Code Groes Like Mara-Groes, "Size / Quantity WQYH LIKE EKPO-MENGE," Unclear FPJH LIKE EKPO-MENGE, "Distribution Plan End of Item.data:Struc Like Item.Data: IITEMC LIKE ITEM OCCURS 0 with header line.data:begin of tekpo occurs 0, Ebeln Like Ekpo-Ebeln," Purchase Order Number EBELP LIKE EKPO-EBELP, "Row Project Number Matnr Like Ekpo-Matnr," Material Code Menge Like Ekpo-Menge, "Order Quantity End of Tekpo.data :Begin of Tekko Occurs 0, Ebeln Like Ekko-Ebeln," Purchase Order Number LIFNR LIKE Ekko-Lifnr, "Supplier ID End of Tekko.data Flag Type I Value 0.data Flag Type I Value 0.data Flag Type I Value 0.data Flag Type I Value 0.data Flag Type I Value 0.data Flag Type I Value 0.data Flag Type v t
Purchase Order No. EBET-EBELP, "Row Item No. Wemng Like Eket-Wemng," Quantity End of Teket.data: BEGIN OF TEKET.DATA :BEGIN OF TWPO OCCURS 0, EBELN LIKE EKPO-EBELN, "Purchasing Order No. EBELP LIKE EKPO-EBELP," Matnr Like Ekpo-Matnr, "Material Code Menge Like Ekpo-Matnr," Order Quantity Lifnr Like Ekko-Lifnr, "Supplier End of Twpo.Data :Begin of Twpo2 Occurs 0, Matnr Like Ekpo-Matnr," Materials Encoding Menge Like Ekpo-Menge, "Unknown LIFNR LIKE EKKO-LIFNR," Supplier Code end of twpo2.data:bEGIN OF TITEMP OCCURS 0, MATNR LIKE EKPO-MATNR, "Material Code LIFNR LIKE EKKO-LIFNR," Supply Business Code WPONUM LIKE EKPO-MENGE, "Supplier Unminement Order W GeneTer Like Ekpo-Menge," Supplier Supplier SLABS LIKE MKOL-SLABS, "Baby Stock Labst Like Mard-Labst," Brand Online Stock WQYH Like Ekpo- Menge, "Unclear | FPJH LIKE EKPO-MENGE," Allocation Plan End of Titemp.constants MatnRlow (18) Type C Value '000000000002300000'.Constants MatnRhigh (18) TYPE C Value '000000000002399999'.Data year like sy-datum.data cyber (4) Type C.Data: Begin of Tmara Occurs 0, Matnr Like Mara-Matnr, "Material Code Matkl Like Mara-Matkl," Material Group GROES LIKE MARA- groes, "size / dimension end of tmara.SELECTION-SCREEN: BEGIN oF BLOCK FRAME01 WITH FRAME TITLE Text-001 select-options s_lifnr for lfa1-lifnr select-options:.. s_matnr for makt-matnr select-options:. s_matkl For t023t-matkl. parameters p_werks like vbap-werks obligatory default '8000'
. Select-options: s_SPART for mara-spart.SELECTION-SCREEN: END OF BLOCK FRAME01.SELECTION-SCREEN: BEGIN OF BLOCK FRAME02 WITH FRAME TITLE TEXT-002.SELECTION-SCREEN COMMENT / 5 (68) TEXT-003.SELECTION- SCREEN: END oF BLOCK FRAME02.SELECTION-SCREEN: BEGIN oF BLOCK FRAME03 WITH FRAME TITLE TEXT-004.SELECTION-SCREEN COMMENT / 5 (68) TEXT-005.SELECTION-SCREEN: END oF BLOCK FRAME03.start-of-selection. Year = SY-DATUM.CYAR = YEAR 0 (4). * Get eligible record SELECT * INTO CORRESPONDING FIELDS OF TABLE TMARA from mara where mtart = 'zver' and matkl in s_matkl and matnr in s_matnr and lvorm <> ' X 'and spart in s_spart.
select * into corresponding fields of table tekpo from ekpo where matnr in s_matnr and matkl in s_matkl and loekz <> 'L' and matnr between matnrlow and matnrhigh and werks = p_werks.sort tekpo by ebeln ebelp.select * into corresponding fields of table tekko From Ekko WHERE LOEKZ <> 'L' and lifnr in s_lifnr.sort tekko by ebeln.if not s_lifnr is initial.flag = 0.loop at tekpo. loop at tekko where ebeln = tekpo-ebeln. Flag = 1. EXIT. endloop . if flag = 0. delete tekpo. else. flag = 0. endif.endloop.endif. * minus cleared POloop at tekpo. select * appending corresponding fields of table teket from eket where ebeln = tekpo-ebeln and ebelp = tekpo -ebelp.endloop.sort teket by ebeln ebelp.loop at tekpo loop at teket where ebeln = tekpo-ebeln and ebelp = tekpo-ebelp tekpo-menge = tekpo-menge -... teket-wemng modify tekpo endloop.endloop.. Data: Begin of Tlif Occurs 0, Lifnr Like LFA1-LIFN r, "Supplier number end of tlif.loop at tekpo. twpo-ebeln = tekpo-ebeln. twpo-ebelp = tekpo-matnr. twpo-menge = tekpo-menge. loop at tekko Where Ebeln = tekpo-ebeln. twpo-lifnr = tekko-lifnr. EXIT. endloop. Append twpo.Endloop. * Press material, supplier code merge record Sort twpo by matnr lifnr.read table twpo index 1.TWPO2-matnr = twpo- Matnr.twpo2-menge = 0.twpo2-lifnr = twpo-lifnr.loop at twpo. if twpo-matnr = twpO2-matnr and twpo-lifnr = twpO2-lifnr. twpO2-menge = twpO2-menge twpo-meng. Else Append twpo2. TwpO2-matnr =
twpo-matnr. twpo2-menge = twpo-menge. twpo2-lifnr = twpo-lifnr. endif.endloop.append twpo2.sort tekko by lifnr.read table tekko index 1.tlif-lifnr = tekko-lifnr.loop at tekko. IF TLIF-LIFNR <> tekko-lifnr. append TLIF-lifnr = tekko-lifnr. endif.Endloop.Append TLIF.Sort Tlif by Lifnr.
* Vendor consignment stock data: begin of tmkol occurs 0, matnr like mkol-matnr, lifnr like mkol-lifnr, slabs like mkol-slabs, end of tmkol.data:tmkol1 like tmkol occurs 0 with header line.loop at tlif. select * appending corresponding fields of table tmkol from mkol where lifnr = tlif-lifnr and lvorm <> 'X' and werks = p_werks.endloop.loop at tmkol. tmkol1-matnr = tmkol-matnr. tmkol1-lifnr = tmkol-lifnr. tmkol1-slabs = tmkol-slabs. collect tmkol1.endloop.loop at twpo2. titemp-matnr = twpo2-matnr. titemp-lifnr = twpo2-lifnr. titemp-wponum = twpo2-menge. append titemp.endloop.flag = 0. loop at tmkol1. loop at titemp where matnr = tmkol1-matnr and lifnr = tmkol1-lifnr. titemp-wmenge = tmkol1-slabs. modify titemp. flag = 1. endloop. if flag = 1. delete tmkol1. flag = 0. endif .endloop.if not tmkol1 [] is initial. loop at tmkol1. Titemp-matnr = tmkol1-matnr. TITEMP- Lifnr = tmkol1-lifnr. TITEMP-W GeneNGe = TMKOL1-SLABS. Append Titemp. endloop.endif.data :begin of tmard occurs 0, Matnr Like MARD-MATNR, "Material Code Labst Like Mard-Labst," Non-limiting Stock END OF tmard.data:begin of mainmard occurs 0, matnr like mard-matnr, bckc like mard-labst, zxkc like mard-labst, end of mainmard.data:finmard like mainmard occurs 0 with header line.data:onlinemard like tmard occurs 0 With header line.select * INTO CORRESPONDING FIELDS OF TABLE TMARD from MATNRLOW AND MATNR BETWEEN MATNRLOW AND MATNRHIGH AND (LGORT = '0040' OR LGORT = '6040'
) And labst <> 0 and werks = p_werks.select * into corresponding fields of table onlinemard from mard where matnr between matnrlow and matnrhigh and (lgort = '0041' or lgort = '6041') and labst <> 0 and werks = p_werks .loop at tmard. mainmard-matnr = tmard-matnr. mainmard-bckc = tmard-labst. mainmard-zxkc = 0. append mainmard.endloop.loop at onlinemard. mainmard-matnr = onlinemard-matnr. mainmard-bckc = 0. mainmard-zxkc = onlinemard-labst. append mainmard.endloop.loop at mainmard. finmard-matnr = mainmard-matnr. finmard-bckc = mainmard-bckc. finmard-zxkc = mainmard-zxkc. collect finmard.endloop.if not finmard [ ] IS initial. Flag = 0. loop at titemp where matnr = titemp-matnr. TITEMP-SLABS = FINMARD-BCKC. TITEMP-LABST = FINMARD-ZXKC. Modify TITEMP. FLAG = 1. endloop. if flag = 1. delete finmard. Flag = 0. Endif. Endloop. Endif.if Not FinMard [] is initial. loop at finmard. TITEMP-MATNR = FINMARD-MATNR. TITEMP-SLABS = FINMARD-BCKC. TITEMP-LABST = FINMARD-ZXKC. Append TITEMP. endloop.endif. * Unclear goods Plan Data: Begin of Tekes Occurs 0, Ebeln Like Ekes-Ebelp, Menge Like Ekes-Menge, Dabmg Like Ekes-Dabmg, End of Tekes.Data: BEGIN OF TWQSL OCCURS 0, MATNR LIKE EKPO-MATNR Lifnr Like Ekko-Lifnr, WQS Like Ekes-Menge, End of Twqsl.select * Into Corresponding Fields of Table Tekees from ekes where eindt =
sy-datum.loop at tekes. select single matnr from ekpo into twqsl-matnr where ebeln = tekes-ebeln and ebelp = tekes-ebelp. select single lifnr from ekko into twqsl-lifnr where ebeln = tekes-ebeln. twqsl-wqs = tekes-menge -.... tekes-dabmg collect twqsl.endloop.flag = 0.loop at twqsl loop at titemp where matnr = twqsl-matnr and lifnr = twqsl-lifnr titemp-wqyh = twqsl-wqs modify titemp flag =. 1. Endloop. If flag = 1. delete TWQSL. Flag = 0. Endif.Endloop.if Not TWQSL [] is initial. Titemp-matnr = twqsl-matnr. Titemp-lifnr = twqsl-lifnr. Titemp-wqyh = twqsl- WQS. Append TITEMP.ENDIF. * Package distribution plan Data: Begin of Tresb Occurs 0, Matnr Like Resb-Matnr, Aufnr Like Resb-aufnr, End of Tresb.Selection * Into Corresponding Fields of Table Tresb From resb where kzear <> x 'and xloek <>' x 'and bdart =' ar 'and matnr between matnrlow and matnrhigh and bdte R = SY-DATUM. * TJ02T table, Chinese character Description Data: Begin of Taufk occurs 0, Aufnr Like Aufnr, Objnr Like Auf-Objnr, Stat Like Jest-Stat, End of Taufk.loop At Tresb. Select Single Aufnr Objnr from aufk into (taufk-aufnr, taufk-objnr) where aufnr = tresb-aufnr. select single stat from jest into taufk-stat where objnr = taufk-objnr and inact <> 'X'. append taufk.endloop.loop at taufk If taufk-stat = 'i0009'. Delete tauf. Endif.Endloop.flag = 0.loop at Tresb. Loop at taufw where aufnr = Tresb-aufnr. Flag =
1. EXIT. Endloop. If FLAG = 0. Delete Tresb. Else. Flag = 0. Endif.Endloop.Data :begin of tequk occurs 0, Matnr Like Equk-Matnr, Qunum Like Equk-qunum, End of Tequk.select * into corresponding fields of table tequk from equk where matnr between matnrlow and matnrhigh and vdatu <= sy-datum and bdatu> = sy-datum.data:begin of tequp occurs 0, qunum like equp-qunum, lifnr like equp-lifnr, quote like equp-quote, end of tequp.loop at tequk. select * appending corresponding fields of table tequp from equp where qunum = tequk-qunum.endloop.data:begin of tpe occurs 0, matnr like equk-matnr, lifnr like equp- LIFNR, END of TPE.LOOP AT TEQUP. TPE-LIFNR = Tequp-Lifnr. TPE-quote = tequp-quote. loop at tequk where quote = tequ-qunum. TPE-matnr = tequk-matnr. EXIT. endloop. append tpe.endloop.data:bEGIN OF TFP OCC URS 0, Matnr Like Makt-Matnr, Lifnr Like Ekko-Lifnr, Menge Like Res-Bdmng, End of TFP.LOOP At TPE. TFP-MATNR = TPE-MATNR. TFP-LIFNR = TPE-LIFNR. loop at Tresb Where Matnr = TPE-MATNR. TFP-MATNR. TFP-MATNR. TRESB-BDMNG * TPE-Quote / 100. endloop. append tfp.endloop.loop at title Matnr = titemp-matnr and lifnr = titemp-lifnr. TITEMP-FPJH = TFP-MENGE. MODIFY TITEMP. EXIT. endloop.endloop.flag = 0.loop at title Matnr = TITEMP-MATNR. Flag = 1. EXIT. endloop. if flag = 0. delete titemp. else. Flag =
0. endif.endloop.data:name111 like lfa1-name1.loop at titemp. Item-matnr = titemp-matnr. Select single maktx from makt into item-maktx where matnr = titemp-matnr and spras = '1'. Loop at Tmara where matnr = titemp-matnr. item-matkl = tmara-matkl. item-groes = Tmara-groes. EXIT. endloop. Select Single WGBEZ from T023T ITO ITEM-WGBEZ WHERE SPRAS = '1' and matkl = item-matkl. item-lifnr = titemp-lifnr. select single name1 from lfa1 into name111 where lifnr = item-lifnr. SHIFT item-lifnr LEFT DELETING LEADING '0'. concatenate name111 '(' item-lifnr ')' into item-fullname. item -WPONUM = TITEMP-WMENGE. Item-slabs = titemp-slabs. item-labst = titemp-labst. item-wqyh = titemp-wqyh. Item-fpjh = titemp-fpjh. append item. Endloop.if item [] IS initial. Message e001.Endif.Sort item by matnr lifnr.read table item index 1.struc-matkl = item-matkl.struc-wgbez = item-wgbez. Struc-matnr = item-matnr.struc-maktx = item-maktx.struc-fullname = item-fullname.struc-lifnr = item-lifnr.struc-wponum = 0.Struc-w GeneNGe = 0.Struc-SLABS = 0. Struc-Labst = 0.Struc-Lifnr = item-lifnr.struc-groes = item-groes.struc-wqyh = 0.Struc-fpjh = 0.loop at item. if struc-matnr = item-matnr. itemc-matkl = item-matkl. itemc-wgbez = item-wgbez. item-matnr = item-matc-maktx = item-maktx. item-fullname = item-fullname. item-lifnr = item-lifnr. Itemc-wponum =
item-wmenge = item-wmenge. itemc-slabs = item-slabs. itemc-Labst = item-labst. item-limited = item-lifnr. item-gROES = item-groes. itemc-wqyh = Item Wqyh. item-fpjh = item-fpjh. append itemc. struct-matkl = item-matkl. struct-wgbez = 'small meter'. struct-matnr = item-matnr. struct-maktx = item-maktx. struct-wponum = struc-wponum item-wponum. struc-wmenge = struc-wmenge item-wmenge. struc-slabs = struc-slabs item-slabs. struc-labst = struc-labst item-labst. struc-groes = item- Groes. Struc-wqyh = struc-wqyh item-wqyh. struct-fpjh = struc-fpjh item-fpjh. else. append struct to itemc. itemc-matkl = item-matkl. itemc-wgbez = item-wgbez. ItemC -matnr = item-matnr. itemc-maktx = item-maktx. item-fullname = item-fullname. itemc-lifnr = item-lifnr. itemc-wponum = iTEM -wponum. item-wmenge. itemc-slabs = item-slabs. item-labst = item-labst. item-lifnr = item-lifnr. item-groes = item-groes. item-wqyh = item-wqyh Item-fpjh = item-fpjh. Append itemc. Struct-matkl = item-matkl. Strung-wgbez = item-wgbez. Struct-matnr = item-matnr. Struct-maktx = item-maktx. Struct-wponum = Item- WPONUM. STRUC-W GeneNGe = item-wmenge. struct-slabs = item-slabs. struct-labst =
Item-labst. struct-groes = item-groes. struct-wqyh = item-wqyh. struct-fpjh = item-fpjh. endif.Endloop.Append Struc To Itemc.loop at itemc where wgbez = 'small meter'. itemc- Matkl = ''. itemc-fullname = ''. itemc-lifnr = ''. modify itemc.endloop.if itemc [] IS INITIAL. Message E001.Endif.End-of-selection.perform ole_excel tables itemc using 'd: /sapdata/ty_mm_0018/ty_mm_0018.xls'.FORM ole_excel TABLES itab USING appl_file_name TYPE string INCLUDE ole2incl DATA:.. excel TYPE ole2_object DATA:. books TYPE ole2_object DATA:. range TYPE ole2_object DATA:. book TYPE ole2_object DATA:. filename LIKE Rcgfiletr-ftfront. data: appl_file_path type string. Data: Appl_FileName Like Rcgfiletr-ftfront.
Filename = 'd: /sapdata/ty_mm_0018/ty_mm_0018.xls'. Appl_File_Path = 'D: / SAPDATA / TY_MM_0018 /'.
Call function 'ws_download' exporting filename = 'd: /sapdata/ty_m_0018/itab.dat' filetype = 'DAT' TABLES DATA_TAB = ITAB. Free itab.
Concatenate appl_file_path appl_file_name INTO APPL_FILENAME.
CALL FUNCTION 'C13Z_FILE_DOWNLOAD_BINARY' EXPORTING i_file_front_end = filename i_file_appl = appl_filename i_file_overwrite = 'X'. CALL FUNCTION 'WS_EXECUTE' EXPORTING document = 'X' COMMANDLINE = filename PROGRAM = 'EXCEL'.
ENDFORM.