cancel
Showing results for 
Search instead for 
Did you mean: 

How to create per section variable that is readable in same-section formula?

07-28-2023 8:53 AM
alexsr700 Participant
1545 views 6 comments
0 Likes
SAP Managed Tags
Subscribe

Good morning,

unfortunately my initial approach for using a formula to identify the section the formula is iused in, was not possible with built-in methods (https://answers.sap.com/questions/13931185/possible-to-use-if-with-referal-to-eg-details-b.html).

I now have a new approach but I seem to be getting one detail wrong.

Idea is to have a global stringvar as identifier in each section that changes value with section change. And then use this stringvar in a formula within that section.

//formula a
global stringvar section:="a"

//formula b
stringvar section:="b"

//formula test
stringvar section;
local numbervar test;

If section="a" Then
    test:=1
Else If section="b" Then
    test:=2;
test

However, the stringvar section is being shown correctly in each section but the result of test is always the same (that for the second section.

Does anybody see what I am doing wrong? Are formulas being executed even if they have not been used yet, i.e. global variable is declared before the formula is even being used?

Thank you

Alex

0 Likes

Accepted Solutions (0)

Answers (1)

Answers (1)

DellSC
Active Contributor
0 Likes

Try adding "WhilePrintingRecords;" to the top of your formula.

-Dell

alexsr700
Participant
0 Likes

Already tried WhileReading and WhilePrinting 😞

If I use whileprintingrecords, then both detail a and b return "1", so both think section="a".

DellSC
Active Contributor
0 Likes

You may have to use two different variables for the total.

-Dell

alexsr700
Participant
0 Likes

How do you mean? If I define a global variable in detail a and one in detail b, they will both be "true" aka their respective value throughout the entire report, will they not?

It seems the global variables are declared independently of where the formula that declares them is placed.

DellSC
Active Contributor
0 Likes

I'm trying to think around this. Also, looking at your formulas - try taking "Global" off the declaration of section in Formula A. If you're going to us a modifier on a variable, you have to use the same modifier the first time you use the variable in any formula. Otherwise Crystal might think you have two different variables.

For testing purposes, try this:

1. Create another formula that will give you the value of section at any point in time:

{@CurrentSection}
StringVar section;
section

2. Instead of using @a and @b in your report as above, use {@CurrentSection}.

-Dell