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: 

ALV block list

Former Member
0 Kudos
125

Guys,

i want to display the data in alv block list. please let me know the procedure.

regards,

vijay

4 REPLIES 4

Former Member
0 Kudos
56

Hi Vijay,

You can use the Function Modules:

REUSE_ALV_BLOCK_LIST_INIT, REUSE_ALV_BLOCK_LIST_APPEND, REUSE_ALV_BLOCK_HS_LIST_APPEND, REUSE_ALV_BLOCK_LIST_DISPLAY.

You will have to check the documentation for the function modules before using them.

Regards,

Kunal

Former Member
0 Kudos
56

Hai Please do the following code

&----


*& Report ZALV_PRAKASH *

*& *

&----


*& *

*& *

&----


REPORT ZALV_PRAKASH NO STANDARD PAGE HEADING

LINE-SIZE 150

LINE-COUNT 60(4)

MESSAGE-ID Z00.

*..Type Definitions for ALV Report

TYPE-POOLS SLIS.

*..Includes

*for ICONs

*INCLUDE <ICON>.

----


  • Table/Structure declarations. *

----


TABLES: MARA,

MARC,

T134.

----


  • Internal Tables declaration *

----


*..To store Basic Report fields

DATA:BEGIN OF IT_MARA OCCURS 0,

MATNR LIKE MARA-MATNR,

MTART LIKE MARA-MTART,

MATKL LIKE MARA-MATKL,

MEINS LIKE MARA-MEINS,

NTGEW LIKE MARA-NTGEW,

END OF IT_MARA.

*DATA:BEGIN OF IT_MATKL OCCURS 0,

  • MATKL LIKE T023-MATKL,

  • WGBEZ LIKE T023-WGBEZ,

  • END OF IT_MATKL.

DATA:BEGIN OF IT_MARC OCCURS 0,

WERKS LIKE MARC-WERKS,

LADGR LIKE MARC-LADGR,

MTVFP LIKE MARC-MTVFP,

DISPR LIKE MARC-DISPR,

DISMM LIKE MARC-DISMM,

DISPO LIKE MARC-DISPO,

END OF IT_MARC.

----


  • ALV Type declaration *

----


DATA:V_NO_DATA TYPE C.

----


  • ALV Type declaration *

----


DATA:V_REPID TYPE SYREPID.

DATA: IT_FIELDCATALOG_MARA TYPE SLIS_T_FIELDCAT_ALV,

WA_FIELDCATALOG_MARA TYPE SLIS_FIELDCAT_ALV,

IT_FIELDCATALOG_MARC TYPE SLIS_T_FIELDCAT_ALV,

WA_FIELDCATALOG_MARC TYPE SLIS_FIELDCAT_ALV,

IT_FIELDCATALOG_MATKL TYPE SLIS_T_FIELDCAT_ALV,

WA_FIELDCATALOG_MATKL TYPE SLIS_FIELDCAT_ALV,

WA_LAYOUT TYPE SLIS_LAYOUT_ALV,

IT_EVENTS TYPE SLIS_T_EVENT,

WA_EVENTS TYPE SLIS_ALV_EVENT,

WA_KEYINFO TYPE SLIS_KEYINFO_ALV.

----


  • Selection Screen. *

----


SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-H01.

SELECT-OPTIONS: S_MATNR FOR MARA-MATNR ,

S_MTART FOR MARA-MTART .

SELECTION-SCREEN END OF BLOCK B1.

----


  • Event:Initialization *

----


INITIALIZATION.

*Report Name

V_REPID = SY-REPID.

----


  • AT Selection Screen. *

----


AT SELECTION-SCREEN.

----


  • Event: Start-of-Selection *

----


START-OF-SELECTION.

PERFORM FETCH_DATA.

----


  • Event: End-of-Selection *

----


END-OF-SELECTION.

IF V_NO_DATA = ''.

MESSAGE I010 WITH 'NO DATA TO DISPLAY ! '.

EXIT.

ELSE.

PERFORM FILL_FIELDCAT_MARA.

  • PERFORM FILL_FIELDCAT_MAKT.

PERFORM FILL_FIELDCAT_MARC.

PERFORM FILL_LAYOUT.

PERFORM CALL_ALV_INIT.

PERFORM ADD_LISTS.

PERFORM DISPLAY_BLOCK_LIST.

ENDIF.

//////////////////////////////////////////////////////////////////////

*

  • FORM DEFINITIONS *

*

*//////////////////////////////////////////////////////////////////////

&----


*& Form FETCH_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FETCH_DATA.

SELECT MATNR

MTART

MATKL

MEINS

NTGEW

INTO CORRESPONDING FIELDS OF TABLE IT_MARA

FROM MARA

WHERE MATNR IN S_MATNR

AND MTART IN S_MTART.

IF SY-SUBRC <> 0.

V_NO_DATA = ''.

ELSE.

V_NO_DATA = 'X'.

SELECT WERKS

LADGR

MTVFP

DISPR

DISMM

DISPO

INTO CORRESPONDING FIELDS OF TABLE IT_MARC

FROM MARC

WHERE MATNR IN S_MATNR.

ENDIF.

ENDFORM. " FETCH_DATA

*

&----


*& Form FILL_FIELDCAT_MARA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FILL_FIELDCAT_MARA.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = V_REPID

  • I_INTERNAL_TABNAME =

I_STRUCTURE_NAME = 'IT_MARA'

  • I_CLIENT_NEVER_DISPLAY = 'X'

I_INCLNAME = V_REPID

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

CT_FIELDCAT = IT_FIELDCATALOG_MARA

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 2

OTHERS = 3

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

LOOP AT IT_FIELDCATALOG_MARA INTO WA_FIELDCATALOG_MARA.

CASE WA_FIELDCATALOG_MARA-FIELDNAME.

WHEN 'MATNR'.

WA_FIELDCATALOG_MARA-COL_POS = '1'.

WA_FIELDCATALOG_MARA-OUTPUTLEN = '15'.

WA_FIELDCATALOG_MARA-SELTEXT_L = 'Material NO'.

WHEN 'MTART'.

WA_FIELDCATALOG_MARA-COL_POS = '2'.

WA_FIELDCATALOG_MARA-OUTPUTLEN = '15'.

WA_FIELDCATALOG_MARA-SELTEXT_L = 'Mat Type'.

WHEN 'MATKL'.

WA_FIELDCATALOG_MARA-COL_POS = '3'.

WA_FIELDCATALOG_MARA-OUTPUTLEN = '15'.

WA_FIELDCATALOG_MARA-SELTEXT_L = 'Mat Group'.

WHEN 'MEINS'.

WA_FIELDCATALOG_MARA-COL_POS = '4'.

WA_FIELDCATALOG_MARA-OUTPUTLEN = '15'.

WA_FIELDCATALOG_MARA-SELTEXT_L = 'Measure Unit'.

WHEN 'NTGEW'.

WA_FIELDCATALOG_MARA-COL_POS = '5'.

WA_FIELDCATALOG_MARA-OUTPUTLEN = '15'.

WA_FIELDCATALOG_MARA-SELTEXT_L = 'Net Wt'.

WA_FIELDCATALOG_MARA-DO_SUM = 'X'.

ENDCASE.

MODIFY IT_FIELDCATALOG_MARA FROM WA_FIELDCATALOG_MARA INDEX SY-TABIX.

ENDLOOP.

ENDFORM. " FILL_FIELDCAT_MARA

&----


*& Form FILL_FIELDCAT_MARC

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FILL_FIELDCAT_MARC.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = V_REPID

I_INTERNAL_TABNAME = 'IT_MARC'

  • I_STRUCTURE_NAME =

  • I_CLIENT_NEVER_DISPLAY = 'X'

I_INCLNAME = V_REPID

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

CT_FIELDCAT = IT_FIELDCATALOG_MARC

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 2

OTHERS = 3

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

LOOP AT IT_FIELDCATALOG_MARC INTO WA_FIELDCATALOG_MARC.

CASE WA_FIELDCATALOG_MARC-FIELDNAME.

WHEN 'WERKS'.

WA_FIELDCATALOG_MARC-COL_POS = '1'.

WA_FIELDCATALOG_MARC-OUTPUTLEN = '15'.

WA_FIELDCATALOG_MARC-SELTEXT_L = 'PLANT NAME'.

WHEN 'LADGR'.

WA_FIELDCATALOG_MARC-COL_POS = '2'.

WA_FIELDCATALOG_MARC-OUTPUTLEN = '15'.

WA_FIELDCATALOG_MARC-SELTEXT_L = 'Loading Group'.

WHEN 'MTVFP'.

WA_FIELDCATALOG_MARC-COL_POS = '3'.

WA_FIELDCATALOG_MARC-OUTPUTLEN = '20'.

WA_FIELDCATALOG_MARC-SELTEXT_L = 'Checking group'.

WHEN 'DISPR'.

WA_FIELDCATALOG_MARC-COL_POS = '4'.

WA_FIELDCATALOG_MARC-OUTPUTLEN = '15'.

WA_FIELDCATALOG_MARC-SELTEXT_L = 'MRP PROFILE'.

WHEN 'DISMM'.

WA_FIELDCATALOG_MARC-COL_POS = '5'.

WA_FIELDCATALOG_MARC-OUTPUTLEN = '15'.

WA_FIELDCATALOG_MARC-SELTEXT_L = 'MRP TYPE'.

WHEN 'DISPO'.

WA_FIELDCATALOG_MARC-COL_POS = '6'.

WA_FIELDCATALOG_MARC-OUTPUTLEN = '15'.

WA_FIELDCATALOG_MARC-SELTEXT_L = 'MRP CONTROLLER'.

ENDCASE.

MODIFY IT_FIELDCATALOG_MARC FROM WA_FIELDCATALOG_MARC INDEX SY-TABIX.

ENDLOOP.

ENDFORM. " FILL_FIELDCAT_MARC

&----


*& Form FILL_FIELDCAT_MAKT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FILL_FIELDCAT_MAKT.

ENDFORM. " FILL_FIELDCAT_MAKT

&----


*& Form CALL_ALV_INIT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CALL_ALV_INIT.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'

EXPORTING

I_CALLBACK_PROGRAM = V_REPID

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • IT_EXCLUDING =

.

ENDFORM. " CALL_ALV_INIT

&----


*& Form ADD_LISTS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM ADD_LISTS.

*ADD IT_MARA TABLE TO THE OUTPUT

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

IS_LAYOUT = WA_LAYOUT

IT_FIELDCAT = IT_FIELDCATALOG_MARA

I_TABNAME = 'IT_MARA'

IT_EVENTS = IT_EVENTS

  • IT_SORT =

  • I_TEXT = ' '

TABLES

T_OUTTAB = IT_MARA

EXCEPTIONS

PROGRAM_ERROR = 1

MAXIMUM_OF_APPENDS_REACHED = 2

OTHERS = 3

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

**ADD IT_MARC TABLE TO THE OUTPUT

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

IS_LAYOUT = WA_LAYOUT

IT_FIELDCAT = IT_FIELDCATALOG_MARC

I_TABNAME = 'IT_MARC'

IT_EVENTS = IT_EVENTS

  • IT_SORT =

  • I_TEXT = ' '

TABLES

T_OUTTAB = IT_MARC

  • EXCEPTIONS

  • PROGRAM_ERROR = 1

  • MAXIMUM_OF_APPENDS_REACHED = 2

  • OTHERS = 3

.

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. " ADD_LISTS

&----


*& Form FILL_LAYOUT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FILL_LAYOUT.

WA_LAYOUT-ZEBRA = 'X'.

WA_LAYOUT-TOTALS_TEXT = 'TOTAL'.

ENDFORM. " FILL_LAYOUT

&----


*& Form DISPLAY_BLOCK_LIST

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM DISPLAY_BLOCK_LIST.

  • WA_KEYINFO-HEADER01 = 'MATNR'.

  • WA_KEYINFO-ITEM01 = 'MATNR'.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'

  • EXPORTING

  • I_INTERFACE_CHECK = ' '

  • IS_PRINT =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

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. " DISPLAY_BLOCK_LIST .

Thanks & regards

Sreenivasulu P

Former Member
0 Kudos
56

Hi Vijay,

you may also have a look at demo reports BALVBT01 and BALVBT02.

I hope it helps. BR,

Alvaro

former_member188685
Active Contributor
0 Kudos
56

Hi,

Check this sample Program <b>BALVBT01</b>.

and you need 3 FM's.

1.REUSE_ALV_BLOCK_LIST_INIT

2 .REUSE_ALV_BLOCK_LIST_APPEND "for normal

REUSE_ALV_BLOCK_LIST_HS_APPEND "heirarchial block

3. REUSE_ALV_BLOCK_LIST_DISPLAY

Regards

vijay