REPORT Z_CREATE_PR.
DATA: BEGIN OF GT_DATA1 OCCURS 0,
BSART TYPE STRING, "凭证类型
BNFPO TYPE STRING, "项目
* KNTTP TYPE STRING, "科目分配类别
MATNR TYPE STRING, "商品代码
* TXZ01 TYPE STRING, "短文本
MENGE TYPE STRING, "数量
MEINS TYPE STRING, "单位
EEIND TYPE STRING, "交货日期
* MATKL TYPE STRING, "物料组
WERKS TYPE STRING, "工厂
EKGRP TYPE STRING, "采购组
AFNAM TYPE STRING, "申请者
BEDNR TYPE STRING, "需求跟踪号
SAKTO TYPE STRING, "总帐科目
KOSTL TYPE STRING, "成本中心
ANLN1 TYPE STRING, "资产
AUFNR TYPE STRING, "订单
PREIS TYPE STRING, "评估价格
WAERS TYPE STRING, "币种
PEINH TYPE STRING, "价格单位
DISPO TYPE STRING, "MRP控制者
STR1 TYPE STRING,"行项目文本-传送文本
STR2 TYPE STRING,"行项目文本-预算年度
STR3 TYPE STRING,"行项目文本-资产类别
END OF GT_DATA1.
DATA: BEGIN OF GT_DATA OCCURS 0,
BEDNR TYPE STRING, "需求跟踪号
BSART TYPE STRING, "凭证类型
BNFPO TYPE STRING, "项目
* KNTTP TYPE STRING, "科目分配类别
MATNR TYPE STRING, "商品代码
* TXZ01 TYPE STRING, "短文本
MENGE TYPE STRING, "数量
MEINS TYPE STRING, "单位
EEIND TYPE STRING, "交货日期
* MATKL TYPE STRING, "物料组
WERKS TYPE STRING, "工厂
EKGRP TYPE STRING, "采购组
AFNAM TYPE STRING, "申请者
SAKTO TYPE STRING, "总帐科目
KOSTL TYPE STRING, "成本中心
ANLN1 TYPE STRING, "资产
AUFNR TYPE STRING, "订单
PREIS TYPE STRING, "评估价格
WAERS TYPE STRING, "币种
PEINH TYPE STRING, "价格单位
DISPO TYPE STRING, "MRP控制者
STR1 TYPE STRING,"行项目文本-传送文本
STR2 TYPE STRING,"行项目文本-预算年度
STR3 TYPE STRING,"行项目文本-资产类别
END OF GT_DATA.
DATA: BEGIN OF GT_OUT OCCURS 0,
TEXT(255),
END OF GT_OUT.
DATA: PR_ITEM LIKE TABLE OF BAPIEBANC WITH HEADER LINE,
PR_ACCOUNT LIKE TABLE OF BAPIEBKN WITH HEADER LINE,
PR_ITEM_ID LIKE TABLE OF BAPIEBANTX WITH HEADER LINE,
PR_RETURN LIKE TABLE OF BAPIRETURN WITH HEADER LINE.
DATA: L_RETURN LIKE PR_RETURN.
DATA: LV_MESSAGE(255).
DATA: PR_NO TYPE BAPIEBANC-PREQ_NO.
DATA: BNFPO TYPE BNFPO.
DATA: MATNR TYPE MATNR.
DATA: PP_FILE TYPE STRING.
PARAMETERS:P_FILE(128) .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM GET_FILE.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM CREATE_PR.
PERFORM WRITE_OUT.
*&---------------------------------------------------------------------*
*& Form GET_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_FILE .
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_FILENAME = P_FILE
MASK = ',*.txt,*.TXT.'
*'',*.xls,*.XLS.'如果读入txt文件,在后边就需要用函数
* CALL FUNCTION 'WS_UPLOAD'
MODE = 'O'
TITLE = 'File Name'
IMPORTING
FILENAME = P_FILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
PP_FILE = P_FILE.
ENDFORM. " GET_FILE
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = PP_FILE
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = GT_DATA1
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
.
IF SY-SUBRC <> 0.
CASE SY-SUBRC.
WHEN 1.MESSAGE 'FILE_OPEN_ERROR ' TYPE 'E'.
WHEN 2.MESSAGE 'FILE_READ_ERROR ' TYPE 'E'.
WHEN 3.MESSAGE 'NO_BATCH' TYPE 'E'.
WHEN 4.MESSAGE 'GUI_REFUSE_FILETRANSFER ' TYPE 'E'.
WHEN 5.MESSAGE 'INVALID_TYPE ' TYPE 'E'.
WHEN 6.MESSAGE ' NO_AUTHORITY' TYPE 'E'.
WHEN 7.MESSAGE 'UNKNOWN_ERROR' TYPE
DATA: BEGIN OF GT_DATA1 OCCURS 0,
BSART TYPE STRING, "凭证类型
BNFPO TYPE STRING, "项目
* KNTTP TYPE STRING, "科目分配类别
MATNR TYPE STRING, "商品代码
* TXZ01 TYPE STRING, "短文本
MENGE TYPE STRING, "数量
MEINS TYPE STRING, "单位
EEIND TYPE STRING, "交货日期
* MATKL TYPE STRING, "物料组
WERKS TYPE STRING, "工厂
EKGRP TYPE STRING, "采购组
AFNAM TYPE STRING, "申请者
BEDNR TYPE STRING, "需求跟踪号
SAKTO TYPE STRING, "总帐科目
KOSTL TYPE STRING, "成本中心
ANLN1 TYPE STRING, "资产
AUFNR TYPE STRING, "订单
PREIS TYPE STRING, "评估价格
WAERS TYPE STRING, "币种
PEINH TYPE STRING, "价格单位
DISPO TYPE STRING, "MRP控制者
STR1 TYPE STRING,"行项目文本-传送文本
STR2 TYPE STRING,"行项目文本-预算年度
STR3 TYPE STRING,"行项目文本-资产类别
END OF GT_DATA1.
DATA: BEGIN OF GT_DATA OCCURS 0,
BEDNR TYPE STRING, "需求跟踪号
BSART TYPE STRING, "凭证类型
BNFPO TYPE STRING, "项目
* KNTTP TYPE STRING, "科目分配类别
MATNR TYPE STRING, "商品代码
* TXZ01 TYPE STRING, "短文本
MENGE TYPE STRING, "数量
MEINS TYPE STRING, "单位
EEIND TYPE STRING, "交货日期
* MATKL TYPE STRING, "物料组
WERKS TYPE STRING, "工厂
EKGRP TYPE STRING, "采购组
AFNAM TYPE STRING, "申请者
SAKTO TYPE STRING, "总帐科目
KOSTL TYPE STRING, "成本中心
ANLN1 TYPE STRING, "资产
AUFNR TYPE STRING, "订单
PREIS TYPE STRING, "评估价格
WAERS TYPE STRING, "币种
PEINH TYPE STRING, "价格单位
DISPO TYPE STRING, "MRP控制者
STR1 TYPE STRING,"行项目文本-传送文本
STR2 TYPE STRING,"行项目文本-预算年度
STR3 TYPE STRING,"行项目文本-资产类别
END OF GT_DATA.
DATA: BEGIN OF GT_OUT OCCURS 0,
TEXT(255),
END OF GT_OUT.
DATA: PR_ITEM LIKE TABLE OF BAPIEBANC WITH HEADER LINE,
PR_ACCOUNT LIKE TABLE OF BAPIEBKN WITH HEADER LINE,
PR_ITEM_ID LIKE TABLE OF BAPIEBANTX WITH HEADER LINE,
PR_RETURN LIKE TABLE OF BAPIRETURN WITH HEADER LINE.
DATA: L_RETURN LIKE PR_RETURN.
DATA: LV_MESSAGE(255).
DATA: PR_NO TYPE BAPIEBANC-PREQ_NO.
DATA: BNFPO TYPE BNFPO.
DATA: MATNR TYPE MATNR.
DATA: PP_FILE TYPE STRING.
PARAMETERS:P_FILE(128) .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM GET_FILE.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM CREATE_PR.
PERFORM WRITE_OUT.
*&---------------------------------------------------------------------*
*& Form GET_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_FILE .
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_FILENAME = P_FILE
MASK = ',*.txt,*.TXT.'
*'',*.xls,*.XLS.'如果读入txt文件,在后边就需要用函数
* CALL FUNCTION 'WS_UPLOAD'
MODE = 'O'
TITLE = 'File Name'
IMPORTING
FILENAME = P_FILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
PP_FILE = P_FILE.
ENDFORM. " GET_FILE
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = PP_FILE
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = GT_DATA1
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
.
IF SY-SUBRC <> 0.
CASE SY-SUBRC.
WHEN 1.MESSAGE 'FILE_OPEN_ERROR ' TYPE 'E'.
WHEN 2.MESSAGE 'FILE_READ_ERROR ' TYPE 'E'.
WHEN 3.MESSAGE 'NO_BATCH' TYPE 'E'.
WHEN 4.MESSAGE 'GUI_REFUSE_FILETRANSFER ' TYPE 'E'.
WHEN 5.MESSAGE 'INVALID_TYPE ' TYPE 'E'.
WHEN 6.MESSAGE ' NO_AUTHORITY' TYPE 'E'.
WHEN 7.MESSAGE 'UNKNOWN_ERROR' TYPE