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: 

Add Picture to Custom Containter

lijisusan_mathews
Active Contributor
0 Kudos

Hi,

Can you please tell me how to add a picture from my local directory to a Custom Container?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

For displaying picture in custom container you have to upload the picture into SAP first with the Txcode - SMW0.

Follow this procedure SMW0->Binary data->F8->Execute(F8)->Create(F5)->Name of the Picture and description of the picture and Import the picture (shift+F6).

Save and come back.

Now use this code in the Module pool program ...

TOP declaration.

--


FOR LOGO DECLARATION--

DATA url(132).

TYPE-POOLS cndp.

  • custom container

DATA container TYPE REF TO cl_gui_custom_container.

  • picture Control.

DATA picture TYPE REF TO cl_gui_picture.

  • Definition of Control Framework

CLASS cl_gui_cfw DEFINITION LOAD.

DATA init.

*DATA ok_code TYPE sy-ucomm.

--


FOR LOGO DECLARATION--

PBO

--


LOGO--

IF init is initial.

  • create the custom container

CREATE OBJECT container

EXPORTING container_name = 'MINE'. "Name of the custom container"

  • create the picture control

CREATE OBJECT picture

EXPORTING parent = container.

  • Request an URL from the data provider by exporting the pic_data.

CLEAR URL.

PERFORM LOAD_PIC_FROM_DB CHANGING URL.

  • 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.

IF sy-subrc <> 0.

  • error handling

ENDIF.

ENDIF.

--


LOGO--

FORMroutine

----


FORM LOAD_PIC_FROM_DB CHANGING P_URL.

DATA QUERY_TABLE LIKE W3QUERY OCCURS 1 WITH HEADER LINE.

DATA HTML_TABLE LIKE W3HTML OCCURS 1.

DATA RETURN_CODE LIKE W3PARAM-RET_CODE.

DATA CONTENT_TYPE LIKE W3PARAM-CONT_TYPE.

DATA CONTENT_LENGTH LIKE W3PARAM-CONT_LEN.

DATA PIC_DATA LIKE W3MIME OCCURS 0.

DATA PIC_SIZE TYPE I.

REFRESH QUERY_TABLE.

QUERY_TABLE-NAME = '_OBJECT_ID'.

QUERY_TABLE-VALUE = 'ZMINES'. "name which u gave in SMW0 txcode

APPEND QUERY_TABLE.

CALL FUNCTION 'WWW_GET_MIME_OBJECT'

TABLES

QUERY_STRING = QUERY_TABLE

HTML = HTML_TABLE

MIME = PIC_DATA

CHANGING

RETURN_CODE = RETURN_CODE

CONTENT_TYPE = CONTENT_TYPE

CONTENT_LENGTH = CONTENT_LENGTH

EXCEPTIONS

OBJECT_NOT_FOUND = 1

PARAMETER_NOT_FOUND = 2

OTHERS = 3.

if sy-subrc = 0.

PIC_SIZE = CONTENT_LENGTH.

endif.

CALL FUNCTION 'DP_CREATE_URL'

EXPORTING

TYPE = 'PICTURES'

SUBTYPE = cndp_sap_tab_unknown

SIZE = PIC_SIZE

lifetime = cndp_lifetime_transaction

TABLES

DATA = PIC_DATA

CHANGING

URL = URL

EXCEPTIONS

others = 1.

ENDFORM. " LOAD_PIC_FROM_DB

Hope this solves your problem.

Cheers!!

4 REPLIES 4

Former Member
0 Kudos

Hi,

For displaying picture in custom container you have to upload the picture into SAP first with the Txcode - SMW0.

Follow this procedure SMW0->Binary data->F8->Execute(F8)->Create(F5)->Name of the Picture and description of the picture and Import the picture (shift+F6).

Save and come back.

Now use this code in the Module pool program ...

TOP declaration.

--


FOR LOGO DECLARATION--

DATA url(132).

TYPE-POOLS cndp.

  • custom container

DATA container TYPE REF TO cl_gui_custom_container.

  • picture Control.

DATA picture TYPE REF TO cl_gui_picture.

  • Definition of Control Framework

CLASS cl_gui_cfw DEFINITION LOAD.

DATA init.

*DATA ok_code TYPE sy-ucomm.

--


FOR LOGO DECLARATION--

PBO

--


LOGO--

IF init is initial.

  • create the custom container

CREATE OBJECT container

EXPORTING container_name = 'MINE'. "Name of the custom container"

  • create the picture control

CREATE OBJECT picture

EXPORTING parent = container.

  • Request an URL from the data provider by exporting the pic_data.

CLEAR URL.

PERFORM LOAD_PIC_FROM_DB CHANGING URL.

  • 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.

IF sy-subrc <> 0.

  • error handling

ENDIF.

ENDIF.

--


LOGO--

FORMroutine

----


FORM LOAD_PIC_FROM_DB CHANGING P_URL.

DATA QUERY_TABLE LIKE W3QUERY OCCURS 1 WITH HEADER LINE.

DATA HTML_TABLE LIKE W3HTML OCCURS 1.

DATA RETURN_CODE LIKE W3PARAM-RET_CODE.

DATA CONTENT_TYPE LIKE W3PARAM-CONT_TYPE.

DATA CONTENT_LENGTH LIKE W3PARAM-CONT_LEN.

DATA PIC_DATA LIKE W3MIME OCCURS 0.

DATA PIC_SIZE TYPE I.

REFRESH QUERY_TABLE.

QUERY_TABLE-NAME = '_OBJECT_ID'.

QUERY_TABLE-VALUE = 'ZMINES'. "name which u gave in SMW0 txcode

APPEND QUERY_TABLE.

CALL FUNCTION 'WWW_GET_MIME_OBJECT'

TABLES

QUERY_STRING = QUERY_TABLE

HTML = HTML_TABLE

MIME = PIC_DATA

CHANGING

RETURN_CODE = RETURN_CODE

CONTENT_TYPE = CONTENT_TYPE

CONTENT_LENGTH = CONTENT_LENGTH

EXCEPTIONS

OBJECT_NOT_FOUND = 1

PARAMETER_NOT_FOUND = 2

OTHERS = 3.

if sy-subrc = 0.

PIC_SIZE = CONTENT_LENGTH.

endif.

CALL FUNCTION 'DP_CREATE_URL'

EXPORTING

TYPE = 'PICTURES'

SUBTYPE = cndp_sap_tab_unknown

SIZE = PIC_SIZE

lifetime = cndp_lifetime_transaction

TABLES

DATA = PIC_DATA

CHANGING

URL = URL

EXCEPTIONS

others = 1.

ENDFORM. " LOAD_PIC_FROM_DB

Hope this solves your problem.

Cheers!!

former_member188685
Active Contributor
0 Kudos

Check this thread

in the above thread check the sample code provided by Rich.

Former Member
0 Kudos

Hi,

At first u need to make a custom container element in the screen painter with the name 'PIC_CONT'


DATA:        pic_container TYPE REF TO  cl_gui_custom_container,
                  pic TYPE REF TO cl_gui_picture.

    CREATE OBJECT pic_container
      EXPORTING
        container_name              = 'PIC_CONT'
      EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5
        OTHERS                      = 6.

    CREATE OBJECT pic
      EXPORTING
        parent = pic_container
      EXCEPTIONS
        error  = 1
        OTHERS = 2.

    DATA url TYPE cndp_url.

    CALL FUNCTION 'DP_PUBLISH_WWW_URL'
      EXPORTING
        objid    = 'ENJOYSAP_LOGO'
        lifetime = 'T'
      IMPORTING
        url      = url
      EXCEPTIONS
        OTHERS   = 1.                                       "#EC *

    CALL METHOD pic->load_picture_from_url
      EXPORTING
        url = url.

    CALL METHOD pic->set_display_mode
      EXPORTING
        display_mode = cl_gui_picture=>display_mode_fit.

lijisusan_mathews
Active Contributor
0 Kudos

thanx a lot for those prompt replies..