Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Merge two string fields

I have two fields that ContactType & ContactName and each record will have at least one contact type (primary or secondary), or it can have also two of the contact types. So I am trying to concatenate the contactName if the record has two contacts or if there is only one, then display that.

This is what I have so far:

//variables are: TotalContact, PrimaryVariable, SecondaryVariable, SingleVar.

totalContact := count (contact.contactName, PrimRecord.RecordID);

if (totalContact > 1) then

{ contact type = primary then

PrimaryVariable := contact.contactName

else

SecondaryVariable: = contact.ContactName

}

else

singleVar := contact.contactName;

Former Member
Former Member replied

Gotcha...

Well the answer would depend on your data structure.

I'll assume it's something along these lines:

CustomerID-|-ContactID-|-ContactType-|-ContactName-|-...

1--


10001
P
--


John Smith

1--


10002
S
--


Bill Cramer

1--


10003
T
--


Mary Jones

2--


10004
P
--


Hank Aaron

2--


10005
S
--


Pete Rose

3--


10006
P
--


Jerry Rice

3--


10007
S
--


Kenny Anderson

3--


10008
T
--


Ikky Woods

You want results that look like this:

Company Name 1: Primary Contact = John Smith, Secondary Contact = Bill Cramer

Company Name 2: Primary Contact = Hank Aaron, Secondary Contact = Pete Rose

Company Name 3: Primary Contact = Jerry Rice, Secondary Contact = Kenny Anderson

Assuming I'm correct, follow these steps and create the following formulas.

1) Primary

IF {tbl.ContactType} = "P" THEN {tbl.ContactName}

2) Secondary

IF {tbl.ContactType} = "S" THEN {tbl.ContactName}

3) ConCat

{tbl.CompanyName} &": Primary Contact = " & {@Primary} & ", Secondary Contact = " & NEXT ( {@Secondary} )

4) Now you need to order the report by: #1. CompanyID then #2. ContactType

5) Here's where it all comes together... While in the Design View, right click in the gray part of the Details section off to the left.

Choose Selection Expert...

Click the "X-2" button next to "Suppress (No Drill Down)"

Enter the following formula:

IF {tbl.ContactType} != "P" THEN TRUE ELSE FALSE

( Just be sure to use the "not equal to" angle brackets in place of "!=")

Anyway, if you made it this far, you should have what you are looking for.

Hope this helps,

Jason

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question