Tips and Tricks for the ABAP® Programming Language

Z_IE_SHOWPIC – Upload a picture into SAP and save it as standard text

This program contains several forms, they can: upload a picture into SAP and save it as standard text;download the standard text format file to PC and explore it with MS Internet Explorer.  These functions may help when somebody wants to save pictures inside SAP and wants to show them on frontend. It’s not so good that SAPgui before release 4.6 can not display colorful pictures. When EnjoySAP appears, this program becomes useless. Just read it for fun.

Parameters:

PICFILE(128) TYPE C,  ” PC FILE TO UPLOAD
TEXTNAME(128) TYPE C. ” NAME OF STANDARD TEXT

ABAP-Source-Code

You can copy and paste the source code directly into the ABAP-Workbench.

REPORT Z_IE_SHOWPIC LINE-SIZE 250.
*
**********************         HEADER                    **************
*
* Copyright (c) 1999 by Yang Song, Basis/ABAP consultant in China,
*                       email: sungari@public2.sta.net.cn
*
*     You can use or modify this report for your own work as long
*               as you don't try to sell or republish it.
*      In no event will the author be liable for indirect, special,
*        Incidental, or consequental damages (if any) arising out of
*                       the use of this report.
*/////////////////////////////////////////////////////////////////*
*
INCLUDE OLE2INCL. "OLE INCLUDE
************************************************************************
*
PARAMETERS:
   PICFILE(128) TYPE C DEFAULT 'C:\temp\gomera01.jpg', "PCFILE TO UPLOAD
   TEXTNAME(128) TYPE C DEFAULT 'GOMERA'.         "NAME OF STANDARD TEXT
*
************************************************************************
DATA: TEXTTAB LIKE TLINE OCCURS 2000 WITH HEADER LINE.
DATA: BEGIN OF HEXTAB OCCURS 1000,
      LINE(33) TYPE X,
      END OF HEXTAB.
DATA: SIZE TYPE I .                    "SIZE OF FILE'
DATA: TEXTHEAD LIKE THEAD.
DATA: NAVIAGTOR TYPE OLE2_OBJECT.
************************************************************************
START-OF-SELECTION.
*
  PERFORM UPLOAD_PIC USING PICFILE TEXTNAME.
  PERFORM DOWNLOAD_PIC USING 'C:\TEMP\SAPTEST.JPG' TEXTNAME.
  PERFORM SHOW_PIC USING 'C:\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(128) TYPE 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.