[ABAP] Charts mit Klasse cl_igs_chart anzeigen

* https://help.sap.com/saphelp_nwpi71/helpdata/en/46/8e558550b568bde10000000a155369/frameset.htm
* IGS-Administration: Transaktion SIGS / Report GRAPHICS_IGS_ADMIN
* Demo: GRAPHICS_IGS_CHART_TEST

TRY.
* Default RFC-Destination für IGS (Internet Graphics Server)
    DATA(lv_rfc_dest) = CONV char32( 'IGS_RFC_DEST' ).

* RFC-Destination festlegen
    cl_gfw=>its_rfc_dest = lv_rfc_dest.

* Ist der IGS Chart interpreter erreichbar?
    IF abap_true = cl_igs_data=>is_registered_type( destination = lv_rfc_dest
                                                    type        = cl_igs_chart=>interpreter_type ).

* IGS Chart-Objekt erzeugen
      DATA(o_igs_chart) = NEW cl_igs_chart( ).

      o_igs_chart->type = cl_igs_chart=>co_type_cols_3d.
      o_igs_chart->width = 640.
      o_igs_chart->height = 480.
      o_igs_chart->title = 'Test Graph'.
      o_igs_chart->title_categories = 'Monat'.
      o_igs_chart->title_values = 'Verbrauch'.
      o_igs_chart->color_scheme = cl_igs_chart=>co_scheme_default.
      o_igs_chart->legend = cl_igs_chart=>co_legend_default.

* Chart-Daten
      o_igs_chart->data = VALUE igs_data_tab(
                                              ( groupid = 'Series 1' y = 10 x = 'Januar' color = 30 datalabel = 'Label 1' extension = 'href="http://www.google.de"' )
                                              ( groupid = 'Series 2' y = 20 x = 'Januar' datalabel = 'Label 2' extension = 'href="http://www.google.de"' )
                                              ( groupid = 'Series 1' y = 15 x = 'Februar' datalabel = 'Label 3' extension = 'href="http://www.google.de"' )
                                              ( groupid = 'Series 2' y = 20 x = 'Februar' datalabel = 'Label 4' extension = 'href="http://www.google.de"' )
                                              ( groupid = 'Series 1' y = 30 x = 'März' datalabel = 'Label 5' extension = 'href="http://www.google.de"' )
                                              ( groupid = 'Series 2' y = 25 x = 'März' datalabel = 'Label 6' extension = 'href="http://www.google.de"' )
                                            ).

* erweiterte Chart-Daten
      o_igs_chart->extension = VALUE igs_ext_tab(
                                                  ( token = 'TITLE' value = 'href="http://www.google.de"' )
                                                  ( token = 'LGNDI' value = 'href="http://www.google.de"' )
                                                ).

      DATA: lv_content_type TYPE w3param-cont_type.
      DATA: lv_content_subtype TYPE w3param-cont_type.
      DATA: lv_content_length TYPE w3param-cont_len.
      DATA: it_mime_content TYPE w3mimetabtype.
      DATA: it_imagemap_html TYPE w3htmltabtype.
      DATA: lv_msg TYPE char255.

* Chart als Image + ImageMap generieren
      o_igs_chart->send( IMPORTING
                           content_type   = lv_content_type
                           content_length = lv_content_length
                           content        = it_mime_content
                           imagemap       = it_imagemap_html
                           msg_text       = lv_msg ).

* Content Typ und Content Subtyp
      SPLIT lv_content_type AT '/' INTO lv_content_type lv_content_subtype.

* HTML-Viewer erzeugen
      DATA(o_html) = NEW cl_gui_html_viewer( parent = cl_gui_container=>default_screen ).

      DATA: lv_mime_content_url TYPE w3url.

* URL zum Image erzeugen
      o_html->load_data( EXPORTING
                           type         = lv_content_type
                           subtype      = lv_content_subtype
                           size         = lv_content_length
                         IMPORTING
                           assigned_url = lv_mime_content_url
                         CHANGING
                           data_table   = it_mime_content ).

* HTML mt eingebetteten Image + Imagemap erzeugen
      DATA(it_html) = VALUE w3htmltabtype( ( line = '<html>' )
                                           ( line = '  <head>' )
                                           ( line = '    <title>IGS Chart Demo</title>' )
                                           ( line = '  </head>' )
                                           ( line = '  <body>' )
                                           ( line = '    <map name=chart>' ) ).

      APPEND LINES OF it_imagemap_html TO it_html.

      APPEND LINES OF VALUE w3htmltabtype( ( line = '    </map>' )
                                           ( line = '    <img src="' && lv_mime_content_url && '" usemap=#chart border=0>' )
                                           ( line = '  </body>' )
                                           ( line = '</html>' ) ) TO it_html.

      DATA: lv_output_url TYPE w3url.

* URL zu HTML erzeugen
      o_html->load_data( EXPORTING
                           type         = 'text'
                           subtype      = 'html'
                         IMPORTING
                           assigned_url = lv_output_url
                         CHANGING
                           data_table   = it_html ).

* HTML im HTML-Viewer anhand der URL anzeigen
      o_html->show_url( url = lv_output_url ).

* Container cl_gui_container=>default_screen erzwingen
      WRITE: / space.
    ENDIF.
  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.

[ABAP] Mit Hilfe der Klasse cl_fxs_image_processor Infos zu einem Bild auslesen, Größe verändern (Resize) und Bildformat konvertieren (Convert)

* Im Beispiel wird das Eingabebild (PNG) nach JPG konvertiert und auf 800x600px in der Größe verändert

* Dateiname der Bilddatei zum hochladen
PARAMETERS: p_fname TYPE file_table-filename OBLIGATORY.
PARAMETERS: p_width TYPE i DEFAULT 800.
PARAMETERS: p_height TYPE i DEFAULT 600.

* wenn die F4-Hilfe für den Dateinamen aufgerufen wird
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.

  DATA: lv_rc TYPE i.
  DATA: it_files TYPE filetable.
  DATA: lv_action TYPE i.

* File-Tabelle leeren, da hier noch alte Einträge von vorherigen Aufrufen drin stehen können
  CLEAR it_files.

* FileOpen-Dialog aufrufen
  TRY.
      cl_gui_frontend_services=>file_open_dialog( EXPORTING
                                                    file_filter = |png (*.png)\|*.png\|{ cl_gui_frontend_services=>filetype_all }|
                                                  CHANGING
                                                    file_table  = it_files
                                                    rc          = lv_rc
                                                    user_action = lv_action ).

      IF lv_action = cl_gui_frontend_services=>action_ok.
* wenn Datei ausgewählt wurde
        IF lines( it_files ) > 0.
* ersten Tabelleneintrag lesen
          p_fname = it_files[ 1 ]-filename.
        ENDIF.
      ENDIF.

    CATCH cx_root INTO DATA(e_text).
      MESSAGE e_text->get_text( ) TYPE 'S' DISPLAY LIKE 'E'.
  ENDTRY.

START-OF-SELECTION.

  TRY.
      DATA: lv_filesize TYPE w3param-cont_len.
      DATA: lv_filetype TYPE w3param-cont_type.
      DATA: it_bin_data TYPE w3mimetabtype.

      WRITE: / p_fname.

* Bild auf Appl. Server hochladen (binary)
      cl_gui_frontend_services=>gui_upload( EXPORTING
                                              filename   = |{ p_fname }|
                                              filetype   = 'BIN'
                                            IMPORTING
                                              filelength = lv_filesize
                                            CHANGING
                                              data_tab   = it_bin_data ).

* solix -> xstring
      DATA(lv_img_data) = cl_bcs_convert=>solix_to_xstring( it_solix = it_bin_data ).

* FXS-Objekt holen
      DATA(o_ip) = NEW cl_fxs_image_processor( ).

* Bild zum Konverter hinzufügen
      DATA(lv_hndl) = o_ip->add_image( iv_data = lv_img_data ).

      DATA: lv_mimetype	TYPE string.
      DATA: lv_xres	TYPE i.
      DATA: lv_yres	TYPE i.
      DATA: lv_xdpi	TYPE i.
      DATA: lv_ydpi	TYPE i.
      DATA: lv_bitdepth	TYPE i.

* Infos holen
      o_ip->get_info( EXPORTING
                        iv_handle   = lv_hndl
                      IMPORTING
                        ev_mimetype = lv_mimetype
                        ev_xres     = lv_xres
                        ev_yres     = lv_yres
                        ev_xdpi     = lv_xdpi
                        ev_ydpi     = lv_ydpi
                        ev_bitdepth = lv_bitdepth ).

* Infos ausgeben
      WRITE: / 'MIME-Type:', lv_mimetype.
      WRITE: / '        X:', lv_xres.
      WRITE: / '        Y:', lv_yres.
      WRITE: / '    X-DPI:', lv_xdpi.
      WRITE: / '    Y-DPI:', lv_ydpi.
      WRITE: / '      Bit:', lv_bitdepth.

* Größe ändern (Resize)
      o_ip->resize( EXPORTING
                      iv_handle = lv_hndl
                      iv_xres   = p_width
                      iv_yres   = p_height ).

* Konvertierung (Convert) nach JPG
* Zielformate können nur sein (andernfalls gibt es eine Exception vom Typ cx_sy_range_out_of_bounds):
*   cl_fxs_mime_types=>co_image_bitmap
*   cl_fxs_mime_types=>co_image_png
*   cl_fxs_mime_types=>co_image_jpeg
      o_ip->convert( EXPORTING
                      iv_handle = lv_hndl
                      iv_format = cl_fxs_mime_types=>co_image_jpeg ).

* Infos holen
      o_ip->get_info( EXPORTING
                        iv_handle   = lv_hndl
                      IMPORTING
                        ev_mimetype = lv_mimetype
                        ev_xres     = lv_xres
                        ev_yres     = lv_yres
                        ev_xdpi     = lv_xdpi
                        ev_ydpi     = lv_ydpi
                        ev_bitdepth = lv_bitdepth ).

* Infos ausgeben
      WRITE: / 'MIME-Type:', lv_mimetype.
      WRITE: / '        X:', lv_xres.
      WRITE: / '        Y:', lv_yres.
      WRITE: / '    X-DPI:', lv_xdpi.
      WRITE: / '    Y-DPI:', lv_ydpi.
      WRITE: / '      Bit:', lv_bitdepth.

* Binärdaten (xstring) des Bildes holen
      DATA(lv_img_conv_data) = o_ip->get_image( EXPORTING iv_handle = lv_hndl ).

* xstring -> solix
      DATA(it_img_conv_data) = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_img_conv_data ).

      WRITE: / |{ p_fname }.jpg|.

* Image lokal speichern
      cl_gui_frontend_services=>gui_download( EXPORTING
                                                filename     = |{ p_fname }.jpg|
                                                filetype     = 'BIN'
                                                bin_filesize = xstrlen( lv_img_conv_data )
                                              CHANGING
                                                data_tab     = it_img_conv_data ).

    CATCH cx_root INTO DATA(e_txt).
      WRITE: / e_txt->get_text( ).
  ENDTRY.

[ABAP] Bilddatei konvertieren mit Hilfe der Klasse cl_igs_image_converter (Internet Graphics Service: Image Converter)

* Demo: GRAPHICS_IGS_IMGCONV_DEMO

* Dateiname der Bilddatei zum hochladen
PARAMETERS: p_fname TYPE file_table-filename OBLIGATORY.

* wenn die F4-Hilfe für den Dateinamen aufgerufen wird
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.

  DATA: lv_rc TYPE i.
  DATA: it_files TYPE filetable.
  DATA: lv_action TYPE i.

* File-Tabelle leeren, da hier noch alte Einträge von vorherigen Aufrufen drin stehen können
  CLEAR: it_files.

* FileOpen-Dialog aufrufen
  TRY.
      cl_gui_frontend_services=>file_open_dialog( EXPORTING
                                                    file_filter = |gif (*.gif)\|*.gif\|{ cl_gui_frontend_services=>filetype_all }|
                                                  CHANGING
                                                    file_table  = it_files
                                                    rc          = lv_rc
                                                    user_action = lv_action ).

      IF lv_action = cl_gui_frontend_services=>action_ok.
* wenn Datei ausgewählt wurde
        IF lines( it_files ) > 0.
* ersten Tabelleneintrag lesen
          p_fname = it_files[ 1 ]-filename.
        ENDIF.
      ENDIF.

    CATCH cx_root INTO DATA(e_text).
      MESSAGE e_text->get_text( ) TYPE 'S' DISPLAY LIKE 'E'.
  ENDTRY.

START-OF-SELECTION.

  TRY.
      DATA: lv_filesize TYPE w3param-cont_len.
      DATA: lv_filetype TYPE w3param-cont_type.
      DATA: it_bin_data TYPE w3mimetabtype.

* Bild auf Appl. Server hochladen (binary)
      cl_gui_frontend_services=>gui_upload( EXPORTING
                                              filename   = |{ p_fname }|
                                              filetype   = 'BIN'
                                            IMPORTING
                                              filelength = lv_filesize
                                            CHANGING
                                              data_tab   = it_bin_data ).

* Konverterobjekt erzeugen
      DATA(o_conv) = NEW cl_igs_image_converter( ).

* MIME-Typen (Format) für input und output festlegen
      o_conv->input  = 'image/gif'.      " Quellformat ist ein GIF
      o_conv->output = 'image/x-ms-bmp'. " Ausgabeformat ist ein BMP

* neue Bildgröße festlegen
*  o_conv->height = '100'. " neue Höhe 100
*  o_conv->width = '100'.  " neue Breite 100

* Bildaten übergeben
      o_conv->set_image( blob      = it_bin_data
                         blob_size = lv_filesize ).

* Image konvertieren
      o_conv->execute( ).

* Anzahl Ergebnisbilder > 0
      IF o_conv->get_image_count( ) > 0.
* Bilddaten im Ausgabeformat holen
        o_conv->get_image( IMPORTING
                             blob      = it_bin_data
                             blob_size = lv_filesize
                             blob_type = lv_filetype ).

* Image lokal speichern
        cl_gui_frontend_services=>gui_download( EXPORTING
                                                  filename     = 'c:\temp\temp.bmp'
                                                  filetype     = 'BIN'
                                                  bin_filesize = lv_filesize
                                                CHANGING
                                                  data_tab     = it_bin_data ).
      ENDIF.
    CATCH cx_root INTO DATA(e_txt).
      WRITE: / e_txt->get_text( ).
  ENDTRY.