Focal Point Banner


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.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Columns to Rows - SQL vs WebFOCUS

Read-Only Read-Only Topic
Go
Search
Notify
Tools
Columns to Rows - SQL vs WebFOCUS
 Login/Join
 
Expert
posted
Is there a way to do use FOCUS code instead of SQL to convert columns to rows, as in this SQL example:

SQL
SELECT 'DEALER_COST' AS COLNAME, DEALER_COST AS COLVALUE FROM CAR
WHERE COUNTRY = 'ENGLAND'
UNION
SELECT 'RETAIL_COST' AS COLNAME, RETAIL_COST AS COLVALUE FROM CAR
WHERE COUNTRY = 'ENGLAND'
UNION
SELECT 'SEATS' AS COLNAME, SEATS AS COLVALUE FROM CAR
WHERE COUNTRY = 'ENGLAND'
UNION
SELECT 'SALES' AS COLNAME, SALES AS COLVALUE FROM CAR
WHERE COUNTRY = 'ENGLAND';
TABLE ON TABLE HOLD AS H001 FORMAT ALPHA
END


Thanks,


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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Virtuoso
posted Hide Post
Match file can do it.


It's essential to pre-summarize the data, so there is one row per set of sort-key values. (That will allow us to treat the Value as a sort-key.)

Use Define (against the summed data) to create name and value vars with consistent formats, for all the dependent fields of interest.

Then issue a multi-leg Match file, one OLD-OR-NEW merge per UNION.
MATCH 
FILE HOLD
COUNT ENTRIES NOPRINT 
 BY {the "real" keys, if applicable}
 BY Name1  AS COLNAME
 BY Value1 AS COLVALUE
RUN
...


- Jack Gross
WF through 8.1.05
 
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005Report This Post
Expert
posted Hide Post
Oh, well - it sounds like it's a lot easier with SQL.

Thanks,


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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Virtuoso
posted Hide Post
De gustibus ... this looks no more complicated to me:

DEFINE FILE CAR
  NAME1/A12 ='DEALER_COST ';  VALUE1/D8.1= DEALER_COST  ;
  NAME2/A12 ='RETAIL_COST ';  VALUE2/D8.1= RETAIL_COST  ;
  NAME3/A12 ='SALES       ';  VALUE3/D8.1= SALES        ;
  NAME4/A12 ='LENGTH      ';  VALUE4/D8.1= LENGTH       ;
  NAME5/A12 ='WIDTH       ';  VALUE5/D8.1= WIDTH        ;
  NAME6/A12 ='HEIGHT      ';  VALUE6/D8.1= HEIGHT       ;
  NAME7/A12 ='WEIGHT      ';  VALUE7/D8.1= WEIGHT       ;
  NAME8/A12 ='WHEELBASE   ';  VALUE8/D8.1= WHEELBASE    ;
END
MATCH FILE CAR
  BY COUNTRY BY CAR BY MODEL BY NAME1 AS COLNAME BY VALUE1 AS COLVALUE
RUN
FILE CAR
  BY COUNTRY BY CAR BY MODEL BY NAME2 AS COLNAME BY VALUE2 AS COLVALUE
AFTER MATCH HOLD OLD-OR-NEW
RUN
FILE CAR
  BY COUNTRY BY CAR BY MODEL BY NAME3 AS COLNAME BY VALUE3 AS COLVALUE
AFTER MATCH HOLD OLD-OR-NEW
RUN
FILE CAR
  BY COUNTRY BY CAR BY MODEL BY NAME4 AS COLNAME BY VALUE4 AS COLVALUE
AFTER MATCH HOLD OLD-OR-NEW
RUN
FILE CAR
  BY COUNTRY BY CAR BY MODEL BY NAME5 AS COLNAME BY VALUE5 AS COLVALUE
AFTER MATCH HOLD OLD-OR-NEW
RUN
FILE CAR
  BY COUNTRY BY CAR BY MODEL BY NAME6 AS COLNAME BY VALUE6 AS COLVALUE
AFTER MATCH HOLD OLD-OR-NEW
RUN
FILE CAR
  BY COUNTRY BY CAR BY MODEL BY NAME7 AS COLNAME BY VALUE7 AS COLVALUE
AFTER MATCH HOLD OLD-OR-NEW
RUN
FILE CAR
  BY COUNTRY BY CAR BY MODEL BY NAME8 AS COLNAME BY VALUE8 AS COLVALUE
AFTER MATCH HOLD OLD-OR-NEW
END

TABLE FILE HOLD PRINT COLVALUE
BY COUNTRY BY CAR BY MODEL BY COLNAME
END



- Jack Gross
WF through 8.1.05
 
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005Report This Post
Guru
posted Hide Post
Hi Francis.

Hope all is well back in Canada.

How are you going to use the HOLD file? I am assuming that since you are putting the column titles in the rows you don't need a master file. My rows don't come out in the same order as yours but that should be fixable.

I used the following code:

 
TABLE FILE CAR
PRINT      DEALER_COST
    OVER RETAIL_COST
 OVER SEATS
 OVER SALES
WHERE COUNTRY EQ 'ENGLAND'
ON TABLE HOLD AS H001 FORMAT LOTUS
-*ON TABLE HOLD AS H001 FORMAT WP
ON TABLE SET PAGE NOLEAD
END


WP output:
  DEALER_COST      7,427
  RETAIL_COST      8,878
  SEATS                2
  SALES                0
  DEALER_COST     11,194
  RETAIL_COST     13,491
  SEATS                5
  SALES            12000
  DEALER_COST     14,940
  RETAIL_COST     17,850
  SEATS                4
  SALES                0
  DEALER_COST      4,292
  RETAIL_COST      5,100
  SEATS                2
  SALES                0
 


LOTUS output:
"DEALER_COST",   7427
"RETAIL_COST",   8878
"SEATS",  2
"SALES",     0
"DEALER_COST",  11194
"RETAIL_COST",  13491
"SEATS",  5
"SALES", 12000
"DEALER_COST",  14940
"RETAIL_COST",  17850
"SEATS",  4
"SALES",     0
"DEALER_COST",   4292
"RETAIL_COST",   5100
"SEATS",  2
"SALES",     0
  



...and... if you want to use constants instead of the field names you could DEFINE or COMPUTE those values and use AS '' for all the fields.

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


ttfn, kp


Access to most releases from R52x, on multiple platforms.
 
Posts: 346 | Location: Melbourne Australia | Registered: April 15, 2003Report This Post
Master
posted Hide Post
JG - nice technique for using MATCH to UNION rather than JOIN - I'm sure that I will find a use.

You could go the McGuiver route

JOIN ONE WITH LENGTH IN CAR TO ALL ONE IN MCGUYVER AS J1

DEFINE FILE CAR
NAME/A12 = IF MCVAL EQ 1 THEN 'DEALER_COST '
ELSE IF MCVAL EQ 2 THEN 'RETAIL_COST '
...
VALUE/D8.1= IF MCVAL EQ 1 THEN DEALER_COST
ELSE IF MCVAL EQ 2 THEN RETAIL_COST
...
END
TABLE FILE CAR
PRINT
NAME
VALUE
BY COUNTRY BY CAR BY MODEL BY MCVAL NOPRINT
END



Server: WF 7.6.2 ( BID/Rcaster) Platform: W2003Server/IIS6/Tomcat/SQL Server repository Adapters: SQL Server 2000/Oracle 9.2
Desktop: Dev Studio 765/XP/Office 2003 Applications: IFS/Jobscope/Maximo
 
Posts: 888 | Location: Airstrip One | Registered: October 06, 2006Report This Post
Master
posted Hide Post
This should be built into wf/SQL just like mcguyver with my MULTIPLY FILE ... AT ... TIMES syntax

Its a shame that OVER does not hold values in the same way as the report.

Could RECTYPEs be adapted in some way?

select over (x1, x2 ... xn) AS namecol valuecol

could be the syntax - will drop ANSI commitee an email.



Server: WF 7.6.2 ( BID/Rcaster) Platform: W2003Server/IIS6/Tomcat/SQL Server repository Adapters: SQL Server 2000/Oracle 9.2
Desktop: Dev Studio 765/XP/Office 2003 Applications: IFS/Jobscope/Maximo
 
Posts: 888 | Location: Airstrip One | Registered: October 06, 2006Report This Post
Expert
posted Hide Post
Here is another way to do it.
TABLE FILE CAR
PRINT COMPUTE NAME1/A20='DEALER_COST' ;
      DEALER_COST/I9
      COMPUTE NAME2/A20='RETAIL_COST' ;
      RETAIL_COST/I9
      COMPUTE NAME3/A20='SEATS' ;
      SEATS/I9
      COMPUTE NAME4/A20='SALES' ;
      SALES/I9
WHERE COUNTRY EQ 'ENGLAND'
ON TABLE SAVE AS TMP_FILE FORMAT ALPHA
ON TABLE SET HOLDLIST PRINTONLY
END

-RUN

EX -LINES 5 EDAPUT MASTER,TMP_FILE ,CV,FILE
FILENAME=TMP_FILE , SUFFIX=FIX,$
SEGNAME=TMP_FILE ,OCCURS=4, $
  FIELD=COLNAME ,ALIAS=  ,A20 ,A20 ,$
  FIELD=COLVALUE,ALIAS=  ,I9  ,A9  ,$

-RUN

TABLE FILE TMP_FILE
PRINT *
END


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!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Columns to Rows - SQL vs WebFOCUS

Copyright © 1996-2020 Information Builders