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

Table Expressions for Method Return Parameter

MichiFr
Participant
0 Likes
2,200

Hi,

I wonder why I can't use table expression with return parameters.

For example: The method JOB_GET_LIST( ) returns a table of type TBTCJOB_TT.

Now I would like to find one or more lines in this table where its STATUS is aborted. Of course I could do this using two lines of code, however, I wanted to try this task with a single line of coding like this:

IF line_exists( me->JOB_GET_LIST( )[ STATUS = 'A' ] ).

...

ENDIF.

This does not work as expected, at least not this way. Maybe I can't use table expressions with method return parameters at all, right?

Thanks,

Michael

1 ACCEPTED SOLUTION
Read only

ralf_wenzel_heuristika
Active Participant
0 Likes
1,872

Michael Fritz wrote:

(....)

This does not work as expected, at least not this way. Maybe I can't use table expressions with method return parameters at all, right?

Right.

9 REPLIES 9
Read only

former_member206650
Active Participant
0 Likes
1,872

Hi Micheal,

can you try the syntax

lt_TBTCJOB TYPE TABLE OF TBTCJOB_TT

lt_TBTCJOB = me-> JOB_GET_LIST( STATUS = 'A')

IF lt_TBTCJOB is bound.


//code here


ENDIF.

Read only

0 Likes
1,872

Hi,

my example type TBTCJOB_TT is already a DDIC defined table which is used in many SAP standard function modules like the one I'm using in my method JOB_GET_LIST().

The name of the function module is e.g. BP_JOB_SELECT that itself returns a table of type TBTCJOB_TT.

I'm using this result table and return it to the caller of my method without any modification. This means the content of this table contains many line with different status.

In order to filter one of those lines I thought about a kind of chaining that would safe some lines of coding. e.g. data(lt_aborted) = me->job_get_list( )[ status = 'A'] )

Michael

Read only

0 Likes
1,872

Hi,

lt_aborted what u mentioned and lt_TBTCJOB are the same.I just gave data declaration.


saving these line of code (checking together if condition and filling the internal table)won't be having such impact.


also it will be much better if you use pattern for calling method,since the other Abaper will have ease when working on it later.

Read only

Former Member
0 Likes
1,872

Hi,

for example you can define a table type in SE11 and refer to it as type in the method-table parameter.

or you can define a class-type and refer to it via "type"

you have to use type "tabletype"

you can no longer use "type table of" when working with abap-oo

regards

Stefan Seeburger

Read only

0 Likes
1,872

Stefan,

please see my answer above. The result type of my method is already a DDIC defined table type.

I just wanted to filter the method's result table without having to use an additional data declaration and that finally gets the method's result table.

In a further step I have to filter the result table, which can of course be done, with some further coding or as I tried before, using some table expressions and filter the method's result this way.

Michael

Read only

0 Likes
1,872

Dear Micheal,

As per my understanding, it's not possible to use your expression.

JOB_GET_LIST( )[ STATUS = 'A' ] ).

...

take the return parameter in local table and then use read statement .

Thanks

Nishant

Read only

ralf_wenzel_heuristika
Active Participant
0 Likes
1,873

Michael Fritz wrote:

(....)

This does not work as expected, at least not this way. Maybe I can't use table expressions with method return parameters at all, right?

Right.

Read only

ChristianGnter
Contributor
0 Likes
1,872

Well, you can use the return parameters of methods in iteration expressions. E.g. to fullfill your requirement you can do something like this.


IF lines( VALUE tbtcjob_tt( FOR job IN job_get_list( )
                                    WHERE ( status = 'A' )
                                    ( job ) ) ) > 0.
ENDIF.

Ok, it's not one line but one expression. You can condense it into one line, but it won't improve readability.

Read only

0 Likes
1,872

Christian,

as usual this is a possible and correct solution.

You know I do not really concern about readability, since I'm not only an ABAP rogrammer but C#, JS or Delphi developer, too, and I use those and much more confusing constructs every day

Thanks,

Michael