4GL Program Section

You use program sections to define functions, and to declare tables and global variables, that you want to use in the other sections in the script. You also use program sections to program actions that you want to be executed when the session starts or ends. 
The following program sections are available. They are all main sections. There are no subsections associated with program sections.


Main sections
declaration:
Use this section to declare tables and global variables that you want to use in other sections in the script. See Variable declarations and Table declarations for details of the declaration syntax. You also use this section to define function prototypes. 


before.program:
Use this section to program actions that must be executed when the session starts. For example, you can use this section to initialize or import variables or to read a special record. Note that the default values or imported values overwrite the fields of the main table.


on.error:
Use this section to program actions that must be executed at the end of the session, before the after.program section. If the session is canceled, the actions in this section are not executed. If an error is detected, you can check the predefined variable e for the error code.


after.program:
Use this section to program actions that must be executed at the end of the session, after the on.error section. If the session is canceled (with the command ABORT.PROGRAM), the actions in this section are not executed. 


after.update.db.commit:
Use this section to program actions that must be executed immediately after a commit.transaction() call, if the database is updated.


before.display.object:
Use this section to program actions that must be executed each time the entire record is displayed.


before.new.object:
Use this section to program actions that must be executed once before the input of the first field of the new created record. It is used for setting the default values of the record fields.


functions:
Use this section to define the functions used in the other sections. This must be the last section in the script. The function syntax is the same as for 3GL functions. 



Example:
declaration:
table tpctst999
long var01, ret


before.program:
if read_parameter() then
mess("pctsts0001", 1) | Parameter not present
stop()
endif


on.error:
mess("........", 1)


functions:
function long read_parameter()
{
select pctst999.*
from pctst999
order by pctst999._index1
as set with 1 rows
selectdo
return(0)
selectempty
return(1)
endselect


}

Related Post:

People who read this post also read :



Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More