Monday, September 29, 2014

How to perform an action on field update

Here is an example of how to perform an action after a field is updated. This is a general technique that can be used on any field.

Let's look at the Products function (GESITM), Units of measure tab:


We have a lot of different units and that gives us flexibility, but suppose that in our case all products will always have the same Stock unit, Purchase unit, Sales unit, Statistic unit and EU unit. Entering all those units manually becomes unnecessary and error-prone. What we want is to only enter the Stock unit and have the other four units change automatically.

First of all, we will set the four secondary unit fields to an Input type of Display, so that they cannot be modified directly. We do this in the Screens function (GESAMK), where we navigate to the ITM3 screen and change the appropriate values from Enter to Display:


Now, in the same screen, we go to the STU field and assign to it an After Change action with a value of SPE:


SPE means that the action handler is going to be located in the specific processing file for this screen. We validate the screen and go to the General tab, from where we can access the specific processing file SPEITM. There we need to type in the following action handler (replacing the default AM_STU subprogram, if such already exists in the file)

Subprog AM_STU(VALEUR)
Variable Char VALEUR()

[M:ITM3]PUU=VALEUR
[M:ITM3]SAU=VALEUR
[M:ITM3]SSU=VALEUR
[M:ITM3]EEU=VALEUR

Affzo [M:ITM3]PUU
Affzo [M:ITM3]SAU
Affzo [M:ITM3]SSU
Affzo [M:ITM3]EEU
End

This handler will be called each time the value of the STU field is modified. The new value is passed in the VALEUR parameter. So we assign this value to the other four unit fields and then we use the Affzo instruction to update their screen presentation. This way we will always change only the Stock unit (STU field) and the other four unit fields will be synced automatically.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.