Você está na página 1de 54

**********************************************************************

**
*
*
* ********************************************
*
* * Confidencial e Proprietrio *
*
* * Copyright 1999, Andersen Consulting *
*
* * Todos os direitos reservados *
*
* ********************************************
*
*
*
* Nome do Shell: YBRA001 Verso do Shell: v1.01
*
*
*
**********************************************************************
**
* Nome do Programa : ZRAAGAE02
*
* Ttulo do Programa : Tela para Baixas
*
* Programador : Cristiano Armellini
*
* Data : 03/12/99
*
* ltima atualizao : 03/12/99
*
*
*
* Descrio : Este um programa report para permitir a seleo de
* imobilizados para realizao da baixa
*
*
*
* Include :
*
*
*
* Calls :
*
*
*
* Mdulos de Funes:
*
*
*
*---------------------------------------------------------------------
-*
* Lista de Modificaes:
*
* Data Autor Corr. # Descrio
*
* dd/mm/aa METROABAP08 T01K905891 Desenvolvimento inicial do prg
*
* 08/01/00 ABAPERTEAM Melhoria de performance
*
* 31/07/00 Auro Tipo de movto depende de zugdt
* 15/08/00 Nilson-04477 No baixava imobilizados
* 16/08/00 Nilson-05497 Wire - Centro de Custos
**********************************************************************
**
*---------------------------------------------------------------------
-*
* ALTERAOES
*
*---------------------------------------------------------------------
-*
* NM.| AUTOR | DATA | DESCRIO
*
*---------------------------------------------------------------------
-*
* 001 | M540283 | 23/11/05 | UPGRADE: Foi alterado o SHDB da chamada
*
* | | | do CALL TRANSACTION da AS02 (Modif.
*
* | | | Imobilizado).
*
*---------------------------------------------------------------------
-*
REPORT zraagae02
NO STANDARD PAGE HEADING "No mostra o cabealho padro SAP
LINE-SIZE 167 "Largura do report de nnn caracteres
LINE-COUNT 58 "Comprimento do report de nn caracteres
MESSAGE-ID zm. "Classe de mensagens ZM

RESERVE 8 LINES. "Pelo menos n linhas sero impressas na ltima pgi


na

"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>"
" SESSO DE DECLARAO DE DADOS "
"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>"
**********************************************************************
**
* Includes
*
**********************************************************************
**
INCLUDE:
zziheadr. "Cabealho padro de report

* Alterao - Marcos Paixo - 22.10.2014 - Incio


TYPE-POOLS: abap.
* Alterao - Marcos Paixo - 22.10.2014 - Fim

**********************************************************************
**
* Tabelas
*
**********************************************************************
**
TABLES: cskt, "Textos de centros de custo
tabwt, "Textos dos tipos de mov. da cont.do imo
b.
t003, "Tipos de documento
t087g, "Critrio de classificao de 8 posies
anla, "Segmento do registro mestre do imobiliz
ad
anlz, "Atribuies de imobilizado com data val
or
aufk, "Dados mestre da ordem
anek. "Cabealho de doc. do lanc. de imob.

**********************************************************************
**
* Dados:
*
* Constantes (C_...)
*
* Variaveis (V_...)
*
* Tabelas Internas (T_...)
*
**********************************************************************
**
*- Constantes --------------------------------------------------------
-*
DATA:
c_trans(4) TYPE c VALUE 'ZA12', "Transao do Report
c_abav(4) TYPE c VALUE 'ABAV', "Transao ABAV
c_as02(4) TYPE c VALUE 'AS02', "Transao AS02
c_pt TYPE c VALUE 'P', "Idioma Portugus
c_mode TYPE c VALUE 'E', "Modo de exec. do Call Transac.
c_cc10(4) TYPE c VALUE 'CC10', "rea de cont. de Custo
c_200(3) TYPE n VALUE '200', "Tipo de Mov.
c_250(3) TYPE n VALUE '250', "Tipo de Mov.
* Nilson-15/08/00-04477
c_data_lim LIKE anla-zugdt VALUE '19991231', "Data Limite
* c_data_lim TYPE d VALUE '31.12.99',"Data limite p/ tipo mov.
c_area_aval(2) TYPE c VALUE '01'. "Area de avaliao
*- Variveis ---------------------------------------------------------
*
DATA:
v_check TYPE c,
v_qtd_ch(17) TYPE c, "Quantidade Digitada em CHAR
v_qtd_ch2(17) TYPE c, "Quantidade Digitada em CHAR
v_quant LIKE anla-menge, "Quantidade Digitada
v_menge LIKE anla-menge, "Qtde somada de todos os sub no
.
v_menge_c(17) TYPE c, "Qtde no formato CHAR
v_menge_dep LIKE anla-menge, "Qtde Baixada de cada Imob.
v_kansw LIKE anlc-kansw, "Valor do Imobilizado
v_nafad LIKE anlc-nafap, "Valor da Depreciao
v_tabix LIKE sy-tabix, "Indice da tabela interna
* v_ordem(12) type c, "Ordem "SIR-
06164
v_ordem(08) TYPE c, "Ordem "SIR-
06164
v_linhas TYPE i, "No. Registros em Tab. Interna
v_linhas_tela TYPE i, "No. Linhas do Relatorio na Tel
a
v_data(10) TYPE c, "Data no formato DD.MM.AAA
v_quant_log LIKE anla-menge, "Qtd para o relatrio
v_od_log(12) TYPE c, "Ordem para relatrio
* v_bwasl like tabwt-bwasl, "Tipo de Movimento "SIR-
06164
* V_BWASL_OUTRO LIKE TABWT-BWASL, "Tipo de Movimento "SIR-
06164
v_imobi(17) TYPE c, "Imobilizado
v_odd LIKE aufk-aufnr, "SIR-06164
v_perc LIKE anbz-prozs. "SIR-06164
DATA v_ucomm LIKE syst-ucomm. "SIR-06164
DATA : saldo_new LIKE anep-anbtr, "SIR-06164
saldo_old LIKE anep-anbtr. "SIr-06164
DATA: v_ult_dia_mes TYPE sy-datum. "RicardoRM - 07.06.2011
*- Tabela Interna ----------------------------------------------------
-*

* Tabela interna para os dados de ANLA


DATA: BEGIN OF i_anla OCCURS 0,
* bukrs LIKE anla-bukrs, "Empresa
anlkl LIKE anla-anlkl, "Classe do imobilizado
invnr LIKE anla-invnr, "N inventrio
menge LIKE anla-menge, "Quantidade
meins LIKE anla-meins, "Unidade medida base
aktiv LIKE anla-aktiv, "Data de capitalizao
zugdt LIKE anla-zugdt, "Data de 1a. aquisio
gdlgrp LIKE anla-gdlgrp, "UAR
* ord41 LIKE anla-ord41, "Critrio de classificao 1
* ord42 LIKE anla-ord42, "Critrio de classificao 1
* ord43 LIKE anla-ord43, "Critrio de classificao 1
ord44 LIKE anla-ord44, "SubConta de Bens
eaufn LIKE anla-eaufn, "Ordem de investimento
stort LIKE anlz-stort,
kostl LIKE anlz-kostl, "Centro de Custo
txt50 LIKE anla-txt50, "Descrio do Imob.
kansw LIKE anlc-kansw, "Custos acumulados de aquisio
answl LIKE anlc-answl, "Custo do ano de aquisio 13/01/2000
knafa LIKE anlc-knafa, "Custo acum de depr. 13/01/2000
nafap LIKE anlc-nafap, "Valor de Depreciao 13/01/2000
nafag LIKE anlc-nafag, "Valor de Depreciao 13/01/2000
anln1 LIKE anla-anln1, "N principal do imobilizado
anln2 LIKE anla-anln2, "Subn imobilizado
bdatu LIKE anlz-bdatu, "Dt Validade CC
gsber LIKE anlz-gsber. "Diviso "SIR-
06164
DATA: END OF i_anla.

* Tabela Interna para armazenar somente o imobilizado principal


DATA: BEGIN OF i_anla_princ OCCURS 1000.
INCLUDE STRUCTURE i_anla.
DATA: END OF i_anla_princ.

* Tabela interna para os dados de ANLZ


*dATA: BEGIN OF i_anlz OCCURS 1000,
* anln1 LIKE anlz-anln1, "N principal do imobilizado
* anln2 LIKE anlz-anln2, "Sub Numero
* kostl LIKE anlz-kostl, "Centro de Custo
* stort LIKE anlz-stort. "Localizao do imobilizado
*DATA: END OF i_anlz.

* Cpia da Tabela interna para os dados de ANLZ para seleo de ANLA


*DATA: BEGIN OF i_anlz_tmp OCCURS 1000,
* anln1 LIKE anlz-anln1, "N principal do imobilizado
* anln2 LIKE anlz-anln2, "Sub Numero
* kostl LIKE anlz-kostl, "Centro de Custo
* stort LIKE anlz-stort. "Localizao do imobilizado
*DATA: END OF i_anlz_tmp.

* Tabela de Valores do Imobilizado


*DATA: BEGIN OF i_anlc OCCURS 1000,
* anln1 LIKE anlc-anln1, "N principal do imobilizado
* anln2 LIKE anlc-anln2, "Sub Numero
* kansw LIKE anlc-kansw, "Custos acumulados de aquisi
o
* answl LIKE anlc-answl, "Custo do ano de aquisio 13/01/200
0
* knafa LIKE anlc-knafa, "Custo acum de depr. 13/01/200
0
* nafap LIKE anlc-nafap, "Valor de Depreciao 13/01/2000
* nafag LIKE anlc-nafag. "Valor de Depreciao 13/01/200
0
*DATA: END OF i_anlc.

* Tabela para dados de Batch-Input


DATA: BEGIN OF i_bdcdata OCCURS 1000.
INCLUDE STRUCTURE bdcdata.
DATA: END OF i_bdcdata.

* Mensagens do Call Transaction


DATA: BEGIN OF i_message OCCURS 1000.
INCLUDE STRUCTURE bdcmsgcoll.
DATA: END OF i_message.

* Tabela para relatrio de log.


DATA: BEGIN OF i_log OCCURS 1000,
tipo TYPE c, "Tipo de Msg (Erro ou Sucesso)
trans(4) TYPE c, "Tipo de Inf. ABAV ou AS02
anln1 LIKE anla-anln1, "Imobilizado
anln2 LIKE anla-anln2, "Subnumero
anlkl LIKE anla-anlkl, "Classe
kostl LIKE anlz-kostl, "Centro de Custo
gdlgrp LIKE anla-gdlgrp, "UAR
stort LIKE anlz-stort, "Local
aktiv LIKE anla-aktiv, "Data de Aquis.
menge LIKE anla-menge, "Quantidade
caufn LIKE anlz-caufn, "Ordem interna
txt50 LIKE anla-txt50, "Descrio do Bem
msg(65) TYPE c, "Mensagem
pep(24) TYPE c.
DATA: END OF i_log.

DATA: BEGIN OF i_t087s OCCURS 1000,


gdlgrp LIKE t087s-gdlgrp, "UAR
gdlgrp_txt LIKE t087s-gdlgrp_txt."Texto do critrio de classifi
DATA: END OF i_t087s.

DATA: BEGIN OF i_t499s OCCURS 1000,


stand LIKE t499s-stand, "Localizao do imobilizado
ktext LIKE t499s-ktext. "Texto com o comprimento de 40
DATA: END OF i_t499s.

DATA: BEGIN OF i_cskt OCCURS 1000,


kostl LIKE cskt-kostl, "Centro de custo
ltext LIKE cskt-ltext. "Descrio
DATA: END OF i_cskt.

DATA: BEGIN OF i_aufk OCCURS 1000,


aufnr LIKE aufk-aufnr, "N ordem
ktext LIKE aufk-ktext. "Texto breve
DATA: END OF i_aufk.
* Alterao - Marcos Paixo - 22.10.2014 - Incio
TYPES: BEGIN OF ty_in,
line(1023),
END OF ty_in,

BEGIN OF ty_file,
anln1(12) TYPE c,
bukrs(4) TYPE c,
pep(24) TYPE c,
odd(12) TYPE c,
menge(17) TYPE c,
END OF ty_file,

BEGIN OF ty_anlav,
anln1 TYPE anla-anln1,
anln2 TYPE anla-anln2,
anlkl TYPE anla-anlkl,
aktiv TYPE anla-aktiv,
meins TYPE anla-meins,
menge TYPE anla-menge,
txt50 TYPE anla-txt50,
gdlgrp TYPE anla-gdlgrp,
kostl TYPE anlz-kostl,
stort TYPE anlz-stort,
END OF ty_anlav.

DATA: it_in TYPE TABLE OF ty_in,


it_file TYPE TABLE OF ty_file,
it_anlav TYPE TABLE OF ty_anlav,
wa_in TYPE ty_in,
wa_file TYPE ty_file,
wa_anlav TYPE ty_anlav.

DATA: BEGIN OF c_dir_default,


local TYPE char8 VALUE 'C:\temp\', "#EC NOTEX
T
serv TYPE char1 VALUE '/',
END OF c_dir_default,

BEGIN OF c_screen_name,
local TYPE char6 VALUE 'RB_LOCL',
serv TYPE char6 VALUE 'RB_UNIX',
backg TYPE char8 VALUE 'RB_BACKGD',
onlin TYPE char8 VALUE 'RB_ONLINE' ,
END OF c_screen_name.

DATA: v_sep.
*Alterao - Marcos Paixo - 22.10.2014 - Fim

**********************************************************************
**
* Parmetros de entrada :
*
* Select Options (S_...)
*
* Parameters (P_...)
*
**********************************************************************
**
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE t3. "13/01/200
0
PARAMETER : "13/01/200
0
* p_bldat LIKE anek-bldat OBLIGATORY,
* p_budat LIKE anek-budat OBLIGATORY.
* Alterado por ilson em 10/02/2000 - SIR-
p_bldat LIKE anek-bldat DEFAULT sy-datum OBLIGATORY ,
p_budat LIKE anek-budat DEFAULT sy-datum OBLIGATORY ,
* Alterao - Marcos Paixo - 22.10.2014 - Incio
p_blart LIKE t003-blart DEFAULT 'BX'.
* Alterao - Marcos Paixo - 22.10.2014 - Fim
SELECTION-SCREEN END OF BLOCK b3. "13/01/200
0
*SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE t4. "13/01/20
00
*PARAMETER : "13/01/20
00
*
** ==> Inicio Alterao # APICE CONSULTORIA - RAFAEL BRITO - 11.01.201
1.
**** p_blart LIKE t003-blart DEFAULT 'AA',
** p_blart LIKE t003-blart DEFAULT 'BX',
** <== Fim Alterao # APICE CONSULTORIA - RAFAEL BRITO - 11.01.2011.
*
*
* p_xblnr LIKE anek-xblnr,
** p_sgtxt like anek-sgtxt. "13/01/200
0
* p_sgtxt LIKE anek-sgtxt OBLIGATORY. "13/01/20
00
*SELECTION-SCREEN END OF BLOCK b4. "13/01/20
00
*selection-screen end of block b2. "13/01/2000
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE t1.
PARAMETER: rb_sel RADIOBUTTON GROUP g0 DEFAULT 'X' USER-COMMAND uc0,
p_bukrs LIKE anlz-bukrs DEFAULT 'MT10' OBLIGATORY MATCHCODE OBJECT bu
k.
SELECT-OPTIONS:
s_anlkl FOR anla-anlkl NO-EXTENSION NO INTERVALS,
s_anln1 FOR anla-anln1, "NO-EXTENSION NO INTERVALS,
* s_invnr FOR anla-invnr NO-EXTENSION NO INTERVALS,
s_invnr FOR anla-invnr ,
* s_aktiv for anla-aktiv no-extension no intervals, "13/01/2000
s_aktiv FOR anla-aktiv, "13/01/200
0
* s_gdlgrp for anla-gdlgrp no-extension no intervals,
s_gdlgrp FOR anla-gdlgrp NO INTERVALS,
* s_ord41 FOR anla-ord41 NO-EXTENSION NO INTERVALS,
* s_ord42 FOR anla-ord42 NO-EXTENSION NO INTERVALS,
* s_ord43 FOR anla-ord43 NO-EXTENSION NO INTERVALS,
* s_ord44 for anla-ord44 no-extension no intervals,
s_ord44 FOR anla-ord44 NO INTERVALS,
* s_stort for anlz-stort no-extension no intervals,
s_stort FOR anlz-stort NO INTERVALS,
* s_kostl for anlz-kostl no-extension no intervals,
s_kostl FOR anlz-kostl NO INTERVALS MATCHCODE OBJECT kost,
* s_eaufn for anla-eaufn no-extension no intervals.
s_eaufn FOR anla-eaufn NO INTERVALS MATCHCODE OBJECT ordea.
* Alterao - 15/09/2014 - Marcos Paixo - Incio
SELECTION-SCREEN SKIP 1.
SELECT-OPTIONS:
s_pnr2 FOR anlz-ps_psp_pnr2 NO-EXTENSION NO INTERVALS MATCHCODE
OBJECT prpm," OBLIGATORY,
s_caufn FOR anlz-caufn NO-EXTENSION NO INTERVALS MATCHCODE OBJE
CT ordea." OBLIGATORY.
PARAMETER: p_xblnr LIKE anek-xblnr,
* p_sgtxt like anek-sgtxt. "13/01/2000
p_sgtxt LIKE anek-sgtxt. "13/01/200
0
* Alterao - Marcos Paixo - 22.10.2014 - Incio
SELECTION-SCREEN SKIP 1.
PARAMETER: rb_imp RADIOBUTTON GROUP g0.
SELECTION-SCREEN BEGIN OF BLOCK b6 WITH FRAME TITLE text-004.
"Execuo
PARAMETER: rb_onlin RADIOBUTTON GROUP gp1 DEFAULT 'X' USER-COMMAND uc
1, "On-line
rb_backg RADIOBUTTON GROUP gp1.
"Background
SELECTION-SCREEN END OF BLOCK b6.

SELECTION-SCREEN BEGIN OF BLOCK b7 WITH FRAME TITLE text-005.


"Local de Guarda para Extrao
PARAMETER: rb_locl RADIOBUTTON GROUP gp2 DEFAULT 'X' USER-COMMAND uc2,
"LOCAL
rb_unix RADIOBUTTON GROUP gp2,
"UNIX
p_dir TYPE rlgrap-filename DEFAULT c_dir_default-local.
"Diretrio
SELECTION-SCREEN END OF BLOCK b7.
* Alterao - Marcos Paixo - 22.10.2014 - Fim

* Alterao - 15/09/2014 - Marcos Paixo - Fim


SELECTION-SCREEN END OF BLOCK b1.
* Alterao - 15/09/2014 - Marcos Paixo - Incio
*SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE t2.
*PARAMETER: p_baixa AS CHECKBOX,
* p_menge LIKE anla-menge,
** p_caufn like anlz-caufn. "13/01/2
000
* p_caufn LIKE anlz-caufn MATCHCODE OBJECT ordea. "13/01/20
00
PARAMETER: p_baixa NO-DISPLAY,
p_menge LIKE anla-menge NO-DISPLAY,
p_caufn LIKE anlz-caufn MATCHCODE OBJECT ordea NO-
DISPLAY."13/01/2000
*SELECTION-SCREEN END OF BLOCK b2. "13/01/20
00
* Alterao - 15/09/2014 - Marcos Paixo - Fim

AT SELECTION-SCREEN OUTPUT.

PERFORM f_tratamento_tela.

*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dir.


** Busca de diretrios
* PERFORM f_sel_diretorio.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dir.


* Busca de diretrios para importao
PERFORM f_sel_diretorio_inbound.

* Alterao - Marcos Paixo - 22.10.2014 - Fim


"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>"
" SESSO DE PROCESSAMENTO "
"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>"
*---------------------------------------------------------------------
-*
INITIALIZATION. "Logica para defaults "inteligente
s"
*---------------------------------------------------------------------
-*
* t1 = 'Dados de Seleo' "13/01/2000
* t1 = 'Dados para Baixa Individual'. "13/01/20
00
t1 = 'Dados para Baixa'. "13/01/200
0
* t2 = 'Dados para Baixa em Massa'. "13/01/20
00
t3 = 'Lanamento'. "13/01/200
0
* t4 = 'Dados Adicionais '. "13/01/20
00
*---------------------------------------------------------------------
-*
AT SELECTION-SCREEN. "Tratamento de Erros e lgica para tela de sele
o
*---------------------------------------------------------------------
-*
v_ucomm = sy-ucomm. "SIR-06164
CLEAR sy-ucomm. "SIR-06164
*** IF v_ucomm NE 'ONLI' AND v_ucomm NE ''. "SIR-06164
*** MESSAGE e999 WITH 'Funo invlida'. "SIR-06164
*** ENDIF. "SIR-06164
* Alterao - 15/09/2014 - Marcos Paixo - Incio
CLEAR p_baixa.
* Alterao - 15/09/2014 - Marcos Paixo - Fim
IF p_baixa = 'X'.

IF p_menge EQ 0 OR
p_caufn EQ ''.
MESSAGE e123. "Entrar Valor.
ENDIF.

ENDIF.
*** PERFORM f_select_data. "13/01/200
0
* sir-06164 ----------------------------------------------------------
-*
*** IF p_baixa = 'X'.
*** LOOP AT i_anla WHERE anln2 = '0000'.
*** PERFORM checa-odd USING p_caufn i_anla-gsber.
*** ENDLOOP.
*** ENDIF.

* Inicio Alteracao - RicardoRM - 07.06.2011


LOOP AT SCREEN.
IF screen-name EQ 'P_BLDAT'.
DATA: vl_dia(2) TYPE c.

* Busca ultimo dia do mes.


IF NOT p_bldat IS INITIAL.
CONCATENATE p_bldat(4) p_bldat+4(2) '01' INTO v_ult_dia_mes.
PERFORM zf_ultimo_dia_mes USING v_ult_dia_mes
CHANGING v_ult_dia_mes.
IF v_ult_dia_mes = p_bldat.
MESSAGE s999(zm) DISPLAY LIKE 'W' WITH 'A baixa deve ser rea
lizada com data de'
'lanamento at o penltimo dia do ms'.
vl_dia = p_bldat+6(2) - 1.
p_bldat+6(2) = vl_dia.
ENDIF.
ENDIF.

ENDIF.
ENDLOOP.
* Final Alteracao - RicardoRM - 07.06.2011
* Alterao - 16/09/2014 - Marcos Paixo - Incio
* IF rb_imp NE 'X'.
* IF p_sgtxt IS INITIAL.
* MESSAGE e999(zm) WITH 'Favor preencher o Texto'.
* ENDIF.
*
* IF NOT s_pnr2[] IS INITIAL
* AND NOT s_caufn[] IS INITIAL.
* MESSAGE e999(zm) WITH 'Favor preencher apenas uma opo ou PEP
ou ODD'.
* ELSEIF s_pnr2[] IS INITIAL
* AND s_caufn[] IS INITIAL.
* MESSAGE e999(zm) WITH 'Favor preencher uma opo ou PEP ou ODD'
.
* ENDIF.
* ENDIF.
* Alterao - 16/09/2014 - Marcos Paixo - Fim
*---------------------------------------------------------------------
-*
START-OF-SELECTION. "Processamento principal
*---------------------------------------------------------------------
-*
** Alterao - 16/09/2014 - Marcos Paixo - Incio
IF rb_imp NE 'X'.
IF p_sgtxt IS INITIAL.
MESSAGE e999(zm) WITH 'Favor preencher o Texto'.
ENDIF.

IF NOT s_pnr2[] IS INITIAL


AND NOT s_caufn[] IS INITIAL.
MESSAGE e999(zm) WITH 'Favor preencher apenas uma opo ou PEP o
u ODD'.
ELSEIF s_pnr2[] IS INITIAL
AND s_caufn[] IS INITIAL.
MESSAGE e999(zm) WITH 'Favor preencher uma opo ou PEP ou ODD'.
ENDIF.
ENDIF.
* IF NOT s_pnr2[] IS INITIAL
* AND NOT s_caufn[] IS INITIAL.
* MESSAGE i999(zm) WITH 'Favor preencher apenas uma opo ou PEP ou
ODD'.
* stop.
* ELSEIF s_pnr2[] IS INITIAL
* AND s_caufn[] IS INITIAL.
* MESSAGE i999(zm) WITH 'Favor preencher uma opo ou PEP ou ODD'.
* stop.
* ENDIF.
** Alterao - 16/09/2014 - Marcos Paixo - Fim
* Alterao - Marcos Paixo - 22.10.2014 - Incio
IF rb_imp NE 'X'.
* perform f_select_data. "13/01/2000
PERFORM f_select_data. "13/01/200
0
IF p_baixa = 'X'.
LOOP AT i_anla WHERE anln2 = '0000'.
PERFORM checa-odd USING p_caufn i_anla-gsber.
ENDLOOP.
ENDIF.
PERFORM f_data_process.
ELSE.
PERFORM f_file.
ENDIF.
* Alterao - Marcos Paixo - 22.10.2014 - Fim

*---------------------------------------------------------------------
-*
END-OF-SELECTION. "Fim do processamento principal
*---------------------------------------------------------------------
-*

*---------------------------------------------------------------------
-*
TOP-OF-PAGE. "Cabealho (Aparece sempre no topo da tela.)
*---------------------------------------------------------------------
-*

*---------------------------------------------------------------------
-*
END-OF-PAGE. "Rodap
*---------------------------------------------------------------------
-*

*---------------------------------------------------------------------
-*
AT USER-COMMAND.
*---------------------------------------------------------------------
-*
CASE sy-ucomm.

*---------- Marca Tudo ----------*


WHEN 'SEL_ALL'.
DESCRIBE TABLE i_anla LINES v_linhas.
sy-lilli = 3.

DO v_linhas TIMES.
READ LINE sy-lilli.
sy-lisel(1) = 'X'.
MODIFY LINE sy-lilli.
sy-lilli = sy-lilli + 1.
ENDDO.

*---------- Desmarca Tudo ----------*


WHEN 'SEL_NONE'.
DESCRIBE TABLE i_anla LINES v_linhas.
sy-lilli = 3.

DO v_linhas TIMES.
READ LINE sy-lilli.
sy-lisel(1) = ' '.
MODIFY LINE sy-lilli.
sy-lilli = sy-lilli + 1.
ENDDO.

*---------- Executa transaes ----------*


WHEN 'SEGUE'.
PERFORM f_check_select.
PERFORM f_print_report.
*-------- Muda a Viso do Report --------*
WHEN 'REPORT'.
PERFORM f_report_alternativo.

*--------- Reinicia o Programa ----------*


WHEN 'BACK2'.
LEAVE TO TRANSACTION c_trans.

*----------- Sai do Programa ------------*


WHEN 'CANC'.
LEAVE PROGRAM.

ENDCASE.

"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>"
" SESSO DE FORMS "
"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>"

*&--------------------------------------------------------------------
-*
*& Form F_SELECT_DATA
*&--------------------------------------------------------------------
-*
* Seleciona dados e armazena-os na tabela interna
*
*---------------------------------------------------------------------
-*
FORM f_select_data.
* Nilson - SIR-05497 - Wire
SELECT anlkl invnr menge meins
aktiv zugdt gdlgrp ord44
eaufn stort kostl txt50
kansw answl knafa nafap
nafag anln1 anln2 bdatu
gsber "SIR-06164
FROM v_anlsum_1
INTO TABLE i_anla
BYPASSING BUFFER
WHERE bukrs = p_bukrs
AND anln1 IN s_anln1
AND afabe = c_area_aval
AND gjahr = sy-datum(4) " *
AND anlkl IN s_anlkl
AND bdatu >= sy-datum "SIR-06164 *
AND zugdt NE 0
AND aktiv IN s_aktiv
AND deakt EQ 0
AND ord44 IN s_ord44
AND eaufn IN s_eaufn
AND invnr IN s_invnr
AND gdlgrp IN s_gdlgrp
AND adatu =< sy-datum
AND kostl IN s_kostl
AND stort IN s_stort
AND bdatu = '99991231' .

* SELECT
* anln1
* anln2
* kansw
* answl "13/01/2000
* knafa "13/01/2000
* nafap "13/01/2000
* nafag "13/01/2000
* FROM anlc
* INTO TABLE i_anlc
* FOR ALL ENTRIES IN i_anla
* WHERE bukrs = p_bukrs
* and anln1 = i_anla-anln1
* and gjahr = sy-datum(4)
* and afabe = c_area_aval.

IF i_anla[] IS INITIAL.
MESSAGE i124.
STOP.
ENDIF.

ENDFORM. " F_SELECT_DATA

*&--------------------------------------------------------------------
-*
*& Form F_DATA_PROCESS
*&--------------------------------------------------------------------
-*
* Processa os dados para Efetuar as Baixas
*---------------------------------------------------------------------
-*
FORM f_data_process.
DATA: v_total LIKE anla-menge.

* Ordena dados por data


SORT i_anla BY aktiv anln1 anln2.

* Proces. diferenciado para check-box de baixa em massa selecionado ou


* no
CASE p_baixa.

*------ Baixa Normal (Flag no selecionado) --------------------------


-*
WHEN ''.

PERFORM f_select_descr.
PERFORM f_report_selecao.

*------ Baixa em Massa (Flag Setado) ---------------------------------


-*
WHEN 'X'.

LOOP AT i_anla WHERE anln2 = '0000'.


v_total = v_total + i_anla-menge.
ENDLOOP.

IF v_total >= p_menge.


i_anla_princ[] = i_anla[].
SORT i_anla_princ BY aktiv anln1 anln2.
SORT i_anla BY aktiv anln1 anln2. "SIR-06164
DELETE ADJACENT DUPLICATES FROM i_anla_princ COMPARING anln1.

LOOP AT i_anla_princ.
* Se a quantidade a ser baixada j foi utilizada, sai.
IF p_menge EQ 0. "SIR-06164
EXIT. "SIR-06164
ENDIF. "SIR-06164
v_od_log = p_caufn. "SIR-06164

* Alterao - 15/09/2014 - Marcos Paixo - Incio


* PERFORM as02 USING v_od_log i_anla_princ-menge "SIR-
06164
* i_anla_princ-anln1. "SIR-
06164
IF NOT v_od_log IS INITIAL.
PERFORM as02 USING v_od_log ' '
i_anla_princ-menge "SIR-06164
i_anla_princ-anln1. "SIR-06164
ELSEIF NOT s_pnr2-low IS INITIAL.
PERFORM as02 USING ' ' s_pnr2-low
i_anla_princ-menge "SIR-06164
i_anla_princ-anln1.

ENDIF.
* Alterao - 15/09/2014 - Marcos Paixo - Fim
IF i_anla_princ-menge = 0. "SIR-06164
v_quant = i_anla_princ-menge. "SIR-06164
ELSEIF i_anla_princ-menge <= p_menge. "SIR-06164
v_quant = i_anla_princ-menge. "SIR-06164
ELSE. "SIR-06164
v_quant = p_menge. "SIR-06164
ENDIF. "SIR-06164
v_menge_dep = v_quant. "SIR-06164
IF i_anla_princ-menge = 0. "SIR-06164
v_perc = 100. "SIR-06164
ELSE. "SIR-06164
v_perc = 100 * v_quant / i_anla_princ-menge. "SIR-06164
ENDIF. "SIR-06164
LOOP AT i_anla WHERE anln1 = i_anla_princ-anln1. "SIR-06164
* Limpa quantidade baixada
* clear v_quant_log. "SIR-
06164
* v_od_log = p_caufn. "SIR-
06164
* ------- baixa imobilizado ----------------------------------"SIR-
06164
CALL FUNCTION 'ZSALDO_IMOB'
EXPORTING
p_bukrs = 'MT10'
p_anln1 = i_anla-anln1
p_anln2 = i_anla-anln2
p_afabe = '01'
IMPORTING
p_saldo_new = saldo_new
p_saldo_old = saldo_old
EXCEPTIONS
OTHERS = 1.
* tran
* IF I_ANLA-MENGE = 0.
* V_QUANT = I_ANLA-MENGE.
* ELSEIF I_ANLA-MENGE <= P_MENGE.
* V_QUANT = I_ANLA-MENGE.
* ELSE.
* V_QUANT = P_MENGE.
* ENDIF.
* V_MENGE_DEP = V_QUANT.
* V_PERC = 100 * V_QUANT / I_ANLA-MENGE.
* perform as02 using v_od_log i_anla-menge.
IF saldo_old <> 0.
PERFORM abav USING v_quant v_perc '200'.
ENDIF.
IF saldo_new <> 0.
PERFORM abav USING v_quant v_perc '250'.
ENDIF.
* Desativado -------------------------------------------------"SIr-
06164
* v_quant = i_anla-menge - v_quant. "SIR-
06164
* v_od_log = ' '. "SIR-
06164
** altera dado mestre
* PERFORM F_BDC_DYNPRO USING 'SAPLAIST' '0100'.
* PERFORM F_BDC_FIELD USING: 'ANLA-ANLN1' I_ANLA-ANLN1,
** 'ANLA-ANLN2' i_anla-anln2,
* 'ANLA-ANLN2' '0000',
* 'ANLA-BUKRS' P_BUKRS,
* 'BDC_OKCODE' '/00'.
*
* PERFORM F_BDC_DYNPRO USING 'SAPLAIST' '0140'.
* PERFORM F_BDC_FIELD USING: 'BDC_OKCODE' '/D145'.
*
* PERFORM F_BDC_DYNPRO USING 'SAPLAIST' '0145'.
** perform f_bdc_field using: 'ANLZ-KOSTL' ' ',
* PERFORM F_BDC_FIELD USING: 'ANLZ-CAUFN' P_CAUFN,
* 'BDC_OKCODE' '=BUCH'.
*
* PERFORM F_TRANSACAO USING C_AS02.

* Executa transao de Baixa (somente se trans. anterior foi c/ sucess


o)
* IF I_LOG-TIPO = 'S'.
** if i_anla-aktiv < c_data_lim.
* IF I_ANLA-ZUGDT < C_DATA_LIM.
* V_BWASL = C_200.
* ELSE.
* V_BWASL = C_250.
* ENDIF.
*
* PERFORM F_BDC_DYNPRO USING 'SAPMA01B' '0100'.
* PERFORM F_BDC_FIELD USING: 'ANBZ-ANLN1' I_ANLA-ANLN1,
* 'ANBZ-ANLN2' I_ANLA-ANLN2,
* 'ANBZ-BWASL' V_BWASL,
* 'BDC_OKCODE' '/00'.
*
* PERFORM F_BDC_DYNPRO USING 'SAPMA01B' '0120'.
*
** Se a quantidade for zero, executa baixa total
* CASE I_ANLA-MENGE.
* WHEN 0.
* WRITE P_BUDAT TO V_DATA.
* PERFORM F_BDC_FIELD USING: 'ANBZ-BZDAT' V_DATA,
* 'ANBZ-XVABG' 'X',
* 'ANEK-SGTXT' P_SGTXT,
* 'BDC_OKCODE' '=UPDA'.
* CLEAR V_MENGE_DEP.
*
* WHEN OTHERS.
*
** Se a quantidade for menor ou igual a quantidade entrada (disponvel
)
* IF I_ANLA-MENGE <= P_MENGE.
* WRITE P_BUDAT TO V_DATA.
* WRITE I_ANLA-MENGE TO V_MENGE_C.
* PERFORM F_BDC_FIELD USING: 'ANBZ-BZDAT' V_DATA,
* 'ANBZ-MENGE' V_MENGE_C,
* 'ANEK-SGTXT' P_SGTXT,
* 'ANEK-XBLNR' P_XBLNR,
* 'BDC_OKCODE' '=UPDA'.
*
* V_QUANT_LOG = I_ANLA-MENGE.
* V_MENGE_DEP = I_ANLA-MENGE.
** p_menge = p_menge - i_anla-menge.
*
** Se a quantidade for maior que a quantidade entrada (disponvel)
* ELSE.
* WRITE P_MENGE TO V_MENGE_C.
* WRITE P_BUDAT TO V_DATA.
* PERFORM F_BDC_FIELD USING: 'ANBZ-BZDAT' V_DATA,
* 'ANBZ-MENGE' V_MENGE_C,
* 'ANEK-SGTXT' P_SGTXT,
* 'ANEK-XBLNR' P_XBLNR,
* 'BDC_OKCODE' '=UPDA'.
*
* V_QUANT_LOG = P_MENGE.
* V_MENGE_DEP = P_MENGE.
* ENDIF.
* ENDCASE.
*
* PERFORM F_TRANSACAO USING C_ABAV.

* Altera Dado Mestre

* READ TABLE i_anlz WITH KEY anln1 = i_anla-anln1


* anln2 = i_anla-anln1.
* PERFORM F_BDC_DYNPRO USING 'SAPLAIST' '0100'.
* PERFORM F_BDC_FIELD USING: 'ANLA-ANLN1' I_ANLA-ANLN1,
* 'ANLA-ANLN2' '0000',
* 'ANLA-BUKRS' P_BUKRS,
* 'BDC_OKCODE' '/00'.
*
* PERFORM F_BDC_DYNPRO USING 'SAPLAIST' '0140'.
* PERFORM F_BDC_FIELD USING: 'BDC_OKCODE' '/D145'.
*
* PERFORM F_BDC_DYNPRO USING 'SAPLAIST' '0145'.
** perform f_bdc_field using: 'ANLZ-KOSTL' i_anlz-kostl,
* PERFORM F_BDC_FIELD USING: 'ANLZ-CAUFN' '',
* 'BDC_OKCODE' '=BUCH'.
*
*
* PERFORM F_TRANSACAO USING C_AS02.
* --------------------------------------------------Sir-
06164
* ENDIF.
ENDLOOP.
* Manuteno 001 (23/11/2005) - Denis Misumi (M540283): INICIO
* i_anla_princ-menge = i_anla_princ-menge - v_quant. "SIR-
06164
* Alterao - 15/09/2014 - Marcos Paixo - Incio
* PERFORM as02 USING ' ' i_anla_princ-menge "SIR-
06164
* i_anla_princ-anln1."SIR-
06164
PERFORM as02 USING ' ' ' ' i_anla_princ-menge "SIR-06164
i_anla_princ-anln1.
* Alterao - 15/09/2014 - Marcos Paixo - Fim
* Manuteno 001 (23/11/2005) - Denis Misumi (M540283): FIM

* Decrementa do valor total para baixa o valor da baixa efetuada


p_menge = p_menge - v_menge_dep.

ENDLOOP.

* Imprime Log de Execuo


PERFORM f_print_report.
ELSE.
MESSAGE i033 WITH
'Quantidade entrada' p_menge
'maior do que existente' v_total.
ENDIF.
ENDCASE.

ENDFORM. "F_PRINT_REPORT

*&--------------------------------------------------------------------
-*
*& Form F_PRINT_REPORT
*&--------------------------------------------------------------------
-*
* Imprime o report *
*---------------------------------------------------------------------
-*
FORM f_print_report.

IF NOT s_caufn-low IS INITIAL.

SET PF-STATUS 'STATUS3'.


NEW-PAGE LINE-SIZE 197.
WRITE: /50 'Log de Execuo das Baixas'.

ULINE.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE: /1 '|Imobilizado',
19 '|',
20 'Classe',
28 '|',
29 'ODD',
41 '|',
42 'UAR',
50 '|',
51 'Descrio do Bem',
91 '|',
92 'Local',
102 '|',
103 'Dt. Aquis',
* 112 '|',
* 113 'Quantidade',
* 130 '|',
* 131 'Mensagem',
113 '|',
114 'Quantidade',
131 '|',
132 'Mensagem',
AT sy-linsz '|'.
ULINE.
FORMAT COLOR COL_NORMAL.

SORT i_log BY anln1 anln2.


LOOP AT i_log.

IF i_log-trans NE c_abav
AND i_log-tipo EQ 'S'.
CONTINUE.
ENDIF.

* Monta cdigo do imobilizado com o nmero e o subnumero


CONCATENATE i_log-anln1
'-'
i_log-anln2
INTO v_imobi.

WRITE: /1 '|',
2 v_imobi,
* 14 '-',
* 15 i_log-anln2,
19 '|',
20 i_log-anlkl,
28 '|',
29 i_log-caufn,
41 '|',
42 i_log-gdlgrp,
50 '|',
51 i_log-txt50,
91 '|',
92 i_anla-stort,
102 '|',
103 i_log-aktiv,
113 '|'.

IF i_log-menge NE 0.
WRITE 114 i_log-menge.
ENDIF.
WRITE: 131 '|',
132 i_log-msg,
AT sy-linsz '|'.
ENDLOOP.
ULINE.
ELSE.
SET PF-STATUS 'STATUS3'.
NEW-PAGE LINE-SIZE 197.
WRITE: /50 'Log de Execuo das Baixas'.

ULINE.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE: /1 '|Imobilizado',
19 '|',
20 'Classe',
28 '|',
29 'PEP',
54 '|',
55 'UAR',
63 '|',
64 'Descrio do Bem',
104 '|',
105 'Local',
115 '|',
116 'Dt. Aquis',
126 '|',
127 'Quantidade',
141 '|',
142 'Mensagem',
AT sy-linsz '|'.
ULINE.
FORMAT COLOR COL_NORMAL.

SORT i_log BY anln1 anln2.


LOOP AT i_log.

IF i_log-trans NE c_abav
AND i_log-tipo EQ 'S'.
CONTINUE.
ENDIF.

* Monta cdigo do imobilizado com o nmero e o subnumero


CONCATENATE i_log-anln1
'-'
i_log-anln2
INTO v_imobi.

WRITE: /1 '|',
2 v_imobi,
* 14 '-',
* 15 i_log-anln2,
19 '|',
20 i_log-anlkl,
28 '|',
29 i_log-pep,
54 '|',
55 i_log-gdlgrp,
63 '|',
64 i_log-txt50,
104 '|',
105 i_anla-stort,
115 '|',
116 i_log-aktiv,
126 '|'.

IF i_log-menge NE 0.
WRITE 127 i_log-menge.
ENDIF.
WRITE: 141 '|',
142 i_log-msg,
AT sy-linsz '|'.
ENDLOOP.
ULINE.
ENDIF.
ENDFORM. " F_PRINT_REPORT

*&--------------------------------------------------------------------
-*
*& Form F_REPORT_SELECAO
*&--------------------------------------------------------------------
-*
* Report para Seleo dos Ativos
*
*---------------------------------------------------------------------
-*
FORM f_report_selecao.
DATA: v_pepd TYPE anlz-ps_psp_pnr2.

SET PF-STATUS 'STATUS1'.


FORMAT COLOR COL_HEADING.
WRITE: /2 'Imobilizado',
15 '|',
16 'Classe',
23 '|',
24 'Local',
31 '|',
32 'UAR',
40 '|',
41 'Ord. Inv.',
49 '|',
50 'C. Custo',
58 '|',
59 'No. Invent.',
70 '|',
71 'Quant.',
87 '|',
88 'Un.',
91 '|',
92 'ODD',
104 '|',
* Alterao - 15/09/2014 - Marcos Paixo - Incio
105 'PEP',
130 '|',
131 'Qtde Baixa',
148 '|',
149 'Valor Aquisio',
165 '|',
166 'Depreciao',
182 '|',
183 'Dt. Ativ',
* 105 'Qtde Baixa',
* 122 '|',
* 123 'Valor Aquisio',
* 139 '|',
* 140 'Depreciao',
* 156 '|',
* 157 'Dt. Ativ',
* Alterao - 15/09/2014 - Marcos Paixo - Fim
AT sy-linsz '|'.

ULINE.
FORMAT COLOR COL_NORMAL.

CLEAR v_linhas_tela. "Limpa contador de linhas

* Loop nos itens.


LOOP AT i_anla WHERE anln2 = 0.

v_tabix = sy-tabix.

* READ TABLE i_anlc WITH KEY anln1 = i_anla-anln1


* anln2 = i_anla-anln1.
* v_kansw = v_kansw + i_anlc-kansw. "13/01/2000
v_kansw = v_kansw + i_anla-kansw + i_anla-answl. "13/01/200
0
* v_nafad = v_nafad + i_anlc-nafap. "13/01/2000
* v_nafad = v_nafad + i_anlc-nafap + i_anlc-knafa. "13/01/2000
v_nafad = v_nafad + i_anla-nafag + i_anla-knafa. "13/01/200
0

* Gera somente uma linha para cada imob. independente do no. de subnum
.
* at end of anln1.

* read table i_anla index v_tabix.


* v_menge = v_menge + i_anla-menge.
* READ TABLE i_anlz WITH KEY anln1 = i_anla-anln1
* anln2 = i_anla-anln1.
* i_anla-menge = v_menge.

* Alterao - 15/09/2014 - Marcos Paixo - Incio


CLEAR: v_ordem, v_pepd.
IF NOT s_caufn-low IS INITIAL.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = s_caufn-low
IMPORTING
output = v_ordem.
ENDIF.

v_pepd = s_pnr2-low.

IF v_pepd IS INITIAL.

WRITE: /1 v_check AS CHECKBOX,


2 i_anla-anln1, "Imobilizado
15 '|',
16 i_anla-anlkl, "Classe
23 '|',
24 i_anla-stort, "Localizao
31 '|',
32 i_anla-gdlgrp, "UAR
40 '|',
41 i_anla-eaufn, "Ordem de Inv.
49 '|',
50 i_anla-kostl, "Centro de Custo
58 '|',
59 i_anla-invnr, "No. Inventrio
70 '|',
71 i_anla-menge, "Qtde
87 '|',
88 i_anla-meins, "Unidade
91 '|',
92 v_ordem, "INPUT ON, "No. da Ordem
104 '|',
* Alterao - 15/09/2014 - Marcos Paixo - Incio
105 v_pepd,
130 '|',
131 v_quant INPUT ON, "
148 '|',
149 v_kansw, "
165 '|',
166 v_nafad, "
182 '|',
183 i_anla-aktiv,
* 105 v_quant INPUT ON, "Valor
* 122 '|',
* 123 v_kansw, "i_anlc-kansw,
* 139 '|',
* 140 v_nafad, "i_anlc-nafap,
* 156 '|',
* 157 i_anla-aktiv,
* Alterao - 15/09/2014 - Marcos Paixo - Fim
AT sy-linsz '|'.
ELSEIF v_ordem IS INITIAL.
WRITE: /1 v_check AS CHECKBOX,
2 i_anla-anln1, "Imobilizado
15 '|',
16 i_anla-anlkl, "Classe
23 '|',
24 i_anla-stort, "Localizao
31 '|',
32 i_anla-gdlgrp, "UAR
40 '|',
41 i_anla-eaufn, "Ordem de Inv.
49 '|',
50 i_anla-kostl, "Centro de Custo
58 '|',
59 i_anla-invnr, "No. Inventrio
70 '|',
71 i_anla-menge, "Qtde
87 '|',
88 i_anla-meins, "Unidade
91 '|',
92 v_ordem , "No. da Ordem
104 '|',
* Alterao - 15/09/2014 - Marcos Paixo - Incio
105 v_pepd, "INPUT ON,
130 '|',
131 v_quant INPUT ON, "
148 '|',
149 v_kansw, "
165 '|',
166 v_nafad, "
182 '|',
183 i_anla-aktiv,
* 105 v_quant INPUT ON, "Valor
* 122 '|',
* 123 v_kansw, "i_anlc-kansw,
* 139 '|',
* 140 v_nafad, "i_anlc-nafap,
* 156 '|',
* 157 i_anla-aktiv,
* Alterao - 15/09/2014 - Marcos Paixo - Fim
AT sy-linsz '|'.

ENDIF.
* Alterao - 15/09/2014 - Marcos Paixo - Fim
HIDE: i_anla-anln1,
i_anla-anln1,
i_anla-kostl,
i_anla-menge,
i_anla-gsber. "SIR-06164

CLEAR: v_menge,
v_kansw,
v_nafad.

* Incrementa o contador de linhas do relatrio


v_linhas_tela = v_linhas_tela + 1. "Incrementa no. de linhas

* endat.
ENDLOOP.
ENDFORM. "F_REPORT_SELECAO

*&--------------------------------------------------------------------
-*
*& Form F_REPORT_ALTERNATIVO
*&--------------------------------------------------------------------
-*
* Report com a viso das Descries
*
*---------------------------------------------------------------------
-*
FORM f_report_alternativo.
SET PF-STATUS 'STATUS2'.
FORMAT COLOR COL_HEADING.

WRITE: /2 'Imobilizado',
15 '|',
16 'Descr. UAR',
55 '|',
56 'Descr. da Localizao',
95 '|',
96 'Descr. Centro de Custo',
135 '|',
136 'Descr. ODI',
AT sy-linsz '|'.

ULINE.
FORMAT COLOR COL_NORMAL.

LOOP AT i_anla WHERE anln2 = 0.


v_tabix = sy-tabix.

* AT END OF anln1. "Nilson-28/03/2000


* READ TABLE i_anla INDEX v_tabix.
* READ TABLE i_anlz WITH KEY anln1 = i_anla-anln1
* anln2 = i_anla-anln1.
CLEAR: i_t087s, i_t499s, i_cskt, i_aufk.
READ TABLE i_t087s WITH KEY gdlgrp = i_anla-gdlgrp.
READ TABLE i_t499s WITH KEY stand = i_anla-stort.
READ TABLE i_cskt WITH KEY kostl = i_anla-kostl.
READ TABLE i_aufk WITH KEY aufnr = i_anla-eaufn.

WRITE: /2 i_anla-anln1,
15 '|',
16 i_t087s-gdlgrp_txt,
55 '|',
56 i_t499s-ktext,
95 '|',
96 i_cskt-ltext,
135 '|',
136 i_aufk-ktext,
AT sy-linsz '|'.

* ENDAT. "Nilson-23/03/2000

ENDLOOP.

ENDFORM. "F_REPORT_ALTERNATIVO

*&--------------------------------------------------------------------
-*
*& Form F_CHECK_SELECT
*&--------------------------------------------------------------------
-*
* Processa as linhas selecionadas no relatrio
*
*---------------------------------------------------------------------
-*
FORM f_check_select.
* Alterao - 15/09/2014 - Marcos Paixo - Incio
DATA: BEGIN OF wa_prps,
post1 TYPE prps-post1,
usr03 TYPE prps-usr03,
objnr TYPE prps-objnr,
END OF wa_prps.

DATA: BEGIN OF t_jcds OCCURS 0,


stat TYPE jcds-stat,
udate TYPE jcds-udate,
utime TYPE jcds-utime,
END OF t_jcds.

DATA: v_pepd TYPE prps-pspnr,


v_st_pepd TYPE jcds-stat,
v_txt04 TYPE tj02t-txt04,
v_pep TYPE prps-pspnr,
v_pep1(24) TYPE c.

DATA: v_point TYPE i,


v_line TYPE i,
v_qdtot TYPE anla-menge,
v_bxtot TYPE c.

* Alterao - 15/09/2014 - Marcos Paixo - Fim


* DESCRIBE TABLE i_anla LINES v_linhas.

* sy-lilli = 2.
v_line = 2.
DO v_linhas_tela TIMES.
* sy-lilli = sy-lilli + 1.
ADD 1 TO v_line.
* READ LINE sy-lilli." INDEX sy-lilli.
READ LINE v_line.
* Se no estiver flegado, vai para a prxima linha
IF sy-lisel(1) NE 'X'.
CONTINUE.
ENDIF.

ADD 1 TO v_point.

IF v_point EQ 1.

IF NOT s_pnr2-low IS INITIAL.


* - checa PEPD ------------------------------------------------
CLEAR: v_pepd, v_pep1.

* v_pepd = sy-lisel+104(24). " INTO v_pepd_log.


CALL FUNCTION 'CONVERSION_EXIT_ABPSP_INPUT'
EXPORTING
input = sy-lisel+104(24)
IMPORTING
output = v_pepd
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
v_pep1 = sy-lisel+104(24).
ENDIF.

CLEAR wa_prps.
SELECT SINGLE post1 usr03 objnr FROM prps INTO wa_prps WHERE p
spnr = v_pepd.
** Consistir se o PEP existe
IF sy-subrc <> 0.
MESSAGE e999(zm) WITH 'PEP de desativao no encontrado'.
ENDIF.
** PEP - Tipo de ordem Aneel - ODD
IF wa_prps-usr03 <> 'ODD'.
MESSAGE e999(zm) WITH 'PEP no tem Ordem do tipo ODD'.
ENDIF.
** Verifica o Status do PEP: 'ENTE'.
CLEAR: v_st_pepd, t_jcds[], v_txt04.
SELECT stat udate utime FROM jcds INTO
TABLE t_jcds WHERE objnr = wa_prps-objnr.

IF NOT t_jcds[] IS INITIAL.


SORT t_jcds BY udate utime DESCENDING.
READ TABLE t_jcds INDEX 1.
CLEAR v_txt04.
SELECT SINGLE txt04 FROM tj02t INTO v_txt04 WHERE istat = t_
jcds-stat.
IF sy-subrc <> 0.
MESSAGE e999(zm) WITH 'STATUS do PEP' t_jcds-stat 'no cad
astrado'.
ENDIF.

ELSE.
MESSAGE e999(zm) WITH 'STATUS do PEP de desativao no enco
ntrado'.
ENDIF.

IF v_txt04 <> 'ENTE'.


MESSAGE i999(zm) WITH 'ATENO: STATUS do PEP de desativao
: ' v_txt04.
ENDIF.
ENDIF.

ENDIF.
* Verifica o valor se maior que o valor do item. Se for exibe msg de
* erro e sai.
* Altero - Marcos Paixo - 18/09/2014 - Incio
* v_qtd_ch = sy-lisel+104(17).
v_qtd_ch = sy-lisel+130(17).
* Altero - Marcos Paixo - 18/09/2014 - Fim
v_qtd_ch2 = v_qtd_ch.
REPLACE ',' WITH ' ' INTO v_qtd_ch.
CONDENSE v_qtd_ch NO-GAPS.
IF v_qtd_ch CN '0123456789 '.
MESSAGE e129. "Formato do campo Qtde invlido
ENDIF.
REPLACE ',' WITH '.' INTO v_qtd_ch2.
CONDENSE v_qtd_ch2 NO-GAPS.
v_quant = v_qtd_ch2.

IF i_anla-menge < v_quant.


MESSAGE e130. "Qtde entrada > que a do item
ENDIF.
* Alterao - 15/09/2014 - Marcos Paixo - Incio
CLEAR v_bxtot.
IF i_anla-menge = v_quant.
v_bxtot = 'X'.
ENDIF.
v_qdtot = i_anla-menge.
* v_od_log = sy-lisel+91(12). "SIr-
06164
IF NOT s_caufn-low IS INITIAL.
CONCATENATE '0000' sy-lisel+91(08) INTO v_od_log. "SIr-06164
IF v_od_log = ''.
MESSAGE e138. "ODD deve ser preenchida
ENDIF.

* - checa ODD ------------------------------------------------"SIR-


06164
v_odd = v_od_log.
PERFORM checa-odd USING v_odd i_anla-gsber.
ENDIF.

* IF NOT s_pnr2-low IS INITIAL.


** - checa PEPD ------------------------------------------------
* CLEAR: v_pepd, v_pep1.
*
** v_pepd = sy-lisel+104(24). " INTO v_pepd_log.
* CALL FUNCTION 'CONVERSION_EXIT_ABPSP_INPUT'
* EXPORTING
* input = sy-lisel+104(24)
* IMPORTING
* output = v_pepd
* EXCEPTIONS
* not_found = 1
* OTHERS = 2.
* IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
* ELSE.
* v_pep1 = sy-lisel+104(24).
* ENDIF.
*
* CLEAR wa_prps.
* SELECT SINGLE post1 usr03 objnr FROM prps INTO wa_prps WHERE ps
pnr = v_pepd.
*** Consistir se o PEP existe
* IF sy-subrc <> 0.
* MESSAGE e999(zm) WITH 'PEP de desativao no encontrado'.
* ENDIF.
*** PEP - Tipo de ordem Aneel - ODD
* IF wa_prps-usr03 <> 'ODD'.
* MESSAGE e999(zm) WITH 'PEP no tem Ordem do tipo ODD'.
* ENDIF.
*** Verifica o Status do PEP: 'ENTE'.
* CLEAR: v_st_pepd, t_jcds[], v_txt04.
* SELECT stat udate utime FROM jcds INTO
* TABLE t_jcds WHERE objnr = wa_prps-objnr.
*
* IF NOT t_jcds[] IS INITIAL.
* SORT t_jcds BY udate utime DESCENDING.
* READ TABLE t_jcds INDEX 1.
* CLEAR v_txt04.
* SELECT SINGLE txt04 FROM tj02t INTO v_txt04 WHERE istat = t_j
cds-stat.
* IF sy-subrc <> 0.
* MESSAGE e999(zm) WITH 'STATUS do PEP' t_jcds-stat 'no cada
strado'.
* ENDIF.
*
* ELSE.
* MESSAGE e999(zm) WITH 'STATUS do PEP de desativao no encon
trado'.
* ENDIF.
*
* IF v_txt04 <> 'ENTE'.
* MESSAGE i999(zm) WITH 'ATENO: STATUS do PEP de desativao:
' v_txt04.
* ENDIF.
* ENDIF.
* Alterao - 15/09/2014 - Marcos Paixo - Fim
IF i_anla-menge = 0.
v_perc = 100.
ELSE.
v_perc = 100 * v_quant / i_anla-menge.
ENDIF.

* Manuteno 001 (23/11/2005) - Denis Misumi (M540283): INICIO


IF i_anla-menge NE v_quant.
i_anla-menge = i_anla-menge - v_quant.
ENDIF.
* Manuteno 001 (23/11/2005) - Denis Misumi (M540283): FIM

* - Atualizar Imobilizado ------------------------------------"SIR-


06164
* Alterao - 15/09/2014 - Marcos Paixo - Incio
* PERFORM as02 USING v_od_log i_anla-menge i_anla-anln1.
IF NOT v_od_log IS INITIAL.
PERFORM as02 USING v_od_log ' ' i_anla-menge i_anla-anln1.
* ELSEIF NOT s_pnr2-low IS INITIAL.
* PERFORM as02 USING ' ' ' ' i_anla-menge i_anla-anln1.
ENDIF.
* Alterao - 15/09/2014 - Marcos Paixo - Fim
* Executa as transaes para baixa do ativo para cada subnumero do ati
vo
LOOP AT i_anla WHERE anln1 = i_anla-anln1.

IF i_anla-menge = 0.
v_perc = 100.
ELSE.
v_perc = 100 * v_quant / i_anla-menge.
ENDIF.

CLEAR v_quant_log.
IF v_bxtot = 'X'.
IF v_qdtot <> i_anla-menge.
v_quant = i_anla-menge.
ENDIF.
ENDIF.
* ------- baixa imobilizado ----------------------------------"SIR-
06164
CALL FUNCTION 'ZSALDO_IMOB'
EXPORTING
p_bukrs = 'MT10'
p_anln1 = i_anla-anln1
p_anln2 = i_anla-anln2
p_afabe = '01'
IMPORTING
p_saldo_new = saldo_new
p_saldo_old = saldo_old
EXCEPTIONS
OTHERS = 1.

IF NOT s_caufn-low IS INITIAL.


IF saldo_old <> 0.
CLEAR: v_pepd, v_pep1.
* PERFORM abav USING v_quant v_perc '200'.
* v_od_log
PERFORM bapi_pep USING p_bukrs
p_blart
i_anla-anln1
i_anla-anln2
i_anla-menge
'200'
i_anla-meins
v_quant
v_perc
v_pepd
v_pep1
v_od_log
i_anla-anlkl
i_anla-kostl
i_anla-gdlgrp
i_anla-stort
i_anla-aktiv
i_anla-txt50.
ENDIF.

IF saldo_new <> 0.
CLEAR: v_pepd, v_pep1.
* PERFORM abav USING v_quant v_perc '250'.
PERFORM bapi_pep USING p_bukrs
p_blart
i_anla-anln1
i_anla-anln2
i_anla-menge
'250'
i_anla-meins
v_quant
v_perc
v_pepd
v_pep1
v_od_log
i_anla-anlkl
i_anla-kostl
i_anla-gdlgrp
i_anla-stort
i_anla-aktiv
i_anla-txt50.
ENDIF.

ELSE.

IF saldo_old <> 0.
CLEAR v_od_log.
PERFORM bapi_pep USING p_bukrs
p_blart
i_anla-anln1
i_anla-anln2
i_anla-menge
'200'
i_anla-meins
v_quant
v_perc
v_pepd
v_pep1
v_od_log
i_anla-anlkl
i_anla-kostl
i_anla-gdlgrp
i_anla-stort
i_anla-aktiv
i_anla-txt50.

ENDIF.

IF saldo_new <> 0.
CLEAR v_od_log.
PERFORM bapi_pep USING p_bukrs
p_blart
i_anla-anln1
i_anla-anln2
i_anla-menge
'250'
i_anla-meins
v_quant
v_perc
v_pepd
v_pep1
v_od_log
i_anla-anlkl
i_anla-kostl
i_anla-gdlgrp
i_anla-stort
i_anla-aktiv
i_anla-txt50.

ENDIF.
ENDIF.
* ------- baixa imobilizado ----------------------------------"SIR-
06164
CLEAR v_quant_log.
* READ TABLE i_anlz WITH KEY anln1 = i_anla-anln1
* anln2 = i_anla-anln1.
*
* ------- desativado -----------------------------------------"SIR-
06164
* PERFORM F_BDC_DYNPRO USING 'SAPLAIST' '0100'.
* PERFORM F_BDC_FIELD USING: 'ANLA-ANLN1' I_ANLA-ANLN1,
* 'ANLA-ANLN2' '0000',
* 'ANLA-BUKRS' P_BUKRS,
* 'BDC_OKCODE' '/00'.
*
* PERFORM F_BDC_DYNPRO USING 'SAPLAIST' '0140'.
* PERFORM F_BDC_FIELD USING: 'BDC_OKCODE' '/D145'.
*
* PERFORM F_BDC_DYNPRO USING 'SAPLAIST' '0145'.
** PERFORM f_bdc_field USING: 'ANLZ-KOSTL' i_anlz-kostl,
* PERFORM F_BDC_FIELD USING: 'ANLZ-CAUFN' '',
* 'BDC_OKCODE' '=BUCH'.
*
* PERFORM F_TRANSACAO USING C_AS02.
*
* ENDIF.
* ------- desativado -----------------------------------------"SIR-
06164

ENDLOOP.

* Manuteno 001 (23/11/2005) - Denis Misumi (M540283): INICIO


v_quant = i_anla-menge - v_quant. "SIR-06164
* v_od_log = ' '. "SIR-
06164

* Alterao - 15/09/2014 - Marcos Paixo - Incio


* Limpar a ODD e o PEP no Dado Mestre do Imobilizado.
* v_od_log = 'ORD'.
CLEAR v_pep.
v_pep = s_pnr2-low.
v_od_log = ' '.
v_pep = ' '.
* PERFORM as02 USING v_od_log v_quant i_anla-anln1. "SIR-
06164

PERFORM as02 USING ' ' ' ' v_quant i_anla-anln1. "SIR-06164
* Alterao - 15/09/2014 - Marcos Paixo - Fim
* Manuteno 001 (23/11/2005) - Denis Misumi (M540283): FIM

ENDDO.

ENDFORM. "F_CHECK_SELECT
*&--------------------------------------------------------------------
-*
*& Form F_SELECT_DESCR
*&--------------------------------------------------------------------
-*
* Seleciona os dados para exibio da outra viso do relatrio
*
*---------------------------------------------------------------------
-*
FORM f_select_descr.

* Descrio da UAR
SELECT gdlgrp
gdlgrp_txt FROM t087s
INTO TABLE i_t087s
FOR ALL ENTRIES IN i_anla
WHERE spras = c_pt
AND gdlgrp = i_anla-gdlgrp.

* Descrio da Localizao
SELECT stand
ktext FROM t499s
INTO TABLE i_t499s
FOR ALL ENTRIES IN i_anla
WHERE stand = i_anla-stort.

* Descrio do Centro de Custo


SELECT kostl
ltext FROM cskt
INTO TABLE i_cskt
FOR ALL ENTRIES IN i_anla
WHERE spras = c_pt
AND kokrs = c_cc10
AND kostl = i_anla-kostl.

* Descrio da Ordem de Investimento


SELECT aufnr
ktext FROM aufk
INTO TABLE i_aufk
FOR ALL ENTRIES IN i_anla
WHERE aufnr = i_anla-eaufn.

ENDFORM. "f_select_descr.

*&--------------------------------------------------------------------
-*
*& Form F_TRANSACAO
*&--------------------------------------------------------------------
-*
* Executa o call transaction e armazena erros/sucesso em tab. int.
*
*---------------------------------------------------------------------
-*
FORM f_transacao USING v_trans.
DATA: v_mode.
CLEAR v_mode.
v_mode = c_mode.
REFRESH i_message.

CALL TRANSACTION v_trans USING i_bdcdata


MODE v_mode
UPDATE 'S'
MESSAGES INTO i_message.

* Move dados para a tabela de log


i_log-anln1 = i_anla-anln1.
* i_log-anln2 = i_anla-anln1. "SIR-
06164
i_log-anln2 = i_anla-anln2. "SIR-06164
i_log-anlkl = i_anla-anlkl.
i_log-kostl = i_anla-kostl.
i_log-gdlgrp = i_anla-gdlgrp.
i_log-stort = i_anla-stort.
i_log-aktiv = i_anla-aktiv.
i_log-menge = v_quant_log.
i_log-caufn = v_od_log.
i_log-txt50 = i_anla-txt50.
i_log-trans = v_trans.

* Verifica se ocorreu erro.


READ TABLE i_message WITH KEY msgtyp = 'E'.
IF sy-subrc EQ 0.
i_log-tipo = 'E'.
ELSE.
READ TABLE i_message WITH KEY msgtyp = 'S'.
i_log-tipo = 'S'.
ENDIF.

* Monta Mensagem
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = i_message-msgid
msgnr = i_message-msgnr
msgv1 = i_message-msgv1
msgv2 = i_message-msgv2
msgv3 = i_message-msgv3
msgv4 = i_message-msgv4
IMPORTING
message_text_output = i_log-msg
EXCEPTIONS
OTHERS = 1.

APPEND i_log.
REFRESH i_bdcdata.
ENDFORM. "F_TRANSACAO

*&--------------------------------------------------------------------
-*
*& Form F_BDC_DYNPRO
*&--------------------------------------------------------------------
-*
* Start new screen
*
*---------------------------------------------------------------------
-*
FORM f_bdc_dynpro USING program dynpro.
CLEAR i_bdcdata.
i_bdcdata-program = program.
i_bdcdata-dynpro = dynpro

_bdcdata-dynbegin = 'X'.
APPEND i_bdcdata.
ENDFORM. "F_BDC_DYNPRO

*&--------------------------------------------------------------------
-*
*& Form F_BDC_FIELD
*&--------------------------------------------------------------------
-*
* Insert field
*
*---------------------------------------------------------------------
-*
FORM f_bdc_field USING fnam fval.
CLEAR i_bdcdata.
i_bdcdata-fnam = fnam.
i_bdcdata-fval = fval.
APPEND i_bdcdata.
ENDFORM. "F_BDC_FIELD
*&--------------------------------------------------------------------
-*
*& Form ABUM
*&--------------------------------------------------------------------
-*
* text
*---------------------------------------------------------------------
-*
* -->P_V_PERC text
*
* -->P_SALDO_OLD text
*
*---------------------------------------------------------------------
-*
FORM abav USING p_quant
p_v_perc
value(p_tm).
DATA v_perc_txt(15) TYPE c. "SIR-06164
* Executa transao de Baixa (Somente se a trans. anterior teve sucess
o)
IF i_log-tipo = 'S'.

* IF i_anla-aktiv < c_data_lim. "Nilson-15/08/00-04477


* - Desativado * ---------------------------------------------"SIR-
06164
* IF I_ANLA-ZUGDT < C_DATA_LIM. "Nilson-15/08/00-
04477
* V_BWASL = C_200.
* V_BWASL_OUTRO = C_250. "Nilson-24/08/00
* ELSE.
* V_BWASL = C_250.
* V_BWASL_OUTRO = C_200. "Nilson-24/08/00
* ENDIF.
* - Desativado * ---------------------------------------------"SIR-
06164

PERFORM f_bdc_dynpro USING 'SAPMA01B' '0100'.


PERFORM f_bdc_field USING: 'ANBZ-ANLN1' i_anla-anln1,
'ANBZ-ANLN2' i_anla-anln2,
* 'ANBZ-BWASL' v_bwasl, "SIR-
06164
'ANBZ-BWASL' p_tm, "SIR-06164
'BDC_OKCODE' '/00'.

PERFORM f_bdc_dynpro USING 'SAPMA01B' '0120'.


WRITE p_budat TO v_data.
* Se baixa total
IF i_anla-menge = 0
OR i_anla-menge = p_quant
OR p_quant = 0.

PERFORM f_bdc_field USING: 'ANBZ-BZDAT' v_data,


'ANBZ-XVABG' 'X',
'ANEK-SGTXT' p_sgtxt,
'BDC_OKCODE' '=UPDA'.
v_quant_log = p_quant.

ELSE. "Baixa Parcial


* write v_quant to v_menge_c. "SIR-
06164
*** WRITE p_v_perc TO v_perc_txt. "SIR-
06164
WRITE p_quant TO v_perc_txt.
PERFORM f_bdc_field USING: 'ANBZ-BZDAT' v_data,
* 'ANBZ-MENGE' v_menge_c, "SIR-
06164
*** 'ANBZ-PROZS' v_perc_txt, "SIR-06164
'ANBZ-MENGE' v_perc_txt,
'ANEK-SGTXT' p_sgtxt,
'ANEK-XBLNR' p_xblnr,
'BDC_OKCODE' '=UPDA'.
v_quant_log = p_quant.
* v_quant = v_quant - i_anla-menge.

* CLEAR v_quant.
ENDIF.
PERFORM f_transacao USING c_abav.
CLEAR v_quant_log.
*Nilson-24/08/00-Incio
* Desativado ------------------------------------------------ "SIR-
06164
* READ TABLE I_MESSAGE WITH KEY MSGTYP = 'E'.
* IF SY-SUBRC = 0.
* IF I_LOG-MSG(32) = 'Utilizar outro tipo de movimento'.
** IF i_anla-zugdt < c_data_lim.
** v_bwasl = c_200.
** ELSE.
** v_bwasl = c_250.
** ENDIF.
* PERFORM F_BDC_DYNPRO USING 'SAPMA01B' '0100'.
* PERFORM F_BDC_FIELD USING: 'ANBZ-ANLN1' I_ANLA-ANLN1,
* 'ANBZ-ANLN2' I_ANLA-ANLN2,
* 'ANBZ-BWASL' V_BWASL_OUTRO,
* 'BDC_OKCODE' '/00'.
* PERFORM F_BDC_DYNPRO USING 'SAPMA01B' '0120'.
* WRITE P_BUDAT TO V_DATA.
* IF I_ANLA-MENGE = 0
* OR I_ANLA-MENGE = V_QUANT
* OR V_QUANT = 0.
* PERFORM F_BDC_FIELD USING: 'ANBZ-BZDAT' V_DATA,
* 'ANBZ-XVABG' 'X',
* 'ANEK-SGTXT' P_SGTXT,
* 'BDC_OKCODE' '=UPDA'.
* V_QUANT_LOG = V_QUANT.
* ELSE.
* WRITE V_QUANT TO V_MENGE_C.
* PERFORM F_BDC_FIELD USING: 'ANBZ-BZDAT' V_DATA,
* 'ANBZ-MENGE' V_MENGE_C,
* 'ANEK-SGTXT' P_SGTXT,
* 'ANEK-XBLNR' P_XBLNR,
* 'BDC_OKCODE' '=UPDA'.
* V_QUANT_LOG = V_QUANT.
* ENDIF.
* PERFORM F_TRANSACAO USING C_ABAV.
* ENDIF.
* ENDIF.
** BREAK-POINT.
**Nilson-24/08/00-Incio
ENDIF.
ENDFORM. " ABUM

*&--------------------------------------------------------------------
-*
*& Form AS02
*&--------------------------------------------------------------------
-*
* text
*---------------------------------------------------------------------
-*
* -->P_V_OD_LOG text
*
* -->P_V_PEPD_LOG text
*
* -->P_I_ANLA_MENGE text
*
* -->P_I_ANLA_ANLN1 text
*
*---------------------------------------------------------------------
-*
FORM as02 USING p_v_od_log
p_v_pepd_log
p_i_anla_menge
p_i_anla_anln1.

* Manuteno 001 (23/11/2005) - Denis Misumi (M540283): INICIO


* DATA v_quant(06) TYPE c. "SIR-06164
DATA v_quant(17) TYPE c.
* Manuteno 001 (23/11/2005) - Denis Misumi (M540283): FIM

WRITE p_i_anla_menge TO v_quant. "SIR-06164

PERFORM f_bdc_dynpro USING 'SAPLAIST' '0100'.


PERFORM f_bdc_field USING: 'ANLA-ANLN1' p_i_anla_anln1,
'ANLA-ANLN2' '0000',
'ANLA-BUKRS' p_bukrs,
'BDC_OKCODE' '/00'.

* Manuteno 001 (23/11/2005) - Denis Misumi (M540283): INICIO


* PERFORM F_BDC_DYNPRO USING 'SAPLAIST' '0140'.
* PERFORM F_BDC_FIELD USING: 'ANLA-MENGE' V_QUANT, "SIR-
06164
* 'BDC_OKCODE' '/D145'.
*
* PERFORM f_bdc_dynpro USING 'SAPLAIST' '0145'.
** PERFORM f_bdc_field USING: 'ANLZ-KOSTL' ' ',
** perform f_bdc_field using: 'ANLZ-CAUFN' sy-lisel+91(12),"SIR-
06164
* PERFORM f_bdc_field USING: 'ANLZ-CAUFN' p_v_od_log, "SIR-
06164
* 'BDC_OKCODE' '=BUCH'.
DATA: w_data(10) TYPE c,
w_anln1 TYPE anlz-anln1.

CONCATENATE sy-datum+6(2)
sy-datum+4(2)
sy-datum(4)
INTO w_data.

PERFORM f_bdc_dynpro USING 'SAPLAIST' '1000'.


PERFORM f_bdc_field USING: 'BDC_OKCODE' '=TAB02'.

* IF p_v_od_log NE 'ORD'.
* PERFORM f_bdc_field USING: 'ANLA-MENGE' v_quant.
* ELSE.
* CLEAR: p_v_od_log.
* ENDIF.

PERFORM f_bdc_dynpro USING 'SAPLAIST' '1000'.


PERFORM f_bdc_field USING: 'ANLZ-CAUFN' p_v_od_log. "SIR-06164

* Alterao - 15/09/2014 - Marcos Paixo - Incio


* PERFORM f_bdc_field USING: 'ANLZ-PS_PSP_PNR2' p_v_pepd_log,
PERFORM f_bdc_field USING: 'BDC_OKCODE' '=BUCH'.
* Alterao - 15/09/2014 - Marcos Paixo - Fim

* Verifica se j foi processado no dia


*** SELECT SINGLE anln1
*** INTO w_anln1
*** FROM anlz
*** WHERE adatu EQ sy-datum.
*** IF NOT sy-subrc IS INITIAL.
*** PERFORM f_bdc_dynpro USING 'SAPLAIST' '3020'.
*** PERFORM f_bdc_field USING: 'BDC_OKCODE' '=INEW'.
***
*** PERFORM f_bdc_dynpro USING 'SAPLAIST' '3010'.
*** PERFORM f_bdc_field USING: 'BDC_OKCODE' '=ENTE',
*** 'ANLZ-ADATU' w_data.
***
*** PERFORM f_bdc_dynpro USING 'SAPLAIST' '3000'.
*** PERFORM f_bdc_field USING: 'BDC_OKCODE' '=BUCH'.
*** ELSE.
PERFORM f_bdc_dynpro USING 'SAPLAIST' '3020'.
PERFORM f_bdc_field USING: 'BDC_OKCODE' '=YES'.
*** ENDIF.
* Manuteno 001 (23/11/2005) - Denis Misumi (M540283): FIM

PERFORM f_transacao USING c_as02.


CLEAR v_quant_log.
ENDFORM. " AS02
*&--------------------------------------------------------------------
-*
*& Form CHECA-ODD
*&--------------------------------------------------------------------
-*
* text
*---------------------------------------------------------------------
-*
* -->P_V_ODD text
*
* -->P_I_ANLA_GSBER text
*
*---------------------------------------------------------------------
-*
FORM checa-odd USING p_v_odd
p_i_anla_gsber.
SELECT SINGLE * FROM aufk WHERE aufnr = p_v_odd.
IF sy-subrc NE 0.
MESSAGE e000(zm) WITH 'Ordem ' p_v_odd 'no encontrada'.
ENDIF.
IF aufk-auart(03) <> 'ODD' AND aufk-auart(03) <> 'ODA'.
MESSAGE e000(zm) WITH 'Ordem deve ser ODD ou ODA'.
ENDIF.
IF aufk-phas1 <> 'X'.
MESSAGE e000(zm) WITH 'Ordem' p_v_odd 'no est liberada'.
ENDIF.
* Incio Alterao Daniel B. 18/07/2007 HP 3063

* IF aufk-gsber <> p_i_anla_gsber.


* MESSAGE e000(zm) WITH 'Diviso do imobilizado ' p_i_anla_gsber
* 'e diviso da ordem ' aufk-gsber.
* ENDIF.
* Fim Alterao Daniel B. 18/07/2007 HP 3063

ENDFORM. " CHECA-ODD

*---------------------------------------------------------------------
-*
* Form ZF_ULTIMO_DIA_MES
*
*---------------------------------------------------------------------
-*
* Busca ultimo dia do mes
*---------------------------------------------------------------------
-*
FORM zf_ultimo_dia_mes USING p_data TYPE sy-datum
CHANGING s_data TYPE sy-datum.

CHECK NOT p_data IS INITIAL.

v_ult_dia_mes = p_data.
v_ult_dia_mes+6(2) = 01.

CALL FUNCTION 'LAST_DAY_OF_MONTHS'


EXPORTING
day_in = v_ult_dia_mes
IMPORTING
last_day_of_month = s_data.

ENDFORM. " ZF_ULTIMO_DIA_MES


*&--------------------------------------------------------------------
-*
*& Form BAPI_PEP
*&--------------------------------------------------------------------
-*
* text
*---------------------------------------------------------------------
-*
* -->P_ANLN1 text
* -->P_ANLN2 text
* -->P_assettrtyp text
* -->P_MEINS text
* -->P_QUANT text
* -->P_PEPD text
* -->P_PEP1 text
*---------------------------------------------------------------------
-*
FORM bapi_pep USING p_bukrs
p_blart
p_anln1
p_anln2
p_menge
p_assettrtyp
p_meins
p_quant
p_perc
p_pepd
p_pep1
p_odd
p_anlkl
p_kostl
p_gdlgrp
p_stort
p_aktiv
p_txt50.

DATA: ls_generalpostingdata LIKE bapifapo_gen_info,


ls_retirementdata LIKE bapifapo_ret,
ls_accountassignments LIKE bapifapo_acc_ass,
ls_furtherpostingdata LIKE bapifapo_add_info,
ld_documentreference LIKE bapifapo_doc_ref,
ls_return LIKE bapiret2.

CLEAR: ls_generalpostingdata,
ls_retirementdata,
ls_accountassignments,
ls_furtherpostingdata,
ld_documentreference,
ls_return.

ls_generalpostingdata-username = sy-uname.
ls_generalpostingdata-doc_type = p_blart.
ls_generalpostingdata-doc_date = sy-datlo.
ls_generalpostingdata-pstng_date = sy-datlo.
ls_generalpostingdata-fis_period = sy-datlo+4(2).
ls_generalpostingdata-comp_code = p_bukrs.
ls_generalpostingdata-assetmaino = p_anln1.
ls_generalpostingdata-assetsubno = p_anln2.
ls_generalpostingdata-assettrtyp = p_assettrtyp.

ls_retirementdata-base_uom = p_meins.
ls_retirementdata-valuedate = sy-datlo.

IF p_quant EQ p_menge.
ls_retirementdata-compl_ret = 'X'.
ELSE.
ls_retirementdata-perc_rate = p_perc.
ENDIF.
ls_retirementdata-quantity = p_quant.

ls_furtherpostingdata-ref_doc_no = p_xblnr.
ls_furtherpostingdata-item_text = p_sgtxt.

IF p_odd IS INITIAL.
ls_accountassignments-wbs_elem = p_pepd.
ls_accountassignments-wbs_element = p_pep1.
ls_accountassignments-wbs_elem_cost = p_pepd.
ELSE.
ls_accountassignments-orderid = p_odd.
ENDIF.

CLEAR: ls_return.

CALL FUNCTION 'BAPI_ASSET_RETIREMENT_POST'


EXPORTING
generalpostingdata = ls_generalpostingdata
retirementdata = ls_retirementdata
accountassignments = ls_accountassignments
furtherpostingdata = ls_furtherpostingdata
IMPORTING
documentreference = ld_documentreference
return = ls_return.

IF NOT ls_return-type EQ 'E'.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'


EXPORTING
wait = 'X'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.

i_log-anln1 = p_anln1.
i_log-anln2 = p_anln2.
i_log-anlkl = p_anlkl.
i_log-kostl = p_kostl.
i_log-gdlgrp = p_gdlgrp.
i_log-stort = p_stort.
i_log-aktiv = p_aktiv.
i_log-menge = p_quant.
i_log-pep = p_pep1.
i_log-txt50 = p_txt50.
i_log-trans = 'ABAV'.
i_log-msg = ls_return-message.

APPEND i_log.

ENDFORM. " BAPI_PEP


* Alterao - Marcos Paixo - 22.10.2014 - Incio
*&--------------------------------------------------------------------
-*
*& Form F_TRATAMENTO_TELA
*&--------------------------------------------------------------------
-*
* text
*---------------------------------------------------------------------
-*
* --> p1 text
* <-- p2 text
*---------------------------------------------------------------------
-*
FORM f_tratamento_tela .

IF NOT rb_sel IS INITIAL.


LOOP AT SCREEN.
IF screen-name = 'RB_BACKG'
OR screen-name = 'RB_LOCL'
OR screen-name = 'RB_ONLIN'
OR screen-name = 'RB_UNIX'
OR screen-name = 'P_DIR'.
screen-input = 0.
* ELSE.
* screen-input = 1.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ELSE.
LOOP AT SCREEN.
IF screen-name = 'RB_BACKG'
OR screen-name = 'RB_LOCL'
OR screen-name = 'RB_ONLIN'
OR screen-name = 'RB_SEL'
OR screen-name = 'RB_IMP'
OR screen-name = 'RB_UNIX'
OR screen-name = 'P_DIR'.
screen-input = 1.
ELSE.
screen-input = 0.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ENDIF.
*> Tratamento de tela para processamento background
IF NOT rb_backg IS INITIAL.

rb_locl = space.
rb_unix = abap_true.

LOOP AT SCREEN.

IF screen-name = c_screen_name-local OR
screen-name = c_screen_name-serv.

screen-input = 0.

ENDIF.

MODIFY SCREEN.
ENDLOOP.

ENDIF.

IF rb_locl IS NOT INITIAL AND p_dir EQ c_dir_default-serv.

p_dir = c_dir_default-local.

ELSEIF rb_unix IS NOT INITIAL AND p_dir = c_dir_default-local.

p_dir = c_dir_default-serv.

ENDIF.

ENDFORM. " F_TRATAMENTO_TELA

*&--------------------------------------------------------------------
-*
*& Form F_SEL_DIRETORIO_INBOUND
*&--------------------------------------------------------------------
-*
* text
*---------------------------------------------------------------------
-*
* --> p1 text
* <-- p2 text
*---------------------------------------------------------------------
-*
FORM f_sel_diretorio_inbound.

DATA: l_path_str TYPE string,


l_win_tit TYPE string, "#EC *
l_rc TYPE i.

DATA: tl_saida TYPE STANDARD TABLE OF file_table.

DATA: wl_saida TYPE file_table.

l_win_tit = text-055.

IF rb_locl IS NOT INITIAL.

*> Lista de Diretrios Local


CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = l_win_tit
CHANGING
file_table = tl_saida
rc = l_rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.

IF sy-subrc IS INITIAL.

READ TABLE tl_saida INTO wl_saida INDEX 1.

p_dir = wl_saida-filename.

ENDIF.

ELSE.

*> Lista de Diretrios Servidor


CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
directory = space
filemask = space
IMPORTING
serverfile = l_path_str
EXCEPTIONS
canceled_by_user = 1
OTHERS = 2.
IF sy-subrc IS INITIAL.

p_dir = l_path_str.

ELSE.

MESSAGE ID sy-msgid
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDIF.
ENDFORM. " F_SEL_DIRETORIO_INBOUND
*&--------------------------------------------------------------------
-*
*& Form F_FILE
*&--------------------------------------------------------------------
-*
* text
*---------------------------------------------------------------------
-*
* --> p1 text
* <-- p2 text
*---------------------------------------------------------------------
-*
FORM f_file .

PERFORM f_import_file.
PERFORM f_selec.
PERFORM f_process.
PERFORM f_print_report.

ENDFORM. " F_FILE


*&--------------------------------------------------------------------
-*
*& Form F_IMPORT_FILE
*&--------------------------------------------------------------------
-*
* text
*---------------------------------------------------------------------
-*
* --> p1 text
* <-- p2 text
*---------------------------------------------------------------------
-*
FORM f_import_file .

DATA: vl_dir TYPE string.


MOVE: ';' TO v_sep.

CLEAR: it_in[], it_file[].

IF rb_locl EQ 'X'.
CLEAR vl_dir.
vl_dir = p_dir.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = vl_dir
filetype = 'ASC'
TABLES
data_tab = it_in[]
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
IF NOT it_in[] IS INITIAL.
LOOP AT it_in INTO wa_in.
PERFORM f_split_file USING wa_in.
ENDLOOP.
ENDIF.
ENDIF.

ELSE.

OPEN DATASET p_dir IN TEXT MODE ENCODING DEFAULT FOR INPUT.


IF sy-subrc EQ 0.
DO.
READ DATASET p_dir INTO wa_in.
IF sy-subrc <> 0.
EXIT.
ELSE.
PERFORM f_split_file USING wa_in.
ENDIF.

ENDDO.

CLOSE DATASET p_dir.

ENDIF.

ENDIF.

IF NOT it_file[] IS INITIAL.


SORT it_file.
ELSE.
MESSAGE e999(zm) WITH 'Nenhum item importado'.
ENDIF.
ENDFORM. " F_IMPORT_FILE
*&--------------------------------------------------------------------
-*
*& Form F_SPLIT_FILE
*&--------------------------------------------------------------------
-*
* text
*---------------------------------------------------------------------
-*
* --> p1 text
* <-- p2 text
*---------------------------------------------------------------------
-*
FORM f_split_file USING p_in.
CLEAR: wa_file.

SPLIT p_in AT v_sep INTO wa_file-bukrs


wa_file-pep
wa_file-odd
wa_file-anln1
wa_file-menge.

APPEND wa_file TO it_file.


CLEAR wa_file.

ENDFORM. " F_SPLIT_FILE


*&--------------------------------------------------------------------
-*
*& Form F_SELEC
*&--------------------------------------------------------------------
-*
* text
*---------------------------------------------------------------------
-*
* --> p1 text
* <-- p2 text
*---------------------------------------------------------------------
-*
FORM f_selec .

CLEAR it_anlav[].

SELECT anln1 anln2 anlkl aktiv meins


menge txt50 gdlgrp kostl stort
FROM v_anlsum_1
INTO TABLE it_anlav
BYPASSING BUFFER
FOR ALL ENTRIES IN it_file
WHERE bukrs = it_file-bukrs
AND anln1 = it_file-anln1
* AND anln2 = '0000'
AND afabe = c_area_aval
AND gjahr = sy-datum(4)
AND bdatu >= sy-datum
AND zugdt <> 0
AND deakt = 0
AND adatu =< sy-datum
AND bdatu = '99991231' .

IF NOT it_anlav[] IS INITIAL.


SORT it_anlav.
ELSE.
MESSAGE e999(zm) WITH 'Nenhum Ativo selecionado'.
ENDIF.
ENDFORM. " F_SELEC
*&--------------------------------------------------------------------
-*
*& Form F_PROCESS
*&--------------------------------------------------------------------
-*
* text
*---------------------------------------------------------------------
-*
* --> p1 text
* <-- p2 text
*---------------------------------------------------------------------
-*
FORM f_process .

DATA: v_menge TYPE anla-menge,


v_anln1 TYPE anla-anln1,
v_pepd TYPE prps-pspnr,
v_pep TYPE prps-pspnr,
v_perc TYPE anbz-prozs,
v_od(12) TYPE c,
v_asstyp(3) TYPE c,
v_pep1(24) TYPE c.

LOOP AT it_file INTO wa_file.

CLEAR: v_pepd, v_pep, v_pep1, v_menge, v_asstyp, v_perc, saldo_new


,
saldo_old, v_od .

* READ TABLE it_anlav INTO wa_anlav WITH KEY anln1 = wa_file-anln1


* BINARY SEARCH.
* IF sy-subrc EQ 0.

LOOP AT it_anlav INTO wa_anlav WHERE anln1 = wa_file-anln1.

IF v_anln1 EQ wa_file-anln1.
CLEAR wa_anlav-menge.
SELECT SINGLE menge FROM anla INTO wa_anlav-menge
BYPASSING BUFFER
WHERE anln1 = wa_file-anln1
AND anln2 = wa_anlav-anln2.
ENDIF.
TRANSLATE wa_file-menge USING ',.'.
v_menge = wa_file-menge.
IF wa_anlav-menge = 0.
v_perc = 100.
ELSE.
v_perc = 100 * v_menge / wa_anlav-menge.
ENDIF.

IF wa_file-odd NE space.

v_od = wa_file-odd.
* IF wa_anlav-anln2 EQ '0000'.
PERFORM as02 USING v_od ' ' wa_anlav-menge wa_anlav-anln1.
* ENDIF.

CLEAR: v_pepd, v_pep, v_pep1.


p_sgtxt = wa_file-odd.

ELSEIF wa_file-pep NE space.

CLEAR v_od.
p_sgtxt = wa_file-pep.
v_pep1 = wa_file-pep.

CALL FUNCTION 'CONVERSION_EXIT_ABPSP_INPUT'


EXPORTING
input = v_pep1
IMPORTING
output = v_pepd
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc NE 0.
CONTINUE.
ENDIF.
ELSE.
CONTINUE.
ENDIF.
* ------- baixa imobilizado ----------------------------------"SIR-
06164
CALL FUNCTION 'ZSALDO_IMOB'
EXPORTING
p_bukrs = 'MT10'
p_anln1 = wa_anlav-anln1
p_anln2 = wa_anlav-anln2
p_afabe = '01'
IMPORTING
p_saldo_new = saldo_new
p_saldo_old = saldo_old
EXCEPTIONS
OTHERS = 1.

IF saldo_old <> 0.
v_asstyp = '200'.
ENDIF.

IF saldo_new <> 0.
v_asstyp = '250'.
ENDIF.

PERFORM bapi_pep USING wa_file-bukrs


p_blart
wa_anlav-anln1
wa_anlav-anln2
wa_anlav-menge
v_asstyp
wa_anlav-meins
v_menge
v_perc
v_pepd
v_pep1
v_od
wa_anlav-anlkl
wa_anlav-kostl
wa_anlav-gdlgrp
wa_anlav-stort
wa_anlav-aktiv
wa_anlav-txt50.

v_menge = wa_anlav-menge - v_menge.


PERFORM as02 USING ' ' ' ' v_menge wa_anlav-anln1.
v_anln1 = wa_file-anln1.
* ENDIF.
ENDLOOP.

ENDLOOP.

ENDFORM. " F_PROCESS