Displaying an Employee Photo dynamically on the selection-screen

By Shaveta Prabhakar Joshi , TATA Consultancy Services

Summary

This tutorial helps you to get Employee Photo dynamically in your Selection Screen and this is the photo, which appears in all the Infotype headers of SAP-HR Module.

You can get Employee Passport Photo in your Selection Screen by using following steps in SE38.

·       Define Custom Container in Selection Screen

·       Load Image in Container

Define Custom Container on Selection Screen

Use the following Function Modules and Methods to define the custom container on Selection Screen

 

  • Object of Class ‘CL_GUI_PICTURE’ is to create Custom Container

  • Set Position of Photo by passing values of Height, Width, Top and Left using method SET_POSITION of Class ‘CL_GUI_PICTURE’.

  • Use Method DISPLAY_MODE_FIT of Class ‘CL_GUI_PICTURE’ to fit Image to the Container.

Load the Image in Container

Use the following Function Modules and Methods to load the photo in the custom container defined on Selection Screen.

 

  • Check the availability of Photo by using Function Module ‘HR_IMAGE_EXISTS’ and get the Achieve ID and Document ID.

  • Get the URL of image by passing parameters Achieve Id and Document Id to the Function Module ‘SCMS_DOC_URL_READ’.

  • Load the photo in the defined container by passing  parameters URL to the Function Module ‘LOAD_PICTURE_FROM_URL’.

Code to get dynamic employee photo in Selection Screen

Use this code in SE38 to see how the passport photo appears against the Info type header of SAP-HR:
*&---------------------------------------------------------------------*
*& Report  ZEMPLOYEE
*& Created By : Shaveta Prabhakar
*& Published at: SAPTechnical.COM
*&---------------------------------------------------------------------*
*& Function Modules:  HR_GET_EMPLOYEE_DATA
*&                    HR_IMAGE_EXISTS
*&                    SCMS_DOC_URL_READ
*&                    HR_IMAGE_RESET
*& Class & Methods :  CL_GUI_DOCKING_CONTAINER
*&                    CL_GUI_PICTURE->SET_POSITION
*&                    CL_GUI_PICTURE->SET_DISPLAY_MODE
*&                    CL_GUI_PICTURE->DISPLAY_MODE_FIT
*&                    CL_GUI_PICTURE->LOAD_PICTURE_FROM_URL_ASYNC
*&---------------------------------------------------------------------*
REPORT  ZEMPLOYEE.
TABLES: PA0001, PERSON.
*----------------------Declaration for Image------------------------*
DATA: DOCKING_CONT TYPE REF TO CL_GUI_DOCKING_CONTAINER, " Custom Container
      PICTURE TYPE REF TO CL_GUI_PICTURE.
*--------------------Declaration of Internal table------------------*
DATA: ITAB_EMPDATA LIKE TABLE OF PERSON.
DATA: ITAB_DATA LIKE TABLE OF PERSON WITH HEADER LINE.
DATA:  P_CONNECT_INFO LIKE TABLE OF TOAV0 WITH HEADER LINE.
DATA:  P_DOCUMENT_TYPE LIKE TOAV0-RESERVE.
DATA:  URL(255) TYPE C.
DATA:  HANDLE TYPE I.
DATA:  PPERNR TYPE PA0001-PERNR.
*----------------------Start of Selection Screen----------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 .
SELECTION-SCREEN SKIP 2.
SELECTION-SCREEN COMMENT 40(25) TEXT-010  .
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 20(15) TEXT-002 FOR FIELD PERNR.
PARAMETERS PERNR TYPE PA0001-PERNR.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 20(15) TEXT-008 FOR FIELD ENAME.
PARAMETERS ENAME TYPE PA0001-ENAME.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 20(15) TEXT-003 FOR FIELD PERSG.
PARAMETERS PERSG TYPE PA0001-PERSG.
SELECTION-SCREEN COMMENT 45(15) TEXT-009 FOR FIELD WERKS.
PARAMETERS WERKS TYPE PA0001-WERKS.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 20(15) TEXT-004 FOR FIELD PERSK.
PARAMETERS PERSK TYPE PA0001-PERSK.
SELECTION-SCREEN COMMENT 45(15) TEXT-005 FOR FIELD KOSTL.
PARAMETERS KOSTL TYPE PA0001-KOSTL.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 20(15) TEXT-006 FOR FIELD ORGEH.
PARAMETERS ORGEH TYPE PA0001-ORGEH.
PARAMETERS ORGEHTXT TYPE PERSON-ORGEH_TXT .
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 20(15) TEXT-007 FOR FIELD PLANS.
PARAMETERS PLANS TYPE PA0001-PLANS.
PARAMETERS PLANSTXT TYPE PERSON-PLANS_TXT .
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B1.
***********************************************************************
*AT SELECTION-SCREEN OUTPUT.
************************************************************************
AT SELECTION-SCREEN OUTPUT .
  LOOP AT SCREEN.
    IF SCREEN-NAME = 'ENAME'
    OR SCREEN-NAME = 'PERSG'
    OR SCREEN-NAME = 'PERSK'
    OR SCREEN-NAME = 'KOSTL'
    OR SCREEN-NAME = 'WERKS'
    OR SCREEN-NAME = 'ORGEH'
    OR SCREEN-NAME = 'PLANS'
    OR SCREEN-NAME = 'ORGEHTXT'
    OR SCREEN-NAME = 'PLANSTXT'.
      SCREEN-INPUT = '0'.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.
  LOOP AT SCREEN.
    IF SCREEN-NAME = 'ORGEHTXT'
    OR SCREEN-NAME = 'PLANSTXT'.
      SCREEN-OUTPUT = '1'.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.
  PERFORM GET_PIC.
***********************************************************************
*AT SELECTION-SCREEN .
************************************************************************
AT SELECTION-SCREEN .
  PPERNR = PERNR.
  CALL FUNCTION 'HR_GET_EMPLOYEE_DATA'
    EXPORTING
      PERSON_ID             = PPERNR
      SELECTION_BEGIN       = SY-DATUM
      SELECTION_END         = SY-DATUM
    IMPORTING
      PERSONAL_DATA         = ITAB_DATA
    EXCEPTIONS
      PERSON_NOT_FOUND      = 1
      NO_ACTIVE_INTEGRATION = 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.
  ENAME = ITAB_DATA-ENAME.
  PERSG = ITAB_DATA-PERSG.
  PERSK = ITAB_DATA-PERSK.
  ORGEH = ITAB_DATA-ORGEH.
  PLANS = ITAB_DATA-PLANS.
  KOSTL = ITAB_DATA-KOSTL.
  WERKS = ITAB_DATA-WERKS.
  ORGEHTXT = ITAB_DATA-ORGEH_TXT.
  PLANSTXT = ITAB_DATA-PLANS_TXT.
*Function Module To check Existance of Image
  CALL FUNCTION 'HR_IMAGE_EXISTS'
    EXPORTING
      P_PERNR        = PPERNR
    IMPORTING
      P_CONNECT_INFO = P_CONNECT_INFO
    EXCEPTIONS
      OTHERS         = 2.
  P_DOCUMENT_TYPE = P_CONNECT_INFO-RESERVE.
*Function Module To Get the URL of Image
  CALL FUNCTION 'SCMS_DOC_URL_READ'
    EXPORTING
      STOR_CAT    = SPACE
      CREP_ID     = P_CONNECT_INFO-ARCHIV_ID
      DOC_ID      = P_CONNECT_INFO-ARC_DOC_ID
      COMP_ID     = 'DATA'
      DP_URL_ONLY = 'X'
    IMPORTING
      URL         = URL
    EXCEPTIONS
      OTHERS      = 10.
  IF SY-SUBRC <> 0.
  ENDIF.
*Method To load Image from URL
  CALL METHOD PICTURE->LOAD_PICTURE_FROM_URL_ASYNC
    EXPORTING
      URL = URL.
  IF SY-SUBRC NE 0.
  ENDIF.
  IF PPERNR NE PERNR.
*Function Module To Reset Image
    CALL FUNCTION 'HR_IMAGE_RESET'
      EXPORTING
        HANDLE         = HANDLE
      EXCEPTIONS
        INVALID_HANDLE = 1
        OTHERS         = 2.
    IF SY-SUBRC <> 0.
    ENDIF.
  ENDIF.
*&---------------------------------------------------------------------*
*& Form Get_Pic
*&---------------------------------------------------------------------*
FORM GET_PIC.
  DATA: REPID LIKE SY-REPID.
  REPID = SY-REPID.
  IF PICTURE IS INITIAL.
*Object To Create the Custom Container
    CREATE OBJECT PICTURE
      EXPORTING
        PARENT = DOCKING_CONT.
    CHECK SY-SUBRC = 0.
*Method To Set Position of Image
    CALL METHOD PICTURE->SET_POSITION
      EXPORTING
        HEIGHT = 47
        LEFT   = 610
        TOP    = 25
        WIDTH  = 70.
*Method To Set Display Mode Fit to Container
    CALL METHOD PICTURE->SET_DISPLAY_MODE
      EXPORTING
        DISPLAY_MODE = CL_GUI_PICTURE=>DISPLAY_MODE_FIT.
  ELSE.
*Function Module To Reset Image
    CALL FUNCTION 'HR_IMAGE_RESET'
      EXPORTING
        HANDLE         = HANDLE
      EXCEPTIONS
        INVALID_HANDLE = 1
        OTHERS         = 2.
    IF SY-SUBRC <> 0.
    ENDIF.
  ENDIF.
ENDFORM. "Get_pic

View Selection Screen

After executing above code your Selection Screen appears as follows

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image