[CLOSED] Concatenate defines into a comma separated value.
Hi,
I have 10 define fields which is of A20 format. Now i want to create a field which concatenate all 10 define fields.
The issue i have is when concatenating using the operand ||','|| i get continuous comma when a define field is empty. I tried using TRIM with LEADING , TRAILING and BOTH options,but how can i remove the commas in between.
Any suggestions.This message has been edited. Last edited by: FP Mod Chuck,
WF8206,Windows 7,8,10 HTM,PDF,EXCEL
August 26, 2019, 02:29 PM
BabakNYC
Can you show us what you're seeing and what you expect? I'm not sure I understand what's happening when a define is empty.
WebFOCUS 8206, Unix, Windows
August 26, 2019, 02:45 PM
srajeevan
When i have DEF1, DEF2 and DEF6 as empty i get the output like.
,,DEF3,DEF4,DEF5,,,DEF7,DEF8,DEF9,DEF10
If i use TRIM_(LEADING, ',', DEF1 || ','|| DEF2 ||','|| DEF3 ||','|| DEF4 ||','|| DEF5 ||','|| DEF6 ||','|| DEF7 ||','|| DEF8 ||','|| DEF9 || ','||DEF11 ) ,i can get rid of the first two commas.
But when i have commas between define outputs,TRIM won't help.
I am working in 8105 currently(for this issue) and it seems like 8105 don't have REPLACE function.
Also it will replace all the commas i think.
WF8206,Windows 7,8,10 HTM,PDF,EXCEL
August 26, 2019, 04:42 PM
Waz
Check out the documentation on functions.
Look at STRREP for example.
The other option you have is to create an intermediate define field for each testing for blank, and either leaving as blank or adding the comma, then combine.
Waz...
Prod:
WebFOCUS 7.6.10/8.1.04
Upgrade:
WebFOCUS 8.2.07
OS:
Linux
Outputs:
HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!
August 26, 2019, 04:53 PM
srajeevan
Okay @Waz. I did use STRREP ,but it work similar to REPLACE. I am thinking of moving forward with the other option you mentioned.
WF8206,Windows 7,8,10 HTM,PDF,EXCEL
August 26, 2019, 05:03 PM
Waz
Yes, its probably the more robust option.
Waz...
Prod:
WebFOCUS 7.6.10/8.1.04
Upgrade:
WebFOCUS 8.2.07
OS:
Linux
Outputs:
HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!
August 26, 2019, 08:00 PM
Hallway
quote:
The other option you have is to create an intermediate define field for each testing for blank, and either leaving as blank or adding the comma, then combine.
Agreed. And then use the TRIM_ function to remove the trailing comma. Something like this:
DEFINE FILE master
DEF1/A4 = IF Field1 EQ '' THEN '' ELSE Field1 || ',';
DEF2/A4 = IF Field2 EQ '' THEN '' ELSE Field2 || ',';
DEF3/A4 = IF Field3 EQ '' THEN '' ELSE Field3 || ',';
DEF4/A4 = IF Field4 EQ '' THEN '' ELSE Field4 || ',';
DEF5/A4 = IF Field5 EQ '' THEN '' ELSE Field5 || ',';
DEF6/A4 = IF Field6 EQ '' THEN '' ELSE Field6 || ',';
DEF7/A4 = IF Field7 EQ '' THEN '' ELSE Field7 || ',';
DEF8/A4 = IF Field8 EQ '' THEN '' ELSE Field8 || ',';
DEF9/A4 = IF Field9 EQ '' THEN '' ELSE Field9 || ',';
CONCAT/50V = TRIM_(TRAILING, ',', DEF1||DEF2||DEF3||DEF4||DEF5||DEF6||DEF7||DEF8||DEF9);
END