Skip to Content
avatar image
Former Member

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

Hi,

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

Regards

Atanu

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

Now

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Apr 22, 2010 at 04:11 PM

    It appears that you are not selecting all of the company records to drive the report. Change the record selection formula to

    {Table.CompName} in Split({?CompCode},",")
    

    which will return all of the records for each of the company codes. Then use a formula on the detail format to concatenate the multiple records using a shared variable to pass back to the main report.

    HTH,

    Carl

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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)
        else
          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}
      

      HTH,

      Carl