Application Development and Automation 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: 
Read only

Change image in Dynpro

Former Member
0 Likes
581

Hi,

I have a dynpro screen, where I can upload images. These images are first saved in an transparent table & then displayed in the screen.

But when I change an image, which already exist in the table, the dynpro displays the old image, even the old image has been deleted from the table. I also used , free PHOTO_CONTAINER & free viewer, but it did not work.

The colde is below.

   SELECT * INTO TABLE IT_IMAGE FROM ZTT_RMS_IMAGES
     WHERE DRIVER_ID = ZTPM_DRIVER_MAST-DRIVER_ID.

   IF SY-SUBRC = 0.
     LOOP AT IT_IMAGE.
       XML_TAB-RAW = IT_IMAGE-DOCCONT.
       GV_IMAGE_FORMAT = IT_IMAGE-DOCTYPE.
       APPEND XML_TAB.
     ENDLOOP. "PHOTO_CONTAINER

*    CLEAR: GRAPHIC_URL, IMAGE, VIEWER, PHOTO_CONTAINER .

     CALL FUNCTION 'DP_CREATE_URL'
       EXPORTING
         TYPE                 = 'IMAGE'
         SUBTYPE              = GV_IMAGE_FORMAT "'JPG'
       TABLES
         DATA                 = XML_TAB[]
       CHANGING
         URL                  = GRAPHIC_URL
       EXCEPTIONS
         DP_INVALID_PARAMETER = 1
         DP_ERROR_PUT_TABLE   = 2
         DP_ERROR_GENERAL     = 3
         OTHERS               = 4.


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

   ELSE.

     MESSAGE 'File does not Exist' TYPE 'I'.
   ENDIF.


   IF PHOTO_CONTAINER IS INITIAL.

     CREATE OBJECT PHOTO_CONTAINER
       EXPORTING
         CONTAINER_NAME              = 'PHOTO_CONTAINER' "'CONT'
         REPID                       = SY-CPROG "'ZRFMS_DRIVER_MASTER_FORM'
         DYNNR                       = '0100'
       EXCEPTIONS
         CNTL_ERROR                  = 1
         CNTL_SYSTEM_ERROR           = 2
         CREATE_ERROR                = 3
         LIFETIME_ERROR              = 4
         LIFETIME_DYNPRO_DYNPRO_LINK = 5
         OTHERS                      = 6.
     IF SY-SUBRC <> 0.
       MESSAGE I001(00) WITH 'Error while creating container'.
       LEAVE LIST-PROCESSING.
     ENDIF.


     CASE SY-SUBRC.
       WHEN 0.
       WHEN OTHERS.
         RAISE CNTL_ERROR.
     ENDCASE.

   ENDIF.

   IF GRAPHIC_URL IS NOT INITIAL AND IMAGE IS INITIAL.

     CREATE OBJECT IMAGE
       EXPORTING
         PARENT = PHOTO_CONTAINER.

     CALL METHOD IMAGE->LOAD_PICTURE_FROM_URL
       EXPORTING
         URL = GRAPHIC_URL.

     IMAGE->SET_DISPLAY_MODE( IMAGE->DISPLAY_MODE_NORMAL_CENTER ).

     CL_GUI_CFW=>FLUSH( ).

     CL_GUI_CFW=>UPDATE_VIEW( ).

*    exit.
   ENDIF.

*
*  IF VIEWER IS INITIAL.
*    FREE VIEWER.
*  ENDIF.

   IF VIEWER IS INITIAL.
     CALL METHOD C_OI_CONTAINER_CONTROL_CREATOR=>GET_DOCUMENT_VIEWER
       IMPORTING
         VIEWER               = VIEWER
       EXCEPTIONS
         UNSUPPORTED_PLATFORM = 1.

     IF SY-SUBRC NE 0.
       MESSAGE I999(ZMSG) WITH 'Unknown error'.
     ENDIF.

     CALL METHOD VIEWER->INIT_VIEWER
       EXPORTING
         PARENT             = PHOTO_CONTAINER
       EXCEPTIONS
         CNTL_ERROR         = 1
         CNTL_INSTALL_ERROR = 2
         DP_INSTALL_ERROR   = 3
         DP_ERROR           = 4.

     IF SY-SUBRC NE 0.
       MESSAGE I999(ZMSGS) WITH 'Unknown error'.
     ENDIF.
   ENDIF.


Cheers,

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
523

Following link helped me to solve the issue.

http://scn.sap.com/thread/929457

I put the following code in PAI.

IF NOT PHOTO_CONTAINER IS INITIAL.
*    FREE PHOTO_CONTAINER.
         CALL METHOD PHOTO_CONTAINER->FREE
           EXCEPTIONS
             CNTL_ERROR        = 1
             CNTL_SYSTEM_ERROR = 2
             OTHERS            = 3.
         IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
         ENDIF.
         FREE PHOTO_CONTAINER.
         CLEAR IMAGE.
          clear ok_code.
       ENDIF.

Hi,

I have a dynpro screen, where I can upload images. These images are first saved in an transparent table & then displayed in the screen.

But when I change an image, which already exist in the table, the dynpro displays the old image, even the old image has been deleted from the table. I also used , free PHOTO_CONTAINER & free viewer, but it did not work.

The colde is below.

   SELECT * INTO TABLE IT_IMAGE FROM ZTT_RMS_IMAGES
     WHERE DRIVER_ID = ZTPM_DRIVER_MAST-DRIVER_ID.

   IF SY-SUBRC = 0.
     LOOP AT IT_IMAGE.
       XML_TAB-RAW = IT_IMAGE-DOCCONT.
       GV_IMAGE_FORMAT = IT_IMAGE-DOCTYPE.
       APPEND XML_TAB.
     ENDLOOP. "PHOTO_CONTAINER

*    CLEAR: GRAPHIC_URL, IMAGE, VIEWER, PHOTO_CONTAINER .

     CALL FUNCTION 'DP_CREATE_URL'
       EXPORTING
         TYPE                 = 'IMAGE'
         SUBTYPE              = GV_IMAGE_FORMAT "'JPG'
       TABLES
         DATA                 = XML_TAB[]
       CHANGING
         URL                  = GRAPHIC_URL
       EXCEPTIONS
         DP_INVALID_PARAMETER = 1
         DP_ERROR_PUT_TABLE   = 2
         DP_ERROR_GENERAL     = 3
         OTHERS               = 4.


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

   ELSE.

     MESSAGE 'File does not Exist' TYPE 'I'.
   ENDIF.


   IF PHOTO_CONTAINER IS INITIAL.

     CREATE OBJECT PHOTO_CONTAINER
       EXPORTING
         CONTAINER_NAME              = 'PHOTO_CONTAINER' "'CONT'
         REPID                       = SY-CPROG "'ZRFMS_DRIVER_MASTER_FORM'
         DYNNR                       = '0100'
       EXCEPTIONS
         CNTL_ERROR                  = 1
         CNTL_SYSTEM_ERROR           = 2
         CREATE_ERROR                = 3
         LIFETIME_ERROR              = 4
         LIFETIME_DYNPRO_DYNPRO_LINK = 5
         OTHERS                      = 6.
     IF SY-SUBRC <> 0.
       MESSAGE I001(00) WITH 'Error while creating container'.
       LEAVE LIST-PROCESSING.
     ENDIF.


     CASE SY-SUBRC.
       WHEN 0.
       WHEN OTHERS.
         RAISE CNTL_ERROR.
     ENDCASE.

   ENDIF.

   IF GRAPHIC_URL IS NOT INITIAL AND IMAGE IS INITIAL.

     CREATE OBJECT IMAGE
       EXPORTING
         PARENT = PHOTO_CONTAINER.

     CALL METHOD IMAGE->LOAD_PICTURE_FROM_URL
       EXPORTING
         URL = GRAPHIC_URL.

     IMAGE->SET_DISPLAY_MODE( IMAGE->DISPLAY_MODE_NORMAL_CENTER ).

     CL_GUI_CFW=>FLUSH( ).

     CL_GUI_CFW=>UPDATE_VIEW( ).

*    exit.
   ENDIF.

*
*  IF VIEWER IS INITIAL.
*    FREE VIEWER.
*  ENDIF.

   IF VIEWER IS INITIAL.
     CALL METHOD C_OI_CONTAINER_CONTROL_CREATOR=>GET_DOCUMENT_VIEWER
       IMPORTING
         VIEWER               = VIEWER
       EXCEPTIONS
         UNSUPPORTED_PLATFORM = 1.

     IF SY-SUBRC NE 0.
       MESSAGE I999(ZMSG) WITH 'Unknown error'.
     ENDIF.

     CALL METHOD VIEWER->INIT_VIEWER
       EXPORTING
         PARENT             = PHOTO_CONTAINER
       EXCEPTIONS
         CNTL_ERROR         = 1
         CNTL_INSTALL_ERROR = 2
         DP_INSTALL_ERROR   = 3
         DP_ERROR           = 4.

     IF SY-SUBRC NE 0.
       MESSAGE I999(ZMSGS) WITH 'Unknown error'.
     ENDIF.
   ENDIF.


Cheers,

1 REPLY 1
Read only

Former Member
0 Likes
524

Following link helped me to solve the issue.

http://scn.sap.com/thread/929457

I put the following code in PAI.

IF NOT PHOTO_CONTAINER IS INITIAL.
*    FREE PHOTO_CONTAINER.
         CALL METHOD PHOTO_CONTAINER->FREE
           EXCEPTIONS
             CNTL_ERROR        = 1
             CNTL_SYSTEM_ERROR = 2
             OTHERS            = 3.
         IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
         ENDIF.
         FREE PHOTO_CONTAINER.
         CLEAR IMAGE.
          clear ok_code.
       ENDIF.