Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Simple logic for the code

Former Member
0 Likes
555

HI All,

Please expalin the logic behind the code and how can we put it simpler this logic by reducing the number of lines of the following logic

FORM fisical_period.

data : l_start_month like v_start_month,

l_end_month like v_end_month.

data: l_current_year like t009b-bdatj,

l_variant like t009-periv.

call function 'CCODE_GET_FISCAL_YEAR_VARIANT'

EXPORTING

company_code = p_bukrs

IMPORTING

fiscal_year_variant = l_variant

EXCEPTIONS

company_code_not_found = 1

others = 2.

if sy-subrc <> 0.

message i368(00) with 'Unable to get Fiscal year'.

endif.

l_current_year = sy-datum(4).

call function 'FIRST_AND_LAST_DAY_IN_YEAR_GET'

EXPORTING

i_gjahr = l_current_year

i_periv = l_variant

IMPORTING

e_first_day = p_fiscal-low

e_last_day = p_fiscal-high

EXCEPTIONS

input_false = 1

t009_notfound = 2

t009b_notfound = 3

others = 4.

if sy-subrc <> 0.

message i368(00) with 'Unable to get the first and last day'.

endif.

if sy-datum < p_fiscal-low.

p_fiscal-low = p_fiscal-low - 365.

p_fiscal-high = p_fiscal-high - 365.

endif.

append p_fiscal.

v_start_month = p_fiscal-low+4(2).

v_end_month = p_fiscal-high+4(2).

if v_start_month >= 01 and v_start_month <= 03.

move 01 to fiscal_quarter_1-month.

append fiscal_quarter_1.

move 02 to fiscal_quarter_1-month.

append fiscal_quarter_1.

move 03 to fiscal_quarter_1-month.

append fiscal_quarter_1.

move 04 to fiscal_quarter_2-month.

append fiscal_quarter_2.

move 05 to fiscal_quarter_2-month.

append fiscal_quarter_2.

move 06 to fiscal_quarter_2-month.

append fiscal_quarter_2.

move 07 to fiscal_quarter_3-month.

append fiscal_quarter_3.

move 08 to fiscal_quarter_3-month.

append fiscal_quarter_3.

move 09 to fiscal_quarter_3-month.

append fiscal_quarter_3.

move 10 to fiscal_quarter_4-month.

append fiscal_quarter_4.

move 11 to fiscal_quarter_4-month.

append fiscal_quarter_4.

move 12 to fiscal_quarter_4-month.

append fiscal_quarter_4.

elseif v_start_month >= 04 and v_start_month <= 06.

move 04 to fiscal_quarter_1-month.

append fiscal_quarter_1.

move 05 to fiscal_quarter_1-month.

append fiscal_quarter_1.

move 06 to fiscal_quarter_1-month.

append fiscal_quarter_1.

move 07 to fiscal_quarter_2-month.

append fiscal_quarter_2.

move 08 to fiscal_quarter_2-month.

append fiscal_quarter_2.

move 09 to fiscal_quarter_2-month.

append fiscal_quarter_2.

move 10 to fiscal_quarter_3-month.

append fiscal_quarter_3.

move 11 to fiscal_quarter_3-month.

append fiscal_quarter_3.

move 12 to fiscal_quarter_3-month.

append fiscal_quarter_3.

move 01 to fiscal_quarter_4-month.

append fiscal_quarter_4.

move 02 to fiscal_quarter_4-month.

append fiscal_quarter_4.

move 03 to fiscal_quarter_4-month.

append fiscal_quarter_4.

elseif v_start_month >= 07 and v_start_month <= 09.

move 07 to fiscal_quarter_1-month.

append fiscal_quarter_1.

move 08 to fiscal_quarter_1-month.

append fiscal_quarter_1.

move 09 to fiscal_quarter_1-month.

append fiscal_quarter_1.

move 10 to fiscal_quarter_2-month.

append fiscal_quarter_2.

move 11 to fiscal_quarter_2-month.

append fiscal_quarter_2.

move 12 to fiscal_quarter_2-month.

append fiscal_quarter_2.

move 01 to fiscal_quarter_3-month.

append fiscal_quarter_3.

move 02 to fiscal_quarter_3-month.

append fiscal_quarter_3.

move 03 to fiscal_quarter_3-month.

append fiscal_quarter_3.

move 04 to fiscal_quarter_4-month.

append fiscal_quarter_4.

move 05 to fiscal_quarter_4-month.

append fiscal_quarter_4.

move 06 to fiscal_quarter_4-month.

append fiscal_quarter_4.

else.

move 10 to fiscal_quarter_1-month.

append fiscal_quarter_1.

move 11 to fiscal_quarter_1-month.

append fiscal_quarter_1.

move 12 to fiscal_quarter_1-month.

append fiscal_quarter_1.

move 01 to fiscal_quarter_2-month.

append fiscal_quarter_2.

move 02 to fiscal_quarter_2-month.

append fiscal_quarter_2.

move 03 to fiscal_quarter_2-month.

append fiscal_quarter_2.

move 04 to fiscal_quarter_3-month.

append fiscal_quarter_3.

move 05 to fiscal_quarter_3-month.

append fiscal_quarter_3.

move 06 to fiscal_quarter_3-month.

append fiscal_quarter_3.

move 07 to fiscal_quarter_4-month.

append fiscal_quarter_4.

move 08 to fiscal_quarter_4-month.

append fiscal_quarter_4.

move 09 to fiscal_quarter_4-month.

append fiscal_quarter_4.

endif.

IF NOT p_fiscal IS INITIAL.

perform get_fiscal_year.

ENDIF.

IF NOT p_fiscal IS INITIAL.

v_start_year = p_fiscal-low+2(2).

v_end_year = p_fiscal-high+2(2).

v_start_year = r_gfiscal-low+2(2).

v_end_year = r_gfiscal-high+2(2).

v_start_month = r_gfiscal-low+4(2).

v_end_month = r_gfiscal-high+4(2).

move 'Jan' to i_months-month.

append i_months.

move 'Feb' to i_months-month.

append i_months.

move 'Mar' to i_months-month.

append i_months.

move 'Apr' to i_months-month.

append i_months.

move 'May' to i_months-month.

append i_months.

move 'Jun' to i_months-month.

append i_months.

move 'Jul' to i_months-month.

append i_months.

move 'Aug' to i_months-month.

append i_months.

move 'Sep' to i_months-month.

append i_months.

move 'Oct' to i_months-month.

append i_months.

move 'Nov' to i_months-month.

append i_months.

move 'Dec' to i_months-month.

append i_months.

if v_end_month < v_start_month.

v_find_month = 13 - v_start_month.

do v_find_month times.

read table i_months index v_start_month.

move v_start_month to fiscal_months-month.

move i_months-month to fiscal_months-literal.

move v_start_year to fiscal_months-year.

append fiscal_months.

add 1 to: v_number_of_months, v_start_month.

enddo.

do v_end_month times.

read table i_months index sy-index.

move sy-index to fiscal_months-month.

move i_months-month to fiscal_months-literal.

move v_end_year to fiscal_months-year.

append fiscal_months.

add 1 to v_number_of_months.

enddo.

else.

v_find_month = v_end_month - v_start_month + 1.

do v_find_month times.

read table i_months index v_start_month.

move v_start_month to fiscal_months-month.

move i_months-month to fiscal_months-literal.

move v_start_year to fiscal_months-year.

append fiscal_months.

add 1 to: v_number_of_months, v_start_month.

enddo.

endif.

ENDIF.

ENDFORM.

form get_fiscal_year.

data : l_lst_day like sy-datum,

l_frst_day like sy-datum,

l_fisc_vnt like t009-periv, "fiscal year variant

l_fisc_prd like t009b-poper,

l_fisc_yr like t009b-bdatj,

l_lines like sy-index.

data : i_periods like table of periods with header line.

perform get_fiscal_year_variant using p_bukrs

changing l_fisc_vnt.

perform get_period_on_date using p_fiscal-low

l_fisc_vnt

changing l_fisc_prd

l_fisc_yr.

call function 'G_PERIODS_OF_YEAR_GET'

EXPORTING

variant = l_fisc_vnt

year = l_fisc_yr

IMPORTING

last_normal_period = l_fisc_prd

TABLES

i_periods = i_periods

EXCEPTIONS

variant_not_defined = 1

year_not_defined = 2

others = 3.

if sy-subrc <> 0.

message i368(00) with 'Unable to Convert Periods'.

endif.

describe table i_periods lines l_lines.

read table i_periods index 1.

move i_periods-datab to r_gfiscal-low.

read table i_periods index l_lines.

move : i_periods-datbi to r_gfiscal-high,

'I' to r_gfiscal-sign,

'BT' to r_gfiscal-option.

append r_gfiscal.

endform. " get_fiscal_year

form get_fiscal_year_variant using p_p_ccode like t001-bukrs

changing p_g_fisc_vnt like t009-periv.

call function 'CCODE_GET_FISCAL_YEAR_VARIANT'

EXPORTING

company_code = p_p_ccode

IMPORTING

fiscal_year_variant = p_g_fisc_vnt

EXCEPTIONS

company_code_not_found = 1

others = 2.

if sy-subrc <> 0.

message i368(00) with 'Unable to retrieve fiscal year variant'.

endif.

endform. " get_fiscal_year_variant

form get_period_on_date using p_p_dcfp like sy-datum

p_g_fisc_vnt like t009-periv

changing p_g_fisc_prd like t009b-poper

p_g_fisc_yr like t009b-bdatj.

call function 'DATE_TO_PERIOD_CONVERT'

exporting

i_date = p_p_dcfp

i_periv = p_g_fisc_vnt

importing

e_buper = p_g_fisc_prd

e_gjahr = p_g_fisc_yr

exceptions

input_false = 1

t009_notfound = 2

t009b_notfound = 3

others = 4

.

if sy-subrc <> 0.

message i368(00) with 'Unable to get period on date'.

endif.

endform. " get_period_on_date

Thanks

2 REPLIES 2
Read only

Former Member
0 Likes
449

using MACRO's concept you can reduce the no. of lines in the code.

Read only

Former Member
0 Likes
449

Hi,

Try to use FMs : (type quarter in fm name field and press f4.

FMs like follows will be dispalyed :

BKK_GET_QUARTER_DATE

HR99S00_TIME Generic time related functions

HR_99S_GET_DATES_QUARTER Get begin and end date of a qrtr

HR_99S_GET_QUARTER Get quarter

HRPAYBE_DMFA Function pool for DMFA

HR_BE_DAQ_CONDT_QUARTER Condition for declaring the Local Unit ID for DMFA

HR_BE_DAQ_QUARTER Get occupation line relevant data for DMFA

HRPAYBE_DMFA_WORKFLOW Workflow DMFA

HR_BE_DMFA_GET_QUARTER Retrieve quarter declared

KRGE

KR_GET_HEADQUARTER_BPLACE

SLIM_DATE_TOOLS

SLIM_GET_QUARTERLY_PERIODS

STS2 Time stream: Generate for periods

TSTR_PERIODS_QUARTERS Generate Time Stream for Quarters