cancel
Showing results for 
Search instead for 
Did you mean: 

How to use ROUND( ) function to a nested case statement

Albatross
Explorer
0 Kudos

Hi There!
I wrote the below case statement. But it is not giving the required results. I WANT 93,855 BUT I'M GETTING 938.5566666666666666666 like this. 

 

(SELECT CASE (MAIN.RECEIPT+MAIN.ISSUE) WHEN 0 THEN 0.0 ELSE MAIN.AMOUNT/(MAIN.RECEIPT+MAIN.ISSUE) END)  AS UNITP

 

So I tried writing the nested case statement for the above line and it worked but in the output, I'm getting so many numbers after decimal. I want the number to round off and I have tried ROUND( ) as well it is throwing an error maybe I misplaced the function. Can anyone let me know how to use ROUND( ) in nested case statements? Thanks

 

CASE
	WHEN 
		case MSEG.SHKZG when 'S' then MSEG.MENGE else 0.0 end
		+
		case MSEG.SHKZG when 'H' then MSEG.MENGE else 0.0 end = 0
	THEN 0.00
ELSE
	CASE
		WHEN 
			CASE WHEN MSEG.DMBTR = 0 THEN 0 ELSE 0.00 END = 0
			AND 
			CASE WHEN MSEG.MENGE = 0 THEN 0 ELSE 0.00 END = 0
			AND
			case MSEG.SHKZG when 'S' then MSEG.MENGE else 0.0 end = 0
			AND
			case MSEG.SHKZG when 'H' then MSEG.MENGE else 0.0 end = 0
		THEN 0
	ELSE
			MSEG.DMBTR/
			(case MSEG.SHKZG when 'S' then MSEG.MENGE else 0.0 end
			+
			case MSEG.SHKZG when 'H' then MSEG.MENGE else 0.0 end)
	END
END
AS UNITP,

 

 

  • SAP Managed Tags:
Sandra_Rossi
Active Contributor
0 Kudos
1) Is it ABAP, ABAP CDS or HANA CDS? 2) There are two questions in one, frst one: why it's multiplied by 10 (NO REASON, CHECK YOUR DATA AGAIN), second one: why it's not rounded. You should use CAST to type correctly your result.

Accepted Solutions (0)

Answers (0)