Focal Point
SORTING PROBLEM

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

April 20, 2005, 01:42 PM
<ROSESINN>
SORTING PROBLEM
Hello Everyone,
i need to create a report with multiple sorts and the sort values are entered by the user. so i defined the by fields as &sorts .the problem is if the user enters a perticular sort option then it should sort the data and also add an additional column beside it .for example if the user is sorting by empid then it should sort the data and also display empname field data beside the empid and if the user is not selecting empid as sort option then it shouldnt display empname in the report data.
hope you understood my problem.thanks guys for ur help.
April 20, 2005, 01:56 PM
susannah
table file car
sum sales by highest weight noprint
by country by model by weight
end

...
put a NOPRINT after the sort variable
April 20, 2005, 02:06 PM
Boogarweed
I think I understand what you want. There are many ways to tackle this. See if this works for you.

-SET &sorts2 = IF &sorts EQ 'empid' THEN 'empid BY empname';

Then in your code write

BY &sorts2
April 20, 2005, 02:45 PM
reFOCUSing
Would this work for you?

-SET &SORT = 'CAR';

TABLE FILE CAR
SUM RETAIL_COST DEALER_COST

-GOTO :&SORT

-:COUNTRY
BY COUNTRY
-GOTO :END_SORT

-:CAR
BY CAR
-GOTO :END_SORT

-:MODEL
BY MODEL
-GOTO :END_SORT

-:END_SORT
END
April 20, 2005, 02:57 PM
<ROSESINN>
Hi ,
thanks for ur replies. i tried the solution given by boogerweed and its working fine but the problem is if i am sorting by empid i want the empname column to be next to empid.
thanks
rosesinn
April 20, 2005, 03:23 PM
<JG>
That's exactly what boogerweed's answer does.
If you want the name before the id, just reverse the fields.
Also If you have multiple possibilities as I suspect you might, then use a decode instead of IF THEN ELSE.
April 20, 2005, 03:47 PM
Leo L
JG,

what is the main difference between "if/else" and decode such that your saying to use the decode function instead of the "if/else"?

I've mainly used the if/else in these situations probably because its more relevant to other programming languages I've used but when I looked up the decode, I didn't see anything that would imply its any different then the if/else statement.

thanks,

Leo
April 20, 2005, 03:52 PM
<ROSESINN>
Hi guys,
here is my sample code

-SET &SORT2 = IF &SORT1 EQ '' THEN ' ' ELSE IF &SORT1 EQ 'empid' THEN 'then ename BY empid ' ELSE IF &SORT1 EQ 'deptno' THEN 'dname BY deptno' ELSE 'BY '| &SORT1 |'';
TABLE FILE SQLOUT
PRINT
sal
comm
&SORT2
END
now if i am giving empid as my sort option i want my report to be displayed as

EMPID ENAME SAL COMM
BUT IT IS DISPLAYING AS
EMPID SAL COMM ENAME
and if i am NOT GIVING ANY VALUE TO my sort option i want my report to be displayed as

SAL COMM

THANKS GUYS
April 21, 2005, 01:26 AM
Piipster
In Boogarweed's example he had
BY &sorts2

Be sure to put the BY either in front of
the &sorts2 or add it into the value of &sorts2.

ie. 'BY ename BY empid'
April 21, 2005, 04:44 AM
<MoonLightWare>
ROSESINN

I am assuming you are using a fairly current version of WebFOCUS. In the Report Painter create you variable (&sorts) and make it a by field. Then using Resource Layout create the by field as a static dropdown in the Display enter EMPID then in the value enter EMPID BY EMPNAME. I think this should work for you. Please Post you result.
April 21, 2005, 08:46 AM
<JG>
Leo Historically the reason to use DECODE instead of IF THEN ELSE was due to a pre 5.2 limitation of 16 IF THEN ELSE pairs DECODE allowed 39 pairs + an ELSE. Also DECODE can take it's input from an external file.

While the 16 pair limit nolonger applies (it's dependant on available memory post 5.2) DECODE is easier to read , and requires less code. However it only does simple in value,out value substitutions not compound conditions