Friday, 23 March 2012

Reading Indirect Valuation Amount in ABAP HR

* using RP_EVALUATE_INDIRECTLY_P0008 
REPORT  ZCLASS_H10.

TABLES PERNR.

INFOTYPES:0001, 0007, 0008.

DATA: G_LGA TYPE P0008-LGA01,
      G_BET TYPE P0008-BET01,
      G_IND TYPE P0008-IND01.

DATA G_MOLGA TYPE  MOLGA.

DATA ITAB TYPE PTBINDBW OCCURS 0 WITH HEADER LINE.

START-OF-SELECTION.

GET PERNR.

  CLEAR: G_IND, G_LGA, G_BET, G_MOLGA.

  REFRESH ITAB.

*---Country Grouping
  CALL FUNCTION 'HR_COUNTRYGROUPING_GET'
   EXPORTING
     PERNR           = PERNR-PERNR
     TCLAS           = 'A'
     BEGDA           = '18000101'
     ENDDA           = '99991231'
*   WERKS           =
   IMPORTING
     MOLGA           = G_MOLGA
* EXCEPTIONS
*   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.
  ENDIF.


  RP-PROVIDE-FROM-LAST P0008 SPACE PN-BEGDA PN-ENDDA.

  DO 40 TIMES
     VARYING G_LGA FROM P0008-LGA01 NEXT P0008-LGA02
     VARYING G_BET FROM P0008-BET01 NEXT P0008-BET02
     VARYING G_IND FROM P0008-IND01 NEXT P0008-IND02.

    IF G_LGA EQ 'MB10'.

     IF G_IND EQ 'I'.

        ITAB-LGART = G_LGA.
        ITAB-INDBW = G_IND.

        APPEND ITAB.

        CALL FUNCTION 'RP_EVALUATE_INDIRECTLY_P0008'
          EXPORTING
*           APPLI                              = 'M'
            PBEGDA                             = P0008-BEGDA
            PMOLGA                             = G_MOLGA
            PP0001                             = P0001
            PP0007                             = P0007
            PP0008                             = P0008
            PTCLAS                             = 'A'
            PPERNR                             = PERNR-PERNR
*           PP0230                             =
*           MSGFLG                             = ''
*           NORDCT                             = ''
*           CONV_CURR                          = 'X'
*         IMPORTING
*           PENDDA                             =
          TABLES
            PTBINDBW                           = ITAB
*         EXCEPTIONS
*           BAD_PARAMETERS                     = 1
*           ERROR_AT_INDIRECT_EVALUATION       = 2
*           OTHERS                             = 3
                  .
        IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.


        READ TABLE ITAB WITH KEY LGART = G_LGA.
        IF SY-SUBRC EQ 0.
          G_BET = ITAB-BETRG.
        ENDIF.

      ENDIF.


      WRITE:/ P0008-PERNR, PERNR-ENAME, P0008-BEGDA, P0008-ENDDA, G_BET.
      EXIT.
    ENDIF.
  ENDDO.