Focal Point
[SOLVED] Array as Field

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

April 19, 2012, 06:30 AM
sladkat
[SOLVED] Array as Field
Hi,
I have a requirement to calculate grand totals. I am able to generate the grand totals but it is in the form of amper variable array. How can I declare an Array variable to a field?
-SET &ECHO = ALL;
TABLE FILE CAR
SUM
CNT.CAR/I5
AVE.DEALER_COST/D12.2
BY COUNTRY/A10
ON TABLE HOLD AS CAR_CNT FORMAT ALPHA
END
-RUN

-SET &LIMIT1 = &LINES;
-SET &I=1;
-REPEAT ENDLOOP_BEN &LIMIT1 TIMES
-READ CAR_CNT NOCLOSE &country.A10 &carcnt.A5 &temp.A7 &car_cost.A12
-SET &country.&I=&country;
-TYPE &country.&I
-SET &carcnt.&I=&carcnt;
-TYPE &carcnt.&I
-SET &car_cost.&I=&car_cost;
-TYPE &car_cost.&I
-SET &I=&I+1;
-ENDLOOP_BEN

TABLE FILE CAR
PRINT
CAR NOPRINT
ON TABLE PCHOLD FORMAT PDF
HEADING
"Grand Totals:"
" "
"Average Cost for Subscribers:"
" "
-BENCONTAGE1_C
"<+0><5 Country<+0><20 Average Cost "
" "
-SET &I=1;
-REPEAT ENDLOOP_BEN1_C &LIMIT1 TIMES
"<+0><5 <+0>&country.&I<+0><20 &car_cost.&I<+0>"
-SET &I = &I+1;
-ENDLOOP_BEN1_C
" "
"Count of Cars:"
" "
-BENCONTAGE1_C
"<+0><5 Country<+0><20 Count "
" "
-SET &I=1;
-REPEAT ENDLOOP_BEN2_C &LIMIT1 TIMES
"<+0><5 <+0>&country.&I<+0><20 &carcnt.&I<+0>"
-SET &I = &I+1;
-ENDLOOP_BEN2_C
END

In the above eg. I am taking count on cars and avg on dealer cost. I am displaying it as a part of heading in the PDF report. But suppose the number of heading lines exceeds the page, then it creates a problem, it starts displaying the calculated fields on the next page without any header space.
Instead of displaying these array variables in heading I want to display it as an part of data, so the problem will be resolved.
How can I assign array variable values as an field?
Please Help

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


Supriya
WF 7.7.02/8.0
April 19, 2012, 05:42 PM
Crymsyn
Well this is one way if you must use parameter arrays (Output does not have any of the headings you have)

-SET &ECHO = ALL;
TABLE FILE CAR
SUM 
CNT.CAR/I5
AVE.DEALER_COST/D12.2
BY COUNTRY/A10 
ON TABLE HOLD AS CAR_CNT FORMAT ALPHA
END 
-RUN

-SET &LIMIT1 = &LINES;
-SET &I=1;
-REPEAT ENDLOOP_BEN &LIMIT1 TIMES
-READ CAR_CNT NOCLOSE &country.A10 &carcnt.A5 &temp.A7 &car_cost.A12
-SET &country.&I=&country;
-TYPE &country.&I
-SET &carcnt.&I=&carcnt;
-TYPE &carcnt.&I
-SET &car_cost.&I=&car_cost;
-TYPE &car_cost.&I
-SET &I=&I+1;
-ENDLOOP_BEN

DEFINE FILE CAR

-SET &TEMP=;
CAR_COST/D12.2=
-REPEAT :LOOP_DEF_COST FOR &I FROM 1 TO &LIMIT1
-SET &TEMP=IF &I.EVAL EQ 1 THEN 'IF COUNTRY EQ ''' | &country.&I | ''' THEN ' | &car_cost.&I ELSE 'ELSE IF COUNTRY EQ ''' | &country.&I | ''' THEN ' | &car_cost.&I;
&TEMP
-:LOOP_DEF_COST
ELSE 0;

CAR_CNT/I5=
-REPEAT :LOOP_DEF_CNT FOR &I FROM 1 TO &LIMIT1
-SET &TEMP=IF &I.EVAL EQ 1 THEN 'IF COUNTRY EQ ''' | &country.&I | ''' THEN ' | &carcnt.&I ELSE 'ELSE IF COUNTRY EQ ''' | &country.&I | ''' THEN ' | &carcnt.&I;
&TEMP
-:LOOP_DEF_CNT
ELSE 0;

END

TABLE FILE CAR
PRINT
CAR_COST
CAR_CNT
BY COUNTRY
BY CAR
END


However in the example above you can do the exact same thing using a multi verb request without using any parameters or arrays

TABLE FILE CAR
SUM 
CNT.CAR/I5 AS 'CAR_CNT'
AVE.DEALER_COST/D12.2 AS 'CAR_COST'
BY COUNTRY/A10 

PRINT
CAR
BY COUNTRY
END



WF: 8201, OS: Windows, Output: HTML, PDF, Excel
April 23, 2012, 12:00 AM
sladkat
Thanks Crymsyn

But it doesn't solve my problem, as my calculation needs to have Heading like Grand Totals and all.
Is there any other solution?


Supriya
WF 7.7.02/8.0
April 23, 2012, 06:11 AM
Tony A
There is always a solution, it is just a case of finding it!

Try this -
FILEDEF OUTPUT DISK OUTPUT.FTM (APPEND
-RUN

DEFINE FILE CAR
  DATATYPE1/A10 = 'Cost';
  DATATYPE2/A10 = 'Count';
END

TABLE FILE CAR
  SUM CNT.CAR/D12.2 AS VALUE
   BY DATATYPE2
   BY COUNTRY
ON TABLE SET ASNAMES ON
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE HOLD AS OUTPUT FORMAT ALPHA
END 
-RUN

TABLE FILE CAR
  SUM AVE.DEALER_COST/D12.2 AS VALUE
   BY DATATYPE1
   BY COUNTRY
ON TABLE SET ASNAMES ON
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE HOLD AS OUTPUT FORMAT ALPHA
END 
-RUN

TABLE FILE OUTPUT
  SUM COMPUTE CFORMAT/A8 = DECODE DATATYPE1 ('Cost' 'D12.2' 'Count' 'I5' ELSE 'D5'); NOPRINT
      VALUE/CFORMAT AS ''
   BY DATATYPE1 NOPRINT SKIP-LINE
   BY COUNTRY AS ''
HEADING
"Grand Totals: </1"
ON DATATYPE1 SUBHEAD
"Count of Cars: </1"
"Country<+0>Count"
WHEN DATATYPE EQ 'Count'
ON DATATYPE1 SUBHEAD
"Average Cost for Subscribers: </1"
"Country<+0>Average Cost"
WHEN DATATYPE EQ 'Cost'
ON DATATYPE1 SUBFOOT
" "
ON TABLE SET PAGE NOLEAD
ON TABLE PCHOLD FORMAT PDF
ON TABLE SET STYLE *
TYPE=REPORT, HEADALIGN=BODY, $
TYPE=SUBHEAD, LINE=3, ITEM=2, JUSTIFY=RIGHT, $
ENDSTYLE
END


Or use the "new" compound reporting syntax.

T

This message has been edited. Last edited by: Tony A,



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 
April 26, 2012, 07:48 AM
sladkat
Thanks Tony

I got the solution of my problem through Compound Report (PDF NOBREAK).
I have around 5 calculation hold files which I am displaying back-to-back through PDF NOBREAK.
I have a logo which has to be displayed on the report top left. With NOBREAK if the report calculation goes to next page the logo isnt there and the data comes just attached to the top.I want the company logo to be on every page.
How would I come to know exactly where it goes to the next page?


Supriya
WF 7.7.02/8.0