Topic
  • 8 replies
  • Latest Post - ‏2018-11-19T17:49:49Z by kimber_t
RaviBhogaraju
RaviBhogaraju
2 Posts

Pinned topic How to transform an XML message to a COBOL copybook messages that has NULL values without using COALESCE function.

‏2016-11-07T16:54:41Z | coalesce cobol copybook dfdl esql nillable null xml

I am trying to convert an XML message (Input Message) to a COBOL copybook (Output message) using a Compute node. As most of you know, a COBOL copybook is a fixed length file format.

 

If I directly assign an element in the XML message (Input) to a COBOL copybook field (Output), the COBOL copybook field is nullified when the XML element is null (eg: <middlename\>). This is causing the next field in the COBOL copybook to take the space of the current element thus disrupting the Message format.  I can use COALESCE function to avoid this situation but then I have to use it for every COBOL copybook field that is getting its value from the Input XML element because there is a potential for any of the XML elements in the Input to be null. 

 

Using COALESCE function for every COBOL copybook field doesn't seem to me like a elegant solution. I also tired using the Nillable property in the DFDL message when creating the Message Model for the COBOl copybook. Below are my Nillble properties I set in the DFDL. 

Nillable -> True

Nil Kind -> literalCharacter

Nil Value -> %SP

Use Nil for Default -> no

 

But that didn't work either.  I am wondering if anyone came across a similar situation and if so please let me know if there is a better way to handle this. 

 

Regards,

Ravi.

  • lancelotlinc
    lancelotlinc
    485 Posts

    Re: How to transform an XML message to a COBOL copybook messages that has NULL values without using COALESCE function.

    ‏2016-11-07T17:18:36Z  

    You mean, COALESCE does not work for you ? Thats the whole point of that function. And its easy to use through copy&paste code generation. Seems someone might be lazy... :(

     

  • RaviBhogaraju
    RaviBhogaraju
    2 Posts

    Re: How to transform an XML message to a COBOL copybook messages that has NULL values without using COALESCE function.

    ‏2016-11-07T17:43:00Z  

    You mean, COALESCE does not work for you ? Thats the whole point of that function. And its easy to use through copy&paste code generation. Seems someone might be lazy... :(

     

    You truly seem be from from Stone age lancelothinc..... I said " doesn't seem to me like a elegant solution". It is not a issue of copy & pasting or being lazy. You should probably consider taking English classes. :(

  • lancelotlinc
    lancelotlinc
    485 Posts

    Re: How to transform an XML message to a COBOL copybook messages that has NULL values without using COALESCE function.

    ‏2016-11-08T12:23:55Z  

    You truly seem be from from Stone age lancelothinc..... I said " doesn't seem to me like a elegant solution". It is not a issue of copy & pasting or being lazy. You should probably consider taking English classes. :(

    Hence my moniker lancelotlinc and my photo of Caveman.

     

    No one ever promised you a turnkey solution for NULL values. COALESCE works well for that. 

  • SupriyoDebnath
    SupriyoDebnath
    27 Posts

    Re: How to transform an XML message to a COBOL copybook messages that has NULL values without using COALESCE function.

    ‏2016-12-14T16:01:42Z  

    Hi RaviBhogaraju

    I don't understand why on earth you think that COALESCE is not an elegant solution. Though there are other ways, you can try the ouput COBOL field with occurrence as [0,1] and keep the padKind property value as padChar. That should maintain the explicit length of the field.

  • fjb_saper
    fjb_saper
    159 Posts

    Re: How to transform an XML message to a COBOL copybook messages that has NULL values without using COALESCE function.

    ‏2017-01-02T17:08:48Z  

    How about using the VALUE solution?

    So if your code says

    SET abc.myfield VALUE = efg.theirfield;
    

    You will still get a NULL value for abc.myfield if efg.theirfield is null. Without the VALUE addendum abc.myfield would be removed from the tree...

    Enjoy

  • kimbetr
    kimbetr
    3 Posts

    Re: How to transform an XML message to a COBOL copybook messages that has NULL values without using COALESCE function.

    ‏2017-01-02T20:56:47Z  

    DFDL is specifically designed to cope with your scenario. Are you 100% sure that these 'null' XML fields are being represented by a NULL value in the message tree? ( please supply proof ).

     

     

  • NSG
    NSG
    1 Post

    Re: How to transform an XML message to a COBOL copybook messages that has NULL values without using COALESCE function.

    ‏2018-11-15T16:12:09Z  

    Hi Ravi,

    Is this issue resolved ? I got same thing now.

  • kimber_t
    kimber_t
    11 Posts

    Re: How to transform an XML message to a COBOL copybook messages that has NULL values without using COALESCE function.

    ‏2018-11-19T17:49:49Z  

    DFDL will write a special value for NULL if and only if the value in the message tree is the special value NULL.

    An element that is missing from the message tree is not 'null'.

    An element which has '' (the empty string) as its value is not 'null'

     

    Hope that helps.