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

URGENT: ALV with variable headers

Former Member
0 Likes
497

Hi everyone!

I need to output an ALV report that will have a header and item lines per MATNR encountered. All the data will come from a single internal table. Example:

<<HEADER>>

-


MATERIAL: 10071199

DATE: 20.10.2006

-


<<LINE ITEM>>

CHARG | ERFMG | ERFMR | BUDAT |

001 | ABC | XXR | 10.06 |

<<HEADER>>

-


MATERIAL: 10071200

DATE: 27.10.2006

-


<<LINE ITEM>>

CHARG | ERFMG | ERFMR | BUDAT |

001 | DEF | XXM | 10.06 |

What are the best options in doing this? ALV LIST or GRID, if possible, are ok.

Thanks in advance.

Cris

Hi everyone!

I need to output an ALV report that will have a header and item lines per MATNR encountered. All the data will come from a single internal table. Example:

<<HEADER>>

-


MATERIAL: 10071199

DATE: 20.10.2006

-


<<LINE ITEM>>

CHARG | ERFMG | ERFMR | BUDAT |

001 | ABC | XXR | 10.06 |

<<HEADER>>

-


MATERIAL: 10071200

DATE: 27.10.2006

-


<<LINE ITEM>>

CHARG | ERFMG | ERFMR | BUDAT |

001 | DEF | XXM | 10.06 |

What are the best options in doing this? ALV LIST or GRID, if possible, are ok.

Thanks in advance.

Cris

4 REPLIES 4
Read only

gopi_narendra
Active Contributor
0 Likes
467

Use the function modules REUSE_ALV_FIELDCATALOG_MERGE to create field catalog from internal table and REUSE_ALV_GRID_DISPLAY to output the same in to a ALV Grid.

Check the sample code to fill a field catalog and output to ALV Grid

perform OUTPUT_ALV.

&----


*& Form OUTPUT_ALV

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form OUTPUT_ALV .

data : IT_FIELDCAT type SLIS_T_FIELDCAT_ALV,

IS_LAYOUT type SLIS_LAYOUT_ALV.

if IT_FIELDCAT is initial.

perform FIELD_FILL using IT_FIELDCAT.

endif.

  • Sub routine to set the layout

perform SET_LAYOUT using IS_LAYOUT.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

I_CALLBACK_PROGRAM = SY-REPID

IT_FIELDCAT = IT_FIELDCAT

IS_LAYOUT = IS_LAYOUT

I_SAVE = 'A'

tables

T_OUTTAB = IT_FINAL

exceptions

PROGRAM_ERROR = 1

others = 2.

if SY-SUBRC <> 0.

message id SY-MSGID type SY-MSGTY number SY-MSGNO

with SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

endform. " OUTPUT_ALV

&----


*& Form FIELD_FILL

&----


  • text

----


  • -->P_IT_FIELDCAT text

----


form FIELD_FILL using PT_FIELDCAT type SLIS_T_FIELDCAT_ALV.

data : LS_FIELDCAT type SLIS_FIELDCAT_ALV,

POS type I value 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'VKORG'.

LS_FIELDCAT-REF_FIELDNAME = 'VKORG'.

LS_FIELDCAT-REF_TABNAME = 'LIKP'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'VTEXT'.

LS_FIELDCAT-REF_FIELDNAME = 'VTEXT'.

LS_FIELDCAT-REF_TABNAME = 'TVKOT'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'KUNNR'.

LS_FIELDCAT-REF_FIELDNAME = 'KUNNR'.

LS_FIELDCAT-REF_TABNAME = 'LIKP'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'NAME1'.

LS_FIELDCAT-REF_FIELDNAME = 'NAME1'.

LS_FIELDCAT-REF_TABNAME = 'KNA1'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'ORT01'.

LS_FIELDCAT-REF_FIELDNAME = 'ORT01'.

LS_FIELDCAT-REF_TABNAME = 'KNA1'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'STRAS'.

LS_FIELDCAT-REF_FIELDNAME = 'STRAS'.

LS_FIELDCAT-REF_TABNAME = 'KNA1'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'VBELN'.

LS_FIELDCAT-REF_FIELDNAME = 'VBELN'.

LS_FIELDCAT-REF_TABNAME = 'LIKP'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'POSNR'.

LS_FIELDCAT-REF_FIELDNAME = 'POSNR'.

LS_FIELDCAT-REF_TABNAME = 'LIPS'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'MATNR'.

LS_FIELDCAT-REF_FIELDNAME = 'MATNR'.

LS_FIELDCAT-REF_TABNAME = 'MARA'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'MAKTX'.

LS_FIELDCAT-REF_FIELDNAME = 'MAKTX'.

LS_FIELDCAT-REF_TABNAME = 'MAKT'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'LFIMG'.

LS_FIELDCAT-REF_FIELDNAME = 'LFIMG'.

LS_FIELDCAT-REF_TABNAME = 'LIPS'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'MEINS'.

LS_FIELDCAT-REF_FIELDNAME = 'MEINS'.

LS_FIELDCAT-REF_TABNAME = 'LIPS'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'VOLUM'.

LS_FIELDCAT-REF_FIELDNAME = 'VOLUM'.

LS_FIELDCAT-REF_TABNAME = 'LIPS'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'VOLEH'.

LS_FIELDCAT-REF_FIELDNAME = 'VOLEH'.

LS_FIELDCAT-REF_TABNAME = 'LIPS'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'BRGEW'.

LS_FIELDCAT-REF_FIELDNAME = 'BRGEW'.

LS_FIELDCAT-REF_TABNAME = 'LIPS'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'GEWEI'.

LS_FIELDCAT-REF_FIELDNAME = 'GEWEI'.

LS_FIELDCAT-REF_TABNAME = 'LIPS'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'NETWR'.

LS_FIELDCAT-REF_FIELDNAME = 'NETWR'.

LS_FIELDCAT-REF_TABNAME = 'VBAP'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'WAERK'.

LS_FIELDCAT-REF_FIELDNAME = 'WAERK'.

LS_FIELDCAT-REF_TABNAME = 'VBAP'.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'AMOUNT_USD'.

LS_FIELDCAT-SELTEXT_L = TEXT-002.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

LS_FIELDCAT-COL_POS = POS.

LS_FIELDCAT-FIELDNAME = 'USD_CURRENCY'.

LS_FIELDCAT-SELTEXT_L = TEXT-003.

append LS_FIELDCAT to PT_FIELDCAT.

clear LS_FIELDCAT.

POS = POS + 1.

endform. " FIELD_FILL

&----


*& Form SET_LAYOUT

&----


  • text

----


  • -->P_IS_LAYOUT text

----


form SET_LAYOUT using LS_LAYOUT type SLIS_LAYOUT_ALV.

clear LS_LAYOUT.

LS_LAYOUT-ZEBRA = 'X'.

LS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

endform. " SET_LAYOUT

Regards

- Gopi

Message was edited by: Gopi Narendra

Read only

shishupalreddy
Active Contributor
0 Likes
467

hi ,

Build fieldcatalog with ROW_POS field of slis_t_fieldcat_alv .

In your case

ROW_POS = 1 here instead of 1 you are supposed to use

sy-curow for the first header

and row_pos = sy-curow + 1 FOR THE SECOND ROW..

HOPE it will help you .

REGARDS,

Read only

0 Likes
467

Hi,

Thanks you for your replies.

But can you please give me more details.

My Internal table has these values:

MATNR CHARG BUDAT ERFMG

1011779 5000854 26.10.2006 23.00

1011779 5000853 26.10.2006 12.00

1011779 5000852 26.10.2006 19.00

1011779 5000851 26.10.2006 2.00

1011778 5000830 26.10.2006 55.00

1011778 5000829 26.10.2006 21.00

1011778 5000828 26.10.2006 36.00

1011778 5000827 26.10.2006 48.00

I want to split it by MATNR in ALV display.

After calling REUSE_ALV_LIST_DISPLAY or REUSE_ALV_GRID_DISPLAY, the display should look like this:

-


Plant: A300

Material: 1011779 <---- This is the 1st header

-


MATNR CHARG BUDAT ERFMG

1011779 5000854 26.10.2006 23.00

1011779 5000853 26.10.2006 12.00

1011779 5000852 26.10.2006 19.00

1011779 5000851 26.10.2006 2.00

-


-


Plant: A300

Material: 1011778 <---- This is the 2nd header

-


MATNR CHARG BUDAT ERFMG

1011778 5000830 26.10.2006 55.00

1011778 5000829 26.10.2006 21.00

1011778 5000828 26.10.2006 36.00

1011778 5000827 26.10.2006 48.00

-


How do I write the headers and the line items separately? Do i need to split the internal tables into MATNRs? Thank you again.

Read only

Former Member
0 Likes
467

Hello,

Try using the function module 'REUSE_ALV_HIERSEQ_LIST_DISPLAY' rather than the conventional ALV list or grid. In this function module it should be possible to display in the form of hierachy i.e. HEADER and correspinding LINE ITEMS.

Regards,

Pavan