Author |
Message
|
amiivas |
Posted: Fri Dec 18, 2009 1:46 pm Post subject: Deleting fields where field path is set in a character |
|
|
Apprentice
Joined: 14 Oct 2007 Posts: 44 Location: Texas, USA
|
Hi,
I want to delete a field whose position is defined in a character.
For e.g, this is the tree structure: OutputRoot.XMLNSC.Company.Name.FirstName;
I am getting this path stored in a character. say
DECLARE absPath CHARACTER 'OutputRoot.XMLNSC.Company.Name.FirstName';
whenever I am using DELETE or DETACH stmts, like DELETE FIELD abPath;
or DETACH absPath;
It give me a 'Inappropriate field reference'
Thanks, |
|
Back to top |
|
 |
rekarm01 |
Posted: Sat Dec 19, 2009 2:29 pm Post subject: Re: Deleting fields where field path is set in a character |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
Declare abspath as a REFERENCE, instead of a CHARACTER. |
|
Back to top |
|
 |
amiivas |
Posted: Sat Dec 19, 2009 3:17 pm Post subject: |
|
|
Apprentice
Joined: 14 Oct 2007 Posts: 44 Location: Texas, USA
|
In the actual issue, this absPath is build rather than just declared. The building of absPath is done by adding multiple FieldNames during the tree traversal. _________________ IBM WebSphere Certified Solution Developer |
|
Back to top |
|
 |
mqjeff |
Posted: Sat Dec 19, 2009 6:48 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You can only use DELETE and DETACH with REFERENCE variables.
It therefore doesn't matter what or how you have built the contents of a CHARACTER variable.
If! absPath contained only the name of a single field, you could use {} as part of a MOVE statement.
If you insist on using a CHARACTER variable and building a multi-level hierarchical name in that CHARACTER variable, you will have to use the non-performant EVALUATE function to construct a MOVE statement to point a REFERENCE variable.
I recommend rethinking your approach, however. |
|
Back to top |
|
 |
amiivas |
Posted: Sat Dec 19, 2009 7:51 pm Post subject: |
|
|
Apprentice
Joined: 14 Oct 2007 Posts: 44 Location: Texas, USA
|
Yes, Eval is an expensive statement and that will help but I would not like to use as the function has to be performed on many fields references.
I am actually looking for a way, not to create parent node if value of child node is not present. The thought of passing the output tree to a recursive function in which save the path of that field which does not have a value and delete that field so that parent of that child is also not created, posed the above question of deleting field whose path is stored in character.
Coming back to my original issue, SET creates the tree till the point of last but one field and only create the last field if it has value. This property is actually creating empty tags [parent] in output xml which is not required.
I don't want to use a null check or exist fn for every field as there are around more than 500 fields . Any fast work around solution is appreciated or else I have to go back for manual coding of many IFs.
Thanks - Amit _________________ IBM WebSphere Certified Solution Developer |
|
Back to top |
|
 |
kimbert |
Posted: Sun Dec 20, 2009 2:26 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
I don't want to use a null check or exist fn for every field as there are around more than 500 fields . Any fast work around solution is appreciated or else I have to go back for manual coding of many IFs |
Maybe you could write a function which takes a source reference and a target reference. It sets the value of the target reference if and only if the source value is not NULL/empty string. No need for 500 IF statements. |
|
Back to top |
|
 |
|