Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ODD, EVEN in CDS

0 Kudos

Hi Experts,

I have below requirement -

All material movement types ending with an odd number, e.g. 101, 201, 221… should be positive amount number, and all movement types ending with an even number, e.g. 102, 202, 222… should Amount be negative number.

As BWART(Movement type) is char field how can i achieve this using MOD or any other way?

1 ACCEPTED SOLUTION

pmcfarling
Participant

You could cast and use mod but might run into issue if BWART isn't a number.

Here's an easy thing to do.

define view ZODD_TEST as select from t156 {

    key bwart as MovementType,

    case right(bwart,1) when '1' then 'X' when '3' then 'X' when '5' then 'X' when '7' then 'X' when '9' then 'X' else '' end as isOdd

}


1 REPLY 1

pmcfarling
Participant

You could cast and use mod but might run into issue if BWART isn't a number.

Here's an easy thing to do.

define view ZODD_TEST as select from t156 {

    key bwart as MovementType,

    case right(bwart,1) when '1' then 'X' when '3' then 'X' when '5' then 'X' when '7' then 'X' when '9' then 'X' else '' end as isOdd

}