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: 

Example for ALV interactive report

Former Member
0 Kudos
1,351

Do you have any example of interactive ALV report?

My requirement is:

First I have to display all sales orders on a ALV output. Then if the user clicks on a particular sales order among these, it will go to another ALV output containing the details related to this sales order.

Please provide me a sample code if you can.

I appreciate.

Thanks,

Krishen

1 ACCEPTED SOLUTION

Former Member
0 Kudos
250

Hi,

Check this code..To display the orders and if you click on the hotspot of the sales order it will display the line items..

TYPE-POOLS: slis.

DATA: BEGIN OF itab1 OCCURS 0,

vbeln TYPE vbeln,

bstnk TYPE vbak-bstnk,

erdat TYPE vbak-erdat,

kunnr TYPE vbak-kunnr,

END OF itab1.

DATA: BEGIN OF itab2 OCCURS 0,

vbeln TYPE vbeln,

matnr TYPE vbap-matnr,

netpr TYPE vbap-netpr,

kwmeng TYPE vbap-kwmeng,

END OF itab2.

DATA: t_fieldcatalog1 TYPE slis_t_fieldcat_alv.

DATA: t_fieldcatalog2 TYPE slis_t_fieldcat_alv.

DATA: v_repid TYPE syrepid.

v_repid = sy-repid.

  • Get the fieldcatalog1

PERFORM get_fieldcat1.

  • Get the fieldcatalog2

PERFORM get_fieldcat2.

SELECT vbeln bstnk erdat kunnr UP TO 10 ROWS

INTO TABLE itab1

FROM vbak.

IF NOT itab1[] IS INITIAL.

SELECT vbeln matnr netpr kwmeng UP TO 10 ROWS

INTO TABLE itab2

FROM vbap

FOR ALL ENTRIES IN itab1

WHERE vbeln = itab1-vbeln.

ENDIF.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = v_repid

i_callback_user_command = 'DISPLAY_DETAIL'

it_fieldcat = t_fieldcatalog1

TABLES

t_outtab = itab1.

----


  • FORM display_detail *

----


  • ........ *

----


  • --> UCOMM *

  • --> SELFIELD *

----


FORM display_detail USING ucomm LIKE sy-ucomm

selfield TYPE slis_selfield.

DATA: itab2_temp LIKE itab2 OCCURS 0 WITH HEADER LINE.

IF ucomm = '&IC1'.

READ TABLE itab1 INDEX selfield-tabindex.

IF sy-subrc = 0.

LOOP AT itab2 WHERE vbeln = itab1-vbeln.

MOVE itab2 TO itab2_temp.

APPEND itab2_temp.

ENDLOOP.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = v_repid

it_fieldcat = t_fieldcatalog2

TABLES

t_outtab = itab2_temp.

ENDIF.

ENDIF.

ENDFORM.

----


  • FORM GET_FIELDCAT1 *

----


  • ........ *

----


FORM get_fieldcat1.

DATA: s_fieldcatalog TYPE slis_fieldcat_alv.

s_fieldcatalog-col_pos = '1'.

s_fieldcatalog-fieldname = 'VBELN'.

s_fieldcatalog-tabname = 'ITAB1'.

s_fieldcatalog-rollname = 'VBELN'.

s_fieldcatalog-hotspot = 'X'.

APPEND s_fieldcatalog TO t_fieldcatalog1.

CLEAR s_fieldcatalog.

s_fieldcatalog-col_pos = '2'.

s_fieldcatalog-fieldname = 'BSTNK'.

s_fieldcatalog-tabname = 'ITAB1'.

s_fieldcatalog-rollname = 'BSTNK'.

APPEND s_fieldcatalog TO t_fieldcatalog1.

CLEAR s_fieldcatalog.

s_fieldcatalog-col_pos = '3'.

s_fieldcatalog-fieldname = 'ERDAT'.

s_fieldcatalog-tabname = 'ITAB1'.

s_fieldcatalog-rollname = 'ERDAT'.

APPEND s_fieldcatalog TO t_fieldcatalog1.

CLEAR s_fieldcatalog.

s_fieldcatalog-col_pos = '4'.

s_fieldcatalog-fieldname = 'KUNNR'.

s_fieldcatalog-tabname = 'ITAB1'.

s_fieldcatalog-rollname = 'KUNNR'.

APPEND s_fieldcatalog TO t_fieldcatalog1.

CLEAR s_fieldcatalog.

ENDFORM.

*

----


  • FORM GET_FIELDCAT2 *

----


  • ........ *

----


FORM get_fieldcat2.

DATA: s_fieldcatalog TYPE slis_fieldcat_alv.

s_fieldcatalog-col_pos = '1'.

s_fieldcatalog-fieldname = 'VBELN'.

s_fieldcatalog-tabname = 'ITAB2'.

s_fieldcatalog-rollname = 'VBELN'.

APPEND s_fieldcatalog TO t_fieldcatalog2.

CLEAR s_fieldcatalog.

s_fieldcatalog-col_pos = '2'.

s_fieldcatalog-fieldname = 'MATNR'.

s_fieldcatalog-tabname = 'ITAB2'.

s_fieldcatalog-rollname = 'MATNR'.

APPEND s_fieldcatalog TO t_fieldcatalog2.

CLEAR s_fieldcatalog.

s_fieldcatalog-col_pos = '3'.

s_fieldcatalog-fieldname = 'NETPR'.

s_fieldcatalog-tabname = 'ITAB2'.

s_fieldcatalog-rollname = 'NETPR'.

APPEND s_fieldcatalog TO t_fieldcatalog2.

CLEAR s_fieldcatalog.

s_fieldcatalog-col_pos = '4'.

s_fieldcatalog-fieldname = 'KWMENG'.

s_fieldcatalog-tabname = 'ITAB2'.

s_fieldcatalog-rollname = 'KWMENG'.

APPEND s_fieldcatalog TO t_fieldcatalog2.

CLEAR s_fieldcatalog.

ENDFORM.

Thanks,

Naren

3 REPLIES 3

ferry_lianto
Active Contributor
0 Kudos
250

Hi,

Please check this links for sample codes.

http://www.sap-img.com/abap/an-interactive-alv-report.htm

Hope this will help.

Regards,

Ferry Lianto

LucianoBentiveg
Active Contributor
0 Kudos
250

In this <a href="http://sapabap.iespana.es/sapabap/sap/reports/alv_jerarquico.htm">link</a> there is a similar example.

Regards.

Former Member
0 Kudos
251

Hi,

Check this code..To display the orders and if you click on the hotspot of the sales order it will display the line items..

TYPE-POOLS: slis.

DATA: BEGIN OF itab1 OCCURS 0,

vbeln TYPE vbeln,

bstnk TYPE vbak-bstnk,

erdat TYPE vbak-erdat,

kunnr TYPE vbak-kunnr,

END OF itab1.

DATA: BEGIN OF itab2 OCCURS 0,

vbeln TYPE vbeln,

matnr TYPE vbap-matnr,

netpr TYPE vbap-netpr,

kwmeng TYPE vbap-kwmeng,

END OF itab2.

DATA: t_fieldcatalog1 TYPE slis_t_fieldcat_alv.

DATA: t_fieldcatalog2 TYPE slis_t_fieldcat_alv.

DATA: v_repid TYPE syrepid.

v_repid = sy-repid.

  • Get the fieldcatalog1

PERFORM get_fieldcat1.

  • Get the fieldcatalog2

PERFORM get_fieldcat2.

SELECT vbeln bstnk erdat kunnr UP TO 10 ROWS

INTO TABLE itab1

FROM vbak.

IF NOT itab1[] IS INITIAL.

SELECT vbeln matnr netpr kwmeng UP TO 10 ROWS

INTO TABLE itab2

FROM vbap

FOR ALL ENTRIES IN itab1

WHERE vbeln = itab1-vbeln.

ENDIF.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = v_repid

i_callback_user_command = 'DISPLAY_DETAIL'

it_fieldcat = t_fieldcatalog1

TABLES

t_outtab = itab1.

----


  • FORM display_detail *

----


  • ........ *

----


  • --> UCOMM *

  • --> SELFIELD *

----


FORM display_detail USING ucomm LIKE sy-ucomm

selfield TYPE slis_selfield.

DATA: itab2_temp LIKE itab2 OCCURS 0 WITH HEADER LINE.

IF ucomm = '&IC1'.

READ TABLE itab1 INDEX selfield-tabindex.

IF sy-subrc = 0.

LOOP AT itab2 WHERE vbeln = itab1-vbeln.

MOVE itab2 TO itab2_temp.

APPEND itab2_temp.

ENDLOOP.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = v_repid

it_fieldcat = t_fieldcatalog2

TABLES

t_outtab = itab2_temp.

ENDIF.

ENDIF.

ENDFORM.

----


  • FORM GET_FIELDCAT1 *

----


  • ........ *

----


FORM get_fieldcat1.

DATA: s_fieldcatalog TYPE slis_fieldcat_alv.

s_fieldcatalog-col_pos = '1'.

s_fieldcatalog-fieldname = 'VBELN'.

s_fieldcatalog-tabname = 'ITAB1'.

s_fieldcatalog-rollname = 'VBELN'.

s_fieldcatalog-hotspot = 'X'.

APPEND s_fieldcatalog TO t_fieldcatalog1.

CLEAR s_fieldcatalog.

s_fieldcatalog-col_pos = '2'.

s_fieldcatalog-fieldname = 'BSTNK'.

s_fieldcatalog-tabname = 'ITAB1'.

s_fieldcatalog-rollname = 'BSTNK'.

APPEND s_fieldcatalog TO t_fieldcatalog1.

CLEAR s_fieldcatalog.

s_fieldcatalog-col_pos = '3'.

s_fieldcatalog-fieldname = 'ERDAT'.

s_fieldcatalog-tabname = 'ITAB1'.

s_fieldcatalog-rollname = 'ERDAT'.

APPEND s_fieldcatalog TO t_fieldcatalog1.

CLEAR s_fieldcatalog.

s_fieldcatalog-col_pos = '4'.

s_fieldcatalog-fieldname = 'KUNNR'.

s_fieldcatalog-tabname = 'ITAB1'.

s_fieldcatalog-rollname = 'KUNNR'.

APPEND s_fieldcatalog TO t_fieldcatalog1.

CLEAR s_fieldcatalog.

ENDFORM.

*

----


  • FORM GET_FIELDCAT2 *

----


  • ........ *

----


FORM get_fieldcat2.

DATA: s_fieldcatalog TYPE slis_fieldcat_alv.

s_fieldcatalog-col_pos = '1'.

s_fieldcatalog-fieldname = 'VBELN'.

s_fieldcatalog-tabname = 'ITAB2'.

s_fieldcatalog-rollname = 'VBELN'.

APPEND s_fieldcatalog TO t_fieldcatalog2.

CLEAR s_fieldcatalog.

s_fieldcatalog-col_pos = '2'.

s_fieldcatalog-fieldname = 'MATNR'.

s_fieldcatalog-tabname = 'ITAB2'.

s_fieldcatalog-rollname = 'MATNR'.

APPEND s_fieldcatalog TO t_fieldcatalog2.

CLEAR s_fieldcatalog.

s_fieldcatalog-col_pos = '3'.

s_fieldcatalog-fieldname = 'NETPR'.

s_fieldcatalog-tabname = 'ITAB2'.

s_fieldcatalog-rollname = 'NETPR'.

APPEND s_fieldcatalog TO t_fieldcatalog2.

CLEAR s_fieldcatalog.

s_fieldcatalog-col_pos = '4'.

s_fieldcatalog-fieldname = 'KWMENG'.

s_fieldcatalog-tabname = 'ITAB2'.

s_fieldcatalog-rollname = 'KWMENG'.

APPEND s_fieldcatalog TO t_fieldcatalog2.

CLEAR s_fieldcatalog.

ENDFORM.

Thanks,

Naren