Transcript Document
File Controlling
File Controlling
1. Upgrade에 따른 File Controlling Issue
- SAP에서는 향후 ‘WS_’로 시작하는 기존의 Function Module들을 사용하지 말고 CL_GUI_FRONTEND_SERVICES Class의 Method를 사용할 것을 권고함.
Function Group Class, Function Module Method로 ABAP 개발환경이 변화하는 추세의 일환으로 판단됨.
- Function Group ‘GRAP’에 포함된 아래의 Function Module은 변경하여야 한다.
CLPB_IMPORT
: Send Text Table to Presentation Server Clipboard
CLPB_EXPORT
: Load Text Table from Presentation Server Clipboard
DOWNLOAD
: Save Internal Table as Presentation Server File with File Length
UPLOAD
: Transfer Presentation Server File to Internal Table with Length
WS_DOWNLOAD
: File Transfer from Internal Table to Presentation Server File
WS_UPLOAD
: Transfer Presentation Server File to Internal Table
WS_FILENAME_GET
: Call File Selector
WS_EXCEL
: Excel File
이들 Function Module에 대한 대체될 Function들은 ‘SFES’ Function Group에서 찾을 수 있다. (WS_ GUI_ 로 변경)
‘SFES’ Function Group은 내부가 CL_GUI_FRONTEND_SERVICES Class의 Method들로 구현됨.
GUI_FILE_SAVE_DIALOG
: Get Download File Name
GUI_DOWNLOAD
: Download
GUI_UPLOAD
: Upload
CL_GUI_FRONTEND_SERVICE=>CLIPBOARD_EXPORT
: Exports data to clipboard
CL_GUI_FRONTEND_SERVICE=>CLIPBOARD_IMPORT
: Imports data from clipboard
CL_GUI_FRONTEND_SERVICE=>EXECUTE
: Starts an Application or Opens a Document in the Client
CL_GUI_FRONTEND_SERVICE=>FILE_OPEN_DIALOG
: Displays a File Open Dialog
CL_GUI_FRONTEND_SERVICE=>FILE_SAVE_DIALOG
: Shows a File Save Dialog
CL_GUI_FRONTEND_SERVICE=>GUI_DOWNLOAD
: Download Data to Client PC
CL_GUI_FRONTEND_SERVICE=>GUI_UPLOAD
: Upload Data from Client PC
※ 관련 Notes
- 594356 : WS_DOWNLOAD, WS_UPLOAD Function Module을 GUI_DOWNLOAD, GUI_UPLOAD로 변경할 것.
- 595310, 833576 : WS_FILENAME_GET Function Module을 CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG,
CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG로 변경할 것.
1
File Controlling
2. Get File Name
- CL_GUI_FRONTEND_SERVICES Class에 속한 Method를 이용하여 파일명을 선택한다.
DATA : L_FILE_TABLE
L_RC
L_USER_ACTIO
FILE_NAME
TYPE
TYPE
TYPE
TYPE
FILETABLE,
I
,
I
,
STRING
.
DATA : LF_SEL_FILE
LF_SEL_PATH
LF_FULL_PATH
LF_USER_ACTION
FILE_NAME
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
EXPORTING :
WINDOW_TITLE
= 'File Open'
DEFAULT_FILENAME
= SPACE
FILE_FILTER
= '*.xls'
INITIAL_DIRECTORY
= 'C:\'
MULTISELECTION
= SPACE
CHANGING :
FILE_TABLE
= L_FILE_TABLE
RC
= L_RC
EXCEPTIONS :
FILE_OPEN_DIALOG_FAILED = 1
CNTL_ERROR
= 2
ERROR_NO_GUI
= 3
OTHERS
= 5.
TYPE
TYPE
TYPE
TYPE
TYPE
STRING,
STRING,
STRING,
I
,
STRING.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING :
WINDOW_TITLE
= 'Save File'
DEFAULT_FILE_NAME
= SPACE
FILE_FILTER
= '*.xls'
INITIAL_DIRECTORY
= 'C:\'
CHANGING :
FILENAME
= LF_SEL_FILE
PATH
= LF_SEL_PATH
FULLPATH
= LF_FULL_PATH
USER_ACTION
= LF_USER_ACTION
EXCEPTIONS :
CNTL_ERROR
= 1
ERROR_NO_GUI
= 2
OTHERS
= 4.
READ TABLE L_FILE_TABLE INTO FILE_NAME INDEX 1.
CONCATENATE LF_SEL_PATH LF_SEL_FILE INTO FILE_NAME.
※ CALL FUNCTION 'WS_FILENAME_GET'
4.6C (SAP_BASIS 41), 4.70 이상에서 사용 불가
※ CALL FUNCTION ‘GUI_FILE_SAVE_DIALOG’로 변경
2
File Controlling
3. ASCII File Read
- CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD Method를 이용하여 ASCII File에서 Data를 읽어 Internal Table에 저장한다.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
EXPORTING :
FILENAME
= FILE_NAME
FILETYPE
= 'ASC'
HAS_FIELD_SEPARATOR
= C_TAB
CHANGING :
DATA_TAB
= ITAB1[]
EXCEPTIONS :
FILE_OPEN_ERROR
= 1 "File does not exist, cannot open
FILE_READ_ERROR
= 2 "File read error
NO_BATCH
= 3 "Front-end function cannot be executed
GUI_REFUSE_FILETRANSFER = 4 "Incorrect front end, or error
INVALID_TYPE
= 5 "Incorrect parameter FILETYPE
NO_AUTHORITY
= 6 "No upload authorization
UNKNOWN_ERROR
= 7 "Unknown error
BAD_DATA_FORMAT
= 8 "Could not interpret data in file
HEADER_NOT_ALLOWED
= 9 "Invalid header
SEPARATOR_NOT_ALLOWED
= 10 "Invalid separator
HEADER_TOO_LONG
= 11 "Header information is maximum 1023
UNKNOWN_DP_ERROR
= 12 "Error when calling data provider
ACCESS_DENIED
= 13 "No access to file
DP_OUT_OF_MEMORY
= 14 "Not enough memory in data provider
DISK_FULL
= 15 "Disk full
DP_TIMEOUT
= 16."Data provider timeout
3
※ CALL FUNCTION ‘WS_UPLOAD‘
사용 불가
※ CALL FUNCTION 'GUI_UPLOAD'
동일 기능
File Controlling
4. ASCII File Save
- CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD Method를 이용하여 Internal Table Data를 ASCII File에 저장한다.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
EXPORTING :
FILENAME
= FILE_NAME
FILETYPE
= 'ASC'
APPEND
= SPACE
WRITE_FIELD_SEPARATOR
= C_TAB
CHANGING :
DATA_TAB
= ITAB1[]
EXCEPTIONS :
FILE_WRITE_ERROR
= 01 "Cannot write to file
NO_BATCH
= 02 "Front-end function cannot be executed
GUI_REFUSE_FILETRANSFER = 03 "Incorrect front-end
INVALID_TYPE
= 04 "Invalid value for parameter FILETYPE
NO_AUTHORITY
= 05 "No download authorization
UNKNOWN_ERROR
= 06 "Unknown error
HEADER_NOT_ALLOWED
= 07 "Invalid header
SEPARATOR_NOT_ALLOWED
= 08 "Invalid separator
FILESIZE_NOT_ALLOWED
= 09 "File size invalid
HEADER_TOO_LONG
= 10 "Header information is maximum 1023
DP_ERROR_CREATE
= 11 "Cannot create Data Provider
DP_ERROR_SEND
= 12 "Error when sending data with DP
DP_ERROR_WRITE
= 13 "Error when writing data with DP
UNKNOWN_DP_ERROR
= 14 "Error when calling data provider
ACCESS_DENIED
= 15 "No access to file
DP_OUT_OF_MEMORY
= 16 "Not enough memory in data provider
DISK_FULL
= 17 "Disk full
DP_TIMEOUT
= 18 "Data provider timeout
FILE_NOT_FOUND
= 19 "Could not find file
DATAPROVIDER_EXCEPTION = 20 "General exception error
CONTROL_FLUSH_ERROR
= 21."Error in control framework
4
※ CALL FUNCTION ‘WS_DOWNLOAD‘
사용 불가
※ CALL FUNCTION 'GUI_DOWNLOAD'
동일 기능
File Controlling
5. Excel File Read
- ALSM_EXCEL_TO_INTERNAL_TABLE Function을 이용하여 Excel File의 Data를 읽어온다.
DATA : FILENAME LIKE RLGRAP-FILENAME VALUE 'C:\sample_data.xls'.
DATA : XLS_DATA1 TYPE STANDARD TABLE OF ALSMEX_TABLINE
WITH HEADER LINE.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME
= FILENAME
I_BEGIN_COL
= 1
I_BEGIN_ROW
= 2
I_END_COL
= 20
I_END_ROW
= 10000
TABLES
INTERN
= XLS_DATA1
EXCEPTIONS
INCONSISTENT_PARAMETERS
= 1
UPLOAD_OLE
= 2
OTHERS
= 3.
ALSMEX_TABLINE Structure
LOOP AT XLS_DATA1.
CASE XLS_DATA1-COL.
WHEN '001'.
ITAB1-MATNR = XLS_DATA1-VALUE.
WHEN '002'.
ITAB1-MAKTX = XLS_DATA1-VALUE.
ENDCASE.
AT END OF ROW.
CHECK ITAB1-MATNR NE SPACE.
APPEND ITAB1.
ENDAT.
ENDLOOP.
5
ROW
Flexible Excel Upload : Row number
COL
Column
VALUE
Comment : String Value
File Controlling
6. Excel File Save
- MS_EXCEL_OLE_STANDARD_DAT Function을 이용하여 Excel File에 Data를 저장한다.
DATA : BEGIN OF H_CAT OCCURS
IDX(02)
TYPE N ,
FIELD(30) TYPE C ,
TITLE(20) TYPE C ,
END OF H_CAT.
0,
"Index
"Field Name
"Title
DATA : BEGIN OF DOWN OCCURS 0,
F1(50) , F2(50) , F3(50) ,
F6(50) , F7(50) , F8(50) ,
F11(50), F12(50), F13(50),
F16(50), F17(50), F18(50),
F21(50), F22(50), F23(50),
F26(50), F27(50), F28(50),
F31(50), F32(50), F33(50),
F36(50), F37(50), F38(50),
END OF DOWN.
F4(50) ,
F9(50) ,
F14(50),
F19(50),
F24(50),
F29(50),
F34(50),
F39(50),
LOOP AT ITAB1.
TABIX = SY-TABIX.
LOOP AT H_CAT.
CNT = SY-TABIX.
FLD1 = H_CAT-FIELD.
CONCATENATE 'DOWN-F' CNT INTO FLD2.
ASSIGN (FLD2) TO <V>.
ASSIGN COMPONENT FLD1 OF STRUCTURE ITAB1 TO <F>.
<V> = <F>.
ENDLOOP.
F5(50) ,
F10(50),
F15(50),
F20(50),
F25(50),
F30(50),
F35(50),
F40(50),
APPEND DOWN.
CLEAR DOWN.
ENDLOOP.
CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
EXPORTING
FILE_NAME = FILENAME
TABLES
DATA_TAB
= DOWN_TABLE
FIELDNAMES = FIELDNAME.
DATA : FLD1(40),
FLD2(40),
CNT(2),
TABIX TYPE I.
FIELD-SYMBOLS :
<F>, <V>.
PERFORM ADD_FIELDCAT
'01' 'MATNR'
'02' 'MAKTX'
'03' 'MEINS'
'04' 'WAERS'
'05' 'NETPR'
*------------------------------------------------FORM ADD_FIELDCAT USING P_IDX P_FIELD P_TITLE.
MOVE : P_IDX
TO H_CAT-IDX ,
P_FIELD TO H_CAT-FIELD,
P_TITLE TO H_CAT-TITLE.
USING :
‘Material’
,
‘Description’,
‘Unit’
,
‘Currency’
,
‘Price’
.
APPEND H_CAT.
ENDFORM.
6
File Controlling
7. Excel File Save
- XXL_FULL_API Function을 이용하여 Excel Data와 Pivot Table을 저장한다.
DATA : BEGIN OF IT_DATA OCCURS 0,
MATNR LIKE MARA-MATNR,
MAKTX LIKE MAKT-MAKTX,
LGPBE LIKE MARD-LGPBE,
FRLAB(20) TYPE C,
LGORT(20) TYPE C,
GIREM(20) TYPE C,
END OF IT_DATA.
DATA : XMPLT_O
XMPLT_P
XMPLT_H
XMPLT_V
XMPLT_S
TYPE
TYPE
TYPE
TYPE
TYPE
TABLE
TABLE
TABLE
TABLE
TABLE
OF
OF
OF
OF
OF
XMPLT_V-COL_NO = 5 .
XMPLT_V-COL_NAME = '청구저장위치' .
APPEND XMPLT_V .
“자재번호
“SVC 품명
“저장 Bin
“접수처재고
“청구저장위치
“출고예정수량
GXXLT_O
GXXLT_P
GXXLT_H
GXXLT_V
GXXLT_S
WITH
WITH
WITH
WITH
WITH
HEADER
HEADER
HEADER
HEADER
HEADER
XMPLT_H-COL_NO = 1 .
XMPLT_H-ROW_NO = 1 .
XMPLT_H-COL_NAME = '출고예정수량' .
APPEND XMPLT_H .
LINE,
LINE,
LINE,
LINE,
LINE.
XMPLT_S-COL_NO = 1 .
XMPLT_S-COL_TYP = 'STR' .
XMPLT_S-COL_OPS = 'DFT' .
XMPLT_S-COL_SRC = 0 .
XMPLT_S-COL_CUR = 0 .
APPEND XMPLT_S .
XMPLT_V-COL_NO = 1 .
XMPLT_V-COL_NAME = '자재번호' .
APPEND XMPLT_V .
XMPLT_S-COL_NO = 2 .
XMPLT_S-COL_TYP = 'STR' .
XMPLT_S-COL_OPS = 'DFT' .
XMPLT_S-COL_SRC = 0 .
XMPLT_S-COL_CUR = 0 .
APPEND XMPLT_S .
XMPLT_V-COL_NO = 2 .
XMPLT_V-COL_NAME = 'SVC품명' .
APPEND XMPLT_V .
XMPLT_V-COL_NO = 3 .
XMPLT_V-COL_NAME = '저장BIN' .
APPEND XMPLT_V .
XMPLT_S-COL_NO = 3 .
XMPLT_S-COL_TYP = 'STR' .
XMPLT_S-COL_OPS = 'DFT' .
XMPLT_S-COL_SRC = 0 .
XMPLT_S-COL_CUR = 0 .
APPEND XMPLT_S .
XMPLT_V-COL_NO = 4 .
XMPLT_V-COL_NAME = '접수처재고' .
APPEND XMPLT_V .
7
File Controlling
XMPLT_S-COL_NO = 4 .
XMPLT_S-COL_TYP = 'STR' .
XMPLT_S-COL_OPS = 'DFT' .
XMPLT_S-COL_SRC = 0 .
XMPLT_S-COL_CUR = 0 .
APPEND XMPLT_S .
CALL FUNCTION 'XXL_FULL_API'
EXPORTING
N_VRT_KEYS
= 5
N_ATT_COLS
= 1
N_HRZ_KEYS
= 1
SEMA_TYPE
= 'X'
FILENAME
= 'TEST'
HEADER_1
= 'DATA'
HEADER_2
= 'PIVOT'
NO_DIALOG
= ' '
TABLES
VKEY
= XMPLT_V
HKEY
= XMPLT_H
DATA
= IT_DATA
SEMA
= XMPLT_S
ONLINE_TEXT
= XMPLT_O
PRINT_TEXT
= XMPLT_P
EXCEPTIONS
CANCELLED_BY_USER = 01
DATA_TOO_BIG
= 02
DIM_MISMATCH_DATA = 03
DIM_MISMATCH_SEMA = 04
DIM_MISMATCH_VKEY = 05
ERROR_IN_HKEY
= 06
ERROR_IN_SEMA
= 07
FILE_OPEN_ERROR
= 08
FILE_WRITE_ERROR = 09
OTHERS
= 10.
XMPLT_S-COL_NO = 5 .
XMPLT_S-COL_TYP = 'STR' .
XMPLT_S-COL_OPS = 'DFT' .
XMPLT_S-COL_SRC = 0 .
XMPLT_S-COL_CUR = 0 .
APPEND XMPLT_S .
XMPLT_S-COL_NO = 6 .
XMPLT_S-COL_TYP = 'NUM' .
XMPLT_S-COL_OPS = 'ADD' .
XMPLT_S-COL_SRC = 0 .
XMPLT_S-COL_CUR = 0 .
APPEND XMPLT_S .
※ COL_TYP
- ‘STR’
- ‘DAT’
- ‘MON’
- ‘PCT’
- ‘NUM’
※ COL_OPS
- ‘DFT’
- ‘ADD’
:
:
:
:
:
String
Date
Month
Percent
Numeric
: Default
: Additional
※ N_VRT_KEYS + N_ATT_COLS는 Internal Table의 Field 수와 동일해야 한다.
8