Sie sind auf Seite 1von 9

Identification Division.

Program-id. manunfe.
Author. Vanderlei Roberto Marques.
Security. * le TAGS arquivos XML - NFE EM COBOL MF MS 5.0 *.
*
Environment division.
Configuration section.
Special-names.
decimal-point is comma.
Input-output Section.
File-control.
Select impres assign to disk
organization is line sequential
access mode is sequential
file status is imp-status
lock mode is automatic with lock on record.

*
Data Division.
File Section.
Fd impres
Label Record is Standart
Value of file-id is ws-nome-txt.
01 Rg-impres.
05 linha PIC x(3000).
05 ws-letra-xml redefines linha pic x(001) occurs 3000.

Working-Storage Section.
01 Area-de-status.
05 imp-status pic x(002) value "xx".
77 Ws-tamanho
pic x(004) comp-5 value 60.
77 CONT-COL PIC 9(05) VALUE ZEROS.
77 CONT-01 PIC 9(05) VALUE ZEROS.
77 CONT-02 PIC 9(05) VALUE ZEROS.
77 TOTAL-ST PIC 9(05) VALUE ZEROS.
01 area-de-dados.
02 ws-nome-txt.
03 ws-nro-nota pic x(008) value spaces.
03 filler pic x(001) value ".".
03 ws-tipo-arquivo pic x(003) value spaces.
02 wtamanho pic 9(003) value zeros.
02 ACUTOT PIC 9(08)V99 VALUE ZEROS.
02 TOTVAL-DPX PIC X(13).
02 TOTVAL-DP PIC ZZZZZZZZZ9.99.
02 reglin2 pic x(015).
01 Area-de-trabalhos.
05 zz-nro-lote pic zzzzzzzzz value zeros.
05 zz-nro redefines zz-nro-lote pic 9(001) occurs 9.
05 zz-nro-processo pic xxxxxxxxxxxxxxx value zeros.
05 zz-nro-pro redefines zz-nro-processo pic 9(001) occurs 15.
05 filler redefines zz-nro-processo.
10 filler pic x(007).
10 zz-nro-final-proc pic x(008).
05 ws-valor-nulo pic x(001) value x"20".
05 ws-ok pic x(001) value spaces.
05 ws-nome-arquivo pic x(30) value spaces.
05 ws-nome-tag pic x(100) value spaces.
05 ws-letra-tag redefines ws-nome-tag pic x(01) occurs 100.
05 ws-valor-tag pic x(3000) value spaces.
05 ws-letra-vlr-tag redefines
ws-valor-tag pic x(01) occurs 3000.
05 ws-ind pic 9(004) value zeros.
05 ws-ind-tag pic 9(004) value zeros.
05 ws-ind-nro pic 9(004) value zeros.
05 ws-ind2 pic 9(004) value zeros.
05 ws-tecla pic x(002) value "00".
88 tecla-esc value "01".
88 F2 value "03".
05 ws-nome-a-mudar pic 9(008) value zeros.
05 ws-flag pic x(001) value "S".
05 ws-espera-nfe pic 9(002) value 5.
copy chamadas.bok.

Linkage Section.
Copy Usuario.bok.
01 dados-nfe.
05 lnk-nro-nota pic 9(008).
05 lnk-nro-lote pic 9(08) value zeros.
05 lnk-nro-chave-nfe pic x(44) value spaces.
05 lnk-nro-protocolo pic x(015) value spaces.
05 lnk-status pic x(003) value spaces.
05 lnk-motivo pic x(050) value spaces.
Screen Section.
copy nfe-mens.ss.
Procedure Division using area-de-usuarios dados-nfe.
0000-inicio.
Display (25, 01)
"Aguardando o retorno da NFE da RECEITA ESTADUAL..."
with back 4 fore 15 blank line.

Perform 7100-salva-tela thru 7100-exit.
Accept (25, 79) ws-ok with timeout after 20 back 4 fore 4.
Display (25, 01)
"Aguardando o retorno da NFE da RECEITA ESTADUAL..."
with back 4 fore 15 blank line.
move "lot" to ws-tipo-arquivo.
* Accept (25, 01) lnk-nro-nota with back 4 fore 15.
move lnk-nro-nota to ws-nro-nota.
*> Pegar numero do lote GERADO PELO UNINFE
******************************************************************
* *> Pegar numero do processo GERADO PELO UNINFE *
* ATRAVEZ DO NRO DA LOTA LOCALIZO O NUM-LOT-XML
* *> EXTENCAO *-NUM-LOT.XML renomeio com *.lot *
* *
******************************************************************
Display (25, 01) "Aguardando retorno de Lote da Nfe...:"
with back 4 fore 15 blank line.
Perform 3100-muda-nome thru 3100-exit.
Perform 1000-abre-arquivos thru 1000-exit.
Perform 2000-le-lote thru 2000-exit.
******************************************************************
* *> Pegar numero do processo ENVIADO PELA RECEITA *
* *> EXTENCAO *-REC.XML renomeio com *.prc *
* LER ESTE ARQUIVO E PEGAR NUMERO DO PROCESSO/RECEITA *
******************************************************************
move lnk-nro-lote to ws-nro-nota.
display (25, 01) lnk-nro-lote with back 0 fore 15
blank line
* accept (25, 00) ws-ok
close impres.
move "S" to ws-flag.
move lnk-nro-lote to ws-nro-nota *> Pegar numero do processo
move "prc" to ws-tipo-arquivo.
Perform 0100-le-arquivos thru 0100-exit.
close impres.
move "N" to ws-flag.
move zz-nro-final-proc to ws-nro-nota *> Pegar dado da nota
******************************************************************
* *> Pegar dados da NOTA FISCAL ELETRONICA *
* *> RENENCAO *-PRO-REC.XML renomeio com *.prc *
* APOS LER O RETORNO DA RECEITA PEGO DADOS DA NOTA *
******************************************************************
move "nfe" to ws-tipo-arquivo.
* display erase.
Perform 0100-le-arquivos thru 0100-exit.
* Display (15, 01) lnk-nro-nota with back 4 fore 15.
* Display (16, 01) lnk-nro-lote with back 4 fore 15.
* Display (17, 01) lnk-nro-chave-nfe with back 4 fore 15.

* Display (18, 01) lnk-nro-protocolo with back 4 fore 15.

* Display (19, 01) lnk-status with back 4 fore 15.
* Display (20, 01) lnk-motivo with back 4 fore 15.
* Display (21, 01) zz-nro-processo with back 4 fore 15.
* Accept (25, 01) ws-ok with back 4 fore 4.
if lnk-status not = 100 and 104
Perform 4105-mensagem thru 4105-exit.
0000-mover-ret-nfe.
close impres.
Perform 3101-move-arq-ret thru 3101-exit.
0000-sair.
close impres.
exit program.
stop run.
0100-le-arquivos.
close impres.
Perform 3100-muda-nome thru 3100-exit.
Perform 1000-abre-arquivos thru 1000-exit.
Perform 4101-le-nro-tags thru 4101-exit.
0100-exit.
exit.
1000-abre-arquivos.
Open input impres.
if imp-status not = "00"
display (23, 09) "Erro na Abertura do RETORNO DA NFE"
WITH BACK 4 FORE 15 BLANK LINE
display (23, 00) imp-status with back 1 fore 15 blink
display (23, 60) ws-nome-txt with back 4 fore 15
accept (25, 00) ws-ok
go to 0000-sair.
1000-exit.
exit.
2000-le-lote.
read impres at end go to 2000-exit.
move zeros to ws-ind ws-ind2.
2000-acha-tag-lote.
add 1 to ws-ind.
if ws-ind > 3000 or
ws-letra-xml(ws-ind) = ws-valor-nulo and
ws-letra-xml(ws-ind + 1) = ws-valor-nulo and
ws-letra-xml(ws-ind + 2) = ws-valor-nulo and
ws-letra-xml(ws-ind + 3) = ws-valor-nulo
go to 2000-le-lote.
if ws-letra-xml(ws-ind) = "<"
move zeros to ws-ind2
Perform 2101-le-tag-lote thru 2101-exit
go to 2000-acha-tag-lote.

go to 2000-le-lote.
2000-exit.
exit.
2101-le-tag-lote.
add 1 to ws-ind.
if ws-letra-xml(ws-ind) = ">" or ws-ind > 2999 or
ws-ind2 > 99
move zeros to ws-ind2
if ws-nome-tag = "NumeroLoteGerado "
Perform 4000-le-nro-lote thru 4000-exit
end-if
move spaces to ws-nome-tag
go to 2101-exit.
add 1 to ws-ind2.
move ws-letra-xml(ws-ind) to ws-letra-tag(ws-ind2).
go to 2101-le-tag-lote.
2101-exit.
exit.
3101-move-arq-ret.
move "move.exe " to ws-parte2.
move " /y *.lot retorno" to ws-parametro
display ws-parametro upon command-line
Call x"91" using ws-resultado ws-numero-funcao ws-comando.
move " /y *.prc retorno" to ws-parametro
display ws-parametro upon command-line
Call x"91" using ws-resultado ws-numero-funcao ws-comando.
move " /y *.nfe retorno" to ws-parametro
display ws-parametro upon command-line
Call x"91" using ws-resultado ws-numero-funcao ws-comando.
move " /y *.txt retorno" to ws-parametro
display ws-parametro upon command-line
Call x"91" using ws-resultado ws-numero-funcao ws-comando.
move " /y *.xml xml" to ws-parametro
display ws-parametro upon command-line
Call x"91" using ws-resultado ws-numero-funcao ws-comando.
3101-exit.
exit.
3100-muda-nome.
move "cmd.exe " to ws-parte2.
string "/c ren " , "*" , ws-nro-nota , "*.xml " ,
ws-nome-txt delimited by size into
ws-parametro
display ws-parametro upon command-line
Call x"91" using ws-resultado ws-numero-funcao ws-comando.
Perform 7200-recupera-tela thru 7200-exit.
Open input impres.
if imp-status not = "00"
go to 3100-muda-nome.
close impres.
3100-exit.
exit.
4000-le-nro-lote.
add 1 to ws-ind ws-ind2.
if ws-letra-xml(ws-ind) = "<"
Perform 4001-posiciona-nro thru 4001-exit
subtract 1 from ws-ind
go to 4000-exit.
move ws-letra-xml(ws-ind) to zz-nro(ws-ind2).
go to 4000-le-nro-lote.
4000-exit.
exit.
4001-posiciona-nro. *> parei em ler o conteudo do lote
if ws-ind2 >= 2
subtract 2 from ws-ind2
else
move 1 to ws-ind2.
compute ws-ind2 = 9 - ws-ind2.
move zeros to ws-ind-nro.
4001-move.
add 1 to ws-ind-nro.
move zz-nro(ws-ind-nro) to zz-nro(ws-ind2).
move zeros to zz-nro(ws-ind-nro).
add 1 to ws-ind2.
if ws-ind2 > 9
move zz-nro-lote to lnk-nro-lote
go to 4001-exit.
go to 4001-move.
4001-exit.
exit.
4100-le-processo.
add 1 to ws-ind.
if ws-letra-xml(ws-ind) = "<"
go to 4100-exit.
add 1 to ws-ind2.
move ws-letra-xml(ws-ind) to zz-nro-pro(ws-ind2).
go to 4100-le-processo.
4100-exit.
exit.
4101-le-nro-tags.
read impres at end go to 4101-exit.
move zeros to ws-ind ws-ind2.
4101-acha-tag.
add 1 to ws-ind.
if ws-ind > 3000 or
ws-letra-xml(ws-ind) = ws-valor-nulo and
ws-letra-xml(ws-ind + 1) = ws-valor-nulo and
ws-letra-xml(ws-ind + 2) = ws-valor-nulo and
ws-letra-xml(ws-ind + 3) = ws-valor-nulo
go to 4101-exit.
if ws-letra-xml(ws-ind) = "<"
move zeros to ws-ind2 ws-ind-tag
Perform 4102-le-valor-tags thru 4102-exit.

go to 4101-le-nro-tags.
4101-exit.
exit.
4102-le-valor-tags. *> Rotina le tags - definir nome de tags aqui
add 1 to ws-ind.
if ws-ind > 3000 or
ws-letra-xml(ws-ind) = ws-valor-nulo and
ws-letra-xml(ws-ind + 1) = ws-valor-nulo and
ws-letra-xml(ws-ind + 2) = ws-valor-nulo and
ws-letra-xml(ws-ind + 3) = ws-valor-nulo
go to 4102-exit.
if ws-letra-xml(ws-ind) = ">"
Perform 4104-retorno-xml thru 4104-exit
move spaces to ws-nome-tag
move zeros to ws-ind2
go to 4102-le-valor-tags.

if ws-letra-xml(ws-ind) = "<"
go to 4102-le-valor-tags.
add 1 to ws-ind2.
if ws-ind2 > 100
go to 4102-le-valor-tags.

move ws-letra-xml(ws-ind) to ws-letra-tag(ws-ind2).
go to 4102-le-valor-tags.
4102-exit.
exit.
4103-valor-tags.
add 1 to ws-ind.
if ws-letra-xml(ws-ind) = "<"
go to 4103-exit.
add 1 to ws-ind2.
move ws-letra-xml(ws-ind) to ws-letra-tag(ws-ind2).
go to 4103-valor-tags.
4103-exit.
exit.
4104-retorno-xml.
if ws-nome-tag = "infProt"
move "S" to ws-flag.
if ws-flag not = "S"
go to 4104-exit.

if ws-nome-tag = "nRec"
move zeros to ws-ind2
move spaces to ws-nome-tag
Perform 4103-valor-tags thru 4103-exit
move ws-nome-tag to zz-nro-processo
else
if ws-nome-tag = "cStat"
move zeros to ws-ind2
move spaces to ws-nome-tag
Perform 4103-valor-tags thru 4103-exit
move ws-nome-tag to lnk-status
else
if ws-nome-tag = "xMotivo"
move zeros to ws-ind2
move spaces to ws-nome-tag
Perform 4103-valor-tags thru 4103-exit
move ws-nome-tag to lnk-motivo
else
if ws-nome-tag = "chNFe"
move zeros to ws-ind2
move spaces to ws-nome-tag
Perform 4103-valor-tags thru 4103-exit
move ws-nome-tag to lnk-nro-chave-nfe
else
if ws-nome-tag = "nProt"
move zeros to ws-ind2
move spaces to ws-nome-tag
Perform 4103-valor-tags thru 4103-exit
move ws-nome-tag to lnk-nro-protocolo.
4104-exit.
exit.
4105-mensagem.
Perform 7200-recupera-tela thru 7200-exit.
display G-NFE-MENS.
Accept (25, 00) ws-ok with back 4 fore 4.
4105-exit.
exit.
copy proc-scr.bok.

Das könnte Ihnen auch gefallen