Application Development and Automation 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: 
Read only

SET OPERATORS IN ABAP

Former Member
0 Likes
1,162

Hi Friends,

I want to compare a variable has any of the 25 stored values in internal table or any variable?

Is there any SET operation possible using ABAP like IN , UNION, NOT IN etc.,

Thanks in advance,

Durai.

Hi Friends,

I want to compare a variable has any of the 25 stored values in internal table or any variable?

Is there any SET operation possible using ABAP like IN , UNION, NOT IN etc.,

Thanks in advance,

Durai.

3 REPLIES 3
Read only

Former Member
0 Likes
672

Hi,

Set Operations Using Bit Sequences

If you have a set of m elements, you can represent any subset as a sequence of bits. If the nth element of the set is present in a subset, the n th bit is set to 1, otherwise, it is set to 0. The universal set therefore contains no zeros.

In ABAP, you can represent a set of m elements using a field with type X and length of at least m/8. To include a member of the universal set in a set, use the SET BIT statement. To check which members of the universal set are included in a particular set, use the GET BIT statement. You can use bit operations for the following set operations:

Set operation

Bit operation

Intersection

BIT-AND

Union

BIT-OR

Symmetrical difference

BIT-XOR

You can also use the O operator when comparing bit sequences to determine whether a particular set is a subset of another.

DATA: FRANKFURT(4) TYPE X,

FRISCO(4) TYPE X,

INTERSECT(4) TYPE X,

UNION(4) TYPE X,

BIT TYPE I.

DATA: CARRID TYPE SPFLI-CARRID,

CARRIER LIKE SORTED TABLE OF CARRID

WITH UNIQUE KEY TABLE LINE.

DATA WA TYPE SPFLI.

SELECT CARRID FROM SCARR INTO TABLE CARRIER.

SELECT CARRID CITYFROM FROM SPFLI

INTO CORRESPONDING FIELDS OF WA.

WRITE: / WA-CARRID, WA-CITYFROM.

READ TABLE CARRIER FROM WA-CARRID TRANSPORTING NO FIELDS.

CASE WA-CITYFROM.

WHEN 'FRANKFURT'.

SET BIT SY-TABIX OF FRANKFURT.

WHEN 'SAN FRANCISCO'.

SET BIT SY-TABIX OF FRISCO.

ENDCASE.

ENDSELECT.

INTERSECT = FRANKFURT BIT-AND FRISCO.

UNION = FRANKFURT BIT-OR FRISCO.

SKIP.

WRITE 'Airlines flying from Frankfurt and San Francisco:'.

DO 32 TIMES.

GET BIT SY-INDEX OF INTERSECT INTO BIT.

IF BIT = 1.

READ TABLE CARRIER INDEX SY-INDEX INTO CARRID.

WRITE CARRID.

ENDIF.

ENDDO.

SKIP.

WRITE 'Airlines flying from Frankfurt or San Francisco:'.

DO 32 TIMES.

GET BIT SY-INDEX OF UNION INTO BIT.

IF BIT = 1.

READ TABLE CARRIER INDEX SY-INDEX INTO CARRID.

WRITE CARRID.

ENDIF.

ENDDO.

This produces the following output list:

AA NEWYORK

AA SANFRANSISCO

AZ ROME

AZ ROME

AZ TOKYO

AZ ROME

DL NEWYORK

DL SANFRANSISCO

The program uses four hexadecimal fields with length 4 - FRANKFURT, FRISCO, INTERSECT, and UNION. Each of these fields can represent a set of up to 32 elements. The basic set is the set of all airlines from database table SCARR. Each bit of the corresponding bit sequences representes one airline. To provide an index, the external index table CARRIER is created and filled with the airline codes from table SCARR. It is then possible to identify an airline using the internal index of table CARRIER.

In the SELECT loop for database table SPFLI, the corresponding bit for the airline is set either in the FRANKFURT field or the FRISCO field, depending on the departure city. The line number SY-TABIX is determined using a READ statement in which no fields are transported.

The intersection and union of FRANKFURT and FRISCO are constructed using the bit operations BIT-AND and BIT-OR.

The bits in INTERSECT and UNION are read one by one and evaluated in two DO loops. For each position in the fields with the value 1, a READ statement retrieves the airline code from the table CARRIER.

<REMOVED BY MODERATOR>

Cheers,

Chandra Sekhar.

Edited by: Alvaro Tejada Galindo on Mar 4, 2008 2:50 PM

Read only

Former Member
0 Likes
672

If u want to pass values from 1 screen to othet screen we use memory id to

pass values from one screen to another screen using set & get parameters.

SET PARAMETER command's function is to create a storage location in memory &

retrieve its contents.The set parameter statement is issued in PAI ,the

value must be input into the fields first before it can be placed in the

buffer.

Syntax : SET PARAMETER ID <pid> FIELD <f>.

This statement saves the content of field <f> under the ID <pid> in tha sap memory.

GET PARAMETER command's function is to pass data from the screen fields to

the abap program.

Syntax : GET PARAMETER ID <pid> FIELD <f>.

This statement fills the value stored under the ID <pid> into the variable

<f>.

SET CURSOR : -

SET CURSOR FIELD <f> .

This statement keeps the name of the screen element on which the cursor is

positioned .

GET CURSOR : -

GET CURSOR FIELD <f> .

This statement transfers the name of the screen element on which the cursor

is positioned during a user action into the variable <f>.

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Mar 4, 2008 2:51 PM

Read only

Former Member
0 Likes
672

Hi Chandrasekar & Sravan

I can compare a variable for a set of values in where

clause of a select query using IN or NOT IN but is it possible

to the set operations in control structures like IF , CASE , WHILE , LOOP etc.,

Durai.