mzficom003f01

Download MZFICOM003F01

If you can't read please download the document

Upload: fjaimesilva

Post on 06-Nov-2015

39 views

Category:

Documents


9 download

DESCRIPTION

Programa abap

TRANSCRIPT

*----------------------------------------------------------------------****INCLUDE MZFICOM003F01 .*----------------------------------------------------------------------**&---------------------------------------------------------------------**& Form f_selecao_inf_nota*&---------------------------------------------------------------------**& TELA 0100 - chamada para seleo de dados*& Rotina que seleciona as comisses que ainda no nro nota fiscal*&---------------------------------------------------------------------**&form f_selecao_pagamentos using value(p_status). call function 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 10 text = 'Lendo comisses ...'.*> Leitura das comisses da quinzena selecionada que no tem o numero*> da nota fiscal informado if ( p_status eq 'E' ). select * from zfitcom003 into table t_zfitcom003 where ( pagnr in s_pagnr ) and ( bukrs eq p_bukrs ) and ( vkbur in s_vkbur )*> and ( quinzena le p_quinz ) and ( status le '2' ). else. select * from zfitcom003 into table t_zfitcom003 where ( pagnr in s_pagnr ) and ( bukrs eq p_bukrs ) and ( vkbur in s_vkbur )*> and ( quinzena le p_quinz ) and ( status eq p_status ). endif. check ( sy-subrc eq 0 ). call function 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 60 text = 'Lendo item das comisses selecionadas ...'. select * from zfitcom004 into table t_zfitcom004 for all entries in t_zfitcom003 where ( pagnr eq t_zfitcom003-pagnr ). select * from zfitcom011 into table t_base12 for all entries in t_zfitcom003 where ( pagnr eq t_zfitcom003-pagnr ). perform f_valida_vkbur. if ( not t_tvbur[] is initial ). perform f_calcula_impostos. endif. call function 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = 100 text = 'Finalizado ...'.endform. " f_selecao_pagamentos*&---------------------------------------------------------------------**& Form f_verifica_nota*&---------------------------------------------------------------------**& Rotina que verifica em quais vendedores foi informada a nf*&---------------------------------------------------------------------**&form f_verifica_nota. zfitcom003-usrnf = sy-uname. zfitcom003-dtrnf = sy-datum. zfitcom003-hrrnf = sy-uzeit. zfitcom003-status = '2'. modify t_zfitcom003 from zfitcom003 transporting usrnf dtrnf hrrnf status where ( nfnum ne space ). delete t_zfitcom003 where ( nfnum eq space ).endform. " f_verifica_nota*&---------------------------------------------------------------------**& Form f_gera_pagamento*&---------------------------------------------------------------------**& Rotina que executa baixa na conta de comisso e lana crdito*& na conta do representante*&---------------------------------------------------------------------**&form f_gera_pagamento.data: SPERR_USER LIKE SY-UNAME. " Sperrender User delete t_zfitcom004 where ( mark ne c_mark ). describe table t_zfitcom003 lines v_totpgt. clear v_totproc. loop at t_zfitcom003 into zfitcom003. refresh: t_bdcdata, t_bdcaux, t_itemaux, t_item. clear wa_shdb.*> Filtra somente itens do pagamento e soma valores por belnr*> criando nova tabela de itens move-corresponding zfitcom003 to wa_shdb. clear v_totlin. t_itemaux[] = t_zfitcom004[]. delete t_itemaux where ( pagnr ne zfitcom003-pagnr ).* sort t_itemaux by pagnr belnr buzei.** loop at t_itemaux into wa_itemaux.* wa_item = wa_itemaux.* on change of belnr.* endon.* at end of belnr.* sum.* wa_item-vlpgto = wa_itemaux-vlpgto + wa_itemaux-vlperd* + wa_itemaux-vldesc + wa_itemaux-vlpdd.* wa_item-vlsald = wa_item-wrbtr - wa_item-vlpgto* - wa_item-vlreal.* if ( wa_item-vlsald lt 0 ).* clear wa_item-vlsald.* endif.** wa_item-vlperd = wa_itemaux-vlperd.* wa_item-vldesc = wa_itemaux-vldesc.* wa_item-vlpdd = wa_itemaux-vlpdd.* append wa_item to t_item.* endat.* endloop.* perform f_saldo_por_atribuicao tables t_itemaux t_item. sort t_item by pagnr belnr buzei. read table t_lfa1 into wa_lfa1 with key vkbur = zfitcom003-vkbur binary search. if ( sy-subrc ne 0 ). clear wa_lfa1. endif. perform f_calcula_totais tables t_item t_lfbw t_lfa1 changing zfiecom002-totalnf zfiecom002-totcom zfiecom002-totimp. wa_shdb-totalnf = zfiecom002-totalnf. wa_shdb-lifnr = wa_lfa1-lifnr. clear v_chg_lfbw. loop at t_item into wa_item. check ( 'RVDGSNDA0312' cs wa_item-blart ). if ( wa_item-blart eq '03' ) or ( wa_item-blart eq '12' ). v_chg_lfbw = c_mark. endif. move-corresponding wa_item to wa_shdb.* if ( wa_item-shkzg eq 'S' ).* wa_shdb-vlpgto = wa_item-vldesc.* endif.* check ( wa_item-vlpgto ne 0 ) or* ( wa_item-shkzg eq 'S' ).* if ( wa_item-vlsald gt 0 ). clear wa_shdb-mark. v_totlin = v_totlin + 1. else. wa_shdb-mark = c_mark. endif. v_bukrs = wa_item-bukrs. wa_shdb-vlpgto = wa_shdb-vlpgto + wa_shdb-vldesc + wa_shdb-vlpdd + wa_shdb-vlperd. if ( wa_shdb-vlpgto ne 0 ).* ( wa_item-shkzg eq 'S' ). append wa_shdb to t_shdb. endif.*BDS - Ira deduzir as devolues if ( wa_item-shkzg eq 'S' ). wa_shdb-vlpgto = wa_shdb-vlpgto * -1. endif.*BDS - fim. move-corresponding wa_shdb to wa_shdb60. append wa_shdb60 to t_shdb60. endloop.*> Guarda valores de impostos para o fornecedor select * from lfbw into table t_lfbw_old where ( lifnr eq wa_lfa1-lifnr ) and ( bukrs eq v_bukrs ).* Verifica se o fornecedor no est sendo bloqueado por alguma transao CALL FUNCTION 'ENQUEUE_EXLFA1' EXPORTING LIFNR = wa_lfa1-lifnr EXCEPTIONS FOREIGN_LOCK = 1 SYSTEM_FAILURE = 2. CASE SY-SUBRC.*------- Konto von anderem Benutzer gesperrt --------------------------- WHEN 1. SPERR_USER = SY-MSGV1.* Erro de sistema ao bloquear; contactar o administrador de sistema MESSAGE E042(f2) WITH wa_LFA1-LIFNR SPERR_USER.*------- Systemfehler -------------------------------------------------- WHEN 2. MESSAGE E038(f2). ENDCASE. CALL FUNCTION 'DEQUEUE_EXLFA1' EXPORTING LIFNR = wa_LFA1-LIFNR EXCEPTIONS SYSTEM_FAILURE = 1. perform f_grava_lfbw using 1. perform f_grava_batch_input. perform f_grava_lfbw using 2. refresh: t_shdb, t_shdb60. endloop. concatenate 'Foram processados' v_totpgt 'pagamentos,' into v_text separated by space. concatenate 'onde' v_totproc 'foram criados com sucesso!' into v_text2 separated by space. message i999(zarm) with v_text v_text2.endform. " f_gera_pagamento*&---------------------------------------------------------------------**& Form f_grava_batch_input*&---------------------------------------------------------------------**& Grava BI*&---------------------------------------------------------------------**&form f_grava_batch_input. data: v_idx(02) type n, v_abpos like rf05a-abpos, v_zuonr like bsis-zuonr, v_first type c, v_item_shkzg type c, v_resctr_txt(8) type c, v_comando type c, v_data(10) type c, v_datnf(10) type c. refresh: t_bdcdata, t_messtab. sort t_shdb60 by mark hkont gsber belnr buzei. sort t_shdb by mark hkont belnr buzei. loop at t_shdb60 into wa_shdb60. wa_60aux = wa_shdb60. at first. clear: v_first, v_comando. write zfitcom003-datnf to v_datnf ddmmyy. write sy-datum to v_data ddmmyy. if ( zfitcom003-resctr eq c_mark ). v_resctr_txt = 'Resciso'. else. v_resctr_txt = 'Clculo'. endif. concatenate v_resctr_txt 'representante' wa_60aux-vkbur into v_text separated by space. concatenate v_resctr_txt wa_60aux-pagnr 'representante' wa_60aux-vkbur into v_text2 separated by space. write wa_60aux-totalnf to v_valor. perform mudar_empresa_do_buffer. refresh: t_bdcdata, t_messtab. perform f_bdcinsert using: 'X' 'SAPMF05A' '1100', ' ' 'BDC_OKCODE' '=PAYM', ' ' 'INVFO-ACCNT' wa_60aux-lifnr, ' ' 'INVFO-BLDAT' v_datnf,*> ' ' 'INVFO-BLART' 'KR', ' ' 'INVFO-BUDAT' v_data, ' ' 'INVFO-XBLNR' wa_60aux-nfnum, ' ' 'INVFO-WRBTR' v_valor, ' ' 'INVFO-WAERS' 'BRL', ' ' 'INVFO-SGTXT' v_text2. perform f_bdcinsert using: 'X' 'SAPMF05A' '1100', ' ' 'BDC_OKCODE' '=MORE', ' ' 'INVFO-ZFBDT' v_data, ' ' 'INVFO-ZTERM' '5000', ' ' 'INVFO-ZLSPR' 'A'. concatenate v_resctr_txt 'rp:' wa_60aux-vkbur into v_text separated by space. perform f_bdcinsert using: 'X' 'SAPMF05A' '1100', ' ' 'BDC_OKCODE' '/00', ' ' 'INVFO-BKTXT' v_text,* ' ' 'INVFO-GSBER' 'OV01', ' ' 'INVFO-GSBER' WA_60AUX-GSBER, ' ' 'INVFO-FDTAG' v_data. perform f_shdb60_creditos. endat. at new gsber. sum. if ( v_linhas > 3 ). clear v_linhas. perform f_bdcinsert using: 'X' 'SAPMF05A' '1100', ' ' 'BDC_OKCODE' '=0006', ' ' 'BDC_CURSOR' 'ACGL_ITEM-MARKSP(01)', ' ' 'ACGL_ITEM-MARKSP(01)' c_mark. perform f_bdcinsert using: 'X' 'SAPMF05A' '1100', ' ' 'BDC_OKCODE' '/00'. endif. v_linhas = v_linhas + 1. if ( wa_shdb60-vlpgto < 0 ). wa_shdb60-vlpgto = wa_shdb60-vlpgto * -1. v_item_shkzg = 'H'. else. v_item_shkzg = 'S'. endif. write wa_shdb60-vlpgto to v_valor.* S gera se tiver o nro da conta contbil if not wa_shdb60-hkont is initial. concatenate 'ACGL_ITEM-HKONT(' v_linhas ')' into v_campo. perform f_bdcinsert using ' ' v_campo wa_shdb60-hkont. concatenate 'ACGL_ITEM-SHKZG(' v_linhas ')' into v_campo. perform f_bdcinsert using ' ' v_campo v_item_shkzg. concatenate 'ACGL_ITEM-WRBTR(' v_linhas ')' into v_campo. perform f_bdcinsert using ' ' v_campo v_valor. concatenate 'ACGL_ITEM-ZUONR(' v_linhas ')' into v_campo. perform f_bdcinsert using ' ' v_campo wa_60aux-nfnum. concatenate 'ACGL_ITEM-SGTXT(' v_linhas ')' into v_campo. perform f_bdcinsert using ' ' v_campo v_text2. concatenate 'ACGL_ITEM-GSBER(' v_linhas ')' into v_campo. perform f_bdcinsert using ' ' v_campo wa_shdb60-gsber. endif. endat. if ( v_linhas > 3 ). clear v_linhas. perform f_bdcinsert using: 'X' 'SAPMF05A' '1100', ' ' 'BDC_OKCODE' '=0006', ' ' 'BDC_CURSOR' 'ACGL_ITEM-MARKSP(01)', ' ' 'ACGL_ITEM-MARKSP(01)' c_mark. perform f_bdcinsert using: 'X' 'SAPMF05A' '1100', ' ' 'BDC_OKCODE' '/00'. endif. endloop. perform f_bdcinsert using: 'X' 'SAPMF05A' '1100', ' ' 'BDC_OKCODE' '=BU'. if ( p_mode is initial ). p_mode = 'N'. endif. call transaction 'FB60' using t_bdcdata mode p_mode update 'S' messages into t_messtab. if ( sy-subrc ne 0 ). perform f_busca_mensagem using ' ' changing v_msg. message i999(zarm) with v_msg(50) v_msg+50(50) v_msg+100(50). else. v_numdoc = sy-msgv1. perform f_busca_mensagem using 'S' changing v_msg. refresh: t_bdcdata, t_messtab. data: lc_fim(01).* Verifica se no grid existem soh os lantos de resciso 1/3 e 1/12 loop at t_shdb into wa_shdb. if wa_shdb-belnr = '9999999999'. lc_fim = 'X'. else. lc_fim = ' '. endif. endloop.*> Fazer agora a PA do pagamento acima. if lc_fim is initial. loop at t_shdb into wa_shdb. wa_shdbaux = wa_shdb. at first. v_abpos = 1. clear: v_first, v_comando. write sy-datum to v_data ddmmyy. if ( zfitcom003-resctr eq c_mark ). v_resctr_txt = 'Resciso'. else. v_resctr_txt = 'Clculo'. endif. concatenate v_resctr_txt 'rp:' wa_shdbaux-vkbur into v_text separated by space. concatenate v_resctr_txt wa_shdbaux-pagnr 'representante' wa_shdbaux-vkbur into v_text2 separated by space. perform f_bdcinsert using: 'X' 'SAPMF05A' '0122', ' ' 'BDC_OKCODE' '=SL', ' ' 'BKPF-BLDAT' v_data, ' ' 'BKPF-BLART' 'AB', ' ' 'BKPF-BUKRS' P_BUKRS, ' ' 'BKPF-WAERS' 'BRL', ' ' 'BKPF-XBLNR' wa_shdbaux-nfnum, ' ' 'BKPF-BKTXT' v_text, ' ' 'RF05A-AUGTX' v_text2, ' ' 'RF05A-XPOS1(04)' c_mark, ' ' 'FS006-DOCID' '*'.* ' ' 'RF05A-NEWBS' '31',* ' ' 'RF05A-NEWKO' wa_shdbaux-lifnr. endat.* S compensa os lanctos normais - resciso no compensa check not wa_shdb-hkont is initial. at new hkont. if ( v_first ne c_mark ). v_first = c_mark. else. perform f_bdcinsert using: 'X' 'SAPDF05X' '3100', ' ' 'BDC_OKCODE' '=SL'. endif. clear v_linhas. v_idx = 1. perform f_bdcinsert using: 'X' 'SAPMF05A' '0710', ' ' 'BDC_OKCODE' '/00', ' ' 'RF05A-AGBUK' P_BUKRS, ' ' 'RF05A-AGKON' wa_shdb-hkont, ' ' 'RF05A-AGKOA' 'S', ' ' 'RF05A-XNOPS' 'X'. if ( wa_shdb-mark eq c_mark ). perform f_bdcinsert using ' ' 'RF05A-XPOS1(18)' c_mark. perform f_bdcinsert using: 'X' 'SAPMF05A' '0608', ' ' 'BDC_OKCODE' '=P+'. perform f_bdcinsert using: 'X' 'SAPMF05A' '0608', ' ' 'BDC_OKCODE' '=ENTR', ' ' 'RF05A-XPOS1(06)' c_mark. else. perform f_bdcinsert using ' ' 'RF05A-XPOS1(03)' c_mark. endif. endat.*> Informa partidas na seleo de PA if ( v_linhas eq 8 ) or ( v_linhas is initial ). perform f_bdcinsert using: 'X' 'SAPMF05A' '0731', ' ' 'BDC_OKCODE' '/00'. clear v_linhas. endif. v_linhas = v_linhas + 1. concatenate 'RF05A-SEL01(' v_linhas ')' into v_campo. if ( wa_shdb-mark ne c_mark ). perform f_bdcinsert using ' ' v_campo wa_shdb-belnr. else. perform f_bdcinsert using ' ' v_campo wa_shdb-zuonr. endif.*> Grava linha do lanamento de partida parcial - processamento PA if ( wa_shdb-mark ne c_mark ). if ( v_idx eq 1 ). perform f_bdcaux using: 'X' 'SAPDF05X' '3100', ' ' 'BDC_OKCODE' '/00'. endif. concatenate 'DF05B-PSZAH(' v_idx ')' into v_campo. write wa_shdb-vlpgto to v_valor. perform f_bdcaux using ' ' v_campo v_valor. v_idx = v_idx + 1. if ( v_idx gt 4 ). v_abpos = v_abpos + 4. if ( v_abpos le v_totlin ). perform f_bdcaux using ' ' 'RF05A-ABPOS' v_abpos. endif. v_idx = 1. endif. endif. at end of hkont. perform f_bdcinsert using: 'X' 'SAPMF05A' '0731', ' ' 'BDC_OKCODE' '=PA'. endat. at end of mark. if ( v_comando is initial ). v_comando = c_mark. perform f_bdcinsert using: 'X' 'SAPDF05X' '3100', ' ' 'BDC_OKCODE' '=DKO', ' ' 'RF05A-ABPOS' '1'. perform f_bdcinsert using: 'X' 'SAPDF05X' '3100', ' ' 'BDC_OKCODE' '/00', ' ' 'RF05A-PSCOM(01)' '+*'. endif.*> Informa valor das partidas com pagamento parcial if ( not t_bdcaux[] is initial ). perform f_bdcinsert using: 'X' 'SAPDF05X' '3100', ' ' 'BDC_OKCODE' '=PART', ' ' 'RF05A-ABPOS' '1'. append lines of t_bdcaux to t_bdcdata. endif. endat. endloop. endif.*> Seleciona as PAs dos pagamentos envolvidos. clear wa_shdb-mark. modify t_shdb from wa_shdb transporting mark where ( mark eq c_mark ). sort t_shdb by mark hkont. clear v_first. if lc_fim is initial. perform f_bdcinsert using: 'X' 'SAPDF05X' '3100', ' ' 'BDC_OKCODE' '=SL'. loop at t_shdb into wa_shdb.* Se no tiver a conta contbil no gera check not wa_shdb-hkont is initial. at new hkont. if ( v_first is initial ). v_first = c_mark. else. perform f_bdcinsert using ' ' 'BDC_OKCODE' '=SLK'. endif. perform f_bdcinsert using: 'X' 'SAPMF05A' '0710', ' ' 'BDC_OKCODE' '/00', ' ' 'RF05A-AGBUK' P_BUKRS, ' ' 'RF05A-AGKON' wa_shdb-hkont, ' ' 'RF05A-AGKOA' 'S', ' ' 'RF05A-XNOPS' 'X', ' ' 'RF05A-XPOS1(03)' c_mark. perform f_bdcinsert using: 'X' 'SAPMF05A' '0731', ' ' 'RF05A-SEL01(01)' v_numdoc. endat. at last. perform f_bdcinsert using ' ' 'BDC_OKCODE' '=PA'. endat. endloop. if ( not t_shdb[] is initial ). perform f_bdcinsert using: 'X' 'SAPDF05X' '3100', ' ' 'BDC_OKCODE' '/00'.* ' ' 'RF05A-PSCOM(01)' '+*'. perform f_bdcinsert using: 'X' 'SAPDF05X' '3100', ' ' 'BDC_OKCODE' '=BU'. if ( p_mode is initial ). p_mode = 'N'. endif. call transaction 'FB05' using t_bdcdata mode p_mode update 'S' messages into t_messtab. else. clear: sy-subrc, sy-msgv1. endif. if ( sy-subrc eq 0 ). v_totproc = v_totproc + 1. v_compdc = sy-msgv1. perform f_busca_mensagem using 'S' changing v_msg. zfitcom003-uspgt = sy-uname. zfitcom003-dtpgt = sy-datum. zfitcom003-hrpgt = sy-uzeit. zfitcom003-status = '3'. zfitcom003-numdoc = v_numdoc. zfitcom003-compdc = v_compdc. modify t_zfitcom003 from zfitcom003 transporting uspgt dtpgt hrpgt status numdoc compdc where ( pagnr eq zfitcom003-pagnr ).* Atualizar no banco update zfitcom003 from table t_zfitcom003. commit work. if ( zfitcom003-resctr ne c_mark ). select * from zfitcom006 into table t_finan for all entries in t_tvbur where ( vkbur eq t_tvbur-vkbur ) and ( stafin ne 'C' ) and ( stafin ne 'P' ). loop at t_finan into wa_finan. call function 'Z_FI_CALC_ADIANTAMENTOS' EXPORTING numfin = wa_finan-numfin pagamento = 'X' EXCEPTIONS adiantamento_not_found = 1 parametros_null = 2 others = 3. endloop. endif. else. perform f_busca_mensagem using ' ' changing v_msg. message i999(zarm) with v_msg(50) v_msg+50(50) v_msg+100(50). refresh: t_bdcdata, t_messtab. perform f_bdcinsert using: 'X' 'SAPMF05A' '0105', ' ' 'BDC_OKCODE' '=BU', ' ' 'RF05A-BELNS' v_numdoc, ' ' 'RF05A-GJAHS' sy-datum(4), ' ' 'UF05A-STGRD' '02'. if ( p_mode is initial ). p_mode = 'N'. endif. call transaction 'FB08' using t_bdcdata mode p_mode update 'S' messages into t_messtab. if ( sy-subrc ne 0 ). perform f_busca_mensagem using ' ' changing v_msg. message i999(zarm) with v_msg(50) v_msg+50(50) v_msg+100(50). endif. endif. else. v_totproc = v_totproc + 1. v_compdc = sy-msgv1. perform f_busca_mensagem using 'S' changing v_msg. zfitcom003-uspgt = sy-uname. zfitcom003-dtpgt = sy-datum. zfitcom003-hrpgt = sy-uzeit. zfitcom003-status = '3'. zfitcom003-numdoc = v_numdoc. zfitcom003-compdc = v_compdc. modify t_zfitcom003 from zfitcom003 transporting uspgt dtpgt hrpgt status numdoc compdc where ( pagnr eq zfitcom003-pagnr ).* Atualizar no banco update zfitcom003 from table t_zfitcom003. commit work. endif. endif.endform. " f_grava_batch_input*&---------------------------------------------------------------------**& Form f_shdb60_creditos*&---------------------------------------------------------------------**& Grava BI dos descontos concedidos, perdas ou proviso de PDD*&---------------------------------------------------------------------**&form f_shdb60_creditos. delete t_item where ( shkzg eq 'S' ). sort t_item by pagnr belnr buzei. clear v_linhas. loop at t_item into wa_item. wa_itemaux = wa_item. at new belnr. sum. if ( wa_item-vlperd gt 0 ). write wa_item-vlperd to v_valor. v_text = text-b01. perform f_bi_creditos. endif. if ( wa_item-vlpdd gt 0 ). write wa_item-vlpdd to v_valor. v_text = text-b02. perform f_bi_creditos. endif. if ( wa_item-vldesc gt 0 ). write wa_item-vldesc to v_valor. v_text = text-b03. perform f_bi_creditos. endif. endat.*> Correo para pagto de resciso*> begin GMS - SPEC - 21.09.2004 if ( wa_item-blart eq '12' ). write wa_item-vlpgto to v_valor. v_text = text-b04. perform f_bi_creditos. endif. if ( wa_item-blart eq '03' ). write wa_item-vlpgto to v_valor. v_text = text-b05. perform f_bi_creditos. endif.*> end GMS - SPEC - 21.09.2004 endloop.endform. " f_shdb60_creditos*&---------------------------------------------------------------------**& Form f_bi_creditos*&---------------------------------------------------------------------*form f_bi_creditos. data: v_hkont like zfitcom004-hkont, v_shkzg like bsis-shkzg. if ( v_linhas eq 4 ). clear v_linhas. perform f_bdcinsert using: 'X' 'SAPMF05A' '1100', ' ' 'BDC_OKCODE' '=0006', ' ' 'BDC_CURSOR' 'ACGL_ITEM-MARKSP(01)', ' ' 'ACGL_ITEM-MARKSP(01)' c_mark. perform f_bdcinsert using: 'X' 'SAPMF05A' '1100', ' ' 'BDC_OKCODE' '/00'. endif. do 1 times. v_hkont = '4302005'. if ( '1203' cs wa_item-blart ). v_shkzg = 'S'. else. v_shkzg = 'H'. endif.*Em 02/09/2004 - alteramos para no lanar a contrapartida da conta.* pois esta j conta sumarizada no total (2104009/2104010)* Pendncia 1035* else.* v_hkont = wa_itemaux-hkont.* endif. v_linhas = v_linhas + 1. concatenate 'ACGL_ITEM-HKONT(' v_linhas ')' into v_campo. perform f_bdcinsert using ' ' v_campo v_hkont. concatenate 'ACGL_ITEM-SHKZG(' v_linhas ')' into v_campo. perform f_bdcinsert using ' ' v_campo v_shkzg. concatenate 'ACGL_ITEM-WRBTR(' v_linhas ')' into v_campo. perform f_bdcinsert using ' ' v_campo v_valor. concatenate 'ACGL_ITEM-ZUONR(' v_linhas ')' into v_campo. perform f_bdcinsert using ' ' v_campo wa_itemaux-zuonr. concatenate 'ACGL_ITEM-SGTXT(' v_linhas ')' into v_campo. perform f_bdcinsert using ' ' v_campo v_text. concatenate 'ACGL_ITEM-GSBER(' v_linhas ')' into v_campo. perform f_bdcinsert using ' ' v_campo wa_itemaux-gsber. enddo.endform. " f_bi_creditos*&---------------------------------------------------------------------**& Form f_shdb_descontos*&---------------------------------------------------------------------**& Grava BI dos descontos concedidos, perdas ou proviso de PDD*&---------------------------------------------------------------------**&form f_shdb_descontos. data: v_totdesc like zfitcom004-vldesc, v_perdas like zfitcom004-vlperd. delete t_item where ( shkzg eq 'S' ). sort t_item by pagnr belnr buzei. refresh: t_bdcaux, t_bdcaux2. clear v_totdesc. loop at t_item into wa_item. wa_itemaux = wa_item. at new belnr. sum. clear v_perdas. if ( wa_item-vlperd gt 0 ). write wa_item-vlperd to v_valor. v_text = text-b01. v_perdas = v_perdas + wa_item-vlperd. perform f_bi_descontos. endif. if ( wa_item-vlpdd gt 0 ). write wa_item-vlpdd to v_valor. v_text = text-b02. v_perdas = v_perdas + wa_item-vlpdd. perform f_bi_descontos. endif. if ( wa_item-vldesc gt 0 ). write wa_item-vldesc to v_valor. v_text = text-b03. v_perdas = v_perdas + wa_item-vldesc. perform f_bi_descontos. endif. endat. if ( wa_item-blart eq '12' ). write wa_item-vlpgto to v_valor. v_text = text-b04. perform f_bi_descontos. endif. if ( wa_item-blart eq '03' ). write wa_item-vlpgto to v_valor. v_text = text-b05. perform f_bi_descontos. endif. endloop. v_text = 'Pagamento de comisses'. write wa_shdbaux-totalnf to v_valor. perform f_bdcinsert using: 'X' 'SAPMF05A' '0302', ' ' 'BSEG-WRBTR' v_valor, ' ' 'BSEG-GSBER' 'OV01', ' ' 'BSEG-SGTXT' v_text. if ( t_bdcaux[] is initial ). perform f_bdcinsert using ' ' 'BDC_OKCODE' '=SL'. else. perform f_bdcinsert using ' ' 'BDC_OKCODE' '/00'. append lines of t_bdcaux2 to t_bdcaux. append lines of t_bdcaux to t_bdcdata. refresh t_bdcaux. perform f_bdcinsert using: 'X' 'SAPMF05A' '0300', ' ' 'BDC_OKCODE' '=SL'. append lines of t_bdcaux2 to t_bdcdata. refresh t_bdcaux2. endif.endform. " f_shdb_descontos*&---------------------------------------------------------------------**& Form f_bi_descontos*&---------------------------------------------------------------------*form f_bi_descontos. if ( '1203' cs wa_item-blart ). perform f_bdcaux using: ' ' 'RF05A-NEWBS' '40', ' ' 'RF05A-NEWKO' '4302005'. else. perform f_bdcaux using: ' ' 'RF05A-NEWBS' '50', ' ' 'RF05A-NEWKO' '4302005'. endif. append lines of t_bdcaux2 to t_bdcaux. refresh t_bdcaux2. perform f_bdcaux using: 'X' 'SAPMF05A' '0300', ' ' 'BDC_OKCODE' '/00', ' ' 'BSEG-WRBTR' v_valor, ' ' 'BSEG-SGTXT' v_text, ' ' 'BSEG-ZUONR' wa_itemaux-zuonr. perform f_bdcaux2 using: 'X' 'SAPLKACB' '0002', ' ' 'BDC_OKCODE' '=ENTE', ' ' 'COBL-GSBER' wa_itemaux-gsber.endform. " f_bi_descontos*&---------------------------------------------------------------------**& Form f_gera_estorno*&---------------------------------------------------------------------**& Rotina que executa estorno da compensao do pagamento*&---------------------------------------------------------------------**&form f_gera_estorno. data: v_vlsald like zfitcom004-vlsald, v_belnr like bsik-belnr, v_return like sy-subrc. describe table t_zfitcom003 lines v_totpgt. clear v_totproc. loop at t_zfitcom003 into zfitcom003.* clear v_vlsald.* t_itemaux[] = t_zfitcom004[].* delete t_itemaux where ( pagnr ne zfitcom003-pagnr ).* perform f_saldo_por_atribuicao tables t_itemaux t_item.** sort t_item by pagnr.* loop at t_item into wa_item.* at first.* sum.* exit.* endat.* endloop.** if ( wa_item-vlsald eq 0 ). "Estorno de pagamento total read table t_lfa1 into wa_lfa1 with key vkbur = zfitcom003-vkbur binary search. if ( sy-subrc ne 0 ). clear wa_lfa1. endif. select belnr from bsik into v_belnr where ( lifnr eq wa_lfa1-lifnr ) and ( bukrs eq 'COVL' ) and ( gjahr eq zfitcom003-dtpgt(04) ) and ( belnr eq zfitcom003-numdoc ). endselect. if ( sy-subrc ne 0 ). message i999(zarm) with 'Pagamento' zfitcom003-numdoc 'j foi realizado!'. continue. endif. refresh: t_bdcdata, t_messtab. perform f_bdcinsert using: 'X' 'SAPMF05R' '0100', ' ' 'BDC_OKCODE' '=RAGL', ' ' 'RF05R-AUGBL' zfitcom003-compdc, ' ' 'RF05R-BUKRS' 'COVL', ' ' 'RF05R-GJAHR' zfitcom003-dtpgt(4). if ( p_mode is initial ). p_mode = 'N'. endif. call transaction 'FBRA' using t_bdcdata mode p_mode update 'S' messages into t_messtab. v_return = sy-subrc. if ( sy-subrc ne 0 ). perform f_busca_mensagem using ' ' changing v_msg. message i999(zarm) with v_msg(50) v_msg+50(50) v_msg+100(50). endif.* else.* v_return = 0.* endif.**> Extorna o lanamento de compensao check ( v_return eq 0 ). refresh: t_bdcdata, t_messtab. perform f_bdcinsert using: 'X' 'SAPMF05A' '0105', ' ' 'BDC_OKCODE' '=BU', ' ' 'RF05A-BELNS' zfitcom003-compdc, ' ' 'RF05A-GJAHS' zfitcom003-dtpgt(4), ' ' 'UF05A-STGRD' '02'. if ( p_mode is initial ). p_mode = 'N'. endif. call transaction 'FB08' using t_bdcdata mode p_mode update 'S' messages into t_messtab. v_return = sy-subrc. if ( sy-subrc ne 0 ). perform f_busca_mensagem using ' ' changing v_msg. message i999(zarm) with v_msg(50) v_msg+50(50) v_msg+100(50). endif.*> Extorna o lanamento de pagamento check ( v_return eq 0 ). refresh: t_bdcdata, t_messtab. perform f_bdcinsert using: 'X' 'SAPMF05A' '0105', ' ' 'BDC_OKCODE' '=BU', ' ' 'RF05A-BELNS' zfitcom003-numdoc, ' ' 'RF05A-GJAHS' zfitcom003-dtpgt(4), ' ' 'UF05A-STGRD' '02'. if ( p_mode is initial ). p_mode = 'N'. endif. call transaction 'FB08' using t_bdcdata mode p_mode update 'S' messages into t_messtab. if ( sy-subrc eq 0 ). v_numdoc = sy-msgv1. perform f_busca_mensagem using 'S' changing v_msg. clear: zfitcom003-uspgt, zfitcom003-dtpgt, zfitcom003-hrpgt, zfitcom003-numdoc, zfitcom003-compdc. zfitcom003-status = '2'. zfitcom003-numcan = v_numdoc. modify t_zfitcom003 from zfitcom003 transporting uspgt dtpgt hrpgt status numcan numdoc compdc where ( pagnr eq zfitcom003-pagnr ). else. perform f_busca_mensagem using ' ' changing v_msg. endif. message i999(zarm) with v_msg(50) v_msg+50(50) v_msg+100(50). endloop.endform. " f_gera_estorno*&---------------------------------------------------------------------**& Form f_elimina_pagamento*&---------------------------------------------------------------------**& Elimina pagamentos da tela*&---------------------------------------------------------------------**&form f_elimina_pagamento. loop at t_zfitcom003 into zfitcom003. zfitcom003-status = '4'. zfitcom003-uscan = sy-uname. zfitcom003-dtcan = sy-datum. zfitcom003-hrcan = sy-uzeit. modify t_zfitcom003 from zfitcom003 transporting uscan dtcan hrcan status where ( pagnr eq zfitcom003-pagnr ). endloop.endform. " f_elimina_pagamento*&---------------------------------------------------------------------**& Form f_bdcinsert*&---------------------------------------------------------------------**& Processa batch-input*&---------------------------------------------------------------------**&form f_bdcinsert using value(p_dynbegin) value(p_program) value(p_dynpro). clear wa_bdcdata. if ( p_dynbegin eq c_mark ). wa_bdcdata-program = p_program. wa_bdcdata-dynpro = p_dynpro. wa_bdcdata-dynbegin = p_dynbegin. else. wa_bdcdata-fnam = p_program. wa_bdcdata-fval = p_dynpro. endif. append wa_bdcdata to t_bdcdata.endform. " f_bdcinsert*&---------------------------------------------------------------------**& Form f_bdcaux*&---------------------------------------------------------------------**& Processa batch-input*&---------------------------------------------------------------------**&form f_bdcaux using value(p_dynbegin) value(p_program) value(p_dynpro). clear wa_bdcaux. if ( p_dynbegin eq c_mark ). wa_bdcaux-program = p_program. wa_bdcaux-dynpro = p_dynpro. wa_bdcaux-dynbegin = p_dynbegin. else. wa_bdcaux-fnam = p_program. wa_bdcaux-fval = p_dynpro. endif. append wa_bdcaux to t_bdcaux.endform. " f_bdcinsert*&---------------------------------------------------------------------**& Form f_bdcaux2*&---------------------------------------------------------------------**& Processa batch-input*&---------------------------------------------------------------------**&form f_bdcaux2 using value(p_dynbegin) value(p_program) value(p_dynpro). clear wa_bdcaux. if ( p_dynbegin eq c_mark ). wa_bdcaux-program = p_program. wa_bdcaux-dynpro = p_dynpro. wa_bdcaux-dynbegin = p_dynbegin. else. wa_bdcaux-fnam = p_program. wa_bdcaux-fval = p_dynpro. endif. append wa_bdcaux to t_bdcaux2.endform. " f_bdcaux2*&---------------------------------------------------------------------**& Form f_busca_mensagem*&---------------------------------------------------------------------**& Retorna mensagem da execuo do BI*&---------------------------------------------------------------------**&form f_busca_mensagem using value(p_msgtyp) changing p_text. loop at t_messtab into wa_messtab. check ( p_msgtyp is initial and 'WIASE' cs wa_messtab-msgtyp ) or ( wa_messtab-msgtyp eq p_msgtyp ). sy-msgv1 = wa_messtab-msgv1. sy-msgv2 = wa_messtab-msgv2. sy-msgv3 = wa_messtab-msgv3. sy-msgv4 = wa_messtab-msgv4. sy-msgno = wa_messtab-msgnr. call function 'CUTC_GET_MESSAGE' EXPORTING msg_type = wa_messtab-msgtyp msg_id = wa_messtab-msgid msg_no = sy-msgno msg_arg1 = sy-msgv1 msg_arg2 = sy-msgv2 msg_arg3 = sy-msgv3 msg_arg4 = sy-msgv4 IMPORTING raw_message = p_text EXCEPTIONS msg_not_found = 1 internal_error = 2 others = 3. if ( wa_messtab-msgtyp eq 'E' ). exit. endif. endloop.endform. " f_busca_mensagem*&---------------------------------------------------------------------**& Form f_limpa_variaveis*&---------------------------------------------------------------------**& Rotina de limpeza de variaveis.*&---------------------------------------------------------------------**&form f_limpa_variaveis. clear : v_rescisao, v_lines, v_mark, v_copied, v_cop400, v_indice, v_oldind, v_indatu, v_totvend, v_answer, v_confirm, v_tabix, v_dynnr, v_linsz, ok_code, v_wrbtr, v_vlcorr, v_vlreal, v_vlpgto, v_vldesc, v_vlperd, v_vlsald, v_imposto, v_pagnr, v_comissao, v_nroitem, v_numdoc, v_nroite, v_totbase12. refresh : t_bsis, t_bsad, t_valida, t_parametros, t_vbrk, t_compdoc, t_descontos, t_zfitcom003, t_zfitcom004, t_base12, t_antigos, t_novos, t_kna1, t_indices, t_lfbw.endform. " f_limpa_variaveis*&---------------------------------------------------------------------**& Form f_saldo_por_atribuicao*&---------------------------------------------------------------------*form f_saldo_por_atribuicao tables t_entrada structure wa_item t_saida structure wa_item. data: wa_saida like wa_item, wa_entrada like wa_item, v_reduz_pgto like wa_item-vlpgto. refresh t_saida. wa_entrada-zuonr = '9999999999'. case p_bukrs. when 'COVL'. wa_entrada-gsber = 'OV01'. when 'CPPL'. wa_entrada-gsber = 'CP01'. endcase. modify t_entrada from wa_entrada transporting zuonr gsber where ( belnr eq '9999999999' ). sort t_entrada by pagnr zuonr belnr buzei. clear: wa_saida, sy-subrc. loop at t_entrada into wa_entrada. on change of wa_entrada-zuonr. if ( not wa_saida-zuonr is initial ). wa_saida-vlsald = wa_saida-wrbtr - wa_saida-vlreal - wa_saida-vlpgto - wa_saida-vlperd - wa_saida-vldesc - wa_saida-vlpdd.** No calcular saldo na resciso* IF V_RESCISAO = '2'.* CLEAR WA_SAIDA-VLSALD.* ENDIF. if ( wa_saida-vlsald lt 0 ). clear wa_saida-vlsald. endif. append wa_saida to t_saida. endif. wa_saida = wa_entrada. clear: wa_saida-vlpgto, wa_saida-vlperd, wa_saida-vldesc, wa_saida-vlpdd, v_reduz_pgto. endon. wa_saida-vlreal = wa_entrada-vlreal - v_reduz_pgto. wa_saida-vlpgto = wa_saida-vlpgto + wa_entrada-vlpgto. v_reduz_pgto = wa_entrada-vlpgto. wa_saida-vlperd = wa_saida-vlperd + wa_entrada-vlperd. wa_saida-vldesc = wa_saida-vldesc + wa_entrada-vldesc. wa_saida-vlpdd = wa_saida-vlpdd + wa_entrada-vlpdd. endloop. wa_saida-vlsald = wa_saida-wrbtr - wa_saida-vlreal - wa_saida-vlpgto - wa_saida-vlperd - wa_saida-vldesc - wa_saida-vlpdd.** No calcular saldo na resciso* IF V_RESCISAO = '2'.* CLEAR WA_SAIDA-VLSALD.* ENDIF. if ( wa_saida-vlsald lt 0 ). clear wa_saida-vlsald. endif. append wa_saida to t_saida.endform. " f_saldo_por_atribuicao*&---------------------------------------------------------------------**& Form f_valida_vkbur*&---------------------------------------------------------------------*form f_valida_vkbur. refresh: t_tvbur, t_lfa1, t_tverr. if ( not t_zfitcom003[] is initial ). loop at t_zfitcom003 into zfitcom003. wa_tvbur-vkbur = zfitcom003-vkbur. append wa_tvbur to t_tvbur. endloop. else. select * from tvbur into table t_tvbur where ( vkbur in s_vkbur ). endif. call function 'Z_FI_GET_NAME1_FROM_VKBUR' EXPORTING i_bukrs = p_bukrs TABLES tvbur = t_tvbur fornec = t_lfa1. sort t_lfa1 by vkbur. loop at t_tvbur into wa_tvbur. read table t_lfa1 into wa_lfa1 with key vkbur = wa_tvbur-vkbur binary search. check ( sy-subrc ne 0 ). delete t_tvbur. append wa_tvbur to t_tverr. endloop. t_tvbur1[] = t_tvbur[]. t_auxlfa1[] = t_lfa1[].endform. " f_valida_vkbur*&---------------------------------------------------------------------**& Form f_menu_pagamentos*&---------------------------------------------------------------------*form f_menu_pagamentos using value(p_tipo) value(p_text). if ( p_excjob ne c_mark ). p_quinz = p_data. p_code100 = code100. p_newcom = p_novcom. p_concom = p_ctocom. p_rescisao = v_rescisao. p_background = p_excjob. endif. perform f_selecao_pagamentos using p_tipo. if ( t_zfitcom003[] is initial ). message w999(zarm) with p_text. else. if ( not t_tverr[] is initial ). call screen '0500' starting at 20 5. endif. if ( t_tvbur[] is initial ). message w999(zarm) with text-m30. else. call screen '0200'. endif. endif.endform. " f_menu_pagamentos*&---------------------------------------------------------------------**& Form f_grava_lfbw*&---------------------------------------------------------------------** Altera o imposto IR do fornecedor, quando se tratar de pagto* de resciso nos lanamentos (1/3) e (1/12)*----------------------------------------------------------------------*form f_grava_lfbw using value(p_ope). data: v_tabix(2) type n, v_field(30) type c. if ( zfitcom003-resctr eq c_mark ) and ( v_chg_lfbw eq c_mark ). sort t_lfbw_old by lifnr bukrs witht. read table t_lfbw_old into lfbw with key witht = 'IR'. if ( sy-subrc eq 0 ). v_tabix = sy-tabix. if ( p_ope eq 1 ). read table t_lfbw into wa_lfbw with key vkbur = zfitcom003-vkbur lifnr = wa_lfa1-lifnr nroseq = zfitcom003-nroseq witht = 'IR'. else. read table t_lfbw_old into lfbw with key witht = 'IR'. wa_lfbw-wt_withcd = lfbw-wt_withcd. endif. if ( sy-subrc eq 0 ). refresh: t_bdcdata, t_messtab. perform f_bdcinsert using: 'X' 'SAPMF02K' '0101', ' ' 'BDC_CURSOR' 'RF02K-D0610', ' ' 'BDC_OKCODE' '/00', ' ' 'RF02K-LIFNR' wa_lfa1-lifnr, ' ' 'RF02K-BUKRS' v_bukrs, ' ' 'RF02K-D0610' c_mark. concatenate 'LFBW-WT_WITHCD(' v_tabix ')' into v_field. perform f_bdcinsert using: 'X' 'SAPMF02K' '0610', ' ' 'BDC_OKCODE' '=UPDA', ' ' v_field wa_lfbw-wt_withcd. if ( p_mode is initial ). p_mode = 'N'. endif. call transaction 'XK02' using t_bdcdata mode p_mode update 'S' messages into t_messtab. if sy-subrc ne 0. perform f_busca_mensagem using ' ' changing v_msg. message i999(zarm) with v_msg(50) v_msg+50(50) v_msg+100(50). endif. commit work. endif. endif. endif.endform. " f_grava_lfbw*&---------------------------------------------------------------------**& Form mudar_empresa_do_buffer*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text*