operation exec

Default component operation, which is invoked by the activate statement.

For dynamic server pages:

operation exec
   {public soap}  
   {public web | partner web} 
   {scopeBlock}
   {variablesBlock}
   Your code here ...
end

For static server pages and services:

operation exec
   {public soap}  
   {public web}    
   {paramsBlock}   ;  Not allowed for public web
   {variablesBlock}
   Your code here ...
end

For forms and reports:

operation exec
   {paramsBlock}
   {variablesBlock}
   Your code here ...
end
Applies to: All components
Activation: Activated by an activate statement
Default behavior: Depends on the type of component.
Behavior upon completion: The value in $status is available after activate statement that started the component.

In Form components, the structure editor is not affected by the value of $status.

Description

The exec operation begins the default trigger activation sequence of a component session.

If a component contains a public web or public soap declaration in the exec operation, it can be activated by an HTTP request from a web client or a SOAP request from a SOAP client.

ProcScript in the exec operation may initialize component-level values, retrieve information, perform batch processing, print data, activate other components, and so on. For example, the ProcScript might set some field values followed by a retrieve statement so that the user only sees a subset of the data.

Default Behavior

If the exec operation is not explicitly declared, it falls back to a default behavior, which varies with the type of component:

  • In a Dynamic Server Page (DSP), there is no default behavior, but the component is available. However, no public or partner web declaration is defined for it, so calling it results in a security message on the browser.
  • In a Static Service Page (USP), an implicit edit is performed by means of the public web, webget and webgen statements. Any submitted data (disconnected records) is loaded into the component and reconnected to the database, reconnect errors are reported, the requested trigger is fired, after which the webgen generates the response based on the default skeleton (depending on ASN settings. the internal or external skeleton is used). The exec trigger is always involved when firing field triggers, as described above.
  • In a Form, an implicit edit statement is executed.
  • In a Service or Report , the exec operation returns to the component instance that issued the activate.

Interactive Processing in Forms

If you implement the exec operation in Form components, you should include an edit or display statement to display the component. If neither of these is present, and the exec operation is not empty, the component exits immediately after the last ProcScript statement in the trigger has executed, without being displayed.

Any statements after the edit or display statement are executed only if the ProcScript in the component-level quit or accept triggers (whichever is used) ends with a value of 0 in $status. (The value of $status can be set explicitly or indirectly by way of the return statement.)

If the component is closed using an exit or apexit statement, any ProcScript statements after the edit or display statement are not executed.

Printing

When defining the ProcScript for a Report, it is usual to include a print statement which initiates printing by retrieving data.

Public Access from Web and Soap Clients

A component that can be accessed from the web, such as a server page or web service, must contain a declaration for the appropriate channel—public web for requests from web clients such as browsers and RESTful web services, and public soap for SOAP clients.

A parameters block (params) is not allowed in an exec operation that contains a (partner or public) web declaration, because this would constitute a security risk for the application.

Retrieving Data in Forms

It is quite common to set a retrieve profile in the exec operation of a Form, and then use a retrieve statement so that the user is presented with a populated form. You can use a retrieve profile to select a subset of data; for example, to retrieve only those occurrences that a user is authorized to modify. For example:

operation exec
  PKFIELD = "D*"
  retrieve
  edit
end; exec

The example only lets the user retrieve data where the primary key field (in this example PKFIELD) starts with the letter ‘D’. It would be more sensible to pass parameters to the form with the activate statement. For example, the following activate statement passes the value that has been placed in the $profile$ component variable to the component AnotherComponent:

activate "AnotherComponent".exec($profile$)

In the exec operation of the activated component:

operation exec
params
   string profile : IN
endparams

PKFIELD = profile
retrieve
edit
end; exec

Use the variables statement to set up local variables for handling the processing in the exec operation.

Related Topics