Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: string from field values Post Reply Post New Topic
Author Message
moondogi
Newbie
Newbie


Joined: 08 Oct 2008
Online Status: Offline
Posts: 5
Quote moondogi Replybullet Topic: string from field values
     Posted: 08 Oct 2008 at 3:22am
Hello,
I have a file that contains: Supplier #, Stock # and other details.

In most cases, the original component is processed into different variants.
e.g. Steel Widget (p/n # 123) is painted in three different colours, and sold as Red Widget (p/n 123R), Blue Widget (p/n 123B) and Green Widget (p/n 123G)

So in my original file looks like;
Supplier # Stock# Description
123 123R Red Widg
123 123B Blue Widg
123 123G Green Widg

What I would like my report to look like:
Supplier# Stock#
123 123R, 123B, 123G

Seperating each Stock# with a comma is not essential, but may come in hand.

I am pretty sure this is possible, but I'm not sure how to approach it. I think concatenate might be the word

Thanks in advance,
JohnW
JohnW
IP IP Logged
Joco
Newbie
Newbie
Avatar

Joined: 09 Oct 2008
Location: United Kingdom
Online Status: Offline
Posts: 3
Quote Joco Replybullet Posted: 09 Oct 2008 at 4:12am

Hello,

Yes you can create a formula to concatenate the fields together, remembering to reset the field on change of supplier. See below for details...
 
1. Create a Group on the Supplier # field.
 
2. Create a formula called Stock, and put it in the details section:
 
WhilePrintingRecords;
Global StringVar Stock;
Stock := Stock + {Stock # fieldname} + ", "; 
 
3. Create a formula called ResetStock, and put this in the Supplier # Group Header:
 
WhilePrintingRecords;
Global StringVar Stock;
Stock := "";
 
4. Create a formula called PrintStock, and put this in the Supplier # Group Footer:
 
WhilePrintingRecords;
Global StringVar Stock;
 
5. Add the Supplier # field to the Group Footer and also suppress the Details section.
 
Note that the concatenated string will have a comma on the end,
(you can change this slightly to check if this is the first record in the detail section, if you're not sure how to do this let me know, it'll mean tweaking the ResetStock and Stock formulae).
 
Hope this helps,
Jo.
 
IP IP Logged
moondogi
Newbie
Newbie


Joined: 08 Oct 2008
Online Status: Offline
Posts: 5
Quote moondogi Replybullet Posted: 12 Oct 2008 at 8:51pm
thanks for the useful help & clear instructions.
JohnW
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 13 Oct 2008 at 10:46am
A slightly different way to do this that only requires one formula works like this:
 
Stringvar stock;
if previousIsNull({table.SupplierNum}) or
   ({table.SupplierNum} <> previous({table.SupplierNum}) then  
  stock := {table.StockNum};
else
  stock := stock + ", " + {table.StockNum};
stock
 
This checks to see if the supplier # of the current record is different from the previous record.  If it is, then it sets the stock number string to the current stock number.  If it isn't, it adds a comma and the current stock number to the string.  Not that the final line contains just the variable name with no semi-colon - this is what will display the value on your report.  
 
Place this formula in the group footer, just like Joco describes.
 
-Dell 


Edited by hilfy - 13 Oct 2008 at 10:48am
IP IP Logged
moondogi
Newbie
Newbie


Joined: 08 Oct 2008
Online Status: Offline
Posts: 5
Quote moondogi Replybullet Posted: 15 Oct 2008 at 9:01pm
Thanks, I'll give it a try.
 
Some stuff in life gets even better!
JohnW
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum