Skip to Content

Hello community,

often developers has the problem that not all applications, which are necessary for their development, are available at the right time. So it is necessary to simulate one or the other application. Here is a solution how to simulate a conversion for images from e-mail attachments, e.g. for an ERMS (E-mail Response Management System). An example: The office worker gets an e-mail from a customer about a case of damage with a photo from his camera. The photo has not a normal format like jpeg or tif. For a fast claims processing it is necessary to convert the photo in pdf and to store it in the archive. For this case the ERMS offers an automatic conversion – but this conversion is not available now. To convert an image you can use nconvert, it is a part from free available XNview. Convert nconvert with BinFile2ABAP in an ABAP function module. With this function module and nconvertX, an ActiveX library for the presentation server which offers the possiblilty to use nconvert inside ABAP, you can simulate an image conversion. Download the picture below.

/wp-content/uploads/2013/12/nconvertx_350755.jpg

Here an source example, to show how easy an conversion could be:

Function ZNCONVERTX.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(TARGETFILETYPE) TYPE  STRING
*"     VALUE(SOURCEFILENAME) TYPE  STRING
*"----------------------------------------------------------------------

  "-Constants-----------------------------------------------------------
    Constants SW_HIDE Type i Value 0.
    Constants SW_SHOWNORMAL Type i Value 1.

  "-Variables-----------------------------------------------------------
    Data oConv Type OLE2_OBJECT.
    Data WorkDir Type String Value ''.
    Data rc Type i Value 0.
    Data Params Type String Value ''.

  "-Macros--------------------------------------------------------------
    Define Flush.
      Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.
    End-Of-Definition.

  "-Main----------------------------------------------------------------

    "-Unpack nconvert.exe to work directory-----------------------------
      Call Function 'ZNCONVERTEXE'.

    Create Object oConv 'nconvertX'.
    If sy-subrc <> 0 Or  oConv-Handle = 0 Or oConv-Type <> 'OLE2'.

      "-Unpack nconvertX.dll to work directory and registers the library
        Call Function 'ZNCONVERTXDLL'.

      Create Object oConv 'nconvertX'.

    EndIf.

    If sy-subrc = 0 And oConv-Handle > 0 And oConv-Type = 'OLE2'.

      Call Method cl_gui_frontend_services=>get_sapgui_workdir
        Changing
          SAPWORKDIR = WorkDir
        Exceptions
          Others = 1.

      Translate TargetFileType To Lower Case.
      Concatenate `-out ` TargetFileType ` ` SourceFileName Into Params.

      "-Converts the image to another format----------------------------
        Call Method Of oConv 'NConvert' = rc Exporting #1 = WorkDir
          #2 = Params #3 = SW_HIDE #4 = 1.
      Flush.

      Free Object oConv.

    EndIf.

EndFunction.

001.JPG

This function module converts with this arguments the image 001.bmp to pdf. All files are in the SAP GUI work directory.

nconvert supports 493 different formats. It is also possible to resize the images or to do a lot of other things.

To convert an image to a specific format type e.g. a few files to tif:

nconvert -out tiff file1.pic file2.jpg file3.tga

With nconvert and nconvertX it is very easy to simulate an e-mail image attachment conversion.

Enjoy it.

 

Cheers

Stefan

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply