Use a SetElementProperty to define the size of an element based
on the value of another element in a flat file.
Before you begin
You have a flat file to use as sample document. You can create one from the sample
data provided below.
About this task
In this example, you have a flat file containing three elements named a
,
b
and c
. The a
element is an
integer that defines the size of the b
element. Since this size can
vary, you cannot set a fixed size in the b
element properties.
However, you still need to define its size to indicate where the b
element ends and the c
element starts.
You can use the following data for your sample
input:
03bbbcc
Procedure
-
Create your structure:
-
In the Hierarchical Mapper, right-click
Structures and click .
-
In the wizard that opens, select Create a new
structure where you manually enter elements and click Next.
-
Select a folder and enter a name for your structure, then click
Next.
-
Select the Flat Files representation and click
Next.
-
Click Import a file as document and click
Next.
-
Browse to the relevant folder and select your flat file, then click
Finish.
-
Right-click the section on the left of your workspace and click New Element to create a root element.
-
Right-click the root element and create three child elements named
a, b and
c.
Your structure should look like this:
-
Click the a element and enter 2
in both Size Min/Max fields, then select
Integer (32) in the Data Type
drop-down list.
This indicates that the a element is an integer with a fixed size
of two bytes. When clicking this element in the structure, 03
is highlighted in the Document tab.
-
Click the c element and enter 2
in both Size Min/Max fields.
These properties define a fixed size for the
c
element, however it is not highlighted in the
Document
tab because there is no information specifying where the
b
element ends and the
c
element starts.
-
Click the b element and drag and drop a
SetElementProperty in its Util
tab.
-
Double-click the SetElementProperty and select
Number of bytes in the
Property drop-down list, then click
OK.
-
Drag and drop the a element on the
Value argument.
This indicates that the size of the
b element is equal
to the value of the
a element.
Results
Your structure is now configured, when clicking the
b
element, the value
bbb
is highlighted in the
Document tab, and
cc
is highlighted when
clicking the
c element.