- Fórum
- Protheus/Microsiga/Totvs
- AdvPL (Advanced Protheus Language)
- Dúvidas Gerais
- Fonte ADVPL chamando Stored Procedure
×
Linguagem de Programação ADVPL
Perguntas Fonte ADVPL chamando Stored Procedure
- jrtimbim
- Autor do Tópico
- Desconectado
- Membro Iniciado
Menos
Mais
- Postagens: 1
- Obrigados Recebidos: 0
11 anos 2 semanas atrás #18262
por jrtimbim
Fonte ADVPL chamando Stored Procedure foi criado por jrtimbim
Boa tarde pessoal, preciso da ajuda de alguém de boa vontade. Preciso de um fonte em ADVPL simples no qual tem que chamar uma Procedure em Oracle.
O usuário irá informar 2 parâmetros para a Procedure ser executada.
Segue abaixo a Procedure que foi criada.
Conto com apoio.
--DECLARACAO DE VARIAVEIS
IS
V_PODE NUMBER ;
V_COUNT NUMBER ;
V_QTDE NUMBER ;
V_SEQ NUMBER ;
V_RECNO NUMBER ;
V_CODGRU CHAR(3) ;
V_CODGR2 CHAR(3) ;
V_CODPSA CHAR(16);
V_BENUTL CHAR(1) ;
V_AUTORI CHAR(1) ;
V_CARENC NUMBER ;
V_UNCAR CHAR(1) ;
V_NIVCAR CHAR(1) ;
V_QTD NUMBER ;
V_UNCA CHAR(1) ;
V_PERIOD NUMBER ;
V_UNPERI CHAR(1) ;
V_QTDESP CHAR(1) ;
V_SEXO CHAR(1) ;
V_QTDMED CHAR(1) ;
V_IDAMIN NUMBER ;
V_QTDPAT CHAR(1) ;
V_IDAMAX NUMBER ;
V_PTRMED CHAR(1) ;
V_PTRESP CHAR(1) ;
V_UNVAL CHAR(1) ;
V_PTRPAT CHAR(1) ;
V_CODPAD CHAR(2) ;
V_CLACAR CHAR(3) ;
--BLOCO PRINCIPAL
BEGIN
V_CODGRU := '058'; --PARAMETRO 01 - GRUPO DE REFERENCIA
V_CODGR2 := '096'; --PARAMETRO 02 - GRUPO A SER ATUALIZADO
SELECT COUNT(*) INTO V_PODE
FROM ALL_TAB_COLUMNS
WHERE OWNER = 'SIGA'
AND TABLE_NAME = 'BG8010'
AND COLUMN_NAME NOT IN ('BG8_FILIAL','BG8_CODINT','BG8_CODGRU','BG8_CODPSA','BG8_BENUTL',
'BG8_AUTORI','BG8_CARENC','BG8_UNCAR' ,'BG8_NIVEL' ,'BG8_NIVCAR',
'BG8_QTD' ,'BG8_UNCA' ,'BG8_PERIOD','BG8_UNPERI','BG8_QTDESP',
'BG8_SEXO' ,'BG8_QTDMED','BG8_IDAMIN','BG8_QTDPAT','BG8_IDAMAX',
'BG8_PTRMED','BG8_PTRESP','BG8_UNVAL' ,'BG8_PTRPAT','BG8_CODPAD',
'BG8_CDNV01','BG8_CDNV02','BG8_CDNV03','BG8_CDNV04','BG8_CLACAR',
'D_E_L_E_T_','R_E_C_N_O_');
--VERIFICA SE NÃO FOI ALTERADA A ESTRUTURA DA TABELA BG8010
IF V_PODE = 0
THEN
--ATUALIZA OS PROCEDIMENTOS
DELETE FROM UNI0177BG8TEMP;
COMMIT;
INSERT INTO UNI0177BG8TEMP (SELECT * FROM BG8010
WHERE BG8_FILIAL = ' '
AND BG8_CODINT = '0177'
AND BG8_CODGRU = V_CODGRU
AND D_E_L_E_T_ = ' ');
COMMIT;
UPDATE UNI0177BG8TEMP SET R_E_C_N_O_ = ROWNUM;
COMMIT;
SELECT MAX(R_E_C_N_O_) INTO V_SEQ FROM BG8010;
SELECT MAX(R_E_C_N_O_) INTO V_QTDE FROM UNI0177BG8TEMP;
SELECT MIN(R_E_C_N_O_) INTO V_COUNT FROM UNI0177BG8TEMP;
WHILE V_COUNT <= V_QTDE
LOOP
BEGIN
SELECT BG8_CODPSA INTO V_CODPSA FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_BENUTL INTO V_BENUTL FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_AUTORI INTO V_AUTORI FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_CARENC INTO V_CARENC FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_UNCAR INTO V_UNCAR FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_NIVCAR INTO V_NIVCAR FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_QTD INTO V_QTD FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_UNCA INTO V_UNCA FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_PERIOD INTO V_PERIOD FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_UNPERI INTO V_UNPERI FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_QTDESP INTO V_QTDESP FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_SEXO INTO V_SEXO FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_QTDMED INTO V_QTDMED FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_IDAMIN INTO V_IDAMIN FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_QTDPAT INTO V_QTDPAT FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_IDAMAX INTO V_IDAMAX FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_PTRMED INTO V_PTRMED FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_PTRESP INTO V_PTRESP FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_UNVAL INTO V_UNVAL FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_PTRPAT INTO V_PTRPAT FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_CODPAD INTO V_CODPAD FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_CLACAR INTO V_CLACAR FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
UPDATE BG8010 SET BG8_BENUTL = V_BENUTL,
BG8_AUTORI = V_AUTORI,
BG8_CARENC = V_CARENC,
BG8_UNCAR = V_UNCAR ,
BG8_NIVCAR = V_NIVCAR,
BG8_QTD = V_QTD ,
BG8_UNCA = V_UNCA ,
BG8_PERIOD = V_PERIOD,
BG8_UNPERI = V_UNPERI,
BG8_QTDESP = V_QTDESP,
BG8_SEXO = V_SEXO ,
BG8_QTDMED = V_QTDMED,
BG8_IDAMIN = V_IDAMIN,
BG8_QTDPAT = V_QTDPAT,
BG8_IDAMAX = V_IDAMAX,
BG8_PTRMED = V_PTRMED,
BG8_PTRESP = V_PTRESP,
BG8_UNVAL = V_UNVAL ,
BG8_PTRPAT = V_PTRPAT,
BG8_CLACAR = V_CLACAR
WHERE BG8_FILIAL = ' '
AND BG8_CODINT = '0177'
AND BG8_CODGRU = V_CODGR2
AND BG8_CODPAD = V_CODPAD
AND BG8_CODPSA = V_CODPSA;
COMMIT;
V_COUNT := V_COUNT+1;
END;
END LOOP;
--INSERE PROCEDIMENTOS NAO EXISTENTES.
DELETE FROM UNI0177BG8TEMP;
COMMIT;
INSERT INTO UNI0177BG8TEMP (SELECT * FROM BG8010 BG8
WHERE BG8.BG8_FILIAL = ' '
AND BG8.BG8_CODINT = '0177'
AND BG8.BG8_CODGRU = V_CODGRU
AND NOT EXISTS(SELECT * FROM BG8010 BG82
WHERE BG82.BG8_FILIAL = BG8.BG8_FILIAL
AND BG82.BG8_CODINT = BG8.BG8_CODINT
AND BG82.BG8_CODGRU = V_CODGR2
AND BG82.BG8_CODPAD = BG8.BG8_CODPAD
AND BG82.BG8_CODPSA = BG8.BG8_CODPSA
AND BG82.BG8_NIVEL = BG8.BG8_NIVEL
AND BG82.R_E_C_N_O_ > 0
AND BG82.D_E_L_E_T_ = ' '
AND BG8.D_E_L_E_T_ = ' '));
COMMIT;
UPDATE UNI0177BG8TEMP SET R_E_C_N_O_ = ROWNUM;
COMMIT;
UPDATE UNI0177BG8TEMP SET R_E_C_N_O_ = R_E_C_N_O_ + V_SEQ;
COMMIT;
UPDATE UNI0177BG8TEMP SET BG8_CODGRU = V_CODGR2;
COMMIT;
INSERT INTO BG8010 (SELECT * FROM UNI0177BG8TEMP BG8TEMP);
COMMIT;
--RETIRA DO GRUPO DE COBERTURA PROCEDIMENTOS NAO CONSTANTES NO GRUPO DE REFERENCIA
UPDATE BG8010 BG8 SET D_E_L_E_T_ = '*'
WHERE BG8_FILIAL = ' '
AND BG8_CODINT = '0177'
AND BG8_CODGRU = V_CODGR2
AND NOT EXISTS (SELECT * FROM BG8010 BG82
WHERE BG82.BG8_FILIAL = BG8.BG8_FILIAL
AND BG82.BG8_CODINT = BG8.BG8_CODINT
AND BG82.BG8_CODGRU = V_CODGRU
AND BG82.BG8_CODPAD = BG8.BG8_CODPAD
AND BG82.BG8_CODPSA = BG8.BG8_CODPSA
AND BG82.BG8_NIVEL = BG8.BG8_NIVEL
AND BG82.R_E_C_N_O_ > 0
AND BG82.D_E_L_E_T_ = ' '
AND BG8.D_E_L_E_T_ = ' ');
COMMIT;
END IF;
COMMIT;
--FIM DO BLOCO PRINCIPAL
END ATUALIZA_BG8010;
O usuário irá informar 2 parâmetros para a Procedure ser executada.
Segue abaixo a Procedure que foi criada.
Conto com apoio.
--DECLARACAO DE VARIAVEIS
IS
V_PODE NUMBER ;
V_COUNT NUMBER ;
V_QTDE NUMBER ;
V_SEQ NUMBER ;
V_RECNO NUMBER ;
V_CODGRU CHAR(3) ;
V_CODGR2 CHAR(3) ;
V_CODPSA CHAR(16);
V_BENUTL CHAR(1) ;
V_AUTORI CHAR(1) ;
V_CARENC NUMBER ;
V_UNCAR CHAR(1) ;
V_NIVCAR CHAR(1) ;
V_QTD NUMBER ;
V_UNCA CHAR(1) ;
V_PERIOD NUMBER ;
V_UNPERI CHAR(1) ;
V_QTDESP CHAR(1) ;
V_SEXO CHAR(1) ;
V_QTDMED CHAR(1) ;
V_IDAMIN NUMBER ;
V_QTDPAT CHAR(1) ;
V_IDAMAX NUMBER ;
V_PTRMED CHAR(1) ;
V_PTRESP CHAR(1) ;
V_UNVAL CHAR(1) ;
V_PTRPAT CHAR(1) ;
V_CODPAD CHAR(2) ;
V_CLACAR CHAR(3) ;
--BLOCO PRINCIPAL
BEGIN
V_CODGRU := '058'; --PARAMETRO 01 - GRUPO DE REFERENCIA
V_CODGR2 := '096'; --PARAMETRO 02 - GRUPO A SER ATUALIZADO
SELECT COUNT(*) INTO V_PODE
FROM ALL_TAB_COLUMNS
WHERE OWNER = 'SIGA'
AND TABLE_NAME = 'BG8010'
AND COLUMN_NAME NOT IN ('BG8_FILIAL','BG8_CODINT','BG8_CODGRU','BG8_CODPSA','BG8_BENUTL',
'BG8_AUTORI','BG8_CARENC','BG8_UNCAR' ,'BG8_NIVEL' ,'BG8_NIVCAR',
'BG8_QTD' ,'BG8_UNCA' ,'BG8_PERIOD','BG8_UNPERI','BG8_QTDESP',
'BG8_SEXO' ,'BG8_QTDMED','BG8_IDAMIN','BG8_QTDPAT','BG8_IDAMAX',
'BG8_PTRMED','BG8_PTRESP','BG8_UNVAL' ,'BG8_PTRPAT','BG8_CODPAD',
'BG8_CDNV01','BG8_CDNV02','BG8_CDNV03','BG8_CDNV04','BG8_CLACAR',
'D_E_L_E_T_','R_E_C_N_O_');
--VERIFICA SE NÃO FOI ALTERADA A ESTRUTURA DA TABELA BG8010
IF V_PODE = 0
THEN
--ATUALIZA OS PROCEDIMENTOS
DELETE FROM UNI0177BG8TEMP;
COMMIT;
INSERT INTO UNI0177BG8TEMP (SELECT * FROM BG8010
WHERE BG8_FILIAL = ' '
AND BG8_CODINT = '0177'
AND BG8_CODGRU = V_CODGRU
AND D_E_L_E_T_ = ' ');
COMMIT;
UPDATE UNI0177BG8TEMP SET R_E_C_N_O_ = ROWNUM;
COMMIT;
SELECT MAX(R_E_C_N_O_) INTO V_SEQ FROM BG8010;
SELECT MAX(R_E_C_N_O_) INTO V_QTDE FROM UNI0177BG8TEMP;
SELECT MIN(R_E_C_N_O_) INTO V_COUNT FROM UNI0177BG8TEMP;
WHILE V_COUNT <= V_QTDE
LOOP
BEGIN
SELECT BG8_CODPSA INTO V_CODPSA FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_BENUTL INTO V_BENUTL FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_AUTORI INTO V_AUTORI FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_CARENC INTO V_CARENC FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_UNCAR INTO V_UNCAR FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_NIVCAR INTO V_NIVCAR FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_QTD INTO V_QTD FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_UNCA INTO V_UNCA FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_PERIOD INTO V_PERIOD FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_UNPERI INTO V_UNPERI FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_QTDESP INTO V_QTDESP FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_SEXO INTO V_SEXO FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_QTDMED INTO V_QTDMED FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_IDAMIN INTO V_IDAMIN FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_QTDPAT INTO V_QTDPAT FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_IDAMAX INTO V_IDAMAX FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_PTRMED INTO V_PTRMED FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_PTRESP INTO V_PTRESP FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_UNVAL INTO V_UNVAL FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_PTRPAT INTO V_PTRPAT FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_CODPAD INTO V_CODPAD FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
SELECT BG8_CLACAR INTO V_CLACAR FROM UNI0177BG8TEMP WHERE R_E_C_N_O_ = V_COUNT;
UPDATE BG8010 SET BG8_BENUTL = V_BENUTL,
BG8_AUTORI = V_AUTORI,
BG8_CARENC = V_CARENC,
BG8_UNCAR = V_UNCAR ,
BG8_NIVCAR = V_NIVCAR,
BG8_QTD = V_QTD ,
BG8_UNCA = V_UNCA ,
BG8_PERIOD = V_PERIOD,
BG8_UNPERI = V_UNPERI,
BG8_QTDESP = V_QTDESP,
BG8_SEXO = V_SEXO ,
BG8_QTDMED = V_QTDMED,
BG8_IDAMIN = V_IDAMIN,
BG8_QTDPAT = V_QTDPAT,
BG8_IDAMAX = V_IDAMAX,
BG8_PTRMED = V_PTRMED,
BG8_PTRESP = V_PTRESP,
BG8_UNVAL = V_UNVAL ,
BG8_PTRPAT = V_PTRPAT,
BG8_CLACAR = V_CLACAR
WHERE BG8_FILIAL = ' '
AND BG8_CODINT = '0177'
AND BG8_CODGRU = V_CODGR2
AND BG8_CODPAD = V_CODPAD
AND BG8_CODPSA = V_CODPSA;
COMMIT;
V_COUNT := V_COUNT+1;
END;
END LOOP;
--INSERE PROCEDIMENTOS NAO EXISTENTES.
DELETE FROM UNI0177BG8TEMP;
COMMIT;
INSERT INTO UNI0177BG8TEMP (SELECT * FROM BG8010 BG8
WHERE BG8.BG8_FILIAL = ' '
AND BG8.BG8_CODINT = '0177'
AND BG8.BG8_CODGRU = V_CODGRU
AND NOT EXISTS(SELECT * FROM BG8010 BG82
WHERE BG82.BG8_FILIAL = BG8.BG8_FILIAL
AND BG82.BG8_CODINT = BG8.BG8_CODINT
AND BG82.BG8_CODGRU = V_CODGR2
AND BG82.BG8_CODPAD = BG8.BG8_CODPAD
AND BG82.BG8_CODPSA = BG8.BG8_CODPSA
AND BG82.BG8_NIVEL = BG8.BG8_NIVEL
AND BG82.R_E_C_N_O_ > 0
AND BG82.D_E_L_E_T_ = ' '
AND BG8.D_E_L_E_T_ = ' '));
COMMIT;
UPDATE UNI0177BG8TEMP SET R_E_C_N_O_ = ROWNUM;
COMMIT;
UPDATE UNI0177BG8TEMP SET R_E_C_N_O_ = R_E_C_N_O_ + V_SEQ;
COMMIT;
UPDATE UNI0177BG8TEMP SET BG8_CODGRU = V_CODGR2;
COMMIT;
INSERT INTO BG8010 (SELECT * FROM UNI0177BG8TEMP BG8TEMP);
COMMIT;
--RETIRA DO GRUPO DE COBERTURA PROCEDIMENTOS NAO CONSTANTES NO GRUPO DE REFERENCIA
UPDATE BG8010 BG8 SET D_E_L_E_T_ = '*'
WHERE BG8_FILIAL = ' '
AND BG8_CODINT = '0177'
AND BG8_CODGRU = V_CODGR2
AND NOT EXISTS (SELECT * FROM BG8010 BG82
WHERE BG82.BG8_FILIAL = BG8.BG8_FILIAL
AND BG82.BG8_CODINT = BG8.BG8_CODINT
AND BG82.BG8_CODGRU = V_CODGRU
AND BG82.BG8_CODPAD = BG8.BG8_CODPAD
AND BG82.BG8_CODPSA = BG8.BG8_CODPSA
AND BG82.BG8_NIVEL = BG8.BG8_NIVEL
AND BG82.R_E_C_N_O_ > 0
AND BG82.D_E_L_E_T_ = ' '
AND BG8.D_E_L_E_T_ = ' ');
COMMIT;
END IF;
COMMIT;
--FIM DO BLOCO PRINCIPAL
END ATUALIZA_BG8010;
Por favor Acessar ou Registrar para participar da conversa.
- kanaamlrr
- Desconectado
- Membro Platina
Menos
Mais
- Postagens: 1576
- Obrigados Recebidos: 4
11 anos 2 semanas atrás #18277
por kanaamlrr
Respondido por kanaamlrr no tópico Fonte ADVPL chamando Stored Procedure
Você pode executar a procedure da seguinte forma:
Faça o teste e depois posta ai
cSql := "EXEC MYPROC 'PARAM1', 'PARAM2'"
TCSQLExec(cSql)
Faça o teste e depois posta ai
Por favor Acessar ou Registrar para participar da conversa.
- Fórum
- Protheus/Microsiga/Totvs
- AdvPL (Advanced Protheus Language)
- Dúvidas Gerais
- Fonte ADVPL chamando Stored Procedure
Tempo para a criação da página:0.102 segundos