2008 Nov 05 10:24 PM
function hr_ben_get_plan_cost.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(EE_BENEFIT_DATA) LIKE RPBENEEDAT STRUCTURE RPBENEEDAT
*" VALUE(BPLAN) LIKE T5UBA-BPLAN
*" VALUE(BCOST) LIKE T5UBH-BCOST
*" VALUE(DATUM) LIKE SY-DATUM
*" VALUE(COVER) LIKE T74FC-COVAM DEFAULT 0
*" VALUE(OUT_CURRE) LIKE T5UD3-CURRE
*" VALUE(OUT_PERIOD) LIKE T5UBH-PERIO
*" VALUE(PERIO_DATE) LIKE T549Q-BEGDA OPTIONAL
*" VALUE(IS_COBRA) TYPE C DEFAULT ' '
*" VALUE(REACTION) LIKE SY-MSGTY
*" EXPORTING
*" VALUE(EECST) LIKE T5UBI-EECST
*" VALUE(PTCST) LIKE T5UBI-PTCST
*" VALUE(ERCST) LIKE T5UBI-ERCST
*" VALUE(ACCST) LIKE T5UBI-ACCST
*" VALUE(IMINC) LIKE T5UBI-IMINC
*" VALUE(FLXCR) LIKE T5UBA-FLXCR
*" VALUE(SUBRC) LIKE SY-SUBRC
*" TABLES
*" ERROR_TABLE STRUCTURE RPBENERR
I'm not sure what to pass to the following parameters:
DATUM
OUT_CURRE
OUT_PERIOD
PERIO-DATE
Your assistance is greatly appreciated!
2008 Nov 07 3:03 PM
Hello,
You can use the FM like example below:
&----
*& Report YRA_HEALTH_PLAN_DETAILS
*&
&----
*&
*&
&----
report yra_health_plan_details no standard page heading line-size 255..
**----
Type-pools declarations
type-pools: slis.
**----
Declare the Logical Database Node ( Pernr )
tables: pernr,
t500p,
t529u,
t501t,
q0167,
t5ubb, "Benefit health option/dependent coverage assignment
rpbeneedat. "Benefit reference structure for function modules
**----
Mention the various infotypes to be used .
infotypes: 0000,
0001,
0002,
0008,
0041,
0167.
**----
Declare the Structures
types: begin of t_final, "Structure for final Alv display
pernr type pernr_d, "Employee id
nachn type pad_nachn, "Last name
vorna type pad_vorna, "First name
perid type prdni, "Social Security Number
name1 type pbtxt, "Personal Area
kostl type kostl, "Cost Center
text1 type text40, "Employment Status
ptext type pgtxt, "Employee Group
divgv type divgv, "Working Hours
gbdat type gbdat, "Birth Date
dat01 type dardt, "Hire Date
dat02 type dardt, "Re Hire Date
pltyp type ben_type, "Benefit Plan Type
bplan type ben_plan, "Benefit Plan
depcv type ben_depcov, "Dependent Coverage
eecst type ben_eecost, "Benefit Employee Cost Amount
ptcst type ben_ptcst, "Benefits Additional Employee Post-Tax Costs
iminc type ben_iminc, "Benefits Imputed Income
end of t_final.
data: ee_benefit_data like rpbeneedat,
error_table like rpbenerr occurs 0,
h5ubb like t5ubb,
subrc like sy-subrc.
constants: no_msg type sy-msgty value 'N',
error_msg type sy-msgty value 'E'. .
**----
Declare the internal tables
data: t_data type standard table of t_final with header line, " Output Internal Table
s_data type t_final. " Workarea for output itab
data : fieldcatalog type slis_t_fieldcat_alv with header line, "Fieldcatalog itab
i_fieldcatalog type slis_fieldcat_alv, " Fieldcatalog header
i_event type slis_t_event, " table for events
t_event type slis_alv_event, " structure for events
i_header type slis_t_listheader, " FOR HEADER
t_header type slis_listheader.
**----
Declare Variables
data: v_repid type sy-repid.
**----
I N I T I A L I Z A T I O N
v_repid = sy-repid.
*----
START OF SELECTION
start-of-selection.
get pernr.
rp-provide-from-last p0000 space pn-begda pn-endda.
if p0000-stat2 ne '3'. " Process only active employees
reject.
endif.
rp-provide-from-last p0001 space pn-begda pn-endda.
if pnp-sw-found = 1.
s_data-pernr = p0001-pernr.
s_data-kostl = p0001-kostl.
endif.
rp-provide-from-last p0002 space pn-begda pn-endda.
if pnp-sw-found = 1.
s_data-nachn = p0002-nachn.
s_data-vorna = p0002-vorna.
s_data-perid = p0002-perid.
s_data-gbdat = p0002-gbdat.
endif.
select single name1 from t500p into s_data-name1 where persa = p0001-werks.
select single text1 from t529u into s_data-text1 where statn = 2 and statv = p0000-stat2.
select single ptext from t501t into s_data-ptext where persg = p0001-persg.
rp-provide-from-last p0008 space pn-begda pn-endda.
if pnp-sw-found = 1.
s_data-divgv = p0008-divgv.
endif.
rp-provide-from-last p0041 space pn-begda pn-endda.
if pnp-sw-found = 1.
s_data-dat01 = p0041-dat01.
s_data-dat02 = p0041-dat02.
endif.
rp-provide-from-last p0167 space pn-begda pn-endda.
if pnp-sw-found = 1.
s_data-begda = p0167-begda.
s_data-endda = p0167-endda.
s_data-pltyp = p0167-pltyp.
s_data-bplan = p0167-bplan.
s_data-depcv = p0167-depcv.
endif.
form dynpro_fields.
data: eeper like q0167-eeper. .
get cost date
if q0167-cstdt is initial.
call function 'HR_BEN_GET_KEY_DATE'
exporting
begda = p0167-begda
endda = p0167-endda
reaction = no_msg
importing
keydt = q0167-cstdt
tables
error_table = error_table.
else.
if q0167-cstdt < p0167-begda.
q0167-cstdt = p0167-begda.
endif.
if q0167-cstdt > p0167-endda.
q0167-cstdt = p0167-endda.
endif.
endif.
*
get employees pay frequency
call function 'HR_BEN_GET_PLAN_PERIOD'
exporting
pernr = p0167-pernr
barea = p0167-barea
bplan = p0167-bplan
validity_date = q0167-cstdt
reaction = no_msg
importing
plan_period = eeper
subrc = subrc
tables
error_table = error_table.
get currency for calculated amounts
call function 'HR_BEN_GET_CURRENCY'
exporting
barea = p0167-barea
datum = q0167-cstdt
reaction = no_msg
importing
currency = q0167-curr1
subrc = subrc
tables
error_table = error_table.
move q0167-curr1 to q0167-curr2.
move q0167-curr1 to q0167-curr3.
move q0167-curr1 to q0167-curr6.
move q0167-curr1 to q0167-curr7.
*
get cost formula
perform re5ubb(sapfben0) tables error_table
using p0167-barea
p0167-bplan
p0167-bopti
p0167-depcv
q0167-cstdt
no_msg
changing h5ubb
subrc.
*
calculate benefit cost
call function 'HR_BEN_GET_PLAN_COST'
exporting
ee_benefit_data = ee_benefit_data
bplan = p0167-bplan
bcost = h5ubb-bcost
datum = q0167-cstdt
out_period = q0167-eeper
out_curre = q0167-curr1
reaction = no_msg
importing
eecst = q0167-eecst
ptcst = q0167-ptcst
ercst = q0167-ercst
accst = q0167-accst
iminc = q0167-iminc
flxcr = q0167-flxcr
subrc = subrc
tables
error_table = error_table.
s_data-eecst = q0167-eecst.
s_data-ptcst = q0167-ptcst.
s_data-iminc = q0167-iminc.
append s_data to t_data.
clear s_data.
ENDIF.
end-of-selection.
PERFORM download.
perform alv_display.
&----
*& Form ALV_DISPLAY
&----
text
----
--> p1 text
<-- p2 text
----
form alv_display .
IF t_data IS NOT INITIAL.
perform build_fieldcatalog.
perform event_cat using i_event.
perform define_alv.
ENDIF.
endform. " ALV_DISPLAY
&----
*& Form event_cat
&----
text
----
-->P_I_EVENT text
----
form event_cat using p_i_event type slis_t_event.
refresh p_i_event.
data : s_i_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
importing
et_events = p_i_event.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
read table p_i_event with key name = slis_ev_top_of_page into t_event.
if sy-subrc = 0.
move 'TOP_OF_PAGE' to t_event-form.
modify p_i_event from t_event index sy-tabix transporting form.
endif.
endform. " event_cat
&----
*& Form build_fieldcatalog
&----
text
----
--> p1 text
<-- p2 text
----
form build_fieldcatalog .
define m_fieldcat.
clear i_fieldcatalog.
i_fieldcatalog-tabname = 'T_DATA'.
i_fieldcatalog-fieldname = &1.
i_fieldcatalog-just = 'L'.
i_fieldcatalog-outputlen = &2.
i_fieldcatalog-seltext_l = &3.
I_FIELDCATALOG-COL_POS = &4.
append i_fieldcatalog to fieldcatalog.
clear i_fieldcatalog.
end-of-definition.
m_fieldcat: 'PERNR' '08' 'Personnel No'.
m_fieldcat: 'NACHN' '40' 'Last Name' .
m_fieldcat: 'VORNA' '40' 'First name' .
m_fieldcat: 'PERID' '20' 'Social Security No.' .
m_fieldcat: 'NAME1' '30' 'Personal Area ' .
m_fieldcat: 'KOSTL' '10' 'Cost Center' .
m_fieldcat: 'TEXT1' '20' 'Employment Status'.
m_fieldcat: 'PTEXT' '20' 'Employment Group' .
m_fieldcat: 'DIVGV' '04' 'Working Hours'.
m_fieldcat: 'GBDAT' '08' 'Birthdate' .
m_fieldcat: 'DAT01' '08' 'Hire Date' .
m_fieldcat: 'DAT02' '08' 'Re-Hire Date' .
m_fieldcat: 'PLTYP' '04' 'Plan Type' .
m_fieldcat: 'BPLAN' '04' 'Benefit Plan'.
m_fieldcat: 'DEPCV' '10' 'Dependent Coverage' .
m_fieldcat: 'EECST' '10' 'Benefit Employee Cost Amount'.
m_fieldcat: 'PTCST' '10' 'Benefits Additional Employee Post-Tax Costs'.
m_fieldcat: 'IMINC' '10' 'Benefits Imputed Income' .
endform. " build_fieldcatalog
&----
*& Form define_alv
&----
text
----
form define_alv.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
I_CALLBACK_TOP_OF_PAGE = ' '
I_GRID_TITLE =
IS_LAYOUT =
it_fieldcat = fieldcatalog[]
it_events = i_event[]
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
tables
t_outtab = t_data
exceptions
program_error = 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.
endform. " define_alv
&----
*& Form TOP_OF_PAGE
&----
text
----
form top_of_page .
LIST HEADING LINE: TYPE H
clear t_header.
t_header-typ = 'H'.
t_header-info = 'Health Plan Details'.
append t_header to i_header.
STATUS LINE: TYPE S
clear t_header.
t_header-typ = 'S'.
t_header-key = 'Date Of Run'.
t_header-info = sy-datum.
append t_header to i_header.
ACTION LINE: TYPE A
clear t_header.
t_header-typ = 'A'.
LS_LINE-KEY: NOT USED FOR THIS TYPE
t_header-info = text-002.
append t_header to i_header.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = i_header
I_LOGO =
I_END_OF_LIST_GRID =
.
endform. "TOP_OF_PAGE
Hope it helps.
Thanks,
Jayant Sahu.
2008 Nov 07 5:27 AM
Hello,
Check this
get currency for calculated amounts
call function 'HR_BEN_GET_CURRENCY'
exporting
barea = p0167-barea
datum = q0167-cstdt
reaction = no_msg
importing
currency = q0167-curr1
subrc = subrc
tables
error_table = error_table.
move q0167-curr1 to q0167-curr2.
move q0167-curr1 to q0167-curr3.
move q0167-curr1 to q0167-curr6.
move q0167-curr1 to q0167-curr7.
call function 'HR_BEN_GET_PLAN_COST'
exporting
ee_benefit_data = ee_benefit_data
bplan = p0167-bplan
bcost = h5ubb-bcost
datum = q0167-cstdt
out_period = q0167-eeper
out_curre = q0167-curr1
reaction = no_msg
importing
eecst = q0167-eecst
ptcst = q0167-ptcst
ercst = q0167-ercst
accst = q0167-accst
iminc = q0167-iminc
flxcr = q0167-flxcr
subrc = subrc
tables
error_table = error_table.
2008 Nov 07 2:48 PM
Santosh:
Thank you for the reply. May I ask about the data object "q0167"? Of what type is this data object and from where did it originate?
Thanks.
2008 Nov 07 3:03 PM
Hello,
You can use the FM like example below:
&----
*& Report YRA_HEALTH_PLAN_DETAILS
*&
&----
*&
*&
&----
report yra_health_plan_details no standard page heading line-size 255..
**----
Type-pools declarations
type-pools: slis.
**----
Declare the Logical Database Node ( Pernr )
tables: pernr,
t500p,
t529u,
t501t,
q0167,
t5ubb, "Benefit health option/dependent coverage assignment
rpbeneedat. "Benefit reference structure for function modules
**----
Mention the various infotypes to be used .
infotypes: 0000,
0001,
0002,
0008,
0041,
0167.
**----
Declare the Structures
types: begin of t_final, "Structure for final Alv display
pernr type pernr_d, "Employee id
nachn type pad_nachn, "Last name
vorna type pad_vorna, "First name
perid type prdni, "Social Security Number
name1 type pbtxt, "Personal Area
kostl type kostl, "Cost Center
text1 type text40, "Employment Status
ptext type pgtxt, "Employee Group
divgv type divgv, "Working Hours
gbdat type gbdat, "Birth Date
dat01 type dardt, "Hire Date
dat02 type dardt, "Re Hire Date
pltyp type ben_type, "Benefit Plan Type
bplan type ben_plan, "Benefit Plan
depcv type ben_depcov, "Dependent Coverage
eecst type ben_eecost, "Benefit Employee Cost Amount
ptcst type ben_ptcst, "Benefits Additional Employee Post-Tax Costs
iminc type ben_iminc, "Benefits Imputed Income
end of t_final.
data: ee_benefit_data like rpbeneedat,
error_table like rpbenerr occurs 0,
h5ubb like t5ubb,
subrc like sy-subrc.
constants: no_msg type sy-msgty value 'N',
error_msg type sy-msgty value 'E'. .
**----
Declare the internal tables
data: t_data type standard table of t_final with header line, " Output Internal Table
s_data type t_final. " Workarea for output itab
data : fieldcatalog type slis_t_fieldcat_alv with header line, "Fieldcatalog itab
i_fieldcatalog type slis_fieldcat_alv, " Fieldcatalog header
i_event type slis_t_event, " table for events
t_event type slis_alv_event, " structure for events
i_header type slis_t_listheader, " FOR HEADER
t_header type slis_listheader.
**----
Declare Variables
data: v_repid type sy-repid.
**----
I N I T I A L I Z A T I O N
v_repid = sy-repid.
*----
START OF SELECTION
start-of-selection.
get pernr.
rp-provide-from-last p0000 space pn-begda pn-endda.
if p0000-stat2 ne '3'. " Process only active employees
reject.
endif.
rp-provide-from-last p0001 space pn-begda pn-endda.
if pnp-sw-found = 1.
s_data-pernr = p0001-pernr.
s_data-kostl = p0001-kostl.
endif.
rp-provide-from-last p0002 space pn-begda pn-endda.
if pnp-sw-found = 1.
s_data-nachn = p0002-nachn.
s_data-vorna = p0002-vorna.
s_data-perid = p0002-perid.
s_data-gbdat = p0002-gbdat.
endif.
select single name1 from t500p into s_data-name1 where persa = p0001-werks.
select single text1 from t529u into s_data-text1 where statn = 2 and statv = p0000-stat2.
select single ptext from t501t into s_data-ptext where persg = p0001-persg.
rp-provide-from-last p0008 space pn-begda pn-endda.
if pnp-sw-found = 1.
s_data-divgv = p0008-divgv.
endif.
rp-provide-from-last p0041 space pn-begda pn-endda.
if pnp-sw-found = 1.
s_data-dat01 = p0041-dat01.
s_data-dat02 = p0041-dat02.
endif.
rp-provide-from-last p0167 space pn-begda pn-endda.
if pnp-sw-found = 1.
s_data-begda = p0167-begda.
s_data-endda = p0167-endda.
s_data-pltyp = p0167-pltyp.
s_data-bplan = p0167-bplan.
s_data-depcv = p0167-depcv.
endif.
form dynpro_fields.
data: eeper like q0167-eeper. .
get cost date
if q0167-cstdt is initial.
call function 'HR_BEN_GET_KEY_DATE'
exporting
begda = p0167-begda
endda = p0167-endda
reaction = no_msg
importing
keydt = q0167-cstdt
tables
error_table = error_table.
else.
if q0167-cstdt < p0167-begda.
q0167-cstdt = p0167-begda.
endif.
if q0167-cstdt > p0167-endda.
q0167-cstdt = p0167-endda.
endif.
endif.
*
get employees pay frequency
call function 'HR_BEN_GET_PLAN_PERIOD'
exporting
pernr = p0167-pernr
barea = p0167-barea
bplan = p0167-bplan
validity_date = q0167-cstdt
reaction = no_msg
importing
plan_period = eeper
subrc = subrc
tables
error_table = error_table.
get currency for calculated amounts
call function 'HR_BEN_GET_CURRENCY'
exporting
barea = p0167-barea
datum = q0167-cstdt
reaction = no_msg
importing
currency = q0167-curr1
subrc = subrc
tables
error_table = error_table.
move q0167-curr1 to q0167-curr2.
move q0167-curr1 to q0167-curr3.
move q0167-curr1 to q0167-curr6.
move q0167-curr1 to q0167-curr7.
*
get cost formula
perform re5ubb(sapfben0) tables error_table
using p0167-barea
p0167-bplan
p0167-bopti
p0167-depcv
q0167-cstdt
no_msg
changing h5ubb
subrc.
*
calculate benefit cost
call function 'HR_BEN_GET_PLAN_COST'
exporting
ee_benefit_data = ee_benefit_data
bplan = p0167-bplan
bcost = h5ubb-bcost
datum = q0167-cstdt
out_period = q0167-eeper
out_curre = q0167-curr1
reaction = no_msg
importing
eecst = q0167-eecst
ptcst = q0167-ptcst
ercst = q0167-ercst
accst = q0167-accst
iminc = q0167-iminc
flxcr = q0167-flxcr
subrc = subrc
tables
error_table = error_table.
s_data-eecst = q0167-eecst.
s_data-ptcst = q0167-ptcst.
s_data-iminc = q0167-iminc.
append s_data to t_data.
clear s_data.
ENDIF.
end-of-selection.
PERFORM download.
perform alv_display.
&----
*& Form ALV_DISPLAY
&----
text
----
--> p1 text
<-- p2 text
----
form alv_display .
IF t_data IS NOT INITIAL.
perform build_fieldcatalog.
perform event_cat using i_event.
perform define_alv.
ENDIF.
endform. " ALV_DISPLAY
&----
*& Form event_cat
&----
text
----
-->P_I_EVENT text
----
form event_cat using p_i_event type slis_t_event.
refresh p_i_event.
data : s_i_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
importing
et_events = p_i_event.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
read table p_i_event with key name = slis_ev_top_of_page into t_event.
if sy-subrc = 0.
move 'TOP_OF_PAGE' to t_event-form.
modify p_i_event from t_event index sy-tabix transporting form.
endif.
endform. " event_cat
&----
*& Form build_fieldcatalog
&----
text
----
--> p1 text
<-- p2 text
----
form build_fieldcatalog .
define m_fieldcat.
clear i_fieldcatalog.
i_fieldcatalog-tabname = 'T_DATA'.
i_fieldcatalog-fieldname = &1.
i_fieldcatalog-just = 'L'.
i_fieldcatalog-outputlen = &2.
i_fieldcatalog-seltext_l = &3.
I_FIELDCATALOG-COL_POS = &4.
append i_fieldcatalog to fieldcatalog.
clear i_fieldcatalog.
end-of-definition.
m_fieldcat: 'PERNR' '08' 'Personnel No'.
m_fieldcat: 'NACHN' '40' 'Last Name' .
m_fieldcat: 'VORNA' '40' 'First name' .
m_fieldcat: 'PERID' '20' 'Social Security No.' .
m_fieldcat: 'NAME1' '30' 'Personal Area ' .
m_fieldcat: 'KOSTL' '10' 'Cost Center' .
m_fieldcat: 'TEXT1' '20' 'Employment Status'.
m_fieldcat: 'PTEXT' '20' 'Employment Group' .
m_fieldcat: 'DIVGV' '04' 'Working Hours'.
m_fieldcat: 'GBDAT' '08' 'Birthdate' .
m_fieldcat: 'DAT01' '08' 'Hire Date' .
m_fieldcat: 'DAT02' '08' 'Re-Hire Date' .
m_fieldcat: 'PLTYP' '04' 'Plan Type' .
m_fieldcat: 'BPLAN' '04' 'Benefit Plan'.
m_fieldcat: 'DEPCV' '10' 'Dependent Coverage' .
m_fieldcat: 'EECST' '10' 'Benefit Employee Cost Amount'.
m_fieldcat: 'PTCST' '10' 'Benefits Additional Employee Post-Tax Costs'.
m_fieldcat: 'IMINC' '10' 'Benefits Imputed Income' .
endform. " build_fieldcatalog
&----
*& Form define_alv
&----
text
----
form define_alv.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
I_CALLBACK_TOP_OF_PAGE = ' '
I_GRID_TITLE =
IS_LAYOUT =
it_fieldcat = fieldcatalog[]
it_events = i_event[]
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
tables
t_outtab = t_data
exceptions
program_error = 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.
endform. " define_alv
&----
*& Form TOP_OF_PAGE
&----
text
----
form top_of_page .
LIST HEADING LINE: TYPE H
clear t_header.
t_header-typ = 'H'.
t_header-info = 'Health Plan Details'.
append t_header to i_header.
STATUS LINE: TYPE S
clear t_header.
t_header-typ = 'S'.
t_header-key = 'Date Of Run'.
t_header-info = sy-datum.
append t_header to i_header.
ACTION LINE: TYPE A
clear t_header.
t_header-typ = 'A'.
LS_LINE-KEY: NOT USED FOR THIS TYPE
t_header-info = text-002.
append t_header to i_header.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = i_header
I_LOGO =
I_END_OF_LIST_GRID =
.
endform. "TOP_OF_PAGE
Hope it helps.
Thanks,
Jayant Sahu.