cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a file with "n" headers and details

Former Member
0 Kudos

I want to create a file with various headers and details:

Example:

50000 AAAAA <- header

50000 1 a1 <- details

50000 2 a2

50000 3 a3

50001 BBBBB <- header

50001 1 b1 <- details

50001 2 b2

50001 3 b3

50002 CCCCC <- header

50002 1 c1 <- details

50002 2 c2

50002 3 c3

But, I need to get the values using a RFC (Sender). This values are in two tables: header and detail

...

<header>

<item>

<id></id>

<text></text>

</item>

</header>

<detail>

<item>

<id></id>

<id_item></id_item>

</text>

</item>

</detail>

...

How I create this file doing a relation between "id" fields?

Message was edited by: Evandro Klen Stephen de Azeredo

Accepted Solutions (1)

Accepted Solutions (1)

stefan_grube
Active Contributor
0 Kudos

Hi Evandro,

When you are sure, that for every entry in header, there is an entry in item and vice verca, then it is very easy.

First you need a structure, you can use for content conversion for the file adapter.

Create a data type like this:

Target
  row (1..unbounded)
    header (1..1)
      id
      text
    item (1..unbounded)
      id
      id_item
      text

The trick is, that the content conversion does not care, how often the <row> is available. It needs to be there at least one time, but it does not matter, if it appears more often.

The elements are just mapped one by one, the nodes are mapped like this:

item(header) - row
constant - header 
id(item) - removeContexts - SplitByValue(valueChanged) - item

The output of the mapping is:

<Target>
 <b><row></b>
 <header>
  <id>50000</id> 
  <text>AAAAA</text> 
  </header>
 <item>
  <id>50000</id> 
  <id_item>1</id_item> 
  <text>a1</text> 
  </item>
 <item>
  <id>50000</id> 
  <id_item>2</id_item> 
  <text>a2</text> 
  </item>
 <item>
  <id>50000</id> 
  <id_item>3</id_item> 
  <text>a3</text> 
  </item>
  <b></row></b>
 <b><row></b>
 <header>
  <id>50001</id> 
  <text>BBBBB</text> 
  </header>
 <item>
  <id>50001</id> 
  <id_item>1</id_item> 
  <text>b1</text> 
  </item>
...

which can easily be converted with the content conversion of the file adapter.

Regards

Stefan

Former Member
0 Kudos

Stefan,

I has this Data Type:

SourceList
  header
    item
      id
      text
  itens
    item
      id
      id_item
      text

And I created this Data Type:

TargetList  
  row (1..unbounded)    
    header (1..1)      
      id      
      text    
    item (1..unbounded)      
      id      
      id_item      
      text

Mapping:

SourceList          ->     TargetList  
header            <None>
    item            ->     row
            [Constant] ->  header
      id            ->     header/id           
      text          ->     header/text
  itens           <None>  
    item          <None>              
      id          removeContext -> splitByValue -> item
      id          ->       item/id
      id_item     ->       item/id_item
      text        ->       item/text

In test, I entry with the folowing data:

<?xml version="1.0" encoding="UTF-8"?>

<p2:SourceList xmlns:p2="urn:spasa_edi.edi">
   <cabecalho>
      <item>
         <id>1</id>
         <texto>A</texto>
      </item>
      <item>
         <id>2</id>
         <texto>B</texto>
      </item>
   </cabecalho>
   <itens>
      <item>
         <id>1</id>
         <id_item>1</id_item>
         <texto>AAA</texto>
      </item>
      <item>
         <id>1</id>
         <id_item>2</id_item>
         <texto>AAA</texto>
      </item>
      <item>
         <id>2</id>
         <id_item>1</id_item>
         <texto>BBB</texto>
      </item>
   </itens>
</p2:SourceList>

And the result was:

<?xml version="1.0" encoding="UTF-8"?>
<p2:TargetList xmlns:p2="urn:spasa_edi.edi">
<row>
  <header>
    <id>1</id>
    <text>A</text>
  </header>
  <item>
    <id>1</id>
    <id_item>1</id_item>
    <text>AAA</text>
  </item>
</row>
<row>
  <header>
    <id>2</id>
    <text>B</text>
  </header>
  <item>
    <id>1</id>
    <id_item>2</id_item>
    <text>AAA</text>
    </item>
</row>
</p2:TargetList>

But It's doing a mapping "1 to 1"

The result must be:

<?xml version="1.0" encoding="UTF-8"?>
<p2:TargetList xmlns:p2="urn:spasa_edi.edi">
<row>
  <header>
    <id>1</id>
    <text>A</text>
  </header>
  <item>
    <id>1</id>
    <id_item>1</id_item>
    <text>AAA</text>
  </item>
  <item>
    <id>1</id>
    <id_item>2</id_item>
    <text>AAA</text>
  </item>
</row>
<row>
  <header>
    <id>2</id>
    <text>B</text>
  </header>
  <item>
    <id>2</id>
    <id_item>1</id_item>
    <text>BBB</text>
  </item>
</row>
</p2:TargetList>

Thank you.

stefan_grube
Active Contributor
0 Kudos

Hi Evandro,

did you change the attributes of the function <i>SplitByValue</i> to <i>valueChanged</i>?

(Doppel click on the function)

Regards

Stefan

Former Member
0 Kudos

I forgot to do this!!!!

Now is perfect!

Thank you!

Answers (0)