Focal Point
Joining Tables w/Flat Files

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

April 25, 2008, 11:33 AM
pbv
Joining Tables w/Flat Files
Hi,

I'm trying to join a flat file to some tables in a DB cause I need data out of both the tables and flat files. Here's the code:

-*****************Define flat file*****************
-SET &LOC = '/home/dppeda8/ibi/srv43/wfs/catalog';
FILEDEF ytf0656 DISK &LOC/ytf0656.txt
-**************************************************
-*********Join PO_HDR table to flat file************
JOIN
PO_HDR.PO_NBR TO ytf0656.PO_NBR AS J1
END
-***************************************************
-***************Join Oracle Tables********************
JOIN IPC AND PO_NBR IN PO_HDR TO IPC AND PO_NBR IN PO_LINE AS J3
*****************************************************
-IF &XPRT_SP EQ 'NO' THEN GOTO SCREEN ELSE GOTO EXCEL;
-SCREEN
TABLE FILE PO_HDR
HEADING CENTER
"Header Text Here"
PRINT
PO_NBR
PO_LINE_NBR AS 'PO LINE'
PO_LINE.DATE_CREATED AS 'LINE CREATED'
VENDOR_CODE AS 'VEND'
RECORDING_CO AS 'REC CO'
ITEM_ID
MR_REFERENCE_NBR
MR_LINE_NBR AS 'MR LINE'
DATE_NEEDED AS 'NEEDED'
DATE_RECEIVED AS 'RECEIVED'
QTY_PURCHASED AS 'QTY PURCH'
INVC_QTY
INVC_AMT
UNIT_PRICE
EXPEDITE_MESSAGE1
COST_ELEM_CODE AS 'CEC'
ORG_CODE
LOC_REMOTE
WORK_ORDER_NBR AS 'WO NUMB'
CHG_TO_ACCOUNT AS 'ACCT'
PO_LINE_STATUS AS 'LINE STAT'
DET_MSG1 AS 'Sub Labor Ops Region Code'

Thanks as always....


Webfocus 5.3.4, Unix, Oracle DB, Apache Tomcat
April 25, 2008, 11:49 AM
dballest
pbv,

What issue are you having? Getting errors?

Dan


Dev: WebFOCUS 7.6.10, Data Migrator 7.6.10
QA: WebFOCUS 7.6.10, Data Migrator 7.6.10
Prod: WebFOCUS 7.6.2, Data Migrator 7.6.8
Windows 2K3, Tomcat 5.5.17, IIS 6
Usage: HTML, PDF, Excel, Self-serve, BID and MRE
April 25, 2008, 11:55 AM
pbv
Getting no data. I know the values I'm inputting are fine because I'm using a PO_NBR from the flat file in my search...


Webfocus 5.3.4, Unix, Oracle DB, Apache Tomcat
April 25, 2008, 12:21 PM
Leah
quote:
JOIN
PO_HDR.PO_NBR TO ytf0656.PO_NBR AS J1
END


I don't think your join is correct you need to say IN ... TO ... IN ...


Leah
April 25, 2008, 04:31 PM
GinnyJakes
Your join syntax is incorrect for WebFOCUS.

Also, and of more importance, you should NEVER join flat files to DB2 or any relational engine. One technique is to extract the foreign keys from the flat file and put them in a SAVE file. Then use the WHERE IN FILE syntax against the DB2 file and hold that result in a FOCUS file with an index.

The SAVE file must be 16000 bytes max.

For example:
TABLE FILE flatfile
PRINT DST.PO_NBR
WHERE screening conditions
ON TABLE SAVE
END
TABLE FILE db2table
PRINT/SUM  whatever
WHERE DB2_PO_NBR IN FILE SAVE
etc.
END  


Now I did notice that you where using 2 fields to join on the DB2 table.

You might want to give us more information on that.


Ginny
---------------------------------
Prod: WF 7.7.01 Dev: WF 7.6.9-11
Admin, MRE,self-service; adapters: Teradata, DB2, Oracle, SQL Server, Essbase, ESRI, FlexEnable, Google
April 25, 2008, 04:46 PM
Darin Lee
Leah's comment would definitely cause your problem. Apart from that, there is one other issue I have run into when joining to flat files. If the field I am joining to is not in proper sort order in the flat file, I found that the join doesn't work sometimes. In other words, if you are joining to PO_NBR in ytf0656, then ytf0565 would need to be sorted in PO_NBR sequence.

May or may not be the problem - you'll have to fix the join first as Leah suggests, then see what you get.


Regards,

Darin



In FOCUS since 1991
WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex
Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex
WF Client: 77 on Linux w/Tomcat
April 25, 2008, 04:50 PM
Darin Lee
Found the reference from the manual that mentions the problem I was trying to describe:

In fixed sequential files, the cross-referenced field can be any field. However, both the host and cross-referenced file must be retrieved in ascending order on the named (key) field. If the data is not in the same sort order, errors are displayed. If the cross-referenced file contains only one segment, the host file must have a segment declaration.


Regards,

Darin



In FOCUS since 1991
WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex
Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex
WF Client: 77 on Linux w/Tomcat
April 27, 2008, 02:34 PM
Danny-SRL
Hi,
You can join a flat file to a relational table. It is the opposite that you cannot do. However, remember that when you join a flat file to a DB WebFocus does the JOIN and not the DB. So if your flat file is very big it will be slow.


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

April 27, 2008, 06:12 PM
Waz
In reality you can join from Flat to Relational or Relation to Flat.

There are some things that need to be taken into account.

1. For joining to a flat file, you file MUST be in the right order, if the join field is out of sequence, it will not match. A simple TABLE HOLD will fix this.

2. Joining from a flat file will cause many "Calls" to the realtional DB, which may be inefficient, always have extra WHERE clauses that filter on a column in the relational table, this will improve the performance.

I would suggest for your problem, do the following.



After this you should have more info on pinpointing the problem.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!