Skip to Content

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

Split a string and compare value in loop to get the description.


I am passing a string {?CompCode} to a subreport which will use the string to fetch the corresponding description and concatenate the description fields and display it in the sub-Report.

String consists of comma u2018,u2019 separated code value and I have to display the description field corresponding to the Code value.

I am using the below code but which is only displaying description field corresponding to the first code value. Remaining descriptions are not getting displayed. Can you please help me to resolve this issue?

I am using Crystal Report 2008.

Thanks in Advance



Local StringVar Array CompCodeName := Split({?CompCode},","); numbervar idx:=0; numbervar MaxArray := UBOUND(CompCodeName); stringvar Cat:=""; For idx := 1 to MaxArray Do ( if CompCodeName[idx] = Table.Comp_Code then Cat:= Cat & ' ' & Table.Comp_Name idx:= idx+1; ); Cat;

Edited by: Atanu Mukhopadhyay on Apr 22, 2010 4:58 PM


I have changed the code as mentioned below and now the output is concatenated value of the Description field (Table.Comp_Name) corresponding to the first Company Code.

Say If

Company_Code Company_Name -

01A XXCom 01B YYCom 01C ZZCom

Now If I pass the string 01A,01B,01C then I am getting an out put ;XXCom;XXCom;XXCom Instead of XXCom;YYCom;ZZCom

StringVar Array CompCodeName:= Split({?CompCode},","); NumberVar Limit := UBound(CompCodeName); Numbervar Indx := 0; StringVar CompCode:= ""; StringVar CompCodeOutPut := ""; For Indx := 1 To Limit Do ( If Table.Comp_Code= ToText(CompCodeName [Indx]) Then CompCode := Table.Comp_Name; CompCodeOutPut := CompCodeOutPut & ';' & CompCode; indx = indx +1; ); CompCodeOutPut

Former Member replied

If you use range array values, you're going to have to program for the fact that you do not have all of the discrete values that you'd have if you were not using ranges. What you'll have to do is build the actual full condition, and pass that into an SQL Command to get the desired results. In pseudo-code (I'm a bit short on time right now):

condition = ''
For each array element
  if condition <> ''
    condition = condition + ' or '
  end if

  if element is range
    condition = condition + ' field between ' + minimum(element) + ' and ' + maximum(element)
    condition = condition + ' field = ' + minimum(element)
  end if
end for

then pass this to the SQL Command (call the parameter {?Condition}):

select *
from table
where {?Condition}



0 View this answer in context

Helpful Answer

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