Tuesday, March 08, 2011

Adding an Image in a dialog

There are some cases wherein you may want to display an image in a sap dialog. In this topic I will show you how this can be done.


STEPS:

1. Create a dialog screen via se51 or create dialog in se80. Add a custom container in your dialog as shown in the picture below:

custom container

2. Add your image file (i.e .jpg) in SMW0. 

  2a. Tick the selection below then press F8

SAP Web repository SMW0
     
  2b. Just proceed when this screen appears:


  2c. Create your object and import the image you've created.

  
 3. After saving the object, you may now proceed with the coding.

  3a. In your screen's PBO module, add the ff. code below:

  IF init is initial.

    init = 'X'.

    CREATE OBJECT:

           container  EXPORTING container_name = 'PICTURE_CONTAINER',

           picture    EXPORTING parent = container.

  ENDIF.


    CALL FUNCTION 'DP_PUBLISH_WWW_URL'
      EXPORTING
        objid    = 'ZPARAM_HELP'
        lifetime = 'T'
      IMPORTING
        url      = url
      EXCEPTIONS
        OTHERS   = 1.

  CALL METHOD picture->load_picture_from_url EXPORTING url = url.

  CALL METHOD picture->set_display_mode

       EXPORTING display_mode = picture->display_mode_fit_center.  

4. Sample output:


That's it!
Happy Coding!
Boost your SAP ABAP morale!

No comments:

Post a Comment