cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Insertion of graphics in Smart from

Former Member
0 Kudos

Hi guys,

I want to insert a dynamic graphic image from the presentation server into smart from its possible?

Reg,

Hriharan

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Yesterday I found a way to go through.

The solution is:

- Use the IGS class cl_igs_chart_engine to produce a GIF of your chart.

- Use the IGS class cl_igs_image_converter to convert that gif into a image/x-ms-bmp

- Next, call function SAPSCRIPT_CONVERT_BITMAP_BDS to convert the BMP into a BDS table

- then, save the BDS to graphics. To do that, use the coding like shown in the import function of SE78. I made an include file with 343 lines out of that.

Ready.

Now you can use a SmartForm graphics element to print out your chart beside other data.

Former Member
0 Kudos

Hi Ernst,

I'm having the same problem as yours. I need to generate the graph dynamically on smartforms as well but having a hard time to do it. Could you give me the example code on how to achieve this?

Your helps is very much appreciated.

Thanks.

Regards

Former Member
0 Kudos

Hi Mohd,

here's how to do it.

I presume you have alredy done charting in general with the cl_gui_chart_engine. You need the data and the customizing XML strings of that chart to print it out.

Follow this coding:

    DATA: l_igs_viewer TYPE REF TO cl_igs_chart_engine,
          i_igs_image_converter TYPE REF TO cl_igs_image_converter.
* Generate an Internet Graphics Server Chart Engine
    CREATE OBJECT l_igs_viewer
      EXPORTING
        destination = 'GFW_ITS_RFC_DEST'.  "IGS must exist, destination be installed
* IGS gets data and customizing
    CALL METHOD l_igs_viewer->set_data( data_doc = l_ixml_doc ).
    CALL METHOD l_igs_viewer->set_customizing(
      custom_doc = l_ixml_custom_doc ).
* and now renders the chart.
    CALL METHOD l_igs_viewer->execute
      EXCEPTIONS
        communication_error = 1
        internal_error      = 2
        external_error      = 3
        OTHERS              = 4.
* Next step ist to convert the image to an MS-BMP.
      DATA:
        l_image TYPE  w3mimetabtype,
        l_image_size  TYPE  w3param-cont_len,
        l_image_type  TYPE  w3param-cont_type.
* get your image
      CALL METHOD l_igs_viewer->get_image
        IMPORTING
          image      = l_image
          image_size = l_image_size
          image_type = l_image_type.
* Create an image converter on the IGS 
      CREATE OBJECT i_igs_image_converter
        EXPORTING
          destination = 'GFW_ITS_RFC_DEST'.
      i_igs_image_converter->input = 'image/gif'.
      i_igs_image_converter->output = 'image/x-ms-bmp'. " !!!!
* Hand the image over
      CALL METHOD i_igs_image_converter->set_image
        EXPORTING
          blob      = l_image
          blob_size = l_image_size.
* and convert it to a BMP
      CALL METHOD i_igs_image_converter->execute
        EXCEPTIONS
          communication_error = 1
          internal_error      = 2
          external_error      = 3
          OTHERS              = 4.
      IF sy-subrc = 0.
* if OK, get that image.
        CALL METHOD i_igs_image_converter->get_image
          IMPORTING
            blob      = l_image
            blob_size = l_image_size
            blob_type = l_image_type.
      ENDIF.
    ENDIF.

At this point, we have a BMP-24, and we are ready to save it to the SE78 BDS graphics system.

This is by far the slowest part of the story. Not applicable for mass printing, the conversion of a bitmap can take up to 1 minute!


    DATA: l_docid TYPE stxbitmaps-docid.

    PERFORM save_bitmap_bds
            USING    'TEMP_CHART0181'
                     'GRAPHICS' 'BMAP' 'BCOL' 'BMP'
                     'Temporäre Grafik Chart 0181'(i16)
                     con_blank
                     con_x
                     con_x
            CHANGING
                     l_image_size
                     l_image
                     l_docid.

The next part ist the form that converts and saves the BMP to BDS.


FORM save_bitmap_bds
    USING    p_name           TYPE stxbitmaps-tdname
             p_object         TYPE stxbitmaps-tdobject
             p_id             TYPE stxbitmaps-tdid
             p_btype          TYPE stxbitmaps-tdbtype
             p_format         TYPE c
             p_title          TYPE bapisignat-prop_value
             p_resident       TYPE stxbitmaps-resident
             p_autoheight     TYPE stxbitmaps-autoheight
             p_bmcomp         TYPE stxbitmaps-bmcomp
    CHANGING
             p_image_size     TYPE i
             p_image          TYPE w3mimetabtype
             p_docid          TYPE stxbitmaps-docid.

  DATA: l_object_key      TYPE sbdst_object_key.
  DATA: l_tab             TYPE ddobjname.
  DATA: l_filename        TYPE string,
        l_bytecount       TYPE i,
        l_error           TYPE c.
  DATA: l_color(1)        TYPE c.
  DATA: l_bds_object      TYPE REF TO cl_bds_document_set,
        l_bds_content     TYPE sbdst_content,
        l_bds_components  TYPE sbdst_components,
        l_dpi             TYPE  stxbitmaps-resolution,
        wa_bds_components TYPE LINE OF sbdst_components,
        l_bds_signature   TYPE sbdst_signature,
        wa_bds_signature  TYPE LINE OF sbdst_signature,
        l_bds_properties  TYPE sbdst_properties,
        wa_bds_properties TYPE LINE OF sbdst_properties.
  DATA  wa_stxbitmaps TYPE stxbitmaps.

  DATA:
    l_width_tw TYPE  stxbitmaps-widthtw,
    l_height_tw TYPE  stxbitmaps-heighttw,
    l_width_pix TYPE  stxbitmaps-widthpix,
    l_height_pix TYPE  stxbitmaps-heightpix,
    l_bds_bytecount TYPE  i,
    l_docid TYPE stxbitmaps-docid.

  CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP_BDS'
    EXPORTING
      color                     = 'X'
      format                    = 'BMP'
      bitmap_bytecount          = p_image_size
      compress_bitmap           = 'X'
    IMPORTING
      width_tw                  = l_width_tw
      height_tw                 = l_height_tw
      width_pix                 = l_width_pix
      height_pix                = l_height_pix
      dpi                       = l_dpi
      bds_bytecount             = l_bds_bytecount
    TABLES
      bitmap_file               = p_image
      bitmap_file_bds           = l_bds_content
    EXCEPTIONS
      format_not_supported      = 1
      no_bmp_file               = 2
      bmperr_invalid_format     = 3
      bmperr_no_colortable      = 4
      bmperr_unsup_compression  = 5
      bmperr_corrupt_rle_data   = 6
      tifferr_invalid_format    = 7
      tifferr_no_colortable     = 8
      tifferr_unsup_compression = 9
      bmperr_eof                = 10
      OTHERS                    = 11.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

* Enqueue
  PERFORM enqueue_graphic USING p_object
                                p_name
                                p_id
                                p_btype
                          CHANGING l_error.
  CHECK l_error EQ con_blank.

  SELECT SINGLE docid INTO p_docid
    FROM stxbitmaps
    WHERE tdobject = p_object
      AND   tdname   = p_name
      AND   tdid     = p_id
      AND   tdbtype  = p_btype.
  IF sy-subrc NE 0.
    CLEAR p_docid.
  ENDIF.
  IF p_btype = c_bmon.
    l_color = con_blank.
  ELSE.
    l_color = con_x.
  ENDIF.

* Save bitmap in BDS
  CREATE OBJECT l_bds_object.

  wa_bds_components-doc_count  = '1'.
  wa_bds_components-comp_count = '1'.
  wa_bds_components-mimetype   = c_bds_mimetype.
  wa_bds_components-comp_size  = l_bds_bytecount.
  APPEND wa_bds_components TO l_bds_components.

  IF p_docid IS INITIAL.          " graphic is new

    wa_bds_signature-doc_count = '1'.
    APPEND wa_bds_signature TO l_bds_signature.

    CALL METHOD l_bds_object->create_with_table
      EXPORTING
        classname  = c_bds_classname
        classtype  = c_bds_classtype
        components = l_bds_components
        content    = l_bds_content
      CHANGING
        signature  = l_bds_signature
        object_key = l_object_key
      EXCEPTIONS
        OTHERS     = 1.
    IF sy-subrc <> 0.
      PERFORM dequeue_graphic USING p_object
                                    p_name
                                    p_id
                                    p_btype.
      MESSAGE e012 WITH p_name  'BDS'.
    ENDIF.
    READ TABLE l_bds_signature INDEX 1 INTO wa_bds_signature
    TRANSPORTING doc_id.
    IF sy-subrc = 0.
      p_docid = wa_bds_signature-doc_id.
    ELSE.
      PERFORM dequeue_graphic USING p_object
                                    p_name
                                    p_id
                                    p_btype.
      MESSAGE e012 WITH p_name 'BDS'.
    ENDIF.

  ELSE.                " graphic already exists
********* read object_key for faster access *****
    CLEAR l_object_key.
    SELECT SINGLE * FROM stxbitmaps INTO wa_stxbitmaps
        WHERE tdobject = p_object
          AND tdid     = p_id
          AND tdname   = p_name
          AND tdbtype  = p_btype.
    SELECT SINGLE tabname FROM bds_locl INTO l_tab
       WHERE classname = c_bds_classname
          AND classtype = c_bds_classtype.
    IF sy-subrc = 0.
      SELECT SINGLE object_key FROM (l_tab) INTO l_object_key
        WHERE loio_id = wa_stxbitmaps-docid+10(32)
          AND classname = c_bds_classname
            AND classtype = c_bds_classtype.
    ENDIF.
******** read object_key end ********************

    CALL METHOD l_bds_object->update_with_table
      EXPORTING
        classname     = c_bds_classname
        classtype     = c_bds_classtype
        object_key    = l_object_key
        doc_id        = p_docid
        doc_ver_no    = '1'
        doc_var_id    = '1'
      CHANGING
        components    = l_bds_components
        content       = l_bds_content
      EXCEPTIONS
        nothing_found = 1
        OTHERS        = 2.
    IF sy-subrc = 1.   " inconsistency STXBITMAPS - BDS; repeat check in
      wa_bds_signature-doc_count = '1'.
      APPEND wa_bds_signature TO l_bds_signature.

      CALL METHOD l_bds_object->create_with_table
        EXPORTING
          classname  = c_bds_classname
          classtype  = c_bds_classtype
          components = l_bds_components
          content    = l_bds_content
        CHANGING
          signature  = l_bds_signature
          object_key = l_object_key
        EXCEPTIONS
          OTHERS     = 1.
      IF sy-subrc <> 0.
        PERFORM dequeue_graphic USING p_object
                                      p_name
                                      p_id
                                      p_btype.
        MESSAGE e012 WITH p_name 'BDS'.
      ENDIF.
      READ TABLE l_bds_signature INDEX 1 INTO wa_bds_signature
      TRANSPORTING doc_id.
      IF sy-subrc = 0.
        p_docid = wa_bds_signature-doc_id.
      ELSE.
        PERFORM dequeue_graphic USING p_object
                                      p_name
                                      p_id
                                      p_btype.
        MESSAGE e012 WITH p_name 'BDS'.
      ENDIF.
    ELSEIF sy-subrc = 2.
      PERFORM dequeue_graphic USING p_object
                                    p_name
                                    p_id
                                    p_btype.
      MESSAGE e012 WITH p_name 'BDS'.
    ENDIF.
  ENDIF.

* Save bitmap header in STXBITPMAPS
  wa_stxbitmaps-tdname     = p_name.
  wa_stxbitmaps-tdobject   = p_object.
  wa_stxbitmaps-tdid       = p_id.
  wa_stxbitmaps-tdbtype    = p_btype.
  wa_stxbitmaps-docid      = p_docid.
  wa_stxbitmaps-widthpix   = l_width_pix.
  wa_stxbitmaps-heightpix  = l_height_pix.
  wa_stxbitmaps-widthtw    = l_width_tw.
  wa_stxbitmaps-heighttw   = l_height_tw.
  wa_stxbitmaps-resolution = l_dpi.
  wa_stxbitmaps-resident   = p_resident.
  wa_stxbitmaps-autoheight = p_autoheight.
  wa_stxbitmaps-bmcomp     = p_bmcomp.
  INSERT INTO stxbitmaps VALUES wa_stxbitmaps.
  IF sy-subrc <> 0.
    UPDATE stxbitmaps FROM wa_stxbitmaps.
    IF sy-subrc <> 0.
      MESSAGE e012 WITH p_name 'STXBITMAPS'.
    ENDIF.
  ENDIF.

* Set description in BDS attributes
  wa_bds_properties-prop_name  = 'DESCRIPTION'.
  wa_bds_properties-prop_value = p_title.
  APPEND wa_bds_properties TO l_bds_properties.

  CALL METHOD l_bds_object->change_properties
    EXPORTING
      classname  = c_bds_classname
      classtype  = c_bds_classtype
      object_key = l_object_key
      doc_id     = p_docid
      doc_ver_no = '1'
      doc_var_id = '1'
    CHANGING
      properties = l_bds_properties
    EXCEPTIONS
      OTHERS     = 1.

  PERFORM dequeue_graphic USING p_object
                                p_name
                                p_id
                                p_btype.

ENDFORM.                    "save_bitmap_bds

Your final part will now be to print out the graphic using a SmartForm. The method I showed above, saves the graphics always with the same name, in this case TEMP_CHART0181. So this method is not qualified for concurrent use by multiple users.

Try it out and see how slow this works unfortunately.

I hope SAP will provide a performant way soon to print charts with smartforms better than that above.

One last hint concerning size and resolution of the bitmap. Take a low resolution of say 50 dpi to gain higher performance but lower print quality. I never tried high resolutions of like 300dpi, it just became too slow for me and I qualified that as simply unpracticable.

I hope the coding snippets can help you.

Kind Regards

Ernst

0 Kudos

Hi,

I am trying to use almost similar algorithim to store an image into BDS. But in my case the image is stored in MIME. The content of the image is TYPE xstring. This Xstring content is all I have to store the image into BDS.

I am having problem in Converting the image to BDS BMP format using :


CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP_BDS'
  EXPORTING
    color                    = 'X'
    format                   = 'BMP'
    resident                 = p_resident
    bitmap_bytecount         = l_bytecount
    compress_bitmap          = 'X'
  IMPORTING
    bds_bytecount            = l_bds_bytecount
  TABLES
    bitmap_file              = l_bitmap
    bitmap_file_bds          = l_bds_content.

I am not passing anything in the l_bds_bytecount. l_bitmap is defined as-


DATA: BEGIN OF l_bitmap OCCURS 0,
        l(64) TYPE x,
      END OF l_bitmap.

Could anybody help me out how to get the converted BMP using this function?

Many Thanks,

Rajib Shome

0 Kudos

Hi.

Thank you very much for your code, it helped me soooo much in my graphic conversion.

I missed just two forms in your code, enqueue_graphic and dequeue_graphic. Can you, please, post them here to know if I lost any important part?

thanks in advance for your help.

BR

0 Kudos

Hi.

Ernst, can You please tell me how to change the resolution?

In my case it is counted automatically and gives me 75 DPI.

I need more, but how ?

THX. Luke.

Former Member
0 Kudos

The result using the cl_igs_chart_engine is on the way, but now I'm experiencing a hard backdrop.

cl_igs_chart_engine generates a BMP graphics with a color depth of 16 bit.

When I try to convert the BMP to BDS Format using the function SAPSCRIPT_CONVERT_BITMAP_BDS, I'm facing the fact that this function converts bitmaps with 1, 4, 8, 24 bit, but not with 16 or 32 bit

I'll have to find a way getting around that. If I can solve this problem, the problem to printing charts with SmartForms may be solved.

Former Member
0 Kudos

I have the same problem. I want to print a chart that was generated with CL_GUI_CHART_ENGINE with a SmartForm.

The way to go I think is:

- Save the chart.

- Import the chart into GRAPHICS (like using SE78, this time automated)

- Print that GRAPHICS object with SmartForms

The chart is a kind of actual project overview. The name of that chart would be reused. The SmartForm can access a static graphics object.

So the question is, how do I save a CL_GUI_CHART_ENGINE Chart to a file that can be imported as a SE78 form graphic. I found no method that provides this functionality.

Importing the file object (BMP, PNG, or whatever) into GRAPHICS like in SE78 would be the next step but not a problem I think.