SAP Knowledge Base Article - Public

1201893 - How to display a hierarchy according to the Parent " Child relationship in Crystal Reports

Symptom

A report contains a hierarchy. This hierarchy is based on a field within the database and is established using the Hierarchial Grouping options on the Report menu of Crystal Reports.

The report contains a group and a Detail section. The Details section is hidden so that only the names of the leves are displayed. The following structure is an illustration:

 LEVEL1

           LEVEL2A

                        LEVEL3AA

                                         LEVEL4AAA

                        LEVEL3AB

           LEVEL2B

                        LEVEL3BA

           LEVEL2C

The requirement is to only display the direct and indirect children of LEVEL2A. The requirement is illustrated below:

 LEVEL2A

             LEVEL3AA

                             LEVEL4AAA

             LEVEL3AB

Cause

N/A

Resolution

1 - In the above example the LEVEL2A is the group level number 2; so, create a formula " VariableX - to define a variable which is assigned to the first 7 letters of this group level - GroupNumber 2:

 

WhilePrintingRecords;

Global stringVar x;

if GroupNumber = 2 then

x:= Left({field_on_which_the hierarchy is defined},7);

 

2 - Create a new section of the group header 1 so as to have GH1a and GH1b;

 

3 " Move all the objects from the GH1b to the GH1a and in the GH1a place the "VariableX" formula;

 

4 " Suppress the GH1a section;

 

5 " Conditionally suppress the GH1b:

 
      Open Section Expert and from the "Sections" screen on the left, select the GH1 section; from the Common tab, click once on the "X+2" button and enter the following formula:

 

      WhilePrintingRecords;

      stringVar x;

      GroupNumber = 1  or

      if Left({field_on_which_the hierarchy is defined }, 7)= x then true

 

      This formula suppresses the section when the Group number is equal to 1 or if the first 7 letters of the field are different from the X variable; as a result, if the field is equal to LEVEL2B and X is equal 
      to LEVEL2A, this section will be suppressed.

Keywords

hierarchy, Parent " Child relationship, relationship, level , 5637576 , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , How To

Product

Crystal Reports 2008 V0 ; SAP Crystal Reports XI ; SAP Crystal Reports XI R2