Last active
December 13, 2016 11:53
-
-
Save brunoconstantino/2f382d5739d375efe7c3fc66dd9c904e to your computer and use it in GitHub Desktop.
Função para calcular o dígito verificador da Chave de Acesso da Nota Fiscal Eletrônica em COBOL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$SET ANS85 | |
* [ fonte ] VERIFICA-CHAVE-NFE | |
* [ linguagem ] microfocus cobol 3-2-50 | |
* [ finalidade ] Função para calculo o digito verificador da NFe | |
* [ local ] LOPO Calcados | |
identification division. | |
program-id. VERIFICA-CHAVE-NFE. | |
author. Bruno Constantino. | |
date-written. 12-12-2016. | |
date-compiled. 12-12-2016. | |
environment division. | |
configuration section. | |
source-computer. Pentium-D. | |
object-computer. Pentium-D. | |
special-names. decimal-point is comma. | |
INPUT-OUTPUT SECTION. | |
FILE-CONTROL. | |
DATA DIVISION. | |
FILE SECTION. | |
WORKING-STORAGE SECTION. | |
77 WX pic 9(03). | |
77 WY pic 9(03). | |
01 WS-CHAVE-NFE pic X(44). | |
01 WS-DIGITO-NFE pic 9(1). | |
01 WS-SOMA pic 9(4) value zeros. | |
01 WS-RESTO pic 9(1). | |
01 WS-RES1 pic 9(4) value zeros. | |
PROCEDURE DIVISION. | |
A-INICIO SECTION. | |
A00. | |
*> Teste de Chave valida | |
display "TESTANDO CHAVE DE ACESSO". | |
move "23140502179938000146550010000658711000658716" | |
to WS-CHAVE-NFE | |
display WS-CHAVE-NFE. | |
perform VERIFICAR-CHAVE-NFE. | |
*> Teste de Chave invalida | |
move "35161102484555000261570050000741851040666710" | |
to WS-CHAVE-NFE | |
display WS-CHAVE-NFE. | |
perform VERIFICAR-CHAVE-NFE. | |
A99. | |
stop run. | |
VERIFICAR-CHAVE-NFE section. | |
VCNF01. | |
*> WY contem os multiplicadores 2 a 9. | |
move 2 to WY | |
move zeros to WX | |
WS-SOMA | |
WS-RES1 | |
*> Percorre a Chave de Acesso de Tras pra Frente | |
perform varying WX from 43 by -1 until WX < 1 | |
compute WS-SOMA = WS-SOMA + | |
(FUNCTION NUMVAL(WS-CHAVE-NFE (WX:1)) * WY) | |
end-compute | |
add 1 to WY | |
if WY > 9 | |
move 2 to WY | |
end-if | |
end-perform. | |
divide WS-SOMA by 11 giving WS-RES1 remainder WS-RESTO. | |
if WS-RESTO = 0 or 1 | |
move "0" to WS-DIGITO-NFE | |
else | |
subtract 11 from WS-RESTO | |
move WS-RESTO to WS-DIGITO-NFE | |
end-if. | |
display "DIGITO CHAVE: " WS-CHAVE-NFE (44:1) | |
display "DIGITO CALCULADO: " WS-DIGITO-NFE | |
if WS-DIGITO-NFE not = WS-CHAVE-NFE (44:1) | |
display "Chave de acesso Invalida." | |
go VCNF099 | |
end-if. | |
if WS-DIGITO-NFE = WS-CHAVE-NFE (44:1) | |
display "Chave de acesso Valida." | |
go VCNF099 | |
end-if. | |
VCNF099. | |
exit. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment