How to read data from infotype

Here are 2 ways you can read data from an infotype.

1) You can use macros.

* IT0041 "Get Date Specifications
  rp_provide_from_last p0041 space pn-begda pn-endda.
  IF pnp-sw-found = 1.
    gs_output-hire_date           = p0041-dat02.
    gs_output-grade_entry_date    = p0041-dat09.
    gs_output-position_entry_date = p0041-dat10.
    gs_output-job_entry_date      = p0041-dat11.
  ELSE.
    CLEAR p0041.
  ENDIF.

2) You can use function module. (For example: writing code for BADI since you cannot use macro inside BADI).

*  Read IT0041 for the employee.
  CALL FUNCTION 'HR_READ_INFOTYPE'
         EXPORTING
*          TCLAS                = 'A'
           pernr                = iv_pernr
           infty                = '0041'
           begda                = iv_keydate
           endda                = iv_keydate
*          BYPASS_BUFFER        = ' '
*          LEGACY_MODE          = ' '
*        IMPORTING
*          SUBRC                =
         TABLES
           infty_tab            =  it_p0041
        EXCEPTIONS
          infty_not_found       = 1
          OTHERS                = 2.