Thursday, January 20, 2022

Upload a picture into SAP and save it as standard text

REPORT ZPICUPLOAD LINE-SIZE 250.

*
INCLUDE OLE2INCL"OLE INCLUDE
************************************************************************
*
PARAMETERS:
   PICFILE(128TYPE DEFAULT 'C:\temp\xyz.jpg'"PCFILE TO UPLOAD
   TEXTNAME(128TYPE DEFAULT 'GOMERA'.         "NAME OF STANDARD TEXT
*
************************************************************************
DATATEXTTAB LIKE TLINE OCCURS 2000 WITH HEADER LINE.
DATABEGIN OF HEXTAB OCCURS 1000,
      LINE(33TYPE X,
      END OF HEXTAB.
DATASIZE TYPE .                    "SIZE OF FILE'
DATATEXTHEAD LIKE THEAD.
DATANAVIAGTOR TYPE OLE2_OBJECT.
************************************************************************
START-OF-SELECTION.
*
  PERFORM UPLOAD_PIC USING PICFILE TEXTNAME.
  PERFORM DOWNLOAD_PIC USING 'D:\TEMP\SAPTEST.JPG' TEXTNAME.
  PERFORM SHOW_PIC USING 'D:\TEMP\SAPTEST.JPG'.
*
END-OF-SELECTION.
*
************************************************************************
*                  upload picture (.jpg)
************************************************************************
FORM UPLOAD_PIC USING OSFILE SAPFILE.
 TEXTHEAD-TDNAME SAPFILE.
  CALL FUNCTION 'WS_UPLOAD'
       EXPORTING
            CODEPAGE '8400'
            FILETYPE 'BIN'
            FILENAME OSFILE
       IMPORTING
            FILELENGTH SIZE
       TABLES
            DATA_TAB HEXTAB
       EXCEPTIONS
            OTHERS   7.
  CALL FUNCTION 'INIT_TEXT'
       EXPORTING
            ID       'ST'
            LANGUAGE 'E'
            NAME     TEXTHEAD-TDNAME
            OBJECT   'TEXT'
       IMPORTING
            HEADER   TEXTHEAD
       TABLES
            LINES    TEXTTAB
       EXCEPTIONS
            OTHERS   5.
  CALL FUNCTION 'SAVE_TEXT'
       EXPORTING
            CLIENT          SY-MANDT
            HEADER          TEXTHEAD
            SAVEMODE_DIRECT 'X'
       TABLES
            LINES           TEXTTAB
       EXCEPTIONS
            OTHERS          5.
ENDFORM.                               "END OF UPLOADING
************************************************************************
*       FORM DOWNLOAD_PIC                                             *
************************************************************************
FORM DOWNLOAD_PIC USING OSFILE SAPFILE.
  LOOP AT TEXTTAB.
    HEXTAB-LINE TEXTTAB-TDLINE.
    APPEND HEXTAB.
  ENDLOOP.
  CALL FUNCTION 'WS_DOWNLOAD'
       EXPORTING
            BIN_FILESIZE SIZE
            CODEPAGE     '8400'
            FILENAME     OSFILE
            FILETYPE     'BIN'
       TABLES
            DATA_TAB     HEXTAB
       EXCEPTIONS
            OTHERS       7.
ENDFORM.                               " ENDOF DOWNLOAD PICTURE
************************************************************************
*       FORM SHOW_PIC                                                 *
************************************************************************
FORM SHOW_PIC USING OSFILE.
  DATA PATH(128TYPE C.
  CREATE OBJECT NAVIAGTOR 'INTERNETEXPLORER.APPLICATION'.
  SET PROPERTY OF NAVIAGTOR 'MENUBAR' 0.
  SET PROPERTY OF NAVIAGTOR 'TOOLBAR' 0.
  SET PROPERTY OF NAVIAGTOR 'STATUSBAR' 1.
  CONCATENATE 'FILE://' OSFILE INTO PATH.
  CALL METHOD OF NAVIAGTOR 'NAVIGATE' EXPORTING #1 PATH.
  SET PROPERTY OF NAVIAGTOR 'STATUSTEXT' 'PICTURE FROM SAP'.
  SET PROPERTY  OF NAVIAGTOR 'VISIBLE' 1.
ENDFORM.                               " ENDOF SHOW_PIC.

No comments:

Post a Comment