Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
cesar_gr
Explorer
0 Kudos

Report with pictures.

Sometime somebody asked to me, how to create a report with pictures
Well, I investigated and I think to use dynamic document and BDS could be one first solution.

 

See this little example: "Report of Argentina country and its regions"

Create pictures into sap system

Upload the pictures with Trx:OAOR (Business Document Navigator for BDS)

In this example should be use one picture to each región. I only use a few pictures for demostration.


Note that photo ID is formed by the concatenation of the prefix 'ZCDGR_PROVIN' and the region code (t005u-bland) in this example.

 

Main logic
  • Get the regions
    SELECT bland bezei
      FROM t005u
      INTO TABLE gt_t005u
     WHERE spras EQ sy-langu
       AND land1 EQ pais.
  • Then create a report using dynamic document (cl_dd_document) to display GT_T005U table.
  • Create one screen (0100) with the container “CONT_HTML”, with this content:
    PROCESS BEFORE OUTPUT.
     MODULE STATUS_0100.

    PROCESS AFTER INPUT.
     MODULE USER_COMMAND_0100.
  • Create status gui: ‘BRP’, with button ‘BACK’
       

     

Add the pictures

Use the add_picture method with these parameters for the main picture

* Set main picture
  str = 'Mapa de Argentina'.
  CALL METHOD p_do->add_picture EXPORTING
*                picture_id = 'ENJOYSAP_LOGO' “for example
                        picture_id = 'ZCDGR_PROVINAR'
                        alternative_text = str
                        WIDTH = '40%'.

And these parameters for the others pictures

* generate picture id 
   CONCATENATE  'ZCDGR_PROVIN' wa_t005u-bland INTO ls_pict_id.

      CALL METHOD col1->add_picture EXPORTING
                            picture_id = ls_pict_id
*                            alternative_text = str .
                            WIDTH = '100'.



Finally

let's to the full code and result   

*&---------------------------------------------------------------------*
*& Report  YYCDGR_002
*&
*&---------------------------------------------------------------------*
*& Autor: CDGR - Cesar Gutierrez
*& Descripcion : Dynamic Documents
*&---------------------------------------------------------------------*
*****************************************************
* Dynamic Documents
* Imagenes cargadas en TRX OAOR
* Nombre de categoría             PICTURES
* Tipo de clase                   OT
*****************************************************

TYPE-POOLS: sdydo, icon.

TABLES: icont.

DATA: do TYPE REF TO cl_dd_document.
DATA: is_displayed.
DATA: BEGIN OF icontab OCCURS 0.
        INCLUDE STRUCTURE icon.
DATA: END OF icontab.


* types definitions
TYPES: BEGIN OF ty_t005u,
        bland TYPE REGIO,
        bezei TYPE BEZEI20,
       END OF ty_t005u.

* table definitions
DATA: gt_t005u TYPE STANDARD TABLE OF ty_t005u,
      wa_t005u TYPE ty_t005u.

 

*------------------------------------------------*
*Selection Screen
*------------------------------------------------*
PARAMETERS pais TYPE land1 OBLIGATORY DEFAULT 'AR'.


* solo mostrar argentina
AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    IF screen-name EQ 'PAIS'.
      screen-input = '0'.
      MODIFY SCREEN.
    ENDIF.

  ENDLOOP.

*------------------------------------------------*
START-OF-SELECTION.
*------------------------------------------------*

REFRESH gt_t005u.

* Get data
SELECT bland bezei
  FROM t005u
  INTO TABLE gt_t005u
 WHERE spras EQ sy-langu
   AND land1 EQ pais.


* Call Screen
CALL SCREEN 100.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  IF is_displayed IS INITIAL.
    SET PF-STATUS 'BRP'.

* create document
    CREATE OBJECT do.
* fill document
    PERFORM dd_add_icon USING do.
* merge document
    CALL METHOD do->merge_document.
* display document .
    CALL METHOD do->display_document
                       EXPORTING  container          = 'CONT_HTML'
                       EXCEPTIONS html_display_error = 1.
                                       " do some exception handling ...
*    is_displayed = 'X'.
  ENDIF.
ENDMODULE.                             " STATUS_0100  OUTPUT


*----------------------------------------------------------------------*
*  MODULE user_command_0100 INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CASE sy-ucomm.
    WHEN 'BACK'.                       "Beenden
      LEAVE PROGRAM.
    WHEN 'OTHERS'.
  ENDCASE.
  CLEAR sy-ucomm.
ENDMODULE.                             " USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*&      Form  DD_ADD_ICON
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM dd_add_icon USING p_do TYPE REF TO cl_dd_document.

  DATA ta TYPE REF TO cl_dd_table_element.
  DATA col1 TYPE REF TO cl_dd_area.
  DATA col2 TYPE REF TO cl_dd_area.
  DATA col3 TYPE REF TO cl_dd_area.
  DATA text TYPE sdydo_text_element.
  DATA str TYPE string.
  DATA ls_pict_id TYPE SDYDO_KEY.
  DATA: lv_objkey TYPE BDS_TYPEID.
* ---------------------------------------------------------------------*

* Set title of dinamic document report
  text = ' Reporte de Provincias'.
  CALL METHOD p_do->add_text EXPORTING text = text
                                  sap_style = 'heading'.
* Set empty lines
  CALL METHOD p_do->new_line.
  CALL METHOD p_do->new_line.

* Set title
  text =  'Detalle por provincias'.
  CALL METHOD p_do->add_text EXPORTING text = text.

* Set empty lines
  CALL METHOD p_do->new_line.
  CALL METHOD p_do->underline.
  CALL METHOD p_do->new_line.


* Set background picture
*  CALL METHOD p_do->SET_DOCUMENT_BACKGROUND EXPORTING
*                        picture_id = 'ZCDGR_LOGO_STK_BLNK'.


* Set main picture
  str = 'Mapa de Argentina'.
  CALL METHOD p_do->add_picture EXPORTING
*                        picture_id = 'ENJOYSAP_LOGO'
                        picture_id = 'ZCDGR_PROVINAR'
                        alternative_text = str
                        WIDTH = '40%'.

* Set empty lines
  CALL METHOD p_do->new_line.
  CALL METHOD p_do->new_line.
  CALL METHOD p_do->underline.
  CALL METHOD p_do->new_line.


* Set table
  str = 'Tabla de Regiones'.
  CALL METHOD p_do->add_table EXPORTING
                            with_heading      = 'X'
                            no_of_columns     = 3
                            width             = '100%'
                            with_a11y_marks   = 'X'
                            a11y_label        = str
                            IMPORTING table   = ta.
* set columns
  text = 'Imagen de provincia'.
  CALL METHOD ta->add_column EXPORTING heading  = text
                             IMPORTING column   = col1.
  text = 'Provincia'.
  CALL METHOD ta->add_column EXPORTING heading  = text
                             IMPORTING column   = col2.
  text = 'Id provincia'.
  CALL METHOD ta->add_column EXPORTING heading  = text
                             IMPORTING column   = col3.

 

* fill table
  LOOP AT gt_t005u INTO wa_t005u.


*////////////////////////////////////////////////////////////////////
* SET PICTURE
*////////////////////////////////////////////////////////////////////
* create picture ID
    CONCATENATE  'ZCDGR_PROVIN' wa_t005u-bland INTO ls_pict_id.
    lv_objkey = ls_pict_id.

* check if image exists
    CALL FUNCTION 'BDS_PHIOS_GET_RIGHT'
     EXPORTING
       CLASSNAME             = 'PICTURES'
       CLASSTYPE             = 'OT'
       CLIENT                = SY-MANDT
       OBJECT_KEY            = lv_objkey
     EXCEPTIONS
       NOTHING_FOUND         = 1
       PARAMETER_ERROR       = 2
       NOT_ALLOWED           = 3
       ERROR_KPRO            = 4
       INTERNAL_ERROR        = 5
       NOT_AUTHORIZED        = 6
       OTHERS                = 7
              .
    IF SY-SUBRC <> 0.
* Set icon picture not found
      str = 'Ubicacion Grafica No encontrada'.
      CALL METHOD col1->add_icon EXPORTING
                          sap_icon         = 'ICON_NEGATIVE'
                          alternative_text = str
                          sap_size         = cl_dd_area=>large
                          sap_style        = 'failed'.

    ELSE.
* Set picture
      CALL METHOD col1->add_picture EXPORTING
                            picture_id = ls_pict_id
                            WIDTH = '100'.

* Set icon picture found
      str = 'Ubicacion Grafica encontrada'.
      CALL METHOD col1->add_icon EXPORTING
                          sap_icon         = 'ICON_POSITIVE'
                          alternative_text = str
                          sap_size         = cl_dd_area=>large
                          sap_style        = 'success'.

    ENDIF.


*////////////////////////////////////////////////////////////////////
* SET REGION DESCRIPTION
*////////////////////////////////////////////////////////////////////
    text = wa_t005u-bezei.
    CALL METHOD col2->add_text EXPORTING text     = text.

*////////////////////////////////////////////////////////////////////
* SET REGION CODE
*////////////////////////////////////////////////////////////////////
    text = wa_t005u-bland.
    CALL METHOD col3->add_text EXPORTING text     = text.
    CALL METHOD ta->new_row.

  ENDLOOP.


ENDFORM.                               " DD_ADD_ICON


Execute the report

 





I hope it will be usefull 😃

PD: sorry for my english.

6 Comments