SFORM
SFORM
SFORM
lt_zbibd-house_no = wa_bp_address-house_num1.
lt_zbibd-street = wa_bp_address-street.
CONCATENATE wa_bp_address-city1 wa_bp_address-city2 INTO lt_zbibd-city
SEPARATED BY ''.
* lt_zbibd-city = wa_bp_address-city1.
lt_zbibd-postl_cod1 = wa_bp_address-post_code1.
CONCATENATE wa_bp_address-str_suppl1 ',' wa_bp_address-
str_suppl2 INTO lt_zbibd-str_suppl1.
* lt_zbibd-str_suppl1 = wa_bp_address-str_suppl1.
* lt_zbibd-str_suppl2 = wa_bp_address-str_suppl2.
lt_zbibd-str_suppl3 = wa_bp_address-str_suppl3.
CLEAR: lv_dt2,lv_datum,lv_header11.
lv_dt2 = lv_month+0(3).
CONCATENATE lv_dt2 '-' lv_dt1 INTO lv_datum.
lt_zbibd-bill_month = lv_datum.
TRANSLATE lt_zbibd-bill_month TO UPPER CASE.
************MOBILE NUMBER********************************************
SELECT * FROM adr2 INTO TABLE it_mob
WHERE addrnumber = wa_bus_part-addrnumber.
IF NOT it_mob IS INITIAL.
SORT it_mob BY consnumber DESCENDING.
LOOP AT it_mob INTO wa_mob.
IF wa_mob-r3_user = '2' OR wa_mob-r3_user = '3'.
lt_zbibd-mob_no = wa_mob-tel_number.
EXIT.
ELSEIF wa_mob-r3_user = '' OR wa_mob-r3_user = '1'.
lt_zbibd-mob_no = wa_mob-tel_number.
ENDIF.
ENDLOOP.
ENDIF.
FREE it_mob.
********************logic for Rate Category******added on 15.06.2016
IF NOT t_doc_item[] IS INITIAL.
v_doc_item = t_doc_item[].
DELETE v_doc_item WHERE erchbelnr IS INITIAL OR
tariftyp IS INITIAL.
SORT v_doc_item BY bis DESCENDING.
READ TABLE v_doc_item INTO wa_vdoc INDEX 1.
IF sy-subrc = 0.
lt_zbibd-tariff_type = wa_vdoc-tariftyp.
ENDIF.
FREE v_doc_item.
ENDIF.
**************logic ended for Rate Category******on 15.06.2016
******************SBM Flag*************************************
IF sy-uname = 'SYS_SBM'. "cprog = 'ZRPT_SBM_INBOUND'.
lt_zbibd-sbm = 'X'.
ENDIF.
****************Getting Previous Doc ROUND,ROUNDO amount
*****added by TMKIRAND for ROUNDO value
IF NOT wa_prev_doc_h-opbel IS INITIAL.
** SELECT printdoc printdocline nettobtr FROM dberdl
** INTO TABLE it_dberdl WHERE printdoc = wa_prev_doc_h-opbel
** AND ( belzart = 'ROUNDO' OR belzart =
'ROUND' ).
SELECT SINGLE date_of_invoice pymt_on_account net_amt_pybl
FROM zbibd INTO (last_budat,payment_acc,v_arrear_chrg)
WHERE invoiceno = wa_prev_doc_h-opbel.
IF sy-subrc NE 0.
SELECT SINGLE date_of_invoice pymt_on_account net_amt_pybl
FROM zbibd_hist INTO (last_budat,payment_acc,v_arrear_chrg)
WHERE invoiceno = wa_prev_doc_h-opbel.
ENDIF.
v_pybl_bibd = v_arrear_chrg.
ENDIF.
*****end of code by TMKIRAND for ROUNDO value
******** Date of Billing*********
lt_zbibd-date_of_invoice = x_doc_header-budat.
v_creation_date = x_doc_header-erdat.
v_creation_time = x_doc_header-creation_time.
* SELECT SINGLE butxt FROM zcs_company INTO lv_header11 WHERE bukrs = wa_c
ont_acct-opbuk.
* End of Company code Logic
***********end of Barcode********************************
**********Print Document******************************
CLEAR: t_erdz,t_erdz1,t_erdz2,t_erdz3,t_erdz4,v_sc_belnr1.
lv_opl = x_doc_header-opbel.
t_erdz1[] = t_erdz[].
t_erdz2[] = t_erdz[] .
t_erdz3[] = t_erdz[].
t_erdz4[] = t_erdz[].
CLEAR wa_erdz1.
READ TABLE t_erdz1 INTO wa_erdz1 INDEX 1.
v_sc_belnr1 = wa_erdz1-awkey.
CLEAR: lc_recorded,lv_other_charges,lv_other_charges2,lv_other_charges11.
CLEAR: lv_daats,lv_daats_ab.
it_docitem = xyt_doc_item[].
***************************************************************************
****************************
CLEAR : lt_dfkklocks,lt_dfkklock_h,t_dfkkop,
lw_dfkklocks,lw_dfkklock_h.
******************************CONVERSION FACTOR****************************
***
IF cfac IS INITIAL AND wa_conversion-
umwfakt IS NOT INITIAL AND wa_conversion-umwgrund EQ '7'.
cfac = wa_conversion-umwfakt.
ENDIF.
*****************PREMISE TEXT*******************************
IF lt_zbibd-pss_name IS INITIAL AND wa_premise-zz_psstxt IS NOT INITIAL.
lt_zbibd-pss_name = wa_premise-zz_psstxt.
ENDIF.
***************LOGIC FOR FETCHING INSTALLATION*****************
IF v_anlage IS INITIAL AND wa_install-anlage IS NOT INITIAL
AND ( lv_daats BETWEEN wa_install-
ab AND wa_install-bis ).
v_anlage = wa_install-anlage.
lt_zbibd-mru = wa_install-ableinh.
ENDIF.
**********************Premise number***************************
IF lv_premise IS INITIAL AND wa_premise-vstelle IS NOT INITIAL.
lv_premise = wa_premise-vstelle.
ENDIF.
*******************METER number and Meter Phase****************************
*******
IF lt_zbibd-meter_no IS INITIAL AND wa_equip-equnr IS NOT INITIAL
AND ( lv_daats BETWEEN wa_equip-ab AND wa_equip-
bis ).
* AND wa_equip-bis EQ '99991231'.
* BREAK-POINT.
lt_zbibd-meter_no = wa_equip-equnr.
lv_no = wa_equip-equnr. "wa_ablesebel-gernr.
SELECT SINGLE zwgruppe equnr logiknr FROM egerh INTO wa_egerh
WHERE equnr = lv_no AND bis = '99991231'.
* lv_egerh1 = wa_egerh-zwgruppe+0(1).
* IF lv_egerh1 = '1'.
* lt_zbibd-meter_phase = 'SINGLE PHASE'.
* ELSEIF lv_egerh1 = '3'.
* lt_zbibd-meter_phase = 'THREE PHASE'.
* ENDIF.
CLEAR: lv_no,lv_egerh1.
ENDIF.
*******************Meter RATIO****************************************
IF lt_zbibd-meter_ratio IS INITIAL AND ( NOT wa_equip-
zstromp IS INITIAL OR
NOT wa_equip-
zstroms IS INITIAL ).
text1 = wa_equip-zstromp.
text2 = wa_equip-zstroms.
dec1 = wa_equip-zstromp / wa_equip-zstroms.
tot1 = dec1.
CONDENSE:text1,text2,tot1.
CONCATENATE text1 '/' text2 INTO lt_zbibd-
meter_ratio RESPECTING BLANKS.
* CONCATENATE text1 '/' text2 ' = ' tot1 INTO lt_zbibd-
meter_ratio RESPECTING BLANKS.
CONDENSE lt_zbibd-meter_ratio.
CLEAR: text1,text2,dec1,tot1.
ENDIF.
**********************SUPPLY VOLTAGE***************************
IF lt_zbibd-supply_voltage IS INITIAL AND NOT wa_install-
spebene IS INITIAL
AND ( lv_daats BETWEEN wa_install-
ab AND wa_install-bis ).
* wa_install-
bis EQ '99991231'.
SELECT SINGLE text30 FROM te369t INTO lt_zbibd-supply_voltage
WHERE spebene = wa_install-spebene AND spras = 'EN'.
ENDIF.
* IF lv_eabl IS INITIAL.
* lv_eabl = wa_doc_item-ablbelnr.
* ENDIF.
IF bluetooth IS INITIAL.
IF wa_material-funklas = '1013'.
bluetooth = 'X'.
ENDIF.
ENDIF.
IF lv_matnr IS INITIAL.
lv_matnr = wa_material-matnr.
ENDIF.
IF lv_bauklas IS INITIAL.
lv_bauklas = wa_material-bauklas.
ENDIF.
**********Logic for Feeder Name*********
IF lt_zbibd-feeder_type IS INITIAL.
lv_feeder_code = wa_premise-zz_feeder.
CALL FUNCTION 'CONVERSION_EXIT_TPLNR_OUTPUT'
EXPORTING
input = lv_feeder_code
IMPORTING
output = lv_feeder_code.
SHIFT lv_feeder_code LEFT DELETING LEADING ' ' .
lv_feeder_code = lv_feeder_code+13(3).
lt_zbibd-feeder_type = lv_feeder_code.
CLEAR lv_feeder_code.
ENDIF.
lt_zbibd-dt_code = obj_temp+19(3).
CLEAR obj_temp.
ENDIF.
IF lv_adatsoll LT wa_ablesebel-adatsoll.
lv_adatsoll = wa_ablesebel-adatsoll.
ENDIF.
*********************Pole no********************************
lt_zbibd-pole_no = obj_temp. "+24(4).
obj_temp = obj_temp+0(16).
CONDENSE lt_zbibd-pole_no.
CLEAR: lt_alloclist,ls_alloclist,lt_class,lt_objectdata,obj_temp.
ENDIF.
ENDIF.
lt_zbibd-sub_div_code = wa_conn_obj-regiogroup.
lt_zbibd-sub_div_name = sub_division.
lt_zbibd-division_code = div.
lt_zbibd-division_name = division1.
lt_zbibd-circle = circle1.
CLEAR: sub_division,div,division1,circle1,cir.
ENDIF.
ENDIF.
* BREAK-POINT.
***********LOGIC FOR ENERGY CALCULATIONS***********************************
***
IF x_doc_item-belzart NE 'Z99999' .
IF x_doc_item-belzart = 'ZOLPPI'.
* For Non HT cases online_rebate field is used for ZOLPPI and for HT cases
this field
* is used for Z148 line item ,
IF lt_zbibd-tariff_type+0(2) <> 'HT' AND lt_zbibd-
tariff_type+0(2) <> 'RT'.
lt_zbibd-online_rebate = lt_zbibd-online_rebate + x_doc_item-
nettobtr.
ENDIF.
online_rebate = online_rebate + x_doc_item-nettobtr.
ENDIF.
IF x_doc_item-sc_belnr = ''.
IF x_doc_item-buchrel = 'X'.
* IF ( x_doc_item-belzart = 'ZENERG' OR x_doc_item-belzart = 'ZMMC') .
lt_zbibd-excess_demand_chrg = lt_zbibd-
excess_demand_chrg + x_doc_item-nettobtr.
ELSEIF ( x_doc_item-belzart = 'ZFIX' OR x_doc_item-
belzart = 'ZKW' OR
x_doc_item-belzart = 'HP' OR x_doc_item-belzart = 'ZKVA').
lt_zbibd-fixed_demand_chrg = lt_zbibd-
fixed_demand_chrg + x_doc_item-nettobtr.
******added by KiranD B10K902722*****************************
****commented by TMKIRAND on 06.05.2017 for pl adj.*****
* IF lt_zbibd-tariff_type NE 'DS-IID' .
* wa_fix-rate = x_doc_item-tariftyp.
* wa_fix-belzart = x_doc_item-belzart.
* wa_fix-nettobtr = x_doc_item-nettobtr.
* wa_fix-ab = x_doc_item-ab.
* wa_fix-bis = x_doc_item-bis.
* wa_fix-belnr = x_doc_item-sc_belnr.
* APPEND wa_fix TO it_fix.
* CLEAR: wa_fix.
* ENDIF.
*******end of comment by TMKIRAND on 06.05.2017 for pl adj.*****
******end of addition by KiranD B10K902722*******************
* IF x_doc_item-belzart = 'ZFIX'.
max_dem = x_doc_item-preisbtr.
* ENDIF.
ELSEIF x_doc_item-belzart = 'ZMTRR' .
lt_zbibd-meter_rent = lt_zbibd-meter_rent + x_doc_item-nettobtr.
ELSEIF x_doc_item-belzart = 'ZMCGST' .
lt_zbibd-meter_cgst = lt_zbibd-meter_cgst + x_doc_item-nettobtr.
ELSEIF x_doc_item-belzart = 'ZMSGST' .
lt_zbibd-meter_sgst = lt_zbibd-meter_sgst + x_doc_item-nettobtr.
ELSEIF x_doc_item-belzart = 'ZSTCCH' .
lt_zbibd-shunt_cap_charge = lt_zbibd-
shunt_cap_charge + x_doc_item-nettobtr.
ELSEIF x_doc_item-belzart = 'ZMMCFN' .
wa_charges-others = wa_charges-others + x_doc_item-nettobtr.
ELSEIF x_doc_item-belzart = 'ZFPCA' .
lt_zbibd-fppca_charges = lt_zbibd-fppca_charges + x_doc_item-
nettobtr.
ELSEIF x_doc_item-belzart = 'ZMTVAT' .
lt_zbibd-vat_on_meter_rent = lt_zbibd-
vat_on_meter_rent + x_doc_item-nettobtr.
* ELSEIF ( x_doc_item-belzart = 'ZSTAFF' OR x_doc_item-
belzart = 'ZBSFIX' ).
ELSEIF x_doc_item-belzart = 'ROUNDO' OR x_doc_item-
belzart = 'ROUND'.
* lv_incentive = lv_incentive + x_doc_item-nettobtr.
* Changes by TMSUDHAKARP #B10K902635
IF creation_date LE '20140910'.
IF x_doc_item-belzart = 'ROUNDO'.
IF x_doc_item-nettobtr LT '.5'.
neg_roundo = neg_roundo + x_doc_item-nettobtr.
ELSE.
* End changes by TMSUDHAKARP #B10K902635
IF last_date IS INITIAL.
ELSEIF x_doc_item-nettobtr LT '.5'.
ELSE.
lt_zbibd-incentive_charge = lt_zbibd-
incentive_charge + x_doc_item-nettobtr..
ENDIF.
ENDIF.
ENDIF.
ELSE.
neg_roundo = neg_roundo + x_doc_item-nettobtr.
ENDIF.
ELSEIF ( x_doc_item-belzart = 'ZIIPRB' OR x_doc_item-
belzart = 'ZIPDPS').
* wa_charges-mmc_rebate = wa_charges-mmc_rebate + x_doc_item-
nettobtr.
lt_zbibd-incentive_under_iip = lt_zbibd-
incentive_under_iip + x_doc_item-nettobtr.
ELSEIF x_doc_item-belzart = 'ZVOLTA'.
lt_zbibd-voltage_surcharge = lt_zbibd-
voltage_surcharge + x_doc_item-nettobtr.
ELSEIF x_doc_item-belzart = 'Z1H1'.
tod_flag = 'X'.
lv_basis = 'Actual'.
lt_zbibd-energy_charge_1h1 = lt_zbibd-
energy_charge_1h1 + x_doc_item-nettobtr.
1h1_rate = x_doc_item-preisbtr.
ELSEIF x_doc_item-belzart = 'Z2H1'.
tod_flag = 'X'.
lv_basis = 'Actual'.
lt_zbibd-energy_charge_2h1 = lt_zbibd-
energy_charge_2h1 + x_doc_item-nettobtr.
2h1_rate = x_doc_item-preisbtr.
ELSEIF x_doc_item-belzart = 'Z3H1'.
tod_flag = 'X'.
lv_basis = 'Actual'.
lt_zbibd-energy_charge_3h1 = lt_zbibd-
energy_charge_3h1 + x_doc_item-nettobtr.
3h1_rate = x_doc_item-preisbtr.
ELSEIF x_doc_item-belzart = 'ZSURCH'.
lt_zbibd-voltage_surcharge = lt_zbibd-
voltage_surcharge + x_doc_item-nettobtr.
ELSEIF x_doc_item-belzart = 'ZTRNCH'.
lt_zbibd-transformer_rent = lt_zbibd-
transformer_rent + x_doc_item-nettobtr.
ELSEIF ( x_doc_item-belzart = 'ZPFSUR' OR x_doc_item-
belzart = 'ZPFREB' ).
lt_zbibd-pf_surchg_rebate = lt_zbibd-
pf_surchg_rebate + x_doc_item-nettobtr.
ELSEIF x_doc_item-belzart = 'ZEDIIP' AND ( x_doc_item-
tariftyp+0(2) EQ 'HT' OR
x_doc_item-
tariftyp+0(2) EQ 'RT') .
lt_zbibd-remission = lt_zbibd-remission + x_doc_item-nettobtr.
ELSEIF x_doc_item-belzart = 'ZEDIIP' AND ( x_doc_item-
tariftyp+0(2) NE 'HT' AND
x_doc_item-
tariftyp+0(2) NE 'RT') .
lt_zbibd-incentive_under_iip = lt_zbibd-
incentive_under_iip + x_doc_item-nettobtr.
* lt_zbibd-other_charges = lt_zbibd-other_charges + x_doc_item-
nettobtr.
* wa_fix-rate = x_doc_item-tariftyp.
* wa_fix-belzart = x_doc_item-belzart.
* wa_fix-nettobtr = x_doc_item-nettobtr.
* wa_fix-ab = x_doc_item-ab.
* wa_fix-bis = x_doc_item-bis.
* wa_fix-belnr = x_doc_item-sc_belnr.
* APPEND wa_fix TO it_fix.
* v_z131 = v_z131 + x_doc_item-nettobtr.
* CLEAR: wa_fix.
ELSEIF x_doc_item-belzart = 'ZDPS' OR x_doc_item-
belzart = 'ZPPI' OR x_doc_item-belzart = 'ZLEGRB'.
* Code inserted by venkat B10K907825
ELSEIF x_doc_item-belzart = 'ZREAOP'.
lt_zbibd-reactive_chrg = lt_zbibd-reactive_chrg + x_doc_item-
nettobtr.
open_access = 'X'.
ELSEIF x_doc_item-belzart = 'ZCSSOP'.
lt_zbibd-cross_subsidy = lt_zbibd-cross_subsidy + x_doc_item-
nettobtr.
* v_css_rate = x_doc_item-preisbtr.
* v_css_unit = x_doc_item-i_abrmenge.
ELSEIF x_doc_item-belzart = 'ZENGOV' OR x_doc_item-
belzart = 'ZFXGOV'.
lt_zbibd-gov_subsidy = lt_zbibd-gov_subsidy + x_doc_item-
nettobtr.
IF x_doc_item-belzart = 'ZENGOV' AND zextra-gov_sub IS INITIAL.
v_gov_sub = x_doc_item-preisbtr.
zextra-gov_sub = v_gov_sub.
CONDENSE zextra-gov_sub.
ENDIF.
IF x_doc_item-xtotal_amnt = 'X'.
IF x_doc_item-hvorg = '0100'." AND
* ( x_doc_item-tvorg = '0010' OR x_doc_item-tvorg = '0020' OR
* x_doc_item-tvorg = '0011' OR x_doc_item-tvorg = '0021' OR
* x_doc_item-tvorg = '0038' OR x_doc_item-tvorg = '0048' OR
* x_doc_item-tvorg = '0016' OR x_doc_item-tvorg = '0026' ).
*****************Logic for Electricity Dues********************************
*
IF x_doc_item-tvorg = '0022' OR x_doc_item-tvorg = '0012'.
lt_zbibd-arrear_ed = lt_zbibd-arrear_ed + x_doc_item-nettobtr.
ELSE.
lt_zbibd-arrear_energy = lt_zbibd-arrear_energy + x_doc_item-
nettobtr.
ENDIF.
*****************Logic for Electricity Dues********************************
*
* ELSEIF x_doc_item-hvorg = '0100' AND
* ( x_doc_item-tvorg = '0022' OR x_doc_item-tvorg = '0012' ).
* lt_zbibd-arrear_ed = lt_zbibd-arrear_ed + x_doc_item-nettobtr.
ELSEIF x_doc_item-hvorg = 'ZCN2'." OR x_doc_item-hvorg = 'ZCN6'.
lt_zbibd-arrear_ed = lt_zbibd-arrear_ed + x_doc_item-nettobtr.
***************DPS *********************************************
ELSEIF x_doc_item-hvorg = 'Z111' AND ( x_doc_item-tvorg = '0010' OR
x_doc_item-tvorg = '0020' ).
* wa_dps-date = x_doc_item-faedn.
* wa_dps-budat = x_doc_item-budat.
* wa_dps-dps = x_doc_item-nettobtr.
* wa_dps-item = x_doc_item-belzart.
* APPEND wa_dps TO it_dps.
ELSEIF x_doc_item-hvorg = 'ZCN4' OR x_doc_item-hvorg = 'ZDP1'.
wa_dps-date = x_doc_item-faedn.
wa_dps-budat = x_doc_item-budat.
wa_dps-dps = x_doc_item-nettobtr.
wa_dps-item = x_doc_item-hvorg.
APPEND wa_dps TO it_dps.
IF x_doc_item-hvorg = 'ZDP1'.
gv_zcn3 = gv_zcn3 + x_doc_item-nettobtr.
ENDIF.
ELSEIF x_doc_item-hvorg = '0080' AND x_doc_item-tvorg = '0010'.
IF x_doc_item-belzart = 'SYNCDD'.
****************0080, 0010 can be for Normal installment or FPPCA installme
nt.
*****below logic is written to check for FPPCA, if this fails then its Norm
al Instlment
SELECT SINGLE * FROM fkk_instpln_hist INTO ls_fkk_instal
WHERE rpnum = x_doc_item-ca_opbel.
IF sy-subrc = 0.
CLEAR ls_dfkk_instal.
SELECT SINGLE * FROM dfkkop INTO ls_dfkk_instal
WHERE opbel = ls_fkk_instal-opbel
AND hvorg = 'Z123'.
IF sy-subrc = 0.
lt_zbibd-fppca_charges = lt_zbibd-
fppca_charges + x_doc_item-nettobtr.
ELSE.
lt_zbibd-installment_amount = lt_zbibd-
installment_amount +
x_doc_item-nettobtr.
ENDIF.
ELSE.
lt_zbibd-installment_amount = lt_zbibd-installment_amount +
x_doc_item-nettobtr.
ENDIF.
ELSEIF x_doc_item-belzart = 'ACCINF' OR x_doc_item-
belzart = 'ACCMNT'.
lt_zbibd-arrear_other_chg = lt_zbibd-
arrear_other_chg + x_doc_item-nettobtr.
ENDIF.
ELSEIF x_doc_item-hvorg = 'ZCN9' AND x_doc_item-tvorg = '0020'.
CLEAR lv_daats.
lv_daats = lt_zbibd-date_of_invoice + 15.
IF x_doc_item-faedn BETWEEN lt_zbibd-
date_of_invoice AND lv_daats.
lt_zbibd-installment_amount = lt_zbibd-
installment_amount + x_doc_item-nettobtr.
ELSEIF x_doc_item-faedn GT lv_daats.
ELSE.
lt_zbibd-arrear_other_chg = lt_zbibd-
arrear_other_chg + x_doc_item-nettobtr.
ENDIF.
ELSEIF x_doc_item-hvorg = 'RUND' AND x_doc_item-tvorg = '0010'.
IF creation_date LE '20140910'.
IF last_budat EQ x_doc_item-budat AND payment_acc LT 0.
last_rund = last_rund + x_doc_item-nettobtr.
ENDIF.
ELSE.
last_rund = last_rund + x_doc_item-nettobtr.
ENDIF.
wa_fix-rate = x_doc_item-tariftyp.
wa_fix-belzart = x_doc_item-belzart.
wa_fix-nettobtr = x_doc_item-nettobtr.
wa_fix-ab = x_doc_item-ab.
wa_fix-bis = x_doc_item-bis.
wa_fix-belnr = x_doc_item-sc_belnr.
APPEND wa_fix TO it_fix.
CLEAR: wa_fix.
v_z131 = v_z131 + x_doc_item-nettobtr.
ELSE.
lt_zbibd-arrear_other_chg = lt_zbibd-
arrear_other_chg + x_doc_item-nettobtr.
ENDIF.
ENDIF.
ENDIF.
ELSE.
lt_zbibd-ppi_levied = lt_zbibd-ppi_levied + x_doc_item-
nettobtr.
ENDIF.
* IF x_doc_item-hvorg = 'Z131' OR x_doc_item-hvorg = 'Z134'.
* v_z131 = v_z131 + x_doc_item-nettobtr.
* ENDIF.
ENDIF.
ENDIF.
IF x_doc_item-hvorg = 'Z111'. "AND ( x_doc_item-
tvorg = '0010' OR x_doc_item-tvorg = '0020' ).
wa_dps-date = x_doc_item-faedn.
wa_dps-budat = x_doc_item-budat.
wa_dps-dps = x_doc_item-nettobtr.
wa_dps-item = x_doc_item-hvorg.
APPEND wa_dps TO it_dps.
ELSEIF x_doc_item-hvorg = 'Z144'.
lt_zbibd-amt_abey_with_dps = lt_zbibd-
amt_abey_with_dps + x_doc_item-nettobtr.
* lt_zbibd-arrear_other_chg = lt_zbibd-
arrear_other_chg + x_doc_item-nettobtr.
ENDIF.
* Begin of changes by TMSUDHAKARP #B10K902635
* WHEN 'ROUNDO' .
* IF x_doc_item-hvorg = 'RUND'
* AND x_doc_item-tvorg = '0010'
* AND x_doc_item-nettobtr LT 0.
* v_arrear_chrg = v_arrear_chrg + x_doc_item-nettobtr.
* ENDIF.
* End of changes by TMSUDHAKARP #B10K902635
WHEN OTHERS.
ENDCASE.
END OF ty_egers.
BEGIN OF ty_dfkkrp,
aedat TYPE dfkkrp-aedat,
opbel TYPE dfkkrp-opbel,
END OF ty_dfkkrp,
BEGIN OF ty_dfkzp,
selw1 TYPE dfkkzp-selw1,
budat TYPE dfkkzp-budat,
valut TYPE dfkkzp-valut,
txtvw TYPE dfkkzp-txtvw,
chckn TYPE dfkkzp-chckn,
END OF ty_dfkzp.
BEGIN OF ty_dfkkzp,
budat TYPE dfkkzp-budat,
klaeb TYPE dfkkzp-klaeb,
opbel TYPE dfkkzp-opbel,
ruebl TYPE dfkkzp-ruebl,
ruear TYPE dfkkzp-ruear,
END OF ty_dfkkzp,
BEGIN OF ty_dfkkko,
opbel TYPE dfkkko-opbel,
cpudt TYPE dfkkko-cpudt,
cputm TYPE dfkkko-cputm,
END OF ty_dfkkko.
IF v_anlage IS INITIAL.
v_anlage = v_anlage2.
ENDIF.
IF lt_zbibd-meter_phase IS INITIAL.
LOOP AT it_ettifn INTO wa_ettifn WHERE ( operand = '1PH' OR operand = '
3PH'
OR operand = '1_PHASE' OR oper
and = '3_PHASE') AND
bis = '99991231' AND
ab LE lt_zbibd-
date_of_invoice.
IF wa_ettifn-operand = '1PH' OR wa_ettifn-operand = '1_PHASE'.
lt_zbibd-meter_phase = 'SINGLE PHASE'.
ELSEIF wa_ettifn-operand = '3PH' OR wa_ettifn-operand = '3_PHASE'.
lt_zbibd-meter_phase = 'THREE PHASE'.
ENDIF.
EXIT.
ENDLOOP.
ENDIF.
ENDIF.
SELECT equnr
zspanns
zspannp
zstromp
zstroms
FROM egers INTO TABLE it_egers
FOR ALL ENTRIES IN it_egerh
WHERE equnr = it_egerh-equnr.
ENDIF.
ENDIF.
ENDIF.
IF it_egerh1[] IS NOT INITIAL.
SELECT wgruppe
wtyp
wspann
wstrom
FROM ewik INTO TABLE it_ewik1
FOR ALL ENTRIES IN it_egerh1
WHERE wgruppe = it_egerh1-wgruppe AND
wtyp = '2'.
CLEAR:zspanns,zspannp,zstromp,zstroms,
wspann,wstrom,wspann1,wstrom1,
zspannsc,zspannpc,zstrompc,zstromsc,
wspannc,wstromc,wspann1c,wstrom1c.
LOOP AT it_eastl INTO wa_eastl.
"""""""""""""Meter Primary CT/PT Ratio, Meter Secondary CT/PT Rat
io"""""
READ TABLE it_egerh INTO wa_egerh WITH KEY logiknr = wa_eastl-
logiknr.
IF sy-subrc = 0.
READ TABLE it_egers INTO wa_egers WITH KEY equnr = wa_egerh-
equnr.
IF sy-subrc = 0.
zspanns = wa_egers-zspanns.
zspannp = wa_egers-zspannp.
zstromp = wa_egers-zstromp.
zstroms = wa_egers-zstroms.
ENDIF.
ENDIF.
CLEAR lv_num1.
lv_num1 = zspannp .
IF lv_num1 CA '.'.
PERFORM delete_zero.
zspannpc = lv_num1.
ELSE.
zspannpc = zspannp.
CONDENSE zspannpc NO-GAPS.
ENDIF.
CLEAR lv_num1.
lv_num1 = zspanns .
IF lv_num1 CA '.'.
PERFORM delete_zero.
zspannsc = lv_num1.
ELSE.
zspannsc = zspanns.
CONDENSE zspannsc NO-GAPS.
ENDIF.
CLEAR lv_num1.
lv_num1 = zstromp .
IF lv_num1 CA '.'.
PERFORM delete_zero.
zstrompc = lv_num1.
ELSE.
zstrompc = zstromp.
CONDENSE zstrompc NO-GAPS.
ENDIF.
CLEAR lv_num1.
lv_num1 = zstroms .
IF lv_num1 CA '.'.
PERFORM delete_zero.
zstromsc = lv_num1.
ELSE.
zstromsc = zstroms.
CONDENSE zstromsc NO-GAPS.
ENDIF.
CLEAR lv_num1.
lv_num1 = wstrom .
IF lv_num1 CA '.'.
PERFORM delete_zero.
wstromc = lv_num1.
ELSE.
wstromc = wstrom.
CONDENSE wstromc NO-GAPS.
ENDIF.
CLEAR lv_num1.
lv_num1 = wstrom1 .
IF lv_num1 CA '.'.
PERFORM delete_zero.
wstrom1c = lv_num1.
ELSE.
wstrom1c = wstrom1.
CONDENSE wstrom1c NO-GAPS.
ENDIF.
CLEAR lv_num1.
lv_num1 = wspann .
IF lv_num1 CA '.'.
PERFORM delete_zero.
wspannc = lv_num1.
ELSE.
wspannc = wspann.
CONDENSE wspannc NO-GAPS.
ENDIF.
CLEAR lv_num1.
lv_num1 = wspann1 .
IF lv_num1 CA '.'.
PERFORM delete_zero.
wspann1c = lv_num1.
ELSE.
wspann1c = wspann1.
CONDENSE wspann1c NO-GAPS.
ENDIF.
IF zspannpc <> '0' AND zspannsc <> '0'.
CONCATENATE zspannpc zspannsc INTO zextra-mpt SEPARATED BY '/'.
ENDIF.
IF zstrompc <> '0' AND zstromsc <> '0'.
CONCATENATE zstrompc zstromsc INTO zextra-mct SEPARATED BY '/'.
ENDIF.
IF wstromc <> '0' AND wstrom1c <> '0'.
CONCATENATE wstromc wstrom1c INTO zextra-muct SEPARATED BY '/'.
ENDIF.
IF wspannc <> '0' AND wspann1c <> '0'.
CONCATENATE wspannc wspann1c INTO zextra-mupt SEPARATED BY '/'.
ENDIF.
* BREAK-POINT.
****************FeederName/Feeder Type for HT consumers***************
SELECT SINGLE * FROM euiinstln INTO wa_euiinstln
WHERE anlage = v_anlage AND dateto = '99991231'.
IF NOT wa_euiinstln-int_ui IS INITIAL.
SELECT SINGLE * FROM euigrid INTO wa_euigrid
WHERE int_ui = wa_euiinstln-int_ui
AND dateto = '99991231'.
IF NOT wa_euigrid-grid_id IS INITIAL.
SELECT SINGLE * FROM egridt INTO wa_egridt
WHERE grid_id = wa_euigrid-grid_id.
IF NOT wa_egridt-grid_name IS INITIAL.
lt_zbibd-feeder_name = wa_egridt-grid_name."(feeder code)
SELECT SINGLE * FROM zedm_fdrtype INTO wa_fdrtype
WHERE feedercode = wa_egridt-grid_name.
IF wa_fdrtype-feedertype = 'U'.
lt_zbibd-feeder_type = 'Urban'.
ELSEIF wa_fdrtype-feedertype = 'R'.
lt_zbibd-feeder_type = 'Rural'.
ELSEIF wa_fdrtype-feedertype = 'M'.
lt_zbibd-feeder_type = 'Mix'.
ENDIF.
* SELECT SINGLE * FROM iflotx INTO wa_iflotx
* WHERE tplnr = wa_egridt-grid_name.
* IF NOT wa_iflotx-pltxt IS INITIAL.
** lt_zbibd-feeder_text = wa_iflotx-pltxt.
* ENDIF.
ENDIF.
ENDIF.
ENDIF.
****************FeederName/Feeder Type for HT consumers***************
ENDIF.
ENDIF.
*+ CT/PT Ratio Logic****************
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
*+chequ dishonour logic
*****************Unmetered Flag**************************************
IF lt_zbibd-tariff_type = 'DS-IU' OR lt_zbibd-tariff_type = 'IAS-IIU' OR
lt_zbibd-tariff_type = 'IAS-IU' OR lt_zbibd-
tariff_type = 'KJ_BPL_RU' OR
lt_zbibd-tariff_type = 'NDS-IU' OR lt_zbibd-tariff_type = 'SS-II'.
lt_zbibd-unmetered = 'X'.
ENDIF.
****************************Installation***********************************
***
lt_zbibd-anlage = v_anlage.
****************Logic for LOAD AND DEMAND**********************************
**********
SELECT belnr FROM erchc INTO TABLE t_erchc22 WHERE opbel = wa_doc_header-
opbel.
IF NOT t_erchc22 IS INITIAL.
SELECT begabrpe endabrpe abrvorg sc_belnr_h FROM erch INTO TABLE t_erch
_ammend
FOR ALL ENTRIES IN t_erchc22 WHERE belnr = t_erchc22-belnr.
********Bill Month************************************************8
IF lt_zbibd-bill_month IS INITIAL OR
lt_zbibd-bill_month EQ '-'.
CLEAR: lv_month,lv_dt1,lv_dt2.
lv_dt1 = curr_bis+0(4).
lv_dt2 = curr_bis+4(2).
mon_no = lv_dt2.
SELECT SINGLE monam FROM t015m INTO lv_month WHERE monum = lv_dt2
AND spras EQ 'EN'.
CLEAR: lv_dt2,lv_datum,lv_header11.
lv_dt2 = lv_month+0(3).
CONCATENATE lv_dt2 '-' lv_dt1 INTO lv_datum.
lt_zbibd-bill_month = lv_datum.
TRANSLATE lt_zbibd-bill_month TO UPPER CASE.
ENDIF.
CLEAR: tt_ettifn_1.
CLEAR: tt_ettifn_1,wa_zdm_mmc.",lv_ta11,lv_ta22,lv_ta1,lv_ta2,lv_ta31,l
v_ta33.
ENDIF.
********************************************************
SELECT ablbelnr
adatsoll
FROM eablg INTO TABLE temp_eablg
WHERE anlage = v_anlage
AND ( adatsoll LE lv_adatsoll AND adatsoll GE dt1 ).
LOOP AT temp_eablg INTO wa_eablg WHERE adatsoll = lv_adatsoll.
APPEND wa_eablg TO t_eablg.
ENDLOOP.
IF t_eablg IS NOT INITIAL.
SELECT ablbelnr equnr zwnummer adat
v_zwstand n_zwstand adatsoll ablhinw
aedat
FROM eabl
INTO TABLE temp_eabl
FOR ALL ENTRIES IN temp_eablg
WHERE ablbelnr = temp_eablg-ablbelnr.
* AND zwnummer = '001'.
LOOP AT temp_eabl INTO wa_eabl WHERE adatsoll = lv_adatsoll.
APPEND wa_eabl TO t_eabl.
ENDLOOP.
READ TABLE t_eabl INTO wa_eabl WITH KEY register = '001'.
IF sy-subrc EQ '0'.
IF wa_eabl-ablhinw = 'PA'.
lt_zbibd-meter_status = 'Premise Locked'.
ELSEIF wa_eabl-ablhinw = ''.
lt_zbibd-meter_status = 'Meter Ok'.
ELSE.
SELECT SINGLE tablhinw
FROM te259t
INTO lt_zbibd-meter_status
WHERE ablhinw = wa_eabl-ablhinw
AND spras EQ 'EN'.
ENDIF.
ENDIF.
IF lt_zbibd-meter_status IS NOT INITIAL.
IF wa_eabl-ablhinw EQ 'RR' OR
wa_eabl-ablhinw EQ 'OK' OR
wa_eabl-ablhinw EQ '' OR
wa_eabl-ablhinw EQ 'RO'.
lt_zbibd-bill_status = lv_basis.
ELSE.
* CONCATENATE 'AVERAGE(' zform_str-mrnote ')' INTO lt_zbibd-
bill_status.
* CONDENSE lt_zbibd-bill_status.
**New Logic added for BILL_STATUS by considering ZBMUNT and ZMTCON items
SELECT SINGLE tablhinw FROM te259t INTO zextra-mrnote
WHERE spras = 'EN' AND ablhinw = wa_eabl-ablhinw.
IF lt_zbibd-minimum_unit GT zmtcon AND lt_zbibd-
tariff_type <> 'DS-II' AND
lt_zbibd-
tariff_type <> 'DS-IID' .
CONCATENATE 'MMC(' zextra-mrnote ')' INTO lt_zbibd-
bill_status.
CONDENSE lt_zbibd-bill_status.
ELSEIF lv_basis = 'MMC' AND ( lt_zbibd-
tariff_type = 'KJ_BPL_RM' OR
lt_zbibd-
tariff_type = 'KJ_BPL_U' ).
CONCATENATE 'MMC(' zextra-mrnote ')' INTO lt_zbibd-
bill_status.
CONDENSE lt_zbibd-bill_status.
ELSE.
CONCATENATE 'Average(' zextra-mrnote ')' INTO lt_zbibd-
bill_status.
CONDENSE lt_zbibd-bill_status.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
* IF NOT lt_zbibd-
other_charges IS INITIAL OR NOT lv_lt_leg_adj IS INITIAL.
IF pl_adj = 'X' OR NOT lv_lt_leg_adj IS INITIAL.
* IF v_z131 = lt_zbibd-other_charges.
* ELSE.
CONCATENATE '(PL Adj.)' lv_basis INTO lt_zbibd-
bill_status SEPARATED BY space .
* ENDIF.
ENDIF.
CLEAR lv_basis.
ENDIF.
ENDIF.
******end of addition by KiranD B10K902722*******************
*****************LOGIC FOR AREA TYPE************************************
SELECT SINGLE anlart FROM eanl INTO lv_area WHERE anlage = v_anlage.
IF lv_area = '1001'.
lt_zbibd-area_type = 'URBAN'.
ELSEIF lv_area = '1002'.
lt_zbibd-area_type = 'RURAL'.
ENDIF.
* IF lt_zbibd-meter_rent IS INITIAL.
* lt_zbibd-meter_provided_by = 'CONSUMER'.
* ELSE.
* lt_zbibd-meter_provided_by = 'COMPANY'.
* ENDIF.
CLEAR: ls_alloclist,lt_class,lt_objectdata,wa_objectdata.
READ TABLE lt_alloclist INTO ls_alloclist INDEX 1.
IF sy-subrc = 0.
CALL FUNCTION 'CLAF_CLASSIFICATION_OF_OBJECTS'
EXPORTING
class = ls_alloclist-classnum
classtext = 'X'
classtype = '002'
object = obj_temp
TABLES
t_class = lt_class
t_objectdata = lt_objectdata.
******************************POWER ON*************************************
*******
CLEAR: lwa_ettifn,lit_ettifn.
LOOP AT it_ettifn INTO wa_ettifn WHERE operand = 'POWER_ON'
AND ab LE lv_ab_date AND bis GE lv_end_date.
lt_zbibd-power_on_hours = wa_ettifn-wert1.
CONDENSE: lt_zbibd-power_on_hours.
ENDLOOP.
********************METERING RATIO*****************************************
*******
CLEAR: lt_eastl,t_wgruppe,wa_wgruppe,lt_ewik,ls_ewik,lv_text.
SELECT anlage logiknr bis ab FROM
eastl INTO TABLE lt_eastl
WHERE anlage = v_anlage
AND bis GE lv_end_date
AND ab LE lv_ab_date.
CLEAR ls_ewik.
READ TABLE lt_ewik INTO ls_ewik WITH KEY wtyp = '2'.
IF sy-subrc = 0.
lv_text = ls_ewik-wstrom.
SHIFT lv_text LEFT DELETING LEADING ' '.
CONCATENATE lt_zbibd-metering_unit_ratio lv_text INTO lt_zbibd-
metering_unit_ratio.
ENDIF.
* IF NOT ls_ewik-wstrom IS INITIAL.
* dec2 = dec2 / ls_ewik-wstrom.
* tot1 = dec2.
* CONDENSE tot1.
* CONCATENATE lt_zbibd-metering_unit_ratio ' = ' tot1 INTO lt_zbibd-
metering_unit_ratio." RESPECTING BLANKS.
* ELSE.
* tot1 = dec2.
* CONCATENATE lt_zbibd-metering_unit_ratio ' = ' tot1 INTO lt_zbibd-
metering_unit_ratio." RESPECTING BLANKS.
* ENDIF.
ENDIF.
IF lt_zbibd-tariff_type+0(2) = 'HT' OR
lt_zbibd-tariff_type+0(2) = 'RT'.
rang-low = 'BILED_KVAH'.
rang-high = 'BILED_KVAH'.
rang-sign = 'E'.
rang-option = 'EQ'.
APPEND rang.
ENDIF.
IF lt_zbibd-tariff_type+0(2) = 'LT'.
rang-low = 'MON_KVAH'.
rang-high = 'MON_KVAH'.
rang-sign = 'E'.
rang-option = 'EQ'.
APPEND rang.
ELSEIF lt_zbibd-tariff_type+0(2) = 'PU'.
rang-low = 'KVAH_CONS'.
rang-high = 'KVAH_CONS'.
rang-sign = 'E'.
rang-option = 'EQ'.
APPEND rang.
ELSEIF lt_zbibd-tariff_type+0(2) = 'DS' OR
lt_zbibd-tariff_type+0(3) = 'NDS'.
rang-low = 'MONTH_CONS'.
rang-high = 'MONTH_CONS'.
rang-sign = 'E'.
rang-option = 'EQ'.
APPEND rang.
ENDIF.
rang-low = 'BILL_BASIS'.
rang-high = 'BILL_BASIS'.
rang-sign = 'E'.
rang-option = 'EQ'.
APPEND rang.
rang-low = 'BILL_CONS'.
rang-high = 'BILL_CONS'.
rang-sign = 'E'.
rang-option = 'EQ'.
APPEND rang.
* ENDIF.
rang-low = 'RCORDED_DM'.
rang-high = 'RCORDED_DM'.
rang-sign = 'E'.
rang-option = 'EQ'.
APPEND rang.
lt_ett = it_ettifn.
IF lt_zbibd-tariff_type+0(2) = 'LT'.
CLEAR lv_wert11.
READ TABLE lt_ett INTO wa_ett WITH KEY operand = 'BILED_UNIT'
bis = '99991231'.
IF sy-subrc = 0.
IF '20170401' BETWEEN wa_ett-ab AND wa_ett-bis.
lv_wert11 = wa_ett-wert1.
READ TABLE lt_ett INTO wa_ett WITH KEY operand = 'MON_KVAH'
ab = wa_ett-ab.
IF sy-subrc = 0.
wa_ett-wert1 = wa_ett-wert1 + lv_wert11.
MODIFY lt_ett FROM wa_ett INDEX sy-tabix.
CLEAR wa_ett.
ENDIF.
ENDIF.
ENDIF.
ELSEIF lt_zbibd-tariff_type+0(2) = 'PU'.
CLEAR lv_wert11.
READ TABLE lt_ett INTO wa_ett WITH KEY operand = 'BILED_UNIT'
bis = '99991231'.
IF sy-subrc = 0.
IF '20170401' BETWEEN wa_ett-ab AND wa_ett-bis.
lv_wert11 = wa_ett-wert1.
READ TABLE lt_ett INTO wa_ett WITH KEY operand = 'KVAH_CONS'
ab = wa_ett-ab.
IF sy-subrc = 0.
wa_ett-wert1 = wa_ett-wert1 + lv_wert11.
MODIFY lt_ett FROM wa_ett INDEX sy-tabix.
CLEAR wa_ett.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ELSE.
LOOP AT lt_ett INTO wa_ett WHERE operand = 'BILED_UNIT' OR
operand = 'BILED_KVAH' OR
operand = 'MON_KVAH' OR
operand = 'KVAH_CONS'.
wa_ett-operand = 'MONTH_CONS'.
MODIFY lt_ett FROM wa_ett.
ENDLOOP.
ENDIF.
SORT lt_ett BY operand DESCENDING bis DESCENDING.
CLEAR: temp2,wa_temp2.
CALL FUNCTION 'ISU_DB_ERCHC_SELECT_OPBEL'
EXPORTING
x_opbel = lt_zbibd-invoiceno
TABLES
t_erchc = temp2
EXCEPTIONS
not_found = 1
system_error = 2
not_qualified = 3
OTHERS = 4.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
ENDIF.
IF lv_units1 IS NOT INITIAL.
IF lv_date1 IS INITIAL.
lv_date1 = wa_ett-bis.
ENDIF.
yr = lv_date1+2(2).
IF wa_erch-sc_belnr_h IS NOT INITIAL .
LOOP AT t_dberchz22 INTO wa_dberchz22 .
lv_wert11 = lv_wert11 + wa_dberchz22-v_zwstdiff .
ENDLOOP.
ELSE.
lv_wert11 = wa_ett-wert1.
ENDIF.
CALL FUNCTION 'ISP_GET_MONTH_NAME'
EXPORTING
date = lv_date1
language = 'E'
* MONTH_NUMBER = '00'
IMPORTING
* LANGU_BACK =
longtext = lv_tex1
* shorttext =
EXCEPTIONS
calendar_id = 1
date_error = 2
not_found = 3
wrong_input = 4
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
IF yr IS NOT INITIAL.
lv_tex1 = lv_tex1+0(3).
CONCATENATE lv_tex1 '-' yr INTO lv_tex1.
ENDIF.
lt_zbibd-bill_month1 = lv_tex1.
* IF NOT lv_wert11 IS INITIAL.
lt_zbibd-unit_consum1 = lv_wert11.
CONDENSE: lt_zbibd-unit_consum1.
SPLIT lt_zbibd-unit_consum1 AT '.' INTO lt_zbibd-unit_consum1 dummy1.
* ELSE.
* lt_zbibd-unit_consum1 = ''.
* ENDIF.
IF NOT lv_units1 IS INITIAL AND wa_ett-operand NE 'BILL_CONS'.
CONCATENATE lt_zbibd-unit_consum1 '(' lv_units1 ')' INTO lt_zbibd-
unit_consum1.
ENDIF.
lt_zbibd-bill_basis1 = lv_units1.
CONDENSE: lt_zbibd-unit_consum1.
* ENDIF.
**************************For SECOND MONTH*********************************
****
CLEAR: t_dberchz22,yr,lv_tex1,lv_date1,
lv_wert11,lv_units1,1c30,2c30,wa_erch.
IF sy-subrc EQ 0.
lv_units1 = wa_dberchz22-ablhinw.
ENDIF.
ENDIF.
IF yr IS NOT INITIAL.
lv_tex1 = lv_tex1+0(3).
CONCATENATE lv_tex1 '-' yr INTO lv_tex1.
ENDIF.
lt_zbibd-bill_month2 = lv_tex1.
* IF NOT lv_wert11 IS INITIAL.
lt_zbibd-unit_consum2 = lv_wert11.
CONDENSE: lt_zbibd-unit_consum2.
SPLIT lt_zbibd-unit_consum2 AT '.' INTO lt_zbibd-unit_consum2 dummy1.
IF NOT lv_units1 IS INITIAL AND wa_ett-operand NE 'BILL_CONS'.
CONCATENATE lt_zbibd-unit_consum2 '(' lv_units1 ')' INTO lt_zbibd-
unit_consum2.
ENDIF.
lt_zbibd-bill_basis2 = lv_units1.
CONDENSE:lt_zbibd-unit_consum2.
* ENDIF.
**************************For THIRD MONTH**********************************
***
CLEAR: t_dberchz22,yr,lv_tex1,lv_date1,
lv_wert11,lv_units1,1c30,2c30,wa_erch.
IF sy-subrc EQ 0.
lv_units1 = wa_dberchz22-ablhinw.
ENDIF.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
IF val2 IS NOT INITIAL.
CLEAR dummy1.
lt_zbibd-rec_dem3 = val2.
CONDENSE lt_zbibd-rec_dem3.
SPLIT lt_zbibd-rec_dem3 AT '.' INTO lt_zbibd-rec_dem3 dummy1.
* CONCATENATE lt_zbibd-rec_dem3 '.' dummy1+0(2) INTO lt_zbibd-
rec_dem3.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
IF yr IS NOT INITIAL.
lv_tex1 = lv_tex1+0(3).
CONCATENATE lv_tex1 '-' yr INTO lv_tex1.
ENDIF.
lt_zbibd-bill_month3 = lv_tex1.
* IF NOT lv_wert11 IS INITIAL.
lt_zbibd-unit_consum3 = lv_wert11.
CONDENSE: lt_zbibd-unit_consum3.
SPLIT lt_zbibd-unit_consum3 AT '.' INTO lt_zbibd-unit_consum3 dummy1.
IF sy-subrc EQ 0.
lv_units1 = wa_dberchz22-ablhinw.
ENDIF.
ENDIF.
IF yr IS NOT INITIAL.
lv_tex1 = lv_tex1+0(3).
CONCATENATE lv_tex1 '-' yr INTO lv_tex1.
ENDIF.
lt_zbibd-bill_month4 = lv_tex1.
* IF NOT lv_wert11 IS INITIAL.
lt_zbibd-unit_consum4 = lv_wert11.
CONDENSE: lt_zbibd-unit_consum4.
SPLIT lt_zbibd-unit_consum4 AT '.' INTO lt_zbibd-unit_consum4 dummy1.
* ELSE.
* lt_zbibd-unit_consum4 = ''.
* ENDIF.
IF NOT lv_units1 IS INITIAL AND wa_ett-operand NE 'BILL_CONS'.
CONCATENATE lt_zbibd-unit_consum4 '(' lv_units1 ')' INTO lt_zbibd-
unit_consum4.
ENDIF.
lt_zbibd-bill_basis4 = lv_units1.
* ENDIF.
CONDENSE: lt_zbibd-unit_consum4.
IF sy-subrc EQ 0.
lv_units1 = wa_dberchz22-ablhinw.
ENDIF.
ENDIF.
IF yr IS NOT INITIAL.
lv_tex1 = lv_tex1+0(3).
CONCATENATE lv_tex1 '-' yr INTO lv_tex1.
ENDIF.
lt_zbibd-bill_month5 = lv_tex1.
* IF NOT lv_wert11 IS INITIAL.
lt_zbibd-unit_consum5 = lv_wert11.
CONDENSE: lt_zbibd-unit_consum5.
SPLIT lt_zbibd-unit_consum5 AT '.' INTO lt_zbibd-unit_consum5 dummy1.
* ELSE.
* lt_zbibd-unit_consum5 = ''.
* ENDIF.
IF NOT lv_units1 IS INITIAL AND wa_ett-operand NE 'BILL_CONS'.
CONCATENATE lt_zbibd-unit_consum5 '(' lv_units1 ')' INTO lt_zbibd-
unit_consum5.
ENDIF.
lt_zbibd-bill_basis5 = lv_units1.
* ENDIF.
CONDENSE: lt_zbibd-unit_consum5.
IF sy-subrc EQ 0.
lv_units1 = wa_dberchz22-ablhinw.
ENDIF.
ENDIF.
IF yr IS NOT INITIAL.
lv_tex1 = lv_tex1+0(3).
CONCATENATE lv_tex1 '-' yr INTO lv_tex1.
ENDIF.
lt_zbibd-bill_month6 = lv_tex1.
* IF NOT lv_wert11 IS INITIAL.
lt_zbibd-unit_consum6 = lv_wert11.
CONDENSE: lt_zbibd-unit_consum6.
SPLIT lt_zbibd-unit_consum6 AT '.' INTO lt_zbibd-unit_consum6 dummy1.
IF sy-subrc EQ 0.
lv_units1 = wa_dberchz22-ablhinw.
ENDIF.
ELSEIF wa_ett-operand = 'BILL_CONS'.
READ TABLE lt_ett INTO wa_ett1 WITH KEY operand = 'BILL_BASIS'.
IF sy-subrc = 0.
lv_indx = sy-tabix.
IF wa_ett1-wert1 = 1.
lv_units1 = 'ACTUAL'.
ELSEIF wa_ett1-wert1 = 2.
lv_units1 = 'MMC'.
ELSE.
lv_units1 = 'AVERAGE'.
ENDIF.
DELETE lt_ett INDEX lv_indx.
CLEAR lv_indx.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
IF yr IS NOT INITIAL.
lv_tex1 = lv_tex1+0(3).
CONCATENATE lv_tex1 '-' yr INTO lv_tex1.
ENDIF.
lt_zbibd-bill_month7 = lv_tex1.
lt_zbibd-unit_consum7 = lv_wert11.
CONDENSE: lt_zbibd-unit_consum7.
SPLIT lt_zbibd-unit_consum7 AT '.' INTO lt_zbibd-unit_consum7 dummy1.
IF sy-subrc EQ 0.
lv_units1 = wa_dberchz22-ablhinw.
ENDIF.
ENDIF.
IF yr IS NOT INITIAL.
lv_tex1 = lv_tex1+0(3).
CONCATENATE lv_tex1 '-' yr INTO lv_tex1.
ENDIF.
lt_zbibd-bill_month8 = lv_tex1.
* IF NOT lv_wert11 IS INITIAL.
lt_zbibd-unit_consum8 = lv_wert11.
CONDENSE: lt_zbibd-unit_consum8.
SPLIT lt_zbibd-unit_consum8 AT '.' INTO lt_zbibd-unit_consum8 dummy1.
IF sy-subrc EQ 0.
lv_units1 = wa_dberchz22-ablhinw.
ENDIF.
ENDIF.
IF yr IS NOT INITIAL.
lv_tex1 = lv_tex1+0(3).
CONCATENATE lv_tex1 '-' yr INTO lv_tex1.
ENDIF.
lt_zbibd-bill_month9 = lv_tex1.
* IF NOT lv_wert11 IS INITIAL.
lt_zbibd-unit_consum9 = lv_wert11.
CONDENSE: lt_zbibd-unit_consum9.
SPLIT lt_zbibd-unit_consum9 AT '.' INTO lt_zbibd-unit_consum9 dummy1.
IF sy-subrc EQ 0.
lv_units1 = wa_dberchz22-ablhinw.
ENDIF.
ENDIF.
IF yr IS NOT INITIAL.
lv_tex1 = lv_tex1+0(3).
CONCATENATE lv_tex1 '-' yr INTO lv_tex1.
ENDIF.
lt_zbibd-bill_month10 = lv_tex1.
lt_zbibd-unit_consum10 = lv_wert11.
CONDENSE: lt_zbibd-unit_consum10.
SPLIT lt_zbibd-unit_consum10 AT '.' INTO lt_zbibd-unit_consum10 dummy1.
* ELSE.
* lt_zbibd-unit_consum10 = ''.
* ENDIF.
IF NOT lv_units1 IS INITIAL AND wa_ett-operand NE 'BILL_CONS'.
CONCATENATE lt_zbibd-unit_consum10 '(' lv_units1 ')' INTO lt_zbibd-
unit_consum10.
ENDIF.
lt_zbibd-bill_basis10 = lv_units1.
* ENDIF.
CONDENSE: lt_zbibd-unit_consum10.
IF sy-subrc EQ 0.
lv_units1 = wa_dberchz22-ablhinw.
ENDIF.
ENDIF.
IF yr IS NOT INITIAL.
lv_tex1 = lv_tex1+0(3).
CONCATENATE lv_tex1 '-' yr INTO lv_tex1.
ENDIF.
lt_zbibd-bill_month11 = lv_tex1.
* IF NOT lv_wert11 IS INITIAL.
lt_zbibd-unit_consum11 = lv_wert11.
CONDENSE: lt_zbibd-unit_consum11.
SPLIT lt_zbibd-unit_consum11 AT '.' INTO lt_zbibd-unit_consum11 dummy1.
CLEAR: lv_rashi.
*
* CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
* EXPORTING
* date = wa_doc_header-budat
* days = lv_days11
* months = lv_months11
* signum = '-'
* years = lv_years11
* IMPORTING
* calc_date = lv_date_2.
lv_cnt1 = 50.
CALL FUNCTION 'FKK_READ_LAST_PAYMENTS'
EXPORTING
i_vkont = lt_zbibd-contract_account
i_count = lv_cnt1
* i_exclude_returns = 'X' "commented by TMKIRAND
TABLES
t_payments = it_payment.
****added by TMKIRAND***********************
SORT it_payment BY cpudt DESCENDING cputm DESCENDING.
DELETE it_payment WHERE cpudt GT wa_doc_header-erdat.
SELECT budat
klaeb
opbel
ruebl
ruear
FROM dfkkzp
APPENDING TABLE it_dfkkzp
FOR ALL ENTRIES IN it_payment
WHERE klaeb = it_payment-opbel.
ENDIF.
* IF sy-subrc EQ 0.
LOOP AT it_payment INTO wa_it_payment.
* READ TABLE it_dfkkop6 INTO wa_dfkkop6 WITH KEY augbl = wa_it_payment
-opbel.
* IF sy-subrc EQ 0.
APPEND wa_it_payment TO it_payment1. "added by Kiran on 06.08.15
IF last_date IS INITIAL.
IF wa_it_payment-budat LE wa_doc_header-budat.
lv_rashi = lv_rashi + wa_it_payment-betrw.
ELSE.
DELETE it_payment.
ENDIF.
ELSEIF ( wa_it_payment-budat GT last_date AND
wa_it_payment-budat LE wa_doc_header-budat ).
lv_rashi = lv_rashi + wa_it_payment-betrw.
ELSE.
DELETE it_payment.
ENDIF.
* ELSE.
* DELETE it_payment.
* ENDIF.
* CLEAR wa_dfkkop6.
ENDLOOP.
* ENDIF.
lt_zbibd-last_pymt_amt = lv_rashi.
lt_zbibd-last_pymt_recpt_no = lv_receipt.
lt_zbibd-last_pymt_dt = lv_receipt_date.
lt_zbibd-pymt_amt = wa_it_payment-betrw.
lt_zbibd-pymt_recpt_no = lv_receipt.
lt_zbibd-pymt_dt = lv_receipt_date.
lt_zbibd-last_pymt_amt = lv_rashi.
lt_zbibd-last_pymt_recpt_no = lv_receipt.
lt_zbibd-last_pymt_dt = lv_receipt_date.
lt_zbibd-pymt_amt = lv_rashi.
lt_zbibd-pymt_recpt_no = lv_receipt.
lt_zbibd-pymt_dt = lv_receipt_date.
ENDIF.
lt_zbibd-last_pymt_amt = lv_rashi.
lt_zbibd-last_pymt_recpt_no = lv_receipt.
lt_zbibd-last_pymt_dt = lv_receipt_date.
IF lt_zbibd-pymt_amt IS INITIAL.
SELECT * FROM zbi_migr_pymt INTO TABLE it_pymt
WHERE sap_ca = lt_zbibd-contract_account.
SORT it_pymt BY payment_date DESCENDING.
READ TABLE it_pymt INTO wa_pymt INDEX 1.
IF sy-subrc = 0.
lv_rashi = wa_pymt-payment_amt.
lv_receipt = wa_pymt-receiptno.
lv_receipt_date = wa_pymt-payment_date.
ENDIF.
lt_zbibd-pymt_amt = lv_rashi.
lt_zbibd-pymt_recpt_no = lv_receipt.
lt_zbibd-pymt_dt = lv_receipt_date.
lt_zbibd-last_pymt_amt = lv_rashi.
lt_zbibd-last_pymt_recpt_no = lv_receipt.
lt_zbibd-last_pymt_dt = lv_receipt_date.
ENDIF.
*****************************POWER FACTOR****************************
CLEAR: lv_power,staff_unit.
IF lt_zbibd-tariff_type+0(2) <> 'HT' AND lt_zbibd-
tariff_type+0(2) <> 'RT'.
LOOP AT it_ettifn INTO wa_ettifn WHERE operand = 'POWER_FACT'.
IF lv_end_date BETWEEN wa_ettifn-ab AND wa_ettifn-bis.
lv_power = wa_ettifn-wert1.
EXIT.
ENDIF.
ENDLOOP.
ELSE.
LOOP AT it_ettifn INTO wa_ettifn WHERE ab LE lv_ab_date AND
bis GE lv_end_date AND
operand = 'POWER_FACT'.
lv_power = wa_ettifn-wert1.
EXIT.
ENDLOOP.
ENDIF.
lt_zbibd-power_factor = lv_power.
IF lt_zbibd-tariff_type = 'HTS-III_OP' OR lt_zbibd-tariff_type = 'HTS-
I_OP'.
ELSE.
IF lt_zbibd-tariff_type+0(2) = 'HT' OR lt_zbibd-
tariff_type+0(2) = 'RT'.
IF lv_daats_ab GE '20160401'.
CLEAR lt_zbibd-power_factor.
ENDIF.
ENDIF.
ENDIF.
******************STAFF CONSUMER ON**********************************
LOOP AT it_ettifn INTO wa_ettifn WHERE ab LE lv_ab_date AND
bis GE lv_end_date AND
operand = 'STAFF_UNIT'.
staff_unit = wa_ettifn-wert1.
EXIT.
ENDLOOP.
IF lt_zbibd-electricity_duty IS INITIAL.
SELECT wert1 ab operand FROM ettifn INTO TABLE t_ettifn4
WHERE anlage = v_anlage AND ( operand = 'CGOVT' OR operand = 'IIP_NOE
D').
IF NOT t_ettifn4 IS INITIAL.
READ TABLE t_ettifn4 INTO wa_ettifn4 INDEX 1.
lv_operand = wa_ettifn4-operand.
ENDIF.
ENDIF.
**************SECURITY DEPOSIT HELD OR REQUIRED***************************
CLEAR: t_dfkkop1,t_dfkkop2,lv_betrw,lv_daaat.",t_dfkkop.
* SELECT * FROM dfkkop INTO TABLE t_dfkkop WHERE vkont = lt_zbibd-
contract_account.
t_dfkkop2[] = t_dfkkop[].
DELETE t_dfkkop2 WHERE budat LT last_date.
DELETE t_dfkkop2 WHERE budat GT lt_zbibd-date_of_invoice.
SORT t_dfkkop2 BY budat.
DELETE t_dfkkop2 WHERE augrd = '05'.
ELSE.
LOOP AT t_dfkkop2 INTO wa_dfkkop2 WHERE ( hvorg = 'Z132'
OR hvorg = 'ZOTS'
OR hvorg = 'Z137'
OR hvorg = 'Z120' ).
lv_betrw2 = wa_dfkkop2-betrw + lv_betrw2.
IF wa_dfkkop2-hvorg = 'Z132'.
lt_zbibd-message6 = 'X'.
ENDIF.
ENDLOOP.
ENDIF.
IF lt_zbibd-message6 = 'X'.
CLEAR: lt_zbibd-message6.
CONCATENATE zextra-fi_mess1 ':' l_waline-tdline
INTO lt_zbibd-z132_message SEPARATED BY space.
ENDIF.
* IF lt_zbibd-z132_message = 'X'.
* CLEAR lt_zbibd-z132_message.
** CONCATENATE 'Rs.'
* lt_zbibd-z132_message = zextra-fi_mess1.
* ENDIF.
* Code added by KiranD TR B10K902530
*Below Logic written for only 1 month for following SUB_DIV_CODE's
* FAAA/CBBA/CBBB/EAEE/DBBA
********Bill Month************************************************
* IF lt_zbibd-sub_div_code = 'FAAA' OR lt_zbibd-sub_div_code = 'CBBA' OR
* lt_zbibd-sub_div_code = 'CBBB' OR lt_zbibd-sub_div_code = 'EAEE' OR
* lt_zbibd-sub_div_code = 'DBBA'.
* CLEAR: ls_dt1,ls_dt2,ls_mon1,lv_month,lv_datum.
* ls_dt1 = lv_end_date+0(4).
* ls_dt2 = lv_end_date+4(2).
*
* SELECT SINGLE monam FROM t015m INTO lv_month WHERE monum = ls_dt2
* AND spras EQ 'EN'.
*
* CLEAR: lv_datum.
*
* ls_mon1 = lv_month+0(3).
* CONCATENATE ls_mon1 '-' ls_dt1 INTO lv_datum.
* lt_zbibd-bill_month = lv_datum.
* TRANSLATE lt_zbibd-bill_month TO UPPER CASE.
* ENDIF.
*End of Code by KiranD TR B10K902530
****************BILL DAYS LOGIC********************************************
**
lv_days = lv_end_date - lv_ab_date.
lt_zbibd-bill_days = lv_days + 1.
* If adjustment is there, then display TOTAL number of days along with
BILL_DAYS****************
CLEAR: lv_mtr_ab,lv_mtr_bis,lv_days1,gv_adj_days.
CLEAR: lv_dt1,lv_dt2,lv_pl_adjustment,lv_datum.
* IF NOT lt_zbibd-
other_charges IS INITIAL OR NOT lv_lt_leg_adj IS INITIAL.
IF pl_adj = 'X' OR NOT lv_lt_leg_adj IS INITIAL.
CLEAR it_tdoc.
LOOP AT t_doc_item INTO wa_tdoc WHERE zwnummer = '001' AND ablesgr NE '
91'.
APPEND wa_tdoc TO it_tdoc.
ENDLOOP.
SORT it_tdoc BY bis DESCENDING.
READ TABLE it_tdoc INTO wa_tdoc INDEX 1.
lv_mtr_bis = wa_tdoc-bis.
lv_mtr_ab = wa_tdoc-ab.
IF lv_lt_leg_adj = 'X'.
DELETE it_ettifn3 WHERE operand NE 'LEG_EC' AND operand NE 'LEG_EC_AP
R' .
SORT it_ettifn3 BY ab .
READ TABLE it_ettifn3 INTO wa_ettifn3 INDEX 1.
lv_mtr_ab = wa_ettifn3-ab.
* lv_mtr_ab = gv_bis.
ENDIF.
IF wa_tdoc-ablesgrv = '06'.
CALL FUNCTION 'HR_AUPBS_MONTH_DAY'
EXPORTING
beg_da = lv_mtr_ab
end_da = lv_mtr_bis
IMPORTING
no_cal_day = lv_days1.
ELSE.
CALL FUNCTION 'HR_AUPBS_MONTH_DAY'
EXPORTING
beg_da = lv_mtr_ab
end_da = lv_mtr_bis
IMPORTING
no_cal_day = lv_days1.
* lv_days1 = lv_days1 - 1 .
ENDIF.
gv_adj_days = lv_days1.
* PACK gv_adj_days to gv_adj_days.
CONDENSE gv_adj_days.
IF wa_eabl IS NOT INITIAL.
IF wa_eabl-ablhinw = 'PL' OR wa_eabl-ablhinw = 'PA'.
CONCATENATE '*''Your meter reading has been estimated due to premis
e locked.'
'It will be adjusted in subsequent bill when actual meter read
ing is received .'
INTO lv_pl_message SEPARATED BY space.
ENDIF.
ENDIF.
*********************PL ADJUSTMENT MESSAGE********************************
lv_dt2 = lv_mtr_ab+4(2).
lv_dt1 = lv_mtr_ab+0(4).
SELECT SINGLE monam FROM t015m INTO lv_adjust WHERE monum = lv_dt2 AND
spras = 'EN'.
IF sy-subrc = 0.
CLEAR lv_dt2.
lv_dt2 = lv_adjust+0(3).
CONCATENATE lv_dt2 '-' lv_dt1 INTO lv_datum.
CONCATENATE 'Bill has been adjusted against the actual'
'consumption received in' lt_zbibd-bill_month
'month for billing period' lv_datum 'to' lt_zbibd-
bill_month
INTO lv_pl_adjustment SEPARATED BY space.
ENDIF.
CLEAR: lv_datum.
ELSE.
CLEAR it_tdoc.
LOOP AT t_doc_item INTO wa_tdoc WHERE zwnummer = '001' AND ablesgr NE '
91'.
APPEND wa_tdoc TO it_tdoc.
ENDLOOP.
SORT it_tdoc BY bis DESCENDING.
READ TABLE it_tdoc INTO wa_tdoc INDEX 1.
lv_mtr_bis = wa_tdoc-bis.
lv_mtr_ab = wa_tdoc-ab.
ENDIF.
ENDIF.
ENDIF.
**********************Total arrear amount**********************************
***
lt_zbibd-total_arrear = lt_zbibd-pymt_on_account + lt_zbibd-
arrear_energy +
lt_zbibd-arrear_ed + lt_zbibd-arrear_dps +
lt_zbibd-arrear_punitive_amt + lt_zbibd-
arrear_punitive_dps +
lt_zbibd-arrear_other_chg." +
* lt_zbibd-online_rebate.
* lt_zbibd-amt_abey_with_dps.
IF lt_zbibd-tariff_type+0(2) = 'HT' OR lt_zbibd-tariff_type+0(2) = 'RT'.
lt_zbibd-total_arrear = lt_zbibd-total_arrear + lt_zbibd-online_rebate.
ENDIF.
IF lt_zbibd-net_amt_pbl_by_due_dt LE 0.
lt_zbibd-net_amt_pbl_btwn_due_dt = lt_zbibd-net_amt_pbl_by_due_dt.
lt_zbibd-amt_pybl_aftr_due_date = lt_zbibd-net_amt_pbl_by_due_dt.
ELSE.
*********************Amount Payable between due date***************
IF lt_zbibd-tariff_type+0(2) = 'LT' OR
lt_zbibd-tariff_type+0(2) = 'PU'.
IF '20170401' BETWEEN lv_ab_date AND lv_end_date.
IF pl_adj = 'X'.
DELETE it_tdoc WHERE zwnummer = '001' AND ablhinw = 'OK' AND
ablesgr = '01'.
* DELETE it_tdoc WHERE zwnummer = '002'.
ELSE.
DELETE it_tdoc WHERE zwnummer = '001'." or zwnummer = '002'.
ENDIF.
ELSEIF lv_end_date LT '20170401'.
ELSE.
DELETE it_tdoc WHERE zwnummer = '001'." or zwnummer = '002'.
ENDIF.
ENDIF.
CLEAR it1_eabl.
SELECT zwnummer adat zz_v_zwstand zz_n_zwstand FROM eabl INTO TAB
LE it1_eabl
WHERE equnr = wa_tdoc-
geraet AND adat LE lv_dt1."wa_tdoc-bis.
SORT it1_eabl BY register ASCENDING adat DESCENDING.
READ TABLE it1_eabl INTO wa1_eabl INDEX 1.
IF sy-subrc = 0 AND wa_tdoc-zwnummer = '1'.
wa_bimd-pre_mtr_rdng = wa1_eabl-zz_v_zwstand.
wa_bimd-curr_mtr_rdng = wa1_eabl-zz_v_zwstand.
ENDIF.
DELETE it1_eabl WHERE register EQ '002'.
READ TABLE it1_eabl INTO wa1_eabl INDEX 2.
wa_bimd-pre_mtr_rdng_date = wa1_eabl-adat.
***********Added by Kiran TR
IF wa_tdoc-zwnummer = '2' AND wa_tdoc-ablhinw = 'MD'.
wa_bimd-pre_mtr_rdng = lt_zbibd-contract_demand_kw.
wa_bimd-curr_mtr_rdng = lt_zbibd-contract_demand_kw.
ENDIF.
***********End of addition by Kiran TR
flag1 = 'X'.
ELSE.
IF lv_lt_leg_adj = 'X' AND wa_tdoc-zwnummer = '1'.
lv_anlage = v_anlage.
CLEAR: it_eabl5,it_eablg5.
AT LAST.
* IF wa_eablg5-ablesgr = '09'.
READ TABLE it_eabl5 INTO wa_eabl5 WITH KEY ablbelnr = lwa
_eablg5-ablbelnr.
* ablhinw = 'OK'.
IF sy-subrc = 0.
wa_bimd-pre_mtr_rdng_date = wa_eabl5-adat. "lv_mtr_ab
wa_bimd-pre_mtr_rdng = wa_eabl5-zz_v_zwstand.
* EXIT.
ENDIF.
* ENDIF.
ENDAT.
ENDLOOP.
* ENDIF.
wa_bimd-rdng_diff = wa_bimd-curr_mtr_rdng - wa_bimd-
pre_mtr_rdng.
wa_bimd-billed_consum = wa_bimd-rdng_diff.
wa_bimd-mult_fac = '1.00'.
ENDIF.
ELSE.
IF wa_tdoc-ablesgr = '01'.
IF wa_tdoc-ablesgrv = '06' OR
wa_tdoc-ablesgrv = '21' OR
wa_tdoc-ablesgrv = '14'.
wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ELSEIF wa_tdoc-ablesgrv = '01'.
IF wa_tdoc-sc_belnr IS INITIAL.
wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ELSE.
wa_bimd-billed_consum = wa_bimd-billed_consum + wa_tdoc-
i_abrmenge.
IF wa_tdoc-i_abrmenge LT 0.
wa_bimd-rdng_diff = wa_bimd-rdng_diff - wa_tdoc-
i_zwstdiff.
ELSE.
wa_bimd-rdng_diff = wa_bimd-rdng_diff + wa_tdoc-
i_zwstdiff.
ENDIF.
ENDIF.
* ELSEIF wa_tdoc-ablesgrv = '11' AND wa_tdoc-zwnummer = '3'.
* wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
* wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ENDIF.
ELSEIF wa_tdoc-ablesgr = '22' OR wa_tdoc-ablesgr = '14'
OR wa_tdoc-ablesgr = '16'.
IF wa_tdoc-ablesgrv = '01' OR wa_tdoc-ablesgrv = '06'
OR wa_tdoc-ablesgrv = '14' OR wa_tdoc-ablesgrv = '11'.
wa_bimd-rdng_diff = wa_bimd-rdng_diff + wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_bimd-billed_consum + wa_tdoc-
i_abrmenge.
ENDIF.
ELSEIF wa_tdoc-ablesgr = '03'.
IF wa_tdoc-ablesgrv = '01' OR wa_tdoc-ablesgrv = '14'.
wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ENDIF.
******added by KiranD B10K902752*****************************
ELSEIF wa_tdoc-ablesgr = '10'.
IF wa_tdoc-ablesgrv = '01'.
wa_bimd-rdng_diff = wa_bimd-rdng_diff + wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_bimd-billed_consum + wa_tdoc-
i_abrmenge.
ENDIF.
******end of addition by KiranD B10K902752*******************
ENDIF.
ENDIF.
ENDIF.
ENDIF.
wa_bimd-invoiceno = lt_zbibd-invoiceno.
wa_bimd-contract_acc_no = lt_zbibd-contract_account.
SELECT SINGLE serge FROM equi INTO wa_bimd-
mnf_srl_no WHERE equnr = wa_tdoc-geraet.
wa_bimd-meter_no = wa_tdoc-geraet.
wa_bimd-register = wa_tdoc-zwnummer.
wa_bimd-bill_month = lt_zbibd-bill_month.
wa_bimd-date_of_invoice = lt_zbibd-date_of_invoice.
wa_bimd-meter_status = wa_tdoc-ablhinw.
wa_bimd-cur_mtr_type = wa_tdoc-istablart.
wa_bimd-curr_mtr_rdng_reason = wa_tdoc-ablesgr.
wa_bimd-billed_mtr_rdng = wa_tdoc-i_zwstndab.
* IF lv_lt_leg_adj = 'X'.
* ELSE.
wa_bimd-mult_fac = wa_tdoc-i_abrmenge / wa_tdoc-i_zwstdiff.
*Start of Addition by TMMANISHT on 12th April 2014
IF wa_bimd-mult_fac = '0.00'.
wa_bimd-mult_fac = '1.00'.
ENDIF.
*End of Addition by TMMANISHT on 12th April 2014
* ENDIF.
IF flag1 IS INITIAL.
IF lv_lt_leg_adj IS INITIAL.
wa_bimd-pre_mtr_rdng = wa_tdoc-i_zwstvor.
wa_bimd-curr_mtr_rdng = wa_tdoc-i_zwstand.
ELSEIF wa_tdoc-zwnummer = 2.
wa_bimd-pre_mtr_rdng = wa_tdoc-i_zwstvor.
wa_bimd-curr_mtr_rdng = wa_tdoc-i_zwstand.
ENDIF.
ENDIF.
wa_bimd-pre_mtr_rdng_reason = wa_tdoc-ablesgrv.
wa_bimd-pre_mtr_type = wa_tdoc-istablartva.
IF flag1 IS INITIAL.
IF lv_lt_leg_adj IS INITIAL.
IF last_date IS INITIAL.
wa_bimd-pre_mtr_rdng_date = wa_tdoc-ab.
ELSE.
wa_bimd-pre_mtr_rdng_date = wa_tdoc-ab - 1.
ENDIF.
ELSEIF wa_tdoc-zwnummer = 2.
IF last_date IS INITIAL.
wa_bimd-pre_mtr_rdng_date = wa_tdoc-ab.
ELSE.
wa_bimd-pre_mtr_rdng_date = wa_tdoc-ab - 1.
ENDIF.
ENDIF.
ENDIF.
IF lv_lt_leg_adj IS INITIAL.
wa_bimd-curr_mtr_rdng_date = wa_tdoc-bis.
ELSEIF wa_tdoc-zwnummer = 2.
wa_bimd-curr_mtr_rdng_date = wa_tdoc-bis.
ENDIF.
wa_bimd-uom = wa_tdoc-massbill.
IF cnt = 1.
APPEND wa_bimd TO gt_bimd.
ELSE.
CLEAR it1_eabl.
SELECT zwnummer adat zz_v_zwstand zz_n_zwstand FROM eabl INTO T
ABLE it1_eabl
WHERE equnr = wa_tdoc-geraet AND adat LE lv_dt1.
SORT it1_eabl BY register DESCENDING adat DESCENDING.
DELETE it1_eabl WHERE register = '001'.
READ TABLE it1_eabl INTO wa1_eabl INDEX 1.
IF sy-subrc = 0 AND wa_tdoc-zwnummer = '3'.
wa_bimd-pre_mtr_rdng = wa1_eabl-zz_v_zwstand.
wa_bimd-curr_mtr_rdng = wa1_eabl-zz_v_zwstand.
ENDIF.
DELETE it1_eabl WHERE register EQ '002'.
READ TABLE it1_eabl INTO wa1_eabl INDEX 2.
wa_bimd-pre_mtr_rdng_date = wa1_eabl-adat.
***********Added by Kiran TR
IF wa_tdoc-zwnummer = '2' AND wa_tdoc-ablhinw = 'MD'.
wa_bimd-pre_mtr_rdng = lt_zbibd-contract_demand_kw.
wa_bimd-curr_mtr_rdng = lt_zbibd-contract_demand_kw.
ENDIF.
***********End of addition by Kiran TR
flag1 = 'X'.
ELSE.
IF lv_lt_leg_adj = 'X' AND wa_tdoc-zwnummer = '1'.
lv_anlage = v_anlage.
CLEAR: it_eabl5,it_eablg5.
AT LAST.
* IF wa_eablg5-ablesgr = '09'.
READ TABLE it_eabl5 INTO wa_eabl5 WITH KEY ablbelnr = l
wa_eablg5-ablbelnr.
* ablhinw = 'OK'.
IF sy-subrc = 0.
wa_bimd-pre_mtr_rdng_date = wa_eabl5-adat. "lv_mtr_ab
wa_bimd-pre_mtr_rdng = wa_eabl5-zz_v_zwstand.
* EXIT.
ENDIF.
* ENDIF.
ENDAT.
ENDLOOP.
* ENDIF.
wa_bimd-rdng_diff = wa_bimd-curr_mtr_rdng - wa_bimd-
pre_mtr_rdng.
wa_bimd-billed_consum = wa_bimd-rdng_diff.
wa_bimd-mult_fac = '1.00'.
ENDIF.
ELSE.
IF wa_tdoc-ablesgr = '01'.
IF wa_tdoc-ablesgrv = '06' OR
wa_tdoc-ablesgrv = '21' OR
wa_tdoc-ablesgrv = '14'.
wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ELSEIF wa_tdoc-ablesgrv = '01'.
IF wa_tdoc-sc_belnr IS INITIAL.
wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ELSE.
wa_bimd-billed_consum = wa_bimd-
billed_consum + wa_tdoc-i_abrmenge.
IF wa_tdoc-i_abrmenge LT 0.
wa_bimd-rdng_diff = wa_bimd-rdng_diff - wa_tdoc-
i_zwstdiff.
ELSE.
wa_bimd-rdng_diff = wa_bimd-rdng_diff + wa_tdoc-
i_zwstdiff.
ENDIF.
ENDIF.
ELSEIF wa_tdoc-ablesgrv = '11' AND wa_tdoc-zwnummer = '3'.
wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ENDIF.
ELSEIF wa_tdoc-ablesgr = '22' OR wa_tdoc-ablesgr = '14'
OR wa_tdoc-ablesgr = '16'.
IF wa_tdoc-ablesgrv = '01' OR wa_tdoc-ablesgrv = '06'
OR wa_tdoc-ablesgrv = '14' OR wa_tdoc-ablesgrv = '11'.
wa_bimd-rdng_diff = wa_bimd-rdng_diff + wa_tdoc-
i_zwstdiff.
wa_bimd-billed_consum = wa_bimd-billed_consum + wa_tdoc-
i_abrmenge.
ENDIF.
ELSEIF wa_tdoc-ablesgr = '03'.
IF wa_tdoc-ablesgrv = '01' OR wa_tdoc-ablesgrv = '14'.
wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ENDIF.
******added by KiranD B10K902752*****************************
ELSEIF wa_tdoc-ablesgr = '10'.
IF wa_tdoc-ablesgrv = '01'.
wa_bimd-rdng_diff = wa_bimd-rdng_diff + wa_tdoc-
i_zwstdiff.
wa_bimd-billed_consum = wa_bimd-billed_consum + wa_tdoc-
i_abrmenge.
ENDIF.
******end of addition by KiranD B10K902752*******************
ENDIF.
ENDIF.
ENDIF.
ENDIF.
wa_bimd-invoiceno = lt_zbibd-invoiceno.
wa_bimd-contract_acc_no = lt_zbibd-contract_account.
SELECT SINGLE serge FROM equi INTO wa_bimd-
mnf_srl_no WHERE equnr = wa_tdoc-geraet.
wa_bimd-meter_no = wa_tdoc-geraet.
wa_bimd-register = wa_tdoc-zwnummer.
wa_bimd-bill_month = lt_zbibd-bill_month.
wa_bimd-date_of_invoice = lt_zbibd-date_of_invoice.
wa_bimd-meter_status = wa_tdoc-ablhinw.
wa_bimd-cur_mtr_type = wa_tdoc-istablart.
wa_bimd-curr_mtr_rdng_reason = wa_tdoc-ablesgr.
wa_bimd-billed_mtr_rdng = wa_tdoc-i_zwstndab.
* IF lv_lt_leg_adj = 'X'.
* ELSE.
wa_bimd-mult_fac = wa_tdoc-i_abrmenge / wa_tdoc-i_zwstdiff.
*Start of Addition by TMMANISHT on 12th April 2014
IF wa_bimd-mult_fac = '0.00'.
wa_bimd-mult_fac = '1.00'.
ENDIF.
*End of Addition by TMMANISHT on 12th April 2014
* ENDIF.
IF flag1 IS INITIAL.
IF lv_lt_leg_adj IS INITIAL.
wa_bimd-pre_mtr_rdng = wa_tdoc-i_zwstvor.
wa_bimd-curr_mtr_rdng = wa_tdoc-i_zwstand.
ELSEIF wa_tdoc-zwnummer = 2.
wa_bimd-pre_mtr_rdng = wa_tdoc-i_zwstvor.
wa_bimd-curr_mtr_rdng = wa_tdoc-i_zwstand.
ENDIF.
ENDIF.
wa_bimd-pre_mtr_rdng_reason = wa_tdoc-ablesgrv.
wa_bimd-pre_mtr_type = wa_tdoc-istablartva.
IF flag1 IS INITIAL.
IF lv_lt_leg_adj IS INITIAL.
IF last_date IS INITIAL.
wa_bimd-pre_mtr_rdng_date = wa_tdoc-ab.
ELSE.
wa_bimd-pre_mtr_rdng_date = wa_tdoc-ab - 1.
IF wa_tdoc-zwnummer = '3' AND wa_tdoc-ablesgrv = '11'.
wa_bimd-pre_mtr_rdng_date = wa_bimd-pre_mtr_rdng_date + 1.
ENDIF.
ENDIF.
ELSEIF wa_tdoc-zwnummer = 2.
IF last_date IS INITIAL.
wa_bimd-pre_mtr_rdng_date = wa_tdoc-ab.
ELSE.
wa_bimd-pre_mtr_rdng_date = wa_tdoc-ab - 1.
ENDIF.
ENDIF.
ENDIF.
IF lv_lt_leg_adj IS INITIAL.
wa_bimd-curr_mtr_rdng_date = wa_tdoc-bis.
ELSEIF wa_tdoc-zwnummer = 2.
wa_bimd-curr_mtr_rdng_date = wa_tdoc-bis.
ENDIF.
wa_bimd-uom = wa_tdoc-massbill.
IF cnt = 1.
APPEND wa_bimd TO gt_bimd.
ELSE.
READ TABLE gt_bimd INTO wa_bimd1 WITH KEY meter_no = wa_tdoc-
geraet
register = wa_tdoc-
zwnummer.
IF sy-subrc = 0.
IF wa_bimd1-curr_mtr_rdng_date LT wa_bimd-curr_mtr_rdng_date.
wa_bimd1-curr_mtr_rdng_date = wa_bimd-curr_mtr_rdng_date.
IF wa_tdoc-ablesgr = '22' AND wa_tdoc-ablesgrv = '10'.
ELSE.
wa_bimd1-curr_mtr_rdng = wa_bimd-curr_mtr_rdng.
ENDIF.
IF pl_adj = 'X' AND lv_lt_leg_adj = ''.
wa_bimd1-billed_consum = wa_bimd-billed_consum.
wa_bimd1-rdng_diff = wa_bimd-rdng_diff.
ENDIF.
ENDIF.
IF pl_adj = 'X' AND lv_lt_leg_adj = ''.
IF wa_tdoc-ablesgr = '14'.
wa_bimd1-pre_mtr_rdng_date = wa_tdoc-ab - 1.
ELSEIF wa_bimd1-pre_mtr_rdng_date LT wa_bimd-
pre_mtr_rdng_date.
wa_bimd1-pre_mtr_rdng_date = wa_bimd-pre_mtr_rdng_date.
wa_bimd1-pre_mtr_rdng = wa_bimd-pre_mtr_rdng.
ENDIF.
ELSEIF wa_bimd1-pre_mtr_rdng_date GT wa_bimd-pre_mtr_rdng_date.
wa_bimd1-pre_mtr_rdng_date = wa_bimd-pre_mtr_rdng_date.
IF wa_tdoc-ablesgr = '22' AND wa_tdoc-ablesgrv = '10'.
ELSE.
wa_bimd1-pre_mtr_rdng = wa_bimd-pre_mtr_rdng.
ENDIF.
ENDIF.
IF lv_lt_leg_adj = 'X'.
IF wa_bimd1-pre_mtr_rdng_date LT wa_tdoc-ab.
wa_bimd1-pre_mtr_rdng_date = wa_tdoc-ab. "wa_bimd-
pre_mtr_rdng_date.
* wa_bimd1-pre_mtr_rdng = wa_bimd-pre_mtr_rdng.
ENDIF.
ENDIF.
* NEW CHANGES DONE BY KIRAN
*Multiple months consumption addition and for Leg Adj cases
IF lv_lt_leg_adj = 'X'.
wa_bimd1-billed_consum = wa_bimd1-billed_consum.
wa_bimd1-rdng_diff = wa_bimd1-rdng_diff.
ELSEIF pl_adj = 'X'. "lt_zbibd-other_charges IS NOT INITIAL.
ELSE.
wa_bimd1-billed_consum = wa_bimd1-billed_consum +
wa_bimd-billed_consum.
wa_bimd1-rdng_diff = wa_bimd1-rdng_diff +
wa_bimd-rdng_diff.
ENDIF.
wa_bimd1-mnf_srl_no = wa_bimd-mnf_srl_no.
**********new changes by Kiran
IF wa_bimd1-curr_mtr_rdng_reason = '22' AND wa_tdoc-
zwnummer = 1.
wa_bimd1-curr_mtr_rdng = wa_tdoc-i_zwstand.
ENDIF.
IF wa_tdoc-zwnummer = 2.
IF wa_bimd1-curr_mtr_rdng > wa_tdoc-i_zwstand.
ELSE.
wa_bimd1-curr_mtr_rdng = wa_tdoc-i_zwstand.
ENDIF.
ENDIF.
*********end of new changes
MODIFY gt_bimd FROM wa_bimd1 INDEX sy-tabix.
ELSE.
APPEND wa_bimd TO gt_bimd.
ENDIF.
* ENDIF.
ENDIF.
CLEAR: wa_bimd.
ELSE. " earlier to 01.04.2017
lv_lt_flag = 'X'.
CLEAR: flag1,it1_eabl,wa1_eabl.
cnt = cnt + 1.
IF wa_tdoc-zwnummer = '1' OR wa_tdoc-zwnummer = '2' OR
wa_tdoc-zwnummer = '3' OR wa_tdoc-zwnummer = '4' OR
wa_tdoc-zwnummer = '5' OR wa_tdoc-zwnummer = '6'.
IF wa_tdoc-ablhinw = 'PL' OR wa_tdoc-ablhinw = 'NB' OR
wa_tdoc-ablhinw = 'UF' OR wa_tdoc-ablhinw = 'MD' OR
wa_tdoc-ablhinw = 'MB' OR wa_tdoc-ablhinw = 'MM' OR
wa_tdoc-ablhinw = 'NF' OR wa_tdoc-ablhinw = 'NM' OR
wa_tdoc-ablhinw = 'RN' OR wa_tdoc-ablhinw = 'UB'.
CLEAR it1_eabl.
SELECT zwnummer adat zz_v_zwstand zz_n_zwstand FROM eabl INTO T
ABLE it1_eabl
WHERE equnr = wa_tdoc-
geraet AND adat LE lv_dt1."wa_tdoc-bis.
SORT it1_eabl BY register ASCENDING adat DESCENDING.
READ TABLE it1_eabl INTO wa1_eabl INDEX 1.
IF sy-subrc = 0 AND wa_tdoc-zwnummer = '1'.
wa_bimd-pre_mtr_rdng = wa1_eabl-zz_v_zwstand.
wa_bimd-curr_mtr_rdng = wa1_eabl-zz_v_zwstand.
ENDIF.
DELETE it1_eabl WHERE register EQ '002'.
READ TABLE it1_eabl INTO wa1_eabl INDEX 2.
wa_bimd-pre_mtr_rdng_date = wa1_eabl-adat.
***********Added by Kiran TR
IF wa_tdoc-zwnummer = '2' AND wa_tdoc-ablhinw = 'MD'.
wa_bimd-pre_mtr_rdng = lt_zbibd-contract_demand_kw.
wa_bimd-curr_mtr_rdng = lt_zbibd-contract_demand_kw.
ENDIF.
***********End of addition by Kiran TR
flag1 = 'X'.
ELSE.
IF lv_lt_leg_adj = 'X' AND wa_tdoc-zwnummer = '1'.
lv_anlage = v_anlage.
CLEAR: it_eabl5,it_eablg5.
AT LAST.
* IF wa_eablg5-ablesgr = '09'.
READ TABLE it_eabl5 INTO wa_eabl5 WITH KEY ablbelnr = l
wa_eablg5-ablbelnr.
* ablhinw = 'OK'.
IF sy-subrc = 0.
wa_bimd-pre_mtr_rdng_date = wa_eabl5-adat. "lv_mtr_ab
wa_bimd-pre_mtr_rdng = wa_eabl5-zz_v_zwstand.
* EXIT.
ENDIF.
* ENDIF.
ENDAT.
ENDLOOP.
* ENDIF.
wa_bimd-rdng_diff = wa_bimd-curr_mtr_rdng - wa_bimd-
pre_mtr_rdng.
wa_bimd-billed_consum = wa_bimd-rdng_diff.
wa_bimd-mult_fac = '1.00'.
ENDIF.
ELSE.
IF wa_tdoc-ablesgr = '01'.
IF wa_tdoc-ablesgrv = '06' OR
wa_tdoc-ablesgrv = '21' OR
wa_tdoc-ablesgrv = '14'.
wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ELSEIF wa_tdoc-ablesgrv = '01'.
IF wa_tdoc-sc_belnr IS INITIAL.
wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ELSE.
wa_bimd-billed_consum = wa_bimd-
billed_consum + wa_tdoc-i_abrmenge.
IF wa_tdoc-i_abrmenge LT 0.
wa_bimd-rdng_diff = wa_bimd-rdng_diff - wa_tdoc-
i_zwstdiff.
ELSE.
wa_bimd-rdng_diff = wa_bimd-rdng_diff + wa_tdoc-
i_zwstdiff.
ENDIF.
ENDIF.
ENDIF.
ELSEIF wa_tdoc-ablesgr = '22' OR wa_tdoc-ablesgr = '14'
OR wa_tdoc-ablesgr = '16'.
IF wa_tdoc-ablesgrv = '01' OR wa_tdoc-ablesgrv = '06'
OR wa_tdoc-ablesgrv = '14' OR wa_tdoc-ablesgrv = '11'.
wa_bimd-rdng_diff = wa_bimd-rdng_diff + wa_tdoc-
i_zwstdiff.
wa_bimd-billed_consum = wa_bimd-billed_consum + wa_tdoc-
i_abrmenge.
ENDIF.
ELSEIF wa_tdoc-ablesgr = '03'.
IF wa_tdoc-ablesgrv = '01' OR wa_tdoc-ablesgrv = '14'.
wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ENDIF.
******added by KiranD B10K902752*****************************
ELSEIF wa_tdoc-ablesgr = '10'.
IF wa_tdoc-ablesgrv = '01'.
wa_bimd-rdng_diff = wa_bimd-rdng_diff + wa_tdoc-
i_zwstdiff.
wa_bimd-billed_consum = wa_bimd-billed_consum + wa_tdoc-
i_abrmenge.
ENDIF.
******end of addition by KiranD B10K902752*******************
ENDIF.
ENDIF.
ENDIF.
ENDIF.
wa_bimd-invoiceno = lt_zbibd-invoiceno.
wa_bimd-contract_acc_no = lt_zbibd-contract_account.
SELECT SINGLE serge FROM equi INTO wa_bimd-
mnf_srl_no WHERE equnr = wa_tdoc-geraet.
wa_bimd-meter_no = wa_tdoc-geraet.
wa_bimd-register = wa_tdoc-zwnummer.
wa_bimd-bill_month = lt_zbibd-bill_month.
wa_bimd-date_of_invoice = lt_zbibd-date_of_invoice.
wa_bimd-meter_status = wa_tdoc-ablhinw.
wa_bimd-cur_mtr_type = wa_tdoc-istablart.
wa_bimd-curr_mtr_rdng_reason = wa_tdoc-ablesgr.
wa_bimd-billed_mtr_rdng = wa_tdoc-i_zwstndab.
* IF lv_lt_leg_adj = 'X'.
* ELSE.
wa_bimd-mult_fac = wa_tdoc-i_abrmenge / wa_tdoc-i_zwstdiff.
*Start of Addition by TMMANISHT on 12th April 2014
IF wa_bimd-mult_fac = '0.00'.
wa_bimd-mult_fac = '1.00'.
ENDIF.
*End of Addition by TMMANISHT on 12th April 2014
* ENDIF.
IF flag1 IS INITIAL.
IF lv_lt_leg_adj IS INITIAL.
wa_bimd-pre_mtr_rdng = wa_tdoc-i_zwstvor.
wa_bimd-curr_mtr_rdng = wa_tdoc-i_zwstand.
ELSEIF wa_tdoc-zwnummer = 2.
wa_bimd-pre_mtr_rdng = wa_tdoc-i_zwstvor.
wa_bimd-curr_mtr_rdng = wa_tdoc-i_zwstand.
ENDIF.
ENDIF.
wa_bimd-pre_mtr_rdng_reason = wa_tdoc-ablesgrv.
wa_bimd-pre_mtr_type = wa_tdoc-istablartva.
IF flag1 IS INITIAL.
IF lv_lt_leg_adj IS INITIAL.
IF last_date IS INITIAL.
wa_bimd-pre_mtr_rdng_date = wa_tdoc-ab.
ELSE.
wa_bimd-pre_mtr_rdng_date = wa_tdoc-ab - 1.
ENDIF.
ELSEIF wa_tdoc-zwnummer = 2.
IF last_date IS INITIAL.
wa_bimd-pre_mtr_rdng_date = wa_tdoc-ab.
ELSE.
wa_bimd-pre_mtr_rdng_date = wa_tdoc-ab - 1.
ENDIF.
ENDIF.
ENDIF.
IF lv_lt_leg_adj IS INITIAL.
wa_bimd-curr_mtr_rdng_date = wa_tdoc-bis.
ELSEIF wa_tdoc-zwnummer = 2.
wa_bimd-curr_mtr_rdng_date = wa_tdoc-bis.
ENDIF.
wa_bimd-uom = wa_tdoc-massbill.
IF cnt = 1.
APPEND wa_bimd TO gt_bimd.
ELSE.
IF wa_tdoc-ablesgr = '01'.
IF wa_tdoc-ablesgrv = '06' OR
wa_tdoc-ablesgrv = '21' OR
wa_tdoc-ablesgrv = '14' OR
wa_tdoc-ablesgrv = '17' OR
wa_tdoc-ablesgrv = '11'.
wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ELSEIF wa_tdoc-ablesgrv = '01'.
IF wa_tdoc-sc_belnr IS INITIAL.
wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ELSE.
wa_bimd-billed_consum = wa_bimd-billed_consum + wa_tdoc-
i_abrmenge.
IF wa_tdoc-i_abrmenge LT 0.
wa_bimd-rdng_diff = wa_bimd-rdng_diff - wa_tdoc-
i_zwstdiff.
ELSE.
wa_bimd-rdng_diff = wa_bimd-rdng_diff + wa_tdoc-
i_zwstdiff.
ENDIF.
ENDIF.
ENDIF.
ELSEIF wa_tdoc-ablesgr = '22' OR wa_tdoc-ablesgr = '14'.
IF wa_tdoc-ablesgrv = '01' OR wa_tdoc-ablesgrv = '06'.
wa_bimd-rdng_diff = wa_bimd-rdng_diff + wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_bimd-billed_consum + wa_tdoc-
i_abrmenge.
ENDIF.
ELSEIF wa_tdoc-ablesgr = '03'.
IF wa_tdoc-ablesgrv = '01' OR wa_tdoc-ablesgrv = '14'.
wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ENDIF.
ELSEIF wa_tdoc-ablesgr = '10'.
IF wa_tdoc-ablesgrv = '01'.
wa_bimd-rdng_diff = wa_bimd-rdng_diff + wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_bimd-billed_consum + wa_tdoc-
i_abrmenge.
ENDIF.
ENDIF.
ENDIF.
wa_bimd-invoiceno = lt_zbibd-invoiceno.
wa_bimd-contract_acc_no = lt_zbibd-contract_account.
SELECT SINGLE serge herst FROM equi INTO (wa_bimd-
mnf_srl_no,wa_bimd-meter_make)
WHERE equnr = wa_tdoc-
equnr. "geraet.
wa_bimd-meter_no = wa_tdoc-geraet.
wa_bimd-register = wa_tdoc-zwnummer.
wa_bimd-bill_month = lt_zbibd-bill_month.
wa_bimd-date_of_invoice = lt_zbibd-date_of_invoice.
wa_bimd-meter_status = wa_tdoc-ablhinw.
wa_bimd-cur_mtr_type = wa_tdoc-istablart.
wa_bimd-curr_mtr_rdng_reason = wa_tdoc-ablesgr.
wa_bimd-billed_mtr_rdng = wa_tdoc-i_zwstndab.
wa_bimd-mult_fac = wa_tdoc-i_abrmenge / wa_tdoc-i_zwstdiff.
IF wa_tdoc-zwnummer = '001'.
lv_mf = wa_bimd-mult_fac.
ENDIF.
IF wa_bimd-mult_fac = '0.00'.
wa_bimd-mult_fac = lv_mf.
ENDIF.
*Start of Addition by TMMANISHT on 12th April 2014
IF wa_bimd-mult_fac = '0.00'.
wa_bimd-mult_fac = '1.00'.
ENDIF.
*End of Addition by TMMANISHT on 12th April 2014
IF flag1 IS INITIAL.
wa_bimd-pre_mtr_rdng = wa_tdoc-i_zwstvor.
wa_bimd-curr_mtr_rdng = wa_tdoc-i_zwstand.
ENDIF.
IF wa_tdoc-zwnummer = '001'.
IF wa_tdoc-ablesgrv NE '06'. "Added on 22nd March 2014
wa_bimd-pre_mtr_rdng_date = wa_bimd-pre_mtr_rdng_date - 1.
ENDIF. "Added on 22nd March 2014
ENDIF.
IF cnt = 1.
APPEND wa_bimd TO gt_bimd.
ELSE.
CLEAR: flag1,it1_eabl,wa1_eabl.
cnt = cnt + 1.
IF wa_tdoc-zwnummer = '1' OR wa_tdoc-zwnummer = '2' OR
wa_tdoc-zwnummer = '3' OR wa_tdoc-zwnummer = '4' OR
wa_tdoc-zwnummer = '5' OR wa_tdoc-zwnummer = '6'.
IF 1 = 2.
CLEAR it1_eabl.
SELECT zwnummer adat zz_v_zwstand zz_n_zwstand FROM eabl INTO T
ABLE it1_eabl
WHERE equnr = wa_tdoc-
geraet AND adat LE lv_dt1."wa_tdoc-bis.
SORT it1_eabl BY adat DESCENDING.
READ TABLE it1_eabl INTO wa1_eabl INDEX 1.
IF sy-subrc = 0 AND wa_tdoc-zwnummer = '1'.
wa_bimd-pre_mtr_rdng = wa1_eabl-zz_v_zwstand.
wa_bimd-curr_mtr_rdng = wa1_eabl-zz_v_zwstand.
ENDIF.
DELETE it1_eabl WHERE register EQ '002'.
READ TABLE it1_eabl INTO wa1_eabl INDEX 2.
wa_bimd-pre_mtr_rdng_date = wa1_eabl-adat.
***********Added by Kiran TR
IF wa_tdoc-zwnummer = '2' AND wa_tdoc-ablhinw = 'MD'.
wa_bimd-pre_mtr_rdng = lt_zbibd-contract_demand_kw.
wa_bimd-curr_mtr_rdng = lt_zbibd-contract_demand_kw.
ENDIF.
flag1 = 'X'.
ELSE.
IF wa_tdoc-ablesgr = '01'.
IF wa_tdoc-ablesgrv = '06' OR
wa_tdoc-ablesgrv = '21' OR
wa_tdoc-ablesgrv = '14' OR
wa_tdoc-ablesgrv = '17'.
wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ELSEIF wa_tdoc-ablesgrv = '01'.
IF wa_tdoc-sc_belnr IS INITIAL.
wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ELSE.
wa_bimd-billed_consum = wa_bimd-billed_consum + wa_tdoc-
i_abrmenge.
IF wa_tdoc-i_abrmenge LT 0.
wa_bimd-rdng_diff = wa_bimd-rdng_diff - wa_tdoc-
i_zwstdiff.
ELSE.
wa_bimd-rdng_diff = wa_bimd-rdng_diff + wa_tdoc-
i_zwstdiff.
ENDIF.
ENDIF.
ENDIF.
ELSEIF wa_tdoc-ablesgr = '22' OR wa_tdoc-ablesgr = '14'.
IF wa_tdoc-ablesgrv = '01' OR wa_tdoc-ablesgrv = '06'.
wa_bimd-rdng_diff = wa_bimd-rdng_diff + wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_bimd-billed_consum + wa_tdoc-
i_abrmenge.
ENDIF.
ELSEIF wa_tdoc-ablesgr = '03'.
IF wa_tdoc-ablesgrv = '01' OR wa_tdoc-ablesgrv = '14'.
wa_bimd-rdng_diff = wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_tdoc-i_abrmenge.
ENDIF.
ELSEIF wa_tdoc-ablesgr = '10'.
IF wa_tdoc-ablesgrv = '01'.
wa_bimd-rdng_diff = wa_bimd-rdng_diff + wa_tdoc-i_zwstdiff.
wa_bimd-billed_consum = wa_bimd-billed_consum + wa_tdoc-
i_abrmenge.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
wa_bimd-invoiceno = lt_zbibd-invoiceno.
wa_bimd-contract_acc_no = lt_zbibd-contract_account.
SELECT SINGLE serge herst FROM equi INTO (wa_bimd-
mnf_srl_no,wa_bimd-meter_make)
WHERE equnr = wa_tdoc-
equnr. "geraet.
wa_bimd-meter_no = wa_tdoc-geraet.
wa_bimd-register = wa_tdoc-zwnummer.
wa_bimd-bill_month = lt_zbibd-bill_month.
wa_bimd-date_of_invoice = lt_zbibd-date_of_invoice.
wa_bimd-meter_status = wa_tdoc-ablhinw.
wa_bimd-cur_mtr_type = wa_tdoc-istablart.
wa_bimd-curr_mtr_rdng_reason = wa_tdoc-ablesgr.
wa_bimd-billed_mtr_rdng = wa_tdoc-i_zwstndab.
wa_bimd-mult_fac = wa_tdoc-i_abrmenge / wa_tdoc-i_zwstdiff.
IF wa_tdoc-zwnummer = '001'.
lv_mf = wa_bimd-mult_fac.
ENDIF.
IF wa_bimd-mult_fac = '0.00'.
wa_bimd-mult_fac = lv_mf.
ENDIF.
*Start of Addition by TMMANISHT on 12th April 2014
IF wa_bimd-mult_fac = '0.00'.
wa_bimd-mult_fac = '1.00'.
ENDIF.
*End of Addition by TMMANISHT on 12th April 2014
IF flag1 IS INITIAL.
wa_bimd-pre_mtr_rdng = wa_tdoc-i_zwstvor.
wa_bimd-curr_mtr_rdng = wa_tdoc-i_zwstand.
ENDIF.
IF wa_tdoc-zwnummer = '001'.
IF wa_tdoc-ablesgrv NE '06'. "Added on 22nd March 2014
wa_bimd-pre_mtr_rdng_date = wa_bimd-pre_mtr_rdng_date - 1.
ENDIF. "Added on 22nd March 2014
ENDIF.
IF cnt = 1.
APPEND wa_bimd TO gt_bimd.
ELSE.
CLEAR: cnt,wa_bimd1,date20,lv_indx,lv_dt1.
IF lt_zbibd-tariff_type+0(2) <> 'HT' AND lt_zbibd-
tariff_type+0(2) <> 'RT'.
SORT gt_bimd BY curr_mtr_rdng_date DESCENDING register ASCENDING.
READ TABLE gt_bimd INTO wa_bimd WITH KEY register = '002'." INDEX 2.
IF sy-
subrc = 0. " AND mr_note = 'OK'. " MR Note commented by Kiran TR:B10K902697
lt_zbibd-rcorded_demand = wa_bimd-curr_mtr_rdng.
ENDIF.
ENDIF.
IF lv_end_date GE '20170401'.
IF lt_zbibd-tariff_type+0(2) = 'LT' OR
lt_zbibd-tariff_type+0(2) = 'PU'.
READ TABLE it_tdoc INTO wa_tdoc WITH KEY bis = lv_end_date
zwnummer = '002'.
IF sy-subrc = 0.
lt_zbibd-rcorded_demand = wa_tdoc-i_zwstand.
ENDIF.
DELETE gt_bimd WHERE register = '002'.
ENDIF.
ENDIF.
****when PL Adj case comes then previous month reading Date shud be last PL
date
****but Reading should be of Last OK reading ****************
***LT_ZBIBD-BILL_DAYS shud be of current month it self. **************
IF lt_zbibd-tariff_type+0(2) <> 'HT' AND lt_zbibd-
tariff_type+0(2) <> 'RT'.
* IF NOT lt_zbibd-other_charges IS INITIAL." AND lv_lt_leg_adj = 'X'.
IF pl_adj = 'X'.
IF lv_lt_leg_adj = ''.
LOOP AT gt_bimd INTO wa_bimd WHERE register = '001'.
************added by Kiran TR B10K902697
CLEAR:it2_eabl,lv_indx.
lv_indx = sy-tabix.
SELECT zwnummer adat ablhinw v_zwstand n_zwstand FROM eabl INTO T
ABLE it2_eabl
WHERE equnr = wa_bimd-meter_no
AND zwnummer = wa_bimd-register
AND adat LE wa_bimd-pre_mtr_rdng_date.
IF NOT it2_eabl IS INITIAL.
SORT it2_eabl BY adat DESCENDING.
LOOP AT it2_eabl INTO wa2_eabl WHERE ablhinw = 'OK'.
wa_bimd-pre_mtr_rdng = wa2_eabl-v_zwstand + wa2_eabl-
n_zwstand.
wa_bimd-billed_consum = wa_bimd-curr_mtr_rdng - wa_bimd-
pre_mtr_rdng.
wa_bimd-rdng_diff = wa_bimd-billed_consum.
MODIFY gt_bimd FROM wa_bimd INDEX lv_indx
TRANSPORTING pre_mtr_rdng billed_consum rdng_diff
.
EXIT.
ENDLOOP.
ENDIF.
CLEAR: it2_eabl,wa2_eabl.
************end of addition by Kiran TR B10K902697
IF wa_bimd-curr_mtr_rdng_date IS NOT INITIAL AND wa_bimd-
pre_mtr_rdng_date IS NOT INITIAL.
lt_zbibd-bill_days = wa_bimd-curr_mtr_rdng_date - wa_bimd-
pre_mtr_rdng_date." + 1.
* IF lt_zbibd-bill_days GT 31.
* lt_zbibd-bill_days = 31.
* ENDIF.
ENDIF.
EXIT.
ENDLOOP.
ELSE.
IF lt_zbibd-finalbill <> 'X'.
LOOP AT gt_bimd INTO wa_bimd WHERE register = '001'.
CLEAR lv_indx.
lv_indx = sy-tabix.
IF NOT it_eabl9 IS INITIAL.
SORT it_eabl9 BY adat DESCENDING.
SORT it_eablg9 BY ablbelnr DESCENDING." ablesgr DESCENDING.
DELETE it_eabl9 WHERE adat GT wa_bimd-pre_mtr_rdng_date.
LOOP AT it_eabl9 INTO wa_eabl9 WHERE ablhinw = 'OK'.
READ TABLE it_eablg9 INTO wa_eablg9 WITH KEY ablbelnr = wa_
eabl9-ablbelnr." BINARY SEARCH.
IF sy-subrc = 0.
CHECK wa_eablg9-ablesgr = '09'.
wa_bimd-pre_mtr_rdng = wa_eabl9-v_zwstand + wa_eabl9-
n_zwstand.
wa_bimd-billed_consum = wa_bimd-curr_mtr_rdng - wa_bimd-
pre_mtr_rdng.
wa_bimd-rdng_diff = wa_bimd-billed_consum.
MODIFY gt_bimd FROM wa_bimd INDEX lv_indx TRANSPORTING pr
e_mtr_rdng billed_consum rdng_diff.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
CLEAR: it_eabl9,wa_eabl9.
IF wa_bimd-curr_mtr_rdng_date IS NOT INITIAL AND wa_bimd-
pre_mtr_rdng_date IS NOT INITIAL.
IF last_date IS INITIAL.
lt_zbibd-bill_days = wa_bimd-curr_mtr_rdng_date - wa_bimd-
pre_mtr_rdng_date + 1.
ELSE.
lt_zbibd-bill_days = wa_bimd-curr_mtr_rdng_date - wa_bimd-
pre_mtr_rdng_date.
ENDIF.
* IF lt_zbibd-bill_days GT 31.
* lt_zbibd-bill_days = 31.
* ENDIF.
ENDIF.
EXIT.
ENDLOOP.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
* BREAK-POINT.
*******From 01.04.17 LT* & PUBWW billed on kvah. If PL Adj comes for
******earlier and current fiscal year, then both entires to be shown in PWB
*****form. How much was billed on KwH in earlier year and how much billed
*****on KVAH in current year. For that below logic is written
CLEAR wa_bimd1.
IF lt_zbibd-tariff_type+0(2) = 'LT' OR
lt_zbibd-tariff_type+0(2) = 'PU' AND pl_adj = 'X'.
IF '20170401' BETWEEN lv_ab_date AND lv_end_date.
DELETE it_tdoc WHERE zwnummer = '002'.
READ TABLE it_tdoc INTO wa_tdoc WITH KEY ablesgr = '16'.
IF sy-subrc = 0.
CLEAR wa_bimd1.
wa_bimd1-invoiceno = lt_zbibd-invoiceno.
wa_bimd1-contract_acc_no = lt_zbibd-contract_account.
SELECT SINGLE serge FROM equi INTO wa_bimd1-
mnf_srl_no WHERE equnr = wa_tdoc-geraet.
wa_bimd1-meter_no = wa_tdoc-geraet.
wa_bimd1-register = wa_tdoc-zwnummer.
wa_bimd1-bill_month = lt_zbibd-bill_month.
wa_bimd1-date_of_invoice = lt_zbibd-date_of_invoice.
wa_bimd1-meter_status = wa_tdoc-ablhinw.
wa_bimd1-cur_mtr_type = wa_tdoc-istablart.
wa_bimd1-curr_mtr_rdng_reason = wa_tdoc-ablesgr.
wa_bimd1-billed_mtr_rdng = wa_tdoc-i_zwstndab.
wa_bimd1-mult_fac = wa_tdoc-i_abrmenge / wa_tdoc-i_zwstdiff.
wa_bimd1-curr_mtr_rdng_date = wa_tdoc-bis.
wa_bimd1-curr_mtr_rdng = wa_tdoc-i_zwstand.
* ENDIF.
ENDIF.
CLEAR it_tdoc.
****************UNMETERED cases all meter details to be BLANKED************
********
IF creation_date LE '20140831'.
ELSE.
IF gt_bimd IS INITIAL.
CLEAR: lt_zbibd-power_factor,
* lt_zbibd-bill_days,
lt_zbibd-tot_unit_billed,
gv_adj_days,
lt_zbibd-meter_provided_by.
ENDIF.
ENDIF.
* BREAK-POINT.
*****************End of Meter details********************
CLEAR: enforc_date,mess_judge,mess_abey,lv_totall.
*******************Enforcement Date****************************************
*********
SELECT SINGLE zorderdate INTO enforc_date FROM zcs_enf_amnt
WHERE zcontract = lt_zbibd-contract_account.
ENDIF.
IF NOT lt_abey IS INITIAL.
READ TABLE lt_abey INTO ls_abey INDEX 1.
IF sy-subrc = 0.
lv_totall = ls_abey-betrw.
CONDENSE: lv_totall,ls_abey-full_name,ls_abey-free_text.
CONCATENATE '*' 'Kept in Abeyance of Rs.' lv_totall
'against' ls_abey-full_name 'due to "'
ls_abey-
free_text '"' INTO mess_judge SEPARATED BY space.
ENDIF.
READ TABLE lt_abey INTO ls_abey INDEX 2.
IF sy-subrc = 0.
lv_totall = ls_abey-betrw.
CONDENSE: lv_totall,ls_abey-full_name,ls_abey-free_text.
CONCATENATE mess_judge '. And Kept in Abeyance of Rs.' lv_totall
'against' ls_abey-full_name 'due to "'
ls_abey-
free_text '"' INTO mess_judge SEPARATED BY space.
ENDIF.
ENDIF.
* lt_zbibd-amt_abey_with_dps = abs( lt_zbibd-amt_abey_with_dps ).
* lv_totall = lt_zbibd-amt_abey_with_dps.
* CONDENSE: lv_totall,ls_abey-full_name,ls_abey-free_text.
* CONCATENATE '*' 'Kept in Abeyance of Rs.' lv_totall
* 'against' ls_abey-full_name 'due to "'
* ls_abey-free_text '"' INTO mess_judge SEPARATED BY space.
ENDIF.
IF sd_rel = 'X'.
** inorder to save the SD release amount in ZBIBD, we are using
** LT_ZBIBD-SEC_DEP_HELD field after 01.04.2017
CLEAR: mess_judge, lv_totall,lt_zbibd-sec_dep_held.
IF lv_ab_date GE '20170401'.
lt_zbibd-sec_dep_held = sd_rel_amt.
ENDIF.
IF sd_rel_amt LT 0.
sd_rel_amt = sd_rel_amt * -1.
ENDIF.
lv_totall = sd_rel_amt.
CONDENSE: lv_totall.
* CONCATENATE '-' lv_totall INTO lv_totall. CONDENSE lv_totall.
CONCATENATE 'SD release amount Rs.' lv_totall 'is adjusted in the bill.
'
INTO mess_judge SEPARATED BY space.
ENDIF.
* IF lt_zbibd-amt_abey_with_dps IS NOT INITIAL.
* CONCATENATE '*' 'Arrear amount includes kept in abeyance,if any.' INTO
mess_abey.
* ENDIF.
****************************PF Remard message for HT cases*****************
****
CLEAR: pf_remark.
IF NOT lt_zbibd-power_factor IS INITIAL.
IF lt_zbibd-power_factor LT '0.63'.
CONCATENATE 'Your average PF for this month is below 70% so you are h
ereby'
'requested to improve PF, failing which your power supply will be cu
t off after'
'expiry of 7 days from date of dispatch of bill as per clause 7.4(c)
of BESC 2007.'
INTO pf_remark SEPARATED BY ' '.
ENDIF.
ENDIF.
*********************Messages**********************************************
****
IF 1 = 2.
CLEAR: t_zmessage1,lv_zmessage,lv_zmessage1,lv_zmessage2.
SELECT * FROM zinv_msg INTO TABLE t_zmessage1 WHERE sub_div = lt_zbibd-
sub_div_name
AND zab LE wa_doc_header-
budat AND zbis GE wa_doc_header-budat.
LOOP AT t_zmessage1 INTO wa_zmessage1.
IF ( wa_zmessage1-ztariiftype = lt_zbibd-tariff_type ).
CASE wa_zmessage1-zpriority.
WHEN '1'.
IF wa_zmessage1-sequence EQ '1'.
lv_zmessage = wa_zmessage1-description.
ELSEIF wa_zmessage1-sequence EQ '2'.
lv_zmessage1 = wa_zmessage1-description.
ELSEIF wa_zmessage1-sequence EQ '3'.
lv_zmessage2 = wa_zmessage1-description.
ENDIF.
WHEN '2'.
IF lv_zmessage IS INITIAL AND
wa_zmessage1-sequence EQ '1'.
lv_zmessage = wa_zmessage1-description.
ELSEIF lv_zmessage1 IS INITIAL
AND lv_zmessage IS NOT INITIAL
AND wa_zmessage1-sequence EQ '1'.
lv_zmessage1 = wa_zmessage1-description.
ELSEIF lv_zmessage1 IS NOT INITIAL
AND lv_zmessage IS NOT INITIAL
AND wa_zmessage1-sequence EQ '2'.
lv_zmessage2 = wa_zmessage1-description.
ELSEIF lv_zmessage2 IS INITIAL
AND lv_zmessage1 IS NOT INITIAL
AND wa_zmessage1-sequence EQ '3'.
lv_zmessage2 = wa_zmessage1-description.
ENDIF.
WHEN '3'.
IF lv_zmessage IS INITIAL AND
wa_zmessage1-sequence EQ '1'.
lv_zmessage = wa_zmessage1-description.
ELSEIF lv_zmessage1 IS INITIAL
AND lv_zmessage IS NOT INITIAL
AND wa_zmessage1-sequence EQ '1'.
lv_zmessage1 = wa_zmessage1-description.
ELSEIF lv_zmessage2 IS INITIAL
AND lv_zmessage1 IS NOT INITIAL
AND wa_zmessage1-sequence EQ '2'.
lv_zmessage2 = wa_zmessage1-description.
ELSEIF lv_zmessage1 IS NOT INITIAL
AND lv_zmessage IS NOT INITIAL
AND wa_zmessage1-sequence EQ '3'.
lv_zmessage2 = wa_zmessage1-description.
ENDIF.
ENDCASE.
ELSE.
CASE wa_zmessage1-zpriority.
WHEN '1'.
IF wa_zmessage1-sequence EQ '1'.
lv_zmessage = wa_zmessage1-description.
ELSEIF wa_zmessage1-sequence EQ '2'.
lv_zmessage1 = wa_zmessage1-description.
ELSEIF wa_zmessage1-sequence EQ '3'.
lv_zmessage2 = wa_zmessage1-description.
ENDIF.
WHEN '2'.
IF lv_zmessage IS INITIAL AND
wa_zmessage1-sequence EQ '1'.
lv_zmessage = wa_zmessage1-description.
ELSEIF lv_zmessage1 IS INITIAL
AND lv_zmessage IS NOT INITIAL
AND wa_zmessage1-sequence EQ '1'.
lv_zmessage1 = wa_zmessage1-description.
ELSEIF lv_zmessage1 IS NOT INITIAL
AND lv_zmessage IS NOT INITIAL
AND wa_zmessage1-sequence EQ '2'.
lv_zmessage2 = wa_zmessage1-description.
ELSEIF lv_zmessage2 IS INITIAL
AND lv_zmessage1 IS NOT INITIAL
AND wa_zmessage1-sequence EQ '3'.
lv_zmessage2 = wa_zmessage1-description.
ENDIF.
WHEN '3'.
IF lv_zmessage IS INITIAL AND
wa_zmessage1-sequence EQ '1'.
lv_zmessage = wa_zmessage1-description.
ELSEIF lv_zmessage1 IS INITIAL
AND lv_zmessage IS NOT INITIAL
AND wa_zmessage1-sequence EQ '1'.
lv_zmessage1 = wa_zmessage1-description.
ELSEIF lv_zmessage2 IS INITIAL
AND lv_zmessage1 IS NOT INITIAL
AND wa_zmessage1-sequence EQ '2'.
lv_zmessage2 = wa_zmessage1-description.
ELSEIF lv_zmessage1 IS NOT INITIAL
AND lv_zmessage IS NOT INITIAL
AND wa_zmessage1-sequence EQ '3'.
lv_zmessage2 = wa_zmessage1-description.
ENDIF.
ENDCASE.
ENDIF.
CLEAR : wa_zmessage1.
ENDLOOP.
ENDIF.
CLEAR: flag_bapi,wa_conversion,trans_flag,meter_flag,
dem_flag1,dem_flag2,dem_flag3,dem_amt,lv_amt90.
IF sy-uname = 'CRM_RFC'.
c-itcpo-tdpreview = 'X'.
ENDIF.
lt_zbibd-created_by = sy-uname.
lt_zbibd-created_on = sy-datum.
lt_zbibd-created_time = sy-uzeit.
isu_bill-t_doc_item = tt_doc_item.
lt_zbibd-energy_charge = lt_zbibd-energy_charge + lt_zbibd-
minimum_charge.
CLEAR: name.
name = '(SAPLZBAPI_ONLINE_BILL_PDF)IT_ZBIMD'.
CONDENSE name.
ASSIGN (name) TO <f1>.
IF sy-subrc IS INITIAL.
<f1> = gt_bimd.
ENDIF.
ENDLOOP.
IF xt_ranges1-low = 'CRM'.
EXIT.
ENDIF.
**used Message10 variable in ZBIBD for Legacy Adjustment flag and Total Bil
ls Days
IF lv_lt_leg_adj = 'X' OR pl_adj = 'X'. "lt_zbibd-
other_charges IS NOT INITIAL.
CONCATENATE 'L' gv_adj_days INTO lt_zbibd-message10.
CONDENSE lt_zbibd-message10.
ELSE.
lt_zbibd-message10 = 'N'.
ENDIF.
*******************************************
IF lt_zbibd-tariff_type+0(2) = 'HT' OR lt_zbibd-tariff_type+0(2) = 'RT'.
CLEAR: it_ettifn3,cntr,dem_amt,dem_flag1,dem_flag2,dem_flag3.
it_ettifn3 = it_ettifn.
SORT it_ettifn3 BY ab DESCENDING.
DELETE it_ettifn3 WHERE operand NE 'RCORDED_DM'.
DELETE it_ettifn3 WHERE ab GT lv_ab_date.
IF NOT lt_zbibd-contract_demand_kv IS INITIAL.
LOOP AT it_ettifn3 INTO wa_ettifn3.
CLEAR dem_amt.
cntr = cntr + 1.
IF cntr GT 3.
EXIT.
ENDIF.
dem_amt = ( lt_zbibd-contract_demand_kv * 110 ) / 100.
IF wa_ettifn3-wert1 GT dem_amt.
IF cntr = 1.
dem_flag1 = 'X'.
ELSEIF cntr = 2.
dem_flag2 = 'X'.
ELSEIF cntr = 3.
dem_flag3 = 'X'.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
IF dem_flag1 = 'X' AND dem_flag2 = 'X' AND dem_flag3 = 'X'.
zextra-
dem_mess1 = 'M.D. > 110% C.D for 3 consecutive mths, Get added C.D sanction
ed or limit drawl'.
ENDIF.
ENDIF.
********From 01.04.2018 for LT* and PUBWW KW will be converted to KVA
***** we need to divide KW value with '0.9' & do upper roundingoff
* BREAK TMKIRAND.
IF lv_end_date GE '20180401' and ( lt_zbibd-tariff_type = 'PUBWW' or
lt_zbibd-tariff_type+0(2) = 'LT' ).
zextra-ltdem_kva = ceil( lt_zbibd-contract_demand_kw / '0.9' ) .
CONDENSE zextra-ltdem_kva.
ENDIF.
**************************************************************
CLEAR form_name.
IF c-itcpo-tdpreview NE 'X' AND flag_bapi EQ ''.
CLEAR: l_inv,wa_inv.
*below changes done by Kiran for tuning the program
l_inv = lt_zbibd-invoiceno.
UNPACK l_inv TO l_inv.
* SELECT SINGLE opbel FROM dfkkop INTO wa_inv-zfidoc WHERE xblnr = l_inv
* AND vtref NE ''.
DELETE t_dfkkop WHERE xblnr NE l_inv.
DELETE t_dfkkop WHERE vtref EQ ''.
IF NOT t_dfkkop IS INITIAL.
READ TABLE t_dfkkop INTO wa_dfkkop INDEX 1.
ENDIF.
wa_inv-zfidoc = wa_dfkkop-opbel.
wa_inv-mandt = sy-mandt.
wa_inv-zcontract_ac = lt_zbibd-contract_account.
wa_inv-zinv_no = lt_zbibd-invoiceno.
wa_inv-zamount1 = lt_zbibd-net_amt_pbl_by_due_dt.
wa_inv-zamount2 = lt_zbibd-ppi_leviable.
wa_inv-zamount3 = lt_zbibd-net_amt_pbl_btwn_due_dt.
wa_inv-zamount4 = lt_zbibd-amt_pybl_aftr_due_date.
wa_inv-zamount5 = lv_dps_leviabl_amt * c_015.
wa_inv-zdate = lt_zbibd-due_date.
* Code inserted by venkat B10K907825
wa_inv-rebate = online_rebate."lt_zbibd-online_rebate.
*End of venkat B10K907825
********when Re-print is done, then do not update ZINV_AMT table**********
IF wa_print_doc-erdk-druckdat IS NOT INITIAL.
CLEAR:tmp_curr.
CALL FUNCTION 'ISU_S_LAST_PRINT_DOC'
EXPORTING
x_vkont = wa_print_doc-erdk-vkont
IMPORTING
y_erdk_ext_cur = tmp_curr
EXCEPTIONS
not_found = 1
system_error = 2
not_qualified = 3
OTHERS = 4.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
IF tmp_curr-opbel = lt_zbibd-invoiceno.
DELETE FROM zinv_amt WHERE zcontract_ac EQ wa_doc_header-vkont.
MODIFY zinv_amt FROM wa_inv.
ENDIF.
ELSE.
DELETE FROM zinv_amt WHERE zcontract_ac EQ wa_doc_header-vkont.
MODIFY zinv_amt FROM wa_inv.
ENDIF.
************************************************************
MODIFY zbibd FROM lt_zbibd.
MODIFY zbimd FROM TABLE gt_bimd.
IF sy-uname = 'SYS_SBM'.
EXIT.
ENDIF.
lt_zbibd-arrear_energy = lt_zbibd-arrear_energy +
lt_zbibd-arrear_ed.
lt_zbibd-arrear_other_chg = lt_zbibd-arrear_other_chg +
lt_zbibd-arrear_punitive_amt +
lt_zbibd-arrear_punitive_dps.
******added by KiranD B10K902752*****************************
* IF lt_zbibd-arrear_energy GT 0.
* CLEAR: lt_zbibd-pymt_on_account.
* ENDIF.
******end of addition by KiranD B10K902752*******************
lt_zbibd-other_charges = lt_zbibd-other_charges +
lt_zbibd-vat_on_meter_rent +
lt_zbibd-voltage_surcharge.
****Added by TMKIRAND for ROUNDO amount
****Ended by TMKIRAND for ROUNDO amount
ELSEIF lt_zbibd-tariff_type+0(2) = 'HT' or lt_zbibd-
tariff_type+0(2) = 'RT'.
lt_zbibd-meter_rent = lt_zbibd-meter_rent + lt_zbibd-meter_sgst +
lt_zbibd-meter_cgst.
ENDIF.
form_name = 'ZIS_LT_PRE_PRINTED'.
* form_name = 'ZIS_BILL_PRINT_ONLINE'.
ELSE.
*********Move to Smartform structure *********************************
IF lt_zbibd-tariff_type+0(2) <> 'HT' AND lt_zbibd-
tariff_type+0(2) <> 'RT'.
lt_zbibd-arrear_energy = lt_zbibd-arrear_energy +
lt_zbibd-arrear_ed.
lt_zbibd-arrear_other_chg = lt_zbibd-arrear_other_chg +
lt_zbibd-arrear_punitive_amt +
lt_zbibd-arrear_punitive_dps.
******added by KiranD B10K902752*****************************
* IF lt_zbibd-arrear_energy GT 0.
* CLEAR: lt_zbibd-pymt_on_account.
* ENDIF.
******end of addition by KiranD B10K902752*******************
lt_zbibd-other_charges = lt_zbibd-other_charges +
lt_zbibd-vat_on_meter_rent +
lt_zbibd-voltage_surcharge.
form_name = 'ZIS_BILL_PRINT_ONLINE'.
IF lv_end_date GE '20170701'.
form_name = 'ZIS_BILL_PRINT_ONLINE_2018'. "'ZIS_LT_PRE_PRINTED'.
ENDIF.
ELSEIF lt_zbibd-tariff_type+0(2) = 'HT' or lt_zbibd-
tariff_type+0(2) = 'RT'.
lt_zbibd-meter_rent = lt_zbibd-meter_rent + lt_zbibd-meter_sgst +
lt_zbibd-meter_cgst.
ENDIF.
ENDIF.
* venkat
IF lt_zbibd-last_pymt_amt IS INITIAL.
CLEAR sf_zbibd-last_pymt_amt.
ENDIF.
IF lt_zbibd-pymt_amt IS INITIAL.
CLEAR sf_zbibd-pymt_amt.
ENDIF.
CLEAR text1.
CONDENSE: sf_zbibd-connect_load_hp,
sf_zbibd-connect_load_kw,
sf_zbibd-contract_demand_kw,
sf_zbibd-contract_demand_kv,
sf_zbibd-rcorded_demand,
sf_zbibd-bar_code,
sf_zbibd-power_factor,
sf_zbibd-cont_dem_85,
sf_zbibd-last_pymt_amt,
sf_zbibd-pymt_amt,
sf_zbibd-bill_status,
sf_zbibd-minimum_unit,
sf_zbibd-tot_unit_billed,
sf_zbibd-bill_days,
sf_zbibd-old_acc_no,
sf_zbibd-mob_no.
zextra-creation_date = creation_date.
CONCATENATE sf_zbibd-sub_contract mon_no lt_zbibd-bill_month+6(2)
sf_zbibd-tariff_type sf_zbibd-invoiceno
INTO zextra-bill_no.
CONDENSE zextra-bill_no.
IF lt_zbibd-tariff_type+0(2) <> 'HT' AND lt_zbibd-
tariff_type+0(2) <> 'RT'.
*******************Copy Meter details data into Smartform type*************
**********************
IF lv_end_date GE '20170401'.
IF lt_zbibd-tariff_type+0(2) = 'LT' OR
lt_zbibd-tariff_type+0(2) = 'PU'.
IF pl_adj = 'X'.
ELSE.
SORT gt_bimd BY register.
ENDIF.
ELSE.
SORT gt_bimd BY register.
ENDIF.
ELSE.
SORT gt_bimd BY register.
ENDIF.
CLEAR dum.
LOOP AT gt_bimd INTO wa_bimd.
* IF last_date IS INITIAL and wa_bimd-register = '001'.
* wa_bimd-pre_mtr_rdng_date = wa_bimd-pre_mtr_rdng_date - 1.
* ENDIF.
MOVE-CORRESPONDING wa_bimd TO str_bimd.
PACK: str_bimd-meter_no TO str_bimd-meter_no.
* str_bimd-mnf_srl_no TO str_bimd-mnf_srl_no.
SPLIT str_bimd-pre_mtr_rdng AT '.' INTO str_bimd-pre_mtr_rdng dummy1.
SPLIT str_bimd-curr_mtr_rdng AT '.' INTO str_bimd-
curr_mtr_rdng dummy1.
SPLIT str_bimd-meter_no AT '.' INTO str_bimd-meter_no dummy1.
SPLIT str_bimd-billed_mtr_rdng AT '.' INTO str_bimd-
billed_mtr_rdng dummy1.
SPLIT str_bimd-rdng_diff AT '.' INTO str_bimd-rdng_diff dummy1.
SPLIT str_bimd-billed_consum AT '.' INTO str_bimd-
billed_consum dummy1.
SPLIT str_bimd-total_consum AT '.' INTO str_bimd-total_consum dummy1.
SPLIT str_bimd-avg_mmc_units AT '.' INTO str_bimd-
avg_mmc_units dummy1.
SPLIT str_bimd-mult_fac AT '.' INTO str_bimd-mult_fac dummy1.
CLEAR: dum.
dum = wa_bimd-curr_mtr_rdng_date.
CONCATENATE dum+6(2) '.' dum+4(2) '.' dum+2(2) INTO str_bimd-
curr_mtr_rdng_date.
CLEAR: dum.
dum = wa_bimd-pre_mtr_rdng_date.
CONCATENATE dum+6(2) '.' dum+4(2) '.' dum+2(2) INTO str_bimd-
pre_mtr_rdng_date.
CONDENSE: str_bimd-pre_mtr_rdng,
str_bimd-curr_mtr_rdng,
str_bimd-meter_no,
str_bimd-billed_mtr_rdng,
str_bimd-rdng_diff,
str_bimd-billed_consum,
str_bimd-total_consum,
str_bimd-avg_mmc_units,
str_bimd-mult_fac,
str_bimd-mnf_srl_no.
IF lv_end_date GE '20170401'.
IF lt_zbibd-tariff_type+0(2) = 'LT' OR
lt_zbibd-tariff_type+0(2) = 'PU'.
IF pl_adj = 'X' AND wa_bimd-register ='001'.
str_bimd-meter_no = 'KWH'.
ENDIF.
ENDIF.
ENDIF.
REPLACE FIRST OCCURRENCE OF '_dummy' IN str_bimd-
mnf_srl_no WITH '' IGNORING CASE.
REPLACE FIRST OCCURRENCE OF 'dummy' IN str_bimd-
mnf_srl_no WITH '' IGNORING CASE.
APPEND str_bimd TO sf_bimd.
ENDLOOP.
* BREAK-POINT.
********************WHEN ZEA60 IS EXECUTED, RAW FORM WILL BE CREATED AS SPO
OL
* ***************NEXT COMING FORMS WILL BE SAVED IN THE SAME SPOOL******
*****
IF c-itcpo-tdpreview NE 'X' AND flag_bapi EQ ''.
IF 1 = 1 and sy-tcode = 'EA60' AND lt_zbibd-
tariff_type+0(2) EQ 'LT' AND sy-batch NE 'X'.
output_options-tdcopies = c-itcpo-tdcopies.
output_options-tddest = 'ZHIN'."c-itcpo-tddest.
output_options-tdprinter = 'ZSWINCF'."c-itcpo-tdprinter.
output_options-tdnoprev = c-itcpo-
tdnoprev."PUT X HERE FOR SPOOL GENERATION
output_options-tdnoprint = c-itcpo-tdnoprint.
output_options-tdnewid = c-itcpo-
tdnewid."PUT X HERE FOR SPOOL GENERATION
output_options-tdimmed = c-itcpo-tdimmed.
output_options-tddelete = c-itcpo-tddelete.
output_options-tdlifetime = c-itcpo-tdlifetime.
output_options-tdarmod = '1'. "print_params-itcpo-tdarmod.
control-no_dialog = 'X'.
control-preview = ''."c-itcpo-tdpreview.
control-device = ''. "c-itcpp-tddevice.
control-getotf = 'X'."c-itcpo-
tdgetotf."DELETE X HERE FOR SPOOL GENERATION
CLEAR: job_output_info,name,l_document_output_info,l_job_output_opt
ions.
IF lv_end_date GE '20180401'.
form_name = 'ZIS_BILL_PRINT_ONLINE_2018'.
ELSE.
form_name = 'ZIS_BILL_PRINT_ONLINE'.
ENDIF.
CLEAR: pdf_table,pdf_fsize,lt_pdf_uc_data,l_cline,otf_table.
* BREAK-POINT.
REFRESH: it_pdf[].
otf_table = job_output_info-otfdata.
******************************************
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = pdf_fsize
TABLES
otf = otf_table
lines = pdf_table
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DATA: desktop TYPE string.
CALL METHOD cl_gui_frontend_services=>get_desktop_directory
CHANGING
desktop_directory = desktop
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
OTHERS = 3.
IF sy-subrc <> 0.
ENDIF.
ELSE.
output_options-tdcopies = c-itcpo-tdcopies.
output_options-tddest = 'ZHIN'."c-itcpo-tddest.
output_options-tdprinter = 'ZSWINCF'."c-itcpo-tdprinter.
output_options-tdnoprev = 'X'."c-itcpo-
tdnoprev."PUT X HERE FOR SPOOL GENERATION
output_options-tdnoprint = c-itcpo-tdnoprint.
**** output_options-tdnewid = c-itcpo-
tdnewid."PUT X HERE FOR SPOOL GENERATION
output_options-tdimmed = c-itcpo-tdimmed.
output_options-tddelete = c-itcpo-tddelete.
output_options-tdlifetime = c-itcpo-tdlifetime.
output_options-tdarmod = '1'. "print_params-itcpo-tdarmod.
control-no_dialog = 'X'.
control-preview = ''."c-itcpo-tdpreview.
control-device = ''. "c-itcpp-tddevice.
control-getotf = ' '."c-itcpo-
tdgetotf."DELETE X HERE FOR SPOOL GENERATION
* control-no_close = 'X'.
IF printflag IS INITIAL.
output_options-tdnewid = 'X'.
gv_invoice = sf_zbibd-invoiceno.
gv_mru = sf_zbibd-mru.
gv_time = sf_zbibd-created_time.
CONCATENATE gv_invoice '_' gv_mru '_' gv_time INTO gv_title.
CONDENSE gv_title.
output_options-tdcovtitle = gv_title.
printflag = 'X'.
ELSE.
output_options-tdcovtitle = gv_title.
output_options-tdnewid = ''.
ENDIF.
spool = spool + 1.
CLEAR: job_output_info,name,l_document_output_info,l_job_output_opt
ions.
EXIT.
ENDIF.
ELSE.
output_options-tdcopies = c-itcpo-tdcopies.
output_options-tddest = 'ZHIN'."c-itcpo-tddest.
output_options-tdprinter = 'ZSWINCF'."c-itcpo-tdprinter.
output_options-tdnoprev = c-itcpo-
tdnoprev."PUT X HERE FOR SPOOL GENERATION
output_options-tdnoprint = c-itcpo-tdnoprint.
output_options-tdnewid = c-itcpo-
tdnewid."PUT X HERE FOR SPOOL GENERATION
output_options-tdimmed = c-itcpo-tdimmed.
output_options-tddelete = c-itcpo-tddelete.
output_options-tdlifetime = c-itcpo-tdlifetime.
output_options-tdarmod = '1'. "print_params-itcpo-tdarmod.
control-no_dialog = 'X'.
control-preview = ''."c-itcpo-tdpreview.
control-device = ''. "c-itcpp-tddevice.
control-getotf = 'X'."c-itcpo-
tdgetotf."DELETE X HERE FOR SPOOL GENERATION
CLEAR: job_output_info,name,l_document_output_info,l_job_output_optio
ns.
REFRESH lt_pdf_uc_data.
"convert PDF data into binary format
*********************E-Bill**********************************
LOOP AT xt_ranges1 WHERE low = 'EMLO'.
CLEAR: name.
name = '(SAPLZBAPI_ONLINE_BILL_PDF)MTAB'.
CONDENSE name.
ASSIGN (name) TO <f1>.
IF sy-subrc IS INITIAL.
<f1> = lt_pdf_uc_data[].
ENDIF.
ENDLOOP.
IF xt_ranges1-low = 'EMLO'.
EXIT.
ENDIF.
*********************End of E-Bill**********************************
********************************************************************
***** IF printflag IS INITIAL.
***** CLEAR: physicpath,filename,additional_parameters.
*****
***** CALL FUNCTION 'FILE_GET_NAME_USING_PATH'
***** EXPORTING
***** client = sy-mandt
***** logical_path = logicpath
***** operating_system = sy-opsys "c_operating_sys "
***** file_name = c_dummy_file
***** IMPORTING
***** file_name_with_path = filename
***** EXCEPTIONS
***** path_not_found = 1
***** missing_parameter = 2
***** operating_system_not_found = 3
***** file_system_not_found = 4
***** OTHERS = 5.
***** IF sy-subrc <> 0.
****** Implement suitable error handling here
***** ENDIF.
***** REPLACE c_dummy_file WITH space INTO filename.
***** physicpath = filename.
***** CONCATENATE physicpath lt_zbibd-sub_div_code '_' sy-
datum+6(2) sy-datum+4(2) sy-datum+0(4)
***** INTO additional_parameters.
***** CONCATENATE physicpath sy-datum+6(2) '_' sy-datum+4(2) '_' sy-
datum+0(4)
***** INTO physicpath. "lt_zbibd-
sub_div_code '_'
***** printflag = 'X'.
***** ENDIF.
***** IF additional_parameters IS NOT INITIAL.
***** physicpath = additional_parameters.
***** CONCATENATE physicpath '_' lt_zbibd-
invoiceno '_LT.pdf' INTO physicpath.
***** CONDENSE physicpath.
***** OPEN DATASET physicpath FOR INPUT IN TEXT MODE ENCODING DEFAUL
T.
***** IF sy-subrc = 0.
***** DELETE DATASET physicpath.
***** ENDIF.
***** OPEN DATASET physicpath FOR OUTPUT IN BINARY MODE. "TEXT MODE
ENCODING DEFAULT. "BINARY MODE.
***** IF sy-subrc = 0.
***** LOOP AT lt_pdf_uc_data INTO wa_pdf_uc.
***** TRANSFER wa_pdf_uc TO physicpath.
***** ENDLOOP.
***** ENDIF.
***** CLOSE DATASET physicpath.
***** CLEAR: physicpath.
****** printflag = 'X'.
***** ENDIF.
*******************************************************************
* *******************************************************************
ELSE.
* BREAK-POINT.
*
* REFRESH: it_pdf[].
* otf_table = job_output_info-otfdata.
*
* CALL FUNCTION 'CONVERT_OTF'
* EXPORTING
* format = 'PDF'
* IMPORTING
* bin_filesize = pdf_fsize
* TABLES
* otf = otf_table
* lines = pdf_table
* EXCEPTIONS
* err_max_linewidth = 1
* err_format = 2
* err_conv_not_possible = 3
* OTHERS = 4.
*
* REFRESH lt_pdf_uc_data.
*
*
* LOOP AT pdf_table INTO l_cline.
* ASSIGN l_cline TO <l_xline> CASTING.
* APPEND <l_xline> TO lt_pdf_uc_data.
* ENDLOOP.
*
*
* DATA: T345 TYPE itcpo,
* spl TYPE ITCPP-TDSPOOLID.
* T345-tdcopies = c-itcpo-tdcopies.
* T345-tddest = 'ZHIN'."c-itcpo-tddest.
* T345-tdprinter = 'ZSWINCF'."c-itcpo-tdprinter.
* T345-tdnoprev = 'X'."c-itcpo-
tdnoprev."PUT X HERE FOR SPOOL GENERATION
* T345-tdnoprint = c-itcpo-tdnoprint.
* T345-tdnewid = 'X'."c-itcpo-tdnewid."PUT X HERE FOR SPOOL GENERATION
* T345-tdimmed = c-itcpo-tdimmed.
* T345-tddelete = c-itcpo-tddelete.
* T345-tdlifetime = c-itcpo-tdlifetime.
* T345-tdarmod = '1'. "print_params-itcpo-tdarmod.
** control-no_dialog = ' '.
* CALL FUNCTION 'PRINT_OTF'
* EXPORTING
* printoptions = T345
* IMPORTING
** OTF_PRINTER =
** OTF_DEVICETYPE =
** PRINT_SUCCESSFUL =
* SPOOLID = spl
* tables
* otf = lt_pdf_uc_data. "job_output_info-
otfdata.
* .
DO meter_flag TIMES.
str_bimd-parameters = 'Date'.
str_bimd-register = '990'.
APPEND str_bimd TO sf_bimd.
IF lv_daats_ab GE '20160401'.
str_bimd-parameters = 'KVAH'.
str_bimd-register = '005'.
APPEND str_bimd TO sf_bimd.
str_bimd-parameters = 'KWH'.
str_bimd-register = '001'.
APPEND str_bimd TO sf_bimd.
IF lt_zbibd-tariff_type = 'HTS-III_OP' OR
lt_zbibd-tariff_type = 'HTS-I_OP'.
str_bimd-parameters = 'KWH OPENACCESS'.
str_bimd-register = '011'.
APPEND str_bimd TO sf_bimd.
str_bimd-parameters = 'KVARH'.
str_bimd-register = '012'.
APPEND str_bimd TO sf_bimd.
ENDIF.
str_bimd-parameters = 'KVAH'.
str_bimd-register = '005'.
APPEND str_bimd TO sf_bimd.
ENDDO.
CLEAR: cntr,trans_flag,cntr2.
IF cfac IS INITIAL.
cfac = 1.
ENDIF.
CONDENSE: str_bimd-rdng_diff,str_bimd-curr_mtr_rdng,str_bimd-
pre_mtr_rdng.
MODIFY sf_bimd FROM str_bimd INDEX cntr.
CLEAR: str_bimd.
CONTINUE.
ENDIF.
ELSE.
IF cntr = 1 OR cntr = 8 OR cntr = 15 OR cntr = 22.
IF tod_flag IS INITIAL AND cntr LT 8.
READ TABLE gt_bimd INTO wa_bimd INDEX 1.
zextra-meter1 = wa_bimd-mnf_srl_no.
zextra-metermake1 = wa_bimd-meter_make.
ELSEIF tod_flag IS INITIAL AND cntr GT 7 AND cntr LT 15.
READ TABLE gt_bimd INTO wa_bimd INDEX 4.
zextra-meter2 = wa_bimd-mnf_srl_no.
zextra-metermake2 = wa_bimd-meter_make.
ELSEIF tod_flag IS INITIAL AND cntr GT 14 AND cntr LT 22.
READ TABLE gt_bimd INTO wa_bimd INDEX 7.
zextra-meter3 = wa_bimd-mnf_srl_no.
zextra-metermake3 = wa_bimd-meter_make.
ELSEIF tod_flag IS INITIAL AND cntr GT 21 AND cntr LT 29.
READ TABLE gt_bimd INTO wa_bimd INDEX 10.
zextra-meter4 = wa_bimd-mnf_srl_no.
zextra-metermake4 = wa_bimd-meter_make.
ELSE.
READ TABLE gt_bimd INTO wa_bimd INDEX cntr.
IF cntr LT 8.
zextra-meter1 = wa_bimd-mnf_srl_no.
zextra-metermake1 = wa_bimd-meter_make.
ELSEIF cntr GE 8 AND cntr LT 15.
zextra-meter2 = wa_bimd-mnf_srl_no.
zextra-metermake2 = wa_bimd-meter_make.
ELSEIF cntr GE 15 AND cntr LT 22.
zextra-meter3 = wa_bimd-mnf_srl_no.
zextra-metermake3 = wa_bimd-meter_make.
ELSEIF cntr GE 22 AND cntr LT 29.
zextra-meter4 = wa_bimd-mnf_srl_no.
zextra-metermake4 = wa_bimd-meter_make.
ENDIF.
ENDIF.
str_bimd-pre_mtr_rdng_date = wa_bimd-pre_mtr_rdng_date.
str_bimd-curr_mtr_rdng_date = wa_bimd-curr_mtr_rdng_date.
* str_bimd-rdng_diff = wa_bimd-curr_mtr_rdng_date - wa_bimd-
pre_mtr_rdng_date.
str_bimd-pre_mtr_rdng = str_bimd-pre_mtr_rdng_date.
CONCATENATE str_bimd-pre_mtr_rdng+6(2) str_bimd-
pre_mtr_rdng+4(2) str_bimd-pre_mtr_rdng+0(4)
INTO str_bimd-pre_mtr_rdng SEPARATED BY '.'.
str_bimd-curr_mtr_rdng = str_bimd-curr_mtr_rdng_date.
CONCATENATE str_bimd-curr_mtr_rdng+6(2) str_bimd-
curr_mtr_rdng+4(2) str_bimd-curr_mtr_rdng+0(4)
INTO str_bimd-curr_mtr_rdng SEPARATED BY '.'.
str_bimd-mnf_srl_no = wa_bimd-mnf_srl_no.
CONDENSE: str_bimd-rdng_diff,str_bimd-curr_mtr_rdng,str_bimd-
pre_mtr_rdng.
MODIFY sf_bimd FROM str_bimd INDEX cntr.
* wa_bimd-register = '777'.
* MODIFY gt_bimd FROM wa_bimd INDEX cntr TRANSPORTING register.
CLEAR: str_bimd.
CONTINUE.
ENDIF.
ENDIF.
READ TABLE gt_bimd INTO wa_bimd WITH KEY register = str_bimd-
register.
IF sy-subrc = 0.
cntr2 = sy-tabix.
wa_bimd-parameters = str_bimd-parameters.
CONDENSE: str_bimd-pre_mtr_rdng,
str_bimd-curr_mtr_rdng,
str_bimd-meter_no,
str_bimd-billed_mtr_rdng,
str_bimd-rdng_diff,
str_bimd-billed_consum,
str_bimd-total_consum,
str_bimd-avg_mmc_units,
str_bimd-mult_fac.
IF str_bimd-register = '005'.
ENDIF.
MODIFY sf_bimd FROM str_bimd INDEX cntr.
wa_bimd-register = '777'.
MODIFY gt_bimd FROM wa_bimd INDEX cntr2.
CLEAR cntr2.
ENDIF.
ENDLOOP.
sf_zbibd-meter_no = str_bimd-mnf_srl_no.
* BREAK-POINT.
IF lv_ab_date GE '20180401'.
SPLIT sf_zbibd-meter_sgst AT '.' INTO sf_zbibd-meter_sgst dummy1.
SPLIT sf_zbibd-meter_cgst AT '.' INTO sf_zbibd-meter_cgst dummy1.
CONCATENATE '(Incl:CGST Rs.' sf_zbibd-meter_sgst ','
'SGST Rs.' sf_zbibd-meter_cgst ')' INTO zextra-meter_gst.
endif.
CLEAR form_name.
IF lv_ab_date GE '20170401'.
form_name = 'ZIS_U_BILL_HT_2017'.
IF lt_zbibd-finalbill = 'X'.
form_name = 'ZIS_U_BILL_HT_FINAL_2017'.
ENDIF.
ELSE.
form_name = 'ZIS_U_BILL_HT_NEW'.
ENDIF.
* BREAK-POINT.
IF lt_zbibd-tariff_type = 'HTS-III_OP' OR
lt_zbibd-tariff_type = 'HTS-I_OP'.
form_name = 'ZIS_U_BILL_HT_OPENACCESS'.
ENDIF.
IF printflag IS INITIAL.
output_options-tdnewid = 'X'.
gv_invoice = sf_zbibd-invoiceno.
gv_mru = sf_zbibd-mru.
gv_time = sf_zbibd-created_time.
CONCATENATE gv_invoice '_' gv_mru '_' gv_time INTO gv_title.
CONDENSE gv_title.
output_options-tdcovtitle = gv_title.
printflag = 'X'.
ELSE.
output_options-tdcovtitle = gv_title.
output_options-tdnewid = ''.
ENDIF.
ELSE.
IF c-itcpo-tdpreview NE 'X'.
otf_table = job_output_info-otfdata.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = pdf_fsize
TABLES
otf = otf_table
lines = pdf_table
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
* DATA: data_tab TYPE TABLE OF x255,
* wa_tab TYPE x255.
* DATA: desktop TYPE string.
* desktop = 'C:\Documents and Settings\41007210\Desktop\kiran.pdf'.
*
* cl_gui_frontend_services=>gui_download(
* EXPORTING
* filename = desktop
* filetype = 'BIN'
* CHANGING
* data_tab = pdf_table ). "data_tab ) .
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
REFRESH lt_pdf_uc_data.
"convert PDF data into binary format
CONCATENATE filename sy-datum+6(2) '_' sy-datum+4(2) '_' sy-
datum+0(4) '_'
lt_zbibd-invoiceno '_HT.pdf' INTO filename.
CONDENSE filename.
LOOP AT pdf_table INTO l_cline.
ASSIGN l_cline TO <l_xline> CASTING.
APPEND <l_xline> TO lt_pdf_uc_data.
ENDLOOP.
*********************E-Bill**********************************
LOOP AT xt_ranges1 WHERE low = 'EMLO'.
CLEAR: name.
name = '(SAPLZBAPI_ONLINE_BILL_PDF)MTAB'.
CONDENSE name.
ASSIGN (name) TO <f1>.
IF sy-subrc IS INITIAL.
<f1> = lt_pdf_uc_data[].
ENDIF.
ENDLOOP.
IF xt_ranges1-low = 'EMLO'.
EXIT.
ENDIF.
*********************End of E-Bill**********************************
**********************************************************************
* OPEN DATASET filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.
* IF sy-subrc = 0.
* DELETE DATASET filename.
* ENDIF.
* OPEN DATASET filename FOR OUTPUT IN BINARY MODE. "TEXT MODE ENCODING
DEFAULT. "BINARY MODE.
* IF sy-subrc = 0.
* LOOP AT lt_pdf_uc_data INTO wa_pdf_uc.
* TRANSFER wa_pdf_uc TO filename.
* ENDLOOP.
* ENDIF.
* CLOSE DATASET filename.
* CLEAR: filename.
**********************************************************************
* ********************************************************************
**
ELSE.
CALL FUNCTION 'HR_IT_DISPLAY_WITH_PDF'
TABLES
otf_table = job_output_info-otfdata.
ENDIF.
ENDIF.
ENDFORM. "convert_currency
*&---------------------------------------------------------------------*
*& Form DELETE_ZERO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM delete_zero .
CONDENSE lv_num1 NO-GAPS.
SHIFT lv_num1 RIGHT DELETING TRAILING '0'.
SHIFT lv_num1 RIGHT DELETING TRAILING '.'.
CONDENSE lv_num1 NO-GAPS.