Professional Documents
Culture Documents
Link
Move Page AB
Click to select the
Tiny Link
Wiki Markup
Close
OK
Cancel
Search
Recently View ed
Failed to retrieve
Code Gallery
Page Ordering
Back
Reorder
Move
Unknow n user or
Page Restrictions
Editing restricted
Cancel
Close
Save
9055
Snippets
view
************************************************************************
* 31/07/2009 Wille A. Alcntara *
************************************************************************
report zfiaa0001 message-id 00 line-size 723
no standard page heading.
************************************************************************
* Include para Ole Excel *
************************************************************************
include ole2incl.
************************************************************************
* Tabelas *
************************************************************************
tables: anla,
anep,
anlp.
************************************************************************
* Work Areas *
************************************************************************
data: begin of wa_anla,
anln1 type anla-anln1,
anln2 type anla-anln2,
anlkl type anla-anlkl,
end of wa_anla,
begin of wa_anlc,
anln1 type anlc-anln1,
anln2 type anlc-anln2,
gjahr type anlc-gjahr,
kansw type anlc-kansw,
knafa type anlc-knafa,
end of wa_anlc,
begin of wa_anea,
anln1 type anea-anln1,
************************************************************************
data: t_anla like table of wa_anla,
t_anlc like table of wa_anlc,
t_anea like table of wa_anea,
t_anep like table of wa_anep,
t_anek like table of wa_anek,
t_anlp like table of wa_anlp,
t_anlz like table of wa_anlz,
t_ankt like table of wa_ankt,
t_t095b like table of wa_t095b,
t_skat like table of wa_skat,
t_saida like table of wa_saida,
t_totais like table of wa_saida,
t_select type table of char72.
************************************************************************
* Field-Symbols *
************************************************************************
field-symbols: <fs_campo> type any.
************************************************************************
* Variaveis *
************************************************************************
data: vg_ktopl type skat-ktopl value 'MONS',
vg_real(02) type c value 'R$',
vg_dolr(03) type c value 'USD',
vg_at01 type werks value 'AT01',
vg_at02 type werks value 'AT02',
vg_at03 type werks value 'AT03',
vg_at04 type werks value 'AT04',
vg_at05 type werks value 'AT05',
vg_020 type anep-bwasl value '020',
vg_101 type anep-bwasl value '101',
vg_114 type anep-bwasl value '114',
vg_200 type anep-bwasl value '200',
vg_300 type anep-bwasl value '300',
vg_310 type anep-bwasl value '310',
vg_331 type anep-bwasl value '331',
vg_336 type anep-bwasl value '336',
vg_338 type anep-bwasl value '338',
vg_339 type anep-bwasl value '339',
vg_dtin type d,
vg_dtfi type d,
vg_dtin_ant type d,
vg_dtfi_ant type d,
vg_c type c value 'C',
vg_d type c value 'D',
vg_z type c value 'Z',
vg_x type c value 'X',
vg_12104000 type anla-anlkl value '12104000',
vg_12104001 type anla-anlkl value '12104001',
vg_empresa type t001-butxt,
vg_descr type t001-butxt,
vg_atual(17) type c,
vg_anterior(17) type c,
vg_titulo(91) type c,
vg_campo(30) type c.
* Declaraes Para OLE EXCEL
data: vg_excel type ole2_object,
vg_workbooks type ole2_object,
vg_cells type ole2_object,
vg_cell1 type ole2_object,
vg_cell2 type ole2_object,
vg_sheet type ole2_object,
vg_col type i,
vg_lin type i.
************************************************************************
* Selection-Screen *
************************************************************************
selection-screen begin of block blck with frame title text-000.
parameter: p_bukrs like anla-bukrs obligatory,
p_year like anlp-gjahr obligatory.
select-options: s_peri for anlp-afbnr obligatory.
parameter: p_afab like anep-afabe obligatory.
selection-screen end of block blck.
selection-screen begin of screen 0100 title text-039.
parameter: p_ver as checkbox,
p_file type rlgrap-filename obligatory.
selection-screen end of screen 0100.
************************************************************************
* At Selection Screen *
************************************************************************
at selection-screen on value-request for p_file.
perform f_salva_arquivo using p_file.
************************************************************************
* At User Command *
************************************************************************
at user-command.
case sy-ucomm.
when 'LEAV'.
perform f_limpa_dados.
leave to screen 0.
when 'CANC'.
perform f_limpa_dados.
leave program.
when 'BT_EXCEL'.
perform: f_call_screen,
f_gera_excel.
endcase.
************************************************************************
* Start-Of-Selection *
************************************************************************
start-of-selection.
stop.
endif.
refresh t_select.
perform f_monta_select using 'WA_ANEA'.
select (t_select)
from anea
into table t_anea
for all entries in t_anek
where bukrs eq p_bukrs
and anln1 eq t_anek-anln1
and anln2 eq t_anek-anln2
and gjahr eq p_year
and afabe eq p_afab.
refresh t_select.
perform f_monta_select using 'WA_ANEP'.
select (t_select)
from anep
into table t_anep
for all entries in t_anek
where bukrs eq p_bukrs
and anln1 eq t_anek-anln1
and anln2 eq t_anek-anln2
and gjahr eq p_year
and afabe eq p_afab.
refresh t_select.
perform f_monta_select using 'WA_ANLP'.
select (t_select)
from anlp
into table t_anlp
for all entries in t_anek
where bukrs eq p_bukrs
and anln1 eq t_anek-anln1
and anln2 eq t_anek-anln2
and gjahr eq p_year
and afaber eq p_afab.
refresh t_select.
perform f_monta_select using 'WA_ANLZ'.
select (t_select)
from anlz
into table t_anlz
for all entries in t_anek
where bukrs eq p_bukrs
and anln1 eq t_anek-anln1
and anln2 eq t_anek-anln2.
refresh t_select.
perform f_monta_select using 'WA_ANKT'.
select (t_select)
from ankt
into table t_ankt
wa_saida-at03_1 = wa_saida-tot_ant2.
collect wa_saida into t_saida.
check wa_anla-anlkl ne vg_12104000
and wa_anla-anlkl ne vg_12104001.
clear: wa_saida-tot_ant2,
wa_saida-tot_ant5,
wa_saida-at03_1.
* Depreciao Acumulada Perodo Anterior
perform f_trata_deprec_acum using wa_saida-tot_ant2
wa_saida-tot_ant5.
wa_saida-at03_1 = wa_saida-tot_ant2.
collect wa_saida into t_saida.
when vg_at04.
perform: f_somatoria using wa_anlc-kansw wa_anep-anbtr
changing wa_saida-tot_ant3,
f_total_bloco using wa_saida-tot_ant3
changing wa_saida-tot_ant5.
wa_saida-at04_1 = wa_saida-tot_ant3.
collect wa_saida into t_saida.
check wa_anla-anlkl ne vg_12104000
and wa_anla-anlkl ne vg_12104001.
clear: wa_saida-tot_ant3,
wa_saida-tot_ant5.
* Depreciao Acumulada Perodo Anterior
perform f_trata_deprec_acum using wa_saida-tot_ant3
wa_saida-tot_ant5.
wa_saida-at04_1 = wa_saida-tot_ant3.
collect wa_saida into t_saida.
when vg_at05.
perform: f_somatoria using wa_anlc-kansw wa_anep-anbtr
changing wa_saida-tot_ant4,
f_total_bloco using wa_saida-tot_ant4
changing wa_saida-tot_ant5.
wa_saida-at05_1 = wa_saida-tot_ant4.
collect wa_saida into t_saida.
check wa_anla-anlkl ne vg_12104000
and wa_anla-anlkl ne vg_12104001.
clear: wa_saida-tot_ant4,
wa_saida-tot_ant5.
* Depreciao Acumulada Perodo Anterior
perform f_trata_deprec_acum using wa_saida-tot_ant4
wa_saida-tot_ant5.
wa_saida-at05_1 = wa_saida-tot_ant4.
collect wa_saida into t_saida.
endcase.
else.
perform f_monta_sum_dep using wa_anlp-nafag wa_anlp-nafaz
wa_anea-nafav wa_anea-nafal
wa_anlc-knafa
changing wa_saida-total_2.
wa_saida-total_7 = wa_saida-total_2.
endif.
collect wa_saida into t_saida.
when vg_at03.
perform f_monta_intermediario using wa_saida-at03_2
wa_saida-at03_3
wa_saida-at03_4
wa_saida-at03_5
wa_saida-total_4.
collect wa_saida into t_saida.
* Trata Totais - ltimo Bloco
clear: wa_saida-at03_1,
wa_saida-at03_2,
wa_saida-at03_3,
wa_saida-at03_4,
wa_saida-at03_5,
wa_saida-resu_1,
wa_saida-resu_2,
wa_saida-resu_3,
wa_saida-resu_4,
wa_saida-resu_5,
wa_saida-total_4.
check wa_anla-anlkl ne vg_12104000
and wa_anla-anlkl ne vg_12104001.
* Depreciao Acumulada Perodo Atual
perform f_trata_depre_acum_atual using wa_saida-at03_2
wa_saida-at03_4
wa_saida-at03_5.
perform f_monta_sum_dep using wa_anlp-nafag wa_anlp-nafaz
wa_anea-nafav wa_anea-nafal
wa_anlc-knafa
changing wa_saida-total_4.
wa_saida-total_7 = wa_saida-total_4.
collect wa_saida into t_saida.
when vg_at04.
perform f_monta_intermediario using wa_saida-at04_2
wa_saida-at04_3
wa_saida-at04_4
wa_saida-at04_5
wa_saida-total_5.
collect wa_saida into t_saida.
* Trata Totais - ltimo Bloco
clear: wa_saida-at04_1,
wa_saida-at04_2,
wa_saida-at04_3,
wa_saida-at04_4,
wa_saida-at04_5,
wa_saida-resu_1,
wa_saida-resu_2,
wa_saida-resu_3,
wa_saida-resu_4,
wa_saida-resu_5,
wa_saida-total_5.
check wa_anla-anlkl ne vg_12104000
and wa_anla-anlkl ne vg_12104001.
* Depreciao Acumulada Perodo Atual
perform f_trata_depre_acum_atual using wa_saida-at04_2
wa_saida-at04_4
wa_saida-at04_5.
perform f_monta_sum_dep using wa_anlp-nafag wa_anlp-nafaz
wa_anea-nafav wa_anea-nafal
wa_anlc-knafa
changing wa_saida-total_5.
wa_saida-total_7 = wa_saida-total_5.
collect wa_saida into t_saida.
when vg_at05.
perform f_monta_intermediario using wa_saida-at05_2
wa_saida-at05_3
wa_saida-at05_4
wa_saida-at05_5
wa_saida-total_6.
collect wa_saida into t_saida.
* Trata Totais - ltimo Bloco
clear: wa_saida-at05_2,
wa_saida-at05_3,
wa_saida-at05_4,
wa_saida-at05_5,
wa_saida-resu_1,
wa_saida-resu_2,
wa_saida-resu_3,
wa_saida-resu_4,
wa_saida-resu_5,
wa_saida-total_6.
check wa_anla-anlkl ne vg_12104000
and wa_anla-anlkl ne vg_12104001.
* Depreciao Acumulada Perodo Atual
perform f_trata_depre_acum_atual using wa_saida-at05_2
wa_saida-at05_4
wa_saida-at05_5.
perform f_monta_sum_dep using wa_anlp-nafag wa_anlp-nafaz
wa_anea-nafav wa_anea-nafal
wa_anlc-knafa
changing wa_saida-total_6.
wa_saida-total_7 = wa_saida-total_6.
collect wa_saida into t_saida.
endcase.
endform. " f_trata_intermediario
*&---------------------------------------------------------------------*
*& Form f_writer
*&---------------------------------------------------------------------*
form f_writer.
data: vl_classe(35) type c,
vl_x type c,
vl_y type c.
sort: t_saida by tipo classe.
* Monta Cabealho
select single butxt
into vg_empresa
from t001
where bukrs eq p_bukrs
and spras eq sy-langu.
* Imprime Linha Inicial
perform f_linha.
concatenate p_bukrs vg_empresa into vg_descr separated by space.
concatenate text-002 vg_real into vg_titulo separated by space.
if p_afab eq 10.
concatenate text-002 vg_dolr into vg_titulo separated by space.
endif.
perform: f_primeiro_cabec,
f_segundo_cabec using vg_descr vg_empresa,
f_terceiro_cabec,
f_pri_lin_total.
loop at t_saida into wa_saida.
concatenate wa_saida-classe '-' wa_saida-descr
into vl_classe separated by space.
format color 2 intensified off.
if wa_saida-tipo eq vg_c
or wa_saida-tipo eq vg_z.
if wa_saida-tipo eq vg_z
and vl_y is initial.
format color 5 intensified off.
read table t_totais into wa_totais with key tipo = vg_z.
write: /(001) sy-vline,
002(35) text-037 centered.
perform f_imprime_rel using wa_totais.
*&---------------------------------------------------------------------*
form f_trata_deprec_acum using p_total like anlc-kansw
p_tot_f like anlc-kansw.
wa_saida-classe = wa_t095b-ktnafb.
wa_saida-descr = wa_skat-txt20.
wa_saida-tipo = vg_d.
perform f_monta_sum_dep using wa_anlp-nafag wa_anlp-nafaz
wa_anea-nafav wa_anea-nafal
wa_anlc-knafa
changing p_total.
perform f_total_bloco using p_total
changing p_tot_f.
endform. " f_trata_deprec_acum
*&---------------------------------------------------------------------*
*& Form f_trata_depre_acum_atual
*&---------------------------------------------------------------------*
form f_trata_depre_acum_atual using p_campo_2
p_campo_4
p_campo_5.
wa_saida-classe = wa_t095b-ktnafb.
wa_saida-descr = wa_skat-txt20.
wa_saida-resu_2 = p_campo_2 = wa_anlp-nafaz.
if wa_anep-bwasl eq vg_020
or wa_anep-bwasl eq vg_101
or wa_anep-bwasl eq vg_114.
wa_saida-resu_4 = p_campo_4 = wa_anea-nafav.
endif.
perform f_monta_sum_dep using wa_anlp-nafag wa_anlp-nafaz
wa_anea-nafav wa_anea-nafal
wa_anlc-knafa
changing p_campo_5.
wa_saida-resu_1 = p_campo_5.
perform f_calcula_resumo using wa_saida-resu_2 wa_saida-resu_3
wa_saida-resu_4 wa_saida-resu_5.
wa_saida-tipo = vg_d.
endform. " f_trata_depre_acum_atual
*&---------------------------------------------------------------------*
*& Form F_PRIMEIRO_CABEC
*&---------------------------------------------------------------------*
form f_primeiro_cabec.
data: vl_periodo(02) type n.
vl_periodo = ( s_peri-low - 1 ).
perform f_monta_mes using vl_periodo
changing vg_anterior.
perform f_monta_mes using s_peri-high
changing vg_atual.
changing p_mes.
when 08.
perform f_concatena using text-010
changing p_mes.
when 09.
perform f_concatena using text-011
changing p_mes.
when 10.
perform f_concatena using text-012
changing p_mes.
when 11.
perform f_concatena using text-013
changing p_mes.
when 12.
perform f_concatena using text-014
changing p_mes.
endcase.
endform. " F_MONTA_MES
*&---------------------------------------------------------------------*
*& Form f_segundo_cabec
*&---------------------------------------------------------------------*
form f_segundo_cabec using p_empresa
p_desc.
format color 3 intensified off.
write: /(001) sy-vline,
002(35) p_empresa centered,
038(17) text-015 centered,
056(17) text-016 centered,
074(17) text-017 centered,
092(17) text-018 centered,
110(17) p_desc centered,
127(01) sy-vline,
129(01) sy-vline,
130(91) text-015 centered,
220(01) sy-vline,
222(01) sy-vline,
223(91) text-016 centered,
313(01) sy-vline,
315(01) sy-vline,
316(91) text-017 centered,
406(01) sy-vline,
408(01) sy-vline,
409(91) text-018 centered,
499(01) sy-vline,
501(01) sy-vline,
502(91) text-026 centered,
592(01) sy-vline,
594(01) sy-vline,
631(17) text-015 centered,
649(17) text-016 centered,
667(17) text-017 centered,
685(17) text-018 centered,
p_resu_4
p_resu_5.
p_resu_5 = p_resu_2 + p_resu_3 + p_resu_4.
endform. " f_calcula_resumo
*&---------------------------------------------------------------------*
*& Form f_linha
*&---------------------------------------------------------------------*
form f_linha.
write: /001(127) sy-uline,
129(092) sy-uline,
222(092) sy-uline,
315(092) sy-uline,
408(092) sy-uline,
501(092) sy-uline,
594(128) sy-uline.
endform. " f_linha
*&---------------------------------------------------------------------*
*& Form f_concatena
*&---------------------------------------------------------------------*
form f_concatena using p_texto
changing p_mes.
case p_afab.
when 01.
concatenate p_texto '-' vg_real into p_mes separated by space.
when 10.
concatenate p_texto '-' vg_dolr into p_mes separated by space.
endcase.
endform. " f_concatena
*&---------------------------------------------------------------------*
*& Form f_cria_planilha
*&---------------------------------------------------------------------*
form f_cria_planilha.
data: vl_visible type i.
vl_visible = 1.
if p_ver is initial.
vl_visible = 0.
endif.
* Cria aplicao Excel
create object vg_excel 'EXCEL.APPLICATION'.
set property of vg_excel 'DisplayAlerts' = 0.
call method of vg_excel 'WORKBOOKS' = vg_workbooks.
set property of vg_excel 'VISIBLE' = vl_visible.
* Criao do WorkBook
set property of vg_excel 'SheetsInNewWorkbook' = 1.
call method of vg_workbooks 'ADD'.
call method of vg_excel 'WORKSHEETS' = vg_sheet.
#1 = vg_cell1
#2 = vg_cell2.
call method of vg_cells 'Select' .
call method of vg_cells 'Merge' .
call method of vg_excel 'Cells' = vg_cell1
exporting
#1 = p_l2
#2 = p_c1.
set property of vg_cell1 'HorizontalAlignment' = -4108 .
set property of vg_cell1 'VerticalAlignment' = -4108 .
endform. " f_mescla_celulas
*&---------------------------------------------------------------------*
*& Form f_add_field
*&---------------------------------------------------------------------*
form f_add_field using p_linha type i
p_coluna type i
p_valor.
call method of vg_excel 'Cells' = vg_cell1
exporting
#1 = p_linha
#2 = p_coluna.
set property of vg_cell1 'Value' = p_valor.
endform. " f_add_field
*&---------------------------------------------------------------------*
*& Form f_monta_linhas
*&---------------------------------------------------------------------*
form f_monta_linhas.
data: vl_dep type c,
vl_and type c.
refresh t_select.
perform f_monta_select using 'WA_SAIDA'.
* Monta Primeira Linha de Totais
perform f_mescla_celulas using 4 1 4 2 text-027.
read table t_totais into wa_totais with key tipo = space.
perform f_print_line using 4 wa_totais vg_x.
* Monta Segunda Linha de Totais
perform f_mescla_celulas using 5 1 5 2 text-028.
read table t_totais into wa_totais with key tipo = vg_c.
perform f_print_line using 5 wa_totais vg_x.
* Monta Linhas
vg_lin = 6.
loop at t_saida into wa_saida.
* Imprime Cabealho para Depreciao Acumulada
if wa_saida-tipo eq vg_d
and vl_dep is initial.
*&---------------------------------------------------------------------*
*& Form f_limpa_dados
*&---------------------------------------------------------------------*
form f_limpa_dados.
clear: wa_anla, wa_anlc, wa_anea, wa_anep,
wa_anek, wa_anlp, wa_anlz, wa_ankt,
wa_t095b, wa_skat, wa_saida, wa_totais.
refresh: t_anla, t_anlc, t_anea, t_anep,
t_anek, t_anlp, t_anlz, t_ankt,
t_t095b, t_skat, t_saida, t_totais, t_select.
free: t_anla, t_anlc, t_anea, t_anep,
t_anek, t_anlp, t_anlz, t_ankt,
t_t095b, t_skat, t_saida, t_totais, t_select.
free object: vg_excel, vg_workbooks, vg_cells,
vg_cell1, vg_cell2, vg_sheet.
endform. " f_limpa_dados