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: 

Generic object-orientated ALV with

Former Member
0 Kudos

Hello everyone!

I've got to solve a little problem and hope, to finde some help here.

My goal is a global ALV-class, that can be used by programms to easily create ALV's.

I want to use a generate_output method within this class, that takes any internal table as a parameter and generates an ALV out of it. So when you got an internal table, you just have to create an instance of the global alv class and run the output method with your table as parameter to get a basic alv (later I'm planning to use sub-classes of this basic, global alv class, for more specified and program-related alv's.).

But for now, that's all I need to do.

So it should look and work like this:

DATA: lo_alv TYPE REF TO zcl_alv_report. "our global class instance
DATA: it_tab TYPE TABLE OF zzm_ehsanl.  "a random internal table
SELECT * FROM zzm_ehsanl INTO TABLE it_tab. "fill it with some data
CREATE OBJECT lo_alv. "let's create an instance of the global alv class
lo_alv->generate_output( it_tab ). "This line is supposed to be all we need for the alv

-


Now, let's take a look at the generate_output method within the global class.

methods GENERATE_OUTPUT importing alv_table type any table.

So we can use any internal table as a parameter.

Let's get to the implementation part:

METHOD generate_output.
  DATA: lx_msg TYPE REF TO cx_salv_msg.
  FIELD-SYMBOLS: <fs_itab> TYPE ANY TABLE.
  ASSIGN alv_table TO <fs_itab>. "assign the parameter to the field-symbol
  TRY.
    cl_salv_table=>factory("<=== that's the point where the dump occurs 
        IMPORTING            r_salv_table = o_alv
        CHANGING             t_table      = <fs_itab> ).
    CATCH cx_salv_msg INTO lx_msg.
  ENDTRY.

The further code shouldn't be relevant for my problem..

-


Edited and split up into 2 posts..

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos

Try changing the method parameter as the CHANGING.


methods GENERATE_OUTPUT CHANGING alv_table type any table

SALV object model interally try to change the table e.g for Sorting or Filtering, and that's why it is as the CHANGING parameter in the FACTORY method of the CL_SALV_TABLE.


cl_salv_table=>factory(
        IMPORTING            r_salv_table = o_alv
        CHANGING             t_table      = <fs_itab> ).    " << CHANGING

Regards,

Naimesh Patel

3 REPLIES 3

Former Member
0 Kudos

Well, sadly this dumps with "CX_SY_DYN_CALL_ILLEGAL_TYPE" at the specified point. It also says, that field <fs_itab> is protected against changes.

Well, right now I'm very stuck with this problem and don't know what to do.

Maybe there is another way to solve the issue?

Or a better alternative to the cl_salv_table=>factory method?

A strange thing is, that everything worked well, when I was been using a local class instead of the global one. But there was a little difference in the local implementation. You will notice, that the field symbol is declared within the generate_output method in this implementation. Because classes can't have any field symbols in their main declaration spaces. But when I used it with a local class, I put the declaration of the field-symbol to the point, where all normal global program data is defined. So in the local implementation, the field symbol was not declared within any class-code, but globally within the report. Maybe this is a start for a possible solution to this problem.

Any help is very appreciated!

Thanks & regards in forward.

naimesh_patel
Active Contributor
0 Kudos

Try changing the method parameter as the CHANGING.


methods GENERATE_OUTPUT CHANGING alv_table type any table

SALV object model interally try to change the table e.g for Sorting or Filtering, and that's why it is as the CHANGING parameter in the FACTORY method of the CL_SALV_TABLE.


cl_salv_table=>factory(
        IMPORTING            r_salv_table = o_alv
        CHANGING             t_table      = <fs_itab> ).    " << CHANGING

Regards,

Naimesh Patel

0 Kudos

Hello Naimesh,

thanks a lot for the fast reply.

Your answer helped me to solve the problem.

Thanks!

Regards

Moritz