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: 

how to deal with number

former_member397166
Participant
0 Kudos

Hi all,

     In ABAP, can I get ther set of number{2, 3, 4, 5} if I pass the parameter the first number '2' and the last number '5'.

     And if A={2, 3, 4, 5}  and B = {3, 5}, is there a function which can caculat A - B = {2,4}?

Thanks

Kical

1 ACCEPTED SOLUTION

kumar_sp
Explorer
0 Kudos

Hi,

     Select-options is better way to your requirement. using the select-option and pass the range value 2 to 5 after u can use 'count' and write the code and pass internal table.

like this...

DATA v_num TYPE i.

SELECT-OPTIONS : p_num FOR v_num.

data count type c.

data diff type i.

diff = P_Num-high - P_Num-low.

data: a(6) TYPE c,

       low(6) TYPE c,

       high TYPE c. "LIKE RANGE OF v_num.

   count = p_num-low.

   LOw = p_num-low.

do diff TIMES.

       count = count + 1.

    if count <= P_Num-high.

      CONCATENATE low ',' count INTO a.

      low = a.

    ENDIF.

ENDDO.


Regards,

kumar.

9 REPLIES 9

Former Member
0 Kudos

Hi Kical,

As per my knowledge there is nothing like set in ABAP.

We can store a list only by using internal table.  we can create 2 internal tables as u require and get the result what u need.

Thanks,

Chandrajith

former_member424229
Participant
0 Kudos

Hi,

Use 'SELECT-OPTIONS' you can get the set of data in internal table format after that what you want can do on the internal tables.

former_member705265
Discoverer
0 Kudos

Hi  Kical,

I don't know there exist a function that can give you what you want, I'm sure if you can use loops and internal tables to meet your requirement.

kumar_sp
Explorer
0 Kudos

Hi,

     Select-options is better way to your requirement. using the select-option and pass the range value 2 to 5 after u can use 'count' and write the code and pass internal table.

like this...

DATA v_num TYPE i.

SELECT-OPTIONS : p_num FOR v_num.

data count type c.

data diff type i.

diff = P_Num-high - P_Num-low.

data: a(6) TYPE c,

       low(6) TYPE c,

       high TYPE c. "LIKE RANGE OF v_num.

   count = p_num-low.

   LOw = p_num-low.

do diff TIMES.

       count = count + 1.

    if count <= P_Num-high.

      CONCATENATE low ',' count INTO a.

      low = a.

    ENDIF.

ENDDO.


Regards,

kumar.

matt
Active Contributor
0 Kudos

No. There is no built in set handling as you describe. The problem with the above posts is that they're concentrating on the implementation, rather than the actual solution, which should be flexible and reusable.

The best approach is to create a class. E.g. ZCL_SET that has methods to do what you want. Then you can write

Pre 7.4

DATA set_a TYPE REF TO zcl_set.

CREATE OBJECT set_a.

set_a->define_set_by_bounds( i_low = 2 i_high = 5 ).

DATA set_b TYPE REF TO zcl_set.

CREATE OBJECT set_b.

set_b->add_element( 3 ).

set_b->add_element( 5 ).

DATA set_diff TYPE REF TO zcl_set.

CREATE OBJECT set_diff.

set_diff = set_a->diff( set_b ).

7.4 up

DATA(set_a) = NEW zcl_set( ).

set_a->define_set_by_bounds( i_low = 2 i_high = 5 ).

DATA(set_b) = NEW zcl_set( ).

set_b->add_element( 3 ).

set_b->add_element( 5 ).

DATA(set_diff) = NEW zcl_set( ).

set_diff = set_a->diff( set_b ).

Now create the class ZCL_SET that implements define_set_by_bounds, add_element, diff

You could use internal tables as suggested by the other posters, or something of your own. You might want to start by defining a class to handle elements. Then you could have something that can handle sets containing elements of any kind.

Former Member
0 Kudos

Hi Matthew ,

Can you please let me know ,how can i work to know available predefined classes in ABAP which can be used frequently in ABAP programming.

Please help me as i m in starting stage of ABAP.

matt
Active Contributor
0 Kudos

You just have to intelligently search the repository, or code that you think probably does what you need. If I need to handle infoobjects in BW for example, I'll search for classes containing "IOBJ". And then I find CL_RSD_IOBJ. Then I look at the methods, and do some "whereused" analysis and figure out how to use them.

Former Member
0 Kudos

Thank u Matthew for your suggestion.

former_member397166
Participant
0 Kudos

Thank you for all suggestion.