Google Search - Blog...........

ABAP - Get Employee Picture In Selection Screen.

*& Report ZEMPLOYEE
*& Created By : Shaveta Prabhakar

*&---------------------------------------------------------------------*
*& 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.

DATA: DOCKING_CONT TYPE REF TO CL_GUI_DOCKING_CONTAINER, " Custom Container

PICTURE TYPE REF TO CL_GUI_PICTURE.

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.

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



ALSO READ:

- Unified Access to All HR Infotypes.

- F4(Value On Request) For Organization Unit In HR Report Program.

- Employee Pay Scale Report Program.

- Finding Job Code For Position.

- Ordering (Descending ) Org. Unit For An Organization.

.....Back To Sub-Index On HR ABAP.

.....Back To MAIN INDEX.


1 comment:

  1. Hi i'm new to ABAP, and i've test this program and can't seem to have the picture viewed on the screen using your code. so i have to call method cl_gui_picture->load_picture_from_url at form get_pic and yes i got to view the picture there on the selection screen. so i got a few question.
    why is that happen how come i can't view the pic as you intend to?
    do the picture seems to be lock into its spot whenever we scroll the screen up and down?
    how can i make the picture go with the page if i scrool the page? meaning that the picture doesn't stay static whenever the screen is scrool up or down.

    ReplyDelete