As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.
Join the TIBCO Community TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.
From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
Request access to the private WebFOCUS User Group (login required) to network with fellow members.
Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.
I had difficulty finding a subject for this post as I do not know to briefly formulate my request. I have a request for a complex report. Let me explain through an example on CAR table.
Let me first start with a simple example:
TABLE FILE CAR
SUM CNT.SALES
BY CAR
ACROSS COUNTRY
END
gives the following report:
COUNTRY
ENGLAND FRANCE ITALY JAPAN W GERMANY
CAR
ALFA ROMEO 0 0 3 0 0
AUDI 0 0 0 0 1
BMW 0 0 0 0 6
DATSUN 0 0 0 1 0
JAGUAR 2 0 0 0 0
JENSEN 1 0 0 0 0
MASERATI 0 0 1 0 0
PEUGEOT 0 1 0 0 0
TOYOTA 0 0 0 1 0
TRIUMPH 1 0 0 0 0
Now I have a separate table COUNTRIES containing the following data:
COUNTRY POPULATION
ENGLAND 1111111
FRANCE 2222222
ITALY 3333333
JAPAN 4444444
NETHERLANDS 5555555
W GERMANY 6666666
So the challenge is to get the population per country in EVERY ROW/CELL, and also add those countries (like NETHERLANDS) where there are no Car Sales at all. This is not an outer join from COUNTRIES to CARS, because then the Population will only show on cells where Car Sales > 0 and NETHERLANDS will be on a row with CAR = MISSING. Neither is it a full cartesion product as there is a matching attribute COUNTRY.
Is it possible to make this with some kind of conditional join? Or should it be done some MATCH statements? Can anyone assist to find the right direction.
Martin.This message has been edited. Last edited by: Martin vK,
WebFocus 8206M, iWay DataMigrator, Windows, DB2 Windows V10.5, MS SQL Server, Azure SQL, Hyperstage, ReportCaster
ENGLAND 11111
FRANCE 22222
ITALY 33333
JAPAN 44444
W GERMANY 55555
NETHERLAND66666
I add NETHERLAND as it doesn't exist in CAR database.
Here is the FEX :
-*I extract the PAYS and population information
TABLE FILE LSTCOUNTRY
SUM POPULATION
BY PAYS
ON TABLE HOLD AS T1 FORMAT ALPHA
END
-RUN
-*I create a loop using Dialog manager in order to list all available cars from CAR database and I store the result into GLOBAL
-*Out file
APP FI GLOBAL DISK global.ftm (APPEND
-RUN
-SET &CPT = 0 ;
-SET &NB_LOOP = &LINES ;
-LOOP
-READ T1 &COUNTRY.10. &POPULATION.5.
-*Get my car informations
DEFINE FILE CAR
PAYS/A10 = '&COUNTRY' ;
CLE/A26 = PAYS || CAR ;
END
TABLE FILE CAR
PRINT
COMPUTE POPULATION/I5 = &POPULATION ;
BY CLE
BY PAYS
BY CAR
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE HOLD AS GLOBAL FORMAT ALPHA
END
-*
-SET &CPT = &CPT + 1 ;
-IF &CPT GT &NB_LOOP GOTO SORTIE ELSE LOOP ;
-SORTIE
-*Now I have a file with a unique key and all cars for each country
-*I generate my SALES count based on CAR master
DEFINE FILE CAR
CLE/A26 = COUNTRY || CAR ;
END
TABLE FILE CAR
SUM CNT.SALES AS 'VENTES'
BY CLE
BY COUNTRY
BY CAR
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE SET ASNAMES FOCUS
ON TABLE HOLD AS STEP1 FORMAT FOCUS INDEX CLE
END
-RUN
-*I join all my possibilities to existing cases
JOIN CLE IN GLOBAL TO CLE IN STEP1
TABLE FILE GLOBAL
SUM MAX.VENTES AS 'VENTES' MAX.POPULATION AS 'Population'
BY CAR
ACROSS PAYS
END
That's it
I can send you the files if you wish
8207, Windows 2016 64b, HTML, AHTML, PDF, EXL07...
Posts: 27 | Location: Suresnes | Registered: August 26, 2010
Like Francis, my mind immediately went to MATCH until I realised the cartesian nature of the data required.
So I fell back on McGyver technique (ala Noreen & Art) -
Try this code -
APP FI CTRYPOP DISK CTRYPOP.MAS (LRECL 80
-RUN
-WRITE CTRYPOP
-WRITE CTRYPOP FILE=CTRYPOP,SUFFIX=FOC
-WRITE CTRYPOP SEGNAME=SEG1
-WRITE CTRYPOP FIELD=COUNTRY, ,A10 ,A10 ,$
-WRITE CTRYPOP FIELD=POPULATION, ,I9 ,I9 ,$
-RUN
CREATE FILE CTRYPOP
MODIFY FILE CTRYPOP
FIXFORM COUNTRY/A10 POPULATION/A9
DATA
ENGLAND 1111111
FRANCE 2222222
ITALY 3333333
JAPAN 4444444
NETHERLAND 5555555
W GERMANY 6666666
END
-RUN
DEFINE FILE CTRYPOP
MCGYVER/A1 = 'x';
END
DEFINE FILE CAR
MCGYVER/A1 WITH COUNTRY = 'x';
CTRYCAR/A36 = COUNTRY | CAR;
END
TABLE FILE CTRYPOP
PRINT POPULATION
BY MCGYVER
BY COUNTRY
ON TABLE HOLD AS TEMPHLD1
END
-RUN
TABLE FILE CAR
PRINT CAR
BY MCGYVER
ON TABLE HOLD AS TEMPHLD2 FORMAT FOCUS INDEX MCGYVER
END
-RUN
TABLE FILE CAR
SUM CNT.SALES
BY CTRYCAR
ON TABLE HOLD AS TEMPHLD3 FORMAT FOCUS INDEX CTRYCAR
END
-RUN
JOIN CLEAR *
JOIN MCGYVER IN TEMPHLD1 TAG T1 TO MULTIPLE MCGYVER IN TEMPHLD2 TAG T2 AS J0
JOIN CTRYCAR WITH CAR IN TEMPHLD1 TO CTRYCAR IN TEMPHLD3 TAG T3 AS J1
DEFINE FILE TEMPHLD1
CTRYCAR/A36 WITH CAR = COUNTRY | CAR;
END
TABLE FILE TEMPHLD1
SUM SALES AS 'Count,of Sales'
MAX.POPULATION AS 'Population'
BY CAR AS ''
ACROSS COUNTRY AS ''
ON TABLE SET PAGE NOLEAD
END
-EXIT
In FOCUS since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2
WebFOCUS App Studio 8.2.06 standalone on Windows 10
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004
Thanks Pat and Tony for your excellent solutions. I was also thinking along the way of Tony.
So first step to make a cartesian product of CAR.CAR and CTRYPOP.COUNTRY, although I have never used this McGyver technique for this, I would use a conditional join, which will work alike. I assume it depends on your sources (focus/flat file/rdbms) which will suit best. Next step to make an outer join to the CAR table.
Nice, thanks again.
WebFocus 8206M, iWay DataMigrator, Windows, DB2 Windows V10.5, MS SQL Server, Azure SQL, Hyperstage, ReportCaster