2007 May 18 6:32 AM
Hi Gurus,
Can any one send one sample report for HR Module? Its Very Urgent
Points Will be awarded
Thanks
SC
2007 May 18 6:34 AM
Hi,
----
T A B L E D E C L E R A T I O N
----
TABLES : PERNR, " HR MASTER DATA REPORTING
PA0003. " PAYROLL STATUS.
----
I N F O T Y P E D E C L E R A T I O N
----
INFOTYPES: 0105. "Communication.
----
T Y P E D E C L E R A T I O N
----
**-- Type for data uploading format
TYPES : BEGIN OF T_DATA,
PERNR TYPE PERNR_D, "Personnel number
USRID TYPE SYSID, "Name of Person Who Changed Object
DEL(2), "Delimited data
END OF T_DATA.
**-- Type for checking data
TYPES : BEGIN OF T_STATUS,
PERNR TYPE PERNR_D, "Personnel number
USRID TYPE SYSID, "Name of Person Who Changed Object
DEL(2), "Delimited data
STATUS(20), "Status Message
COMMENTS(40), "Error Report
END OF T_STATUS.
----
I N T E R N A L T A B L E D E C L E R A T I O N *
----
**-- Internal table to store data from the flat file.
DATA : IT_DATA TYPE STANDARD TABLE OF T_DATA WITH HEADER LINE,
**-- Copy of the flat file data for validation
IT_DATA_COPY TYPE STANDARD TABLE OF T_DATA WITH HEADER LINE,
**-- Internal table to store data from the infotypes.
IT_INFOTYPE TYPE STANDARD TABLE OF T_DATA WITH HEADER LINE,
**-- Internal table for Status and Error message report
IT_STATUS TYPE STANDARD TABLE OF T_STATUS WITH HEADER LINE,
**-- Internal table for BDCDATA
IT_BDCDATA TYPE STANDARD TABLE OF BDCDATA WITH HEADER LINE,
**-- Correct Data
IT_CORRECT TYPE STANDARD TABLE OF T_DATA WITH HEADER LINE .
----
W O R K A R E A D E C L E R A T I O N
----
DATA : WA_INFOTYPE TYPE T_DATA.
----
D A T A D E C L E R A T I O N
----
DATA: V_FILE LIKE DYNPREAD-FIELDNAME, "Fieldname in search function
V_PATH TYPE STRING, "Path in charecter type
V_LENGTH TYPE I, "Length of the path string
V_LEN TYPE I, "Pos of char in the path string
V_STRING TYPE STRING, "Last 3 char of path string
V_LINE TYPE I, "Lines
V_COUNT_I TYPE I, "Counter
V_COUNT_C TYPE C LENGTH 5, "Counter charecter type
V_COUNT_I1 TYPE I, "Counter
V_COUNT_C1 TYPE C LENGTH 5, "Counter charecter type
V_FIELDVAL TYPE C LENGTH 25, "Fieldvalue
V_MAT_NUM TYPE C LENGTH 18, "Material Number
V_QTY TYPE C LENGTH 15, "Quantity
V_FLAG TYPE I,
V_SY-TABIX TYPE I,
V_PERNR TYPE PERNR_D,
V_USRID(30).
----
C O N S T A N T S D E C L E R A T I O N
----
**-- Constant with value of text file extension
CONSTANTS: C_TXT TYPE C LENGTH 3 VALUE 'txt',
**-- Constant with value 'X'
C_X TYPE C LENGTH 3 VALUE 'X',
**-- Constant for Mode 'N' Do not display
C_N TYPE C LENGTH 2 VALUE 'N',
**-- Constant for 'S' (ssynchronous update)
C_S TYPE C LENGTH 2 VALUE 'S'.
----
I N I T I A L I Z A T I O N
----
INITIALIZATION.
**-- Clear all internal tables
CLEAR: IT_DATA,
IT_DATA_COPY,
IT_INFOTYPE,
IT_STATUS,
V_FILE,
V_PATH,
V_LENGTH,
V_LEN,
V_STRING,
V_LINE,
V_COUNT_I,
V_COUNT_C,
V_FIELDVAL,
V_FLAG.
**-- Refresh all internal table.
REFRESH : IT_DATA,
IT_DATA_COPY,
IT_INFOTYPE,
IT_STATUS.
----
S E L E C T I O N S C R E E N *
----
**-- File name is in the selection screen. File name is
**-- the file which is to be uploaded
SELECTION-SCREEN BEGIN OF BLOCK 123 WITH FRAME TITLE TEXT-008.
PARAMETERS: PATH LIKE IBIPPARMS-PATH OBLIGATORY,
CHK_BOX AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK 123.
----
A T S E L E C T I O N S C R E E N ( V A L I D A T I O N S ) *
----
**-- On F4 key
AT SELECTION-SCREEN ON VALUE-REQUEST FOR PATH.
**-- Function to fetch the file name from the PC.
PERFORM ZF_SEARCH.
**-- Validation for text file
AT SELECTION-SCREEN.
PERFORM ZF_VALIDATE.
----
S T A R T- O F -S E L E C T I O N
----
START-OF-SELECTION.
GET PERNR.
**-- Fetch data from the infotypes into the internal table
PERFORM Z_DATA_FETCH.
----
E N D O F S E L E C T I O N *
----
END-OF-SELECTION.
*-- File name is passed to the GUI_UPLOAD function and the data from
**-- there is stored in the internal table IT_FINAL.
PERFORM ZF_UPLOAD.
**-- Validate records of the flat file
PERFORM ZF_VALIDATE_RECORDS.
**-- Test Run
PERFORM ZF_TEST_RUN.
**-- Call BDC
PERFORM ZF_BDC.
&----
*& Form ZF_SEARCH
&----
text
----
--> p1 text
<-- p2 text
----
FORM ZF_SEARCH .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
FIELD_NAME = V_FILE
IMPORTING
FILE_NAME = PATH.
ENDFORM. " ZF_SEARCH
&----
*& Form ZF_VALIDATE
&----
text
----
--> p1 text
<-- p2 text
----
FORM ZF_VALIDATE .
V_PATH = PATH.
V_LENGTH = STRLEN( V_PATH ).
V_LEN = V_LENGTH - 3.
V_STRING = V_PATH+V_LEN(3).
IF V_STRING <> C_TXT.
MESSAGE E020.
ENDIF.
ENDFORM. " ZF_VALIDATE
&----
*& Form ZF_UPLOAD
&----
text
----
--> p1 text
<-- p2 text
----
FORM ZF_UPLOAD .
**-- Pass the path name in a variable of charecter type.
V_PATH = PATH.
**-- Function call GUI_UPLOAD
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = V_PATH
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = IT_DATA
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
OTHERS = 17.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IT_DATA_COPY[] = IT_DATA[].
ENDFORM. " ZF_UPLOAD
&----
*& Form Z_DATA_FETCH
&----
text
----
--> p1 text
<-- p2 text
----
&----
Put the employee records from the infotypes into the internal table
through the workarea. Select only those records fall in the specified
date range.
----
FORM Z_DATA_FETCH .
RP-PROVIDE-FROM-LAST P0105 SPACE PN-BEGDA PN-ENDDA.
IF PNP-SW-FOUND = 1.
WA_INFOTYPE-PERNR = P0105-PERNR.
WA_INFOTYPE-USRID = P0105-USRID.
ENDIF.
APPEND WA_INFOTYPE TO IT_INFOTYPE.
CLEAR IT_INFOTYPE.
ENDFORM. " Z_DATA_FETCH
&----
*& Form ZF_VALIDATE_RECORDS
&----
FORM ZF_VALIDATE_RECORDS .
**-- Loop at the internal table containing the data from the flat file,
**-- take one mare internal table which contains the copy of the flat
**-- file data. Sort both the internal table by User Name. Read the
**-- second internal table with key User Name. Compare the index of the
**-- record, if the index is not same mark it as error record in the
**-- status table.
CLEAR : IT_DATA,
IT_DATA_COPY.
REFRESH : IT_STATUS.
SORT IT_DATA BY USRID.
SORT IT_DATA_COPY BY USRID.
LOOP AT IT_DATA.
V_FLAG = 0.
V_SY-TABIX = SY-TABIX.
SELECT SINGLE PERNR
FROM PA0003
INTO V_PERNR
WHERE PERNR = IT_DATA-PERNR.
IF SY-SUBRC <> 0.
V_FLAG = 1.
ENDIF.
READ TABLE IT_DATA_COPY WITH KEY USRID = IT_DATA-USRID
BINARY SEARCH.
IF SY-SUBRC = 0.
IF V_SY-TABIX <> SY-TABIX.
IF IT_DATA-DEL <> 'X'.
V_FLAG = 1.
ENDIF.
ENDIF.
ENDIF.
READ TABLE IT_INFOTYPE WITH KEY USRID = IT_DATA-USRID.
IF SY-SUBRC = 0.
IF IT_DATA-DEL <> 'X'.
V_FLAG = 1.
ENDIF.
ENDIF.
IT_STATUS = IT_DATA.
IF V_FLAG = 1.
IT_STATUS-STATUS = 'ERROR'.
IT_STATUS-COMMENTS = 'User Name exists/Personnel no not present'.
ENDIF.
APPEND IT_STATUS.
CLEAR IT_STATUS.
ENDLOOP.
LOOP AT IT_STATUS.
IF IT_STATUS-STATUS <> 'ERROR'.
IT_CORRECT = IT_STATUS.
APPEND IT_CORRECT.
CLEAR IT_CORRECT.
ENDIF.
ENDLOOP.
ENDFORM. " ZF_VALIDATE_RECORDS
----
Start new screen *
----
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR IT_BDCDATA.
IT_BDCDATA-PROGRAM = PROGRAM.
IT_BDCDATA-DYNPRO = DYNPRO.
IT_BDCDATA-DYNBEGIN = 'X'.
APPEND IT_BDCDATA.
ENDFORM. "BDC_DYNPRO
----
Insert field *
----
FORM BDC_FIELD USING FNAM FVAL.
CLEAR IT_BDCDATA.
IT_BDCDATA-FNAM = FNAM.
IT_BDCDATA-FVAL = FVAL.
APPEND IT_BDCDATA.
ENDFORM. "BDC_FIELD
&----
*& Form ZF_TEST_RUN
&----
text
----
--> p1 text
<-- p2 text
----
FORM ZF_TEST_RUN .
IF CHK_BOX = 'X'.
LOOP AT IT_STATUS.
WRITE:/ IT_STATUS-PERNR,
IT_STATUS-USRID,
IT_STATUS-DEL,
IT_STATUS-STATUS,
IT_STATUS-COMMENTS.
ENDLOOP.
ENDIF.
ENDFORM. " ZF_TEST_RUN
&----
*& Form ZF_BDC
&----
text
----
--> p1 text
<-- p2 text
----
form ZF_BDC .
IF CHK_BOX <> 'X'.
LOOP AT IT_CORRECT.
V_USRID = IT_CORRECT-USRID.
AT NEW PERNR.
perform bdc_dynpro using 'SAPMP50A' '1000'.
perform bdc_field using 'BDC_OKCODE'
'=INS'.
perform bdc_field using 'RP50G-PERNR'
it_correct-pernr.
perform bdc_field using 'RP50G-TIMR6'
'X'.
perform bdc_field using 'BDC_CURSOR'
'RP50G-SUBTY'.
perform bdc_field using 'RP50G-CHOIC'
'105'.
perform bdc_field using 'RP50G-SUBTY'
'0001'.
perform bdc_dynpro using 'MP010500' '2000'.
perform bdc_field using 'BDC_CURSOR'
'P0105-USRID'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
IF IT_CORRECT-DEL = 'X'.
perform bdc_field using 'P0105-ENDDA'
SY-DATUM.
perform bdc_field using 'P0105-ENDDA'
'31.12.9999'.
ENDIF.
perform bdc_field using 'P0105-USRID'
V_USRID.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_DYNPRO USING 'MP010500' '2000'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'P0105-BEGDA'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=UPD'.
IF IT_CORRECT-DEL = 'X'.
PERFORM BDC_FIELD USING 'P0105-ENDDA'
SY-DATUM.
ELSE.
PERFORM BDC_FIELD USING 'P0105-ENDDA'
'31.12.9999'.
ENDIF.
PERFORM BDC_FIELD USING 'P0105-USRID'
V_USRID.
CALL TRANSACTION 'PA30' USING IT_BDCDATA
MODE 'N'
UPDATE C_S.
CLEAR IT_BDCDATA.
REFRESH IT_BDCDATA.
ENDAT.
ENDLOOP.
ENDIF.
endform. " ZF_BDC
******do reward if usefull
Regards,
vijay
2007 May 18 6:38 AM
hi
look at this report , here i m reading data of previous empoyers and i used PNP logical database and aslo have used HR macros.
Reward if helpfull
REPORT ZPPL_PREVEMPLOYERS message-id rp
line-size 250
line-count 65.
*Program logic :- This Report is used to Download all the Previous
* Employer (IT0023) records of the employees
*eject
*&---------------------------------------------------------------------*
*& Tables and Infotypes *
*& *
*&---------------------------------------------------------------------*
tables: pernr.
infotypes: 0000,
0001,
0002,
0023.
*eject
*&---------------------------------------------------------------------*
*& Constants *
*& *
*&---------------------------------------------------------------------*
constants: c_1(1) type c value '1' ,
c_3(1) type c value '3' ,
c_i(1) type c value 'I' ,
c_x(1) type c value 'X' ,
c_eq(2) type c value 'EQ' ,
c_pl03 like p0001-werks value 'PL03'.
*eject
*&---------------------------------------------------------------------*
*& Selection-Screen *
*& *
*&---------------------------------------------------------------------*
parameters: p_file like rlgrap-filename default 'C:TempABC.xls',
p_test as checkbox default c_x .
*eject
*&---------------------------------------------------------------------*
*& Internal tables *
*& *
*&---------------------------------------------------------------------*
* Internal Table for Output
data: begin of t_output occurs 0 ,
pernr like pernr-pernr ,
nachn like p0002-nachn ,
vorna like p0002-vorna ,
orgeh_stext like p1000-stext ,
plans_stext like p1000-stext ,
begda like p0023-begda ,
endda like p0023-endda ,
land1 like p0023-land1 ,
arbgb like p0023-arbgb ,
ort01 like p0023-ort01 .
data: end of t_output .
*eject
*&---------------------------------------------------------------------*
*& Variables *
*& *
*&---------------------------------------------------------------------*
data: o_stext like p1000-stext,
p_stext like p1000-stext.
*eject
*&---------------------------------------------------------------------*
*& Initialization *
*& *
*&---------------------------------------------------------------------*
Initialization.
* Initialize Selection-Screen values
perform init_selction_screen.
*eject
*&---------------------------------------------------------------------*
*& AT Selection-screen *
*& *
*&---------------------------------------------------------------------*
at selection-screen .
* Check if Test run selected, download file name should be entered
if p_test is initial. "
if p_file is initial.
message e016 with 'Please enter file name'
'specifying complete path'.
endif.
endif.
*eject
*&---------------------------------------------------------------------*
*& Start-of Selection *
*& *
*&---------------------------------------------------------------------*
Start-of-selection.
get pernr.
clear t_output.
* Read Infotype 0
rp-provide-from-last p0000 space pn-begda pn-endda.
check pnp-sw-found eq c_1.
* Check if employee is active
check p0000-stat2 in pnpstat2. "pernr Active
* Read Infotype 1
rp-provide-from-last p0001 space pn-begda pn-endda.
check pnp-sw-found eq c_1.
* check if employee belongs to PL03
check p0001-werks in pnpwerks. "belongs to PL03
* Check if emp belongs to Active Group
check p0001-persg in pnppersg.
* Read Infotype 2
rp-provide-from-last p0002 space pn-begda pn-endda.
check pnp-sw-found eq c_1.
* Read Org Unit Text.
CALL FUNCTION 'HR_READ_FOREIGN_OBJECT_TEXT'
EXPORTING
OTYPE = 'O'
objid = p0001-orgeh
begda = p0001-begda
endda = p0001-endda
reference_date = p0001-begda
IMPORTING
object_text = o_stext
EXCEPTIONS
nothing_found = 1
wrong_objecttype = 2
missing_costcenter_data = 3
missing_object_id = 4
OTHERS = 5.
*Read Position Text.
CALL FUNCTION 'HR_READ_FOREIGN_OBJECT_TEXT'
EXPORTING
OTYPE = 'S'
objid = p0001-plans
begda = p0001-begda
endda = p0001-endda
reference_date = p0001-begda
IMPORTING
object_text = p_stext
EXCEPTIONS
nothing_found = 1
wrong_objecttype = 2
missing_costcenter_data = 3
missing_object_id = 4
OTHERS = 5.
* Gather all the required information related to the emp
move: pernr-pernr to t_output-pernr,
o_stext to t_output-orgeh_stext,
p_stext to t_output-plans_stext,
p0002-nachn to t_output-nachn,
p0002-vorna to t_output-vorna.
* Gather previous Employee details
loop at p0023.
move-corresponding p0023 to t_output.
append t_output.
endloop.
*eject
*&---------------------------------------------------------------------*
*& End-of Selection *
*& *
*&---------------------------------------------------------------------*
end-of-selection.
perform print_report.
* Downlaod the file
if not t_output[] is initial.
if p_test eq space.
perform download_file.
endif.
else.
write: 'No records selected' color col_negative.
endif.
*eject
*&---------------------------------------------------------------------*
*& Top-of-page *
*& *
*&---------------------------------------------------------------------*
Top-of-page.
* Print Header
perform print_header.
*eject
*&---------------------------------------------------------------------*
*& Form download_file
*&---------------------------------------------------------------------*
* Description :
*----------------------------------------------------------------------*
FORM download_file .
DATA: full_file_name TYPE string,
z_akt_filesize TYPE i .
full_file_name = p_file.
* download table into file on presentation server
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = full_file_name
filetype = 'DAT'
NO_AUTH_CHECK = c_x
codepage = '1160'
IMPORTING
FILELENGTH = z_akt_filesize
CHANGING
data_tab = t_output[]
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24.
*
IF sy-subrc NE 0.
MESSAGE e016 WITH 'Download-Error; RC:' sy-subrc.
ENDIF.
ENDFORM. " download_file
*eject
*&---------------------------------------------------------------------*
*& Form print_report
*&---------------------------------------------------------------------*
*Description:
*----------------------------------------------------------------------*
FORM print_report .
data: i type i,
w_count type i.
sort t_output.
* Print the report
loop at t_output.
i = sy-tabix mod 2.
if i eq 0.
format color col_normal intensified on.
else.
format color col_normal intensified off.
endif.
write:/1 t_output-pernr ,
10 t_output-vorna(25) ,
35 t_output-nachn(25) ,
61 t_output-orgeh_stext ,
102 t_output-plans_stext ,
143 t_output-begda ,
154 t_output-endda ,
168 t_output-land1 ,
178 t_output-arbgb(40) ,
219 t_output-ort01 ,
249 space .
endloop.
uline.
Describe table t_output lines w_count.
Skip 2.
Write:/ 'Total No of Records Downloaded: ' color col_total,
w_count.
ENDFORM. " print_report
*eject
*&---------------------------------------------------------------------*
*& Form print_header
*&---------------------------------------------------------------------*
*Description:
*----------------------------------------------------------------------*
FORM print_header .
skip 1.
Uline.
format Intensified on color col_heading.
write:/1 'Pers. #' ,
10 'Last Name' ,
35 'First Name' ,
61 'Org Unit' ,
102 'Position' ,
143 'Beg Date' ,
154 'End Date' ,
168 'Cntry Key' ,
178 'Prev Employer' ,
219 'City' ,
249 space .
format intensified off color off.
uline.
ENDFORM. " print_header
*eject
*&---------------------------------------------------------------------*
*& Form init_selction_screen
*&---------------------------------------------------------------------*
*Description:
*----------------------------------------------------------------------*
FORM init_selction_screen .
refresh: pnpwerks,
pnppersg,
pnpstat2.
clear: pnpwerks,
pnppersg,
pnpstat2.
pnpwerks-sign = c_i.
pnpwerks-option = c_EQ.
pnpwerks-low = c_pl03.
append pnpwerks.
pnppersg-sign = c_i.
pnppersg-option = c_EQ.
pnppersg-low = c_1.
append pnppersg.
pnpstat2-sign = c_i.
pnpstat2-option = c_EQ.
pnpstat2-low = c_3.
append pnpstat2.
ENDFORM. " init_selction_screen
2007 May 18 6:43 AM
hi
good
go through this link you ll get a sample HR report
http://www.sap-img.com/abap/sample-hr-reports-allocate-petrol-allowance.htm
thanks
mrutyun^