分类:
2010-11-16 11:53:08
1.UPLOAD
将所需要的资料从其它系统"上载"到SAP系统叫"UPLOAD",目前,我们在使用时,都是将资料转成文本文件(.TXT FILE),然后CALL FUNCTION将此文本文件读到internal table中.
格式:
CALL FUNCTION 'UPLOAD'
EXPORTING
CODEPAGE = ' '
FILENAME =
FILETYPE = 'ASC'
IMPORINT
FILELENGTH =
TABLES
DATA_TAB =
EXCEPTIONS
CONVENSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
OTHERS = 8.
其中:
EXCEPTIONS:是发生不可预知的错误时返回的值;
例如:
REPORT ZTEST006.
DATA : BEGIN OF MAN,
NAME(20) TYPE C,
HIGH TYPE P DECIMALS 2,
WEIGHT TYPE P DECIMALS 2,
END OF MAN.
DATA : MAN1 LIKE TABLE OF MAN.
CALL FUNCTION 'UPLOAD'
EXPORTING
codepage = 'TEST'
FILENAME = 'D:\TEMP\TESTA.TXT'
FILETYPE = 'DAT'
ITEM = '读入文件'
TABLES
DATA_TAB = MAN1
EXCEPTIONS
CONVERSION_ERROR = 1
INVAIL_TABLE_WIDTH = 2
INVAIL_TYPE = 3.
LOOP AT MAN1 INTO MAN.
WRITE :/ MAN-NAME,MAN-HIGH,MAN-WEIGHT.
ENDLOOP.
使用此方法,程序运行时会弹出输入读入文件的提示框,将程序中"CALL FUNCTION UPLOAD"改为"CALL FUNCTION WS_UPLOAD",程序运行时将不再提示直接输入读入文件。
2.DOWNLOAD
DOWNLOAD是将SAP中的资料"下载",SAP支持'ASC格式','TXT格式','BINARY格式'等,它可以直接将资料转成TXT FILE或EXCEL格式等.
一般来讲,,我们会把资料DOWNLOAD成TXT FILE,所以必须预先建立一个Internal table,把所要DOWNLOAD的资料存放在此Internal Table中,然后通过CALL FUNCTION来做DOWNLOAD.
格式:
CALL FUNCTION 'DOWNLOAD'
EXPORTING
BIN_FILESIZE = 255
FILENAME =
FILETYPE = 'ASC'
IMPORINT
FILELENGTH =
TABLES
DATA_TAB =
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
OTHERS = 8
其中:
BIN_FILESIZE 是指TXT FILE每行显示的字节数,可省;
FILENAME指定TXT FILE的路径和文件名,必须将此预先存与一变量中;
此变量可这样定义:
fname1 like rlgrap-filename default 'c:\temp.txt'.
DATA_TAB指定internal table的名称;
EXCEPTIONS:用来指定发生不可预知错误时返回的信息.
注意: 如果internal table中某字段是数值型(‘I’或’P’或’F’等),则要定义成字符串,否则会DOWNLOAD到TXT 文件时成乱码.
例如:
REPORT ZTEST005.
DATA : BEGIN OF MAN,
NAME(20) TYPE C,
HIGH TYPE P DECIMALS 2,
WEIGHT TYPE P DECIMALS 2,
END OF MAN.
DATA : MAN1 LIKE TABLE OF MAN.
DATA : NAME TYPE RLGRAP-FILENAME ,
TYPA TYPE RLGRAP-FILETYPE.
MAN-NAME = '张参'.
MAN-HIGH = '1.68'.
MAN-WEIGHT = 120.
INSERT MAN INTO TABLE MAN1.
MAN-NAME = '刘志'.
MAN-HIGH = '1.72'.
MAN-WEIGHT = 160.
INSERT MAN INTO TABLE MAN1.
MAN-NAME = '李志'.
MAN-HIGH = '1.58'.
MAN-WEIGHT = 110.
INSERT MAN INTO MAN1 INDEX 2.
NAME = 'D:\TEMP\TESTA.TXT'.
TYPA = 'DAT'.
CALL FUNCTION 'DOWNLOAD'
EXPORTING
CODEPAGE = 'TESTA'
FILENAME = NAME
FILETYPE = TYPA
ITEM = '文件测试'
TABLES
DATA_TAB = MAN1
EXCEPTIONS
INVALID_FILESIZE = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE = 3.
使用此方法,程序运行时会弹出输入存取文件名的提示框,将程序中"CALL FUNCTION DOWNLOAD"改为"CALL FUNCTION WS_DOWNLOAD",程序运行时将不再提示直接输入读入文件。