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

Crosstab report using ALV grid

Former Member
0 Likes
1,242

Is it possible to develop a crosstab report using ALV grid?

By crosstab report I mean one or more columns of data may be displayed horizontally as columns(column headers).

eg. A row may represent a customer and year wise sales as columns. i.e. no of columns may be determined dynamically upon the selection criteria(or may be some other criteria)

_______2002_______2003______2004..(determined dynamically)

Cust1

Cust2

Cust3

:

:

If possible please tell me how to do it.

The field catalog can be generated dynamically which is possible but

how can the data internal table which we need to pass to the function or method to display the data be structured dynamically. Is there any provision in fieldcatalog to mark a column in internal table as a crosstab column?

Further, Can a column have multiple header texts?

____________2002___________2003_________2004....

________jan__feb__mar......

Cust1

Cust2

Cust3

:

:

Please guide me how to go about it.

Regards,

Amit Trivedi.

Is it possible to develop a crosstab report using ALV grid?

By crosstab report I mean one or more columns of data may be displayed horizontally as columns(column headers).

eg. A row may represent a customer and year wise sales as columns. i.e. no of columns may be determined dynamically upon the selection criteria(or may be some other criteria)

_______2002_______2003______2004..(determined dynamically)

Cust1

Cust2

Cust3

:

:

If possible please tell me how to do it.

The field catalog can be generated dynamically which is possible but

how can the data internal table which we need to pass to the function or method to display the data be structured dynamically. Is there any provision in fieldcatalog to mark a column in internal table as a crosstab column?

Further, Can a column have multiple header texts?

____________2002___________2003_________2004....

________jan__feb__mar......

Cust1

Cust2

Cust3

:

:

Please guide me how to go about it.

Regards,

Amit Trivedi.

6 REPLIES 6
Read only

Former Member
0 Likes
1,069

<i>A row may represent a customer and year wise sales as columns. i.e. no of columns may be determined dynamically upon the selection criteria(or may be some other criteria)</i>

Determination of number of columns may be determined dynamically is possible. You have to dabble with

a) AT NEW CUSTOMER

b) ASSIGN COMPONENT .... OF STRUCTURE .... TO ....

Multiple header texts, I do not think is possible.

Regards,

Subramanian V.

Read only

0 Likes
1,069

Hi Subramanian,

see if we fm use reuse_alv_grid_display for ALVgrid, we need to pass an internal table in tables parameter. right?

This is a table whose data is plainly displayed in the output. (as per the fieldcatalog).

But in a crosstab report i will need to add the columns to this internal table dynamically. i.e depending upon the selection criteria, there may be 10 columns or 20 or any number of columns. My question is how this can be achieved?

the further extension of question is,

there are chances that there may be more than 1 column as crosstab columns.

______________2002___________2003_________2004....

__________jan__feb__mar..........jan__feb__mar__

Cust1

Cust2

Cust3

:

:

i.e. for a particular month in a year, the sales for each customer is displayed.

how can this be done if no of columns is to be determined dynamically.

Hope you get what i mean to say.

Thanks n regards,

Amit Trivedi

Read only

0 Likes
1,069

Hi Amit,

You can have a look at this weblog /people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

It talks about creating dynamic internal tables.

Once you have created your dynamic internal table, the next step you would be looking for is to create a fieldcatalog. Had you known the number of columns, it would have hardly been an issue, since you don't, using FIELD-SYMBOLS , I am sure this is possible.

Let us say, you have created this dynamic internal table with months. We shall call it LT_DYNAMICTABLE.


LOOP AT LT_DYNAMICTABLE.
 DO.
  ASSIGN COMPONENT SY-TABIX OF LT_DYNAMICTABLE TO <FS>.
  if sy-subrc <> 0.
     exit.
  endif.
*** Fill fieldcatalog here   (1)
 ENDDO.
ENDLOOP.

What the above code basically does is, goes through every field of your internal table and you can put that field in the fieldcatalog. Now question is, how to find the name of the month ?

You can put months in the dynamic internal table as

LT_DYNAMICTABLE - Structure

MONTH1

MONTH2

...

MONTH20 (have any upper limit you want but decide on the upper limit).

Now it is easy to determine from sy-index, which month you are referring to.


*** Fill fieldcatalog here (1)
concatenate 'MONTH' SY-INDEX(of type character) TO LS_FIELDCATALOG-FIELDNAME.
LS_FIELDCATALOG-TABNAME = 'LT_DYNAMICTABLE'.
append LS_FIELDCATALOG TO LT_FIELDCATALOG.

Let me know if you are not clear on any part.

Regards,

Subramanian V.

Read only

Former Member
0 Likes
1,069

Dear Amit Trivedi,

Your question is very nice and very practically

required.

What i understand from your question is :

"The cross-tab should come automatically from the data"

But presently i feel that it is not possible.

The logic for it, the internal table definition

for it -- all has to be done programatically,

to display in a cross-tab format.

Thanks & Regards,

Amit Mittal.

Read only

0 Likes
1,069

Hi Amit,

thanks for ur reply.

ya its real practical and a very basic requirement for any type of reporting.

I have been pondering over it for quite some time now but still unable to find a soln.

yes the crosstabs should come automatically from data.

i.e there can be variable number of columns depending upon the selection criteria.

Please guide me about it if you can.

regards,

Amit Trivedi

Read only

Former Member
0 Likes
1,069

HI,

I too required the same answer...

plz message me if u get the answer....

i need how to represent thecross tab format through quick viewer....

it will b very useful for me if u help in this...