Search This Blog

Search This Blog

Uploading Flat File Data to Infotypes in ABAP HR

* METHOD 1 using HR_MAINTAIN_MASTERDATA *
REPORT  ZCLASS_H12.


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 IT_PPROP TYPE PPROP OCCURS 0 WITH HEADER LINE.

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.

    IT_PPROP-INFTY = ITAB-INFTY.
    IT_PPROP-FNAME = 'P0006-STRAS'.
    IT_PPROP-FVAL = ITAB-STRAS.

    APPEND IT_PPROP.

    IT_PPROP-INFTY = ITAB-INFTY.
    IT_PPROP-FNAME = 'P0006-ORT01'.
    IT_PPROP-FVAL = ITAB-ORT01.

    APPEND IT_PPROP.

    IT_PPROP-INFTY = ITAB-INFTY.
    IT_PPROP-FNAME = 'P0006-PSTLZ'.
    IT_PPROP-FVAL = ITAB-PSTLZ.

    APPEND IT_PPROP.


    CALL FUNCTION 'HR_MAINTAIN_MASTERDATA'
     EXPORTING
       PERNR                    = ITAB-PERNR
*   MASSN                    =
       ACTIO                    = 'INS'
       TCLAS                    = 'A'
       BEGDA                    = ITAB-BEGDA
       ENDDA                    = ITAB-ENDDA
*   OBJPS                    =
*   SEQNR                    =
*   SPRPS                    =
       SUBTY                    = ITAB-SUBTY
*   WERKS                    =
*   PERSG                    =
*   PERSK                    =
*   PLANS                    =
       DIALOG_MODE              = '2'
*   LUW_MODE                 = '1'
*   NO_EXISTENCE_CHECK       = ' '
*   NO_ENQUEUE               = ' '
* IMPORTING
*   RETURN                   =
*   RETURN1                  =
*   HR_RETURN                =
      TABLES
        PROPOSED_VALUES          = IT_PPROP
*   MODIFIED_KEYS            =
              .


  ENDLOOP.