Friday, 23 March 2012

Uploading Flat File Data to Infotypes in ABAP HR

* METHOD 2 using HR_INFOTYPE_OPERATION *
REPORT  ZCLASS_H11.

DATA: BEGIN OF ITAB OCCURS 0,
        INFTY  TYPE  P0006-INFTY,
        SUBTY  TYPE  P0006-SUBTY,
        PERNR  TYPE  P0006-PERNR,
        BEGDA  TYPE  P0006-BEGDA,
        ENDDA  TYPE  P0006-ENDDA,
        STRAS  TYPE  P0006-STRAS,
        ORT01  TYPE  P0006-ORT01,
        PSTLZ  TYPE  P0006-PSTLZ,
      END OF ITAB.

DATA WA_P0006 TYPE P0006.

PARAMETERS P_FILE TYPE STRING.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

  CALL METHOD CL_RSAN_UT_FILES=>F4
    EXPORTING
      I_APPLSERV       = SPACE
      I_TITLE          = 'File path...'
      I_GUI_EXTENSION  = 'TXT'
      I_GUI_EXT_FILTER = SPACE
    CHANGING
      C_FILE_NAME      = P_FILE.


START-OF-SELECTION.

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
    EXPORTING
      FILENAME                = P_FILE
*    FILETYPE                = 'ASC'
    HAS_FIELD_SEPARATOR     = 'X'
*    HEADER_LENGTH           = 0
*    READ_BY_LINE            = 'X'
*    DAT_MODE                = SPACE
*    CODEPAGE                = SPACE
*    IGNORE_CERR             = ABAP_TRUE
*    REPLACEMENT             = '#'
*    VIRUS_SCAN_PROFILE      =
*  IMPORTING
*    FILELENGTH              =
*    HEADER                  =
    CHANGING
      DATA_TAB                = ITAB[]
  EXCEPTIONS
    FILE_OPEN_ERROR         = 1
    FILE_READ_ERROR         = 2
    NO_BATCH                = 3
    GUI_REFUSE_FILETRANSFER = 4
    INVALID_TYPE            = 5
    NO_AUTHORITY            = 6
    UNKNOWN_ERROR           = 7
    BAD_DATA_FORMAT         = 8
    HEADER_NOT_ALLOWED      = 9
    SEPARATOR_NOT_ALLOWED   = 10
    HEADER_TOO_LONG         = 11
    UNKNOWN_DP_ERROR        = 12
    ACCESS_DENIED           = 13
    DP_OUT_OF_MEMORY        = 14
    DISK_FULL               = 15
    DP_TIMEOUT              = 16
    NOT_SUPPORTED_BY_GUI    = 17
    ERROR_NO_GUI            = 18
    OTHERS                  = 19.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

END-OF-SELECTION.

  LOOP AT ITAB.


    CALL FUNCTION 'BAPI_EMPLOYEE_ENQUEUE'
      EXPORTING
        NUMBER        = ITAB-PERNR
*   IMPORTING
*     RETURN        =
              .

    MOVE-CORRESPONDING ITAB TO WA_P0006.

    CALL FUNCTION 'HR_INFOTYPE_OPERATION'
      EXPORTING
        INFTY                  = ITAB-INFTY
        NUMBER                 = ITAB-PERNR
       SUBTYPE                = ITAB-SUBTY
*   OBJECTID               =
*   LOCKINDICATOR          =
       VALIDITYEND            = ITAB-ENDDA
       VALIDITYBEGIN          = ITAB-BEGDA
*   RECORDNUMBER           =
        RECORD                 = WA_P0006
        OPERATION              = 'INS'
       TCLAS                  = 'A'
       DIALOG_MODE            = '2'
*   NOCOMMIT               =
*   VIEW_IDENTIFIER        =
*   SECONDARY_RECORD       =
* IMPORTING
*   RETURN                 =
*   KEY                    =
              .


    CALL FUNCTION 'BAPI_EMPLOYEE_DEQUEUE'
      EXPORTING
        NUMBER        = ITAB-PERNR
* IMPORTING
*   RETURN        =

           .

  ENDLOOP.