Tuesday, 16 January 2018

CAT employee email trigger


REPORT zhr_r_email_time_reject.

INFOTYPES 0105.

TABLES pernr.

TYPES BEGIN OF gty_pernr,
          pernr TYPE pernr_d,
          ename TYPE emnam,
          email TYPE comm_id_long,
        END OF gty_pernr,

        BEGIN OF gty_final,
          pernr TYPE pernr_d,
          ename TYPE emnam,
          date  TYPE catsdate,
          hours TYPE catshours,
          text  TYPE catsretext,
          email TYPE comm_id_long,
        END OF gty_final,

        BEGIN OF gty_catsdb,
          pernr     TYPE pernr_d,
          workdate  TYPE catsdate,
          catshours  TYPE catshours,
          status    TYPE catsstatus,
          laetm      TYPE cats_laetm,
          reason    TYPE catsreason,
        END OF gty_catsdb.


DATA gs_pernr    TYPE gty_pernr,
       gs_final    TYPE gty_final,
       gs_catsdb   TYPE gty_catsdb,
       gs_catsdb1  TYPE gty_catsdb,
       gs_body_msg LIKE solisti1,
       gs_tcatsdt  TYPE tcatsdt,
       gt_tcatsdt  TYPE STANDARD TABLE OF tcatsdt,
       gt_body_msg TYPE STANDARD TABLE OF solisti1,
       gt_catsdb   TYPE STANDARD TABLE OF gty_catsdb,
       gt_final    TYPE STANDARD TABLE OF gty_final,
       gt_pernr    TYPE STANDARD TABLE OF gty_pernr.

DATA lv_string  TYPE string,
       lv_string1 TYPE string,
       lv_reason  TYPE catsdb-reason,
       gv_email   TYPE comm_id_long,
       gv_time    TYPE cats_laetm.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS     p_status TYPE catsstatus OBLIGATORY DEFAULT '40',
                 p_time   TYPE cats_laetm.
SELECT-OPTIONS s_reason FOR lv_reason NO INTERVALS.
PARAMETERS p_test   AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b1.

INITIALIZATION.

  s_reason-sign   'I'.
  s_reason-option 'EQ'.
  s_reason-low    'YB15'.
  APPEND s_reason.
  s_reason-low    'YB20'.
  APPEND s_reason.
  s_reason-low    'YB25'.
  APPEND s_reason.
  s_reason-low    'YB30'.
  APPEND s_reason.
  s_reason-low    'YB35'.
  APPEND s_reason.

  GET pernr.

  gs_pernr-pernr pernr-pernr.
  gs_pernr-ename pernr-ename.
  rp-provide-from-last p0105 '0010' pn-begda pn-endda.
  IF pnp-sw-found 1.
    gs_pernr-email p0105-usrid_long.
  ENDIF.
  APPEND gs_pernr TO gt_pernr.

END-OF-SELECTION.

  IF gt_pernr IS NOT INITIAL.
    IF p_time IS NOT INITIAL.
      gv_time sy-uzeit p_time.
    ELSE.

    ENDIF.

    SELECT FROM tcatsdt INTO TABLE gt_tcatsdt
             WHERE reason IN s_reason.
    IF sy-subrc 0.
      SORT gt_tcatsdt BY reason.
    ENDIF.

    SELECT pernr
           workdate
           catshours
           status
           laetm
           reason FROM catsdb INTO TABLE gt_catsdb
            FOR ALL ENTRIES IN gt_pernr
            WHERE pernr gt_pernr-pernr
              AND status p_status
              AND laeda >= pn-begda AND laeda <= pn-endda
              AND reason IN s_reason.
    IF sy-subrc 0.
      IF p_time IS NOT INITIAL.
        DELETE gt_catsdb WHERE laetm NOT BETWEEN gv_time AND sy-uzeit.
      ENDIF.
      SORT gt_catsdb BY pernr.
      LOOP AT gt_catsdb INTO gs_catsdb1.
        gs_catsdb gs_catsdb1.
        gs_final-pernr gs_catsdb-pernr.
        gs_final-date  gs_catsdb-workdate.
        gs_final-hours gs_catsdb-catshours.
        CLEAR gs_tcatsdt.
        READ TABLE gt_tcatsdt INTO gs_tcatsdt
            WITH KEY reason gs_catsdb-reason.
        IF sy-subrc 0.
          gs_final-text gs_tcatsdt-text.
        ENDIF.
        READ TABLE gt_pernr INTO gs_pernr WITH KEY pernr gs_catsdb-pernr.
        IF sy-subrc 0.
          gs_final-ename gs_pernr-ename.
          gv_email gs_final-email gs_pernr-email.
        ENDIF.
        AT NEW pernr.
          IF p_test IS INITIAL.
            "Body
            CLEAR gt_body_msglv_string.
            CONCATENATE 'Hi' gs_final-ename ','
                        INTO lv_string SEPARATED BY space.
            PERFORM body_mail USING:spacelv_stringspace,
                                    'Hours on your timesheet have been REJECTED'.
          ENDIF.
        ENDAT.
        IF p_test IS INITIAL.
          CLEAR lv_string1lv_string.
          CONCATENATE gs_final-date+4(2'/' gs_final-date+6(2'/'
                      gs_final-date+0(4INTO lv_string.
          CONCATENATE 'Date  : ' lv_string space
                      INTO lv_string1 SEPARATED BY space.
*          PERFORM body_mail USING: lv_string.
          CLEAR lv_string.
          lv_string gs_final-hours.
          CONCATENATE lv_string1 'Hours  : ' lv_string space
                      INTO lv_string1 SEPARATED BY space.
*          PERFORM body_mail USING: lv_string.
*          CLEAR lv_string.
          CONCATENATE lv_string1 'Reason  : ' gs_final-text space
                      INTO lv_string1 SEPARATED BY space.
          PERFORM body_mail USINGlv_string1.
        ENDIF.
        APPEND gs_final TO gt_final.
        CLEAR gs_final.
        AT END OF pernr.
          IF p_test IS INITIAL AND gv_email IS NOT INITIAL.
            PERFORM body_mail USING:space,
                    'If you are an hourly employee, please contact your manager immediately for discussion regarding this.  Then please correct your time in the system and resubmit.',
                    space,
                    'Please Note:',
'If you are a salaried employee and your hours exceeded 40 in a week, and the rejection reason is SALARIED, you are receiving this message because our system, while capturing all hours worked, only passes the initial 40 on to the payroll system',
                    'please disregard this message.',
                    space,
                    'If you are a salaried employee and your hours are being rejected for some other reason, please contact your manager immediately for discussion regarding this.  Then please correct your time in the system and resubmit.',
                    space,
                    'If your manager is not available, please reach out to your HR Representative for support.',
                    space,
                    'Regards,',
                    'Time System Administration',
                    '-------------------------------------------------------------------------------------------'.
            PERFORM email.
          ENDIF.
          CLEAR lv_stringgt_body_msggv_email.
        ENDAT.
      ENDLOOP.
    ENDIF.
  ENDIF.

  IF gt_final IS NOT INITIAL.
    PERFORM display.
  ELSE.
    MESSAGE 'No Data Found' TYPE 'I'.
  ENDIF.

FORM email.

  DATA:  lv_lines        TYPE i,
         ls_doc          TYPE sodocchgi1,
         ls_receivers    TYPE somlreci1,
         ls_packing_list TYPE sopcklsti1,
         lt_packing_list TYPE STANDARD TABLE OF sopcklsti1,
         lt_receivers    TYPE STANDARD TABLE OF somlreci1.

  ls_receivers-rec_type   'U'.  "Internet address
  ls_receivers-receiver   gv_email.
  ls_receivers-com_type   'INT'.
  APPEND ls_receivers TO lt_receivers .

  "Subject of the
  ls_doc-obj_name  'Timesheet'.
  ls_doc-obj_descr 'SAP Timesheet – Request has been rejected'.
  ls_doc-obj_langu  sy-langu.

  "Write Packing List for Body
  DESCRIBE TABLE gt_body_msg LINES lv_lines.
  ls_packing_list-head_start 1.
  ls_packing_list-head_num   0.
  ls_packing_list-body_start 1.
  ls_packing_list-body_num   lv_lines.
  ls_packing_list-doc_type   'RAW'.
  APPEND ls_packing_list TO lt_packing_list.
  CLEAR  ls_packing_list.

  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
      document_data              ls_doc
      put_in_outbox              'X'
      commit_work                'X'
      sender_address             'SAP@csscorp.com'
      sender_address_type        'INT'
    TABLES
      packing_list               lt_packing_list
      contents_txt               gt_body_msg
      receivers                  lt_receivers
    EXCEPTIONS
      too_many_receivers         1
      document_not_sent          2
      document_type_not_exist    3
      operation_no_authorization 4
      parameter_error            5
      x_error                    6
      enqueue_error              7
      OTHERS                     8.
  WAIT UP TO SECONDS.
  SUBMIT rsconn01 WITH mode 'INT'
          AND RETURN.
ENDFORM.

FORM body_mail USING p_space.
  gs_body_msg p_space.
  APPEND gs_body_msg TO gt_body_msg.
  CLEAR  gs_body_msg.
ENDFORM.

FORM display.
  DATA lo_alv       TYPE REF TO cl_salv_table,
         lo_functions TYPE REF TO cl_salv_functions,
         lo_columns   TYPE REF TO cl_salv_columns_table,
         lo_column    TYPE REF TO cl_salv_column_table.

  CALL METHOD cl_salv_table=>factory
    IMPORTING
      r_salv_table lo_alv
    CHANGING
      t_table      gt_final.
  lo_functions lo_alv->get_functions).
  lo_functions->set_allabap_true ).
  CALL METHOD lo_alv->get_columns
    RECEIVING
      value lo_columns.
  lo_columns->set_optimize'X' ).

  CALL METHOD lo_alv->display.
ENDFORM.

Friday, 12 January 2018

Onbording or Hiring and Relationship Creation and Infotype insert operation in HCM:

*&---------------------------------------------------------------------*
*&  Include           ZHR_ON_BORADING_PROCESS_TOP
*&---------------------------------------------------------------------*
TYPESBEGIN OF gty_input,
****infotype 0000 & 0001
         pernr     type string,
         begda     TYPE string,
         endda     TYPE string,
*         massn TYPE string,
         massg     TYPE string,
         plans     TYPE string,
         org_unit type string,
         org_level1 type string,
         org_level2 type string,
         org_level3 type string,
         org_level4 type string,
         werks     TYPE string,
         persg     TYPE string,
         persk     TYPE string,
         btrtl     TYPE string,
         abkrs     TYPE string,
         vdsk1     TYPE string,
         zposfx    type string,
         rrf1       type string,
         candid    type string,
****infotype 0002
         anrex     TYPE string" title
         nachn     TYPE string"last name
         vorna     TYPE string,
         gesch     TYPE string" Gender
         gbdat     TYPE string" data brith
         natio     TYPE string,
****infotype 0007
         schkz     TYPE string,
         zterf     TYPE string,
****infotype 0008
         trfgr     TYPE string,
         trfst     TYPE string,
         ansal     TYPE string,
****infotype 0050
****infotype 0016
         cttyp     TYPE string,
         prbzt     TYPE string,
         prbeh     TYPE string,
         kdgfr     TYPE string,
         kdgf2     TYPE string,
****infotype 0017
         spebe     TYPE string,
         pkwrg     TYPE string,
         kzpmf     TYPE string,
         pkwkl     TYPE string,
****infotype 0027 Subtype 01
         bukrs     TYPE string,
         kostl     TYPE string,
         prozt     TYPE string,
****infotype 0027 Subtype 02
         bukrs1    TYPE string,
         kostl1    TYPE string,
         prozt1    TYPE string,
****infotype 0315
         kostl2    TYPE string,
         lstar     TYPE string,
         werks2    TYPE string,
         accnt     TYPE string,
****infotype 0587
         tstid     TYPE string,
         penid     TYPE string,
         eepfm     TYPE string,
         eepnm     TYPE string,
         evpfa     TYPE string,
         pnflg     TYPE string,
         erpn1     TYPE string,
         erpn2     TYPE string,
****infotype 0588
         ticnm1    TYPE string,
         esinm1    TYPE string,
         esidp1    TYPE string,
         lwfck     TYPE string,
         ptxel     TYPE string,
****infotype 0591
         nname     TYPE string,
         nmadd     TYPE string,
         reltn     TYPE string,
         datob     TYPE string,
         shprc     TYPE string,
         nname1    TYPE string,
         nmadd1    TYPE string,
         reltn1    TYPE string,
         datob1    TYPE string,
         shprc1    TYPE string,
         nname2    TYPE string,
         nmadd2    TYPE string,
         reltn2    TYPE string,
         datob2    TYPE string,
         shprc2    TYPE string,
         nname3    TYPE string,
         nmadd3    TYPE string,
         reltn3    TYPE string,
         datob3    TYPE string,
         shprc3    TYPE string,
****infotype 0804
         heght     TYPE string,
         weght     TYPE string,
         bgrup     TYPE string,
****infotype 9013
         source    TYPE string,
         agrmnt    TYPE string,
         rrf       TYPE string,
         bl_typ    TYPE string,
         emp_roll  TYPE string,
         emp_con   TYPE string,
         emp_num   TYPE string,
         dep_ins   TYPE string,
         board_usr TYPE string,
****infotype 9015
         language  TYPE string,
         zread     TYPE string,
         zwrite    TYPE string,
         zspeak    TYPE string,
       END OF gty_input.

DATA gs_input TYPE gty_input.

DATA gt_input TYPE STANDARD TABLE OF gty_input,
       gt_raw   TYPE truxs_t_text_data.

DATA gv_pernr   TYPE pernr_d,
       gv_row     TYPE i,
       gv_row_str TYPE string.
*{   INSERT         CHDK900354                                        1
DATA gv_position TYPE HROBJID.
*}   INSERT

"BDC
DATAbdcdata LIKE bdcdata    OCCURS WITH HEADER LINE.
DATAmesstab LIKE bdcmsgcoll OCCURS WITH HEADER LINE.
DATAl_mstring(480).



*&---------------------------------------------------------------------*
*&  Include           ZHR_ON_BORADING_PROCESS_SEL
*&---------------------------------------------------------------------*
PARAMETERS p_file TYPE rlgrap-filename.
PARAMETERS R1 RADIOBUTTON GROUP G1,
             R2 RADIOBUTTON GROUP G1.
*PARAMETERs : mode type ctuparams

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name 'P_FILE'
    IMPORTING
      file_name  p_file.




START-OF-SELECTION.

  PERFORM get_excel.

  PERFORM bdc_creation.

FORM get_excel.
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_line_header        'X'
      i_tab_raw_data       gt_raw
      i_filename           p_file
    TABLES
      i_tab_converted_data gt_input
    EXCEPTIONS
      conversion_failed    1
      OTHERS               2.
ENDFORM.

FORM bdc_creation.
  IF gt_input IS NOT INITIAL.
    LOOP AT gt_input INTO gs_input.
      gv_row gv_row + 1.
      CLEAR gv_pernr.
      SET PARAMETER ID 'PER' FIELD gv_pernr.
      PERFORM bdc_dynpro      USING 'SAPMP50A' '2200'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=P+'.
*perform bdc_field       using 'BDC_CURSOR'
*                              'RP50G-PERNR'.
      PERFORM bdc_field       USING 'RP50G-PERNR'
                                    space.
      PERFORM bdc_dynpro      USING 'SAPMP50A' '2200'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'RP50G-EINDA'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=PICK'.
      PERFORM bdc_field       USING 'RP50G-EINDA'
                                    gs_input-begda.
      PERFORM bdc_field       USING 'RP50G-SELEC(02)'
                                    'X'."record-SELEC_11_003'.

****Infotype 0000
      PERFORM bdc_dynpro      USING 'MP000000' '2000'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'PSPAR-PERSK'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=UPD'.
*      PERFORM bdc_field       USING 'P0000-PERNR'
*                                    space.
      PERFORM bdc_field       USING 'P0000-BEGDA'
                                    gs_input-begda.
      PERFORM bdc_field       USING 'P0000-ENDDA'
                                    gs_input-endda.
      PERFORM bdc_field       USING 'P0000-MASSG'
                                    gs_input-massg.
      PERFORM bdc_field       USING 'PSPAR-PLANS'
                                    gs_input-plans.
      PERFORM bdc_field       USING 'PSPAR-WERKS'
                                    gs_input-werks.
      PERFORM bdc_field       USING 'PSPAR-PERSG'
                                    gs_input-persg.
      PERFORM bdc_field       USING 'PSPAR-PERSK'
                                    gs_input-persk.
*{   INSERT         CHDK900107                                        1
*      PERFORM bdc_dynpro      USING 'MP000000' '2000'.
*      PERFORM bdc_field       USING 'BDC_OKCODE'
*                                    '=UPD'.
*}   INSERT

****Infotype 0001
      PERFORM bdc_dynpro      USING 'MP000100' '2000'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=UPD'.
      PERFORM bdc_field       USING 'P0001-BTRTL'
                                    gs_input-btrtl.
      PERFORM bdc_field       USING 'P0001-ABKRS'
                                    gs_input-abkrs.
      PERFORM bdc_field       USING 'P0001-PLANS'
                                    gs_input-plans.
      PERFORM bdc_field       USING 'P0001-VDSK1'
                                    gs_input-vdsk1.

****Infotype 0002
      PERFORM bdc_dynpro      USING 'MP000200' '2040'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=UPD'.
      PERFORM bdc_field       USING 'Q0002-ANREX'
                                    gs_input-anrex.
      PERFORM bdc_field       USING 'P0002-NACHN'
                                    gs_input-nachn.
      PERFORM bdc_field       USING 'P0002-VORNA'
                                    gs_input-vorna.
      PERFORM bdc_field       USING 'P0002-GESCH'
                                    gs_input-gesch.
*perform bdc_field       using 'P0002-SPRSL'
*                              record-SPRSL_024.
      PERFORM bdc_field       USING 'P0002-GBDAT'
                                    gs_input-gbdat.
      PERFORM bdc_field       USING 'P0002-NATIO'
                                    gs_input-natio.

****Infotype 0007
      PERFORM bdc_dynpro      USING 'MP000700' '2000'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'P0007-BEGDA'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    'UPD'.
      IF gs_input-schkz IS NOT INITIAL.
        PERFORM bdc_field       USING 'P0007-SCHKZ'
                                      gs_input-schkz.
      ENDIF.
      IF gs_input-zterf IS NOT INITIAL.
        PERFORM bdc_field       USING 'P0007-ZTERF'
                                      gs_input-zterf.
      ENDIF.
*perform bdc_field       using 'P0007-EMPCT'
*                              gs_input-EMPCT.

****Infotype 0008
      PERFORM bdc_dynpro      USING 'MP000800' '2040'.
      IF gs_input-trfgr IS NOT INITIAL OR gs_input-trfst IS NOT INITIAL
        OR gs_input-ansal IS NOT INITIAL.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=UPD'.
*perform bdc_field       using 'P0008-TRFAR'
*                              record-TRFAR_034.
*perform bdc_field       using 'P0008-BSGRD'
*                              record-BSGRD_035.
*perform bdc_field       using 'P0008-TRFGB'
*                              record-TRFGB_036.
*perform bdc_field       using 'P0008-DIVGV'
*                              record-DIVGV_037.
        PERFORM bdc_field       USING 'P0008-TRFGR'
                                      gs_input-trfgr.
        PERFORM bdc_field       USING 'P0008-TRFST'
                                      gs_input-trfst.
        PERFORM bdc_field       USING 'P0008-ANSAL'
                                      gs_input-ansal.
      ELSE.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                            '/E'.
      ENDIF.
*perform bdc_field       using 'P0008-ANCUR'
*                              record-ANCUR_041.
*perform bdc_field       using 'Q0008-IBBEG'
*                              record-IBBEG_042.
*perform bdc_field       using 'P0008-WAERS'
*                              record-WAERS_043.

****Infotype 0016
      PERFORM bdc_dynpro      USING 'MP001600' '2040'.
      IF gs_input-cttyp IS NOT INITIAL OR gs_input-prbzt IS NOT INITIAL
        OR gs_input-prbeh IS NOT INITIAL OR gs_input-kdgfr IS NOT INITIAL
        OR gs_input-kdgf2 IS NOT INITIAL.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=UPD'.
        PERFORM bdc_field       USING 'P0016-CTTYP'
                                      gs_input-cttyp.
        PERFORM bdc_field       USING 'P0016-PRBZT'
                                      gs_input-prbzt.
        PERFORM bdc_field       USING 'Q0016-PRBEH'
                                      gs_input-prbeh.
        PERFORM bdc_field       USING 'P0016-KDGFR'
                                      gs_input-kdgfr.
        PERFORM bdc_field       USING 'P0016-KDGF2'
                                      gs_input-kdgf2.
      ELSE.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                            '/E'.
      ENDIF.
****Infotype 0017
      PERFORM bdc_dynpro      USING 'MP001700' '2000'.
      IF gs_input-spebe IS NOT INITIAL OR gs_input-pkwrg IS NOT INITIAL
        OR gs_input-kzpmf IS NOT INITIAL OR gs_input-pkwkl IS NOT INITIAL.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=UPD'.
        PERFORM bdc_field       USING 'P0017-SPEBE'
                                      gs_input-spebe.
        PERFORM bdc_field       USING 'P0017-PKWRG'
                                      gs_input-pkwrg.
        PERFORM bdc_field       USING 'P0017-KZPMF'
                                      gs_input-kzpmf.
        PERFORM bdc_field       USING 'P0017-PKWKL'
                                      gs_input-pkwkl.
      ELSE.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                            '/E'.
      ENDIF.
****Infotype 0027 subtype 01
      PERFORM bdc_dynpro      USING 'MP002700' '2500'.
      IF gs_input-bukrs IS NOT INITIAL OR gs_input-kostl IS NOT INITIAL
        OR gs_input-prozt IS NOT INITIAL.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      'UPD'.
        PERFORM bdc_field       USING 'P0027-KSTAR'
                                      '01'.
*      PERFORM bdc_field       USING 'BDC_CURSOR'
*                                    'RHCD_TAB-PROZT(01)'.
        PERFORM bdc_field       USING 'RHCD_TAB-BUKRS(01)'
                                      gs_input-bukrs.
        PERFORM bdc_field       USING 'RHCD_TAB-KOSTL(01)'
                                      gs_input-kostl.
        PERFORM bdc_field       USING 'RHCD_TAB-PROZT(01)'
                                      gs_input-prozt.
      ELSE.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                            '/E'.
      ENDIF.
****Infotype 0027 subtype 02
      PERFORM bdc_dynpro      USING 'MP002700' '2500'.
      IF gs_input-bukrs IS NOT INITIAL OR gs_input-kostl IS NOT INITIAL
        OR gs_input-prozt IS NOT INITIAL.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=UPD'.
        PERFORM bdc_field       USING 'P0027-KSTAR'
                                      '02'.
        PERFORM bdc_field       USING 'RHCD_TAB-BUKRS(01)'
                                      gs_input-bukrs1.
        PERFORM bdc_field       USING 'RHCD_TAB-KOSTL(01)'
                                      gs_input-kostl1.
        PERFORM bdc_field       USING 'RHCD_TAB-PROZT(01)'
                                      gs_input-prozt1.
      ELSE.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                            '/E'.
      ENDIF.
****Infotype 0315
      PERFORM bdc_dynpro      USING 'MP031500' '2000'.
      IF gs_input-kostl2 IS NOT INITIAL OR gs_input-lstar IS NOT INITIAL
        OR gs_input-werks2 IS NOT INITIAL OR gs_input-accnt IS NOT INITIAL.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=UPD'.
        PERFORM bdc_field       USING 'P0315-KOSTL'
                                      gs_input-kostl2.
        PERFORM bdc_field       USING 'P0315-LSTAR'
                                      gs_input-lstar.
        PERFORM bdc_field       USING 'P0315-WERKS'
                                      gs_input-werks2.
        PERFORM bdc_field       USING 'P0315-ACCNT'
                                      gs_input-accnt.
      ELSE.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                            '/E'.
      ENDIF.
****Infotype 0587
      PERFORM bdc_dynpro      USING 'MP058700' '2000'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=UPD'.
      PERFORM bdc_field       USING 'P0587-TSTID'
                                    gs_input-tstid.
      PERFORM bdc_field       USING 'P0587-PENID'
                                    gs_input-penid.
      PERFORM bdc_field       USING 'P0587-EEPFM'
                                    gs_input-eepfm.
      PERFORM bdc_field       USING 'P0587-EEPNM'
                                    gs_input-eepnm.
*perform bdc_field       using 'Q0587-EEPF2'
*                              record-EEPF2_081.
      PERFORM bdc_field       USING 'P0587-EVPFA'
                                    gs_input-evpfa.
*perform bdc_field       using 'Q0587-ERPF1'
*                              record-ERPF1_083.
*perform bdc_field       using 'Q0587-ERPF2'
*                              record-ERPF2_084.
      PERFORM bdc_field       USING 'P0587-PNFLG'
                                    gs_input-pnflg.
      PERFORM bdc_field       USING 'Q0587-ERPN1'
                                    gs_input-erpn1.
      PERFORM bdc_field       USING 'Q0587-ERPN2'
                                    gs_input-erpn2.
****Infotype 0588 subtype 0001
      PERFORM bdc_dynpro      USING 'MP058800' '2000'.
      IF gs_input-ticnm1 IS NOT INITIAL OR gs_input-esinm1 IS NOT INITIAL
        OR gs_input-esidp1 IS NOT INITIAL.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=UPD'.
        PERFORM bdc_field       USING 'P0588-TICNM'
                                      gs_input-ticnm1.
        PERFORM bdc_field       USING 'P0588-ESINM'
                                      gs_input-esinm1.
        PERFORM bdc_field       USING 'P0588-ESIDP'
                                      gs_input-esidp1.
      ELSE.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                            '/E'.
      ENDIF.
****Infotype 0588 subtype 0002
      PERFORM bdc_dynpro      USING 'MP058800' '2000'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=UPD'.
      PERFORM bdc_field       USING 'Q0588-LWFCK'
                                    gs_input-lwfck.
****Infotype 0588 subtype 0003
      PERFORM bdc_dynpro      USING 'MP058800' '2000'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=UPD'.
      PERFORM bdc_field       USING 'Q0588-PTXEL'
                                    gs_input-ptxel.
****Infotype 0591 subtype BNES

      PERFORM bdc_dynpro      USING 'MP059100' '2000'.
      IF gs_input-nname IS NOT INITIAL OR gs_input-nmadd IS NOT INITIAL
        OR gs_input-reltn IS NOT INITIAL OR gs_input-datob IS NOT INITIAL
        OR gs_input-shprc IS NOT INITIAL.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'ITAB_NOM-GRADD(01)'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=UPD'.
        PERFORM bdc_field       USING 'ITAB_NOM-NNAME(01)'
                                      gs_input-nname.
        PERFORM bdc_field       USING 'ITAB_NOM-NMADD(01)'
                                      gs_input-nmadd.
        PERFORM bdc_field       USING 'ITAB_NOM-RELTN(01)'
                                      gs_input-reltn.
        PERFORM bdc_field       USING 'ITAB_NOM-DATOB(01)'
                                      gs_input-datob.
        PERFORM bdc_field       USING 'ITAB_NOM-SHPRC(01)'
                                      gs_input-shprc.
      ELSE.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                            '/E'.
      ENDIF.
****Infotype 0591 subtype BNGR
      PERFORM bdc_dynpro      USING 'MP059100' '2000'.
      IF gs_input-nname1 IS NOT INITIAL OR gs_input-nmadd1 IS NOT INITIAL
        OR gs_input-reltn1 IS NOT INITIAL OR gs_input-datob1 IS NOT INITIAL
        OR gs_input-shprc1 IS NOT INITIAL.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'ITAB_NOM-GRADD(01)'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=UPD'.
        PERFORM bdc_field       USING 'ITAB_NOM-NNAME(01)'
                                      gs_input-nname1.
        PERFORM bdc_field       USING 'ITAB_NOM-NMADD(01)'
                                      gs_input-nmadd1.
        PERFORM bdc_field       USING 'ITAB_NOM-RELTN(01)'
                                      gs_input-reltn1.
        PERFORM bdc_field       USING 'ITAB_NOM-DATOB(01)'
                                      gs_input-datob1.
        PERFORM bdc_field       USING 'ITAB_NOM-SHPRC(01)'
                                      gs_input-shprc1.
      ELSE.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                            '/E'.
      ENDIF.
****Infotype 0591 subtype BNPF
      PERFORM bdc_dynpro      USING 'MP059100' '2000'.
      IF gs_input-nname2 IS NOT INITIAL OR gs_input-nmadd2 IS NOT INITIAL
        OR gs_input-reltn2 IS NOT INITIAL OR gs_input-datob2 IS NOT INITIAL
        OR gs_input-shprc2 IS NOT INITIAL.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'ITAB_NOM-GRADD(01)'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=UPD'.
        PERFORM bdc_field       USING 'ITAB_NOM-NNAME(01)'
                                      gs_input-nname2.
        PERFORM bdc_field       USING 'ITAB_NOM-NMADD(01)'
                                      gs_input-nmadd2.
        PERFORM bdc_field       USING 'ITAB_NOM-RELTN(01)'
                                      gs_input-reltn2.
        PERFORM bdc_field       USING 'ITAB_NOM-DATOB(01)'
                                      gs_input-datob2.
        PERFORM bdc_field       USING 'ITAB_NOM-SHPRC(01)'
                                      gs_input-shprc2.
      ELSE.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                            '/E'.
      ENDIF.
****Infotype 0591 subtype BNPN
      PERFORM bdc_dynpro      USING 'MP059100' '2000'.
      IF gs_input-nname3 IS NOT INITIAL OR gs_input-nmadd3 IS NOT INITIAL
        OR gs_input-reltn3 IS NOT INITIAL OR gs_input-datob3 IS NOT INITIAL
        OR gs_input-shprc3 IS NOT INITIAL.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'ITAB_NOM-GRADD(01)'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=UPD'.
        PERFORM bdc_field       USING 'ITAB_NOM-NNAME(01)'
                                      gs_input-nname3.
        PERFORM bdc_field       USING 'ITAB_NOM-NMADD(01)'
                                      gs_input-nmadd3.
        PERFORM bdc_field       USING 'ITAB_NOM-RELTN(01)'
                                      gs_input-reltn3.
        PERFORM bdc_field       USING 'ITAB_NOM-DATOB(01)'
                                      gs_input-datob3.
        PERFORM bdc_field       USING 'ITAB_NOM-SHPRC(01)'
                                      gs_input-shprc3.
      ELSE.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                            '/E'.
      ENDIF.
****Infotype 0804
      PERFORM bdc_dynpro      USING 'MP080400' '2000'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=UPD'.
      PERFORM bdc_field       USING 'P0804-HEGHT'
                                    gs_input-heght.
      PERFORM bdc_field       USING 'P0804-WEGHT'
                                    gs_input-weght.
      PERFORM bdc_field       USING 'P0804-BGRUP'
                                    gs_input-bgrup.
****Infotype 9013
      PERFORM bdc_dynpro      USING 'MP901300' '2000'.
      IF gs_input-source IS NOT INITIAL OR gs_input-agrmnt IS NOT INITIAL
        OR gs_input-rrf IS NOT INITIAL OR gs_input-bl_typ IS NOT INITIAL
        OR gs_input-emp_roll IS NOT INITIAL OR gs_input-emp_con IS NOT INITIAL
        OR gs_input-emp_num IS NOT INITIAL OR gs_input-dep_ins IS NOT INITIAL
        OR gs_input-board_usr IS NOT INITIAL.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=UPD'.
        PERFORM bdc_field       USING 'P9013-SOURCE'
                                      gs_input-source.
        PERFORM bdc_field       USING 'P9013-AGRMNT'
                                      gs_input-agrmnt.
        PERFORM bdc_field       USING 'P9013-RRF'
                                      gs_input-rrf.
        PERFORM bdc_field       USING 'P9013-BL_TYP'
                                      gs_input-bl_typ.
        PERFORM bdc_field       USING 'P9013-EMP_ROLL'
                                      gs_input-emp_roll.
        PERFORM bdc_field       USING 'P9013-EMP_CON'
                                      gs_input-emp_con.
        PERFORM bdc_field       USING 'P9013-EMP_NUM'
                                      gs_input-emp_num.
        PERFORM bdc_field       USING 'P9013-DEP_INS'
                                      gs_input-dep_ins.
        PERFORM bdc_field       USING 'P9013-BOARD_USR'
                                      gs_input-board_usr.
      ELSE.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                            '/E'.
      ENDIF.
****Infotype 9015
      PERFORM bdc_dynpro      USING 'MP901500' '2000'.
      IF gs_input-language IS NOT INITIAL.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=UPD'.
        PERFORM bdc_field       USING 'P9015-LANGUAGE'
                                      gs_input-language.
        PERFORM bdc_field       USING 'P9015-ZREAD'
                                      gs_input-zread.
        PERFORM bdc_field       USING 'P9015-ZWRITE'
                                      gs_input-zwrite.
        PERFORM bdc_field       USING 'P9015-ZSPEAK'
                                      gs_input-zspeak.
      ELSE.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                            '/E'.
      ENDIF.
      PERFORM bdc_dynpro      USING 'SAPMP50A' '2200'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '/EBCK'.
      PERFORM bdc_transaction USING 'PA40'.
      CLEAR gs_input.
    ENDLOOP.
  ELSE.
    MESSAGE 'No record in excel' TYPE 'I'.
  ENDIF.
ENDFORM.

FORM bdc_field USING fnam fval.
  CLEAR bdcdata.
  bdcdata-fnam fnam.
  bdcdata-fval fval.
  APPEND bdcdata.
ENDFORM.

FORM bdc_dynpro USING program dynpro.
  CLEAR bdcdata.
  bdcdata-program  program.
  bdcdata-dynpro   dynpro.
  bdcdata-dynbegin 'X'.
  APPEND bdcdata.
ENDFORM.


FORM bdc_transaction USING tcode.
  DATA ls_ctu TYPE ctu_params.
*{   INSERT         CHDK900245                                        4
  DATA lv_pernr TYPE persno,
         lv_begda TYPE begda.
*}   INSERT
  ls_ctu-dismode 'N'.
  ls_ctu-updmode 'S'.
  ls_ctu-defsize 'X'.
  CLEAR messtab[].
  SET PARAMETER ID '/ISDFPS/UNIT_LENGTH' FIELD 'CM'.

  SET PARAMETER ID '/ISDFPS/UNIT_MASS' FIELD 'KG'.
  CALL TRANSACTION tcode USING bdcdata
                      OPTIONS FROM ls_ctu
                      MESSAGES INTO messtab.
  COMMIT WORK.
*{   INSERT         CHDK900101                                        2
 GET PARAMETER ID 'PER' FIELD gv_pernr.
 gv_row_str gv_row.
    IF gv_row 1.
      WRITE/ sy-vline,'Row ID'10 sy-vline,12 'Error',19 sy-vline,21 'Employee Id' ,32 sy-vline,34  'Message'.
      ULINE.
    ENDIF.
*}   INSERT
  IF messtab[] IS NOT INITIAL.
*{   DELETE         CHDK900101                                        1
*\    GET PARAMETER ID 'PER' FIELD gv_pernr.
*}   DELETE
*{   DELETE         CHDK900245                                        5
*\    IF gv_row = 1.
*\      WRITE: / sy-vline,2 'Row ID', 10 sy-vline,12 'Error',19 sy-vline,21 'Employee Id' ,32 sy-vline,34  'Message'.
*\      ULINE.
*\    ENDIF.
*}   DELETE
*{   DELETE         CHDK900245                                        6
*\    gv_row_str = gv_row.
*}   DELETE
    LOOP AT messtab.
      MESSAGE ID     messtab-msgid
              TYPE   messtab-msgtyp
              NUMBER messtab-msgnr
              INTO l_mstring
              WITH messtab-msgv1
                   messtab-msgv2
                   messtab-msgv3
                   messtab-msgv4.
      WRITE/ sy-vline,gv_row_str10 sy-vline,12 messtab-msgtyp,19 sy-vline,21 gv_pernr ,32 sy-vline,34  l_mstring.
    ENDLOOP.
*{   REPLACE        CHDK900245                                        3
*\  ELSE.
*\    WRITE: / sy-vline,2 gv_row_str, 10 sy-vline,12 'S',19 sy-vline,21 gv_pernr ,32 sy-vline,34  'Employee created Success'.
*\  ENDIF.
*\  IF messtab[] IS NOT INITIAL.
*\    READ TABLE messtab[] TRANSPORTING NO FIELDS WITH KEY msgtyp = 'E'.
*\    IF sy-subrc NE 0.
*\      WRITE: / sy-vline,2 gv_row_str, 10 sy-vline,12 'S',19 sy-vline,21 gv_pernr ,32 sy-vline,34  'Employee created Success'.
*\    ENDIF.
*\  ENDIF.
*\  CLEAR: bdcdata, bdcdata[].
  ENDIF.
    CLEAR lv_pernr.
    SELECT SINGLE pernr begda INTO (lv_pernr,lv_begdaFROM pa0000 WHERE pernr gv_pernr.
      IF sy-subrc 0.
        CLEAR gv_position.
        PERFORM create_0041 USING lv_pernr lv_begda.
        gv_position gs_input-plans.
        IF lv_pernr IS NOT INITIAL AND gv_position IS NOT INITIAL AND gv_position NE '99999999'.
          PERFORM create_1001 USING gv_position lv_pernr lv_begda.
        ENDIF.
        WRITE/ sy-vline,gv_row_str10 sy-vline,12 'S',19 sy-vline,21 gv_pernr ,32 sy-vline,34  'Employee created Success'.
      ELSE.
        WRITE/ sy-vline,gv_row_str10 sy-vline,12 'E',19 sy-vline,21 lv_pernr ,32 sy-vline,34  'Employee IS Not created'.
      ENDIF.
  CLEARbdcdatabdcdata[].
*}   REPLACE
ENDFORM.
*{   INSERT         CHDK900245                                        1

FORM create_0041 USING lv_pernr TYPE persno
                       lv_begda TYPE begda.

  DATA lv_msg    TYPE string,
         ls_return TYPE bapireturn1,
         ls_0041   TYPE p0041.

        CALL FUNCTION 'HR_EMPLOYEE_ENQUEUE'
            EXPORTING
              number lv_pernr
            IMPORTING
              return ls_return.
          IF ls_return-type NE 'E'.
            CLEAR ls_return.
            ls_0041-pernr lv_pernr.
            ls_0041-begda lv_begda.
            ls_0041-endda '99991231'.
            ls_0041-dar01 'Z1'.
            ls_0041-dat01 lv_begda.
            ls_0041-dar02 'Z6'.
            ls_0041-dat02 lv_begda.
            ls_0041-dar03 'Z9'.
            ls_0041-dat03 lv_begda.
            CALL FUNCTION 'HR_INFOTYPE_OPERATION'
              EXPORTING
                infty         '0041'
                number        lv_pernr
*                subtype       = subty
                validityend   '99991231'
                validitybegin lv_begda
                record        ls_0041
                operation     'INS'
              IMPORTING
                return        ls_return.
            IF ls_return-type 'E'.
              CLEAR lv_msg.
              CALL FUNCTION 'FORMAT_MESSAGE'
                EXPORTING
                  id        ls_return-id
                  lang      'EN'
                  no        ls_return-number
                  v1        ls_return-message_v1
                  v2        ls_return-message_v2
                  v3        ls_return-message_v3
                  v4        ls_return-message_v4
                IMPORTING
                  msg       lv_msg
                EXCEPTIONS
                  not_found 1
                  OTHERS    2.
              WRITE/ sy-vline,gv_row_str10 sy-vline,12 'W',19 sy-vline,21 gv_pernr ,32 sy-vline,
                        34  'Info 0041 is not created because'lv_msg.
            ENDIF.
            COMMIT WORK.
            CALL FUNCTION 'HR_EMPLOYEE_DEQUEUE'
              EXPORTING
                number lv_pernr
              IMPORTING
                return ls_return.
          ENDIF.
          CLEARls_return.
ENDFORM.

FORM create_1001 USING lv_position TYPE OBJEKTID
                       lv_pernr TYPE persno
                       lv_begda TYPE begda.
  DATA ls_1001    TYPE p1001.

  CLEAR ls_1001.
  ls_1001-OTYPE 'S'.
  ls_1001-OBJID lv_position.
  ls_1001-PLVAR '01'.
  ls_1001-RSIGN 'A'.
  ls_1001-RELAT '008'.
  ls_1001-ISTAT '1'.
  ls_1001-BEGDA lv_begda.
  ls_1001-ENDDA '99993112'.
  ls_1001-INFTY '1001'.
  ls_1001-SCLAS 'P'.
  ls_1001-SOBID lv_pernr.
  ls_1001-PROZT 100.
  CALL FUNCTION 'RH_PM_ENQUEUE'
    EXPORTING
      act_plvar              '01'
      act_otype              'S'
      act_objid              lv_position
   EXCEPTIONS
     ERROR_IN_ENQUEUE       1
     OTHERS                 2.
  IF sy-subrc 0.
    CALL FUNCTION 'RH_PNNNN_MAINTAIN'
      EXPORTING
        act_fcode                   'INSE'
        ACT_PLVAR                   '01'
        act_otype                   'S'
        act_objid                   lv_position
        ACT_INFTY                   '1001'
        ACT_SUBTY                   'A008'
       ACT_ISTAT                   '1'
       ACT_BEGDA                   lv_begda
       ACT_ENDDA                   '99991231'
        ACT_PNNNN                   ls_1001
       ACT_VTASK                   'S'
       ACT_COMMIT_FLG              'X'
       SUPPRESS_DIALOG             2
     EXCEPTIONS
       INFTY_NOT_VALID             1
       NO_PLVAR                    2
       OBJECT_NOT_DEFINED          3
       OTYPE_NOT_VALID             4
       NO_AUTHORITY                5
       ACTION_REJECTED             6
       NO_GDATE                    7
       FCODE_NOT_SUPPORTED         8
       OTHERS                      9.
   IF sy-subrc NE 0.
    WRITE/ sy-vline,gv_row_str10 sy-vline,12 'W',19 sy-vline,21 gv_pernr ,32 sy-vline,
                     34  'Info 1001 - Position to Employess relationship is not created'.
   ENDIF.
  CALL FUNCTION 'RH_PM_DEQUEUE'
    EXPORTING
      act_plvar       '01'
      act_otype       'S'
      act_objid       lv_position.
ELSE.
  WRITE/ sy-vline,gv_row_str10 sy-vline,12 'W',19 sy-vline,21 lv_position ,32 sy-vline,
                     34  'Position is locked, So 1001 - Position to Employess relationship is not created'.
ENDIF.
ENDFORM.
*}   INSERT