SQL Programming Manual for TAL
Examples of Static NonStop SQL Programs
HP NonStop SQL Programming Manual for TAL—527887-001
B-6
Insertion Program
J Page 4 [1] $VOL1.S04.TALTEST 1991-10-15 13:40:20
108. 000000 0 0 PROC CHECK^SUPPLIER;
109. 000000 1 0 BEGIN
110. 000000 1 1 -- Open the cursor at value of host variable
SUPPLIER^OF^PARTS:
111. 000000 1 1 EXEC SQL OPEN get_supplier_cursor;
112. 000046 1 1
113. 000046 1 1 -- Perform cursor FETCH:
114. 000046 1 1 EXEC SQL
115. 000046 1 1 FETCH get_supplier_cursor INTO
116. 000046 1 1 :supplier^rec.suppnum,
117. 000046 1 1 :supplier^rec.suppname,
118. 000046 1 1 :supplier^rec.street,
119. 000046 1 1 :supplier^rec.city,
120. 000046 1 1 :supplier^rec.state,
121. 000046 1 1 :supplier^rec.postcode;
122. 000207 1 1
123. 000207 1 1 -- A not-found condition goes to abort^transaction;
otherwise,
124. 000207 1 1 -- the supplier record is present.
125. 000207 1 1
126. 000207 1 1 sbuf ':=' "SUPPLIER IS "&supplier^rec.suppname
127. 000207 1 1 FOR $OCCURS(supplier^rec.suppname) ->@buf^end;
128. 000225 1 1 CALL WRITE(home^term^num,ibuf,@buf^end '-' @sbuf);
129. 000237 1 1
130. 000237 1 1 END; --end of CHECK^SUPPLIER
131. 000000 0 0
Page 5 [1] $VOL1.S04.TALTEST 1991-10-15 13:40:20
133. 000000 0 0 PROC DO^ADD^TO^PARTS;
134. 000000 1 0 BEGIN
135. 000000 1 1 parts^rec.partnum := in^data^rec.in^partnum;
136. 000003 1 1 parts^rec.partdesc ':=' in^data^rec.in^partdesc
137. 000003 1 1 FOR $OCCURS(parts^rec.partdesc);
138. 000013 1 1 parts^rec.price := in^data^rec.in^price;
139. 000016 1 1 parts^rec.qty^available := in^data^rec.in^qty;
140. 000023 1 1
141. 000023 1 1 sbuf ':=' "BEGIN INSERT ON PARTS *******"->@buf^end;
142. 000034 1 1 CALL WRITE(home^term^num,ibuf,@buf^end '-' @sbuf);
143. 000046 1 1
144. 000046 1 1 --Insert the record. Use SETSCALE to communicate a scale
145. 000046 1 1 --of 2 to SQL (SETSCALE is used because you are using the
146. 000046 1 1 --INVOKE generated descriptions; otherwise, you could
define
147. 000046 1 1 --the PRICE column as FIXED(2).
148. 000046 1 1 EXEC SQL
149. 000046 1 1 INSERT INTO =PARTS
150. 000046 1 1 VALUES ( :parts^rec.partnum,
151. 000046 1 1 :parts^rec.partdesc,
152. 000046 1 1 SETSCALE (:parts^rec.price, 2),
153. 000046 1 1 :parts^rec.qty^available);
154. 000140 1 1 END;
155. 000000 0 0 --End of DO^ADD^TO^PARTS
156. 000000 0 0