CALL SCREEN 100.
*-------------------------------------------------*
* Module STATUS_0100 OUTPUT
*-------------------------------------------------*
* TEXT
*-------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS '0100'.
PERFORM DISPLAY_DOCUMENT.
ENDMODULE. " STATUS_0100 OUTPUT
*------------------------------------------------*
* Module USER_COMMAND_0100 INPUT
*------------------------------------------------*
* TEXT
*------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
GV_UCOMM = SY_UCOMM.
CLEAR SY-UCOMM.
CASE GV_UCOMM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'OPEN'.
PERFORM OPEN_FILE_AND_SAVE.
WHEN OTHERS.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
******************************************************
***görsel tema ayarlamaları sap layout dizininde
***callscrenn içinden sürekle bırak tarzı ayarlamayla
***kendi eşleşmemişse yapılır eğer
******************************************************
*--------------------------------------------------------*
* FORM COPY_FILE
*--------------------------------------------------------*
*TEXT
*--------------------------------------------------------*
*--> P_WORD_SOURCE TEXT
*<-- p="" p_word_destination="" text="">*--------------------------------------------------------*
FORM COPY_FILE USING P_SOURCE
P_DESTINATION.
REFRESH : WORD-BIN_DATA.
* Önce yerelden dosya bınary olarak okunur
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
EXPORTING
FILENAME = P_SOURCE
FILETYPE = 'BIN'
IMPORTING
FILELENGTH = WORD-DOC_SIZE
CHANGING
DATA_TAB = WORD-BIN_DATA[]
EXCEPTIONS
FILE_OPEN_ERROS = 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
SPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOW_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
NOT_SUPPORTED_BY_GUI = 17
ERROR_NO_GUI = 18
OTHERS = 19.
*BINARY veri sap dizinine yazılır
PERFORM WRITE_DESTINATION_BIN_DATA USING P_DESTINATION.
ENDFORM.
*--------------------------------------------------*
* FORM WRITE_DESTINATION_BIN_DATA
*--------------------------------------------------*
*TEXT
*--------------------------------------------------*
*-->P_BIN_DATA TEXT
*<--p_p_destination nbsp="" p="" text="">*--------------------------------------------------*
FORM WRITE_DESTIONATION_BIN_DATA USING P_DESTINATION.
DATA : RECLEN TYPE I,
FILE_STR_ TYPE STRING,
DOC_SIZE TYPE I.
FILE_STR = P_DESTIONATION.
DOC_SIZE = WORD-DOC-SIZE.
*HEDEF DOSYAYI AÇ
OPEN DATASET FILE_STR FOR OUTPUT IN BINARY MODE.
IF SY-SUBRC EQ 0.
CLEAR GV-SUBRC.
*BİNARY VERİYİ KAYDET
LOOP AT WORD-BIN_DATA INTO BIN.
DESCRIBE FIELD BIN-DATA LENGTH RECLEN IN BYTE MODE.
IF DOC_SIZE > RECLEN.
DOC_SIZE = DOC_SIZE - RECLEN.
ELSE.
RECLEN = DOC_SIZE.
ENDIF.
TRANSFER BIN-DATA TO P_DESTINATIONLENGTH RECLEN.
ENDLOOP.
CLOSE DATASET FILE_STR.
COMMIT WORK AND WAIT.
ELSE.
GV-SUBRC = 4.
MESSAGE S000(L1) WITH P_DESTINATION
'konumuna erişilmiyor...'.
ENDIF.
ENDFORM. " WRITE_DESTINATION_BIN_DATA
**************************************************************
*-----------------------------------------------*
* Form DISPLAY_DOCUMENT
*-----------------------------------------------*
*TEXT
*-----------------------------------------------*
*--> P1 TEXT
*<-- p2="" p="" text="">*-----------------------------------------------*
FORM DISPLAY_DOCUMENT.
CHECK WORD-SOURCE IS NOT INITIAL.
CHECK GV-SUBRC IS INITIAL.
*Ekrandaki konteyner ile programdaki konteyner nesnesinin eşleştirilmesi
IF WORD-CONTAINER IS INITIAL.
CREATE OBJECT WORD-CONTAINER
EXPORTING
CONTAINER_NAME = 'CONTAINER_FOR_WORD'
EXCEPTİONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
CREATE_ERROR = 3
LIFETIME_ERROR = 4
LIFETIME_DYNPRO_LINK = 5
OTHERS = 6.
ENDIF.
*ole nesnesinin yaratılması
C_OI_CONTAINER_CONTROL_CREATOR=> GET_CONTAINER_CONTROL(
IMPORTING CONTROL = WORD-OLE RETCODE = WORD-RETCODE ).
C_IO_ERRORS => RAISE_MESSAGE( 'E' ).
*Word nesnesinin yaratılması
WORD-OKE -> INIT_CONTROL (
EXPORTING R3_APPLICATION_NAME = 'Doc'
INPLACE_ENABLED = 'X'
INPLACE_SCROLL_DOCUMENTS = 'X'
PARENT = WORD-CONTAINER
REGISTER_ON_CLOSE_EVENT = 'X'
REGISTER_ON_CLOSE_EVENT = 'X'
IMPORTING RETCODE = WORD-RETCODE ).
C_OI_ERROS => RAISE_MESSAGE( ' E ' ).
*Dokuman sınıf nesnesinin yaratılması
WORD-OLE->GET_DOCUMENT_PROXY(
EXPORTING DOCUMENT_TYPE = 'Word.documnet.12'
DOCUMNET_FORMAT = 'OLE'
IMPORTING DOCUMENT_PROXY = WORD-DOCUMENT
RETCODE = WORD-RETCODE ).
IF WORD-RETCODE NE C_OI_ERROS => RET_OK.
EXIT.
ENDIF.
*BINARY verinin ekranda görüntülenmesi
CALL METHOD WORD-DOCUMENT->OPEN_DOCUMENT_FROM_TABLE
EXPORTING
DOCUMENT_TABLE = WORD-BIN_DATA[]
DOCUMENT_SIZE = WORD-DOC_SIZE
DOCUMENT_TITLE = 'Word notepad'
OPEN_INPLACE = 'X'
NO_FLUSH = ' '
IMPORTING
RETCODE = WORD-RETCODE.
*HATA YAKALAMA
IF WORD-RETCODE NE C_OI_ERRORS=>RET_OK.
MESSAGE I000(L1) WITH WORD-RETCODE.
EXIT.
ENDIF. " DISPLAY_DOCUMENT
*--------------------------------------------------------*
* FORM OPEN FILE_AND_SAVE
*--------------------------------------------------------*
* TEXT
*--------------------------------------------------------*
* --> P1 TEXT
* <-- nbsp="" p2="" p="" text="">*--------------------------------------------------------*
FORM OPEN_FILE_AND_SAVE .
* kaynak dosya adının alınması
PERFORM GET_FILE CHANGING WORD-SOURCE.
CHECK GV-SUBRC IS INITIAL.
* Yerel dizinden sap dizinine dosyanın kopyalanması
PERFORM COPY_FILE USING WORD-SOURCE WORD-DESTINATION.
CHECK GV_SUBRC IS INITIAL.
MESSAGE S000(L1) WITH 'Döküman içeri aktarıldı...'.
ENDFORM.
*--------------------------------------------------------*
* Form GET_FILE
*--------------------------------------------------------*
* TEXT
*--------------------------------------------------------*
*-->P1 TEXT
*<--p2 p="" text="">*--------------------------------------------------------*
FORM GET_FILE CHANGING P_FILE.
DATA : LV_RC TYPE I,
LV_FILENAME TYPE STRING,
LT_FILELIST TYPE FILETABLE.
CLEAR : LT_FILELIST[],
LV_RC.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
EXPORTING
FILE_FILTER = CL_GUI_FRONTEND_SERVICES=>FILETYPE_WORD
MULTISELECTION = SPACE
DEFAULT_FILENAME = '*.doc'
CHANGING
FILE_TABLE = LT_FILELIST
RC = LV_RC.
IF LINES( LT_FILELIST ) IS INITIAL.
MESSAGE S000(L1) WITH 'Dosya secmediniz!'.
GV-SUBRC = 4.
RETURN.
ENDIF.
READ TABLE LT_FILELIST INDEX 1 INTO LV_FILENAME .
P_FILE = LV_FILENAME.
GV-SUBRC = SY-SUBRC.
ENDFORM.
report**
*Global değişkenler
Data : BEGIN OF GV,
UCOMM LIKE SY-UCOMM,
SUBRC LIKE SY-SUBRC,
END OF GV.
*BINARY formatı için satır yapısı
DATA : BEGIN OF BIN,
DATA(1024) TYPE X ,
END OF BIN.
* DÖKÜMAN
DATA : BEGIN OF WORD,
*döküman nesnesi
DOCUMENT TYPE REF TO I_OI_DOCUMENT_PROXY,
*ole sınıfı
OLE TYPE REF TO O_IO_CONTAINER_CONTROL,
* ekradaki contaıner nesnesi
CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
*hata sınıfı
ERROR TYPE REF TO I_OI_ERROR,
* hata mesajı formatı
RET CODE TYPE SOI_RET_STRING,
*BINARY VERİ
BIN_DATA LIKE TABLE OF BIN,
*Dokumann boyutu
DOC_SIZE TYPE I ,
* Dokumanın okunacagı yerel dizin
source type string,
*döküman kaydedileceği dizin
DESTİNATİON TYPE STRİNG VALUE '\USR\SAP\TRANS\.DOC'.
end of word.
START-OF-SELECTİON.
*User command rutinine ek ***
WHEN ' DOWNLOAD '.
*BINARY VERİYİ OKU
PERFORM GET_DATASET_BIN_FILE USING WORD-DESTINATION.
*BINARY VERİYİ YEREL DİZİNE KAYDET
PERFORM DOWNLOAD_BIN_DATA..
* bın dosyasının alınması **
*--------------------------------------*
* Form GET_DATASET_BIN_FILE
*--------------------------------------*
* TEXT
*--------------------------------------*
*-->P_BIN_DATA TEXT
*-->P_L_FILE TEXT
*<--p_doc_size p="" text="">*--------------------------------------*
FORM GET_DATASET_BIN_FILE USING P_FILE.
DATA : FILEDATA TYPE XSTRING,
STR_FILE TYPE STRING.
REFRESH : WORD-BIN_DATA.
STR_FILE = P_FILE.
OPEN DATASET STR_FILE FOR INPUT IN BINARY MODE.
IF SY-SUBRC EQ 0 .
GV-SUBRC = 0.
DO.
READ DATASET STR_FILE INTO FILEDATA.
IF SY-SUBRC <> 0.
EXIT.
ELSE.
CLOSE DATASET STR_FILE.
EXIT.
ENDIF.
ENDDO.
ELSE.
GV-SUBRC = 4.
MESSAGE S000(L1) WITH P_FILE 'konumuna erişilmiyor...'.
EXIT.
ENDIF.
* xstrıng veriyi bınary formatına çevir
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = FILEDATA
IMPORTING
OUTPUT_LENGTH = WORD-DOC_SIZE
TABLES
BINARY_TAB = WORD-BIN_DATA.
ENDFORM. " GET_DATASET_BIN_FILE
*----------------------------------*
* Form DOWNLOAD_BIN_DATA
*----------------------------------*
* TEXT
*----------------------------------*
* -->P1 TEXT
* <--p2 nbsp="" p="">*----------------------------------*
FORM DOWNLOAD_BIN_DATA.
DATA : LV_DESKTOP TYPE STRING.
* Masaüstü dizinini al
CALL METHOD CL_GUI_FRONTED_SERVICES=>GET_DESKTOP_DIRECTORY
CHANGING
DESKTOP_DIRECTORY = LV_DESKTOP.
CALL METHOD CL_GUI_CFW=>FLUSH.
CONCATENATE LV_DESKTOP '\*.doc' INTO LV_DESTOP.
CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD(
EXPORTING
BIN_FILESIZE = WORD-DOC_SIZE
FILENAME = LV_DESKTOP
FILETYPE = 'BIN'
CHANGING
DATA_TAB = WORD-BIN_DATA[]
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_WRITE = 12
DP_ERROR_SEND = 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
NOT_SUPPORTED_BY_GUI= 22
ERROR_NO_GUI = 23
OTHERS = 24
).
IF SY-SUBRC EQ 0 .
MESSAGE S000(L1) WITH 'DOSYA' LV_ DESKTOP ' konumuna indirildi..'.
else.
MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4
DISPLAY LIKE 'E'.
ENDIF.
ENDFORM. " DOWNLOAD_BIN_DATA
Hiç yorum yok:
Yorum Gönder