Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

We end up writing epics in the ABAP editor just to do simple reads on infotypes using SAP Standard function Modules. Here is a sample method which does read on any HR infotype and returns a table which you request.

1. Create a class via SE24. For this example i named my class ZTEST_IT_READ.

2. Create a STATIC method in the class named READ_IT with the following parameters.

3. Paste the following code there in the class.

Error rendering macro 'code': Invalid value specified for parameter 'lang'
METHOD read_it.
  DATA: lv_it TYPE char5,
        lt_data     TYPE REF TO data.
  FIELD-SYMBOLS: <table>  TYPE STANDARD TABLE.
* mimic P Structure
  CONCATENATE 'P' mi_infotype INTO lv_it.
* Create P structure specific to the Infotype
  CREATE DATA lt_data TYPE STANDARD TABLE OF (lv_it).
  ASSIGN lt_data->* TO <table>.
* Disable Authority check if requested
  IF  mi_authority_chk = space.
    CALL FUNCTION 'HR_READ_INFOTYPE_AUTHC_DISABLE'.
  ENDIF.
* Call function to read infotype passed
  CALL FUNCTION 'HR_READ_INFOTYPE'
    EXPORTING
      pernr           = mi_pernr
      infty           = mi_infotype
      begda           = mi_begda
      endda           = mi_endda
    TABLES
      infty_tab       = <table>
    EXCEPTIONS
      infty_not_found = 1
      OTHERS          = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
* If all Ok pass back the table
    me_it = <table>.
  ENDIF.
ENDMETHOD.
4. You must be wondering how do we use this method ? Below is  a simple implementation of this method.
PROGRAM ztest.
PARAMETERS: p_pernr TYPE persno DEFAULT '900347',
            p_begda TYPE datum  DEFAULT '18000101',
            p_endda TYPE datum  DEFAULT '99991231',
            p_info  LIKE prelp-infty DEFAULT '2001'.
DATA: lv_it TYPE char5,
      lt_data     TYPE REF TO data.
FIELD-SYMBOLS: <table>  TYPE STANDARD TABLE.
CONCATENATE 'P' p_info INTO lv_it.
CREATE DATA lt_data TYPE STANDARD TABLE OF (lv_it).
ASSIGN lt_data->* TO <table>.
CALL METHOD ztest_it_read=>read_it
  EXPORTING
    mi_pernr    = p_pernr
    mi_begda    = p_begda
    mi_endda    = p_endda
    mi_infotype = p_info
  IMPORTING
    me_it       = <table>.


 

 Here you go.

I hope this helps.

Amandeep.

2 Comments

  1. Guest

    The function module HR_READ_INFOTYPE is "Not released". How can a customer use a function module that is not released?

  2. Former Member

    Every body is using this FM, even SAP is using this FM in many of it's programs. You can't use any FM if you are worried if it is released or not.