Question

I am modifying a subreport that prints optional report card comments. The data that is supplied (via a stored procedure) is in this format (trimmed for brevity):

StudentID / Grade / CourseNum / ReportCode / CName     / Comment
9999991   / KG    / EA0_AM1   / M1         / T1Comment / Pam is good!
9999991   / KG    / KP0_PM1   / M1         / T1Comment / Pam is okay!
9999992   / 3     / EA3_AM1   / M1         / T1Comment / Joe is good!
9999993   / 5     / EA5_AM1   / M1         / T1Comment / <null>

If a student is not in kindergarten, the only comment I want to print is the one where CourseNum = "EA?_AM1". If they're in Kindergarten, however, the comments should pull from "EA0_AM1", "EA0_PM1", "KP0_AM1", and "KP0_PM1", and those comments should be concatenated. The original report would only print the comment from either "EA0_AM1" or "EA0_PM1", but not both (it didn't know about the other two kindergarten classes, and it used a running total to find the maximum value for Comment), but among the four potential classes there are two potential teachers, and this year they both want their comments to appear on the report card. I don't think it matters, but here's the record selection formula:

(Select {?Marking Period}
    Case '1' : {ReportCode} = 'M1'
    Case '2' : {ReportCode} in ['M1', 'M2']
    Case '3' : {ReportCode} in ['M1', 'M2', 'M3']) and
(Select {Grade}
    Case 'KG': {CourseNum} in ["EA0_AM1", "EA0_PM1", "KP0_AM1", "KP0_PM1"]
    Default  : {CourseNum} like "EA?_AM1")

({?MarkingPeriod} refers to the trimester we're interested in.)

The problem I'm encountering springs from the fact that we want to print T1, T2 and T3 comments separately. I found the start of my solution in an answer given by Abhilash Kumar in a thread here: http://scn.sap.com/thread/3195910. Based on his answer to someone else's question I created a formula GetAllCommentsT1:

WhilePrintingRecords;  
stringvar array arrT1;  
numbervar iT1;  
if not(({Comment} in arrT1) and ({CName} like "T1*")) then  
(  
    iT1 := iT1 + 1;  
    redim preserve arrT1[iT1];  
    arrT1[iT1] := {Comment};  
);  
arrT1[iT1]  

GetAllCommentsT2 and GetAllCommentsT3 are identical except that all instances of "T1" are replaced with "T2" and "T3" respectively. I placed these three formulas in the Details section (this section is suppressed: only Group Footer 2a through 2d are enabled).

To display the results, I created three formulas (DisplayT1Comments, DisplayT2Comments, and DisplayT3Comments). All are similar to this:

WhilePrintingRecords;  
stringvar array arrT1;  
join (arrT1, CHR(13) + CHR(13))

with "T1" replaced with "T2" or "T3" as appropriate. DisplayT1Comments is placed in Group Footer 2b, DisplayT2Comments is placed in Group Footer 2c, and DisplayT3Comments is placed in Group Footer 2d.

Using the data mentioned at the beginning of this question, for StudentID: 999991 DisplayT1Comments is "Pam is good!\n\nPam is okay!", and that's exactly what prints in Group Footer 2b. Since no T2 or T3 comments have been entered yet (verified directly in the database), I would expect both DisplayT2Comments and DisplayT3Comments to be null. However, when I run the subreport the contents all three footers are displaying "Pam is good!\n\nPam is okay!"

Any ideas what I've done wrong? Or maybe suggestions for a better solution (i.e.: one that works!) to my problem? Thanks!

Was it helpful?

Solution

The problem was a stupid logic error on my part: the line that read

if not(({Comment} in arrT1) and ({CName} like "T1*")) then

should have had the not moved inside the first parenthesis, so it negated ({Comment} in arrT1), and not the whole thing. That's what I get for blindly rushing in to modify existing code rather than sit down to think for a moment. Thanks to those who asked for clarification.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top