Author |
Message
|
18tillidie |
Posted: Tue Jul 21, 2020 6:57 am Post subject: DFDL Double Quotes for NULL or any value for CSV |
|
|
Newbie
Joined: 04 May 2020 Posts: 9
|
Hi I am new to IIB,
Need help in sending "" (double quotes in case the value is NULL, or any value with double quotes.)
I have 2 DFDLs created Input and Output I am using the below code to map and generate .csv output file. I need to send double quotes in case the SET value is NULL and I am using the below code.
SET refToOutput.TEST_DFDL[i].Name=COALESCE(reftoInput.Name,'""');
This shows as """""" in output when I send single double quote I get """"
OR for any value
SET refToOutput.TEST_DFDL[i].Doc_NBR=COALESCE(reftoInput.FileNum,'"TRY"');
Output for this is getting generated as """TRY""" instead of "TRY"
Any help would be much appreciated. |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Jul 21, 2020 7:10 am Post subject: Re: DFDL Double Quotes for NULL or any value for CSV |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
18tillidie wrote: |
Hi I am new to IIB,
Need help in sending "" (double quotes in case the value is NULL, or any value with double quotes.)
I have 2 DFDLs created Input and Output I am using the below code to map and generate .csv output file. I need to send double quotes in case the SET value is NULL and I am using the below code.
SET refToOutput.TEST_DFDL[i].Name=COALESCE(reftoInput.Name,'""');
This shows as """""" in output when I send single double quote I get """"
OR for any value
SET refToOutput.TEST_DFDL[i].Doc_NBR=COALESCE(reftoInput.FileNum,'"TRY"');
Output for this is getting generated as """TRY""" instead of "TRY"
Any help would be much appreciated. |
So what happens if you use:
Code: |
SET refToOutput.TEST_DFDL[i].Doc_NBR=COALESCE(reftoOpGtInput.FileNum,'TRY');
|
Have you tried it ?  _________________ MQ & Broker admin |
|
Back to top |
|
 |
18tillidie |
Posted: Tue Jul 21, 2020 7:12 am Post subject: |
|
|
Newbie
Joined: 04 May 2020 Posts: 9
|
'TRY' comes out as only TRY I need it in double quotes. |
|
Back to top |
|
 |
18tillidie |
Posted: Tue Jul 21, 2020 7:15 am Post subject: |
|
|
Newbie
Joined: 04 May 2020 Posts: 9
|
18tillidie wrote: |
'TRY' comes out as only TRY I need it in double quotes. |
Forgot to mention I am opening the csv file in notepad ++ |
|
Back to top |
|
 |
timber |
Posted: Tue Jul 21, 2020 8:01 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
When writing delimited data like CSV, the DFDL 'escape scheme' comes into play. CSV formats use a standard escape scheme that works like this:
- normal values are output unchanged
- values that contain a comma or a line-end character get escaped by putting double quotes around the value.
- empty string values are not[ escaped with "". They just result in two commas together.
These rules are as close as you will get to an industry-standard for CSV.
You can tweak the escape scheme settings, but I don't know if you will be able to achieve exactly what you are trying to do. Are you
a) trying to represent an empty string as "", but other values without quotes
b) trying to put quotes around all values
c) something else |
|
Back to top |
|
 |
18tillidie |
Posted: Tue Jul 21, 2020 9:51 am Post subject: |
|
|
Newbie
Joined: 04 May 2020 Posts: 9
|
Issue Resolved, Thank you @timber owe you
Went to the DFDL - http://www.ibm.com/dfdl/CommaSeparatedFormat >> Schema location in the Library project >> opened with DFDL editor >> Under Representation Properties changed values for Escape Block Start and Escape Block End from " to ,
Deployed and tested code it worked like a charm. Thanks again. I LOVE MQSERIES.NET.  |
|
Back to top |
|
 |
timber |
Posted: Tue Jul 21, 2020 3:06 pm Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Thanks for the feedback. I hate to say this, but I don't think that's anywhere near the correct solution. In fact, I would be surprised if it outputs the correct number of commas in all circumstances.
The problem is, the Escape Block Start is definitely NOT a delimiter. But the comma definitely is. Arguably, the DFDL validator should complain about using a comma in the EBS property.
Also, less seriously, you have edited the global settings for DFDL. The correct way to do it would be to declare your own Escape Scheme (by copying the one in the IBM-supplied schema) and apply your own settings there. Then adjust the 'default format block' in your own schema to point at it. |
|
Back to top |
|
 |
|