-
Notifications
You must be signed in to change notification settings - Fork 0
/
cursor.sqlrpgle
101 lines (84 loc) · 2.7 KB
/
cursor.sqlrpgle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// curseur de lecture
exec sql
declare CURS_01 cursor for
select corkro, cornum, corord, cordat,
prtkro, prtres, prtmot
from t4pcorpf
exception join adh1csupf on corkro = csukro
inner join t4pprtpf on cornum = prtnum
and corord = prtord
where cornat = 250
and cordte = '0001-01-01'
and cordat = :pcordat
order by cornum, corord
for fetch only;
// ouverture curseur
exec sql open CURS_01;
wsqlcodCurseur = sqlcode;
if wsqlcodCurseur = *zero; // pas erreur open curseur
clear wcorkro;
clear wcornum;
clear wcorord;
clear wcordat;
clear wprtkro;
clear wprtres;
clear wprtmot;
wnbLecture = 0;
// lecture curseur
exec sql
fetch next from CURS_01
into :wcorkro, :wcornum, :wcorord, :wcordat,
:wprtkro, :wprtres, :wprtmot;
wsqlcodCurseur = sqlcode;
dow wsqlcodCurseur <> 100; // tant que pas fin de curseur
wnbLecture += 1;
// coder ci dessous le traitement
dsply ('num oav : ' + %char(wcornum));
// lecture curseur
exec sql
fetch next from CURS_01
into :wcorkro, :wcornum, :wcorord, :wcordat,
:wprtkro, :wprtres, :wprtmot;
wsqlcodCurseur = sqlcode;
enddo;
select;
when wsqlcodCurseur = 0;
when wsqlcodCurseur = 100;
// sortie de boucle normale
other;
// erreur : sortie de boucle anormale
m_error ('000190'
:*omit
:'erreur fetch'
// ajouter les données de contexte (numéro oav...)
:'*Sql'
:'INFO'
:' '
);
endsl;
exec sql close CURS_01;
else; // erreur open curseur
m_error ('000203'
:*omit
:'erreur open curseur CURS_01'
:'*Sql'
:'INFO'
:' '
);
endif;
*inlr = *on;
// Cursor avec Update
EXEC SQL
declare CURS_01 cursor for
select corkroTmp,
cornumTmp, corordTmp,
cornatTmp,
corkrgTmp,
apedemTmp
from pcorTmp
order by cornatTmp, apedemTmp, corkroTmp
for update with nc;
EXEC SQL
update pcorTmp
set corkrgTmp = :corkroTmp
where current of CURS_01;