Saturday 9 December 2023

How to display photo of employees from PA30 to module pool custom container

In this blog post you will learn how to make a basic Module Pool program using custom container to display image of employee from PA30.

Module pool programming is a special type of programming which is used to create custom SAP screens.

We will first upload the image for the employee on the SAP Server using the transaction OAAD. The name of the image we upload is APPLE and is in black and white (the supported formats are .jpg and .png).

Transaction code for creating module pool program is SE80.

Below is the required configuration in the SAP system:-

1. Using SM30 with table T588J click on maintain

How to display photo of employees from PA30 to module pool custom container

2. Add the below highlighted entry if does not exist in your system and save it in your transport

or local object as per your convenience.

How to display photo of employees from PA30 to module pool custom container

3. Upload the image as per the below using transaction OAAD.Click on Store and Assign

How to display photo of employees from PA30 to module pool custom container

4. Create as per the provided business object & document type and provide the employee no

and it will pop up to select the photo for the employee

How to display photo of employees from PA30 to module pool custom container

How to display photo of employees from PA30 to module pool custom container

5. Photo uploaded for the employee No 4180

How to display photo of employees from PA30 to module pool custom container

6. Now we are going to get the photo into the module pool custom container.Below are the code

for the same.

*&---------------------------------------------------------------------*
*& Report  ZHR_EMPLOYEE_IMAGE_DISPLAY
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zhr_employee_image_display.

"To display employee photo from PA30 to module pool custom container

***Variable Declaration
DATA : handle         TYPE i,
       p_exists       TYPE c,
       p_connect_info LIKE toav0,
       gv_initialize  TYPE flag,
       p_pernr TYPE pa0001-pernr.

START-OF-SELECTION.
  "Screen with custom Container
  CALL SCREEN 100.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.

ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
  WHEN 'ENTER' OR ' '.
      IF p_pernr IS NOT INITIAL.
    "Variable Clear
    CLEAR: p_exists, p_connect_info.", handle.
    "Below funtion module to check if the photo exists for the employee
    CALL FUNCTION 'HR_IMAGE_EXISTS'
      EXPORTING
        p_pernr               = p_pernr
        p_tclas               = 'A'
        p_begda               = '19100101'
        p_endda               = '99991231'
      IMPORTING
        p_exists              = p_exists
        p_connect_info        = p_connect_info
      EXCEPTIONS
        error_connectiontable = 1
        OTHERS                = 2.
    IF sy-subrc <> 0.
      gv_initialize = abap_false.
      "Below function module to display the blank in the screen if no photo exists for the employee
      CALL FUNCTION 'HR_IMAGE_SHOW'
        EXPORTING
          p_pernr        = p_pernr
          p_tclas        = 'A'
          handle         = handle
        EXCEPTIONS
          invalid_handle = 1
          no_document    = 2
          internal_error = 3
          OTHERS         = 4.
      IF sy-subrc <> 0.
        "Below function module to reset the image in the screen
        CALL FUNCTION 'HR_IMAGE_RESET'
          EXPORTING
            handle         = handle
          EXCEPTIONS
            invalid_handle = 1
            OTHERS         = 2.
      ENDIF.
    ELSE.
      IF gv_initialize = abap_false.
        "Below function module to initialize the custom container to displaye the photo for the employee
        CALL FUNCTION 'HR_IMAGE_INIT'
          EXPORTING
            p_pernr        = p_pernr
            p_tclas        = 'A'
            container      = 'IMAGE'
          IMPORTING
            handle         = handle
          EXCEPTIONS
            no_document    = 1
            internal_error = 2
            OTHERS         = 3.
        IF sy-subrc IS INITIAL.
          gv_initialize = abap_true.
          "Below function module to display the photo in the screen if photo exists for the employee
          CALL FUNCTION 'HR_IMAGE_SHOW'
            EXPORTING
              p_pernr        = p_pernr
              p_tclas        = 'A'
              handle         = handle
            EXCEPTIONS
              invalid_handle = 1
              no_document    = 2
              internal_error = 3
              OTHERS         = 4.
        ENDIF.
      ELSE.
        CALL FUNCTION 'HR_IMAGE_SHOW'
          EXPORTING
            p_pernr        = p_pernr
            p_tclas        = 'A'
            handle         = handle
          EXCEPTIONS
            invalid_handle = 1
            no_document    = 2
            internal_error = 3
            OTHERS         = 4.
      ENDIF.  " SY-SUBRC IS INITIAL.
    ENDIF.
  ENDIF.
ENDCASE.
ENDMODULE.

PROCESS BEFORE OUTPUT.
 MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
 MODULE USER_COMMAND_0100.

Screen 0100:-

In the screen 100 click on highlighted layout to open screen painter

How to display photo of employees from PA30 to module pool custom container

In the screen painter as shown below click on Dictionary/Program fields to get the program fields to copy into the screen

How to display photo of employees from PA30 to module pool custom container

Now we have added the employee no(P_PERNR) from the program to screen

How to display photo of employees from PA30 to module pool custom container

We have added the custom container in the name of IMAGE into the screen and also added Text filed as Employee Photo

How to display photo of employees from PA30 to module pool custom container

Create transaction ZPA30 using transaction SE93 as shown below

How to display photo of employees from PA30 to module pool custom container

How to display photo of employees from PA30 to module pool custom container

Finally executing the report using transaction ZPA30 to display the image into custom container

How to display photo of employees from PA30 to module pool custom container

How to display photo of employees from PA30 to module pool custom container

By following the steps you will be able to create basic Module Pool Program to display image of the employee.

No comments:

Post a Comment