SAP ABAP 文件操作函数大全
Working With Files
Skip to end of metadata
Created by Xinpeng Lin, last modified by Gregor Wolf on Feb 09, 2016
Go to start of metadata
Author: Xinpeng Lin
Submitted: 11.9.2007
This Code Snippets will clarify some general process of working with files when ABAP programmming. Such as,Uploading/Downloading files from/to Application/Presentation server, adding F4 help to file path on the selection-screen,checking file existence.
Check File Existence
Before we process the file which is input on the selection screen by end-user, we need to check whether this file exists or not. If it does not exist, we just give an error message and need not to go into the main
program .This logic should be done within the event 'AT SELECTION-SCREEN'.
presentation server file
For the presentation server file,here intruduce 2 ways, one is Function Module, the other is Class Static Method.
1. Using Funciton Moudle 'DX_FILE_EXISTENCE_CHECK'.
DATA: gdf_file_exist(1) TYPE c.
PARAMETERS p_file TYPE dxfile-filename.
AT SELECTION-SCREEN.
CALL FUNCTION 'DX_FILE_EXISTENCE_CHECK'
EXPORTING
filename = p_file
pc = 'X'
* SERVER =
IMPORTING
file_exists = gdf_file_exist.
IF NOT ( sy-subrc = 0 and gdf_file_exist = 'X' )
MESSAGE 'the input file does not exist.' TYPE 'E'.
ENDIF.
Pay attention to the importing parameter 'pc', it should be set as 'X'.
2. Using Class Static Method 'CL_GUI_FRONTEND_SERVICES=>FILE_EXIST'
DATA: gdf_file_exist(1) TYPE c.
PARAMETERS p_file TYPE dxfile-filename.
AT SELECTION-SCREEN.
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = p_file
RECEIVING
result = gdf_file_exist.
IF NOT ( sy-subrc = 0 and gdf_file_exist = 'X' )
MESSAGE 'the input file does not exist.' TYPE 'E'.
ENDIF.
application server file
For application server file, generally we open it first within the event 'AT SELECTION-SCREEN'.If it can be opened successfully, this file exists. After open,do not forget to close it.
PARAMETERS p_file TYPE dxfile-filename.
AT SELECTION-SCREEN.
OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
CLOSE DATASET p_file.
ELSE.
MESSAGE 'the input file does not exist.' TYPE 'E'.
ENDIF.
There is also a Function Module can be used, named 'OCS_GET_FILE_INFO'.
DATA: gdt_ocs_file TYPE TABLE OF ocs_file.
PARAMETERS p_file TYPE dxfile-filename.
AT SELECTION-SCREEN.
CALL FUNCTION 'OCS_GET_FILE_INFO'
EXPORTING
dir_name = p_file
file_name = '*'
TABLES
dir_list = gdt_ocs_file. Importing parameter 'file_name' is set as '*' means all the file in the specfied directory will be get and stored in the internal table 'gdt_ocs_file'. If the input file is included in the internal table, this file exists.
Add F4 Help
Adding one F4 Help to the file path on the selection-screen will be very helpful to the end-user.The logic should be under the event 'ON VALUE-REQUEST'.
presentation server file
For the presentation server file,here intruduce 2 ways, one is Function Module, the other is Class Static Method.
1. Using Funciton Module 'F4_FILENAME'.
PARAMETERS p_file TYPE dxfile-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
* EXPORTING
* PROGRAM_NAME =
* DYNPRO_NUMBER =
* FIELD_NAME =
IMPORTING
file_name = p_file.
2. Using Class Static Method 'CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG'.
DATA: gdt_filetable TYPE filetable.
DATA: gdf_rc TYPE I.
PARAMETERS p_file TYPE dxfile-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
WINDOW_TITLE = 'Choose a file'
CHANGING
file_table = gdt_filetable
rc = gdf_rc.
IF sy-subrc = 0.
READ TABLE gdt_filetable
INTO gds_filetable INDEX 1.
p_file = gds_filetable-filename.
ENDIF.
gdf_rc is the number of selected file, if it is equal -1, error occured.
application server file
Generally it need not to provide F4 help for application server file. If we want it, there is also a Funciotn Module which can be used.
PARAMETERS p_file TYPE dxfile-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_DXFILENAME_4_DYNP'
EXPORTING
dynpfield_filename = 'P_FILE'
dyname = sy-repid
dynumb = sy-dynnr
filetype = 'P'
location = 'A'
server = ' '. filetype: 'P' represents Physical file name; 'L' represents Logical file name.
location: 'A' represents Application Server; 'P' represents Presentation server.
Download Files
Sometimes we need to save the internal table data as a file for the further process.For download to
presentation server and download to application server,they are 2 different kinds of process methods.
to presentation server
When storing internal table data as a local file on the presentation server, there are 2 methods we can use.
One is using the function modeule, the other is using the class static method.
1. Using Function Module 'GUI_DOWNLOAD'.
DATA: gdf_filepath type dxfile-filename
DATA: gdt_data type table of gts_data.
START-OF-SELECTION.
gdf_filepath = 'C:\mydata.txt'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = gdf_filepath
filetype = 'ASC'
write_field_separator = 'X'
TABLES
data_tab = gdt_data.
filetype is set by 'X' mens separating columns by Tabs in case of ASCII download.
If sy-subrc is equal 0, file downloading is successful.
2. Using class static method 'CL_GUI_FRONTEND_SERVICES =>GUI_DOWNLOAD'
DATA: gdf_filepath type dxfile-filename
DATA: gdt_data type table of gts_data.
START-OF-SELECTION.
gdf_filepath = 'C:\mydata.txt'.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = gdf_filepath
filetype = 'ASC'
write_field_separator = 'X'
CHANGING
data_tab = gdt_data.
filetype is set by 'X' mens separating columns by Tabs in case of ASCII download.
If sy-subrc is equal 0, file downloading is successful.
to application server
If we want to save the internal table data to the application server, there is no function module or class static
method which we can use, we must wirte the code by ourselves.
DATA: gdf_filepath type dxfile-filename
DATA: gdt_data type table of gts_data.
DATA: ldf_length type i.
FIELD-SYMBOLS:
START-OF-SELECTION.
gdf_filepath = 'C:\mydata.txt'.
OPEN DATASET gdf_filepath FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT prt_data ASSIGNING
DESCRIBE FIELD
TRANSFER
ENDLOOP.
CLOSE DATASET gdf_filepath.
The prerequsite is the field of prt_data must be character type.
Using this method, every field column will output as the length defined,without separator.
If we want field columns are separated by tab, we can realize it as below.
DATA: gdf_filepath type dxfile-filename
DATA: gdt_data type table of gts_data.
DATA: ldf_length type i.
FIELD-SYMBOLS:
START-OF-SELECTION.
gdf_filepath = 'C:\mydata.txt'.
OPEN DATASET gdf_filepath FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT prt_data ASSIGNING
CONCATENATE
... INTO LDF_OUTDATA SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZON TRANSFER LDF_OUTDATA TO gdf_filepath. ENDLOOP. CLOSE DATASET gdf_filepath. Upload Files Sometimes we need to upload the file data to the internal table first, and then process it.For upload from presentation server and upload from application server,they are 2 different kinds of process methods. from presentation server When we upload a file data from presentation server to the internal table, there are 2 method that we can choose.One is using the Function Moduel, the other is using the class static method. 1. Using function module 'GUI_UPLOAD'. DATA: gdt_filedata TYPE TABLE OF gts_filedata. PARAMETERS p_file TYPE dxfile-filename. START-OF-SELECTION. CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = p_file has_field_separator = 'X' TABLES data_tab = gdt_filedata. parameter has_field_separator is set as 'X' means columns separated by tabs in case of ASCII upload. 2. Using the class tatic method 'CL_GUI_FRONTEND_SERVICES =>GUI_UPLOAD'. DATA: gdt_filedata TYPE TABLE OF gts_filedata. PARAMETERS p_file TYPE dxfile-filename. START-OF-SELECTION. CALL METHOD cl_gui_frontend_services=>gui_upload EXPORTING filename = p_file has_field_separator = 'X' CHANGING data_tab = prt_table. parameter 'has_field_separator' is set as 'X' means columns separated by tabs in case of ASCII upload. from application server If we want to upload file data from the application server to the internal table, there is no function module or class static method which we can use, we must wirte the code by ourselves. 1. For the file data which has no seperator between field columns. PARAMETERS p_file TYPE dxfile-filename. START-OF-SELECTION. OPEN DATASET p_file IN TEXT MODE ENCODING DEFAULT FOR INPUT. DO. READ DATASET p_file INTO gds_data. IF sy-subrc <> 0. EXIT. ENDIF. APPEND gds_data TO gdt_data. ENDDO. CLOSE DATASET p_file. 2. For the file data which has tab separator between field columns. DATA: gds_field_split type gts_data. FIELD-SYMBOLS: PARAMETERS p_file TYPE dxfile-filename. START-OF-SELECTION. OPEN DATASET prf_file IN TEXT MODE ENCODING DEFAULT FOR INPUT. DO. READ DATASET p_file INTO gds_field. SPLIT gds_field AT cl_abap_char_utilities=>horizontal_tab INTO TABLE gdt_field_split. LOOP AT gdt_field_split into gds_field_split. gdf_index = gdf_index + 1. ASSIGN COMPONENT gdf_index OF STRUCTURE gds_data to IF sy-subrc = 0. ENDIF. ENDLOOP. APPEND gds_data TO gdt_data. ENDDO. CLOSE DATASET p_file. 函数的单调性 【学习目标】 1.理解函数的单调性定义; 2.会判断函数的单调区间、证明函数在给定区间上的单调性; 3.学会运用单调性的定义求函数的最大(小)值。 【要点梳理】 要点一、函数的单调性 1.增函数、减函数的概念 一般地,设函数f(x)的定义域为A ,区间D A ?: 如果对于D 内的任意两个自变量的值x 1、x 2,当x 1 (4)图象特征:在单调区间上增函数的图象从左向右是上升的,减函数的图象从左向右是下降的. 2.单调性与单调区间 (1)单调区间的定义 如果函数f(x)在区间D 上是增函数或减函数,那么就说函数f(x)在区间D 上具有单调性,D 称为函 数f(x)的单调区间. 函数的单调性是函数在某个区间上的性质. 要点诠释: ①单调区间与定义域的关系----单调区间可以是整个定义域,也可以是定义域的真子集; ②单调性是通过函数值变化与自变量的变化方向是否一致来描述函数性质的; ③不能随意合并两个单调区间; ④有的函数不具有单调性. (2)已知解析式,如何判断一个函数在所给区间上的单调性? 3.证明函数单调性的步骤 (1)取值.设12x x ,是()f x 定义域内一个区间上的任意两个量,且12x x ; (2)变形.作差变形(变形方法:因式分解、配方、有理化等)或作商变形; (3)定号.判断差的正负或商与1的大小关系; (4)得出结论. 4.函数单调性的判断方法 Mathematica函数及使用方法 (来源:北峰数模) --------------------------------------------------------------------- 注:为了对Mathematica有一定了解的同学系统掌握Mathematica的强大功能,我们把它的一些资料性的东西整理了一下,希望能对大家有所帮助。 --------------------------------------------------------------------- 一、运算符及特殊符号 Line1; 执行Line,不显示结果 Line1,line2 顺次执行Line1,2,并显示结果 ?name 关于系统变量name的信息 ??name 关于系统变量name的全部信息 !command 执行Dos命令 n! N的阶乘 !!filename 显示文件内容 < Expr>> filename 打开文件写 Expr>>>filename 打开文件从文件末写 () 结合率 [] 函数 {} 一个表 <*Math Fun*> 在c语言中使用math的函数 (*Note*) 程序的注释 #n 第n个参数 ## 所有参数 rule& 把rule作用于后面的式子 % 前一次的输出 %% 倒数第二次的输出 %n 第n个输出 var::note 变量var的注释"Astring " 字符串 Context ` 上下文 a+b 加 a-b 减 a*b或a b 乘 a/b 除 a^b 乘方 base^^num 以base为进位的数 lhs&&rhs 且 lhs||rhs 或 !lha 非 ++,-- 自加1,自减1 +=,-=,*=,/= 同C语言 >,<,>=,<=,==,!= 逻辑判断(同c)知识讲解-函数的单调性-基础
Mathematica函数及使用方法
必修一函数的单调性专题讲解(经典)