ABAP Code Examples

Create new HR Infotype record ABAP Code

*& TITLE: Create new HR Infotype record
*&-------------------------------*
*& Report  ZUPD_INFOTYPE.
*&-------------------------------*
*& This example creates a new infotype 0105 record by selecting an existing
*& one from the database and updating its from and to date. The code will
*& be similar code for almost all other HR infotypes
*&-------------------------------*
REPORT ZUPD_INFOTYPE.

PARAMETERS: p_itype type PRELP-INFTY DEFAULT '0105',
            p_pernr type pernr-pernr default '1'.

*Change P0105 to the structure of the infotype you want to update
*Structure can be built dynamically but this wouldn't add any value to
*this example just over complicate it
DATA: ld_record type p0105,
      ld_table  type string.

data: return_struct   type BAPIRETURN1,
      personaldatakey type BAPIPAKEY.

*---------------------------------
START-OF-SELECTION.

  data : it_tabdescr type abap_compdescr_tab,
         wa_tabdescr type abap_compdescr.
  data : ref_table_descr type ref to cl_abap_structdescr.

  CONCATENATE 'PA' p_itype into ld_table.
  SELECT single *
    from (ld_table)
    into CORRESPONDING FIELDS OF ld_record
   where pernr eq p_pernr
     and USRTY eq 'MAIL'. "Only relevant for infotype 0105

* Change values within record you want to create
*  clear: ld_record-???,
*         ld_record-???,
*         ld_record-???.
*  ld_record-??? =
*  ld_record-??? =

  ld_record-endda = '99991231'.
  ld_record-begda = sy-datum.

* HR_INFOTYPE_OPERATION will fail if record is not locked
CALL FUNCTION 'HR_EMPLOYEE_ENQUEUE'
    EXPORTING
      number = p_pernr.

CALL FUNCTION 'HR_INFOTYPE_OPERATION'
    EXPORTING
      infty         = p_itype
      subtype       = ld_record-subty
      number        = ld_record-pernr     "employeenumber
      validityend   = ld_record-endda
      validitybegin = ld_record-begda
      record        = ld_record
      operation     = 'INS'
      nocommit      = ' '
      dialog_mode   = '0'
    IMPORTING
      return        = return_struct
      key           = personaldatakey
    EXCEPTIONS
      OTHERS        = 0.


* Release lock from record after update completed
CALL FUNCTION 'HR_EMPLOYEE_DEQUEUE'
    EXPORTING
      number = p_pernr.

Text pool values



See other example ABAP Reports/Programs..



comments powered by Disqus