How to Read Infotype (in oops)
DATA: lo_infotype TYPE REF TO cl_hrpa_read_infotype,
li_infotype TYPE REF TO if_hrpa_read_infotype,
lt_pri_infty TYPE pnnnn, "primary infotype
lt_sec_infty TYPE pnnnn, "secoundary infotype
lv_has_data TYPE boole_d,
lv_has_auth TYPE boole_d.
// Initialization of the object
TRY.
CALL METHOD cl_hrpa_read_infotype=>get_instance
* EXPORTING
* masterdata_buffer =
IMPORTING
infotype_reader = li_infotype.
CATCH cx_hrpa_violated_assertion.
ENDTRY.
// Read method to get infotype data - METHOD: READ_SINGLE
TRY.
CALL METHOD li_infotype->read_single
EXPORTING
tclas = 'A' "employee
pernr = '00012345'
infty = '0001'
subty = space
objps = space
sprps = ''
begda = '19000101'
endda = sy-datum
mode = '3'
no_auth_check = space
IMPORTING
pnnnn = lt_pri_infty
pnnnn2 = lt_sec_infty
* pref =
data_exists = lv_has_data
missing_auth = lv_has_auth.
CATCH cx_hrpa_violated_assertion .
ENDTRY.
// Read method to get infotype data - METHOD: READ
// Manipulate Data as needed
CLEAR lt_infotype.
CALL METHOD lr_infotype_reader->read
EXPORTING
tclas = 'A'
pernr = lv_pernr
infty = '0001'
begda = iv_begda
endda = iv_endda
no_auth_check = abap_true
IMPORTING
infotype_tab = lt_infotype
data_exists = lv_data_exists
missing_auth = lv_missing_auth.
// Manipulate data
LOOP AT lt_infotype INTO ls_infotype.
CALL METHOD cl_hr_pnnnn_type_cast=>prelp_to_pnnnn
EXPORTING
prelp = ls_infotype
IMPORTING
pnnnn = ls_p0001.
APPEND ls_p0001 TO lt_p0001.
ENDLOOP.