‎2014 Oct 02 7:45 AM
Hi All,
I have noted something that can be done when processing internal tables but doesn't seem to work for Select statements against a DB table.
So, lets say I have class ZCL_MyClass which has a static method GET_RANGE.
The static method returns a Range.
If I have an internal (lt_tab) I can do the following:
delete lt_tab where statu in ZCL_MyClass=>GET_RANGE( ).
Is it possible to do something similar when using SQL. for example something like:
select *
into table lt_tab
from mara
where statu in ZCL_MyClass=>GET_RANGE( ).
I have a number of ways I would also like to use this scenario (basically using the class method like a function is used in other languages) but this scenario is specifically what I am interested in at the moment.
I was also wondering whether (if the scenario is possible) whether a singleton would be a good idea in this case?
I have searched the forums but nothing similar seemes to come up.
Look forward to hearing the replies
Many thanks
Gaz Hawkins
‎2014 Oct 02 12:15 PM
select *
into table lt_tab
from mara
where statu in ZCL_MyClass=>GET_RANGE( ).
SQL conditions seem to have a more restrictive syntax. How about trying the following:
data(rt_statu) = ZCL_MyClass=>GET_RANGE( ).
select *
into table lt_tab
from mara
where statu in rt_statu.
‎2014 Oct 02 12:49 PM
Hi Eric,
That is certainly would be neater than declaring the range and doing a method call.
Unfortunately that doesnt compile.
Although that is another point that would be nice to know.. can we can shortcut method calls in other ways.. for example in an IF statement.
if lv_myvar = zcl_myclass=>get_var( ).
"Do stuff
EndIf.
OR
if lv_myvar = zcl_myclass=>get_var(exporting it_check = lv_check).
"Do stuff
EndIf.
Having used OO in other programming languages and being able to do similar the above using functions it would be useful to use it in ABAP.
Thanks for the reply
Gaz Hawkins
‎2014 Oct 02 1:41 PM
Something like:
if lv_flag eq return_bool( ).
clear sy-subrc.
endif.
But it only works in ABAP release 7.4.
‎2014 Oct 02 1:53 PM
‎2014 Oct 02 3:32 PM
Thanks Eric and Raymond,
Your answers prompted my to try this out and for IF (and CASE by the sound of it) you can use a methods RETURNING parameter to acheive this.
if we have a class:
class lcl_test definition.
PUBLIC SECTION.
CLASS-METHODS: get_value importing iv_num type i
RETURNING value(EV_NUMBER) type i.
endclass.
class lcl_test IMPLEMENTATION.
METHOD GET_VALUE.
ev_number = 2.
ENDMETHOD.
endclass.
We can then use this in an IF statement like:
data:lv_ret type i.
lv_ret = 1.
if lv_ret = lcl_test=>get_value( iv_num = 1 ). "this would not match as method returns 2
"matched....
endif.
So, I can do what I want to do in general code but SQL statements seem to be a different beast.
Anyone acheived anything similar in SQL?
Thanks Again for the replies
Gaz Hawkins
‎2014 Oct 02 5:26 PM