SAP 輸出資料給LIMS系統

dicksonjyl560101發表於2015-04-25

對於這個程式,只是提供一種解決的辦法,從SAP中取對應的資料 ,然後讀到伺服器上.供LIMS讀取,然後LIMS只要返回一個值給SAP。最後在SAP QA32中使用一個出口,讀取這樣的狀態,就可以直接看到合格 還是不合格的狀態了。


*&---------------------------------------------------------------------*
*&Program name: ZQMR0031
*&Create by: Chouer
*&Create on: 2007.09.17
*&Describe: SAP data download to Server for LIMS
*&---------------------------------------------------------------------*

TABLES: QALS.

**---Internal table it_qals
TYPES: BEGIN OF STR_QALS,
MATNR LIKE QALS-MATNR, "物料名稱
PRUEFLOS LIKE QALS-PRUEFLOS, "檢驗批號
KTEXTMAT LIKE QALS-KTEXTMAT, "物料描述(規格)
LIFNR LIKE QALS-LIFNR, "供應商編碼
EBELN LIKE QALS-EBELN, "採購編碼
EBELP LIKE QALS-EBELP, "採購編碼專案
LOSMENGE LIKE QALS-LOSMENGE, "檢驗數量
PASTRTERM LIKE QALS-PASTRTERM, "開始檢驗日期
NAME1 LIKE LFA1-NAME1, "供應商名稱
ACTUS TYPE C, "狀態
MBLNR LIKE QALS-MBLNR, "物料憑證
TXZ01 LIKE EKPO-TXZ01,
END OF STR_QALS.

DATA: WA_QALS TYPE STR_QALS,
IT_QALS TYPE TABLE OF STR_QALS.

DATA: WA_QALS2 TYPE STR_QALS,
IT_QALS2 TYPE TABLE OF STR_QALS.

**---Internal table it_lfa1
TYPES: BEGIN OF STR_LFA1,
LIFNR LIKE LFA1-LIFNR,
NAME1 LIKE LFA1-NAME1,
END OF STR_LFA1.

DATA: WA_LFA1 TYPE STR_LFA1,
IT_LFA1 TYPE TABLE OF STR_LFA1.

DATA: BEGIN OF T_DATA OCCURS 0,
TEXT(200) TYPE C,
END OF T_DATA.

DATA: P_PATH LIKE RLGRAP-FILENAME,
P_FPATH(60) TYPE C,
P_FILE(10) TYPE C,
P_NAME(11) TYPE C.
* P_NAME LIKE QALS-PRUEFLOS.
DATA: FH TYPE C VALUE ';',
QUALITY(20) TYPE C.

*&---------------------------------------------------------------------*
*& Form download_data_txt
*&---------------------------------------------------------------------*
* 產生txt文件,供傳入LIMS系統
*----------------------------------------------------------------------*
FORM DOWNLOAD_DATA_TXT TABLES P_EKPO STRUCTURE I_EKPO.

IF NOT P_EKPO IS INITIAL.
SELECT MATNR PRUEFLOS KTEXTMAT LIFNR EBELN EBELP LOSMENGE PASTRTERM
MBLNR
FROM QALS
INTO CORRESPONDING FIELDS OF TABLE IT_QALS
FOR ALL ENTRIES IN P_EKPO
WHERE EBELN = P_EKPO-EBELN
AND EBELP = P_EKPO-EBELP
AND MBLNR = P_EKPO-BELNR.
ENDIF.
IF NOT IT_QALS IS INITIAL.
SELECT LIFNR NAME1
FROM LFA1
INTO CORRESPONDING FIELDS OF TABLE IT_LFA1
FOR ALL ENTRIES IN IT_QALS
WHERE LIFNR = IT_QALS-LIFNR.
ENDIF.

LOOP AT IT_QALS INTO WA_QALS.
READ TABLE P_EKPO WITH KEY EBELN = WA_QALS-EBELN
EBELP = WA_QALS-EBELP
BELNR = WA_QALS-MBLNR.
IF SY-SUBRC = 0.
MOVE: P_EKPO-TXZ01 TO WA_QALS-TXZ01.
ENDIF.
MODIFY IT_QALS FROM WA_QALS TRANSPORTING TXZ01.
CLEAR: WA_QALS,P_EKPO.
ENDLOOP.
PERFORM GET_TXT_DATA. "處理資料
PERFORM DOWNLOAD_DATA. "Download data to servers
ENDFORM. " download_data_txt

*&---------------------------------------------------------------------*
*& Form DOWNLOAD_DATA
*&---------------------------------------------------------------------*
* 資料DownLoad到伺服器上
*----------------------------------------------------------------------*
FORM DOWNLOAD_DATA .
REFRESH T_DATA.
LOOP AT IT_QALS INTO WA_QALS.
REFRESH T_DATA.
**--用於檔名輸
P_NAME = WA_QALS-PRUEFLOS+1(11).
* P_FPATH = 'C:臨時TEST'.
* P_FPATH = 'X:TEST'.
* P_FPATH = 'LABSRVSAPLINKSAP'.
P_FPATH = 'LABSRVSAPlinkTESTSAP'.

P_FILE = '.TXT'.
CONCATENATE P_FPATH P_NAME P_FILE INTO P_PATH.
**--把數值型數量 轉換為 字元型
QUALITY = WA_QALS-LOSMENGE.

**---刪除數量左邊的空格
SHIFT QUALITY LEFT DELETING LEADING SPACE.

**---字串合併
* CONCATENATE WA_QALS-PRUEFLOS WA_QALS-MATNR WA_QALS-KTEXTMAT
* WA_QALS-LIFNR WA_QALS-NAME1 WA_QALS-EBELN
* QUALITY WA_QALS-PASTRTERM
* INTO T_DATA-TEXT SEPARATED BY ';' .
CONCATENATE WA_QALS-PRUEFLOS WA_QALS-MATNR WA_QALS-TXZ01
WA_QALS-LIFNR WA_QALS-NAME1 WA_QALS-EBELN
QUALITY WA_QALS-PASTRTERM
INTO T_DATA-TEXT SEPARATED BY ';' .
APPEND T_DATA.

**---Download file to txt
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
CODEPAGE = 'TIBM'
FILENAME = P_PATH
FILETYPE = 'DAT'
TABLES
DATA_TAB = T_DATA
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
NO_AUTHORITY = 10
OTHERS = 11.
IF SY-SUBRC <> 0.
MESSAGE '檔案路徑錯誤或者沒有許可權' TYPE 'E'.
STOP.
ENDIF.
CLEAR: WA_QALS, QUALITY,T_DATA.
ENDLOOP.
ENDFORM. " DOWNLOAD_DATA
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* 處理資料(得到供應商的名稱)
*----------------------------------------------------------------------*
FORM GET_TXT_DATA .
LOOP AT IT_QALS INTO WA_QALS.
READ TABLE IT_LFA1 INTO WA_LFA1 WITH KEY LIFNR = WA_QALS-LIFNR.
IF SY-SUBRC = 0.
MOVE: WA_LFA1-NAME1 TO WA_QALS-NAME1.
ENDIF.
MODIFY IT_QALS FROM WA_QALS TRANSPORTING NAME1.
ENDLOOP.
ENDFORM. " GET_TXT_DATA

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29829936/viewspace-1598565/,如需轉載,請註明出處,否則將追究法律責任。

相關文章