100小時學習SAP之自學環境(一)
阿新 • • 發佈:2019-02-11
《100小時學會SAP》很老的一本書,現在想認真的花些時間學習一下。
系統環境:
選用仁鵬的ECC6 EHP7 純淨系統虛擬機器,WIN2003, SQLSERVER2008,磁碟大小80GB。(雖然自己也是BASIS,安裝出來其實也是一樣,就用這個把,很方便,應該把時間都花到模組上)。
系統跑起來後,給了16G實體記憶體,調整SAP總的記憶體佔用 em/initial_size_MB 10000 給SAP 10GB吧。
建立邏輯系統用 T-code: SALE ,SCC4新建一個client100,裡面要指定邏輯系統。
退出系統,用SAP* ,pass 登陸client100, 密碼不對。 引數檔案(C:\usr\sap\ECC\SYS\profile)中加: login/no_automatic_user_sapstar = 0 搞定。 沒空用rz10,自己的系統直接就改引數檔案了。
登陸client100,用scc9 從源client000中,引數選SAP_CUST, 把000拷貝到100中。 (3小時完成,db02看看 free 20G, OS C盤還剩5G, 夠用就行)
MM配置:
按書中完成MM後臺配置,之後要求建立5個原材料物料主資料。
正好練習一下ABAP吧,寫了一個物料主資料的批匯入程式:
程式匯入資料模版:
物料型別 | 物料號 | 行業領域 | 工廠 | 物料描述 | 基本計量單位 | 物料組 | 採購組 | MRP型別 | MRP控制者 | 批量 | 計劃交貨時間 | 計劃邊際碼 | 安全庫存 | 可用性檢查 | 評估類 | 價格控制 | 價格單位 | 移動平均價 |
ROH | R999-701 | M | P999 | 金屬片 | M2 | 1 | PG1 | PD | 1 | EX | 3 | Z01 | 60 | 2 | 3000 | V | 1 | 21 |
*&---------------------------------------------------------------------* *& REPORT ZMM0001 *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZMM0001. DATA: BEGIN OF RECORD OCCURS 0, HEAD_MATL_TYPE TYPE MTART,"物料型別 HEAD_MATERIAL TYPE MATNR,"物料號 HEAD_IND_SECTOR TYPE MBRSH,"行業領域 MARC_PLANT TYPE WERKS_D, "工廠 T_MAKT_MATL_DESC TYPE MAKTX,"物料描述 MARA_BASE_UOM TYPE MEINS,"基本計量單位 MARA_MATL_GROUP TYPE MATKL,"物料組 MARC_PUR_GROUP TYPE EKGRP,"採購組 MARC_MRP_TYPE TYPE DISMM, "MRP型別 MARC_MRP_CTRLER TYPE DISPO,"MRP控制者 MARC_LOTSIZEKEY TYPE DISLS,"批量 MARC_PLND_DELRY TYPE PLIFZ,"計劃交貨時間 MARC_SM_KEY TYPE FHORI," 計劃邊際碼 MARC_SAFETY_STK TYPE EISBE,"安全庫存 MARC_AVAILCHECK TYPE MTVFP,"可用性檢查 MBEW_VAL_CLASS TYPE BKLAS,"評估類 MBEW_PRICE_CTRL TYPE VPRSV,"價格控制 MBEW_PRICE_UNIT TYPE PEINH,"價格單位 MBEW_MOVING_PR TYPE VERPR_BAPI,"移動平均價 END OF RECORD. "輸入引數 DATA: HEADDATA TYPE BAPIMATHEAD, "表頭資料 CLIENTDATA TYPE BAPI_MARA, "基本資料 CLIENTDATAX TYPE BAPI_MARAX, PLANTDATA TYPE BAPI_MARC, "工廠級別資料 PLANTDATAX TYPE BAPI_MARCX, FORECASTPARAMETERS TYPE BAPI_MPOP, "預測 FORECASTPARAMETERSX TYPE BAPI_MPOPX, PLANNINGDATA TYPE BAPI_MPGD, "計劃 PLANNINGDATAX TYPE BAPI_MPGDX, STORAGELOCATIONDATA TYPE BAPI_MARD, "儲存位置 STORAGELOCATIONDATAX TYPE BAPI_MARDX, VALUATIONDATA TYPE BAPI_MBEW, "評估資料 VALUATIONDATAX TYPE BAPI_MBEWX, WAREHOUSENUMBERDATA TYPE BAPI_MLGN, "倉庫資料 WAREHOUSENUMBERDATAX TYPE BAPI_MLGNX, SALESDATA TYPE BAPI_MVKE, "銷售資料 SALESDATAX TYPE BAPI_MVKEX, STORAGETYPEDATA TYPE BAPI_MLGT, "儲存型別資料 STORAGETYPEDATAX TYPE BAPI_MLGTX. "TABLE引數 DATA: MATERIALDESCRIPTION TYPE TABLE OF BAPI_MAKT WITH HEADER LINE,"描述 UNITSOFMEASURE TYPE TABLE OF BAPI_MARM WITH HEADER LINE,"單位 UNITSOFMEASUREX TYPE TABLE OF BAPI_MARMX WITH HEADER LINE, TAXCLASSIFICATIONS TYPE TABLE OF BAPI_MLAN WITH HEADER LINE."稅分類 "RETURN DATA RETURN TYPE BAPIRET2. *宣告一個輸入框,變數是DATASET PARAMETERS: DATASET TYPE LOCALFILE. *螢幕選擇輸入框,去開啟取檔名FORM. AT SELECTION-SCREEN ON VALUE-REQUEST FOR DATASET. PERFORM OPEN_FILE USING DATASET. START-OF-SELECTION. PERFORM IMPORT_FROM_FILE TABLES RECORD[] USING DATASET. *如果內表中沒內容,退出 IF RECORD[] IS INITIAL. WRITE:/'輸入資料為空'. EXIT. ENDIF. DATA: PR_UNIT TYPE MEINS."基本計量單位 LOOP AT RECORD. CLEAR HEADDATA. HEADDATA-MATERIAL = RECORD-HEAD_MATERIAL. "物料號 HEADDATA-MATL_TYPE = RECORD-HEAD_MATL_TYPE. "物料型別 HEADDATA-IND_SECTOR = RECORD-HEAD_IND_SECTOR."行業領域 HEADDATA-BASIC_VIEW = 'X'. HEADDATA-SALES_VIEW = 'X'. HEADDATA-PURCHASE_VIEW = 'X'. HEADDATA-MRP_VIEW = 'X'. HEADDATA-WAREHOUSE_VIEW = 'X'. HEADDATA-ACCOUNT_VIEW = 'X'. HEADDATA-COST_VIEW = 'X'. "基本資料 CLEAR CLIENTDATA. CLIENTDATA-MATL_GROUP = RECORD-MARA_MATL_GROUP. "物料組 PERFORM GET_PR_UNIT USING RECORD-MARA_BASE_UOM CHANGING PR_UNIT. "基本計量單位 CLIENTDATA-BASE_UOM = PR_UNIT. CLEAR CLIENTDATAX. CLIENTDATAX-MATL_GROUP = 'X'. CLIENTDATAX-BASE_UOM = 'X'. CLIENTDATAX-EXTMATLGRP = 'X'. CLIENTDATAX-ITEM_CAT = 'X'. CLIENTDATAX-NET_WEIGHT = 'X'. CLIENTDATAX-TRANS_GRP = 'X'. "工廠級別資料 CLEAR PLANTDATA. PLANTDATA-PLANT = RECORD-MARC_PLANT. "工廠 PLANTDATA-PUR_GROUP = RECORD-MARC_PUR_GROUP."採購組 PLANTDATA-MRP_TYPE = RECORD-MARC_MRP_TYPE."MRP型別 PLANTDATA-MRP_CTRLER = RECORD-MARC_MRP_CTRLER."MRP控制者 PLANTDATA-LOTSIZEKEY = RECORD-MARC_LOTSIZEKEY."批量 PLANTDATA-PLND_DELRY = RECORD-MARC_PLND_DELRY."計劃交貨時間 PLANTDATA-SM_KEY = RECORD-MARC_SM_KEY." 計劃邊際碼 PLANTDATA-SAFETY_STK = RECORD-MARC_SAFETY_STK."安全庫存 PLANTDATA-AVAILCHECK = RECORD-MARC_AVAILCHECK."可用性檢查 CLEAR PLANTDATAX. PLANTDATAX-PLANT = RECORD-MARC_PLANT. PLANTDATAX-AVAILCHECK = 'X'. PLANTDATAX-LOADINGGRP = 'X'. PLANTDATAX-PUR_GROUP = 'X'. PLANTDATAX-BATCH_MGMT = 'X'. PLANTDATAX-AUTO_P_ORD = 'X'. PLANTDATAX-IND_POST_TO_INSP_STOCK = 'X'. PLANTDATAX-QUOTAUSAGE = 'X'. PLANTDATAX-SOURCELIST = 'X'. PLANTDATAX-MRP_GROUP = 'X'. PLANTDATAX-MRP_TYPE = 'X'. PLANTDATAX-MRP_CTRLER = 'X'. PLANTDATAX-LOTSIZEKEY = 'X'. PLANTDATAX-MINLOTSIZE = 'X'. PLANTDATAX-MAXLOTSIZE = 'X'. PLANTDATAX-ROUND_VAL = 'X'. PLANTDATAX-PROC_TYPE = 'X'. PLANTDATAX-BACKFLUSH = 'X'. PLANTDATAX-PLND_DELRY = 'X'. PLANTDATAX-GR_PR_TIME = 'X'. PLANTDATAX-SAFETY_STK = 'X'. PLANTDATAX-SM_KEY = 'X'. PLANTDATAX-PLAN_STRGP = 'X'. PLANTDATAX-ALT_BOM_ID = 'X'. "會計、成本 CLEAR VALUATIONDATA. VALUATIONDATA-VAL_AREA = RECORD-MARC_PLANT. "評估範圍=================== VALUATIONDATA-VAL_CLASS = RECORD-MBEW_VAL_CLASS. "評估類 VALUATIONDATA-PRICE_CTRL = RECORD-MBEW_PRICE_CTRL. "價格控制 VALUATIONDATA-PRICE_UNIT = RECORD-MBEW_PRICE_UNIT. "價格單位 VALUATIONDATA-MOVING_PR = RECORD-MBEW_MOVING_PR. "移動平均價 CLEAR VALUATIONDATAX. VALUATIONDATAX-VAL_AREA = RECORD-MARC_PLANT. VALUATIONDATAX-VAL_CLASS = 'X'. VALUATIONDATAX-PRICE_CTRL = 'X'. VALUATIONDATAX-PRICE_UNIT = 'X'. VALUATIONDATAX-MOVING_PR = 'X'. "物料描述 CLEAR MATERIALDESCRIPTION[]. MATERIALDESCRIPTION-LANGU_ISO = 'ZH'. MATERIALDESCRIPTION-MATL_DESC = RECORD-T_MAKT_MATL_DESC. "物料描述 APPEND MATERIALDESCRIPTION. CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA' EXPORTING HEADDATA = HEADDATA CLIENTDATA = CLIENTDATA CLIENTDATAX = CLIENTDATAX PLANTDATA = PLANTDATA PLANTDATAX = PLANTDATAX VALUATIONDATA = VALUATIONDATA VALUATIONDATAX = VALUATIONDATAX IMPORTING RETURN = RETURN TABLES MATERIALDESCRIPTION = MATERIALDESCRIPTION[]. IF SY-SUBRC = 0. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING WAIT = 'X'. WRITE:/ RETURN-MESSAGE. ENDIF. ENDLOOP. "獲取基本計量單位內碼 FORM GET_PR_UNIT USING UNIT1 CHANGING UNIT2. SELECT SINGLE MSEHI INTO UNIT2 FROM T006A WHERE SPRAS = 1 AND MSEH3 = UNIT1. IF SY-SUBRC <> 0. UNIT2 = UNIT1. ENDIF. ENDFORM. *--------------取檔名的FORM------------- FORM OPEN_FILE CHANGING X TYPE LOCALFILE . CALL FUNCTION 'WS_FILENAME_GET' EXPORTING DEF_FILENAME = '' DEF_PATH = '' MASK = ',*.TXT,*.TXT.' MODE = '0' TITLE = '取檔名' IMPORTING FILENAME = X EXCEPTIONS INV_WINSYS = 01 NO_BATCH = 02 SELECTION_CANCEL = 03 SELECTION_ERROR = 04. ENDFORM. *--------把檔案放內表的FORM---------------- FORM IMPORT_FROM_FILE TABLES RECORD_TEMP LIKE RECORD[] USING X TYPE LOCALFILE. DATA: FLENGTH TYPE I. CALL FUNCTION 'WS_UPLOAD' EXPORTING FILENAME = X FILETYPE = 'DAT' IMPORTING FILELENGTH = FLENGTH TABLES DATA_TAB = RECORD_TEMP EXCEPTIONS CONVERSION_ERROR = 1 FILE_OPEN_ERROR = 2 FILE_READ_ERROR = 3 INVALID_TABLE_WIDTH = 4 INVALID_TYPE = 5. ENDFORM.
程式碼太長,影響文字連貫性,不貼上來,又影響完整性。只有把文章分開了。