How to use HR_MAINTAIN_MASTERDATA for new hiring

In HCM SAP Module you can enter new hire employer via PA40 tcode, but in ABAP Code you can use HR_MAINTAIN_MASTERDATA to automate new hire, in my requirement is to create ABAP Program to process new hiring employer via excel upload.

Before you use HR_MAINTAIN_MASTERDATA you need to ask your SAP HCM Functional team about all of infotypes they use for new hiring employer, because if you use HR_MAINTAIN_MASTERDATA you need to provide all infotype within Infogroup sequentially.

In My Sample Code, my SAP HCM Functional team has setup configuration for new hiring use 3 infotype only, they are 0000, 0002, 0001 infotype.

FUNCTION zfm_hr_save_new_hire.
*”———————————————————————-
*”*”Local Interface:
*” IMPORTING
*” REFERENCE(GV_FILE) TYPE LOCALFILE
*” REFERENCE(GV_TEST) TYPE CHAR1 OPTIONAL
*” EXPORTING
*” REFERENCE(GV_MESSAGE) TYPE CHAR100
*” TABLES
*” GT_OUTPUT STRUCTURE ZTA_HR_NEW_HIRE
*”———————————————————————-
TYPES: BEGIN OF ty_excel,
pernr(100),
massg(100),
endda(100),
begda(100),
persa(100),
btrtl(100),
persg(100),
persk(100),
plans(100),
abkrs(100),
ansvh(100),
trfar(100),
trfgb(100),
trfgr(100),
trfst(100),
gapok(100),
tunj1(100),
tunj2(100),
tunj3(100),
status(100),
END OF ty_excel.

DATA: lv_string_file TYPE string,
lv_raw TYPE truxs_t_text_data,
li_excel TYPE TABLE OF ty_excel WITH HEADER LINE,
li_hr_new_hire TYPE TABLE OF zta_hr_new_hire WITH HEADER LINE,
lv_count TYPE i,
lv_char(5),
lv_string(100),
lv_val LIKE pprop-fval.

DATA : li_proposed LIKE pprop OCCURS 0 WITH HEADER LINE,
lw_rc LIKE bapireturn,
lw_rc1 LIKE bapireturn1,
lw_hr TYPE hrhrmm_msg.

DATA: lt_messtab TYPE TABLE OF bdcmsgcoll,
ls_messtab TYPE bdcmsgcoll.

CALL FUNCTION ‘TEXT_CONVERT_XLS_TO_SAP’
EXPORTING
i_line_header = ‘X’
i_tab_raw_data = lv_raw
i_filename = gv_file
TABLES
i_tab_converted_data = li_excel
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
CASE sy-subrc.
WHEN 1.
gv_message = ‘Conversion Failed’.
WHEN 2.
gv_message = ‘Error’.
ENDCASE.
ELSE.

LOOP AT li_excel.
ADD 1 TO lv_count.
MOVE-CORRESPONDING li_excel TO li_hr_new_hire.
CONCATENATE li_excel-endda+6(4) li_excel-endda+3(2) li_excel-endda(2) INTO li_hr_new_hire-endda.
CONCATENATE li_excel-begda+6(4) li_excel-begda+3(2) li_excel-begda(2) INTO li_hr_new_hire-begda.
APPEND li_hr_new_hire.
ENDLOOP.

CLEAR lv_count.
IF gv_test = ‘X’.
WRITE lv_count TO lv_char.
CONDENSE lv_char.
CONCATENATE ‘Successfully process’ lv_char ‘rows’ INTO gv_message SEPARATED BY space.
ELSE.

LOOP AT li_hr_new_hire.
REFRESH : li_proposed.

lv_val = li_hr_new_hire-massg.
PERFORM fill TABLES li_proposed USING ‘0000’
‘P0000-MASSG’
lv_val.

“P0002
lv_val = ‘1’.
PERFORM fill TABLES li_proposed USING ‘0002’
‘P0002-ANRED’
lv_val.

lv_val = ‘Please Changed’.
PERFORM fill TABLES li_proposed USING ‘0002’
‘P0002-CNAME’
lv_val.

lv_val = li_hr_new_hire-begda.
PERFORM fill TABLES li_proposed USING ‘0002’
‘P0002-GBPAS’
lv_val.

lv_val = ‘1’.
PERFORM fill TABLES li_proposed USING ‘0002’
‘P0002-FAMST’
lv_val.

“P0001
lv_val = ‘PP01’.
PERFORM fill TABLES li_proposed USING ‘0001’
‘P0001-BUKRS’
lv_val.

lv_val = li_hr_new_hire-persk.
PERFORM fill TABLES li_proposed USING ‘0001’
‘P0001-PERSK’
lv_val.

lv_val = li_hr_new_hire-btrtl.
PERFORM fill TABLES li_proposed USING ‘0001’
‘P0001-BTRTL’
lv_val.

*
lv_val = li_hr_new_hire-abkrs.
PERFORM fill TABLES li_proposed USING ‘0001’
‘P0001-ABKRS’
lv_val.

*
lv_val = li_hr_new_hire-ansvh.
PERFORM fill TABLES li_proposed USING ‘0001’
‘P0001-ANSVH’
lv_val.

CALL FUNCTION ‘HR_MAINTAIN_MASTERDATA’
EXPORTING
pernr = ‘00000000’
massn = ‘Q0’
actio = ‘INSS’
tclas = ‘A’
no_existence_check = ‘X’
dialog_mode = ‘0’
no_enqueue = ”
begda = li_hr_new_hire-begda
werks = li_hr_new_hire-persa
persg = li_hr_new_hire-persg
persk = li_hr_new_hire-persk
plans = li_hr_new_hire-plans
IMPORTING
return = lw_rc
return1 = lw_rc1
hr_return = lw_hr
TABLES
proposed_values = li_proposed.

IF lw_rc-type NE ‘E’.
gt_output = li_hr_new_hire.

GET PARAMETER ID ‘PER’ FIELD gt_output-pernr.
gt_output-mess = lw_rc-message.
APPEND gt_output.

ELSE.

gt_output = li_hr_new_hire.
gt_output-mess = lw_rc-message.
APPEND gt_output.

ENDIF.

ENDLOOP.

ENDIF.

ENDIF.

ENDFUNCTION.

FORM fill TABLES loc_proposed_values STRUCTURE pprop
USING infty LIKE pprop-infty
fname LIKE pprop-fname
fval LIKE pprop-fval.
* seqnr LIKE pprop-seqnr.

DATA: wa_values LIKE pprop.

wa_values-infty = infty.
wa_values-fname = fname.
wa_values-fval = fval.
* wa_values-seqnr = seqnr.
APPEND wa_values TO loc_proposed_values.

ENDFORM. “fill

hr_maintain_masterdata-1

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.