You are on page 1of 33

*----------------------------------------------------------------------* * Report ..... ZSAFE147 * Author: .....

MasterSAF *----------------------------------------------------------------------* * Programa extrator dos demais documentos e operaes geradoras de * crdito *----------------------------------------------------------------------* * version author date log * initial version <details> *v0704 *----------------------------------------------------------------------* report zsafe147 message-id zmastersaf . *----------------------------------------------------------------------* * TABLES *----------------------------------------------------------------------* tables: zsafa , zsafb , zsaf2 , zsaf11 , t001w , kna1 , knb1 , lfa1 , lfb1 . *----------------------------------------------------------------------* * Standard types *----------------------------------------------------------------------* type-pools: abap . *----------------------------------------------------------------------* * INCLUDES *----------------------------------------------------------------------* include zsafhex . include zsaft147 . include zsafx147 . include zsafi000 . include zsafi001 . include zsafz147 . *----------------------------------------------------------------------* * TYPES *----------------------------------------------------------------------* types: begin of ty_t001 , bukrs type bukrs , waers type waers , end of ty_t001 . types: begin of ty_1bbranch , bukrs type bukrs , branch type j_1bbranc_ , end of ty_1bbranch . types:

begin of ty_bseg , bukrs type bseg-bukrs belnr type bseg-belnr gjahr type bseg-gjahr buzei type bseg-buzei matnr type bseg-matnr dmbtr type bseg-dmbtr hkont type bseg-hkont shkzg type bseg-shkzg kokrs type bseg-kokrs kostl type bseg-kostl kunnr type bseg-kunnr lifnr type bseg-lifnr gsber type bseg-gsber werks type bseg-werks sgtxt type bseg-sgtxt end of ty_bseg .

, , , , , , , , , , , , , , ,

types: begin of ty_bkpf , bukrs type bkpf-bukrs , belnr type bkpf-belnr , gjahr type bkpf-gjahr , blart type bkpf-blart , * Inicio - Carlos Renato Barcelos de Oliveira (25/01/2012) ** Inicio - Carlos Renato Barcelos de Oliveira (18/01/2012) * CPUDT TYPE BKPF-CPUDT , ** Fim - Carlos Renato Barcelos de Oliveira (18/01/2012) budat type bkpf-budat , * Inicio - Carlos Renato Barcelos de Oliveira (25/01/2012) stblg type bkpf-stblg , stgrd type bkpf-stgrd , end of ty_bkpf . types: begin of ty_1bnfdoc , " documentos fiscais cabealho docnum type j_1bdocnum , nftype type j_1bnftype , doctyp type j_1bdoctyp , direct type j_1bdirect , docdat type j_1bdocdat , pstdat type j_1bpstdat , credat type j_1bcredat , chadat type j_1bchadat , form type j_1bform , model type j_1bmodel , series type j_1bseries , subser type j_1bsubser , nfnum type j_1bnfnumb , belnr type belnr_d , gjahr type gjahr , bukrs type bukrs , branch type j_1bbranc_ , parvw type j_1bparvw , parid type j_1bparid , partyp type j_1bpartyp , cancel type j_1bcancel , docref type j_1bdocref , nfe type j_1bnfe , nfenum type j_1bnfnum9 , docstat type j_1bnfedocstatus ,

code type j_1bstatuscode , end of ty_1bnfdoc . types: begin of ty_1bnflin , docnum like j_1bnflin-docnum , itmnum like j_1bnflin-itmnum , matnr like j_1bnflin-matnr , bwkey like j_1bnflin-bwkey , maktx like j_1bnflin-maktx , netpr like j_1bnflin-netpr , incltx like j_1bnflin-incltx , cfop like j_1bnflin-cfop , * Inicio - Carlos Renato Barcelos de Oliveira (03/01/2012) taxsi4 like j_1bnflin-taxsi4 , * Fim - Carlos Renato Barcelos de Oliveira (03/01/2012) end of ty_1bnflin . types: begin of ty_1bnfstx , " docnum type j_1bnfstx-docnum itmnum type j_1bnfstx-itmnum taxtyp type j_1bnfstx-taxtyp base type j_1bnfstx-base , rate type j_1bnfstx-rate , taxval type j_1bnfstx-taxval end of ty_1bnfstx . impostos por item , , , ,

types begin of ty_saftb1 . include structure zsaf1 . types end of ty_saftb1 . types begin of ty_saftb5 . include structure zsaf5 . types end of ty_saftb5 . types begin of ty_saftbd . include structure zsafd . types end of ty_saftbd . types begin of ty_saftb03 . include structure zsaf3 . types end of ty_saftb03 . types begin of ty_saftb04 . include structure zsaf4 . types end of ty_saftb04 . types begin of ty_saftb05 . include structure zsaf5 . types end of ty_saftb05 . types begin of ty_saftb39 . include structure zsaf39 . types end of ty_saftb39 . *Inicio types: begin ryear docnr - Michel Moura (03/05/2013) of ty_flexa, like faglflexa-ryear, like faglflexa-docnr,

rbukrs like faglflexa-rbukrs, end of ty_flexa. *Fim - Michel Moura (03/05/2013) data : gv_netpr like j_1bnfstx-base , gv_rate_pis(8) type p decimals 4, *like j_1bnfstx-rate , gv_rate_cof(8) type p decimals 4, *like j_1bnfstx-rate , gv_base_pis like j_1bnfstx-base , * Inicio - Carlos Renato Barcelos de Oliveira (01/02/2012) * Inicio - Carlos Renato Barcelos de Oliveira (05/03/2012) gv_val_pis like j_1bnfstx-taxval , * GV_VAL_PIS(15) TYPE P DECIMALS 4 , * Fim - Carlos Renato Barcelos de Oliveira (05/03/2012) * Fim - Carlos Renato Barcelos de Oliveira (01/02/2012) gv_base_cof like j_1bnfstx-base , * Inicio - Carlos Renato Barcelos de Oliveira (01/02/2012) * Inicio - Carlos Renato Barcelos de Oliveira (05/03/2012) gv_val_cof like j_1bnfstx-taxval . * GV_VAL_COF(15) TYPE P DECIMALS 4 . * Fim - Carlos Renato Barcelos de Oliveira (05/03/2012) * Fim - Carlos Renato Barcelos de Oliveira (01/02/2012) *----------------------------------------------------------------------* * Standard tables *----------------------------------------------------------------------* data: gt_zsaf1 type table of ty_saftb1 , gt_t001 type table of ty_t001 , gt_1bbranch type table of ty_1bbranch , gt_1bnfdoc type table of ty_1bnfdoc , gt_1bnflin type table of ty_1bnflin , gt_1bnfstx type table of ty_1bnfstx , gt_bseg type table of ty_bseg , gt_bseg2 type table of ty_bseg , * Inicio - Carlos Renato Barcelos de Oliveira (03/01/2012) gt_bseg_aux type table of ty_bseg , * Fim - Carlos Renato Barcelos de Oliveira (03/01/2012) gt_bkpf type table of ty_bkpf , gt_saftbd type table of ty_saftbd , gt_saftb03 type table of ty_saftb03 , gt_saftb04 type table of ty_saftb04 , gt_saftb05 type table of ty_saftb05 , gt_saftb39 type table of ty_saftb39 , *Inicio - Ana Paula Rosa Pereira (23.05.2011) gt_zfint_piscofins type table of zfint_piscofins, *Fim - Ana Paula Rosa Pereira (23.05.2011) gt_flexa type table of ty_flexa, " Add - Michel Moura (03/05/2013) gs_flexa like line of gt_flexa. " Add - Michel Moura (03/05/2013) data gs_zsaf1 like line of gt_zsaf1 .

data: begin of h_arqs, arquivo(12) type c, total type i, end of h_arqs. data: begin of h_zsafa occurs 0 ,

bukrs like zsafa-bukrs, branch like zsafa-branch, mascara like zsafa-mascara, end of h_zsafa. data: begin of t_zsafa occurs 0 , bukrs like zsafa-bukrs, branch like zsafa-branch, mascara like zsafa-mascara, end of t_zsafa. data: begin of h_zsafb occurs 0, bukrs like zsafa-bukrs, mascara like zsafb-mascara, end of h_zsafb. data: begin of t_zsafb occurs 0, bukrs like zsafa-bukrs, mascara like zsafb-mascara, end of t_zsafb. data: begin of chv , chv1(4) type c , chv2(4) type c , end of chv . *----------------------------------------------------------------------* * global variables *----------------------------------------------------------------------* data: gv_mascara(4) type c , gv_arquivo(128) type c , gv_cont type i , gv_ini(2) type n , gv_tam(2) type n , gv_nomearq(12) type c , gv_filial(4) type c . ranges: gr_bukrs gr_branc gr_pstda gr_hkont gr_lifnr gr_nftype gr_blart gr_cfop for for for for for for for for t001-bukrs , j_1bbranch-branch , j_1bnfdoc-pstdat , bseg-hkont , bseg-lifnr , j_1bnfdoc-nftype , bkpf-blart , j_1bnflin-cfop .

data: gt_zsaft147_aux like gt_zsaft147 with header line, gs_zsaft147_aux like gs_zsaft147. *----------------------------------------------------------------------* * Parmetros adicionais *----------------------------------------------------------------------* selection-screen skip . selection-screen begin of block a1 with frame title text-t01 . selection-screen end of block a1 . *&---------------------------------------------------------------------*

** *& START-OF-SELECTION *&---------------------------------------------------------------------* start-of-selection . *----------------------------------------------------------------------* * Principal *----------------------------------------------------------------------* *&===================================================================== *& ATENO: Utilizar SOMENTE para customizaes do cliente, em *& SUBSTITUIO rotina padro disponibilizada pela Mastersaf *&===================================================================== perform f_exec_prog_cliente using gv_prog_cliente . if not gv_prog_cliente is initial . leave program . endif . *&--------------------------------------------------------------------*& Rotina padro do Mastersaf *&--------------------------------------------------------------------perform f_init . perform f_importar_dados . perform f_constroi_range . clear gv_tipo_grav . perform f_gera_arqv_vazio tables gt_zsafx147 using '147' .

perform f_user_exit_seleciona_dados in program zsafe147 if found . *Inicio - Carlos Renato Barcelos de Oliveira (01.02.2012) perform f_seleciona_dados_fiscais . *Fim - Carlos Renato Barcelos de Oliveira (01.02.2012) perform f_seleciona_dados_contabeis . *Inicio - Ana Paula Rosa Pereira (23.05.2011) * perform f_processar_dados_fiscais . *Fim - Ana Paula Rosa Pereira (23.05.2011) perform f_processar_dados_contabeis . perform f_processar_saida . *&---------------------------------------------------------------------* *& Form F_INIT *&---------------------------------------------------------------------* * inicializao das tabelas internas *----------------------------------------------------------------------* form f_init . clear: gs_zsaft147 , gs_zsafx147 . refresh: gt_zsaft147[] , gt_zsafx147[] . endform . " f_init

*&---------------------------------------------------------------------* *& Form F_SELECIONA_DADOS_FISCAIS

*&---------------------------------------------------------------------* * seleciona dados fiscais no banco de dados *----------------------------------------------------------------------* form f_seleciona_dados_fiscais . *- begin of local data data: ls_1bnfdoc like line ls_1bnfstx like line ls_docref like line ls_saftb03 like line ls_saftb05 like line ls_saftbd like line l_index type i .

of of of of of of

gt_1bnfdoc , gt_1bnfstx , gt_1bnfdoc , gt_saftb03 , gt_saftb05 , gt_saftbd ,

constants c_x type c value 'X' . *- end of local data clear zsaf0 . select single * from zsaf0 client specified where mandt eq sy-mandt . check sy-subrc is initial . refresh gt_zsaf1[] . select * from zsaf1 client specified into table gt_zsaf1 where mandt eq sy-mandt and bukrs in gr_bukrs . check sy-subrc is initial . refresh gt_t001[] . select bukrs waers from t001 into table gt_t001 for all entries in gt_zsaf1 where bukrs eq gt_zsaf1-bukrs . check sy-subrc is initial . select bukrs branch from j_1bbranch into table gt_1bbranch for all entries in gt_t001 where bukrs eq gt_t001-bukrs and branch in gr_branc . refresh gt_saftb03[] . select * from zsaf3 client specified into table gt_saftb03 where mandt eq sy-mandt . if sy-subrc is initial .

delete gt_saftb03 where int147 is initial . endif . move 'IEQ' to gr_nftype . loop at gt_saftb03 into ls_saftb03 . move ls_saftb03-nftype to gr_nftype-low . append gr_nftype . endloop . refresh gt_saftbd[] . select * from zsafd client specified into table gt_saftbd where mandt eq sy-mandt . if sy-subrc is initial . delete gt_saftbd where int147 is initial . endif . move 'IEQ' to gr_cfop . loop at gt_saftbd into ls_saftbd . move ls_saftbd-cfop to gr_cfop-low . append gr_cfop . endloop . refresh gt_saftb05[] . select * from zsaf5 client specified into table gt_saftb05 where mandt eq sy-mandt . select docnum nftype doctyp direct pstdat credat chadat form series subser nfnum belnr bukrs branch parvw parid cancel docref nfe nfenum code from j_1bnfdoc into table gt_1bnfdoc for all entries in gt_t001 where ( bukrs eq gt_t001-bukrs and branch in gr_branc and pstdat in gr_pstda ) * condio para cancelamento or ( bukrs eq gt_t001-bukrs and branch in gr_branc and chadat in gr_pstda and cancel eq c_x ) . if sy-subrc is initial . delete gt_1bnfdoc where not nftype in gr_nftype . loop at gt_1bnfdoc into ls_1bnfdoc where docref <> 0 and doctyp = '6' . clear ls_docref . read table gt_1bnfdoc into ls_docref docdat " cabealho notas fiscais model gjahr partyp docstat

with key docnum = ls_1bnfdoc-docref . if sy-subrc is initial . if ls_docref not in gr_pstda . delete gt_1bnfdoc where docnum eq ls_1bnfdoc-docref and credat in gr_pstda . endif. endif. endloop. delete gt_1bnfdoc where doctyp eq '3' or doctyp eq '5' . " correo " cancelada

delete gt_1bnfdoc where nfnum is initial and nfenum is initial . " nf no lanada delete gt_1bnfdoc where cancel eq 'X' " lanada e and direct eq '1' " estornada no mesmo and credat in gr_pstda . " perodo sort gt_1bnfdoc by docnum . delete adjacent duplicates from gt_1bnfdoc comparing docnum . check not gt_1bnfdoc[] is initial . select docnum itmnum matnr bwkey maktx netpr incltx cfop * Inicio - Carlos Renato Barcelos de Oliveira (03/01/2012) taxsi4 * Fim - Carlos Renato Barcelos de Oliveira (03/01/2012) from j_1bnflin into table gt_1bnflin for all entries in gt_1bnfdoc where docnum eq gt_1bnfdoc-docnum . if sy-subrc is initial . sort gt_1bnflin by cfop . delete gt_1bnflin where not cfop in gr_cfop . endif . select docnum itmnum taxtyp base rate taxval from j_1bnfstx into table gt_1bnfstx for all entries in gt_1bnfdoc where docnum eq gt_1bnfdoc-docnum . loop at gt_1bnfstx into ls_1bnfstx . l_index = sy-tabix . clear ls_saftb05 . read table gt_saftb05 into ls_saftb05 with key taxtyp = ls_1bnfstx-taxtyp . if ls_saftb05-taxgroup = ls_saftb05-taxgroup = ls_saftb05-taxgroup = continue . else . delete gt_1bnfstx index endif . 'COFINS' or 'PIS ' or 'ICMS ' . l_index .

endloop . endif . endform . " f_seleciona_dados

*&---------------------------------------------------------------------* *& Form F_SELECIONA_DADOS_CONTABEIS *&---------------------------------------------------------------------* * seleciona dados contabeis do banco de dados *----------------------------------------------------------------------* form f_seleciona_dados_contabeis . *- begin of local data data: ls_saftb39 like line of gt_saftb39 , ls_saftb04 like line of gt_saftb04 , ls_bseg like line of gt_bseg , ls_bseg2 like line of gt_bseg , lt_aux type table of ty_bseg , * Inicio - Carlos Renato Barcelos de Oliveira (18/01/2012) ls_bkpf like line of gt_bkpf . * Fim - Carlos Renato Barcelos de Oliveira (18/01/2012) *- end of local data select * from zsaf39 client specified into table gt_saftb39 where mandt eq sy-mandt and bukrs in gr_bukrs . check sy-subrc is initial . * * * * * * * * * * * * * * * * * * * Inicio - Carlos Renato Barcelos de Oliveira (12/01/2012) No buscar da ZSAF4. Ser parametrizado tudo na ZSAF39 SELECT * FROM ZSAF4 CLIENT SPECIFIED INTO TABLE GT_SAFTB04 WHERE MANDT EQ SY-MANDT . IF SY-SUBRC IS INITIAL . DELETE GT_SAFTB04 WHERE INT147 IS INITIAL . ENDIF . CHECK NOT GT_SAFTB04[] IS INITIAL . MOVE 'IEQ' TO GR_BLART . LOOP AT GT_SAFTB04 INTO LS_SAFTB04 . MOVE LS_SAFTB04-BLART TO GR_BLART-LOW . APPEND GR_BLART . ENDLOOP .

* MOVE 'IEQ' TO : GR_HKONT , GR_LIFNR . move 'IEQ' to : gr_hkont , gr_blart . loop at gt_saftb39 into ls_saftb39 . if not ls_saftb39-hkont is initial . move ls_saftb39-hkont to gr_hkont-low .

append gr_hkont . endif . * * * * IF NOT LS_SAFTB39-LIFNR IS INITIAL . MOVE LS_SAFTB39-LIFNR TO GR_LIFNR-LOW . APPEND GR_LIFNR . ENDIF . if not ls_saftb39-blart is initial . move ls_saftb39-blart to gr_blart-low . append gr_blart . endif . endloop . * Fim - Carlos Renato Barcelos de Oliveira (12/01/2012) sort gr_hkont by low . delete adjacent duplicates from gr_hkont comparing low . sort gr_lifnr by low . delete adjacent duplicates from gr_lifnr comparing low . * Inicio - Carlos Renato Barcelos de Oliveira (03/01/2012) ** * * * * * * * * * * * * * * Inicio - Ana Paula Rosa Pereira (10/05/2011) SELECT * FROM ZFINT_PISCOFINS INTO TABLE GT_ZFINT_PISCOFINS WHERE BUKRS IN GR_BUKRS AND BUDAT IN GR_PSTDA. CHECK NOT GT_ZFINT_PISCOFINS IS INITIAL. SELECT BUKRS BELNR GJAHR BLART BUDAT STBLG STGRD FROM BKPF INTO TABLE GT_BKPF FOR ALL ENTRIES IN GT_ZFINT_PISCOFINS WHERE BUKRS EQ GT_ZFINT_PISCOFINS-BUKRS AND BELNR EQ GT_ZFINT_PISCOFINS-BELNR AND GJAHR EQ GT_ZFINT_PISCOFINS-GJAHR.

* Inicio - Carlos Renato Barcelos de Oliveira (05/01/2012) * Buscar documentos partindo da BKPF select bukrs belnr gjahr blart * Inicio - Carlos Renato Barcelos de Oliveira (25/01/2012) ** Inicio - Carlos Renato Barcelos de Oliveira (18/01/2012) ** BUDAT * CPUDT ** Fim - Carlos Renato Barcelos de Oliveira (18/01/2012) budat * Fim - Carlos Renato Barcelos de Oliveira (25/01/2012) stblg stgrd from bkpf into table gt_bkpf where bukrs in gr_bukrs * Inicio - Carlos Renato Barcelos de Oliveira (25/01/2012) ** Inicio - Carlos Renato Barcelos de Oliveira (18/01/2012) ** AND BUDAT IN GR_PSTDA. * AND CPUDT IN GR_PSTDA. ** Inicio - Carlos Renato Barcelos de Oliveira (18/01/2012)

and budat in gr_pstda. * Fim - Carlos Renato Barcelos de Oliveira (25/01/2012) if sy-subrc is initial . delete gt_bkpf where not blart in gr_blart . endif . check not gt_bkpf[] is initial. * Fim - Carlos Renato Barcelos de Oliveira (05/01/2012) * Inicio - Michel Moura (03/05/2013) if ( gr_pstda-high le '20121130' ) and '1100' in gr_bukrs. select ryear docnr rbukrs from faglflexa into table gt_flexa for all entries in gt_bkpf where rbukrs = gt_bkpf-bukrs and docnr = gt_bkpf-belnr and ryear = gt_bkpf-gjahr and rldnr = 'LL'. endif. * Fim - Michel Moura (03/05/2013) * Busca dados da BSEG com data como critrio select bukrs belnr gjahr buzei matnr dmbtr hkont shkzg kokrs kostl kunnr lifnr gsber werks sgtxt from bseg * Inicio - Carlos Renato Barcelos de Oliveira (05/01/2012) * INTO TABLE GT_BSEG_AUX into table gt_bseg2 for all entries in gt_bkpf where bukrs = gt_bkpf-bukrs and belnr = gt_bkpf-belnr and gjahr = gt_bkpf-gjahr. * Fim - Carlos Renato Barcelos de Oliveira (05/01/2012) * Inicio - Carlos Renato Barcelos de Oliveira (05/01/2012) ** Achados os Documentos, refazer a busca por BELNR. ** Isso pq o campo VALUT (data) est vazio para as contas parametrizadas. * SELECT BUKRS BELNR GJAHR BUZEI MATNR * DMBTR HKONT SHKZG KOKRS KOSTL * KUNNR LIFNR GSBER WERKS SGTXT * FROM BSEG * INTO TABLE GT_BSEG2 * FOR ALL ENTRIES IN GT_BSEG_AUX * WHERE BUKRS EQ GT_BSEG_AUX-BUKRS * AND BELNR EQ GT_BSEG_AUX-BELNR . * "WHERE BUKRS IN GR_BUKRS * " AND VALUT IN GR_PSTDA. ** AND hkont IN gr_hkont ** AND lifnr IN gr_lifnr . * Fim - Carlos Renato Barcelos de Oliveira (05/01/2012) * IF SY-SUBRC = 0. * * SELECT BUKRS BELNR GJAHR BUZEI MATNR * DMBTR HKONT SHKZG KOKRS KOSTL

* KUNNR LIFNR GSBER WERKS SGTXT * FROM BSEG * INTO TABLE GT_BSEG2 * FOR ALL ENTRIES IN GT_ZFINT_PISCOFINS * WHERE BUKRS EQ GT_ZFINT_PISCOFINS-BUKRS * AND BELNR EQ GT_ZFINT_PISCOFINS-BELNR * AND GJAHR EQ GT_ZFINT_PISCOFINS-GJAHR. * * ENDIF. ** Fim - Ana Paula Rosa Pereira (10/05/2011) * Fim - Carlos Renato Barcelos de Oliveira (03/01/2012) if sy-subrc is initial . sort gt_bseg2 by bukrs belnr gjahr buzei . * Inicio - Carlos Renato Barcelos de Oliveira (25/01/2012) move gt_bseg2 to gt_bseg_aux . * Fim - Carlos Renato Barcelos de Oliveira (25/01/2012) * Inicio - Carlos Renato Barcelos de Oliveira (18/01/2012) delete gt_bseg2 where not hkont in gr_hkont . * Fim - Carlos Renato Barcelos de Oliveira (18/01/2012) * Inicio - Carlos Renato Barcelos de Oliveira (05/01/2012) ** Inicio - Carlos Renato Barcelos de Oliveira (03/01/2012) ** Preencher LIFNR que esto vazios com os BELNR que tem valor. * LOOP AT gt_bseg2 INTO ls_bseg2 WHERE lifnr IS NOT INITIAL. * MODIFY GT_BSEG2 FROM ls_bseg2 * TRANSPORTING lifnr * WHERE belnr = ls_bseg2-belnr. * ENDLOOP. ** Fim - Carlos Renato Barcelos de Oliveira (03/01/2012) * Fim - Carlos Renato Barcelos de Oliveira (05/01/2012) move gt_bseg2[] to lt_aux[] . * Inicio - Ana Paula Rosa Pereira (23.05.2011) * LOOP AT gt_bseg2 INTO ls_bseg2 WHERE lifnr IN gr_lifnr . * Inicio - Carlos Renato Barcelos de Oliveira (12/01/2012) * LOOP AT GT_BSEG2 INTO LS_BSEG2 WHERE LIFNR IS NOT INITIAL . * No fazer verificao por Fornecedor (LIFNR) * LOOP AT GT_BSEG2 INTO LS_BSEG2 . loop at gt_bseg2 into ls_bseg . * Fim - Carlos Renato Barcelos de Oliveira (12/01/2012) * Inicio - Carlos Renato Barcelos de Oliveira (18/01/2012) * LOOP AT GT_SAFTB39 INTO LS_SAFTB39. read table gt_bkpf into ls_bkpf with key bukrs = ls_bseg-bukrs belnr = ls_bseg-belnr gjahr = ls_bseg-gjahr. if sy-subrc = 0. read table gt_saftb39 into ls_saftb39 with key hkont = ls_bseg-hkont blart = ls_bkpf-blart . IF ls_bseg-hkont = LS_SAFTB39-hkont AND LS_BKPF-blart = LS_SAFTB39-blar if sy-subrc = 0.

* t.

append ls_bseg to gt_bseg . endif. endif. * ENDLOOP. * Fim - Carlos Renato Barcelos de Oliveira (18/01/2012) * Inicio - Carlos Renato Barcelos de Oliveira (18/01/2012) **Fim - Ana Paula Rosa Pereira (23.05.2011) * LOOP AT LT_AUX[] INTO LS_BSEG * WHERE BUKRS EQ LS_BSEG2-BUKRS * AND BELNR EQ LS_BSEG2-BELNR * AND GJAHR EQ LS_BSEG2-GJAHR ** Inicio - Carlos Renato Barcelos de Oliveira (18/01/2012) * AND buzei EQ ls_bseg2-buzei . ** Fim - Carlos Renato Barcelos de Oliveira (18/01/2012) ** Inicio - Carlos Renato Barcelos de Oliveira (03/01/2012) *** Inicio - Ana Paula Rosa Pereira (23.05.2011) * CHECK ls_bseg-hkont IN gr_hkont . ** MOVE LS_BSEG2-LIFNR TO LS_BSEG-LIFNR . *** Fim - Ana Paula Rosa Pereira (23.05.2011) ** Fim - Carlos Renato Barcelos de Oliveira (03/01/2012) * ENDLOOP . * Fim - Carlos Renato Barcelos de Oliveira (18/01/2012) endloop . * Inicio - Carlos Renato Barcelos de Oliveira (05/01/2012) * IF NOT GT_BSEG[] IS INITIAL . * SELECT BUKRS BELNR GJAHR BLART BUDAT * STBLG STGRD * FROM BKPF * INTO TABLE GT_BKPF * FOR ALL ENTRIES IN GT_BSEG * WHERE BUKRS EQ GT_BSEG-BUKRS * AND BELNR EQ GT_BSEG-BELNR * AND GJAHR EQ GT_BSEG-GJAHR . ** Inicio - Carlos Renato Barcelos de Oliveira (03/01/2012) *** Inicio - Ana Paula Rosa Pereira (23.05.2011) * IF sy-subrc IS INITIAL . * DELETE gt_bkpf WHERE NOT blart IN gr_blart . * ENDIF . *** FIm - Ana Paula Rosa Pereira (23.05.2011) ** Fim - Carlos Renato Barcelos de Oliveira (03/01/2012) * ENDIF . * Fim - Carlos Renato Barcelos de Oliveira (05/01/2012) endif . endform . " f_seleciona_dados_contabeis

*&---------------------------------------------------------------------* *& Form F_PROCESSAR_DADOS_FISCAIS *&---------------------------------------------------------------------* * processamento interno de dados fiscais gerador da interface *----------------------------------------------------------------------* form f_processar_dados_fiscais . *- begin of local data data:

ls_t001 ls_1bnfdoc ls_1bnflin ls_1bnfstx ls_docref ls_saftb03 ls_saftb05 ls_saftbd

like like like like like like like like

line line line line line line line line

of of of of of of of of

gt_t001 , gt_1bnfdoc , gt_1bnflin , gt_1bnfstx , gt_1bnfdoc , gt_saftb03 , gt_saftb05 , gt_saftbd .

* Inicio - Ana Paula Rosa Pereira (19/05/2011) data: gl_bseg like line of gt_bseg, gl_awkey like j_1bnflin-refkey. * Fim - Ana Paula Rosa Pereira (19/05/2011) data l_found_item type c . constants c_x type c value 'X' . *- end of local data sort gt_1bnfdoc by docnum . sort gt_1bnflin by docnum itmnum . sort gt_1bnfstx by docnum itmnum . loop at gt_1bnfdoc into ls_1bnfdoc . clear: gv_netpr , gv_base_pis , gv_rate_pis , gv_val_pis , gv_base_cof , gv_rate_cof , gv_val_cof . " " " " " " " montante nf base PIS aliquota PIS valor PIS base COFIN aliquota COFINS valor COFINS

move: ls_1bnfdoc-bukrs to chv-chv1 . if p_fil eq 'X' . move: ls_1bnfdoc-branch to chv-chv2 . else . move: '0000' to chv-chv2 . endif . move move move move chv ls_1bnfdoc-bukrs ls_1bnfdoc-branch ls_1bnfdoc-pstdat to to to to gs_zsaft147-chave . gs_zsaft147-bukrs . gs_zsaft147-branch . gs_zsaft147-pstdat .

** Inicio - Ana Paula Rosa Pereira (19/05/2011) * read table gt_1bnflin into ls_1bnflin * with key docnum = ls_1bnfdoc-docnum. * * * select single refkey * from j_1bnflin into gl_awkey * where docnum = ls_1bnflin-docnum * and itmnum = ls_1bnflin-itmnum. * * select single bukrs belnr gjahr buzei matnr * dmbtr hkont shkzg kokrs kostl * kunnr lifnr gsber werks sgtxt

* from bseg * into gl_bseg * where bukrs eq ls_1bnfdoc-bukrs * and belnr eq gl_awkey(10) * and gjahr eq gl_awkey+10(4). * * if sy-subrc = 0. * gs_zsaft147-hkont = gl_bseg-hkont. * gs_zsaft147-kostl = gl_bseg-kostl. * else. ** Fim - Ana Paula Rosa Pereira (19/05/2011) move '@' to gs_zsaft147-hkont . ** Inicio - Ana Paula Rosa Pereira (19/05/2011) * endif. ** Fim - Ana Paula Rosa Pereira (19/05/2011) clear ls_saftb03 . read table gt_saftb03 into ls_saftb03 with key origem = 'D' nftype = ls_1bnfdoc-nftype . check sy-subrc is initial . move ls_saftb03-especie to gs_zsaft147-blart . perform f_le_parceiro using ls_1bnfdoc-partyp ls_1bnfdoc-parid changing gs_zsaft147-partyp gs_zsaft147-ind_cred . move ls_1bnfdoc-parid to gs_zsaft147-parid . shift gs_zsaft147-parid left deleting leading '0' . loop at gt_1bnflin into ls_1bnflin where docnum eq ls_1bnfdoc-docnum . l_found_item = c_x . " founded itens perform f_tipo_matnr using ls_1bnflin-matnr changing gs_zsaft147-ind_pro . if ls_1bnflin-matnr is initial . move '@' to gs_zsaft147-matnr . else . gs_zsaft147-matnr = ls_1bnflin-matnr . endif . if not ls_1bnfdoc-nfe is initial . gs_zsaft147-numdoc = ls_1bnfdoc-nfenum . else . gs_zsaft147-numdoc = ls_1bnfdoc-nfnum . endif . gs_zsaft147-series = ls_1bnfdoc-series . gs_zsaft147-subser = ls_1bnfdoc-subser . gs_zsaft147-belnr = ls_1bnfdoc-docnum . concatenate ls_1bnfdoc-docnum ls_1bnflin-maktx into gs_zsaft147-descricao separated by space .

if zsaf0-masprod eq 'X' . shift gs_zsaft147-matnr left deleting leading '0' . endif . add ls_1bnflin-netpr to gv_netpr . loop at gt_1bnfstx into ls_1bnfstx where docnum eq ls_1bnflin-docnum and itmnum eq ls_1bnflin-itmnum . read table gt_saftb05 into ls_saftb05 with key taxtyp = ls_1bnfstx-taxtyp . check sy-subrc = 0 . if ls_saftb05-taxgroup = 'PIS ' . gv_rate_pis = ls_1bnfstx-rate . add ls_1bnfstx-base to gv_base_pis . " base PIS add ls_1bnfstx-taxval to gv_val_pis . " valor PIS endif . if ls_saftb05-taxgroup = 'COFINS' . gv_rate_cof = ls_1bnfstx-rate . add ls_1bnfstx-base to gv_base_cof . " base COFINS add ls_1bnfstx-taxval to gv_val_cof . " valor COFINS endif . endloop . endloop . check not l_found_item is initial . clear l_found_item . * * * * * * * * * unpack gv_netpr to gs_zsaft147-vloperv .

unpack gv_base_pis to gs_zsaft147-pis_base . " base PIS unpack gv_rate_pis to gs_zsaft147-pis_rate . " aliq PIS unpack gv_val_pis to gs_zsaft147-pis_taxval . " valor PIS unpack gv_base_cof to gs_zsaft147-cof_base . " base COFINS unpack gv_rate_cof to gs_zsaft147-cof_rate . " aliq COFINS unpack gv_val_cof to gs_zsaft147-cof_taxval . " valor COFINS if ls_1bnflin-incltx = space . gs_zsaft147-vloperv = gs_zsaft147-vloperv + gs_zsaft147-cof_taxval + gs_zsaft147-pis_taxval . endif . perform f_user_exit_append_zsaft147 in program zsafe147 if found . append gs_zsaft147 to gt_zsaft147 . clear gs_zsaft147 . endloop .

endform .

" f_processar_dados_fiscais

*&---------------------------------------------------------------------*

*& Form f_processar_dados_contabeis *&---------------------------------------------------------------------* * processamento interno de dados contabeis gerador da interface *----------------------------------------------------------------------* form f_processar_dados_contabeis . *- begin of local data data: ls_bkpf like line of gt_bkpf , ls_bseg like line of gt_bseg , ls_bseg_aux like line of gt_bseg , ls_bseg2 like line of gt_bseg , " Add - Michel Moura (29/04/2013) ls_saftb39 like line of gt_saftb39 , vl_rbukrs like ls_bkpf-bukrs, " Add - Michel Moura (29/04/2013) * Inicio - Carlos Renato Barcelos de Oliveira (01/02/2012) tam type i, * Fim - Carlos Renato Barcelos de Oliveira (01/02/2012) * Inicio - Carlos Renato Barcelos de Oliveira (27/02/2012) conta type bseg-hkont . * Fim - Carlos Renato Barcelos de Oliveira (27/02/2012) data l_founded_hkont type c . constants c_x type c value 'X' . * Inicio - Carlos Renato Barcelos de Oliveira (09/01/2012) * Criar contador para o Campo Nm. Lancto (belnr) data num_lancto(2) type n. * Fim - Carlos Renato Barcelos de Oliveira (09/01/2012) *- end of local data sort sort sort sort sort gt_bkpf gt_zsaf1 gt_bseg gt_saftb39 gt_flexa by by by by by bukrs belnr gjahr . bukrs . bukrs belnr gjahr buzei . lifnr hkont . rbukrs docnr. " Add - Michel Moura (03/05/2013)

* Inicio - Carlos Renato Barcelos de Oliveira (09/01/2012) num_lancto = 0. * Fim - Carlos Renato Barcelos de Oliveira (09/01/2012) * Inicio - Carlos Renato Barcelos de Oliveira (25/01/2012) clear: gt_bseg2. refresh: gt_bseg2. move gt_bseg to gt_bseg2. * Fim - Carlos Renato Barcelos de Oliveira (25/01/2012) loop at gt_bkpf into ls_bkpf . clear gs_zsaf1 . read table gt_zsaf1 into gs_zsaf1 with key bukrs = ls_bkpf-bukrs binary search. check sy-subrc is initial . gv_ini = gs_zsaf1-inicc . gv_tam = 10 - gv_ini . clear: gv_netpr , " montante nf gv_base_pis , " base PIS

gv_rate_pis , gv_val_pis , gv_base_cof , gv_rate_cof , gv_val_cof .

" " " " "

aliquota PIS valor PIS base COFIN aliquota COFINS valor COFINS

* Inicio - Michel Moura (29/01/2013) if ( ls_bkpf-bukrs eq '1100') and ( ls_bkpf-budat le '20121130' ). clear: gs_flexa. read table gt_flexa into gs_flexa with key rbukrs = ls_bkpf-bukrs docnr = ls_bkpf-belnr ryear = ls_bkpf-gjahr. check sy-subrc is initial . endif. * Fim - Michel Moura (29/01/2013) * * MOVE ls_1bnfdoc-branch TO gs_zsaft147-branch . MOVE ls_1bnfdoc-pstdat TO gs_zsaft147-pstdat .

* Inicio - Carlos Renato Barcelos de Oliveira (18/01/2012) ** Inicio - Carlos Renato Barcelos de Oliveira (09/01/2012) * CLEAR GS_ZSAFT147. ** Fim - Carlos Renato Barcelos de Oliveira (09/01/2012) * Fim - Carlos Renato Barcelos de Oliveira (18/01/2012) loop at gt_bseg into ls_bseg where bukrs eq ls_bkpf-bukrs and belnr eq ls_bkpf-belnr and gjahr eq ls_bkpf-gjahr . * Inicio - Carlos Renato Barcelos de Oliveira (27/02/2012) clear conta. conta = ls_bseg-hkont. shift conta left deleting leading '0' . * Inicio - Carlos Renato Barcelos de Oliveira (05/03/2012) * IF ( conta(1) = '7' AND LS_BSEG-SHKZG = 'S' )"Receita (7) - Desconsiderar Lanamentos de Dbito. (S) * OR ( conta(1) = '8' AND LS_BSEG-SHKZG = 'H' ). "Despesa (8) - Desconsi derar Lanamentos de Crdito (H) ****** if ( ( conta(1) = '7' or conta(1) = '3' ) and ls_bseg-shkzg = 'S' )" Receita (7) - Desconsiderar Lanamentos de Dbito. (S) ****** or ( ( conta(1) = '8' or conta(1) = '4' ) and ls_bseg-shkzg = 'H' ). "Despesa (8) - Desconsiderar Lanamentos de Crdito (H) if ( ( conta(1) = '3' ) and ls_bseg-shkzg = 'S' )"Receita (7) - Desconside rar Lanamentos de Dbito. (S) or ( ( conta(1) = '8' or conta(1) = '4' ) and ls_bseg-shkzg = 'H' ). "Des pesa (8) - Desconsiderar Lanamentos de Crdito (H) * Fim - Carlos Renato Barcelos de Oliveira (05/03/2012) continue. endif. * Fim - Carlos Renato Barcelos de Oliveira (27/02/2012) * Inicio - Carlos Renato Barcelos de Oliveira (18/01/2012)

clear: gs_zsaft147, ls_bseg2. * Fim - Carlos Renato Barcelos de Oliveira (18/01/2012) * Inicio - Michel Moura (03/05/2013) if ls_bkpf-stblg is not initial. select bukrs belnr gjahr buzei matnr dmbtr hkont shkzg kokrs kostl kunnr lifnr gsber werks sgtxt from bseg into ls_bseg2 where bukrs = ls_bkpf-bukrs and belnr = ls_bkpf-stblg and gjahr = ls_bkpf-gjahr and hkont = ls_bseg-hkont. check sy-subrc eq 0 . subtract ls_bseg2-dmbtr from ls_bseg-dmbtr. endselect. check ls_bseg-dmbtr le 0. endif. * Fim - Michel Moura (03/05/2013) * Inicio - Carlos Renato Barcelos de Oliveira (09/01/2012) * Incrementa o Num. Lancto. if num_lancto = 99. num_lancto = 0. endif. num_lancto = num_lancto + 1. * Inicio - Carlos Renato Barcelos de Oliveira (09/01/2012) perform f_busca_filial using ls_bkpf-bukrs ls_bseg-gsber ls_bseg-werks . check gv_filial in gr_branc . if p_fil eq 'X' . move: gv_filial to chv-chv2 . else . move: '0000' to chv-chv2 . endif . move ls_bkpf-bukrs to chv-chv1 . move chv to gs_zsaft147-chave . move ls_bkpf-bukrs to gs_zsaft147-bukrs . " 1 move gv_filial to gs_zsaft147-branch . " 2 concatenate 'E' ls_bkpf-blart into gs_zsaft147-blart . " 3 move '1' to gs_zsaft147-partyp . " 4 * Inicio - Carlos Renato Barcelos de Oliveira (25/01/2012) * MOVE LS_BSEG-LIFNR TO GS_ZSAFT147-PARID . " 5 loop at gt_bseg_aux into ls_bseg_aux where and and and bukrs belnr gjahr lifnr = ls_bseg-bukrs = ls_bseg-belnr = ls_bseg-gjahr is not initial .

move ls_bseg_aux-lifnr to gs_zsaft147-parid . " 5 endloop. * Inicio - Ana Paula Rosa Pereira (09/08/2012) * Inicio - Michel Moura (22/04/2013) * Cdigo pessoa Fis/Jur estiver vazio vai procurar * na obs. Estava comentado e estou ativando por pedido do Especialista Francisco (Aliz) * Pois para alguns cenrios estavam errados. if gs_zsaft147-parid is initial. "Add Michel Moura (22/04/2013) if gr_pstda-low >= '20120801'. data: v_name like thead-tdname. data: v_line like table of tline with header line. concatenate ls_bkpf-bukrs ls_bseg-belnr ls_bseg-gjahr ls_bseg-buzei into v_name. call function 'READ_TEXT' exporting client id language name object tables lines exceptions id language name not_found object reference_check wrong_access_to_archive others

= = = = =

sy-mandt '0001' 'P' v_name 'DOC_ITEM'

= v_line = = = = = = = = 1 2 3 4 5 6 7 8.

if sy-subrc <> 0. * Implement suitable error handling here endif. if sy-subrc = 0. loop at v_line. gs_zsaft147-parid = v_line-tdline. endloop. endif. endif. endif. "Add Michel Moura (22/04/2013) * Fim - Ana Paula Rosa Pereira (09/08/2012) * Fim - Michel Moura (22/04/2013) * Fim - Carlos Renato Barcelos de Oliveira (25/01/2012)

* Inicio - Carlos Renato Barcelos de Oliveira (17/02/2012) shift gs_zsaft147-parid left deleting leading '0' . * Fim - Carlos Renato Barcelos de Oliveira (17/02/2012) perform f_tipo_matnr using ls_bseg-matnr changing gs_zsaft147-ind_pro . " 6 if ls_bseg-matnr is initial . move '@' to gs_zsaft147-matnr . * Inicio - Carlos Renato Barcelos de Oliveira (09/01/2012) * Quando o MATNR for em branco, o Indicador tambm ser em branco. move '@' to gs_zsaft147-ind_pro . * Fim - Carlos Renato Barcelos de Oliveira (09/01/2012) else . move ls_bseg-matnr to gs_zsaft147-matnr . " 7 endif . * Inicio - Carlos Renato Barcelos de Oliveira (18/01/2012) ** Inicio - Carlos Renato Barcelos de Oliveira (18/01/2012) ** MOVE LS_BKPF-BUDAT TO GS_ZSAFT147-PSTDAT . " 8 * MOVE LS_BKPF-CPUDT TO GS_ZSAFT147-PSTDAT . " 8 ** Fim - Carlos Renato Barcelos de Oliveira (18/01/2012) move ls_bkpf-budat to gs_zsaft147-pstdat . " 8 * Fim - Carlos Renato Barcelos de Oliveira (18/01/2012) * Inicio - Carlos Renato Barcelos de Oliveira (09/04/2012) * CONCATENATE LS_BKPF-BELNR LS_BSEG-SGTXT " 19 * INTO GS_ZSAFT147-DESCRICAO SEPARATED BY SPACE . move ls_bseg-sgtxt to gs_zsaft147-descricao ." 19 * Fim - Carlos Renato Barcelos de Oliveira (09/04/2012) if not ls_bseg-kunnr is initial . perform f_le_parceiro using 'C' ls_bseg-kunnr changing gs_zsaft147-partyp gs_zsaft147-ind_cred . else . perform f_le_parceiro using 'V' ls_bseg-lifnr changing gs_zsaft147-partyp gs_zsaft147-ind_cred . move ls_bseg-lifnr to ls_bseg-kunnr . endif . clear ls_saftb39 . loop at gt_saftb39 into ls_saftb39 *Inicio - Ana Paula Rosa Pereira (26/05/2011) * WHERE lifnr EQ ls_bseg-kunnr * AND hkont EQ ls_bseg-hkont . where hkont eq ls_bseg-hkont *Fim - Ana Paula Rosa Pereira (26/05/2011) * Inicio - Carlos Renato Barcelos de Oliveira (24/02/2012)

and blart eq ls_bkpf-blart and bukrs eq ls_bkpf-bukrs. * Fim - Carlos Renato Barcelos de Oliveira (24/02/2012) * CLEAR l_founded_hkont .

* Inicio - Carlos Renato Barcelos de Oliveira (09/01/2012) * Valor da BASE est dobrando. * ADD LS_BSEG-DMBTR TO GV_NETPR . " 9 move ls_bseg-dmbtr to gv_netpr . " 9 * Fim - Carlos Renato Barcelos de Oliveira (09/01/2012) case ls_saftb39-indpc . when '1' . " PIS gv_rate_pis = ls_saftb39-rate . " 11 * Inicio - Carlos Renato Barcelos de Oliveira (09/01/2012) * Valor do PIS ser calculado. * ADD LS_BSEG-DMBTR TO GV_VAL_PIS . " 12 gv_val_pis = ls_bseg-dmbtr * ls_saftb39-rate / 100. "12 * Fim - Carlos Renato Barcelos de Oliveira (09/01/2012) * unpack gv_rate_pis to gs_zsaft147-pis_rate . unpack gv_val_pis to gs_zsaft147-pis_taxval . gs_zsaft147-pis_taxval = gv_val_pis.

* Inicio - Carlos Renato Barcelos de Oliveira (05/03/2012) **** Inicio - Carlos Renato Barcelos de Oliveira (01/02/2012) *** tam = STRLEN( GS_ZSAFT147-PIS_TAXVAL ) - 2. *** GS_ZSAFT147-PIS_TAXVAL = GS_ZSAFT147-PIS_TAXVAL(tam) . **** Fim - Carlos Renato Barcelos de Oliveira (01/02/2012) * Fim - Carlos Renato Barcelos de Oliveira (05/03/2012) when '2' . " COFINS gv_rate_cof = ls_saftb39-rate . " 14 Inicio - Carlos Renato Barcelos de Oliveira (09/01/2012) Valor do PIS ser calculado. ADD LS_BSEG-DMBTR TO GV_VAL_COF . " 15 gv_val_cof = ls_bseg-dmbtr * ls_saftb39-rate / 100. "15 Fim - Carlos Renato Barcelos de Oliveira (09/01/2012)

* * * * *

unpack gv_rate_cof to gs_zsaft147-cof_rate . unpack gv_val_cof to gs_zsaft147-cof_taxval . gs_zsaft147-cof_taxval = gv_val_cof. * Inicio - Carlos Renato Barcelos de Oliveira (05/03/2012) **** Inicio - Carlos Renato Barcelos de Oliveira (01/02/2012) *** tam = STRLEN( GS_ZSAFT147-COF_TAXVAL ) - 2. *** GS_ZSAFT147-COF_TAXVAL = GS_ZSAFT147-COF_TAXVAL(tam) . **** Fim - Carlos Renato Barcelos de Oliveira (01/02/2012) * Fim - Carlos Renato Barcelos de Oliveira (05/03/2012) endcase . * Inicio - Carlos Renato Barcelos de Oliveira - 05/01/2011 gs_zsaft147-cod_nat_rec = ls_saftb39-cod_nat_rec. * Fim - Carlos Renato Barcelos de Oliveira - 05/01/2011 endloop . * * CHECK NOT l_founded_hkont IS INITIAL . MOVE 'X' TO l_founded_hkont . move gv_netpr to : gs_zsaft147-cof_base , " 13

gs_zsaft147-pis_base , " 10 * Inicio - Carlos Renato Barcelos de Oliveira (09/01/2012) gs_zsaft147-vloperv. " 9 * Fim - Carlos Renato Barcelos de Oliveira (09/01/2012) * Inicio - Carlos Renato Barcelos de Oliveira (27/02/2012) ** Inicio - Carlos Renato Barcelos de Oliveira (01/02/2012) * IF GV_NETPR < 0. * CONCATENATE '-' GS_ZSAFT147-COF_BASE INTO GS_ZSAFT147-COF_BASE. * CONCATENATE '-' GS_ZSAFT147-PIS_BASE INTO GS_ZSAFT147-PIS_BASE. * CONCATENATE '-' GS_ZSAFT147-VLOPERV INTO GS_ZSAFT147-VLOPERV. * CONCATENATE '-' GS_ZSAFT147-COF_TAXVAL INTO GS_ZSAFT147-COF_TAXVAL. * CONCATENATE '-' GS_ZSAFT147-PIS_TAXVAL INTO GS_ZSAFT147-PIS_TAXVAL. * ENDIF. ** Fim - Carlos Renato Barcelos de Oliveira (01/02/2012) * Fim - Carlos Renato Barcelos de Oliveira (27/02/2012) * Inicio - Carlos Renato Barcelos de Oliveira (09/04/2012) move '0' to gs_zsaft147-ind_cred . " 16 * Fim - Carlos Renato Barcelos de Oliveira (09/04/2012) * MOVE ls_bseg-hkont TO gs_zsaft147-hkont+gv_ini(gv_tam) . " 17 * Inicio - Ana Paula Rosa Pereira (23/05/2011) * MOVE '@' TO gs_zsaft147-hkont . move ls_bseg-hkont to gs_zsaft147-hkont. * Fim - Ana Paula Rosa Pereira (23/05/2011) * Inicio - Carlos Renato Barcelos de Oliveira (07/03/2012) shift gs_zsaft147-hkont left deleting leading '0'. * Fim - Carlos Renato Barcelos de Oliveira (07/03/2012) * Inicio - Carlos Renato Barcelos de Oliveira (16/02/2012) * CONCATENATE LS_BSEG-KOKRS LS_BSEG-KOSTL " 18 * INTO GS_ZSAFT147-KOSTL . move ls_bseg-kostl to gs_zsaft147-kostl . " 18 * Fim - Carlos Renato Barcelos de Oliveira (16/02/2012) move ls_bkpf-belnr to : gs_zsaft147-numdoc . " 20 * Inicio - Carlos Renato Barcelos de Oliveira (09/01/2012) * GS_ZSAFT147-BELNR . " 23 * Fim - Carlos Renato Barcelos de Oliveira (09/01/2012) * Inicio - Carlos Renato Barcelos de Oliveira (09/04/2012) concatenate num_lancto ls_bkpf-belnr into gs_zsaft147-belnr . ** Inicio - Carlos Renato Barcelos de Oliveira (09/01/2012) * GS_ZSAFT147-BELNR = num_lancto . " 23 ** Fim - Carlos Renato Barcelos de Oliveira (09/01/2012) * Fim - Carlos Renato Barcelos de Oliveira (09/04/2012) move '@' to : gs_zsaft147-series , " 21 gs_zsaft147-subser . " 22 * Inicio - Carlos Renato Barcelos de Oliveira (17/02/2012) shift gs_zsaft147-matnr left deleting leading '0'. * Fim - Carlos Renato Barcelos de Oliveira (17/02/2012) check gs_zsaft147-vloperv is not initial. " Add - Michel Moura (03/05/2013 ) * Inicio - Carlos Renato Barcelos de Oliveira (18/01/2012) append gs_zsaft147 to gt_zsaft147 . * Fim - Carlos Renato Barcelos de Oliveira (18/01/2012) " 23

endloop . * ** iNICIO - cARLOS rENATO bARCELOS DE oLIVEIRA (18/01/2012) * *** iNICIO - aNA pAULA rOSA pEREIRA (19/05/2011) ** if not gs_zsaft147 is initial. *** fIM - aNA pAULA rOSA pEREIRA (19/05/2011) ** append gs_zsaft147 to gt_zsaft147 . *** iNICIO - aNA pAULA rOSA pEREIRA (19/05/2011) ** endif. *** fIM - aNA pAULA rOSA pEREIRA (19/05/2011) * ** fIM - cARLOS rENATO bARCELOS DE oLIVEIRA (18/01/2012) * endloop . * *Inicio - Ana Paula Rosa Pereira (08/08/2012) data: v_vloperv like bseg-dmbtr, v_pis_base like bseg-dmbtr, v_pis_taxval like bseg-dmbtr, v_cof_base like bseg-dmbtr, v_cof_taxval like bseg-dmbtr, v_vlopervneg like bseg-dmbtr, v_pis_baseneg like bseg-dmbtr, v_pis_taxvalneg like bseg-dmbtr, v_cof_baseneg like bseg-dmbtr, v_cof_taxvalneg like bseg-dmbtr, v_hkont like bseg-hkont, v_dat1 like sy-datum, v_dat2 like sy-datum. data: gt_zsaft147_aux2 like gt_zsaft147 with header line. sort gt_zsaft147 by hkont. loop at gt_zsaft147 into gs_zsaft147_aux. read table gt_saftb39 into ls_saftb39 with key hkont = gs_zsaft147_aux-hkont bukrs = gs_zsaft147_aux-bukrs. if not ls_saftb39-saldo is initial. v_dat1 = gs_zsaft147_aux-pstdat. call function 'FKK_LAST_DAY_OF_MONTH' exporting day_in = v_dat1 importing last_day_of_month = v_dat2. gs_zsaft147_aux-pstdat = v_dat2. gs_zsaft147_aux-kostl = '@'. select single txt50 into gs_zsaft147_aux-descricao from skat

where spras = 'PT' and ktopl = '0050' and saknr = gs_zsaft147_aux-hkont. if gs_zsaft147_aux-hkont <> v_hkont. clear: v_vloperv, v_pis_base, v_pis_taxval, v_cof_base, v_cof_taxval. clear: v_vlopervneg, v_pis_baseneg, v_pis_taxvalneg, v_cof_baseneg, v_cof_taxvalneg. endif. read table gt_bseg into ls_bseg with key bukrs = gs_zsaft147_aux-bukrs belnr = gs_zsaft147_aux-numdoc dmbtr = gs_zsaft147_aux-vloperv. if ls_bseg-shkzg = 'S'. v_vlopervneg v_pis_baseneg v_pis_taxvalneg v_cof_baseneg v_cof_taxvalneg else. v_vloperv v_pis_base v_pis_taxval v_cof_base v_cof_taxval endif. = = = = = = = = = = v_vlopervneg v_pis_baseneg v_pis_taxvalneg v_cof_baseneg v_cof_taxvalneg + + + + + + + + + + gs_zsaft147_aux-vloperv. gs_zsaft147_aux-pis_base. gs_zsaft147_aux-pis_taxval. gs_zsaft147_aux-cof_base. gs_zsaft147_aux-cof_taxval.

v_vloperv v_pis_base v_pis_taxval v_cof_base v_cof_taxval = = = = =

gs_zsaft147_aux-vloperv. gs_zsaft147_aux-pis_base. gs_zsaft147_aux-pis_taxval. gs_zsaft147_aux-cof_base. gs_zsaft147_aux-cof_taxval. v_vlopervneg. v_pis_baseneg. v_pis_taxvalneg. v_cof_baseneg. v_cof_taxvalneg.

gs_zsaft147_aux-vloperv gs_zsaft147_aux-pis_base gs_zsaft147_aux-pis_taxval gs_zsaft147_aux-cof_base gs_zsaft147_aux-cof_taxval

v_vloperv v_pis_base v_pis_taxval v_cof_base v_cof_taxval

if gs_zsaft147_aux-hkont = v_hkont. modify gt_zsaft147_aux from gs_zsaft147_aux transporting vloperv pis_base pis_taxval cof_base cof_taxval where hkont eq v_hkont. elseif v_hkont is initial . append gs_zsaft147_aux to gt_zsaft147_aux . else. append gs_zsaft147_aux to gt_zsaft147_aux .

endif. v_hkont = gs_zsaft147_aux-hkont. else. append gs_zsaft147_aux to gt_zsaft147_aux. endif. endloop. *Fim - Ana Paula Rosa Pereira (06/08/2012) endform . "f_processar_dados_contabeis *&---------------------------------------------------------------------* *& Form F_CONSTROI_RANGE *&---------------------------------------------------------------------* * constri ranges para as clasulas where *----------------------------------------------------------------------* form f_constroi_range . clear gr_bukrs . move 'IBT' to gr_bukrs . move b1_bukrs_low to gr_bukrs-low . move b1_bukrs_high to gr_bukrs-high . append gr_bukrs . clear gr_branc . move 'IBT' to gr_branc . move b1_brnch_low to gr_branc-low . move b1_brnch_high to gr_branc-high . append gr_branc . clear gr_pstda . move 'IBT' to gr_pstda . move b1_pdate_low to gr_pstda-low . move b1_pdate_high to gr_pstda-high . append gr_pstda . endform . " f_constroi_range

*&---------------------------------------------------------------------* *& Form F_PROCESSAR_SAIDA *&---------------------------------------------------------------------* * faz a gerao do arquivo de sada em .txt ou em batch *----------------------------------------------------------------------* form f_processar_saida . *- begin of local data data lv_tabix type sy-tabix . field-symbols <vers_prdt> type any . data l_vers_prdt(2) type c . *- end of local data loop at gt_zsaft147_aux into gs_zsaft147 . lv_tabix = sy-tabix . at new bukrs .

clear zsafb . select single * from zsafb where bukrs eq gs_zsaft147-bukrs . endat . at new branch . clear zsafa . select single * from zsafa where bukrs eq gs_zsaft147-bukrs and branch eq gs_zsaft147-branch . endat . if <vers_prdt> is assigned . unassign <vers_prdt> . endif . assign component 'VERS_PRDT' of structure zsaf0 to <vers_prdt> . if <vers_prdt> is assigned . l_vers_prdt = <vers_prdt> . endif . if l_vers_prdt eq '37' . perform f_preencher_tabela_zsafx147_37 . else . perform f_preencher_tabela_zsafx147 . endif . at end of chave. perform f_busca_mascara using gs_zsaft147-chave(4) gs_zsaft147-chave+4(4) . if l_vers_prdt eq '37' . perform f_gravar_dados tables gt_zsafx147_v37 using '147.txt' . else . perform f_gravar_dados tables gt_zsafx147 using '147.txt' . endif . refresh: gt_zsafx147, gt_zsafx147_v37 . endat . delete gt_zsaft147 index lv_tabix . endloop . refresh gt_zsaft147 . endform . " f_processar_saida

*&---------------------------------------------------------------------*

*& Form F_BUSCA_MASCARA *&---------------------------------------------------------------------* * busca mscara parametrizavel *----------------------------------------------------------------------* * --> p_chave(4) empresa * --> p_chave+4(4) filial *----------------------------------------------------------------------* form f_busca_mascara using p_bukrs type any p_branch type any . gv_mascara = 'SAFX' . if p_fil eq 'X' . clear zsafa . select single * from zsafa where bukrs and branch if sy-subrc is initial . if not ( zsafa-mascara is initial ). gv_mascara = zsafa-mascara . move-corresponding zsafa to h_zsafa append h_zsafa . endif . endif . else . clear zsafb . select single * from zsafb where bukrs if sy-subrc is initial . if not ( zsafb-mascara is initial ) . gv_mascara = zsafb-mascara . move-corresponding zsafb to h_zsafb append h_zsafb . endif . endif . endif . endform .

= p_bukrs = p_branch .

= p_bukrs .

" f_busca_mascara

*&---------------------------------------------------------------------* *& Form F_PREENCHER_TABELA_ZSAFX147_37 *&---------------------------------------------------------------------* * preenche tabela de sada para verso 37 *----------------------------------------------------------------------* form f_preencher_tabela_zsafx147_37 . clear gs_zsafx147_v37 . move-corresponding gs_zsaft147 to gs_zsafx147_v37 . move-corresponding hex_fill to gs_zsafx147_v37 . move zsafb-codigo to gs_zsafx147_v37-bukrs . move zsafa-codigo to gs_zsafx147_v37-branch . *Inicio - Ana Paula Rosa Pereira (07/08/2012) unpack: unpack: unpack: unpack: unpack: gs_zsaft147-vloperv to gs_zsafx147_v37-vloperv. gs_zsaft147-pis_base to gs_zsafx147_v37-pis_base. gs_zsaft147-pis_taxval to gs_zsafx147_v37-pis_taxval. gs_zsaft147-cof_base to gs_zsafx147_v37-cof_base. gs_zsaft147-cof_taxval to gs_zsafx147_v37-cof_taxval.

*Fim - Ana Paula Rosa Pereira (07/08/2012) perform f_user_exit_append_zsafx147 in program zsafe147 if found . append gs_zsafx147_v37 to gt_zsafx147_v37 . endform . " f_preencher_tabela_zsafx147_37

*&---------------------------------------------------------------------* *& Form F_PREENCHER_TABELA_ZSAFX147 *&---------------------------------------------------------------------* * preenche tabela de sada para outras verses *----------------------------------------------------------------------* form f_preencher_tabela_zsafx147 . clear gs_zsafx147 . move-corresponding gs_zsaft147 to gs_zsafx147 . move-corresponding hex_fill to gs_zsafx147 . move zsafb-codigo move zsafa-codigo to gs_zsafx147-bukrs . to gs_zsafx147-branch .

*Inicio - Ana Paula Rosa Pereira (07/08/2012) unpack: unpack: unpack: unpack: unpack: gs_zsaft147-vloperv to gs_zsafx147-vloperv. gs_zsaft147-pis_base to gs_zsafx147-pis_base. gs_zsaft147-pis_taxval to gs_zsafx147-pis_taxval. gs_zsaft147-cof_base to gs_zsafx147-cof_base. gs_zsaft147-cof_taxval to gs_zsafx147-cof_taxval.

*Fim - Ana Paula Rosa Pereira (07/08/2012) perform f_user_exit_append_zsafx147 in program zsafe147 if found . append gs_zsafx147 to gt_zsafx147 . endform . " f_preencher_tabela_zsafx147 *&---------------------------------------------------------------------* *& Form F_GRAVAR_DADOS *&---------------------------------------------------------------------* * funo geradora do arquivo *----------------------------------------------------------------------* * --> pt_table tabela interna da interface a ser gerada * --> param1 cdigo da SAFX *----------------------------------------------------------------------* form f_gravar_dados tables p_t_table using param1 type any . *&===================================================================== *& ATENO: Utilizar SOMENTE para customizaes do cliente, visando *& MODIFICAR os dados gerados pela rotina padro do Mastersaf *&===================================================================== perform f_user_exit_trata_dados in program zsafe147 if found . condense p_path no-gaps . concatenate p_path gv_mascara param1 into gv_arquivo . condense gv_arquivo no-gaps . describe table p_t_table lines gv_cont .

clear h_arqs . h_arqs-total = gv_cont . concatenate gv_mascara param1 into h_arqs-arquivo . clear gv_nomearq . gv_nomearq = h_arqs-arquivo . perform grava_dados_zsafx in program zsafm000 using p_nrarq b1_bukrs_low b1_bukrs_high b1_brnch_low b1_brnch_high b1_pdate_low b1_pdate_high p_path gv_nomearq gv_cont . call function 'Z_MASTERSAF_FILE_WRITE' exporting pe_file_name = gv_arquivo pe_frontend = p_pc pe_datum = gv_datum pe_uzeit = gv_uzeit tables te_info = p_t_table. endform . " f_gravar_dados

*&---------------------------------------------------------------------* *& Form F_TIPO_MATNR *&---------------------------------------------------------------------* * busca tipo de material parametrizado *----------------------------------------------------------------------* form f_tipo_matnr using p_matnr type any changing p_ind type any . *- begin of local data data ls_mara type mara . *- end of local data call function 'MARA_SINGLE_READ' exporting matnr = p_matnr importing wmara = ls_mara exceptions lock_on_material = 1 lock_system_error = 2 wrong_call = 3 not_found = 4. clear zsaf11 . select single * from zsaf11 where mtart eq ls_mara-mtart .

if sy-subrc is initial . move zsaf11-tipo to p_ind . else . move '8' to p_ind . endif . endform . " f_tipo_matnr *&---------------------------------------------------------------------* *& Form F_BUSCA_FILIAL *&---------------------------------------------------------------------* * busca filial por diviso/centro *----------------------------------------------------------------------* * --> P_BUKRS empresa * --> P_GSBER diviso * --> P_WERKS centro *----------------------------------------------------------------------* form f_busca_filial using p_bukrs type bukrs p_gsber type gsber p_werks type werks_d . clear gv_filial . if sy-subrc is initial . if gs_zsaf1-udvcf eq 'X' . clear zsaf2 . select single * from zsaf2 where gsber = p_gsber . if sy-subrc is initial . gv_filial = zsaf2-branch . endif . else. if not p_werks is initial . clear t001w . select single * from t001w where werks = p_werks . if sy-subrc is initial . gv_filial = t001w-j_1bbranch . endif . else . gv_filial = gs_zsaf1-branch . endif . endif . endif . endform . " f_busca_filial

*&---------------------------------------------------------------------* *& Form F_LE_PARCEIRO *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_LS_1BNFDOC_PARTYP text * -->P_LS_1BNFDOC_PARID text * <--P_GS_ZSAFT147_PARTYP text * <--P_GS_ZSAFT147_IND_CRED text *----------------------------------------------------------------------* form f_le_parceiro using p_partyp type any

p_parid type any changing pg_partyp type any pg_ind_cred type any . case p_partyp . when 'C' . " client move '2' to pg_partyp . clear kna1 . select single * from kna1 where kunnr eq p_parid . if kna1-land1 ne 'BR' . pg_ind_cred = '1' . else . pg_ind_cred = '0' . endif . when 'V' . " vendor move '1' to pg_partyp . clear lfa1 . select single * from lfa1 where lifnr eq p_parid . if lfa1-land1 ne 'BR' . pg_ind_cred = '1' . else . pg_ind_cred = '0' . endif . when 'B' . " branch move '3' to pg_partyp . move '0' to pg_partyp . endcase . endform "v0504

"v0504

You might also like