Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Optional elements in XML transformation

Former Member
0 Likes
3,355

Hi,

I call a transformation ( defined in STRANS ) that has as source a XML document and as destination several Abap variables.

I have a dump when transforming the XML, because some elements sometime do not exist in XML to transform.

For example, if the element <fax tt:value-ref="$REF.C250"/> of the bellow example does not exist in a XML, how can i preview it ? How do I don't have problem if tag <fax> does not exist

I know there's a property minOccurs="0", I've seen in several forums but I don't know how to adapt it to the bellow example. Can anyone help me solve this problem.

Thanks,

Paulo Sousa

EXAMPLE ( part of my transformation 😞

<?sap.transform simple?>

<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined">

<tt:root name="ZSHSTXML_EMPRESA" type="ddic:ZSHSTXML_EMPRESA"/>

<tt:root name="ZSHSTXML_SST_C140" type="ddic:CHAR1000SF"/>

<tt:root line-type="ddic:ZSHSTXML_ESTABL" name="ZSHSTXML_ESTABL"/>

<tt:root line-type="ddic:ZSHSTXML_ACTVHST" name="ZSHSTXML_ACTVHST"/>

<tt:root line-type="ddic:ZSHSTXML_SRV_SST" name="ZSHSTXML_SRV_SST"/>

<tt:root line-type="ddic:ZSHSTXML_MEDICOS" name="ZSHSTXML_MEDICOS"/>

<tt:root line-type="ddic:ZSHSTXML_TEC_SHT" name="ZSHSTXML_TEC_SHT"/>

<tt:root line-type="ddic:ZSHSTXML_ACTIVID" name="ZSHSTXML_ACTIVID"/>

<tt:root line-type="ddic:ZSHSTXML_CONSULT" name="ZSHSTXML_CONSULT"/>

<tt:root line-type="ddic:ZSHSTXML_INFO" name="ZSHSTXML_INFO"/>

<tt:root line-type="ddic:ZSHSTXML_FORMAC" name="ZSHSTXML_FORMAC"/>

<tt:root line-type="ddic:ZSHSTXML_RFISICO" name="ZSHSTXML_RFISICO"/>

<tt:root line-type="ddic:ZSHSTXML_RQUIMIC" name="ZSHSTXML_RQUIMIC"/>

<tt:root line-type="ddic:ZSHSTXML_RBIOLOG" name="ZSHSTXML_RBIOLOG"/>

<tt:root line-type="ddic:ZSHSTXML_RMUSCUL" name="ZSHSTXML_RMUSCUL"/>

<tt:root line-type="ddic:ZSHSTXML_RPSICOS" name="ZSHSTXML_RPSICOS"/>

<tt:root line-type="ddic:ZSHSTXML_ROUTROS" name="ZSHSTXML_ROUTROS"/>

<tt:root line-type="ddic:ZSHSTXML_EXAMES" name="ZSHSTXML_EXAMES"/>

<tt:root line-type="ddic:ZSHSTXML_EXCOMPL" name="ZSHSTXML_EXCOMPL"/>

<tt:root line-type="ddic:ZSHSTXML_IMUNIZA" name="ZSHSTXML_IMUNIZA"/>

<tt:root line-type="ddic:ZSHSTXML_PROMOST" name="ZSHSTXML_PROMOST"/>

<tt:root line-type="ddic:ZSHSTXML_ACIDTRA" name="ZSHSTXML_ACIDTRA"/>

<tt:root line-type="ddic:ZSHSTXML_DOENCAP" name="ZSHSTXML_DOENCAP"/>

<tt:root line-type="ddic:ZSHSTXML_DOENCAC" name="ZSHSTXML_DOENCAC"/>

<tt:root line-type="ddic:ZSHSTXML_RFMEDID" name="ZSHSTXML_RFMEDID"/>

<tt:root line-type="ddic:ZSHSTXML_RQMEDID" name="ZSHSTXML_RQMEDID"/>

<tt:root line-type="ddic:ZSHSTXML_RBMEDID" name="ZSHSTXML_RBMEDID"/>

<tt:root line-type="ddic:ZSHSTXML_RMMEDID" name="ZSHSTXML_RMMEDID"/>

<tt:root line-type="ddic:ZSHSTXML_RPMEDID" name="ZSHSTXML_RPMEDID"/>

<tt:root line-type="ddic:ZSHSTXML_ROMEDID" name="ZSHSTXML_ROMEDID"/>

<tt:root line-type="ddic:ZSHSTXML_EXCMEDI" name="ZSHSTXML_EXCMEDI"/>

<tt:template>

<entity_data xmlns="http://www.gep.mtss.gov.pt/sguri/ru" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<active_estabs>

<tt:attribute name="year_ref" value-ref=".ZSHSTXML_EMPRESA.ANO"/>

... SOME LINES I'VE REMOVED. I BELIEVE NOT RELEVANT

<estabs>

<tt:loop ref="ZSHSTXML_ESTABL">

<estab>

<estab_id>

<tt:value ref="$REF.ID"/>

</estab_id>

<dcf tbl="RU_DCF">

<tt:value ref="$REF.C230"/>

</dcf>

<dcf_description>

<tt:value ref="$REF.C231"/>

</dcf_description>

<country tbl="RU_CODPAIS">

<tt:value ref=".ZSHSTXML_SST_C140"/>

</country>

<country_description>

<tt:value ref=".ZSHSTXML_SST_C140"/>

</country_description>

<phone tt:value-ref="$REF.C240" />

<fax tt:value-ref="$REF.C250"/>

<email tt:value-ref="$REF.C260"/>

<cae tbl="RU_CAE_5DIG">

<tt:value ref="$REF.C300"/>

</cae>

<cae_description>

<tt:value ref="$REF.C301"/>

</cae_description>

</estab>

</tt:loop>

</estabs>

</entity>

</entity_data>

</tt:template>

</tt:transform>

1 ACCEPTED SOLUTION
Read only

brad_bohn
Active Contributor
1,730

Can't see your example - are you using XSLT or ABAP ST? For ABAP ST, you can make a node in the template conditional as follows:


        <tt:cond frq="?">
          <Location>
            <tt:value ref="LOCATION"/>
          </Location>
        </tt:cond>

3 REPLIES 3
Read only

brad_bohn
Active Contributor
1,731

Can't see your example - are you using XSLT or ABAP ST? For ABAP ST, you can make a node in the template conditional as follows:


        <tt:cond frq="?">
          <Location>
            <tt:value ref="LOCATION"/>
          </Location>
        </tt:cond>

Read only

0 Likes
1,730

Hi brad.bohn.


I am also facing similar issue when trying to upload multiple XML files using ST in abap.

how to check optional tags?

could you please help me if you have any solution on above?

i tried as below: transformation logic:

Read only

0 Likes
1,730

XML FILES as below: