Setting a dynamic element size in a flat structure - 8.0

Talend Data Mapper Functions Reference Guide

Version
8.0
Language
English
Product
Talend Big Data Platform
Talend Data Fabric
Talend Data Management Platform
Talend Data Services Platform
Talend MDM Platform
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
Design and Development > Designing Jobs
Last publication date
2023-10-26

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

  1. Create your structure:
    1. In the Hierarchical Mapper, right-click Structures and click New > Structure.
    2. In the wizard that opens, select Create a new structure where you manually enter elements and click Next.
    3. Select a folder and enter a name for your structure, then click Next.
    4. Select the Flat Files representation and click Next.
    5. Click Import a file as document and click Next.
    6. Browse to the relevant folder and select your flat file, then click Finish.
  2. Right-click the section on the left of your workspace and click New Element to create a root element.
  3. Right-click the root element and create three child elements named a, b and c.
    Your structure should look like this:
  4. 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.
  5. 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.
  6. Click the b element and drag and drop a SetElementProperty in its Util tab.
  7. Double-click the SetElementProperty and select Number of bytes in the Property drop-down list, then click OK.
  8. 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.