Google Search - Blog...........

Gosi Calculation Report In HR ABAP

REPORT zhr_gosi_calculation MESSAGE-ID zmsg.

*----------------------------------------------------------------*
* TABLES *
*----------------------------------------------------------------*
TABLES: pa0001,
t569v,
t549a,
t549q.

*-----------------------------------------------------------------*
* T Y P E P O O L S *
*-----------------------------------------------------------------*
TYPE-POOLS : slis.

************************************************************************
* DECLARATION OF INTERNAL TABLES *
************************************************************************


TYPES: BEGIN OF ty_pa0001,
pernr TYPE pa0001-pernr,
bukrs TYPE pa0001-bukrs,
werks TYPE pa0001-werks,
persg TYPE pa0001-persg,
persk TYPE pa0001-persk,
btrtl TYPE pa0001-btrtl,
abkrs TYPE pa0001-abkrs,
ename TYPE char80,
END OF ty_pa0001.

TYPES: BEGIN OF ty_pa0002,
pernr TYPE pa0002-pernr,
vorna TYPE pa0002-vorna,
nachn TYPE pa0002-nachn,
natio TYPE pa0002-natio,
END OF ty_pa0002.

TYPES: BEGIN OF ty_pa0008.
INCLUDE STRUCTURE p0008.
TYPES: END OF ty_pa0008.

DATA: BEGIN OF wagetypes,
lga LIKE p0008-lga01,
bet LIKE p0008-bet01,
END OF wagetypes.

DATA: BEGIN OF dates,
dar LIKE p0041-dar01,
dat LIKE p0041-dat01,
END OF dates.

TYPES: BEGIN OF ty_pa0000,
pernr TYPE pa0000-pernr,
begda TYPE pa0000-begda,
endda TYPE pa0000-endda,
massn TYPE pa0000-massn,
stat2 TYPE p0000-stat2,
END OF ty_pa0000.

TYPES: BEGIN OF ty_t005t,
land1 TYPE t005t-land1,
natio TYPE t005t-natio,
END OF ty_t005t.

DATA: lfs_0008 LIKE p0008.

TYPES: BEGIN OF ty_pa0041.
INCLUDE STRUCTURE p0041.
TYPES: END OF ty_pa0041.

TYPES: BEGIN OF ty_final,
sno type i,
pernr TYPE pa0001-pernr,
ename TYPE pa0001-ename,
begda TYPE pa0001-begda,
endda TYPE pa0001-endda,
bukrs TYPE pa0001-bukrs,
natio TYPE pa0002-natio,
ntext TYPE t005t-natio,
bsal TYPE pa0008-bet01,
hra TYPE pa0008-bet01,
bsal_9 TYPE pa0008-bet01,
bsal_11 TYPE pa0008-bet01,
bsal_2 TYPE pa0008-bet01,
total TYPE pa0008-bet01,
END OF ty_final.


* Work area and Internal tables declaration
DATA: it_pa0000 TYPE TABLE OF ty_pa0000 WITH HEADER LINE,
it_pa0001 TYPE TABLE OF ty_pa0001 WITH HEADER LINE,
it_pa0002 TYPE TABLE OF ty_pa0002 WITH HEADER LINE,
it_pa0008 TYPE TABLE OF ty_pa0008 WITH HEADER LINE,
it_pa0041 TYPE STANDARD TABLE OF ty_pa0041 WITH HEADER LINE,
it_t005t TYPE TABLE OF ty_t005t WITH HEADER LINE,
it_final TYPE TABLE OF ty_final WITH HEADER LINE.

DATA : v_permo TYPE t549a-permo.

DATA: v_pernr TYPE pa0001-pernr,
v_werks TYPE pa0001-werks,
v_btrtl TYPE pa0001-btrtl,
v_persg TYPE pa0001-persg,
v_persk TYPE pa0001-persk,
v_abkrs TYPE pa0001-abkrs.

data: sno type i.

*For ALV fieldcatlog
DATA : it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
it_layout TYPE slis_layout_alv,
it_events TYPE slis_t_event,
wa_events TYPE slis_alv_event,
it_list TYPE slis_t_listheader WITH HEADER LINE.

RANGES: r_stat2 FOR pa0000-stat2.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-002.

select-options: s_abkrs for pa0001-abkrs no intervals obligatory.

*PARAMETERS:p_abkrs TYPE pa0001-abkrs .

PARAMETERS: p_pabrp TYPE t569v-pabrp,
p_pabrj TYPE t569v-pabrj,
p_begda TYPE pa0001-begda,
p_endda TYPE pa0001-endda.

PARAMETERS: r1 RADIOBUTTON GROUP g1 DEFAULT 'X' USER-COMMAND aaa,
r2 RADIOBUTTON GROUP g1.

SELECTION-SCREEN END OF BLOCK b3.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-003.
SELECT-OPTIONS: s_pernr FOR pa0001-pernr,
s_werks FOR pa0001-werks, "Personnel Area
s_btrtl FOR pa0001-btrtl, "Personnel Subarea
s_persg FOR pa0001-persg, "Employee Group
s_persk FOR pa0001-persk. "Employee Subgroup
SELECTION-SCREEN END OF BLOCK b2 .
SELECTION-SCREEN END OF BLOCK b1 .

************************************************************************
* AT SELECTION SCREEN *
************************************************************************
AT SELECTION-SCREEN.

IF NOT s_pernr[] IS INITIAL.
SELECT pernr
FROM pa0001
INTO v_pernr
WHERE pernr IN s_pernr.
IF sy-subrc NE 0.
MESSAGE e000 WITH 'Enter a valid Personnel Number'.
ENDIF.
ENDSELECT.
ENDIF.

IF NOT s_werks[] IS INITIAL.
SELECT werks
FROM pa0001
INTO v_werks
WHERE pernr IN s_werks.
IF sy-subrc NE 0.
MESSAGE e000 WITH 'Enter a valid Personnel Area'.
ENDIF.
ENDSELECT.
ENDIF.

IF NOT s_btrtl[] IS INITIAL.
SELECT btrtl
FROM pa0001
INTO v_btrtl
WHERE pernr IN s_btrtl.
IF sy-subrc NE 0.
MESSAGE e000 WITH 'Enter a valid Personnel Subarea'.
ENDIF.
ENDSELECT.
ENDIF.

IF NOT s_persg[] IS INITIAL.
SELECT persg
FROM pa0001
INTO v_persg
WHERE pernr IN s_persg.
IF sy-subrc NE 0.
MESSAGE e000 WITH 'Enter a valid Employee Group'.
ENDIF.
ENDSELECT.
ENDIF.

IF NOT s_persk[] IS INITIAL.
SELECT persk
FROM pa0001
INTO v_persk
WHERE pernr IN s_persk.
IF sy-subrc NE 0.
MESSAGE e000 WITH 'Enter a valid Employee Subgroup'.
ENDIF.
ENDSELECT.
ENDIF.


AT SELECTION-SCREEN OUTPUT.

IF r1 = 'X'.

PERFORM get_data_from_current_period.

LOOP AT SCREEN.

IF screen-name = 'P_PABRP'
OR screen-name = 'P_PABRJ'
OR screen-name = 'P_BEGDA'
OR screen-name = 'P_ENDDA'.
screen-input = 0.
ENDIF.
MODIFY SCREEN.

ENDLOOP.

ELSEIF r2 = 'X'.


PERFORM get_data_from_period.


LOOP AT SCREEN.
IF screen-name = 'P_BEGDA'
OR screen-name = 'P_ENDDA'.
screen-input = 0.
ENDIF.

MODIFY SCREEN.

ENDLOOP.

ENDIF.

START-OF-SELECTION.

PERFORM get_pa0000_data.

PERFORM get_pa0001_data.

PERFORM get_pa0002_data.

PERFORM get_pa0008_data.

PERFORM get_pa0041_data.

END-OF-SELECTION.

PERFORM process_data.

PERFORM display_alv.
*&---------------------------------------------------------------------*
*& Form GET_PA0001_DATA
*----------------------------------------------------------------------*
FORM get_pa0001_data .

SELECT pernr
bukrs
werks
persg
persk
btrtl
abkrs
FROM pa0001
INTO TABLE it_pa0001
FOR ALL ENTRIES IN it_pa0000
WHERE pernr = it_pa0000-pernr
AND werks IN s_werks
AND btrtl IN s_btrtl
AND persg IN s_persg
AND persk IN s_persk
and abkrs in s_abkrs
AND begda LE p_endda
AND endda GE p_begda.

IF sy-subrc = 0.
SORT it_pa0001 BY pernr.
delete adjacent duplicates from it_pa0001 comparing pernr.
ENDIF.

ENDFORM. " GET_PA0001_DATA
*&---------------------------------------------------------------------*
*& Form GET_PA0002_DATA
*----------------------------------------------------------------------*
FORM get_pa0002_data .

SELECT pernr
vorna
nachn
natio
FROM pa0002
INTO TABLE it_pa0002
FOR ALL ENTRIES IN it_pa0001
WHERE pernr = it_pa0001-pernr
AND begda LE p_endda
AND endda GE p_begda.


IF sy-subrc = 0.
SORT it_pa0002 BY pernr.
ENDIF.

SELECT land1
natio
FROM t005t
INTO TABLE it_t005t
FOR ALL ENTRIES IN it_pa0002
WHERE land1 = it_pa0002-natio
AND spras = 'E'.

IF sy-subrc = 0.
SORT it_t005t BY natio.
ENDIF.

ENDFORM. " GET_PA0002_DATA
*&---------------------------------------------------------------------*
*& Form GET_PA0008_DATA
*----------------------------------------------------------------------*
FORM get_pa0008_data .

SELECT *
FROM pa0008
INTO CORRESPONDING FIELDS OF TABLE it_pa0008
FOR ALL ENTRIES IN it_pa0001
WHERE pernr = it_pa0001-pernr
AND begda LE p_endda
AND endda GE p_begda.


IF sy-subrc = 0.
SORT it_pa0008 BY pernr.
ENDIF.

ENDFORM. " GET_PA0008_DATA
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*----------------------------------------------------------------------*
FORM process_data .

LOOP AT it_pa0001.

it_final-pernr = it_pa0001-pernr.
it_final-bukrs = it_pa0001-bukrs.

READ TABLE it_pa0002 WITH KEY pernr = it_pa0001-pernr.
IF sy-subrc = 0.
it_final-natio = it_pa0002-natio.
CONCATENATE it_pa0002-vorna it_pa0002-nachn INTO it_final-ename.

READ TABLE it_t005t WITH KEY land1 = it_pa0002-natio.
IF sy-subrc = 0.
it_final-ntext = it_t005t-natio.
ENDIF.

ENDIF.

READ TABLE it_pa0008 WITH KEY pernr = it_pa0001-pernr.
IF sy-subrc = 0.
CLEAR : lfs_0008.

MOVE-CORRESPONDING it_pa0008 TO lfs_0008.

DO 40 TIMES VARYING wagetypes-lga FROM lfs_0008-lga01 NEXT lfs_0008-lga02
VARYING wagetypes-bet FROM lfs_0008-bet01 NEXT lfs_0008-bet02.

CHECK wagetypes-lga IS NOT INITIAL.

CASE wagetypes-lga.

WHEN '1000'.
it_final-bsal = wagetypes-bet . " Basic
WHEN '1010'.
it_final-hra = wagetypes-bet . " HRA
ENDCASE.
ENDDO.
ENDIF.

READ TABLE it_pa0041 WITH KEY pernr = it_pa0001-pernr.
IF sy-subrc = 0.

DO 12 TIMES VARYING dates-dar FROM it_pa0041-dar01 NEXT it_pa0041-dar02
VARYING dates-dat FROM it_pa0041-dat01 NEXT it_pa0041-dat02.

CHECK dates-dar IS NOT INITIAL.

IF dates-dar = '01'.
it_final-begda = dates-dat.
ENDIF.
ENDDO.
ENDIF.

LOOP AT it_pa0000 WHERE pernr = it_pa0001-pernr.
IF it_pa0000-massn = 'Z6' OR it_pa0000-massn = 'Z7' OR it_pa0000-massn = '10'.
it_final-endda = it_pa0000-begda.
EXIT.
ENDIF.
ENDLOOP.

IF it_pa0001-persg = 'S'.
it_final-bsal_9 = ( it_final-bsal + it_final-hra ) * 9 / 100 .
it_final-bsal_11 = ( it_final-bsal + it_final-hra ) * 11 / 100 .
ELSEIF it_pa0001-persg = 'E'.
it_final-bsal_2 = ( it_final-bsal + it_final-hra ) * 2 / 100 .
ENDIF.

it_final-total = it_final-bsal_9 + it_final-bsal_11 + it_final-bsal_2.

sno = sno + 1.

it_final-sno = sno.

APPEND it_final.
CLEAR it_final.
ENDLOOP.


ENDFORM. " PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV
*----------------------------------------------------------------------*
FORM display_alv .

wa_fieldcat-fieldname = 'SNO'.
wa_fieldcat-reptext_ddic = 'Serial No'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'ENAME'.
wa_fieldcat-reptext_ddic = 'Employee Name'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'BUKRS'.
wa_fieldcat-just = 'C'.
wa_fieldcat-reptext_ddic = 'Company Code'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'PERNR'.
wa_fieldcat-reptext_ddic = 'Personnel Number'.
wa_fieldcat-just = 'C'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'BEGDA'.
wa_fieldcat-reptext_ddic = 'Joining Date'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'NTEXT'.
wa_fieldcat-reptext_ddic = 'Nationality'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'BSAL'.
wa_fieldcat-reptext_ddic = 'Basic Salary'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'HRA'.
wa_fieldcat-reptext_ddic = 'Housing'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'BSAL_9'.
wa_fieldcat-reptext_ddic = 'Gosi Amount 9%'.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'BSAL_11'.
wa_fieldcat-reptext_ddic = 'Gosi Amount 11%'.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'BSAL_2'.
wa_fieldcat-reptext_ddic = 'Gosi Amount 2%'.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'TOTAL'.
wa_fieldcat-reptext_ddic = 'Total Gosi Amount'.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

it_layout-colwidth_optimize = 'X'.
it_layout-zebra = 'X'.

*---top of page for the first block
wa_events-name = 'TOP_OF_PAGE'.
wa_events-form = 'TOP_OF_PAGE'.
APPEND wa_events TO it_events.
CLEAR wa_events.


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = it_layout
it_fieldcat = it_fieldcat
it_events = it_events
TABLES
t_outtab = it_final
EXCEPTIONS
program_error = 1
OTHERS = 2.

ENDFORM. " DISPLAY_ALV

*&---------------------------------------------------------------------*
*& Form top_of_page
*----------------------------------------------------------------------*
FORM top_of_page. "#EC CALLED

*------form header

REFRESH it_list.
CLEAR it_list.

CLEAR it_list.
it_list-typ = 'H'.
it_list-key = space.
it_list-info = 'Employees Gosi Calculations Report'.
APPEND it_list TO it_list.

****** REPORT PROGRAM NAME AND CLIENT ****************
it_list-typ = 'S'.
it_list-key = space.
CONCATENATE 'Report...:' sy-repid INTO it_list-info SEPARATED BY space.
APPEND it_list TO it_list.

****** USER NAME *************************************
CLEAR it_list.
it_list-typ = 'S'.
it_list-key = space.
CONCATENATE 'User.....:' sy-uname INTO it_list-info SEPARATED BY space.
APPEND it_list TO it_list.

****** DATE / TIME STAMP *****************************
CLEAR it_list.
it_list-typ = 'S'.
it_list-key = space.
CONCATENATE 'Date/Time:' sy-datum+6(2) '/'
sy-datum+4(2) '/'
sy-datum+0(4) ' '
sy-uzeit+0(2) ':'
sy-uzeit+2(2) ':'
sy-uzeit+4(2)
INTO it_list-info SEPARATED BY space.
APPEND it_list TO it_list.

clear it_list.
it_list-typ = 'S'.
it_list-key = space.
concatenate 'Payroll Area:' s_abkrs-low into it_list-info separated by space.
append it_list to it_list.

it_list-typ = 'S'.
it_list-key = space.
concatenate 'Payroll Period:' p_begda+4(2) '.' p_begda+6(2) '.' p_begda+0(4) ' ' '-' ' '
p_endda+4(2) '.' p_endda+6(2) '.' p_endda+0(4) into it_list-info.
append it_list to it_list.

*--- Get the comments on the top of page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_list[].

ENDFORM. "top_of_page
*&---------------------------------------------------------------------*
*& Form GET_PA0000_DATA
*----------------------------------------------------------------------*
FORM get_pa0000_data .

SELECT pernr
begda
endda
massn
stat2
FROM pa0000
INTO TABLE it_pa0000
WHERE pernr IN s_pernr
AND begda LE p_endda
AND endda GE p_begda
and stat2 = '3'.

IF sy-subrc = 0.
SORT it_pa0000 BY pernr.
ENDIF.

ENDFORM. " GET_PA0000_DATA
*&---------------------------------------------------------------------*
*& Form GET_PA0041_DATA
*----------------------------------------------------------------------*
FORM get_pa0041_data .

SELECT *
FROM pa0041
INTO CORRESPONDING FIELDS OF TABLE it_pa0041
FOR ALL ENTRIES IN it_pa0000
WHERE pernr = it_pa0000-pernr
AND begda LE p_endda
AND endda GE p_begda.


IF NOT it_pa0041[] IS INITIAL.
SORT it_pa0041 BY pernr.
ENDIF.
ENDFORM. " GET_PA0041_DATA
*&---------------------------------------------------------------------*
*& Form GET_DATA_FROM_CURRENT_PERIOD
*----------------------------------------------------------------------*
FORM get_data_from_current_period .

SELECT SINGLE * FROM t569v
WHERE abkrs = s_abkrs-low
AND vwsaz = '01'.
IF sy-subrc = 0.
p_pabrp = t569v-pabrp.
p_pabrj = t569v-pabrj.
ENDIF.

SELECT SINGLE * FROM t549a WHERE abkrs = s_abkrs-low.
IF sy-subrc = 0.
v_permo = t549a-permo.
ELSE.
IF r2 = 'X'.
MESSAGE e000 WITH 'Enter a valid Payroll Period'.
ENDIF.

ENDIF.

SELECT SINGLE * FROM t549q WHERE permo = v_permo
AND pabrj = t569v-pabrj
AND pabrp = t569v-pabrp.
IF sy-subrc = 0.
p_begda = t549q-begda.
p_endda = t549q-endda.
ENDIF.

ENDFORM. " GET_DATA_FROM_CURRENT_PERIOD
*&---------------------------------------------------------------------*
*& Form GET_DATA_FROM_PERIOD
*----------------------------------------------------------------------*
FORM get_data_from_period .

SELECT SINGLE * FROM t549a WHERE abkrs = s_abkrs-low.
v_permo = t549a-permo.

SELECT SINGLE * FROM t549q WHERE permo = v_permo
AND pabrj = p_pabrj
AND pabrp = p_pabrp.


IF sy-subrc = 0.
p_begda = t549q-begda.
p_endda = t549q-endda.
ENDIF.

ENDFORM. " GET_DATA_FROM_PERIOD


ALSO READ:

- Employee Pay Details Report In HR ABAP.

- Employee Existence Check Report.

- Send Employee Payslip As An E-Mail Attachment.

- Time Quota For An Employee In HR ABAP.

- Employee Deduction Report In HR ABAP.

.....Back To Sub-Index On HR ABAP.

.....Back To MAIN INDEX.


No comments:

Post a Comment