The example below illustrates
a valid public method. It has a void return type (no RETURNS clause),
uses only publicly supported data types, and treats in_out arguments
as output only.
method quickSortStep (int lowerIndex, int higherIndex, in_out double numbers[10]);
dcl int i;
dcl int j;
dcl int pivot;
dcl double temp;
i = lowerIndex;
j = higherIndex;
/* Calculate the pivot number, taking the pivot as the
* middle index number. */
pivot = numbers[ceil(lowerIndex+(higherIndex-lowerIndex)/2)];
/* Divide into two arrays */
do while (i <= j);
/**
* In each iteration, identify a number from the left side that
* is greater than the pivot value. Also identify a number
* from the right side that is less than the pivot value.
* Once the search is done, then exchange both numbers.
*/
do while (numbers[i] < pivot);
i = i+1;
end;
do while (numbers[j] > pivot);
j = j-1;
end;
if (i <= j) then do;
temp = numbers[i];
numbers[i] = numbers[j];
numbers[j] = temp;
/* Move the index to the next position on both sides. */
i = i+1;
j = j-1;
end;
end;
/* Call quickSort recursively. */
if (lowerIndex < j) then do;
quickSortStep(lowerIndex, j, numbers);
end;
if (i < higherIndex) then do;
quickSortStep(i, higherIndex, numbers);
end;
end;
Here is another example
of a public method that illustrates the use of the HTTP package calling
out to a web service using a POST request and then getting a response.
method httppost( nvarchar(8192) url,
nvarchar(67108864) payload,
in_out nvarchar respbody,
in_out int hstat, in_out int rc );
declare package http h();
rc = h.createPostMethod( url );
if rc ne 0 then goto Exit;
rc = h.setRequestContentType( 'application/json;charset=utf-8' );
if rc ne 0 then goto Exit;
rc = h.addRequestHeader( 'Accept', 'application/json' );
if rc ne 0 then goto Exit;
rc = h.setRequestBodyAsString( payload );
if rc ne 0 then goto Exit;
rc = h.executeMethod();
if rc ne 0 then goto Exit;
hstat = h.getStatusCode();
if hstat lt 400 then h.getResponseBodyAsString( respbody, rc );
else respbody = '';
Exit:
h.delete();
end;