Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula to determine positive/negative value

Status
Not open for further replies.

hankjeff

Programmer
Jun 20, 2003
6
0
0
US
In determining the total of an amount field in all of the records on an input file, I need to either add or subtract the number contained in the amount field based on the value found in another field. That "flag" is either 10 (positive) or 60 (negative) (this was not my idea - the software came that way!)

I would have written it this way in COBOL:

IF FLAG = 10, ADD AMOUNT TO TOTAL_AMOUNT
ELSE SUBTRACT AMOUNT FROM TOTAL_AMOUNT.

This input file will potentially be used in many reports so I want to develop a function which can simply be called in rather than having to write the code multiple times.

Can somebody please give a CR newbie some quick help here with what probably is a very basic task? Thanks a bunch.
 
I'd create a formula something like:

if {table.flag = 10 then
AMOUNT
else
AMOUNT*-1

Use thi formula in lieu of the field for summing, etc..

-k
 
I would use a formula like this

//@SumWeirdData

WhilePrintingRecords;
numbervar Amount;

if {table.flag} = 10 then
Amount := Amount + {Table.ABS Value}
else
Amount := Amount - {Table.ABS Value};


in the Group header I would put this initialization formula

//Initialization (suppressed)

WhilePrintingRecords;

if not InRepeatedGroupHeader then
numbervar Amount := 0;




Jim Broadbent

The quality of the answer is directly proportional to the quality of the problem statement!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top