Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP Picture Control: LOAD_PICTURE_FROM_URL always returns RESULT = 0

Former Member
0 Kudos
2,911

Hi all,

I want to display a picture from the local file system of the WebAS (6.20). Therefore I create a custom container, add a Picture Control (CL_GUI_PICTURE) to it and use the method LOAD_PICTURE_FROM_URL to load the picture. However, the picture is never displayed and the control returns RESULT = 0 (error). I've tried the following combinations to load the file into the Picture Control:


  CALL METHOD p_pic->load_picture_from_url
    EXPORTING
      url    = '/tmp/test.jpg'

or:

      url    = 'file://tmp/test.jpg'

or:

      url    = 'file:///tmp/test.jpg'

I also tried to create a data provider, by loading the file into an internal table and using function module DP_CREATE_URL. I get a valid sapr3://... Url from the fm, but also in this case, the pic is not loaded.

So, any ideas? Any help is appreciated! Thanks in advance.

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos
333

First, you need to upload your Picture in the binary format and than call the FM DP_CREATE_URL to get back the URL. Pass this URL to load the picture.


  DATA: l_string TYPE string.

  l_string = 'c:\temp\1.jpg'.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename   = l_string
      filetype   = 'BIN'
    IMPORTING
      filelength = pic_size
    TABLES
      data_tab   = pic_data.

  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


  CALL FUNCTION 'DP_CREATE_URL'
    EXPORTING
      type     = 'image'
      subtype  = cndp_sap_tab_unknown
      size     = pic_size
      lifetime = cndp_lifetime_transaction
    TABLES
      data     = pic_data
    CHANGING
      url      = pic_url
    EXCEPTIONS
      OTHERS   = 1.

    CALL METHOD W_PICTURE->LOAD_PICTURE_FROM_URL
      EXPORTING
        URL = PIC_URL.

Regards,

Naimesh Patel

8 REPLIES 8

Former Member
0 Kudos
333

Hi,,,,,,,,,

I used the following code to diplay the Picture,,, But first i saved my Picture on the SAP's document management system... and then used the following code........


CALL FUNCTION 'DP_PUBLISH_WWW_URL'
  EXPORTING
    OBJID                       = 'JCB' >>>>>>>>>>>>>>> Image stored in the SAP's Document management system....
    LIFETIME                    = cndp_lifetime_transaction
  IMPORTING
    URL                         = url
  EXCEPTIONS
    OTHERS                      = 1.

* Load the picture by using the url generated by the data provider.
    if sy-subrc = 0.
    CREATE OBJECT picture_control_1 EXPORTING parent = CONTAINER_1.

     CALL METHOD picture_control_1->set_3d_border
     EXPORTING
     border = 5.

    CALL METHOD picture_control_1->set_display_mode
    EXPORTING
    display_mode = cl_gui_picture=>display_mode_stretch.

    CALL METHOD picture_control_1->set_position
    EXPORTING
    height = 50
    left = 30
    top = 5
    width = 138.

      CALL METHOD PICTURE_CONTROL_1->LOAD_PICTURE_FROM_URL_ASYNC
         exporting url = url.
    endif.

Thanks

Saurabh

Former Member
0 Kudos
333

Thank you very much! Using the archive for storing the picture might be a viable approach.

But, I would prefer having the picture on a network share or maybe even directly in a dictionary table (is this even possible?)...

raymond_giuseppi
Active Contributor
0 Kudos
333

Look at [ class cl_gui_picture - loading picture doesn't work|http://sap.ittoolbox.com/groups/technical-functional/sap-dev/class-cl_gui_picture-loading-picture-doesnt-work-374550]

You cannot give an arbitrary filename as input as URL for the method youmentioned below.

You need to maintain the address of the URL in the table WWWPARAMS as anObject.

And in the program, before calling the method, you need to Publish theURL string by calling the Function module DP_PUBLISH_WWW_URL passing theObject Id of the url path maintained in the WWWPARAMS table. Then call the method 'load_picture_from_url' of the PICTURE control object todisplay the picture on the screen.

For a sample, look at [Object Oriented ALV-Sample program to insert Logo in ALV|http://www.abapcode.info/2007/06/object-oriented-alv-sample-program-to.html]

Regards

0 Kudos
333

Look at class cl_gui_picture - loading picture doesn't work

You cannot give an arbitrary filename as input as URL for the method youmentioned below.

You need to maintain the address of the URL in the table WWWPARAMS as anObject.

And in the program, before calling the method, you need to Publish theURL string by calling the Function module DP_PUBLISH_WWW_URL passing theObject Id of the url path maintained in the WWWPARAMS table. Then call the method 'load_picture_from_url' of the PICTURE control object todisplay the picture on the screen.

For a sample, look at Object Oriented ALV-Sample program to insert Logo in ALV

Regards

I have already found this article, I think this is not the solution:

- What should I exactly write into the table? The existing entries don't look at all like an URL

- I would need to create one (or more) table entry per picture I want to display...

naimesh_patel
Active Contributor
0 Kudos
334

First, you need to upload your Picture in the binary format and than call the FM DP_CREATE_URL to get back the URL. Pass this URL to load the picture.


  DATA: l_string TYPE string.

  l_string = 'c:\temp\1.jpg'.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename   = l_string
      filetype   = 'BIN'
    IMPORTING
      filelength = pic_size
    TABLES
      data_tab   = pic_data.

  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


  CALL FUNCTION 'DP_CREATE_URL'
    EXPORTING
      type     = 'image'
      subtype  = cndp_sap_tab_unknown
      size     = pic_size
      lifetime = cndp_lifetime_transaction
    TABLES
      data     = pic_data
    CHANGING
      url      = pic_url
    EXCEPTIONS
      OTHERS   = 1.

    CALL METHOD W_PICTURE->LOAD_PICTURE_FROM_URL
      EXPORTING
        URL = PIC_URL.

Regards,

Naimesh Patel

Former Member
0 Kudos
333

Hi,

Probably you will find the picture now, its working at my end...


    * load picture
    CALL METHOD picture->load_picture_from_url
      EXPORTING
        url = url.
    init = 'X'.

    CALL METHOD cl_gui_cfw=>flush
      EXCEPTIONS
        cntl_system_error = 1
        cntl_error        = 2.

Thanks & Regards,

Krishna..

Former Member
0 Kudos
333

I finally managed to display a file from the network in the picture control. I don't even need the data provider! Here's the working code:


REPORT  zbalt_test                              .

CALL SCREEN '0001'.


*&---------------------------------------------------------------------*
*&      Module  STATUS_0001  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

MODULE status_0001 OUTPUT.

  DATA lo_container      TYPE REF TO cl_gui_custom_container.
  DATA lo_pic            TYPE REF TO cl_gui_picture.

  DATA lv_result TYPE int4.

  CREATE OBJECT lo_container
    EXPORTING container_name = 'MYCC'.

  CREATE OBJECT lo_pic
    EXPORTING parent  = lo_container.

  CALL METHOD lo_pic->load_picture_from_url
    EXPORTING
      url    = 'FILE:////10.0.0.1/sapmnt/tmp/test.jpg'
    IMPORTING
      RESULT = lv_result.

ENDMODULE.                 " STATUS_0001  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0001 INPUT.

  LEAVE TO SCREEN 0.

ENDMODULE.                 " USER_COMMAND_0001  INPUT

Dynpro 0001 just contains a custom control named 'MYCC'.

The trickiest part was to figure out that you need 4 (!!) slashes to specify the FILE URL...

Former Member
0 Kudos
333

Thank you all for your help!