In this step you will add logic to CheckItemAvailability.seqflow (a)
to delete some unnecessary mappings; (b) to store a result value into
an output parameter indicating whether the requested item number was
found; and (c) to add an alternate path to handle the scenario in
which the flow does not page through all the screens of the multipage
list in the terminal application.
Delete
mappings added automatically during the flow recording
In this subtopic you delete the Extract mappings from
the mapping routine for the Assign node variableAssignOutput in
the flow CheckItemAvailability.seqflow. These
mappings were added automatically to the mapping routine during flow
recording as a convenience when you created the Extract actions. (This
feature is controlled by the option Automatically expose
insert and extract variables in the interface operation messages,
see B. Begin the flow recording.)
In Step
3.2 you deleted the output variables referenced by these mappings
(see Output message).
Now you must also delete the mappings to avoid getting
compile errors when you compile the generated source code.
Note: The compiler would generate a compile error for each
of these mappings, because each mapping currently refers to a non-existing
variable.
To delete the mappings:
- Open CheckItemAvailability.seqflow in
the flow editor.
Open the mapping routine of the Assign node
variableAssignOutput in
the mapping editor:
In the flow editor right-click the Assign node variableAssignOutput.
Click Open Mapping Routine.
The
mapping editor opens the mapping file for the flow and
displays the mapping routine for the Assign node.
In the mapping routine delete each of the unconnected
mappings leading out of variables INQ1-ITEMREF through INQ15-ITEMREF
in the source message
v_CheckItemAvailability:
- Right-click the mapping.
- Click Delete.
At this point the mapping routine contains a source variable
and a target variable but does not contain any mappings.
Close the mapping editor if you wish, or leave
it open for the next subtopic.
Store a
return value into the output message
In this
subtopic you add to the mapping routine for the
Assign node variableAssignOutput a mapping
that copies a result value set in the While loop, indicating whether
the requested item number was found or not, into the output message
of CheckItemAvailability.seqflow.
Now a mapping is needed to copy the
result from v_CheckItemAvailability.available to o_CheckItemAvailability.available,
so that the result is returned to the invoking flow CatalogOrder.seqflow. To
create the mapping:
- Open CheckItemAvailability.seqflow in
the flow editor, if it is not already open.
In the flow message editor:
- Right-click the Assign node variableAssignOutput (see Figure 1).
- Click Open Mapping Routine. The mapping
editor opens the mapping file for the flow and displays the mapping
routine for the Assign node.
Currently this mapping routine should contain
the following items:
- Source messages: The only source message is v_CheckItemAvailability.
- Target messages: The only target message is o_CheckItemAvailability.
- Mappings: None
Create a mapping that copies the contents of
v_CheckItemAvailability.available into
o_CheckItemAvailability.available:
- Drag the variable available in the source
message to the variable available in the target
message.
- The mapping editor creates a Move transform
between the two variables. This transform copies the contents of the
source variable into the target variable.
Close the mapping editor.
Close the flow editor.
Add an alternate
path for remaining screens
In this subtopic
you add an alternate path to handle the scenario in which the While
node does not page through all the application screens in the multipage
list.
The current version of the flow works
correctly when the While loop does not find the requested item number,
but it works incorrectly when the While loop does find the requested
item number.
If the While loop does not find
the requested item number then the flow works correctly. The currently
displayed application screen is the
Exit Loop screen.
The flow of control goes from the While node to the parse node; the
parse node recognizes the currently displayed application screen as
the
Exit Loop screen; and the flow of control
goes from the first output terminal of the parse node to the following
Invoke screen operation node, which manages the
Exit Loop screen
(see
Figure 1).
Figure 1. CheckItemAvailability.seqflow
(before alternate path)
But if the requested item is found then
the flow does not work correctly. In this case the currently displayed
screen is not the Exit Loop screen but rather
is the screen that contains the requested item number (because the
While node terminates when it finds the requested item number). The
flow of control goes from the While node to the parse node as before,
but the parse node is unable to recognize the currently displayed
application screen and the flow of control goes out through the second
(and disconnected) output terminal of the parse node, causing a runtime
error.
To fix this problem a Switch node is added
to check whether the requested item number is found and to branch
accordingly. Follow these steps:
- Open CheckItemAvailability.seqflow in the
flow editor if it is not already open.
- Add the Switch node and its connections:
- Delete the connection going from the output terminal of the While
node to the parse node.
- Create a new Switch node and position it immediately to the right
of the While node.
- Rename the Switch node cAvailable.
- Make the following connections. You will have to rearrange some
of the nodes to keep the layout neat (see Figure 2):
- Connect the output terminal of the While node while_variable0 to
the input terminal of the Switch node cAvailable.
- Connect the first output terminal of the Switch
node to the input terminal of the parse node.
- Connect the second output terminal of the Switch
node to the input terminal of the Assign node variableAssignOutput.
Your flow should now look like
Figure 2:
Figure 2. CheckItemAvailability.seqflow
Open the ESQL expression for the topmost
output terminal of the Switch node
cAvailable:
- Right-click the Switch node.
- Click . The Edit
Expression window opens. The Messages in scope list
is empty and the expression input field is blank.
Add the variable
v_CheckItemAvailability to
the scope:
- Click Add. The Select Message window
opens.
- In the Select Message window click .
- Click OK.
The message v_CheckItemAvailability is
added to the scope.
Create an ESQL expression for the Switch node:
- Copy the short expression shown in Figure 3 into
the Expression input field of the Edit
Expression window. You should be able to copy and paste
the lines from this tutorial document directly into the Expression input field:
Figure 3. ESQL expression for
the Switch node named cAvailableNOT(v_CheckItemAvailability.available='YES')
This expression tests whether the variable v_CheckItemAvailability.available contains
the string 'YES' and then negates
the Boolean result using the NOT operator.
Recall that in the flow invoked by the While
node the variable v_CheckItemAvailability.available is
set to 'YES' if the requested item is found in the item-number column
of one of the application screens. (See the descriptions of the ESQL
expression in the Switch node and the mapping routine for the node Assign in Add a Switch node and an Assign node to the flow.)
In the ESQL expression in
Figure 3:
- If the variable is not equal to 'YES' then the expression evaluates
to Boolean true and the flow of control passes out of the first output
terminal of the Switch node and goes to the parse node.
In this
case the While loop has searched all the screens in the multipage
list without finding the requested item number and the Exit
Loop screen is displayed.
- If the variable is equal to 'YES' then the expression evaluates
to Boolean false and the flow of control passes out of the second
output terminal of the Switch node and goes directly to the variableAssignOutput node.
In
this case the While loop has found the item number and a screen of
the multipaged list is displayed.
Click OK to close the Edit
Expression window.