Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to append a list of details into just one line 1

Status
Not open for further replies.

fedleo

Technical User
Oct 26, 2003
11
IT
I found over the net this interesting formula that explain how to append a list of string details into just one line like

ItemA, ItemB, ItemC

Here's the original text:

The solutions requires three formulas, and assumes that the items are within an existing group on the report:

1) In the Group Header place the @reset formula:

WhilePrintingRecords;
StringVar chain := '';
NumberVar ChCnt := 1


2) On the Details place the @Accum formula, putting your field into the second line:

WhilePrintingRecords;
StringVar Item:= {Your.Field}; // place your field in place of {Your.Field}
StringVar Chain;
NumberVar ChCnt;

if ChCnt = 1
then (ChCnt:= 2; chain := Item)
else
if Length(Chain) + Length(Item) > 254
then Chain := Chain else
chain := chain + ', ' + Item


3) On the Group Footer place the @Display formula:

WhilePrintingRecords;
StringVar Chain


**Important Note. A formula result (string) cannot be more than 254 characters. If your items add up to over 254 characters, this formula will not print them all. It will only print the first 254 characters. You could create a second parallell set of formulas that picks up where this one leaves off.

------------------

BTW, how can I obtain a list of "unique" value, for example a list of customers that have bought multiple items?

Thanks in advance,

Fedleo
 
This formula is intended for CR 8.5 or below (the 254 char limitation), and could be greatly improved by then adding anything over 254 to another variable, NOT another set of formulas.

Rather than posting random formulas, try posting version information, example data and expected output, otherwise there will be a lengthy discovery process to determine your business rules.

-k
 
Hope you will undestand that I'm NOT a programmer. So I'll try to explain my problem again:

The version of CR is 8.5 ITA.
Here's the example:

In a tab with this fields
{ITEMS} {Qty} {CUSTOMERS}
ITEM1 5 Frank
ITEM2 3 Paul
ITEM3 4 Paul
ITEM4 3 Frank
ITEM5 2 Jake

I've as a result of the report using this forumula

{ITEMS} {Qty}
ITEM1 5
ITEM2 3
ITEM3 4
ITEM4 3
ITEM5 2

{Customers} Frank, Paul, Paul, Frank, Jake

------------

But the result I need is the same:

{ITEMS} {Qty}
ITEM1 5
ITEM2 3
ITEM3 4
ITEM4 3
ITEM5 2

{Customers} Frank, Paul, Jake

So I need something that allows me to see just unique record on the field {Customers}. If I have understood well you say that is not possible do a filter for this formula. Is there any other possibility to do what I need?
The 254 characters are not a problem for me becouse I exceed 200 very rarely.

I have been enough precise now? [thumbsup2]

Cheers,

Fedleo
 
And apparently gave yourself a star for your post!

I think what you'[re trying to do is collect the names used if they are unique, correct?

Change this:

WhilePrintingRecords;
StringVar Item:= {Your.Field}; // place your field in place of {Your.Field}
StringVar Chain;
NumberVar ChCnt;
if ChCnt = 1
then (ChCnt:= 2; chain := Item)
else
if Length(Chain) + Length(Item) < 255
and
instr(chain, Item) = 0 then
chain := chain + ', ' + Item

The if... then tchain := chain was all redundant.

-k
 
Don't know about the star K... Maybe my mistake?

The new formula is exactly what I need: it run just fine.
Thanks so much!

Cheers,

Fedleo
 
This thread helped me with my data, but displays kind of strangly.

My data is based on {@part}:
whileprintingrecords;
if {SERVICE_CALL_XREF.XREF_LABEL} startswith ["part", "Part"]
then {SERVICE_CALL_XREF.XREF_ID}

That will give me a detail line for those records with Part # or part # and the specific part number. EG:

Call 1 540-1234
Call 1 123-4556
Call 2 555-1235 (there are xref ids that are not part related for call 2)

With the formulas above I get:
Call 1 540-1234,123-4556
Call 2 ,555-1235

I can supress Item 3, no big deal, but the Item 2 line looks stupid. How do I nuke the preceeding ,?

Crystal 9, SQL, Oracle.
 
Try changing "chain := chain + ', ' + Item" to:

chain := chain + Item + ", ";

Then for the display formula use:

whileprintingrecords;
stringvar chain;
if len(chain) > 2 then
left(chain,len(chain)-2) else
chain

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top