*----------------------------------------------------------------------*
* TITLE : GUI_DOWNLOAD / GUI_UPLOAD 함수 활용 *
* PROGRAM NAME : ZTABLE_UTIL (REPORT-TYPE) *
* AUTHOR : CHANHOON KIM *
* CREATED ON : 2010.05.04 *
* DESCRIPTION : *
* REF.PROGRAM : *
*----------------------------------------------------------------------*
* MODIFICATION LOG *
* DATE AUTHOR DESCRIPTION *
*----------------------------------------------------------------------*
* *
*----------------------------------------------------------------------*
REPORT ZTABLE_UTIL MESSAGE-ID ZMDYNPRO .
*&---------------------------------------------------------------------*
*& TABLES 정의
*&---------------------------------------------------------------------*
TABLES: DD02L, "SAP 테이블
SSCRFIELDS.
*&---------------------------------------------------------------------*
*& TYPE-POOLS , TYPES
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& INTERNAL TABLES
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
* GLOBALE VARIABLES
*&---------------------------------------------------------------------*
DATA: GT_FIELDCAT TYPE LVC_T_FCAT,
GT_TAB TYPE REF TO DATA,
G_FILELENGTH TYPE I.
FIELD-SYMBOLS: <ALL_TABLE> TYPE TABLE.
*&---------------------------------------------------------------------*
* CONSTANTS
*&---------------------------------------------------------------------*
CONSTANTS: C_XTRUE(1) TYPE C VALUE 'X',
C_XFALSE(1) TYPE C VALUE ' '.
*----------------------------------------------------------------------*
* SELECTION SCREEN ( SELECT-OPTIONS & PARAMETERS )
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK FRM1 WITH FRAME TITLE TEXT-S01.
PARAMETERS: PA_TAB LIKE DD02L-TABNAME OBLIGATORY, "Table Name
DATEINAM LIKE RLGRAP-FILENAME OBLIGATORY. "File Name
SELECTION-SCREEN SKIP.
PARAMETERS: PA_DOW RADIOBUTTON GROUP G1 DEFAULT 'X',
PA_UP RADIOBUTTON GROUP G1.
SELECTION-SCREEN END OF BLOCK FRM1.
** Description
*※ Upload 데이터 포맷 준수 사항
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (79) TEXT-Z01.
SELECTION-SCREEN END OF LINE.
* 1. 클라이언트 컬럼 있을 것
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (79) TEXT-Z02.
SELECTION-SCREEN END OF LINE.
* 2. File 확장자 - *.txt
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (79) TEXT-Z03.
SELECTION-SCREEN END OF LINE.
* 3. 데이터 구분자 : TAB(Tabulator)
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (79) TEXT-Z04.
SELECTION-SCREEN END OF LINE.
* 4. Date format : YYYYMMDD
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (79) TEXT-Z05.
SELECTION-SCREEN END OF LINE.
* 5. Time format - HH:MM:SS
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (79) TEXT-Z06.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN FUNCTION KEY 1.
*----------------------------------------------------------------------*
* INITIALIZATION. *
*----------------------------------------------------------------------*
INITIALIZATION.
MOVE '테이블조회' TO SSCRFIELDS-FUNCTXT_01.
*----------------------------------------------------------------------*
* SELECTION-SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
IF SSCRFIELDS-UCOMM = 'FC01'.
SET PARAMETER ID 'DTB' FIELD PA_TAB.
CALL TRANSACTION 'SE16' AND SKIP FIRST SCREEN.
ENDIF.
** 값 확인.
PERFORM CHECK_INPUT_DATA.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR DATEINAM.
PERFORM GET_FILENAME.
*----------------------------------------------------------------------*
* START OF SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM FIELD_CATALOG_MERGE.
PERFORM CHANGE TABLES GT_FIELDCAT.
PERFORM CREATE_DYNAMIC_TABLE.
IF PA_DOW EQ 'X'.
PERFORM DOWN_LOAD_TO_LOCAL.
ELSE.
PERFORM UPLOAD_TO_LOCAL.
ENDIF.
*----------------------------------------------------------------------*
* END-OF-SELECTION
*----------------------------------------------------------------------*
END-OF-SELECTION.
LEAVE LIST-PROCESSING.
*&---------------------------------------------------------------------*
*& Form check_input_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM CHECK_INPUT_DATA .
DATA: LS_DD02L LIKE DD02L.
SELECT SINGLE *
FROM DD02L
INTO LS_DD02L
WHERE TABNAME = PA_TAB
AND AS4LOCAL = 'A'.
IF SY-SUBRC <> 0.
MESSAGE W000 WITH 'Table Name 입력란을 확인하세요!'.
ENDIF.
IF PA_TAB(1) <> 'Z' AND PA_TAB(1) <> 'Y'.
* MESSAGE e000 WITH 'CBO Table만 가능...'.
ENDIF.
ENDFORM. " check_input_data
*&---------------------------------------------------------------------*
*& Form get_filename
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GET_FILENAME.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_FILENAME = DATEINAM
DEF_PATH = 'C:'
MASK = ',*.*,*.*.'
MODE = 'O'
TITLE = ' '
IMPORTING
FILENAME = DATEINAM
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
WRITE: 'Error occurs IN getting filename!'.
ENDIF.
ENDFORM. " get_filename
*&---------------------------------------------------------------------*
*& Form field_catalog_merge
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM FIELD_CATALOG_MERGE .
REFRESH GT_FIELDCAT. CLEAR GT_FIELDCAT.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = PA_TAB
CHANGING
CT_FIELDCAT = GT_FIELDCAT.
IF SY-SUBRC <> 0.
MESSAGE E000 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " field_catalog_merge
*&---------------------------------------------------------------------*
*& Form change
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM CHANGE TABLES P_GT_FIELDCAT TYPE LVC_T_FCAT.
DATA:L_FIELDCAT_S LIKE P_GT_FIELDCAT.
LOOP AT P_GT_FIELDCAT INTO L_FIELDCAT_S.
IF L_FIELDCAT_S-DATATYPE = 'DATS'.
L_FIELDCAT_S-DATATYPE = 'CHAR'.
L_FIELDCAT_S-DD_OUTLEN = '10'.
L_FIELDCAT_S-INTLEN = '000008'.
ELSEIF L_FIELDCAT_S-DATATYPE = 'TIMS'.
L_FIELDCAT_S-DATATYPE = 'CHAR'.
L_FIELDCAT_S-DD_OUTLEN = '8'.
L_FIELDCAT_S-INTLEN = '000006'.
ENDIF.
MODIFY P_GT_FIELDCAT FROM L_FIELDCAT_S INDEX SY-TABIX.
ENDLOOP.
ENDFORM. " change
*&---------------------------------------------------------------------*
*& Form create_dynamic_table
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM CREATE_DYNAMIC_TABLE .
CLEAR GT_TAB.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = GT_FIELDCAT
IMPORTING
EP_TABLE = GT_TAB.
ASSIGN GT_TAB->* TO <ALL_TABLE>.
ENDFORM. " create_dynamic_table
*&---------------------------------------------------------------------*
*& Form down_load_to_local
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM DOWN_LOAD_TO_LOCAL .
DATA: L_FILENAME TYPE STRING.
REFRESH <ALL_TABLE>. CLEAR <ALL_TABLE>.
SELECT * FROM (PA_TAB)
INTO CORRESPONDING FIELDS OF TABLE <ALL_TABLE>.
L_FILENAME = DATEINAM.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = L_FILENAME
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = 'X'
IMPORTING
FILELENGTH = G_FILELENGTH
TABLES
DATA_TAB = <ALL_TABLE>
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.
* CALL FUNCTION 'WS_DOWNLOAD'
* EXPORTING
* filename = dateinam
* filetype = 'DAT'
* IMPORTING
* filelength = g_filelength
* TABLES
* data_tab = .
IF SY-SUBRC <> 0.
MESSAGE S000
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
MESSAGE S000 WITH '다운로드 성공' G_FILELENGTH.
ENDIF.
ENDFORM. " down_load_to_local
*&---------------------------------------------------------------------*
*& Form upload_to_local
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM UPLOAD_TO_LOCAL .
REFRESH <ALL_TABLE>. CLEAR <ALL_TABLE>.
DATA: L_FILENAME TYPE STRING .
L_FILENAME = DATEINAM.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = L_FILENAME
* FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = <ALL_TABLE>
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.
* CALL FUNCTION 'WS_UPLOAD'
* EXPORTING
* filename = dateinam
* filetype = 'DAT'
* TABLES
* data_tab = .
*
IF SY-SUBRC <> 0.
MESSAGE S000
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
MODIFY (PA_TAB) FROM TABLE <ALL_TABLE>.
IF SY-SUBRC EQ 0.
MESSAGE S000 WITH '업로드 성공' SY-DBCNT.
ENDIF.
ENDIF.
ENDFORM. " upload_to_local
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
391 | report zsaptip_009 [1] | sapjoy | 2010.12.10 | 3852 |
390 | REPORT Z_3DGRAPH. [1] | sapjoy | 2010.10.18 | 3666 |
389 | REPORT zsmw0010 | sapjoy | 2010.10.12 | 4315 |
388 | z_exception_test | sapjoy | 2010.10.11 | 3521 |
387 | REPORT zmacro_01. | sapjoy | 2010.10.10 | 2582 |
386 | REPORT ZTEST_ABAPTPDF | sapjoy | 2010.10.10 | 3693 |
385 | REPORT ZALVCOLOR | sapjoy | 2010.10.10 | 3212 |
» | REPORT ZTABLE_UTIL | sapjoy | 2010.10.10 | 4012 |
383 | REPORT Z_DYNAMIC_SCREEN [1] | sapjoy | 2010.10.08 | 3035 |
382 | report zsalv_045 . | sapjoy | 2010.08.20 | 4264 |
381 | report zsalv_043 . | sapjoy | 2010.08.20 | 2978 |
380 | report zsalv_042 . | sapjoy | 2010.08.20 | 3135 |
379 | report zsalv_041 . | sapjoy | 2010.08.20 | 2998 |
378 | report zsalv_040 . | sapjoy | 2010.08.20 | 2608 |
377 | report zsalv_036 . | sapjoy | 2010.08.20 | 3473 |
376 | report zsalv_035 . | sapjoy | 2010.08.20 | 2505 |
375 | report zsalv_032 . | sapjoy | 2010.08.20 | 2976 |
374 | report zsalv_031 . | sapjoy | 2010.08.20 | 2427 |
373 | report zsalv_030 . | sapjoy | 2010.08.20 | 2331 |
372 | report zsalv_023 . | sapjoy | 2010.08.20 | 2347 |