Focal Point
[SOLVED] How to merge two hold files.

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

June 24, 2009, 12:41 PM
Pku
[SOLVED] How to merge two hold files.
Hi all,

I have two hold files: HOLD1, HOLD2 which contains some IDs of HOLD1. After merging, the file should have all data of HOLD1, plus some data of HOLD2 which its IDs are in HOLD1.

Example:

HOLD1:
ID  DATE        AMOUNT
11  09/30/2008  100
22  09/30/2008  200
33  09/30/2008  300

HOLD2:
ID  DATE        AMOUNT
11  08/31/2008  110
12  08/31/2008  120
13  08/31/2008  123 
22  08/31/2008  234
33  08/31/2008  333
  
The result needs to be:

ID  DATE        AMOUNT
11  09/30/2008  100
11  08/31/2008  110
22  09/30/2008  200
22  08/31/2008  234
33  09/30/2008  300
33  08/31/2008  333


Thank you,
Pku

This message has been edited. Last edited by: Kerry,


Thanks,
Pku

Focus, WebFocus 8201 on Windows
June 24, 2009, 12:59 PM
j.gross
You can accomplish it with Match File (two merges, three data sources) as sketched below:

file hold1: by ID
file hold2: by id by date by amount
hold old-and-new
run
(yields the rows of hold2 with matching ID in hold1)

file hold1: by id by date by amount
hold old-or-new
end
(merges any rows of hold1 not already obtained from hold2)


- Jack Gross
WF through 8.1.05
June 24, 2009, 01:13 PM
Microfich
One way:

  
DEFINE FILE HOLD1
H1/A1 = '1';
END

MATCH FILE HOLD1
PRINT DATE AS DATE1 AMOUNT AS AMOUNT1 H1
BY ID
RUN
FILE HOLD2
PRINT DATE AS DATE2 AMOUNT AS AMOUNT2  
BY ID
AFTER MATCH HOLD AS HOLD3 OLD
END
-RUN

DEFINE FILE HOLD3
DATE/MDYY = IF H1 EQ '1' THEN DATE1 ELSE DATE2;
AMOUNT/I9 = IF H1 EQ '1' THEN AMOUNT1 ELSE AMOUNT2;
END

TABLE FILE HOLD3
PRINT ID DATE AMOUNT
END



WebFOCUS 8105
Windows;
DB2, UDB, SQL Server, Oracle
FOCUS-WebFOCUS since 1981
June 24, 2009, 02:47 PM
Doug
I like the alternatives that you provided Jack. Afterall, anything is possible...
July 01, 2009, 09:33 AM
Pku
Thanks, Jack and Microfich.

I used Jack's way with a bit of modification since the IDs could not be duplicated.
After matching HOLD2 to HOLD1 as HOLD3 as "OLD-AND-NEW". Then, I used "MORE" to merge HOLD1 back to HOLD3 to get the result.

  
TABLE FILE HOLD1
PRINT *
ON TABLE HOLD AS FINAL
MORE
FILE HOLD3
END


Thanks again,
Pku


Thanks,
Pku

Focus, WebFocus 8201 on Windows