Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Add Picture to Custom Containter

Hi,

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

Tags:
Former Member replied

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!!

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question