Tempo de leitura: 2 minutos
Olá, no post de hoje iremos aprender como usar a função ExistCPO no ADVPL. Elá é uma das funções de validação no ADVPL. A função ExistCPO verifica se um registro passado como parâmetro existe em qualquer tabela(arquivos de dados) especificada.
Sintaxe:
Parâmetro(s):
Retorno:
Obs.:
As funções ExistChav e ExistCpo tem algumas semelhanças. Porém, enquanto que a função ExistChav verifica uma chave única, ou seja, verifica se um código já existe no próprio arquivo de dados que está sendo manipulado, a função ExistCpo verifica uma chave estrangeira, ou seja, verifica se um código existe em outro arquivo de dados.
Exemplo da função ExistCPO no ADVPL:
#include 'protheus.ch'
#include "tbiconn.ch"
/**{Protheus.doc} User Function fExisCPO
A função ExistCPO valida a existência de um registro em qualquer tabela do Protheus
@type Function
@author Adilio Costa
@since 07/04/2025
@version 1.0
@Link de referência:https://tdn.totvs.com/pages/releaseview.action?pageId=24346640
@Inscreva-se no Blog ProtheusAdvpl:
https://www.protheusadvpl.com.br
@Inscreva-se no Canal ProtheusAdvpl:
https://www.youtube.com/protheusadvpl
@Siga-nos no Instagram:
https://www.instagram.com/protheusadvpl
@Conheça os Cursos do ProtheusAdvpl:
https://cursos-e-formacoes-protheusadvpl.gr-site.com/
|Se esse conteúdo foi útil pra você nos ajude divulgando
ele e nossas redes sociais!!|
-Plataforma: Portal ProtheusAdvpl-https://hotm.art/portal_protheusadvpl
-Módulo 7:7.39.2- [Protheus-Programação/ADVPL II/Funções de Validação] - Como Utilizar a Função ExistCPO para Validar a Existência de Registros em Tabelas ADVPL
*/
User Function fExisCPO()
Local cAlias := "SA1"
Local cCodCli := "000001"
Local cLoja := "01"
Local cChave := ""
Local cInd := 1 //A1_FILIAL+A1_COD+A1_LOJA
cChave := cCodCli+cLoja
If(ExistCPO(cAlias,cChave,cInd))
MsgInfo("O cliente de "+cCodCli+" e loja "+cLoja+" existe na tabela de clientes "+cAlias+".","Função ExistCPO")
Else
MsgInfo("O cliente de "+cCodCli+" e loja "+cLoja+" existe na tabela de clientes "+cAlias+".","Função ExistCPO")
EndIf
Return
Bem, finalizamos mais um post aqui no blog. Espero que você tenha entendido, qualquer dúvida nos envie um e-mail para adiliocosta@protheusadvpl.com.br. Grande abraço e fica com Deus.
Links de referência(s):
Link permanente
>nice
Link permanente
https://vaidaan.com/collections/footwear-daily-wear
Link permanente
Hi there, just became aware of your blog through Google, and found that it’s really informative. I am going to watch out for brussels. I will be grateful if you continue this in future. Many people will be benefited from your writing. Cheers!