DGL Statement Reference : PROCEDURE

PROCEDURE

Description
Begins a procedure section. It assigns an identifying name to the procedure and defines the return type, if the function returns a value.
The definition of a procedure is as follows:

PROC <procname> [return <type>];
[PARAMETER
<type> <parm1>;
....
<type> <parmN>;
]
[VARIABLE
var section;
]
BEGIN
<statements>;
return <expression>;
END;
Syntax
PROCEDURE procedure_name [RETURN type];
Parameters
 

 

Notes
The scoping rules for procedures are as follows:

For simplification reasons, procedures are not lexically nested within other procedures, nor are they nested within segments.

Like segments, procedures can see template global variables.

Procedures can be referenced by any template segment and can be defined anywhere within the template (but not within segments).

Parameters are always In/Out.

Example
TEMPLATE sss;
PARAMETER
string plot_dir := ’’;
string appendix := ’’;
VARIABLE
string module_name;
string key_bg , key_en;
BEGIN
open (da, ’DIALOG’, OUTPUT);
.....
END;
 
PROCEDURE get_generic_info;
PARAMETER
activity cap; -- Input
activity capdef;
boolean is_generic;
element chrt; -- Outputs
VARIABLE
integer st, st1, st2, st3;
activity acttmp;
BEGIN
capdef := cap;
is_generic := false;
IF (stm_r_mx_generic_instance_mx ({cap}, st) <> {})
THEN
chrt:=stm_list_first_element
(stm_r_ch_defining_ac({cap},st),st2);
IF (st = stm_success AND st2 = stm_success) THEN
acttmp := stm_list_first_element
(stm_r_ac_root_in_ch({chrt},st),st2);
IF (st = stm_success AND st2 = stm_success) THEN
acttmp := stm_list_first_element
(stm_r_ac_internal_ac(
stm_r_ac_logical_sub_of_ac ({acttmp}, st)
,st2),st3);
IF (st = stm_success AND st2 = stm_success AND
st3 = st2) THEN capdef := acttmp;
is_generic := true;
END IF;
END IF;
END IF;
END IF;
END;

 

PROCEDURE put_plot_lines;
PARAMETER
float acty; -- Whatever it means
string title;
VARIABLE
integer lines;
BEGIN
acty := (acty/INCH_PER_LINE) + 0.5;
lines := 0;
WHILE (acty > 0) LOOP
acty := acty-1;
lines := lines + 1;
END LOOP;
write (’\n<HardReturn>’);
write (’\n First line of plot ’,title,’
(Delete between lines)--->>>’);
WHILE (lines > 0) LOOP
write (’\n<HardReturn>\nReserved for plot ---> ’,fl);
lines := lines - 1;
END LOOP;
write (’\n<HardReturn>’);
write (’\n Last line of plot ’,title,’
(Delete between lines)--->>>’);
END;

 

 

PROCEDURE put_bindings ;
PARAMETER
element cap;
VARIABLE
element par;
list of element formals;
integer st, etype;
string title, stype, actual;
BEGIN
-- Specify the bindings
formals := stm_r_mx_parameter_of_ch
(stm_r_ch_defining_ac ({cap}, st), st);
.........
END; -- Put bindings

PROCEDURE put_mini_spec;
PARAMETER
activity act;
VARIABLE
integer st1,st;
string mini_spec;
BEGIN
mini_spec := stm_r_ac_mini_spec (act, st1);
IF (st1 = stm_success) THEN
write (’\n<Bold>\n’);
write (’Mini-Spec :’);
write (’\n<NoBold>\n’);
write (’\n\n’);
lwrite (mini_spec);
write (’\n\n’);
END IF;
IF (st <> stm_success and st1 <> stm_success) THEN
write (’TBD.’);
END IF;
END ; -- put_mini_spec

SEGMENT body;

cap:=....
put_bindings (cap);
put_mini_spec (cap);

.....
END;

See Also