Interface (Non-SAP to SAP)
METHOD zpiii_mmcjournal_voucher_to_sa~mmcjournal_voucher_to_sapecc_i.
*** **** INSERT IMPLEMENTATION HERE **** ***
TYPES:
BEGIN OF ty_skb1,
saknr TYPE saknr,
altkt TYPE altkt_skb1,
mitkz TYPE mitkz,
END OF ty_skb1,
BEGIN OF ty_bkpf,
belnr TYPE belnr_d,
message(100) TYPE c,
END OF ty_bkpf,
BEGIN OF ty_csks,
kostl TYPE kostl,
bkzer TYPE bkzer,
END OF ty_csks,
BEGIN OF ty_cepc,
prctr TYPE prctr,
END OF ty_cepc,
BEGIN OF ty_olimms_tmp,
gl_main_acct(10) TYPE n,
unit_code(10) TYPE c,
prof_cen TYPE bdc_fval,
kostl TYPE bdc_fval,
scheme_code TYPE bdc_fval,
div_code TYPE bdc_fval,
gl_code TYPE bdc_fval,
dr_amt TYPE bdc_fval,
cr_amt TYPE bdc_fval,
poskey TYPE bdc_fval,
bus_place TYPE bdc_fval,
jv_no TYPE bdc_fval,
END OF ty_olimms_tmp,
BEGIN OF ty_jvno,
jvno TYPE bdc_fval,
END OF ty_jvno,
BEGIN OF ty_dwnld,
unit_code TYPE string,
scheme_code TYPE string,
div_code TYPE string,
gl_code TYPE string,
dr_amt TYPE string,
cr_amt TYPE string,
jv_no TYPE string,
ch_jv_type TYPE string,
END OF ty_dwnld,
BEGIN OF ty_dwnld_bc,
unit_code TYPE string,
scheme_code TYPE string,
div_code TYPE string,
gl_code TYPE string,
dr_amt TYPE string,
cr_amt TYPE string,
kostl TYPE string,
prof_cen TYPE string,
poskey TYPE string,
gl_main_acct TYPE string,
internal_order TYPE string,
jv_no TYPE string,
ch_jv_type TYPE string,
END OF ty_dwnld_bc,
BEGIN OF ty_dwnldsap,
unit_code TYPE string,
scheme_code TYPE string,
div_code TYPE string,
gl_code TYPE string,
dr_amt TYPE string,
cr_amt TYPE string,
kostl TYPE string,
prof_cen TYPE string,
poskey TYPE string,
gl_main_acct TYPE string,
internal_order TYPE string,
END OF ty_dwnldsap.
DATA:
lt_olimms TYPE zpimmcjournal_voucher_to_s_tab,
lwa_olimms TYPE zpimmcjournal_voucher_to_sape2,
lwa_climscd TYPE zfi_olimms_cd,
lwa_olimms_data TYPE zolimms,
lwa_olimms_tmp TYPE ty_olimms_tmp,
lwa_olimms_cov TYPE ty_olimms_tmp,
lwa_olimms_tmp1 TYPE ty_olimms_tmp,
lwa_upd_olimms TYPE zolimms,
lwa_skb1 TYPE ty_skb1,
lwa_elog TYPE zfi_olimmselog,
lwa_olimms_ckc TYPE zolimms,
lwa_olimms_ckdata TYPE zolimms,
lwa_bkpf TYPE zfi_olimmsslog,
lwa_bkpf2 TYPE zfi_olimmsslog,
lwa_olimms_unit TYPE zolimms,
lwa_csks TYPE ty_csks,
lwa_cepc TYPE ty_cepc,
lwa_jvno TYPE ty_jvno,
lwa_dwnld TYPE ty_dwnld,
lwa_olimms_dwnd TYPE ty_dwnldsap,
lwa_olimms_bsdwnd TYPE ty_dwnld_bc.
DATA:
lt_climscd TYPE TABLE OF zfi_olimms_cd,
lt_olimms_data TYPE TABLE OF zolimms,
lt_olimms_dwnd TYPE TABLE OF ty_dwnldsap,
lt_olimms_tmp TYPE TABLE OF ty_olimms_tmp,
lt_olimms_cov TYPE TABLE OF ty_olimms_tmp,
lt_olimms_tmp1 TYPE TABLE OF ty_olimms_tmp,
lt_olimms_ckdata TYPE TABLE OF zolimms,
lt_olimms_unit TYPE TABLE OF zolimms,
lt_delete TYPE TABLE OF zolimms,
lt_skb1 TYPE TABLE OF ty_skb1,
lt_upd_olimms TYPE TABLE OF zolimms,
lt_elog TYPE TABLE OF zfi_olimmselog,
lt_olimms_ckc TYPE TABLE OF zolimms,
lt_bkpf TYPE TABLE OF zfi_olimmsslog,
lt_bkpf2 TYPE TABLE OF zfi_olimmsslog,
lt_csks TYPE TABLE OF ty_csks,
lt_cepc TYPE TABLE OF ty_cepc,
lt_jvno TYPE TABLE OF ty_jvno,
lt_dwnld TYPE TABLE OF ty_dwnld,
lt_olimms_bsdwnd TYPE TABLE OF ty_dwnld_bc.
DATA:
lv_error TYPE boolean,
lv_amt TYPE pad_amt7s,
lv_scr TYPE string,
lv_cnt TYPE string,
lv_glcode(10) TYPE n,
lv_record TYPE string,
lv_dramt(16) TYPE p DECIMALS 2,
lv_cramt(16) TYPE p DECIMALS 2,
lv_fdramt(16) TYPE p DECIMALS 2,
lv_fcramt(16) TYPE p DECIMALS 2,
lv_fnlamt(16) TYPE p DECIMALS 2,
lv_rec(3) TYPE n,
lv_difamt TYPE string,
lv_prvdt TYPE cpudt,
lv_year TYPE gjahr,
lv_count TYPE string,
lv_errflg TYPE boole,
lv_idx TYPE string,
lv_lnmac TYPE c,
lv_path TYPE string,
lv_code TYPE string,
lv_tabix TYPE i. "sy-tabix.
CONSTANTS :
lc_dr TYPE newbs VALUE '40',
lc_cr TYPE newbs VALUE '50',
lc_amt(15) TYPE c VALUE '000000000000000',
lc_maxrec(3) TYPE n VALUE '500',
lc_bukrs TYPE bukrs VALUE '1000',
lc_dctyp TYPE blart VALUE 'ZI', "'SA',
lc_glcode(10) TYPE c VALUE '5000000020',
lc_main_acc TYPE bdc_fval VALUE '4025211123',
lc_ackostl TYPE kostl VALUE 'M010010101',
lc_recacc(10) TYPE c VALUE '1210010528'.
DATA:
lr_table TYPE REF TO cl_salv_table,
lr_functions TYPE REF TO cl_salv_functions_list.
DATA:
rwa_altkt TYPE RANGE OF skb1-altkt,
rt_altkt LIKE TABLE OF rwa_altkt.
DATA :
lt_success TYPE STANDARD TABLE OF zfi_olimmsslog,
lt_error TYPE STANDARD TABLE OF zfi_olimmselog,
lwa_success TYPE zfi_olimmsslog,
lwa_error TYPE zfi_olimmselog.
DELETE FROM zfi_olimmselog. " Error log
DELETE FROM zfi_olimmsslog. "Success log
COMMIT WORK.
lt_olimms[] = input-mmcjournal_voucher_to_sapecc-journal_voucher_data[].
************************* 04.06.2015
**Checking Success log
lv_prvdt = sy-datum - 1.
lv_year = sy-datum+0(4).
SELECT belnr FROM bkpf INTO CORRESPONDING FIELDS OF TABLE lt_bkpf2
WHERE bukrs EQ lc_bukrs AND
blart EQ lc_dctyp AND
( cpudt EQ sy-datum OR
cpudt EQ lv_prvdt ).
*************************
**Download File which is received from OLIMMS ***
lwa_dwnld-unit_code = 'Unit'.
lwa_dwnld-scheme_code = 'Scheme Code'.
lwa_dwnld-div_code = 'Division Code'.
lwa_dwnld-gl_code = 'GL Code'.
lwa_dwnld-dr_amt = 'Debit Amount'.
lwa_dwnld-cr_amt = 'Credit Amount'.
lwa_dwnld-jv_no = 'JV Number'.
lwa_dwnld-ch_jv_type = 'JV Type'.
APPEND lwa_dwnld TO lt_dwnld.
LOOP AT lt_olimms INTO lwa_olimms.
MOVE-CORRESPONDING lwa_olimms TO lwa_dwnld.
APPEND lwa_dwnld TO lt_dwnld.
ENDLOOP.
**First Download
IF sy-mandt+0(1) = '2'.
CONCATENATE 'C:\INTERFACES\OLIMMS\DEV\LEGACYDATA' sy-mandt sy-datum '.XLS' INTO lv_path.
ELSEIF sy-mandt+0(1) = '3'.
CONCATENATE 'C:\INTERFACES\OLIMMS\QTY\LEGACYDATA' sy-mandt sy-datum '.XLS' INTO lv_path.
ELSEIF sy-mandt+0(1) = '4'.
CONCATENATE 'C:\INTERFACES\OLIMMS\PRD\LEGACYDATA' sy-mandt sy-datum '.XLS' INTO lv_path.
ENDIF.
* lv_path = 'E:\OLIMMS.XLS'.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = lv_path
filetype = 'ASC'
write_field_separator = 'X'
CHANGING
data_tab = lt_dwnld
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 <> 0.
* Implement suitable error handling here
ENDIF.
SELECT *
FROM zfi_olimms_cd
INTO TABLE lt_climscd.
**Fetch GL Account Number
SELECT saknr altkt mitkz FROM skb1 INTO TABLE lt_skb1 WHERE bukrs EQ lc_bukrs.
** Get Cost Center
SELECT kostl bkzer FROM csks INTO TABLE lt_csks.
**Profit center
SELECT prctr FROM cepc INTO TABLE lt_cepc.
LOOP AT lt_olimms INTO lwa_olimms.
**If Credit and Debit amount is ZERO then skip the record
IF lwa_olimms-dr_amt EQ '0' AND lwa_olimms-cr_amt EQ '0'.
CONTINUE.
ENDIF.
*Check if the Unit Code,Scheme Code and Div.Code matches
READ TABLE lt_climscd INTO lwa_climscd WITH KEY unit_code = lwa_olimms-unit_code
scheme_code = lwa_olimms-scheme_code
div_code = lwa_olimms-div_code.
IF sy-subrc = 0.
CLEAR lv_code.
** Inserting in Custom Table
lwa_olimms_data-unit_code = lwa_climscd-unit_code.
lwa_olimms_data-scheme_code = lwa_climscd-scheme_code.
lwa_olimms_data-div_code = lwa_climscd-div_code.
lwa_olimms_data-gl_code = lwa_olimms-gl_code.
lwa_olimms_data-dr_amt = lwa_olimms-dr_amt.
lwa_olimms_data-cr_amt = lwa_olimms-cr_amt.
lwa_olimms_data-kostl = lwa_climscd-kostl.
lwa_olimms_data-prof_cen = lwa_climscd-prof_cnt.
lwa_olimms_data-mandt = sy-mandt.
lwa_olimms_data-jv_no = lwa_olimms-jv_no.
lwa_olimms_data-ch_jv_type = lwa_olimms-ch_jv_type.
IF lwa_olimms_data-dr_amt NE lc_amt AND lwa_olimms_data-dr_amt NE '0'. " Changes on 13.02.2015
lwa_olimms_data-poskey = lc_dr.
ELSEIF lwa_olimms_data-cr_amt NE lc_amt AND lwa_olimms_data-cr_amt NE '0'.
lwa_olimms_data-poskey = lc_cr.
ENDIF.
lv_glcode = lwa_olimms-gl_code.
**Clearing JV No. for Equestion related Plant and Michanery
"Begin Of Change 25-042015 PNK
IF lwa_olimms_data-ch_jv_type EQ 'O'.
lwa_jvno-jvno = lwa_olimms_data-jv_no.
APPEND lwa_jvno TO lt_jvno.
CLEAR lwa_jvno.
ENDIF.
"End Of Change 25-042015 PNK
IF ( lwa_olimms_data-gl_code EQ '1823' ) OR ( lwa_olimms_data-gl_code EQ '1833' ) OR
( lwa_olimms_data-gl_code EQ'1834' ) OR ( lwa_olimms_data-gl_code EQ '1841' ) OR
( lwa_olimms_data-gl_code EQ'1853' ) OR ( lwa_olimms_data-gl_code EQ '1863' ) OR
( lwa_olimms_data-gl_code EQ '0823' ) OR ( lwa_olimms_data-gl_code EQ '0833' ) OR
( lwa_olimms_data-gl_code EQ '0834' ) OR ( lwa_olimms_data-gl_code EQ '0841' ) OR
( lwa_olimms_data-gl_code EQ '0853' ) OR ( lwa_olimms_data-gl_code EQ '0863' )." OR
"( lwa_olimms_data-ch_jv_type EQ 'O' ).
lwa_jvno-jvno = lwa_olimms_data-jv_no.
APPEND lwa_jvno TO lt_jvno.
CLEAR lwa_jvno.
ENDIF.
CASE lv_glcode.
WHEN '4314'.
lwa_olimms_data-gl_main_acct = '4010040006'.
WHEN '2293'.
lwa_olimms_data-gl_main_acct = '2220030113'.
WHEN '525'.
lwa_olimms_data-gl_main_acct = '5088888886'.
WHEN '1108'.
lwa_olimms_data-gl_main_acct = '5088888887'.
WHEN '1150'.
lwa_olimms_data-gl_main_acct = '5088888885'.
WHEN '1864' OR '2311'.
lwa_olimms_data-gl_main_acct = '2205010154'.
* WHEN '823' OR '853' OR '863'.
* lwa_olimms_data-gl_main_acct = '1210010517'.
* WHEN '1823' OR '1833' OR '1853' OR '1863'.
* lwa_olimms_data-gl_main_acct = '2205010154'.
WHEN '1842' OR '1824'.
lwa_olimms_data-gl_main_acct = '2205010129'.
WHEN '1850'.
lwa_olimms_data-gl_main_acct = '2205010136'.
ENDCASE.
IF lv_glcode+6(2) = '98'.
lwa_olimms_data-gl_main_acct = '5900000000'.
ENDIF.
**If GL Code doesnt have above mentioned value
IF lwa_olimms_data-gl_main_acct IS INITIAL.
CLEAR lwa_skb1.
READ TABLE lt_skb1 INTO lwa_skb1 WITH KEY altkt = lv_glcode.
IF lwa_skb1-mitkz IS INITIAL AND sy-subrc = 0.
lwa_olimms_data-gl_main_acct = lwa_skb1-saknr.
ENDIF.
CLEAR lwa_skb1.
IF ( lv_glcode NE '1823' ) AND ( lv_glcode NE '1833' ) AND
( lv_glcode NE '1834' ) AND ( lv_glcode NE '1841' ) AND
( lv_glcode NE'1853' ) AND ( lv_glcode NE '1863' ) AND
( lv_glcode NE '0823' ) AND ( lv_glcode NE '0833' ) AND
( lv_glcode NE '0834' ) AND ( lv_glcode NE '0841' ) AND
( lv_glcode NE '0853' ) AND ( lv_glcode NE '0863' ).
READ TABLE lt_skb1 INTO lwa_skb1 WITH KEY altkt = lv_glcode.
IF sy-subrc EQ '0' AND lwa_skb1-mitkz IS NOT INITIAL.
lwa_elog-message = text-011.
lwa_elog-gl_code = lv_glcode.
* lwa_elog-message = text-001.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ELSEIF sy-subrc NE '0' AND lwa_olimms_data-gl_main_acct IS INITIAL.
lwa_elog-message = text-012.
lwa_elog-gl_code = lv_glcode.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
ENDIF.
ENDIF.
** Collecting the Error log.
IF lwa_olimms_data-unit_code IS INITIAL.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
lwa_elog-message = text-001.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
IF lwa_olimms_data-scheme_code IS INITIAL.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
lwa_elog-message = text-002.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
IF lwa_olimms_data-div_code IS INITIAL.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
lwa_elog-message = text-003.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
IF lwa_olimms_data-gl_code IS INITIAL.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
lwa_elog-message = text-004.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
IF lwa_olimms_data-kostl EQ '0000000000' AND
lwa_olimms_data-gl_main_acct+0(1) EQ'4' AND
lwa_olimms_data-gl_main_acct+0(1) EQ '5'.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
lwa_elog-message = text-005.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
IF lwa_olimms_data-prof_cen EQ '00000000'.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
lwa_elog-message = text-006.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
**Clearing Cost center for balance Sheet account
IF lwa_olimms_data-gl_main_acct+0(1) NE '4' AND
lwa_olimms_data-gl_main_acct+0(1) NE '5'.
CLEAR: lwa_olimms_data-kostl.
ENDIF.
IF lwa_olimms_data-gl_main_acct+0(1) EQ'4' OR
lwa_olimms_data-gl_main_acct+0(1) EQ '5'.
READ TABLE lt_csks INTO lwa_csks WITH KEY kostl = lwa_olimms_data-kostl.
IF sy-subrc NE 0.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
CONCATENATE lwa_olimms_data-kostl text-005 INTO lwa_elog-message.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
ENDIF.
READ TABLE lt_csks INTO lwa_csks WITH KEY kostl = lwa_olimms_data-kostl.
IF sy-subrc = 0 AND lwa_csks-bkzer IS NOT INITIAL.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
CONCATENATE 'Cost Center' lwa_olimms_data-kostl text-009
lwa_csks-bkzer INTO lwa_elog-message.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
READ TABLE lt_cepc INTO lwa_cepc WITH KEY prctr = lwa_olimms_data-prof_cen.
IF sy-subrc NE 0.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
CONCATENATE text-010 lwa_olimms_data-prof_cen INTO
lwa_elog-message.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
APPEND lwa_olimms_data TO lt_olimms_data.
CLEAR lwa_olimms_data.
ELSEIF sy-subrc NE 0.
lwa_elog-gl_code = lwa_olimms-gl_code.
CONCATENATE 'Unit Code' lwa_olimms-unit_code 'Division Code' lwa_olimms-div_code
'Scheme Code' lwa_olimms-scheme_code 'Combination not maintained in table'
INTO lwa_elog-message.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
* LV_ERROR = 'X'.
* EXIT.
ENDIF.
ENDLOOP.
**Second Download
IF sy-mandt+0(1) = '2'.
CONCATENATE 'C:\INTERFACES\OLIMMS\DEV\OLIMMS_SAP' sy-mandt sy-datum '.XLS' INTO lv_path.
ELSEIF sy-mandt+0(1) = '3'.
CONCATENATE 'C:\INTERFACES\OLIMMS\QTY\OLIMMS_SAP' sy-mandt sy-datum '.XLS' INTO lv_path.
ELSEIF sy-mandt+0(1) = '4'.
CONCATENATE 'C:\INTERFACES\OLIMMS\PRD\OLIMMS_SAP' sy-mandt sy-datum '.XLS' INTO lv_path.
ENDIF.
* lv_path = 'E:\OLIMMS_SAP.XLS'.
lwa_olimms_bsdwnd-unit_code = 'Unit'.
lwa_olimms_bsdwnd-scheme_code = 'Scheme Code'.
lwa_olimms_bsdwnd-div_code = 'Division Code'.
lwa_olimms_bsdwnd-gl_code = 'GL Code'.
lwa_olimms_bsdwnd-dr_amt = 'Debit Amount'.
lwa_olimms_bsdwnd-cr_amt = 'Credit Amount'.
lwa_olimms_bsdwnd-kostl = 'Cost Center'.
lwa_olimms_bsdwnd-prof_cen = 'Profit Center'.
lwa_olimms_bsdwnd-poskey = 'Posting Key'.
lwa_olimms_bsdwnd-gl_main_acct = 'GL Account'.
lwa_olimms_bsdwnd-internal_order = 'Internal Order'.
lwa_olimms_bsdwnd-jv_no = 'JV Number'.
lwa_olimms_bsdwnd-ch_jv_type = 'JV Type'.
APPEND lwa_olimms_bsdwnd TO lt_olimms_bsdwnd.
LOOP AT lt_olimms_data INTO lwa_olimms_data.
MOVE-CORRESPONDING lwa_olimms_data TO lwa_olimms_bsdwnd.
APPEND lwa_olimms_bsdwnd TO lt_olimms_bsdwnd.
ENDLOOP.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = lv_path
filetype = 'ASC'
write_field_separator = 'X'
CHANGING
data_tab = lt_olimms_bsdwnd
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 <> 0.
* Implement suitable error handling here
ENDIF.
**Check Debit and Credit matches
SORT lt_olimms_data BY unit_code.
CLEAR lv_idx.
LOOP AT lt_olimms_data INTO lwa_olimms_data.
lv_idx = lv_idx + 1.
READ TABLE lt_jvno INTO lwa_jvno WITH KEY jvno = lwa_olimms_data-jv_no .
IF sy-subrc = 0.
CLEAR lwa_olimms_data-jv_no.
* MODIFY lt_olimms_data INDEX LV_IDX FROM lwa_olimms_data .
DELETE lt_olimms_data INDEX lv_idx.
lv_idx = lv_idx - 1.
ENDIF.
lv_cramt = lv_cramt + lwa_olimms_data-cr_amt.
lv_dramt = lv_dramt + lwa_olimms_data-dr_amt.
ENDLOOP.
lv_fnlamt = lv_cramt + lv_dramt.
IF lv_fnlamt NE '0'.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
lwa_elog-message = text-007.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
* EXIT.
ENDIF.
** Segerating on the Unit Level
CLEAR: lv_count,lv_cramt,lv_dramt.
** Error log
IF lt_elog IS NOT INITIAL.
MODIFY zfi_olimmselog FROM TABLE lt_elog.
COMMIT WORK.
EXIT.
ENDIF.
***** Segrating unit code Cost center and Profit center wise
** Adding Amount for the corresponding GL Account
LOOP AT lt_olimms_data INTO lwa_olimms_data.
MOVE-CORRESPONDING lwa_olimms_data TO lwa_olimms_tmp.
APPEND lwa_olimms_tmp TO lt_olimms_tmp.
ENDLOOP.
* SORT lt_olimms_data BY unit_code kostl prof_cen gl_main_acct.
SORT lt_olimms_tmp BY unit_code kostl prof_cen gl_main_acct.
lt_olimms_cov = lt_olimms_tmp.
lv_idx = 1.
LOOP AT lt_olimms_tmp INTO lwa_olimms_tmp.
lv_idx = lv_idx + 1.
lwa_olimms_tmp1-dr_amt = lwa_olimms_tmp1-dr_amt + lwa_olimms_tmp-dr_amt.
lwa_olimms_tmp1-cr_amt = lwa_olimms_tmp1-cr_amt + lwa_olimms_tmp-cr_amt.
CONDENSE: lwa_olimms_tmp1-dr_amt, lwa_olimms_tmp1-cr_amt,
lwa_olimms_tmp-dr_amt, lwa_olimms_tmp-cr_amt.
READ TABLE lt_olimms_cov INTO lwa_olimms_cov INDEX lv_idx.
IF sy-subrc NE '0'.
CLEAR lwa_olimms_cov.
ENDIF.
IF lwa_olimms_cov-unit_code NE lwa_olimms_tmp-unit_code OR
lwa_olimms_cov-prof_cen NE lwa_olimms_tmp-prof_cen OR
lwa_olimms_cov-kostl NE lwa_olimms_tmp-kostl OR
lwa_olimms_cov-gl_main_acct NE lwa_olimms_tmp-gl_main_acct.
lwa_olimms_tmp1-unit_code = lwa_olimms_tmp-unit_code.
lwa_olimms_tmp1-scheme_code = lwa_olimms_tmp-scheme_code.
lwa_olimms_tmp1-div_code = lwa_olimms_tmp-div_code.
IF ( lwa_olimms_tmp-gl_code+0(2) EQ '98' ) or ( lwa_olimms_tmp-gl_code+0(2) EQ '99' ).
CONCATENATE lwa_olimms_tmp-gl_code+0(2) 'XX' INTO lv_code. "abap07
CONDENSE lv_code.
lwa_olimms_tmp1-gl_code = lv_code.
ELSE.
lwa_olimms_tmp1-gl_code = lwa_olimms_tmp-gl_code.
ENDIF.
lwa_olimms_tmp1-kostl = lwa_olimms_tmp-kostl.
lwa_olimms_tmp1-prof_cen = lwa_olimms_tmp-prof_cen.
lwa_olimms_tmp1-gl_main_acct = lwa_olimms_tmp-gl_main_acct.
lwa_olimms_tmp1-poskey = lwa_olimms_tmp-poskey.
lwa_olimms_tmp1-bus_place = lwa_olimms_tmp-bus_place.
lwa_olimms_tmp1-jv_no = lwa_olimms_tmp-jv_no.
APPEND lwa_olimms_tmp1 TO lt_olimms_tmp1.
CLEAR lwa_olimms_tmp1.
* ENDAT.
ENDIF.
ENDLOOP.
CLEAR lt_olimms_data[].
LOOP AT lt_olimms_tmp1 INTO lwa_olimms_tmp1.
MOVE-CORRESPONDING lwa_olimms_tmp1 TO lwa_olimms_data.
lwa_olimms_data-mandt = sy-mandt.
*****************************************************************************************
***Start of Changes of Incroperate Logic for Internal Oder on 27.05.2015 by Anand Raj **'
IF lwa_olimms_data-gl_main_acct+0(1) EQ '3' OR
lwa_olimms_data-gl_main_acct+0(1) EQ '4'. "OR
** lwa_olimms_data-gl_main_acct+0(1) EQ '5'.
CASE lwa_olimms_tmp1-prof_cen.
WHEN 'N01022'.
lwa_olimms_data-internal_order = '400106'.
WHEN 'N01054'.
lwa_olimms_data-internal_order = '400113'.
WHEN 'N19004'.
lwa_olimms_data-internal_order = '400120'.
WHEN 'N25086'.
lwa_olimms_data-internal_order = '400127'.
WHEN 'N26068'.
lwa_olimms_data-internal_order = '400134'.
WHEN 'N01053'.
lwa_olimms_data-internal_order = '400141'.
WHEN 'N19065'.
lwa_olimms_data-internal_order = '400148'.
WHEN 'N20069'.
lwa_olimms_data-internal_order = '400155'.
WHEN 'N24082'.
lwa_olimms_data-internal_order = '400162'.
ENDCASE.
IF lwa_olimms_data-internal_order IS INITIAL.
lwa_olimms_data-internal_order = '600080'.
ENDIF.
ENDIF.
******************************End of Changes ***********************************************************
APPEND lwa_olimms_data TO lt_olimms_data.
CLEAR lwa_olimms_data.
ENDLOOP.
** Downloading the File in which SAP is going to be processed
**Third Download
IF sy-mandt+0(1) = '2'.
CONCATENATE 'C:\INTERFACES\OLIMMS\DEV\SAP' sy-mandt sy-datum '.XLS' INTO lv_path.
ELSEIF sy-mandt+0(1) = '3'.
CONCATENATE 'C:\INTERFACES\OLIMMS\QTY\SAP' sy-mandt sy-datum '.XLS' INTO lv_path.
ELSEIF sy-mandt+0(1) = '4'.
CONCATENATE 'C:\INTERFACES\OLIMMS\PRD\SAP' sy-mandt sy-datum '.XLS' INTO lv_path.
ENDIF.
* lv_path = 'E:\OLIMMS_SAP.XLS'.
lwa_olimms_dwnd-unit_code = 'Unit'.
lwa_olimms_dwnd-scheme_code = 'Scheme Code'.
lwa_olimms_dwnd-div_code = 'Division Code'.
lwa_olimms_dwnd-gl_code = 'GL Code'.
lwa_olimms_dwnd-dr_amt = 'Debit Amount'.
lwa_olimms_dwnd-cr_amt = 'Credit Amount'.
lwa_olimms_dwnd-kostl = 'Cost Center'.
lwa_olimms_dwnd-prof_cen = 'Profit Center'.
lwa_olimms_dwnd-poskey = 'Posting Key'.
lwa_olimms_dwnd-gl_main_acct = 'GL Account'.
lwa_olimms_dwnd-internal_order = 'Internal Order'.
* lwa_olimms_dwnd-jv_no = 'JV Number'.
* lwa_olimms_dwnd-ch_jv_type = 'JV Type'.
APPEND lwa_olimms_dwnd TO lt_olimms_dwnd.
LOOP AT lt_olimms_data INTO lwa_olimms_data.
MOVE-CORRESPONDING lwa_olimms_data TO lwa_olimms_dwnd.
APPEND lwa_olimms_dwnd TO lt_olimms_dwnd.
ENDLOOP.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = lv_path
filetype = 'ASC'
write_field_separator = 'X'
CHANGING
data_tab = lt_olimms_dwnd
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 <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT lt_olimms_data INTO lwa_olimms_data.
lv_count = lv_count + 1.
lwa_olimms_unit = lwa_olimms_data.
lv_cramt = lv_cramt + lwa_olimms_data-cr_amt.
lv_dramt = lv_dramt + lwa_olimms_data-dr_amt.
APPEND lwa_olimms_unit TO lt_olimms_unit.
CLEAR lwa_olimms_unit.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
AT END OF unit_code.
lv_fnlamt = lv_cramt + lv_dramt.
IF lv_fnlamt NE '0'.
lwa_elog-message = text-007.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
EXIT.
ENDIF.
CLEAR: lv_cramt,lv_dramt.
*********************************************************************************
**** IF Number of records are less than '500' then can upload directely *****
** Else add difference amount with the lesser and Update *******************
*********************************************************************************
CLEAR lv_idx.
LOOP AT lt_olimms_unit INTO lwa_olimms_unit.
lv_idx = lv_idx + 1.
IF lwa_olimms_unit-cr_amt NE '0' AND
lwa_olimms_unit-dr_amt NE '0' .
lv_amt = lwa_olimms_unit-dr_amt + lwa_olimms_unit-cr_amt.
* CONDENSE lv_amt.
IF lv_amt LT '0'.
lwa_olimms_unit-cr_amt = lv_amt.
lwa_olimms_unit-dr_amt = '0'.
lwa_olimms_unit-poskey = '50'.
CONDENSE lwa_olimms_unit-cr_amt.
MODIFY lt_olimms_unit FROM lwa_olimms_unit INDEX lv_idx.
ELSEIF lv_amt GT '0'.
lwa_olimms_unit-dr_amt = lv_amt.
lwa_olimms_unit-cr_amt = '0'.
lwa_olimms_unit-poskey = '40'.
CONDENSE lwa_olimms_unit-dr_amt.
MODIFY lt_olimms_unit FROM lwa_olimms_unit INDEX lv_idx.
ELSEIF lv_amt EQ '0'.
DELETE TABLE lt_olimms_unit FROM lwa_olimms_unit .
lv_idx = lv_idx - 1.
ENDIF.
CLEAR lwa_olimms_unit.
ENDIF.
ENDLOOP.
IF lv_count LE lc_maxrec.
CALL FUNCTION 'ZFI_INTERFACE_OLIMMS'
IMPORTING
ep_error = lv_errflg
TABLES
lt_olimms_data = lt_olimms_unit[].
CLEAR: lt_olimms_unit[],lv_count.
IF lv_errflg IS NOT INITIAL.
EXIT.
ENDIF.
ELSEIF lv_count GT lc_maxrec.
CALL FUNCTION 'ZFI_OLIMMS_CALC'
IMPORTING
ep_error = lv_errflg
TABLES
it_olimms = lt_olimms_unit[].
CLEAR: lt_olimms_unit[],lv_count.
IF lv_errflg IS NOT INITIAL.
EXIT.
ENDIF.
ENDIF.
ENDAT.
ENDLOOP.
IF lt_elog IS NOT INITIAL.
INSERT zfi_olimmselog FROM TABLE lt_elog.
COMMIT WORK.
EXIT.
ENDIF.
**Checking Success log
lv_prvdt = sy-datum - 1.
lv_year = sy-datum+0(4).
SELECT belnr FROM bkpf INTO CORRESPONDING FIELDS OF TABLE lt_bkpf
WHERE bukrs EQ lc_bukrs AND
blart EQ lc_dctyp AND
( cpudt EQ sy-datum OR
cpudt EQ lv_prvdt ).
LOOP AT lt_bkpf INTO lwa_bkpf.
lwa_bkpf-message = 'Uploaded Success fully'.
MODIFY lt_bkpf FROM lwa_bkpf INDEX sy-tabix.
CLEAR lwa_bkpf.
ENDLOOP.
***Updating Data base table
MODIFY zfi_olimmsslog FROM TABLE lt_bkpf.
IF sy-subrc EQ 0.
COMMIT WORK.
ENDIF.
**-- select query to get the log records
**-- error log
SELECT *
FROM zfi_olimmselog
INTO TABLE lt_error.
IF lt_error[] IS NOT INITIAL.
**--send mail
CALL FUNCTION 'ZSEND_MAIL_OLIMMS'
TABLES
lt_mail = lt_error[].
ENDIF.
**--success log
SELECT *
FROM zfi_olimmsslog
INTO TABLE lt_success.
**-- sort internal tables
SORT lt_success.
SORT lt_bkpf2.
**-- loop at lt_success to delete the matched records.
LOOP AT lt_success INTO lwa_success.
lv_tabix = sy-tabix. "get the tabix number
READ TABLE lt_bkpf2 INTO lwa_bkpf2 WITH KEY belnr = lwa_success-belnr
BINARY SEARCH.
IF sy-subrc EQ 0.
**-- delete lt_success for matched records
DELETE lt_success INDEX lv_tabix.
CLEAR lv_tabix.
ENDIF.
ENDLOOP.
**--send mail
IF lt_success[] IS NOT INITIAL.
** --SEND MAIL
CALL FUNCTION 'ZSEND_MAIL_OLIMMS'
TABLES
lt_mail = lt_success[].
ENDIF.
ENDMETHOD.
METHOD zpiii_mmcjournal_voucher_to_sa~mmcjournal_voucher_to_sapecc_i.
*** **** INSERT IMPLEMENTATION HERE **** ***
TYPES:
BEGIN OF ty_skb1,
saknr TYPE saknr,
altkt TYPE altkt_skb1,
mitkz TYPE mitkz,
END OF ty_skb1,
BEGIN OF ty_bkpf,
belnr TYPE belnr_d,
message(100) TYPE c,
END OF ty_bkpf,
BEGIN OF ty_csks,
kostl TYPE kostl,
bkzer TYPE bkzer,
END OF ty_csks,
BEGIN OF ty_cepc,
prctr TYPE prctr,
END OF ty_cepc,
BEGIN OF ty_olimms_tmp,
gl_main_acct(10) TYPE n,
unit_code(10) TYPE c,
prof_cen TYPE bdc_fval,
kostl TYPE bdc_fval,
scheme_code TYPE bdc_fval,
div_code TYPE bdc_fval,
gl_code TYPE bdc_fval,
dr_amt TYPE bdc_fval,
cr_amt TYPE bdc_fval,
poskey TYPE bdc_fval,
bus_place TYPE bdc_fval,
jv_no TYPE bdc_fval,
END OF ty_olimms_tmp,
BEGIN OF ty_jvno,
jvno TYPE bdc_fval,
END OF ty_jvno,
BEGIN OF ty_dwnld,
unit_code TYPE string,
scheme_code TYPE string,
div_code TYPE string,
gl_code TYPE string,
dr_amt TYPE string,
cr_amt TYPE string,
jv_no TYPE string,
ch_jv_type TYPE string,
END OF ty_dwnld,
BEGIN OF ty_dwnld_bc,
unit_code TYPE string,
scheme_code TYPE string,
div_code TYPE string,
gl_code TYPE string,
dr_amt TYPE string,
cr_amt TYPE string,
kostl TYPE string,
prof_cen TYPE string,
poskey TYPE string,
gl_main_acct TYPE string,
internal_order TYPE string,
jv_no TYPE string,
ch_jv_type TYPE string,
END OF ty_dwnld_bc,
BEGIN OF ty_dwnldsap,
unit_code TYPE string,
scheme_code TYPE string,
div_code TYPE string,
gl_code TYPE string,
dr_amt TYPE string,
cr_amt TYPE string,
kostl TYPE string,
prof_cen TYPE string,
poskey TYPE string,
gl_main_acct TYPE string,
internal_order TYPE string,
END OF ty_dwnldsap.
DATA:
lt_olimms TYPE zpimmcjournal_voucher_to_s_tab,
lwa_olimms TYPE zpimmcjournal_voucher_to_sape2,
lwa_climscd TYPE zfi_olimms_cd,
lwa_olimms_data TYPE zolimms,
lwa_olimms_tmp TYPE ty_olimms_tmp,
lwa_olimms_cov TYPE ty_olimms_tmp,
lwa_olimms_tmp1 TYPE ty_olimms_tmp,
lwa_upd_olimms TYPE zolimms,
lwa_skb1 TYPE ty_skb1,
lwa_elog TYPE zfi_olimmselog,
lwa_olimms_ckc TYPE zolimms,
lwa_olimms_ckdata TYPE zolimms,
lwa_bkpf TYPE zfi_olimmsslog,
lwa_bkpf2 TYPE zfi_olimmsslog,
lwa_olimms_unit TYPE zolimms,
lwa_csks TYPE ty_csks,
lwa_cepc TYPE ty_cepc,
lwa_jvno TYPE ty_jvno,
lwa_dwnld TYPE ty_dwnld,
lwa_olimms_dwnd TYPE ty_dwnldsap,
lwa_olimms_bsdwnd TYPE ty_dwnld_bc.
DATA:
lt_climscd TYPE TABLE OF zfi_olimms_cd,
lt_olimms_data TYPE TABLE OF zolimms,
lt_olimms_dwnd TYPE TABLE OF ty_dwnldsap,
lt_olimms_tmp TYPE TABLE OF ty_olimms_tmp,
lt_olimms_cov TYPE TABLE OF ty_olimms_tmp,
lt_olimms_tmp1 TYPE TABLE OF ty_olimms_tmp,
lt_olimms_ckdata TYPE TABLE OF zolimms,
lt_olimms_unit TYPE TABLE OF zolimms,
lt_delete TYPE TABLE OF zolimms,
lt_skb1 TYPE TABLE OF ty_skb1,
lt_upd_olimms TYPE TABLE OF zolimms,
lt_elog TYPE TABLE OF zfi_olimmselog,
lt_olimms_ckc TYPE TABLE OF zolimms,
lt_bkpf TYPE TABLE OF zfi_olimmsslog,
lt_bkpf2 TYPE TABLE OF zfi_olimmsslog,
lt_csks TYPE TABLE OF ty_csks,
lt_cepc TYPE TABLE OF ty_cepc,
lt_jvno TYPE TABLE OF ty_jvno,
lt_dwnld TYPE TABLE OF ty_dwnld,
lt_olimms_bsdwnd TYPE TABLE OF ty_dwnld_bc.
DATA:
lv_error TYPE boolean,
lv_amt TYPE pad_amt7s,
lv_scr TYPE string,
lv_cnt TYPE string,
lv_glcode(10) TYPE n,
lv_record TYPE string,
lv_dramt(16) TYPE p DECIMALS 2,
lv_cramt(16) TYPE p DECIMALS 2,
lv_fdramt(16) TYPE p DECIMALS 2,
lv_fcramt(16) TYPE p DECIMALS 2,
lv_fnlamt(16) TYPE p DECIMALS 2,
lv_rec(3) TYPE n,
lv_difamt TYPE string,
lv_prvdt TYPE cpudt,
lv_year TYPE gjahr,
lv_count TYPE string,
lv_errflg TYPE boole,
lv_idx TYPE string,
lv_lnmac TYPE c,
lv_path TYPE string,
lv_code TYPE string,
lv_tabix TYPE i. "sy-tabix.
CONSTANTS :
lc_dr TYPE newbs VALUE '40',
lc_cr TYPE newbs VALUE '50',
lc_amt(15) TYPE c VALUE '000000000000000',
lc_maxrec(3) TYPE n VALUE '500',
lc_bukrs TYPE bukrs VALUE '1000',
lc_dctyp TYPE blart VALUE 'ZI', "'SA',
lc_glcode(10) TYPE c VALUE '5000000020',
lc_main_acc TYPE bdc_fval VALUE '4025211123',
lc_ackostl TYPE kostl VALUE 'M010010101',
lc_recacc(10) TYPE c VALUE '1210010528'.
DATA:
lr_table TYPE REF TO cl_salv_table,
lr_functions TYPE REF TO cl_salv_functions_list.
DATA:
rwa_altkt TYPE RANGE OF skb1-altkt,
rt_altkt LIKE TABLE OF rwa_altkt.
DATA :
lt_success TYPE STANDARD TABLE OF zfi_olimmsslog,
lt_error TYPE STANDARD TABLE OF zfi_olimmselog,
lwa_success TYPE zfi_olimmsslog,
lwa_error TYPE zfi_olimmselog.
DELETE FROM zfi_olimmselog. " Error log
DELETE FROM zfi_olimmsslog. "Success log
COMMIT WORK.
lt_olimms[] = input-mmcjournal_voucher_to_sapecc-journal_voucher_data[].
************************* 04.06.2015
**Checking Success log
lv_prvdt = sy-datum - 1.
lv_year = sy-datum+0(4).
SELECT belnr FROM bkpf INTO CORRESPONDING FIELDS OF TABLE lt_bkpf2
WHERE bukrs EQ lc_bukrs AND
blart EQ lc_dctyp AND
( cpudt EQ sy-datum OR
cpudt EQ lv_prvdt ).
*************************
**Download File which is received from OLIMMS ***
lwa_dwnld-unit_code = 'Unit'.
lwa_dwnld-scheme_code = 'Scheme Code'.
lwa_dwnld-div_code = 'Division Code'.
lwa_dwnld-gl_code = 'GL Code'.
lwa_dwnld-dr_amt = 'Debit Amount'.
lwa_dwnld-cr_amt = 'Credit Amount'.
lwa_dwnld-jv_no = 'JV Number'.
lwa_dwnld-ch_jv_type = 'JV Type'.
APPEND lwa_dwnld TO lt_dwnld.
LOOP AT lt_olimms INTO lwa_olimms.
MOVE-CORRESPONDING lwa_olimms TO lwa_dwnld.
APPEND lwa_dwnld TO lt_dwnld.
ENDLOOP.
**First Download
IF sy-mandt+0(1) = '2'.
CONCATENATE 'C:\INTERFACES\OLIMMS\DEV\LEGACYDATA' sy-mandt sy-datum '.XLS' INTO lv_path.
ELSEIF sy-mandt+0(1) = '3'.
CONCATENATE 'C:\INTERFACES\OLIMMS\QTY\LEGACYDATA' sy-mandt sy-datum '.XLS' INTO lv_path.
ELSEIF sy-mandt+0(1) = '4'.
CONCATENATE 'C:\INTERFACES\OLIMMS\PRD\LEGACYDATA' sy-mandt sy-datum '.XLS' INTO lv_path.
ENDIF.
* lv_path = 'E:\OLIMMS.XLS'.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = lv_path
filetype = 'ASC'
write_field_separator = 'X'
CHANGING
data_tab = lt_dwnld
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 <> 0.
* Implement suitable error handling here
ENDIF.
SELECT *
FROM zfi_olimms_cd
INTO TABLE lt_climscd.
**Fetch GL Account Number
SELECT saknr altkt mitkz FROM skb1 INTO TABLE lt_skb1 WHERE bukrs EQ lc_bukrs.
** Get Cost Center
SELECT kostl bkzer FROM csks INTO TABLE lt_csks.
**Profit center
SELECT prctr FROM cepc INTO TABLE lt_cepc.
LOOP AT lt_olimms INTO lwa_olimms.
**If Credit and Debit amount is ZERO then skip the record
IF lwa_olimms-dr_amt EQ '0' AND lwa_olimms-cr_amt EQ '0'.
CONTINUE.
ENDIF.
*Check if the Unit Code,Scheme Code and Div.Code matches
READ TABLE lt_climscd INTO lwa_climscd WITH KEY unit_code = lwa_olimms-unit_code
scheme_code = lwa_olimms-scheme_code
div_code = lwa_olimms-div_code.
IF sy-subrc = 0.
CLEAR lv_code.
** Inserting in Custom Table
lwa_olimms_data-unit_code = lwa_climscd-unit_code.
lwa_olimms_data-scheme_code = lwa_climscd-scheme_code.
lwa_olimms_data-div_code = lwa_climscd-div_code.
lwa_olimms_data-gl_code = lwa_olimms-gl_code.
lwa_olimms_data-dr_amt = lwa_olimms-dr_amt.
lwa_olimms_data-cr_amt = lwa_olimms-cr_amt.
lwa_olimms_data-kostl = lwa_climscd-kostl.
lwa_olimms_data-prof_cen = lwa_climscd-prof_cnt.
lwa_olimms_data-mandt = sy-mandt.
lwa_olimms_data-jv_no = lwa_olimms-jv_no.
lwa_olimms_data-ch_jv_type = lwa_olimms-ch_jv_type.
IF lwa_olimms_data-dr_amt NE lc_amt AND lwa_olimms_data-dr_amt NE '0'. " Changes on 13.02.2015
lwa_olimms_data-poskey = lc_dr.
ELSEIF lwa_olimms_data-cr_amt NE lc_amt AND lwa_olimms_data-cr_amt NE '0'.
lwa_olimms_data-poskey = lc_cr.
ENDIF.
lv_glcode = lwa_olimms-gl_code.
**Clearing JV No. for Equestion related Plant and Michanery
"Begin Of Change 25-042015 PNK
IF lwa_olimms_data-ch_jv_type EQ 'O'.
lwa_jvno-jvno = lwa_olimms_data-jv_no.
APPEND lwa_jvno TO lt_jvno.
CLEAR lwa_jvno.
ENDIF.
"End Of Change 25-042015 PNK
IF ( lwa_olimms_data-gl_code EQ '1823' ) OR ( lwa_olimms_data-gl_code EQ '1833' ) OR
( lwa_olimms_data-gl_code EQ'1834' ) OR ( lwa_olimms_data-gl_code EQ '1841' ) OR
( lwa_olimms_data-gl_code EQ'1853' ) OR ( lwa_olimms_data-gl_code EQ '1863' ) OR
( lwa_olimms_data-gl_code EQ '0823' ) OR ( lwa_olimms_data-gl_code EQ '0833' ) OR
( lwa_olimms_data-gl_code EQ '0834' ) OR ( lwa_olimms_data-gl_code EQ '0841' ) OR
( lwa_olimms_data-gl_code EQ '0853' ) OR ( lwa_olimms_data-gl_code EQ '0863' )." OR
"( lwa_olimms_data-ch_jv_type EQ 'O' ).
lwa_jvno-jvno = lwa_olimms_data-jv_no.
APPEND lwa_jvno TO lt_jvno.
CLEAR lwa_jvno.
ENDIF.
CASE lv_glcode.
WHEN '4314'.
lwa_olimms_data-gl_main_acct = '4010040006'.
WHEN '2293'.
lwa_olimms_data-gl_main_acct = '2220030113'.
WHEN '525'.
lwa_olimms_data-gl_main_acct = '5088888886'.
WHEN '1108'.
lwa_olimms_data-gl_main_acct = '5088888887'.
WHEN '1150'.
lwa_olimms_data-gl_main_acct = '5088888885'.
WHEN '1864' OR '2311'.
lwa_olimms_data-gl_main_acct = '2205010154'.
* WHEN '823' OR '853' OR '863'.
* lwa_olimms_data-gl_main_acct = '1210010517'.
* WHEN '1823' OR '1833' OR '1853' OR '1863'.
* lwa_olimms_data-gl_main_acct = '2205010154'.
WHEN '1842' OR '1824'.
lwa_olimms_data-gl_main_acct = '2205010129'.
WHEN '1850'.
lwa_olimms_data-gl_main_acct = '2205010136'.
ENDCASE.
IF lv_glcode+6(2) = '98'.
lwa_olimms_data-gl_main_acct = '5900000000'.
ENDIF.
**If GL Code doesnt have above mentioned value
IF lwa_olimms_data-gl_main_acct IS INITIAL.
CLEAR lwa_skb1.
READ TABLE lt_skb1 INTO lwa_skb1 WITH KEY altkt = lv_glcode.
IF lwa_skb1-mitkz IS INITIAL AND sy-subrc = 0.
lwa_olimms_data-gl_main_acct = lwa_skb1-saknr.
ENDIF.
CLEAR lwa_skb1.
IF ( lv_glcode NE '1823' ) AND ( lv_glcode NE '1833' ) AND
( lv_glcode NE '1834' ) AND ( lv_glcode NE '1841' ) AND
( lv_glcode NE'1853' ) AND ( lv_glcode NE '1863' ) AND
( lv_glcode NE '0823' ) AND ( lv_glcode NE '0833' ) AND
( lv_glcode NE '0834' ) AND ( lv_glcode NE '0841' ) AND
( lv_glcode NE '0853' ) AND ( lv_glcode NE '0863' ).
READ TABLE lt_skb1 INTO lwa_skb1 WITH KEY altkt = lv_glcode.
IF sy-subrc EQ '0' AND lwa_skb1-mitkz IS NOT INITIAL.
lwa_elog-message = text-011.
lwa_elog-gl_code = lv_glcode.
* lwa_elog-message = text-001.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ELSEIF sy-subrc NE '0' AND lwa_olimms_data-gl_main_acct IS INITIAL.
lwa_elog-message = text-012.
lwa_elog-gl_code = lv_glcode.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
ENDIF.
ENDIF.
** Collecting the Error log.
IF lwa_olimms_data-unit_code IS INITIAL.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
lwa_elog-message = text-001.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
IF lwa_olimms_data-scheme_code IS INITIAL.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
lwa_elog-message = text-002.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
IF lwa_olimms_data-div_code IS INITIAL.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
lwa_elog-message = text-003.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
IF lwa_olimms_data-gl_code IS INITIAL.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
lwa_elog-message = text-004.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
IF lwa_olimms_data-kostl EQ '0000000000' AND
lwa_olimms_data-gl_main_acct+0(1) EQ'4' AND
lwa_olimms_data-gl_main_acct+0(1) EQ '5'.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
lwa_elog-message = text-005.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
IF lwa_olimms_data-prof_cen EQ '00000000'.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
lwa_elog-message = text-006.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
**Clearing Cost center for balance Sheet account
IF lwa_olimms_data-gl_main_acct+0(1) NE '4' AND
lwa_olimms_data-gl_main_acct+0(1) NE '5'.
CLEAR: lwa_olimms_data-kostl.
ENDIF.
IF lwa_olimms_data-gl_main_acct+0(1) EQ'4' OR
lwa_olimms_data-gl_main_acct+0(1) EQ '5'.
READ TABLE lt_csks INTO lwa_csks WITH KEY kostl = lwa_olimms_data-kostl.
IF sy-subrc NE 0.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
CONCATENATE lwa_olimms_data-kostl text-005 INTO lwa_elog-message.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
ENDIF.
READ TABLE lt_csks INTO lwa_csks WITH KEY kostl = lwa_olimms_data-kostl.
IF sy-subrc = 0 AND lwa_csks-bkzer IS NOT INITIAL.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
CONCATENATE 'Cost Center' lwa_olimms_data-kostl text-009
lwa_csks-bkzer INTO lwa_elog-message.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
READ TABLE lt_cepc INTO lwa_cepc WITH KEY prctr = lwa_olimms_data-prof_cen.
IF sy-subrc NE 0.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
CONCATENATE text-010 lwa_olimms_data-prof_cen INTO
lwa_elog-message.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
ENDIF.
APPEND lwa_olimms_data TO lt_olimms_data.
CLEAR lwa_olimms_data.
ELSEIF sy-subrc NE 0.
lwa_elog-gl_code = lwa_olimms-gl_code.
CONCATENATE 'Unit Code' lwa_olimms-unit_code 'Division Code' lwa_olimms-div_code
'Scheme Code' lwa_olimms-scheme_code 'Combination not maintained in table'
INTO lwa_elog-message.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
* LV_ERROR = 'X'.
* EXIT.
ENDIF.
ENDLOOP.
**Second Download
IF sy-mandt+0(1) = '2'.
CONCATENATE 'C:\INTERFACES\OLIMMS\DEV\OLIMMS_SAP' sy-mandt sy-datum '.XLS' INTO lv_path.
ELSEIF sy-mandt+0(1) = '3'.
CONCATENATE 'C:\INTERFACES\OLIMMS\QTY\OLIMMS_SAP' sy-mandt sy-datum '.XLS' INTO lv_path.
ELSEIF sy-mandt+0(1) = '4'.
CONCATENATE 'C:\INTERFACES\OLIMMS\PRD\OLIMMS_SAP' sy-mandt sy-datum '.XLS' INTO lv_path.
ENDIF.
* lv_path = 'E:\OLIMMS_SAP.XLS'.
lwa_olimms_bsdwnd-unit_code = 'Unit'.
lwa_olimms_bsdwnd-scheme_code = 'Scheme Code'.
lwa_olimms_bsdwnd-div_code = 'Division Code'.
lwa_olimms_bsdwnd-gl_code = 'GL Code'.
lwa_olimms_bsdwnd-dr_amt = 'Debit Amount'.
lwa_olimms_bsdwnd-cr_amt = 'Credit Amount'.
lwa_olimms_bsdwnd-kostl = 'Cost Center'.
lwa_olimms_bsdwnd-prof_cen = 'Profit Center'.
lwa_olimms_bsdwnd-poskey = 'Posting Key'.
lwa_olimms_bsdwnd-gl_main_acct = 'GL Account'.
lwa_olimms_bsdwnd-internal_order = 'Internal Order'.
lwa_olimms_bsdwnd-jv_no = 'JV Number'.
lwa_olimms_bsdwnd-ch_jv_type = 'JV Type'.
APPEND lwa_olimms_bsdwnd TO lt_olimms_bsdwnd.
LOOP AT lt_olimms_data INTO lwa_olimms_data.
MOVE-CORRESPONDING lwa_olimms_data TO lwa_olimms_bsdwnd.
APPEND lwa_olimms_bsdwnd TO lt_olimms_bsdwnd.
ENDLOOP.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = lv_path
filetype = 'ASC'
write_field_separator = 'X'
CHANGING
data_tab = lt_olimms_bsdwnd
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 <> 0.
* Implement suitable error handling here
ENDIF.
**Check Debit and Credit matches
SORT lt_olimms_data BY unit_code.
CLEAR lv_idx.
LOOP AT lt_olimms_data INTO lwa_olimms_data.
lv_idx = lv_idx + 1.
READ TABLE lt_jvno INTO lwa_jvno WITH KEY jvno = lwa_olimms_data-jv_no .
IF sy-subrc = 0.
CLEAR lwa_olimms_data-jv_no.
* MODIFY lt_olimms_data INDEX LV_IDX FROM lwa_olimms_data .
DELETE lt_olimms_data INDEX lv_idx.
lv_idx = lv_idx - 1.
ENDIF.
lv_cramt = lv_cramt + lwa_olimms_data-cr_amt.
lv_dramt = lv_dramt + lwa_olimms_data-dr_amt.
ENDLOOP.
lv_fnlamt = lv_cramt + lv_dramt.
IF lv_fnlamt NE '0'.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
lwa_elog-message = text-007.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
* EXIT.
ENDIF.
** Segerating on the Unit Level
CLEAR: lv_count,lv_cramt,lv_dramt.
** Error log
IF lt_elog IS NOT INITIAL.
MODIFY zfi_olimmselog FROM TABLE lt_elog.
COMMIT WORK.
EXIT.
ENDIF.
***** Segrating unit code Cost center and Profit center wise
** Adding Amount for the corresponding GL Account
LOOP AT lt_olimms_data INTO lwa_olimms_data.
MOVE-CORRESPONDING lwa_olimms_data TO lwa_olimms_tmp.
APPEND lwa_olimms_tmp TO lt_olimms_tmp.
ENDLOOP.
* SORT lt_olimms_data BY unit_code kostl prof_cen gl_main_acct.
SORT lt_olimms_tmp BY unit_code kostl prof_cen gl_main_acct.
lt_olimms_cov = lt_olimms_tmp.
lv_idx = 1.
LOOP AT lt_olimms_tmp INTO lwa_olimms_tmp.
lv_idx = lv_idx + 1.
lwa_olimms_tmp1-dr_amt = lwa_olimms_tmp1-dr_amt + lwa_olimms_tmp-dr_amt.
lwa_olimms_tmp1-cr_amt = lwa_olimms_tmp1-cr_amt + lwa_olimms_tmp-cr_amt.
CONDENSE: lwa_olimms_tmp1-dr_amt, lwa_olimms_tmp1-cr_amt,
lwa_olimms_tmp-dr_amt, lwa_olimms_tmp-cr_amt.
READ TABLE lt_olimms_cov INTO lwa_olimms_cov INDEX lv_idx.
IF sy-subrc NE '0'.
CLEAR lwa_olimms_cov.
ENDIF.
IF lwa_olimms_cov-unit_code NE lwa_olimms_tmp-unit_code OR
lwa_olimms_cov-prof_cen NE lwa_olimms_tmp-prof_cen OR
lwa_olimms_cov-kostl NE lwa_olimms_tmp-kostl OR
lwa_olimms_cov-gl_main_acct NE lwa_olimms_tmp-gl_main_acct.
lwa_olimms_tmp1-unit_code = lwa_olimms_tmp-unit_code.
lwa_olimms_tmp1-scheme_code = lwa_olimms_tmp-scheme_code.
lwa_olimms_tmp1-div_code = lwa_olimms_tmp-div_code.
IF ( lwa_olimms_tmp-gl_code+0(2) EQ '98' ) or ( lwa_olimms_tmp-gl_code+0(2) EQ '99' ).
CONCATENATE lwa_olimms_tmp-gl_code+0(2) 'XX' INTO lv_code. "abap07
CONDENSE lv_code.
lwa_olimms_tmp1-gl_code = lv_code.
ELSE.
lwa_olimms_tmp1-gl_code = lwa_olimms_tmp-gl_code.
ENDIF.
lwa_olimms_tmp1-kostl = lwa_olimms_tmp-kostl.
lwa_olimms_tmp1-prof_cen = lwa_olimms_tmp-prof_cen.
lwa_olimms_tmp1-gl_main_acct = lwa_olimms_tmp-gl_main_acct.
lwa_olimms_tmp1-poskey = lwa_olimms_tmp-poskey.
lwa_olimms_tmp1-bus_place = lwa_olimms_tmp-bus_place.
lwa_olimms_tmp1-jv_no = lwa_olimms_tmp-jv_no.
APPEND lwa_olimms_tmp1 TO lt_olimms_tmp1.
CLEAR lwa_olimms_tmp1.
* ENDAT.
ENDIF.
ENDLOOP.
CLEAR lt_olimms_data[].
LOOP AT lt_olimms_tmp1 INTO lwa_olimms_tmp1.
MOVE-CORRESPONDING lwa_olimms_tmp1 TO lwa_olimms_data.
lwa_olimms_data-mandt = sy-mandt.
*****************************************************************************************
***Start of Changes of Incroperate Logic for Internal Oder on 27.05.2015 by Anand Raj **'
IF lwa_olimms_data-gl_main_acct+0(1) EQ '3' OR
lwa_olimms_data-gl_main_acct+0(1) EQ '4'. "OR
** lwa_olimms_data-gl_main_acct+0(1) EQ '5'.
CASE lwa_olimms_tmp1-prof_cen.
WHEN 'N01022'.
lwa_olimms_data-internal_order = '400106'.
WHEN 'N01054'.
lwa_olimms_data-internal_order = '400113'.
WHEN 'N19004'.
lwa_olimms_data-internal_order = '400120'.
WHEN 'N25086'.
lwa_olimms_data-internal_order = '400127'.
WHEN 'N26068'.
lwa_olimms_data-internal_order = '400134'.
WHEN 'N01053'.
lwa_olimms_data-internal_order = '400141'.
WHEN 'N19065'.
lwa_olimms_data-internal_order = '400148'.
WHEN 'N20069'.
lwa_olimms_data-internal_order = '400155'.
WHEN 'N24082'.
lwa_olimms_data-internal_order = '400162'.
ENDCASE.
IF lwa_olimms_data-internal_order IS INITIAL.
lwa_olimms_data-internal_order = '600080'.
ENDIF.
ENDIF.
******************************End of Changes ***********************************************************
APPEND lwa_olimms_data TO lt_olimms_data.
CLEAR lwa_olimms_data.
ENDLOOP.
** Downloading the File in which SAP is going to be processed
**Third Download
IF sy-mandt+0(1) = '2'.
CONCATENATE 'C:\INTERFACES\OLIMMS\DEV\SAP' sy-mandt sy-datum '.XLS' INTO lv_path.
ELSEIF sy-mandt+0(1) = '3'.
CONCATENATE 'C:\INTERFACES\OLIMMS\QTY\SAP' sy-mandt sy-datum '.XLS' INTO lv_path.
ELSEIF sy-mandt+0(1) = '4'.
CONCATENATE 'C:\INTERFACES\OLIMMS\PRD\SAP' sy-mandt sy-datum '.XLS' INTO lv_path.
ENDIF.
* lv_path = 'E:\OLIMMS_SAP.XLS'.
lwa_olimms_dwnd-unit_code = 'Unit'.
lwa_olimms_dwnd-scheme_code = 'Scheme Code'.
lwa_olimms_dwnd-div_code = 'Division Code'.
lwa_olimms_dwnd-gl_code = 'GL Code'.
lwa_olimms_dwnd-dr_amt = 'Debit Amount'.
lwa_olimms_dwnd-cr_amt = 'Credit Amount'.
lwa_olimms_dwnd-kostl = 'Cost Center'.
lwa_olimms_dwnd-prof_cen = 'Profit Center'.
lwa_olimms_dwnd-poskey = 'Posting Key'.
lwa_olimms_dwnd-gl_main_acct = 'GL Account'.
lwa_olimms_dwnd-internal_order = 'Internal Order'.
* lwa_olimms_dwnd-jv_no = 'JV Number'.
* lwa_olimms_dwnd-ch_jv_type = 'JV Type'.
APPEND lwa_olimms_dwnd TO lt_olimms_dwnd.
LOOP AT lt_olimms_data INTO lwa_olimms_data.
MOVE-CORRESPONDING lwa_olimms_data TO lwa_olimms_dwnd.
APPEND lwa_olimms_dwnd TO lt_olimms_dwnd.
ENDLOOP.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = lv_path
filetype = 'ASC'
write_field_separator = 'X'
CHANGING
data_tab = lt_olimms_dwnd
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 <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT lt_olimms_data INTO lwa_olimms_data.
lv_count = lv_count + 1.
lwa_olimms_unit = lwa_olimms_data.
lv_cramt = lv_cramt + lwa_olimms_data-cr_amt.
lv_dramt = lv_dramt + lwa_olimms_data-dr_amt.
APPEND lwa_olimms_unit TO lt_olimms_unit.
CLEAR lwa_olimms_unit.
lwa_elog-gl_code = lwa_olimms_data-gl_code.
AT END OF unit_code.
lv_fnlamt = lv_cramt + lv_dramt.
IF lv_fnlamt NE '0'.
lwa_elog-message = text-007.
APPEND lwa_elog TO lt_elog.
CLEAR lwa_elog.
EXIT.
ENDIF.
CLEAR: lv_cramt,lv_dramt.
*********************************************************************************
**** IF Number of records are less than '500' then can upload directely *****
** Else add difference amount with the lesser and Update *******************
*********************************************************************************
CLEAR lv_idx.
LOOP AT lt_olimms_unit INTO lwa_olimms_unit.
lv_idx = lv_idx + 1.
IF lwa_olimms_unit-cr_amt NE '0' AND
lwa_olimms_unit-dr_amt NE '0' .
lv_amt = lwa_olimms_unit-dr_amt + lwa_olimms_unit-cr_amt.
* CONDENSE lv_amt.
IF lv_amt LT '0'.
lwa_olimms_unit-cr_amt = lv_amt.
lwa_olimms_unit-dr_amt = '0'.
lwa_olimms_unit-poskey = '50'.
CONDENSE lwa_olimms_unit-cr_amt.
MODIFY lt_olimms_unit FROM lwa_olimms_unit INDEX lv_idx.
ELSEIF lv_amt GT '0'.
lwa_olimms_unit-dr_amt = lv_amt.
lwa_olimms_unit-cr_amt = '0'.
lwa_olimms_unit-poskey = '40'.
CONDENSE lwa_olimms_unit-dr_amt.
MODIFY lt_olimms_unit FROM lwa_olimms_unit INDEX lv_idx.
ELSEIF lv_amt EQ '0'.
DELETE TABLE lt_olimms_unit FROM lwa_olimms_unit .
lv_idx = lv_idx - 1.
ENDIF.
CLEAR lwa_olimms_unit.
ENDIF.
ENDLOOP.
IF lv_count LE lc_maxrec.
CALL FUNCTION 'ZFI_INTERFACE_OLIMMS'
IMPORTING
ep_error = lv_errflg
TABLES
lt_olimms_data = lt_olimms_unit[].
CLEAR: lt_olimms_unit[],lv_count.
IF lv_errflg IS NOT INITIAL.
EXIT.
ENDIF.
ELSEIF lv_count GT lc_maxrec.
CALL FUNCTION 'ZFI_OLIMMS_CALC'
IMPORTING
ep_error = lv_errflg
TABLES
it_olimms = lt_olimms_unit[].
CLEAR: lt_olimms_unit[],lv_count.
IF lv_errflg IS NOT INITIAL.
EXIT.
ENDIF.
ENDIF.
ENDAT.
ENDLOOP.
IF lt_elog IS NOT INITIAL.
INSERT zfi_olimmselog FROM TABLE lt_elog.
COMMIT WORK.
EXIT.
ENDIF.
**Checking Success log
lv_prvdt = sy-datum - 1.
lv_year = sy-datum+0(4).
SELECT belnr FROM bkpf INTO CORRESPONDING FIELDS OF TABLE lt_bkpf
WHERE bukrs EQ lc_bukrs AND
blart EQ lc_dctyp AND
( cpudt EQ sy-datum OR
cpudt EQ lv_prvdt ).
LOOP AT lt_bkpf INTO lwa_bkpf.
lwa_bkpf-message = 'Uploaded Success fully'.
MODIFY lt_bkpf FROM lwa_bkpf INDEX sy-tabix.
CLEAR lwa_bkpf.
ENDLOOP.
***Updating Data base table
MODIFY zfi_olimmsslog FROM TABLE lt_bkpf.
IF sy-subrc EQ 0.
COMMIT WORK.
ENDIF.
**-- select query to get the log records
**-- error log
SELECT *
FROM zfi_olimmselog
INTO TABLE lt_error.
IF lt_error[] IS NOT INITIAL.
**--send mail
CALL FUNCTION 'ZSEND_MAIL_OLIMMS'
TABLES
lt_mail = lt_error[].
ENDIF.
**--success log
SELECT *
FROM zfi_olimmsslog
INTO TABLE lt_success.
**-- sort internal tables
SORT lt_success.
SORT lt_bkpf2.
**-- loop at lt_success to delete the matched records.
LOOP AT lt_success INTO lwa_success.
lv_tabix = sy-tabix. "get the tabix number
READ TABLE lt_bkpf2 INTO lwa_bkpf2 WITH KEY belnr = lwa_success-belnr
BINARY SEARCH.
IF sy-subrc EQ 0.
**-- delete lt_success for matched records
DELETE lt_success INDEX lv_tabix.
CLEAR lv_tabix.
ENDIF.
ENDLOOP.
**--send mail
IF lt_success[] IS NOT INITIAL.
** --SEND MAIL
CALL FUNCTION 'ZSEND_MAIL_OLIMMS'
TABLES
lt_mail = lt_success[].
ENDIF.
ENDMETHOD.
No comments:
Post a Comment