cancel
Showing results for 
Search instead for 
Did you mean: 

IF.....XOR.....

Former Member
0 Kudos

My questin is very simple, why can't I use XOR statement in ABAP? Some like this:

IF wa_lt_op_exist-status EQ 'PDST' XOR wa_lt_op_pos-status EQ 'PDST'.

Is there any similar function?

thanx!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Fer fer,

You can perform XOR only on bit-operands. It is not supported for logical operators. U need to use general rule for XOR as logical expressions in ABAP statements.

A XOR B = ((A OR B) AND NOT(A AND B))

In ur case,

A = wa_lt_op_exist-status EQ 'PDST' and

B = wa_lt_op_pos-status EQ 'PDST'.

For this part IF wa_lt_op_exist-status EQ 'PDST' XOR wa_lt_op_pos-status EQ 'PDST'

just replace the following part in ur report

IF ((wa_lt_op_exist-status EQ 'PDST' <b>OR</b> wa_lt_op_pos-status EQ 'PDST') <b>AND</b> (<b>NOT</b>(wa_lt_op_exist-status EQ 'PDST' <b>AND</b> wa_lt_op_pos-status EQ 'PDST')))

Thanks

Vinay

Message was edited by: Vinaykumar Gorrela

Former Member
0 Kudos

Thank U all!

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

You need to validate the two expressions using xor right.

<b>XOR Function:</b>

For eg. log_exp1 XOR log_exp2

1. if log_exp1 & log_exp2 are different it returns 1.

2. if log_exp1 & log_exp2 are same then it returns 0.

You can create a function which takes input parameters as 2 logical expressions and return 0 or 1 based on the processing in the functional module.

For Eg.

if log_exp1 = log_exp2.
result = 0.
else.
result = 1.
endif.

<i>Here make log_exp1 & log_exp2 as input parameters and

make result as the output parameter.</i>

By making this you can use this function in any of your programs. This is the powerful feature of ABAP.

You can create your own functional module in se37.

A sample functional module.

http://www.sap-img.com/abap/function-to-return-next-business-day.htm

Hope it helps.

Regards,

Maheswaran.B

Message was edited by: Maheswaran B

manuel_bassani
Contributor
0 Kudos

Hi,

there isn't an ABAP XOR statememt for boolean expressions. The thing you can do is translate XOR statement with an expression containing OR and AND

consider the following:


A	B	(a|B)	(a&B)	NOT(A&B)	(A|B)& NOT(A&B)
T	T	T	T	F		F
T	F	T	F	T		T
F	T	T	F	T		T
F	F	F	F	T		F

so A XOR B = ((A OR B) AND NOT(A AND B))

I hope this can be useful.

Regards, Manuel

manuel_bassani
Contributor
0 Kudos

you can translate your code with:


if ((wa_lt_op_exist-status EQ 'PDST' OR wa_lt_op_pos-status EQ 'PDST')
AND NOT(wa_lt_op_exist-status EQ 'PDST' AND wa_lt_op_pos-status EQ 'PDST'))

Regards, Manuel

former_member181962
Active Contributor
0 Kudos

Hi fer fer,

This is an excerpt from the abap documentation.

"COMPUTE - Bit Expression

Variant 2

COMPUTE x = bitexp.

Effect

The bit expression bitexp is calculated and the result placed in field x.

You can use the four bit operators BIT-NOT, BIT-AND, BIT-XOR and BIT-OR. The operands are linked according to the table below.

The priority is normal: BIT-NOT has priority over BIT-AND, followed by BIT-XOR, and then BIT-OR. You can use any number of parentheses.

All operands in bitexp, and the result field x, must have type X or type XSTRING.

The ABAP keyword COMPUTE is optional.

Relationship table

x y | BIT-NOT x x BIT-AND y x BIT-XOR y x BIT-OR y

-


0 0 | 1 0 0 0

0 1 | 1 0 1 1

1 0 | 0 0 1 1

1 1 | 0 1 0 1

Note

If the field lengths of the operands (on the right side of the expression) are different, they are all changed to the length of the result field x using MOVE X TOX. This means that shorter operands are filled with hexadecimal 0 characters on the right. Then the result field is filled. This also happens using MOVE X TOX. If the result field is of the type XSTRING, then the length is automatically adjusted.

Example

DATA: X1(1) TYPE X VALUE '30', " 0011 0000 BIT-XOR

X2(1) TYPE X VALUE '50'. " 0101 0000 =

X1 = X1 BIT-XOR X2. " 0110 0000

WRITE X1.

Output: 60

"

REgards,

Ravi

Former Member
0 Kudos

How can I use it in my sentence?

thanx

former_member181962
Active Contributor
0 Kudos

See this example:

DATA: X1(1) TYPE X VALUE '30', " 0011 0000 BIT-XOR

X2(1) TYPE X VALUE '50'. " 0101 0000 =

X1 = X1 BIT-XOR X2. " 0110 0000

WRITE X1.

Output: 60

REgards,

Ravi