AMT-COBOL Form Code
Automatic generation of the form code
In AMT-COBOL the sharing of data values between the graphical Layout Controls and the Screen Working Storage (generally a Screen Copy) is only automatic when the Layout Controls of the form and fieldnames in the Screen Copy are exactly the same. The code in the procedure division of the form then only needs to have empty ws-to-form and form-to-ws sections as shown in the example below. This code will already be in the template when creating a new Form.
ws-to-form section.
init-ws-to-form.
* this functionality is implemented in the runtime library.
exit-ws-to-form.
form-to-ws section.
init-form-to-ws.
* this functionality is implemented in the runtime library.
exit-form-to-ws.
exit.
Manual creation of the form code
For Controls with names different from the Screen Working storage the Form needs to contain code to perform the task of copying the data values from the Layout Controls to the Working Storage Fields on input and vice versa on output. It is also possible to manipulate the data before sending it to the form to be displayed.
Working Storage
The Screen Working Storage should be copied into the code Working Storage as shown in the example below. The name 'SCREEN-WS' is mandatory.
copy 'SCREEN-CSTEDT-001'.
WS-TO-FORM section
In the Procedure Division there should be a section named 'WS-TO-FORM'. This section should contain the code to copy the Screen Working Storage field values to the corresponding Graphical Layout Controls. This section can also be used to change the data before being send to the form as shown in the example below.
ws-to-form-begin.
* fill form fields with data from workings-storage (forminput)
move s1-email of screen-ws to email.
move s1-firstname of screen-ws to firstname.
move s1-lastname of screen-ws to lastname.
move s1-postcode of screen-ws to postcode.
inspect s1-tel_no of screen-wsreplacing all '_' by '-'.
ws-to-form-end.
exit.
FORM-TO-WS section
For the copying or the values of the Graphical Layout Controls there should also be a section named 'FORM-TO-WS'. This section can also be used to change the data before being send to the Working Storage an example of such a section is shown below.
form-to-ws-begin.
* fill working-storage (formoutput) with data from form fields
move email to s1-email of screen-ws.
move firstname to s1-firstname of screen-ws.
move lastname to s1-lastname of screen-ws.
move postcode to s1-postcode of screen-ws.
inspects1-tel_no of screen-ws replacing all '-' by '_'.
form-to-ws-end.
exit.