Focal Point
[SOLVED] Concatenate multiple occurrences of a field

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/9477036676

June 09, 2015, 12:03 PM
AprilC
[SOLVED] Concatenate multiple occurrences of a field
I am doing a query to get data fields to put together as a message table. The data in the table would have message number, line number, and text. I am getting the data out of the table but then want to concatenate the text by message number and line number into 1 field. For example:

message number line number text
1 1 This is the
1 2 first paragraph
1 3 of information.
2 1 This is the
2 2 second paragraph.

What I want in the end is to be able to create a table that has 2 rows:
This is the first paragraph of information.
This is the second paragraph.

I could have multiple message numbers and multiple line numbers within what I'm getting back from db2. Can anyone help with how I can accomplish this?

This message has been edited. Last edited by: <Kathryn Henning>,


WebFOCUS 8.1.04
Windows, All Outputs
June 09, 2015, 02:31 PM
Francis Mariani
Here is a working example.

I first create a data file to simulate your db2 table. Then I create a Master for the file. The first TABLE FILE.. HOLD ensures that the data rows are in the correct order. The DEFINE FILE concatenates the multiple occurrences, the TABLE FILE... SUM outputs the paragraphs.


FILEDEF MY_DB2_TABLE DISK my_db2_table.txt
-RUN

-WRITE MY_DB2_TABLE 1 1 This is the
-WRITE MY_DB2_TABLE 1 2 first paragraph
-WRITE MY_DB2_TABLE 1 3 of information.
-WRITE MY_DB2_TABLE 2 1 This is the
-WRITE MY_DB2_TABLE 2 2 second paragraph.

FILEDEF MASTER DISK my_db2_table.mas
-RUN

-WRITE MASTER FILENAME=MY_DB2_TABLE, SUFFIX=FIX, $
-WRITE MASTER SEGNAME=MY_DB2_TABLE, $
-WRITE MASTER FIELDNAME=MESSAGE_NUMBER, FORMAT=I1 , ACTUAL=A1 , $
-WRITE MASTER FIELDNAME=FILL1         , FORMAT=A1 , ACTUAL=A1 , $
-WRITE MASTER FIELDNAME=LINE_NUMBER   , FORMAT=I1 , ACTUAL=A1 , $
-WRITE MASTER FIELDNAME=FILL2         , FORMAT=A1 , ACTUAL=A1 , $
-WRITE MASTER FIELDNAME=MESSAGE_TEXT  , FORMAT=A20, ACTUAL=A20, $

TABLE FILE MY_DB2_TABLE
PRINT
MESSAGE_TEXT

BY MESSAGE_NUMBER
BY LINE_NUMBER
ON TABLE HOLD AS HOLD001
END
-RUN

DEFINE FILE HOLD001
MESSAGE_TEXT_OUT/A500V = IF MESSAGE_NUMBER EQ LAST MESSAGE_NUMBER THEN MESSAGE_TEXT_OUT || (' ' | MESSAGE_TEXT) ELSE MESSAGE_TEXT;
END
-RUN

TABLE FILE HOLD001
SUM
MESSAGE_TEXT_OUT
BY MESSAGE_NUMBER NOPRINT
END
-RUN



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
June 09, 2015, 04:18 PM
AprilC
Thank you Francis! This gives me exactly what I need.


WebFOCUS 8.1.04
Windows, All Outputs