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: 

Display data in pivot format in ALV

Former Member
0 Kudos
792

Hi Experts,

I got some problem with data display in ALV. I had my internal table full of data, but I want it to be displayed in ALV in a special way. For example, I had the internal table of 3 fields: A,B, Ca & Cb with data like A1, B1....

-


A

B

Ca

Cb

-


A1

B1

C1

Cat

-


A1

B1

C2

Cry

-


A2

B2

C1

Cat

-


A2

B2

C2

Cry

-


A3

B3

C3

Car

-


Can they be displayed in ALV in a pivotal form like below

-


A

B

Cat

Cry

Car

-


A1

B1

C1

C2

-


A2

B2

C1

C2

-


A3

B3

C3

-


Appreciate any kind of help provided. Many thanks in advance.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
355

HI,

PERFORM change_headings

USING

*.. Table name

'?' "put your table name i here!!

*.. Fieldname

'M112005'

*.. Short...

'NOV 2005'

*.. Long

'November 2005'

*.. Medium

'November 2005'

*.. Dictionary Heading

'November 2005'.

*

&----


*& Form change_headings

&----


  • Changes the short, long, medium and and dictionary heading

  • fields for a given output field.

----


  • -->us_fieldname name of field to deal with

  • -->us_short text for short heading

  • -->us_long text for long heading

  • -->us_medium text for medium heading

  • -->us_heading text for dictionary heading

----


FORM change_headings

USING

us_tabname TYPE tabname

us_fieldname TYPE fieldname

us_short TYPE scrtext_s

us_long TYPE scrtext_l

us_medium TYPE scrtext_m

us_heading TYPE reptext.

*.. Short...

PERFORM set_fieldcat_attribute

USING

us_tabname

us_fieldname

'seltext_S'

us_short

t_fieldcat.

*.. Long

PERFORM set_fieldcat_attribute

USING

us_tabname

us_fieldname

'seltext_L'

us_long

t_fieldcat.

*.. Medium

PERFORM set_fieldcat_attribute

USING

us_tabname

us_fieldname

'seltext_M'

us_medium

t_fieldcat.

*.. Dictionary Heading

PERFORM set_fieldcat_attribute

USING

us_tabname

us_fieldname

'reptext_ddic'

us_heading

t_fieldcat.

ENDFORM. " change_headings

*

&----


*& Form SET_fieldCAT_attribute

&----


  • sets a fieldcat attribute,

  • e.g. can hide a field in ALV output, change title, etc

----


  • -->pv_table table name

  • -->pv_field field name

  • -->pv_attrib name of attribute to be changed

  • -->pv_newval new value to be put in attribute

  • -->pt_fieldcat field catlog

----


FORM set_fieldcat_attribute

USING pv_table TYPE tabname

pv_field TYPE fieldname

pv_attrib TYPE fieldname

pv_newval TYPE any

pt_fieldcat TYPE slis_t_fieldcat_alv

.

FIELD-SYMBOLS: <attrib>,

<fieldcat> TYPE slis_fieldcat_alv.

  • ensure working in upper case

TRANSLATE pv_table TO UPPER CASE.

  • ensure working in upper case

TRANSLATE pv_field TO UPPER CASE.

  • find the entry matching the input fieldname

READ TABLE pt_fieldcat ASSIGNING <fieldcat>

WITH KEY fieldname = pv_field tabname = pv_table.

  • if found..

IF sy-subrc = 0.

*.. set up the full name of field

CONCATENATE '<FIELDCAT>-' pv_attrib INTO w_field_name.

*.. point a field-symbol to it

ASSIGN (w_field_name) TO <attrib>.

*.. fill it with the input new value

<attrib> = pv_newval.

ENDIF.

ENDFORM. " set_fieldcat_attribute

-


assume itab-date1 = M112005

assume itab-date2 = M112004

assume itab-date3 = M122005

assume itab-date4 = M112004

data : begin of itab1 occurs 0,

mon(2) type c, " example 11

mon_desc(15) type c, "example november

end of itab1.

loop at itab.

l_mon1 = itab-date1+1(2).

l_year1 = itab-date1+3(4).

itab1-mon = l_mon1.

append itab1.

clear itab1.

l_mon2 = itab-date2+1(2).

l_year2 = itab-date2+3(4).

itab1-mon = l_mon2.

append itab1.

clear itab1.

l_mon3 = itab-date3+1(2).

l_year3 = itab-date3+3(4).

itab1-mon = l_mon3.

append itab1.

clear itab1.

l_mon4 = itab-date4+1(2).

l_year4 = itab-date4+3(4).

itab1-mon = l_mon3.

append itab1.

clear itab1.

delete adjacent duplicates from itab1 comparing mon.

  • write one perform here to get month description for given month using CASE statement and store in itab1-mon_desc.

loop at itab1.

if l_mon_desc1 is initial.

l_mon_desc1 = itab1-mon_desc.

else.

l_mon_desc2 = itab1-mon_desc.

endif.

endloop.

write : 'material description' ,l_mon_desc1 , l_mon_desc2.

write : l_year1 ,l_year2 ,l_year3 ,l_year4 .

just assuming the layout what u had given

PLS: AWARD POINTS .

SRI

1 REPLY 1

Former Member
0 Kudos
356

HI,

PERFORM change_headings

USING

*.. Table name

'?' "put your table name i here!!

*.. Fieldname

'M112005'

*.. Short...

'NOV 2005'

*.. Long

'November 2005'

*.. Medium

'November 2005'

*.. Dictionary Heading

'November 2005'.

*

&----


*& Form change_headings

&----


  • Changes the short, long, medium and and dictionary heading

  • fields for a given output field.

----


  • -->us_fieldname name of field to deal with

  • -->us_short text for short heading

  • -->us_long text for long heading

  • -->us_medium text for medium heading

  • -->us_heading text for dictionary heading

----


FORM change_headings

USING

us_tabname TYPE tabname

us_fieldname TYPE fieldname

us_short TYPE scrtext_s

us_long TYPE scrtext_l

us_medium TYPE scrtext_m

us_heading TYPE reptext.

*.. Short...

PERFORM set_fieldcat_attribute

USING

us_tabname

us_fieldname

'seltext_S'

us_short

t_fieldcat.

*.. Long

PERFORM set_fieldcat_attribute

USING

us_tabname

us_fieldname

'seltext_L'

us_long

t_fieldcat.

*.. Medium

PERFORM set_fieldcat_attribute

USING

us_tabname

us_fieldname

'seltext_M'

us_medium

t_fieldcat.

*.. Dictionary Heading

PERFORM set_fieldcat_attribute

USING

us_tabname

us_fieldname

'reptext_ddic'

us_heading

t_fieldcat.

ENDFORM. " change_headings

*

&----


*& Form SET_fieldCAT_attribute

&----


  • sets a fieldcat attribute,

  • e.g. can hide a field in ALV output, change title, etc

----


  • -->pv_table table name

  • -->pv_field field name

  • -->pv_attrib name of attribute to be changed

  • -->pv_newval new value to be put in attribute

  • -->pt_fieldcat field catlog

----


FORM set_fieldcat_attribute

USING pv_table TYPE tabname

pv_field TYPE fieldname

pv_attrib TYPE fieldname

pv_newval TYPE any

pt_fieldcat TYPE slis_t_fieldcat_alv

.

FIELD-SYMBOLS: <attrib>,

<fieldcat> TYPE slis_fieldcat_alv.

  • ensure working in upper case

TRANSLATE pv_table TO UPPER CASE.

  • ensure working in upper case

TRANSLATE pv_field TO UPPER CASE.

  • find the entry matching the input fieldname

READ TABLE pt_fieldcat ASSIGNING <fieldcat>

WITH KEY fieldname = pv_field tabname = pv_table.

  • if found..

IF sy-subrc = 0.

*.. set up the full name of field

CONCATENATE '<FIELDCAT>-' pv_attrib INTO w_field_name.

*.. point a field-symbol to it

ASSIGN (w_field_name) TO <attrib>.

*.. fill it with the input new value

<attrib> = pv_newval.

ENDIF.

ENDFORM. " set_fieldcat_attribute

-


assume itab-date1 = M112005

assume itab-date2 = M112004

assume itab-date3 = M122005

assume itab-date4 = M112004

data : begin of itab1 occurs 0,

mon(2) type c, " example 11

mon_desc(15) type c, "example november

end of itab1.

loop at itab.

l_mon1 = itab-date1+1(2).

l_year1 = itab-date1+3(4).

itab1-mon = l_mon1.

append itab1.

clear itab1.

l_mon2 = itab-date2+1(2).

l_year2 = itab-date2+3(4).

itab1-mon = l_mon2.

append itab1.

clear itab1.

l_mon3 = itab-date3+1(2).

l_year3 = itab-date3+3(4).

itab1-mon = l_mon3.

append itab1.

clear itab1.

l_mon4 = itab-date4+1(2).

l_year4 = itab-date4+3(4).

itab1-mon = l_mon3.

append itab1.

clear itab1.

delete adjacent duplicates from itab1 comparing mon.

  • write one perform here to get month description for given month using CASE statement and store in itab1-mon_desc.

loop at itab1.

if l_mon_desc1 is initial.

l_mon_desc1 = itab1-mon_desc.

else.

l_mon_desc2 = itab1-mon_desc.

endif.

endloop.

write : 'material description' ,l_mon_desc1 , l_mon_desc2.

write : l_year1 ,l_year2 ,l_year3 ,l_year4 .

just assuming the layout what u had given

PLS: AWARD POINTS .

SRI