‎2009 Feb 18 11:32 AM
Hi,
I am new to HR ABAP . Can anybody send me an end to end sample BDC program using HR ABAP. I have a requirement to develop a program.
Please give the sample file which has the sample data to upload to SAP.
Rgds,
Sofia
‎2009 Feb 18 11:39 AM
hi....
to create a program of your own....
goto tcode 'SHDB' and there go for a new recording of the TCODE as required by you...
after recording is complete there is a button to GENERATE a program for that
i am looking for a complete data tranfer example which i have done.... i ll send that to you
regards
this is a sample code for it
THIS IS WRITTEN BY ME,YOU CAN GENERATE PROGRAM DIRECTLY
*" Type declarations...................................................
"----
Type declaration of the structure to hold material information *
"----
TYPES:
BEGIN OF type_s_mat,
name(10) TYPE c, " Material Number
industry TYPE c, " Industry Sector
mtype(10) TYPE c, " Material Type
descr(20) TYPE c, " Material Description
unit(10) TYPE c, " Base Unit of Measure
END OF type_s_mat,
type_s_f2(4096) TYPE c.
*" Data declarations...................................................
"----
Work variables *
"----
DATA:
fs_f1 TYPE type_s_mat, " Field string of TYPE_S_MAT
fs_workarea TYPE bdcdata, " Field string of type BDCDATA
fs_bdc TYPE bdcmsgcoll, " Field string of type bdcmsgcoll
w_msg(72) TYPE c, " Holds message for writing
w_i TYPE i, " Holds value of rc
w_file TYPE filetable, " Holds name of the file
w_var TYPE file_table, " Field string of file_table
w_file1 TYPE string. " Holds the path of the file
"----
Internal table to hold data for the input *
"----
DATA:
t_itab LIKE
STANDARD TABLE
OF fs_workarea,
"----
Internal table to hold data for the messages *
"----
t_mess LIKE
STANDARD TABLE
OF fs_bdc,
t_mat LIKE
STANDARD TABLE
OF fs_f1,
"----
Internal table to hold data for the input *
"----
t_temp TYPE
STANDARD TABLE
OF type_s_f2.
*"Selection screen elements............................................
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_file(128) TYPE c.
SELECTION-SCREEN END OF BLOCK b1.
"----
AT SELECTION-SCREEN ON VALUE-REQUEST EVENT *
"----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'FILE_OPEN'
default_extension = 'XLS'
CHANGING
file_table = w_file
rc = w_i
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. " IF SY-SUBRC <> 0.
LOOP AT w_file INTO w_var.
p_file = w_var-filename.
ENDLOOP. " LOOP AT W_FILE INTO W_VAR.
ULINE.
"----
START-OF-SELECTION EVENT *
"----
START-OF-SELECTION.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_tab_raw_data = t_temp
i_filename = p_file
TABLES
i_tab_converted_data = t_mat
EXCEPTIONS
conversion_failed = 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. " IF SY-SUBRC EQ 0.
"----
END-OF-SELECTION EVENT *
"----
END-OF-SELECTION.
PERFORM sub_display.
&----
*& Form sub_screen
&----
This subroutine appends the value of screen name and number *
----
-->PV_screenam This holds screen name *
-->PV_scrnum This holds screen number *
----
FORM sub_screen USING value(pv_screenam)
value(pv_scrnum).
CLEAR fs_workarea.
fs_workarea-program = pv_screenam.
fs_workarea-dynpro = pv_scrnum.
fs_workarea-dynbegin = 'X'.
APPEND fs_workarea TO t_itab.
ENDFORM. " FORM SUB_SCREEN
&----
*& Form SUB_FIELD_DATA *
&----
This subroutine apppends field name and value of the screen. *
----
-->PV_FLDNAM This holds field name *
-->PV_FLDVAL This holds Field value *
----
FORM sub_field_data USING value(pv_fldnam)
value(pv_fldval).
CLEAR fs_workarea.
fs_workarea-fnam = pv_fldnam.
fs_workarea-fval = pv_fldval.
APPEND fs_workarea TO t_itab.
ENDFORM. " FORM SUB_FIELD_DATA
&----
*& Form sub_display *
&----
This subroutine fills the value on screen fields when BDC executes *
----
There are no interface parameters to be passed to this subroutine. *
----
FORM sub_display .
LOOP AT t_mat INTO fs_f1.
CLEAR fs_workarea.
CLEAR fs_bdc.
PERFORM sub_screen USING 'SAPLMGMM' '0060'.
PERFORM sub_field_data USING 'RMMG1-MATNR' fs_f1-name.
PERFORM sub_field_data USING 'RMMG1-MBRSH' fs_f1-industry.
PERFORM sub_field_data USING 'RMMG1-MTART' fs_f1-mtype.
PERFORM sub_field_data USING 'BDC_OKCODE' '/00'.
PERFORM sub_screen USING 'SAPLMGMM' '0070'.
PERFORM sub_field_data USING 'MSICHTAUSW-KZSEL(01)' 'X'.
PERFORM sub_field_data USING 'MSICHTAUSW-KZSEL(02)' 'X'.
PERFORM sub_field_data USING 'BDC_OKCODE' '=ENTR'.
PERFORM sub_screen USING 'SAPLMGMM' '4004'.
PERFORM sub_field_data USING 'MAKT-MAKTX' fs_f1-descr.
PERFORM sub_field_data USING 'MARA-MEINS' fs_f1-unit.
PERFORM sub_field_data USING 'BDC_OKCODE' '/00'.
PERFORM sub_screen USING 'SAPLMGMM' '4004'.
PERFORM sub_field_data USING 'BDC_OKCODE' '=BU'.
CALL TRANSACTION 'MM01' USING t_itab MODE 'A' MESSAGES INTO t_mess.
ENDLOOP.
ENDFORM. " SUB_DISPLAY
Edited by: Mohit Kumar on Feb 18, 2009 12:40 PM
‎2009 Feb 18 12:11 PM
Hi Mohit,
Thanks for the updates. I was looking for a program coded in HR ABAP. can you please pass that to me . It may be any kind of data upload (tcode) in HR module .
Thanks.
Rgds,
Sofia
‎2009 Feb 18 12:46 PM
Hi Sofia,
Avoid if possible using BDC in new programs.
The best option is use the standard function modules like:
HR_MAINTAIN_MASTERDATA
HR_INFOTYPE_OPERATION
Check the example program RPLAPL00.
Roger
‎2009 Feb 19 3:21 AM
Hi Dude,
Go through this link : [https://www.sdn.sap.com/irj/scn/wiki?path=/label/snippets/hr-abap]
Better to goo for FM for upload / update the infotypes :
1. HR_INFOTYPE_OPERATION
‎2009 Feb 24 2:10 PM
Hi Raghunath,
Thanks for your reply.Could you please give me a sample program using the FM which you suggested.
Thanks in Advance.
Rgds,
Sofia
‎2009 Feb 25 5:35 AM
Hi Dude,
Go through the sample Code ...
CONSTANTS: change TYPE pspar-actio VALUE 'MOD'.
"This code is requred and locks the record ready for modification
CALL FUNCTION 'HR_EMPLOYEE_ENQUEUE'
EXPORTING
number = p_pernr.
"loop at p0071 into p_p0071. "added to put code in context
validitybegin = p_record-begda.
validityend = p_record-endda.
p_record-endda = pn-begda - 1.
CALL FUNCTION 'HR_INFOTYPE_OPERATION'
EXPORTING
infty = '0071'
subtype = p_record-subty
objectid = P_record-objps
number = p_record-pernr "employeenumber
validityend = validityend
validitybegin = validitybegin
record = p_record
recordnumber = p_record-SEQNR
operation = change
nocommit = nocommit
dialog_mode = '0'
IMPORTING
return = return_struct
key = personaldatakey
EXCEPTIONS
OTHERS = 0.
"endloop.
"unlock record after modification
CALL FUNCTION 'HR_EMPLOYEE_DEQUEUE'
EXPORTING
number = p_pernr.
Second one
tables: pa0001, pa0171, pa0378.
DATA BEGIN OF i0378.
include structure p0378.
DATA END OF i0378.
DATA: START_DATE LIKE SY-DATUM.
DATA RETURN LIKE BAPIRETURN1.
selection-screen begin of block p1.
* This select option allows for testing on limited employees
* or for splitting the update into multiple runs.
SELECT-OPTIONS pernr for pa0001-pernr.
selection-screen end of block p1.
selection-screen skip.
selection-screen begin of block b1.
* The plan year date is normally the first day of the next year
PARAMETERS: py_date LIKE SY-DATUM.
* This date is the beginning of the enrollment period for managers
PARAMETERS: MGR_DATE LIKE SY-DATUM.
* This date is the beginning of the enrollment period for hourlys
PARAMETERS: HRLY_DATE LIKE SY-DATUM.
selection-screen end of block b1.
INITIALIZATION.
py_date = sy-datum.
py_date(4) = py_date(4) + 1.
py_date+4(4) = '0101'.
START-OF-SELECTION.
select * from pa0171
where pernr in pernr
and endda ge py_date
and begda le py_date.
* skip ineligible employees
if pa0171-bstat eq 'INEL'.
continue.
endif.
* determine start date of enrollment based on benefit group
if pa0171-bengr eq 'MNGR'.
start_date = mgr_date.
elseif pa0171-bengr eq 'HRLY'.
start_date = hrly_date.
else.
* ERROR HANDLING GOES HERE
continue.
endif.
* create IT0378 record for this person
clear i0378.
i0378-pernr = PA0171-pernr.
i0378-barea = PA0171-barea.
i0378-event = 'OPEN'.
i0378-begda = start_date.
i0378-infty = '0378'.
i0378-aedtm = sy-datum.
i0378-uname = sy-uname.
CALL FUNCTION 'HR_INFOTYPE_OPERATION'
EXPORTING
INFTY = '0378'
NUMBER = i0378-pernr
SUBTYPE = 'OPEN'
VALIDITYBEGIN = i0378-begda
RECORD = i0378
OPERATION = 'INS'
IMPORTING
RETURN = return
EXCEPTIONS
OTHERS = 1.
if sy-subrc ne 0 or return-type ne ' '.
* ERROR HANDLING GOES HERE
endif.
ENDSELECT.
Edited by: Raghunath Shyamala on Feb 25, 2009 6:36 AM