FI Period Automation – OB52

pts.
Tags:
MySAP
R/3
SAP
SAP development
Security
Strategic Enterprise Management
Hello All, Did anyone work for FI period open/Close automation? OB52 is used for opening and closing of FI posting periods. Did anyone write a BDC for transaction OB52. If yes can I have the sample code. Thanks in advance

Answer Wiki

Thanks. We'll let you know when a new response is added.

A little late however this code will open the new fiscal period:

report zfu005
message-id zz
no standard page heading.
tables: t001, “Company code table
t001b. “Posting periods allowed

*———————————————————————-*
* CONSTANTS
*———————————————————————-*
constants: gc_true type i value 1,
gc_false type i value 0.

*———————————————————————-*
* INTERNAL TABLES
*———————————————————————-*
data: begin of it_bdcdata occurs 100.
include structure bdcdata.
data: end of it_bdcdata.

*———————————————————————-*
* VARIABLES
*———————————————————————-*
data: gv_date type d,
gv_subrc like sy-subrc,
gv_repid like sy-repid,
gv_cr_gjahr like bsid-gjahr,
gv_nx_gjahr like bsid-gjahr,
gv_cr_poper like vbrk-poper,
gv_nx_poper like vbrk-poper.

*———————————————————————-*
* SELECTION SCREEN
*———————————————————————-*
selection-screen begin of block b1 with frame title text-001.
parameters: p_update as checkbox.
selection-screen end of block b1.

*———————————————————————-*
* TOP OF PAGE
*———————————————————————-*
top-of-page.
gv_repid = sy-repid.
call function ‘Z_HEADER’
exporting
repid = gv_repid
titel = sy-title
exceptions
others = 1.

perform add_column_headings.

*———————————————————————-*
* MAIN PROGRAM
*———————————————————————-*
start-of-selection.

check p_update = ‘X’.

perform authorisation_check.

check gv_subrc = 0.

perform get_data.

perform get_next_period.

perform open_period.

end-of-selection.
perform output_report.

*———————————————————————-*
* Form GET_DATA
*———————————————————————-*
* get data from database
*———————————————————————-*
form get_data.
select single * from t001b
where rrcty = ’0′
and bukrs = ’0001′
and mkoar = ‘+’
and bkont = space.
endform. ” GET_DATA

*———————————————————————-*
* FORM ADD_COLUMN_HEADINGS
*———————————————————————-*
* This form displays any extra column headings
*———————————————————————-*
form add_column_headings.

endform.

*———————————————————————-*
* Form GET_PERIOD
*———————————————————————-*
* Get fiscal period
*———————————————————————-*
form get_next_period.
select single periv from t001 into t001-periv
where bukrs = ’0001′.

* First get current fiscal period
perform get_period using sy-datum gv_cr_gjahr gv_cr_poper.

* Now get last day in fiscal period
call function ‘LAST_DAY_IN_PERIOD_GET’
exporting
i_gjahr = gv_cr_gjahr
i_periv = t001-periv
i_poper = gv_cr_poper
importing
e_date = gv_date
exceptions
input_false = 1
t009_notfound = 2
t009b_notfound = 3
others = 4.

* Now get first day in next period
add 1 to gv_date.

* Now get next fiscal period
perform get_period using gv_date gv_nx_gjahr gv_nx_poper.
endform. ” GET_PERIOD

*———————————————————————-*
* Form GET_PERIOD
*———————————————————————-*
* Get fiscal period
*———————————————————————-*
form get_period using p_date p_gjahr p_poper.
call function ‘FI_PERIOD_DETERMINE’
exporting
i_budat = p_date
i_bukrs = ’0001′
i_periv = t001-periv
importing
e_gjahr = p_gjahr
e_poper = p_poper
exceptions
fiscal_year = 1
period = 2
period_version = 3
posting_period = 4
special_period = 5
version = 6
posting_date = 7
others = 8.
endform. ” GET_PERIOD

*———————————————————————-*
* Form OPEN_PERIOD
*———————————————————————-*
* Determine if period should be opened
*———————————————————————-*
form open_period.
check t001b-tope1 ne gv_nx_poper.

perform build_bdc.

call function ‘BDC_OPEN_GROUP’
exporting client = sy-mandt
group = text-002
user = sy-uname
keep = ‘X’.

call function ‘BDC_INSERT’
exporting tcode = ‘OB52′
tables dynprotab = it_bdcdata.

call function ‘BDC_CLOSE_GROUP’.

submit rsbdcsub with mappe = text-002
with z_verarb = ‘X’
with fehler = space
and return.
endform. ” OPEN_PERIOD

*———————————————————————-*
* Form BUILD_BDC
*———————————————————————-*
* Edit customer group 3 for selected customer
*———————————————————————-*
form build_bdc.
clear: it_bdcdata[], it_bdcdata.
perform bdc_dynpro using ‘SAPL0F00′ ’0065′.
perform bdc_field using ‘BDC_OKCODE’ ‘=SAVE’.
perform bdc_field using ‘BDC_CURSOR’ ‘V_T001B-TOYE2(06)’.
perform bdc_field using ‘V_T001B-TOPE1(01)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOPE1(02)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOPE1(03)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOPE1(04)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOPE1(05)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOPE1(06)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOYE1(01)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOYE1(02)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOYE1(03)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOYE1(04)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOYE1(05)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOYE1(06)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOPE2(01)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOPE2(02)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOPE2(03)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOPE2(04)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOPE2(05)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOPE2(06)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOYE2(01)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOYE2(02)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOYE2(03)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOYE2(04)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOYE2(05)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOYE2(06)’ gv_nx_gjahr.

* BEGIN OE BackOffice – add new lines for Company Code 0021
perform bdc_field using ‘V_T001B-TOPE1(07)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOPE1(08)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOPE1(09)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOPE1(10)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOYE1(07)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOYE1(08)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOYE1(09)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOYE1(10)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOPE2(07)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOPE2(08)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOPE2(09)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOPE2(10)’ gv_nx_poper.
perform bdc_field using ‘V_T001B-TOYE2(07)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOYE2(08)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOYE2(09)’ gv_nx_gjahr.
perform bdc_field using ‘V_T001B-TOYE2(10)’ gv_nx_gjahr.
* END OE BackOffice

perform bdc_dynpro using ‘SAPL0F00′ ’0065′.
perform bdc_field using ‘BDC_OKCODE’ ‘=BACK’.
perform bdc_field using ‘BDC_CURSOR’ ‘V_T001B-TOYE1(01)’.
endform. ” BUILD_BDC

*———————————————————————-*
* Transfer program and dynpro number to bdc table
*———————————————————————-*
* –>P_PROGRAM – program name *
* –>P_SCREEN – dynpro number *
*———————————————————————-*
form bdc_dynpro using value(p_program) value(p_screen).
clear it_bdcdata.
it_bdcdata-program = p_program.
it_bdcdata-dynpro = p_screen.
it_bdcdata-dynbegin = ‘X’.
append it_bdcdata.
endform. ” BDC_DYNPRO

*———————————————————————-*
* Form BDC_FIELD
*———————————————————————-*
* Add field data to bdc table
*———————————————————————-*
* –>P_FNAME – field name *
* –>P_FVALUE – field value *
*———————————————————————-*
form bdc_field using value(p_fname) value(p_fvalue).
clear it_bdcdata.
it_bdcdata-fnam = p_fname.
it_bdcdata-fval = p_fvalue.
append it_bdcdata.
endform. ” BDC_FIELD

*———————————————————————-*
* Form AUTHORISATION_CHECK
*———————————————————————-*
* Check for table maintenance authorisation
*———————————————————————-*
form authorisation_check.
authority-check object ‘S_TABU_DIS’
id ‘ACTVT’ field ’02′
id ‘DICBERCLS’ field ‘FC31′.

if sy-subrc ne 0.
gv_subrc = sy-subrc.
write: / text-003.
endif.
endform. ” AUTHORISATION_CHECK

*———————————————————————-*
* Form OUTPUT_REPORT
*———————————————————————-*
* Report
*———————————————————————-*
form output_report.
skip.
if p_update = space.
write: / text-005.
elseif t001b-tope1 = gv_nx_poper.
write: / text-004.
endif.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following