2 Ekim 2011 Pazar

SAP/ABAP: TXT to SAP ( ‘GUI_UPLOAD’ FM )



FORM TXT_TO_SAP .

DATA: LT_FILETABLE TYPE FILETABLE,
LF_RC TYPE I,
LV_FNAME(50) TYPE C,
LV_FEXT(3) TYPE C.

* Function module to show File open Dialog
CALL METHOD CL_GUI_FRONTEND_SERVICES->FILE_OPEN_DIALOG
EXPORTING
WINDOW_TITLE            = 'Bir txt dosyası seçin'
FILE_FILTER             = '*.txt'
MULTISELECTION          = ABAP_FALSE
CHANGING
FILE_TABLE              = LT_FILETABLE
RC                      = LF_RC
EXCEPTIONS
FILE_OPEN_DIALOG_FAILED = 1
CNTL_ERROR              = 2
ERROR_NO_GUI            = 3
NOT_SUPPORTED_BY_GUI    = 4
OTHERS                  = 5.

IF SY-SUBRC NE 0.
MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO
DISPLAY LIKE 'E'
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
EXIT.
ENDIF.

CHECK LF_RC = 1.

DATA: LS_FILE TYPE FILE_TABLE.

READ TABLE LT_FILETABLE INTO LS_FILE INDEX 1.
CHECK SY-SUBRC = 0.
PA_FILE = LS_FILE-FILENAME.

SPLIT  PA_FILE AT '.' INTO LV_FNAME LV_FEXT.
* Check if Text file is Selected
IF LV_FEXT NE 'txt'.
MESSAGE 'Dosya tipinde bir sıkıntı var' TYPE 'I'.
ENDIF.

*--------------------------------------------------------------------*

DATA: LV_FILENAME TYPE STRING.

LV_FILENAME = PA_FILE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME                = LV_FILENAME
FILETYPE                = 'ASC'
HAS_FIELD_SEPARATOR     = 'X'
TABLES
DATA_TAB                = ITAB
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 NE 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


ENDFORM.                    " TXT_TO_SAP

Hiç yorum yok:

Yorum Gönder

İnsdroid

Sabahtan beri çatada çutada çatada çutada… Bitmedi yine de… Neyse, yolumuz uzun, toparlıyorum çantamı, adaptörü falan tıkıştırıyorum bir şe...