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

alv interactive

Former Member
0 Likes
795

can someone give me a code for alv interactive when i click on a field in basic i shud get next list.

if i click other fields it shud not give the list unless i code it.

6 REPLIES 6
Read only

Former Member
0 Likes
757

Hi,

Check the following link:

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

Regrds,

Bhaskar

Read only

Former Member
0 Likes
757

Hi,

check this code,it may be helpful.

TYPE-POOLS: SLIS.

&----


*& TYPES DECLARATION *

&----


*--- To hold the Customer details

TYPES: BEGIN OF TY_KNA1,

KUNNR TYPE KUNNR, "Customer No

NAME1 TYPE NAME1, "Name of the customer

END OF TY_KNA1,

*--- Sales document no's

BEGIN OF TY_VBAK,

VBELN TYPE VBELN_VA, "Sales Document no

ERDAT TYPE ERDAT, "Doc Creation date

AUDAT TYPE AUDAT, "Document date

VKORG TYPE VKORG, "Sales organization

END OF TY_VBAK,

*--- Sales document item details

BEGIN OF TY_VBAP,

VBELN TYPE VBELN_VA, "Sales document no

POSNR TYPE POSNR_VA, "Sales document Item

MATNR TYPE MATNR, "material No

KWMENG TYPE KWMENG, "Order qty

END OF TY_VBAP,

*--- Delivery document no

BEGIN OF TY_LIPS,

VBELN TYPE VBELN_VL, "Delivery document no

END OF TY_LIPS.

&----


*& Internal tables DECLARATION *

&----


DATA: IT_KNA1 TYPE STANDARD TABLE OF TY_KNA1,

IT_VBAK TYPE STANDARD TABLE OF TY_VBAK,

IT_VBAP TYPE STANDARD TABLE OF TY_VBAP,

IT_LIPS TYPE STANDARD TABLE OF TY_LIPS,

IT_FCAT1 TYPE SLIS_T_FIELDCAT_ALV,

IT_FCAT2 TYPE SLIS_T_FIELDCAT_ALV,

IT_FCAT3 TYPE SLIS_T_FIELDCAT_ALV,

IT_FCAT4 TYPE SLIS_T_FIELDCAT_ALV,

IT_EVENT TYPE SLIS_T_EVENT,

&----


*& Data DECLARATION *

&----


V_REPID TYPE SY-REPID,

V_KUNNR TYPE KNA1-KUNNR,

X_FCAT TYPE SLIS_FIELDCAT_ALV,

V_IND TYPE I,

V_STATUS TYPE SLIS_FORMNAME,

V_USER TYPE SLIS_FORMNAME.

&----


*& *

&----


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

SELECT-OPTIONS: S_KUNNR FOR V_KUNNR.

PARAMETERS: P_HITS TYPE CHAR5.

SELECTION-SCREEN END OF BLOCK B1.

&----


*& Intialization *

&----


INITIALIZATION.

CLEAR: IT_KNA1,

IT_VBAK,

IT_VBAP,

IT_LIPS,

X_FCAT.

REFRESH: IT_KNA1,

IT_VBAK,

IT_VBAP,

IT_LIPS,

IT_FCAT1,

IT_FCAT2,

IT_FCAT3.

V_REPID = SY-REPID.

&----


*& start-of-selection *

&----


START-OF-SELECTION.

*--- Fetch the Customer details from KNA1

PERFORM F_GET_KNA1.

&----


*& end-of-selection *

&----


END-OF-SELECTION.

V_IND = 1.

PERFORM F_FILL_FIELDCATALOG USING IT_FCAT1

V_IND.

PERFORM F_FILL_ALVLAYOUT.

V_STATUS = 'F_SET_PFSTATUS'.

V_USER = 'F_USER_COMMAND'.

PERFORM F_ALV_DISPLAY USING IT_FCAT1

IT_KNA1

V_STATUS

V_USER.

&----


*& Form f_get_kna1

&----


*Fetch the customers no

----


FORM F_GET_KNA1 .

*--- Get the customer information

SELECT KUNNR

NAME1

FROM KNA1

UP TO P_HITS ROWS

INTO TABLE IT_KNA1

WHERE KUNNR IN S_KUNNR.

IF SY-SUBRC = 0.

SORT IT_KNA1 BY KUNNR.

ENDIF.

ENDFORM. " f_get_kna1

&----


*& Form f_fill_fieldcatalog

&----


  • text

----


FORM F_FILL_FIELDCATALOG USING P_FCAT TYPE SLIS_T_FIELDCAT_ALV

P_IND TYPE I.

IF P_IND = 1.

*--- Change reference field name and refrence table

CLEAR X_FCAT.

X_FCAT-TABNAME = 'IT_KNA1'.

X_FCAT-FIELDNAME = 'KUNNR'.

X_FCAT-DDICTXT = 'L'.

X_FCAT-SELTEXT_L = 'Customer'.

X_FCAT-SELTEXT_M = 'Customer'.

X_FCAT-SELTEXT_S = 'Customer'.

APPEND X_FCAT TO IT_FCAT1.

*--- Change reference field name and refrence table

CLEAR X_FCAT.

X_FCAT-TABNAME = 'IT_KNA1'.

X_FCAT-FIELDNAME = 'NAME1'.

X_FCAT-DDICTXT = 'L'.

X_FCAT-SELTEXT_L = 'Customer Name'.

X_FCAT-SELTEXT_M = 'Customer Name'.

X_FCAT-SELTEXT_S = 'Customer Name'.

APPEND X_FCAT TO IT_FCAT1.

ELSEIF P_IND = 2.

*--- Change reference field name and refrence table

CLEAR X_FCAT.

X_FCAT-TABNAME = 'IT_VBAK'.

X_FCAT-FIELDNAME = 'VBELN'.

X_FCAT-DDICTXT = 'L'.

X_FCAT-SELTEXT_L = 'Sales doc'.

X_FCAT-SELTEXT_M = 'Sales doc'.

X_FCAT-SELTEXT_S = 'Sales doc'.

APPEND X_FCAT TO IT_FCAT2.

*--- Change reference field name and refrence table

CLEAR X_FCAT.

X_FCAT-TABNAME = 'IT_VBAK'.

X_FCAT-FIELDNAME = 'ERDAT'.

X_FCAT-DDICTXT = 'L'.

X_FCAT-SELTEXT_L = 'Creation Dt'.

X_FCAT-SELTEXT_M = 'Creation Dt'.

X_FCAT-SELTEXT_S = 'Creation Dt'.

APPEND X_FCAT TO IT_FCAT2.

*--- Change reference field name and refrence table

CLEAR X_FCAT.

X_FCAT-TABNAME = 'IT_VBAK'.

X_FCAT-FIELDNAME = 'AUDAT'.

X_FCAT-DDICTXT = 'L'.

X_FCAT-SELTEXT_L = 'Doc Dt'.

X_FCAT-SELTEXT_M = 'Doc Dt'.

X_FCAT-SELTEXT_S = 'Doc Dt'.

APPEND X_FCAT TO IT_FCAT2.

*--- Change reference field name and refrence table

CLEAR X_FCAT.

X_FCAT-TABNAME = 'IT_VBAK'.

X_FCAT-FIELDNAME = 'VKORG'.

X_FCAT-DDICTXT = 'L'.

X_FCAT-SELTEXT_L = 'Sales Org'.

X_FCAT-SELTEXT_M = 'Sales Org'.

X_FCAT-SELTEXT_S = 'Sales Org'.

APPEND X_FCAT TO IT_FCAT2.

ELSEIF P_IND = 3.

*--- Change reference field name and refrence table

CLEAR X_FCAT.

X_FCAT-TABNAME = 'IT_VBAP'.

X_FCAT-FIELDNAME = 'VBELN'.

X_FCAT-DDICTXT = 'L'.

X_FCAT-SELTEXT_L = 'Sales doc'.

X_FCAT-SELTEXT_M = 'Sales doc'.

X_FCAT-SELTEXT_S = 'Sales doc'.

APPEND X_FCAT TO IT_FCAT3.

*--- Change reference field name and refrence table

CLEAR X_FCAT.

X_FCAT-TABNAME = 'IT_VBAP'.

X_FCAT-FIELDNAME = 'POSNR'.

X_FCAT-DDICTXT = 'L'.

X_FCAT-SELTEXT_L = 'Sales doc itm'.

X_FCAT-SELTEXT_M = 'Sales doc itm'.

X_FCAT-SELTEXT_S = 'Sales doc itm'.

APPEND X_FCAT TO IT_FCAT3.

*--- Change reference field name and refrence table

CLEAR X_FCAT.

X_FCAT-TABNAME = 'IT_VBAP'.

X_FCAT-FIELDNAME = 'MATNR'.

X_FCAT-DDICTXT = 'L'.

X_FCAT-SELTEXT_L = 'Material'.

X_FCAT-SELTEXT_M = 'Material'.

X_FCAT-SELTEXT_S = 'Material'.

APPEND X_FCAT TO IT_FCAT3.

*--- Change reference field name and refrence table

CLEAR X_FCAT.

X_FCAT-TABNAME = 'IT_VBAP'.

X_FCAT-FIELDNAME = 'KWMENG'.

X_FCAT-DDICTXT = 'L'.

X_FCAT-SELTEXT_L = 'QTY'.

X_FCAT-SELTEXT_M = 'QTY'.

X_FCAT-SELTEXT_S = 'QTY'.

APPEND X_FCAT TO IT_FCAT3.

ELSEIF P_IND = 4.

*--- Change reference field name and refrence table

CLEAR X_FCAT.

X_FCAT-TABNAME = 'IT_LIPS'.

X_FCAT-FIELDNAME = 'VBELN'.

X_FCAT-DDICTXT = 'L'.

X_FCAT-SELTEXT_L = 'Sales doc'.

X_FCAT-SELTEXT_M = 'Sales doc'.

X_FCAT-SELTEXT_S = 'Sales doc'.

APPEND X_FCAT TO IT_FCAT4.

ENDIF.

ENDFORM. " f_fill_fieldcatalog

&----


*& Form f_fill_alvlayout

&----


  • text

----


FORM F_FILL_ALVLAYOUT .

ENDFORM. " f_fill_alvlayout

&----


*& Form f_alv_display

&----


  • text

----


FORM F_ALV_DISPLAY USING P_FCAT TYPE SLIS_T_FIELDCAT_ALV

P_TAB TYPE STANDARD TABLE

P_STATUS TYPE SLIS_FORMNAME

P_USER TYPE SLIS_FORMNAME.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = I_BYPASSING_BUFFER

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = V_REPID

I_CALLBACK_PF_STATUS_SET = P_STATUS

I_CALLBACK_USER_COMMAND = P_USER

  • I_STRUCTURE_NAME = I_STRUCTURE_NAME

  • IS_LAYOUT = IS_LAYOUT

IT_FIELDCAT = P_FCAT

  • IT_EXCLUDING = IT_EXCLUDING

  • IT_SPECIAL_GROUPS = IT_SPECIAL_GROUPS

  • IT_SORT = IT_SORT

  • IT_FILTER = IT_FILTER

  • IS_SEL_HIDE = IS_SEL_HIDE

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT = IS_VARIANT

  • IT_EVENTS = IT_EVENTS

  • IT_EVENT_EXIT = IT_EVENT_EXIT

  • IS_PRINT = IS_PRINT

  • IS_REPREP_ID = IS_REPREP_ID

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IR_SALV_LIST_ADAPTER = IR_SALV_LIST_ADAPTER

  • IT_EXCEPT_QINFO = IT_EXCEPT_QINFO

  • I_SUPPRESS_EMPTY_DATA = ABAP_FALSE

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER = E_EXIT_CAUSED_BY_CALLER

  • ES_EXIT_CAUSED_BY_USER = ES_EXIT_CAUSED_BY_USER

TABLES

T_OUTTAB = P_TAB

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

&----


*& Form f_set_pfstatus

&----


  • text

----


  • -->RT_EXTAB TYPE SLIS_T_EXTAB

----


FORM F_SET_PFSTATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.

SET PF-STATUS 'ALV_STATUS'.

ENDFORM. "f_set_pfstatus

&----


*& Form f_user_command

&----


  • text

----


FORM F_USER_COMMAND USING

UCMD LIKE SY-UCOMM " SY-UCOMM value

FIELDINFO TYPE SLIS_SELFIELD. " Current ALV Cell & ALV Info

  • ALV_FCAT_DTEL TYPE TYP_T_FCAT_DTEL. " Table utilized by std ucmd

DATA LV_KUNNR TYPE KUNNR.

IF UCMD = '&IC1'.

LV_KUNNR = FIELDINFO-VALUE.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = LV_KUNNR

IMPORTING

OUTPUT = LV_KUNNR.

SELECT VBELN

ERDAT

AUDAT

VKORG

FROM VBAK

INTO TABLE IT_VBAK

WHERE KUNNR = LV_KUNNR.

IF SY-SUBRC = 0.

SORT IT_VBAK BY VBELN.

REFRESH IT_FCAT2.

V_IND = 2.

PERFORM F_FILL_FIELDCATALOG USING IT_FCAT2

V_IND.

PERFORM F_FILL_ALVLAYOUT.

V_STATUS = 'F_SET_PFSTATUS1'.

V_USER = 'F_USER_COMMAND1'.

PERFORM F_ALV_DISPLAY USING IT_FCAT2

IT_VBAK

V_STATUS

V_USER.

ENDIF.

ENDIF.

ENDFORM. "f_user_command

&----


*& Form f_set_pfstatus1

&----


  • text

----


  • -->RT_EXTAB TYPE SLIS_T_EXTAB

----


FORM F_SET_PFSTATUS1 USING RT_EXTAB TYPE SLIS_T_EXTAB.

SET PF-STATUS 'ALV_STATUS1'.

ENDFORM. "f_set_pfstatus

&----


*& Form f_user_command1

&----


  • text

----


FORM F_USER_COMMAND1 USING

UCMD LIKE SY-UCOMM " SY-UCOMM value

FIELDINFO TYPE SLIS_SELFIELD. " Current ALV Cell & ALV Info

  • ALV_FCAT_DTEL TYPE TYP_T_FCAT_DTEL. " Table utilized by std ucmd

DATA: LV_VBELN TYPE VBELN_VA.

IF UCMD = 'SALES'.

LV_VBELN = FIELDINFO-VALUE.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = LV_VBELN

IMPORTING

OUTPUT = LV_VBELN.

SELECT VBELN

POSNR

MATNR

KWMENG

FROM VBAP

INTO TABLE IT_VBAP

WHERE VBELN = LV_VBELN.

IF SY-SUBRC = 0.

SORT IT_VBAP BY VBELN.

REFRESH IT_FCAT3.

V_IND = 3.

PERFORM F_FILL_FIELDCATALOG USING IT_FCAT3

V_IND.

PERFORM F_FILL_ALVLAYOUT.

V_STATUS = 'F_SET_PFSTATUS2'.

V_USER = 'F_USER_COMMAND2'.

PERFORM F_ALV_DISPLAY USING IT_FCAT3

IT_VBAP

V_STATUS

V_USER.

ENDIF.

ELSEIF UCMD = 'DELVR'.

LV_VBELN = FIELDINFO-VALUE.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = LV_VBELN

IMPORTING

OUTPUT = LV_VBELN.

SELECT VBELN

FROM LIPS

INTO TABLE IT_LIPS

WHERE VBELN = LV_VBELN.

IF SY-SUBRC = 0.

SORT IT_LIPS BY VBELN.

V_IND = 4.

REFRESH IT_FCAT4.

PERFORM F_FILL_FIELDCATALOG USING IT_FCAT4

V_IND.

PERFORM F_FILL_ALVLAYOUT.

V_STATUS = 'F_SET_PFSTATUS3'.

PERFORM F_ALV_DISPLAY USING IT_FCAT4

IT_LIPS

V_STATUS

SPACE.

ENDIF.

ENDIF.

ENDFORM. "f_user_command

&----


*& Form f_set_pfstatus2

&----


  • text

----


  • -->RT_EXTAB TYPE SLIS_T_EXTAB

----


FORM F_SET_PFSTATUS2 USING RT_EXTAB TYPE SLIS_T_EXTAB.

SET PF-STATUS 'ALV_STATUS'.

ENDFORM. "f_set_pfstatus

&----


*& Form f_set_pfstatus3

&----


  • text

----


  • -->RT_EXTAB TYPE SLIS_T_EXTAB

----


FORM F_SET_PFSTATUS3 USING RT_EXTAB TYPE SLIS_T_EXTAB.

SET PF-STATUS 'ALV_STATUS'.

ENDFORM. "f_set_pfstatus

regards,

vineela

Read only

Former Member
0 Likes
757

hi,

just check this code

tables : ekko,

ekpo.

select-options: s_ebeln for ekko-ebeln.

type-pools: slis.

data: begin of headertab occurs 0,

ebeln like ekko-ebeln,

bstyp like ekko-bstyp,

bsart like ekko-bsart,

statu like ekko-statu,

end of headertab.

data: begin of itemtab occurs 0,

ebeln like ekpo-ebeln,

ebelp like ekpo-ebelp,

matnr like ekpo-matnr,

werks like ekpo-werks,

menge like ekpo-menge,

netpr like ekpo-netpr,

peinh like ekpo-peinh,

netwr like ekpo-netwr,

end of itemtab.

data: begin of level2 occurs 0,

ebeln like ekpo-ebeln,

ebelp like ekpo-ebelp,

matnr like ekpo-matnr,

werks like ekpo-werks,

menge like ekpo-menge,

netpr like ekpo-netpr,

peinh like ekpo-peinh,

netwr like ekpo-netwr,

end of level2.

data: i_fieldcat type slis_t_fieldcat_alv,

i_fieldcat1 type slis_t_fieldcat_alv.

data: v_repid like sy-repid,

v_layout type slis_layout_alv,

v_events type slis_t_event,

v_print type slis_print_alv,

l_fieldcat type slis_fieldcat_alv.

start-of-selection.

v_repid = sy-repid.

select ebeln

bstyp

bsart

statu

into table headertab

from ekko

where ebeln in s_ebeln.

if not headertab[] is initial.

select ebeln

ebelp

matnr

werks

menge

netpr

peinh

netwr

into table itemtab

from ekpo

for all entries in headertab

where ebeln = headertab-ebeln.

endif.

call function 'REUSE_ALV_FIELDCATALOG_MERGE'

exporting

i_program_name = v_repid

i_internal_tabname = 'HEADERTAB'

  • I_STRUCTURE_NAME =

  • I_CLIENT_NEVER_DISPLAY = 'X'

i_inclname = v_repid

i_bypassing_buffer = 'X'

i_buffer_active = ' '

changing

ct_fieldcat = i_fieldcat

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 i_fieldcat into l_fieldcat.

case l_fieldcat-fieldname.

when 'EBELN'.

l_fieldcat-hotspot = 'X'.

modify i_fieldcat from l_fieldcat.

endcase.

endloop.

call function 'REUSE_ALV_LIST_DISPLAY'

exporting

  • I_INTERFACE_CHECK = ' '

i_bypassing_buffer = 'X'

i_buffer_active = ' '

i_callback_program = v_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

i_callback_user_command = 'USER_COMMAND'

  • I_STRUCTURE_NAME =

  • IS_LAYOUT =

it_fieldcat = i_fieldcat

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

i_save = 'A'

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • 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 =

tables

t_outtab = headertab

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.

&----


*& Form USER_COMMAND

&----


  • text

----


  • -->R_UCOMM text

  • -->RS_SELFIELDtext

----


form user_command using r_ucomm like sy-ucomm

rs_selfield type slis_selfield.

if rs_selfield-fieldname eq 'EBELN'.

case r_ucomm.

when '&IC1'.

read table headertab index rs_selfield-tabindex.

refresh level2.

clear level2.

loop at itemtab where ebeln = headertab-ebeln.

append itemtab to level2.

endloop.

call function 'REUSE_ALV_FIELDCATALOG_MERGE'

exporting

i_program_name = v_repid

i_internal_tabname = 'LEVEL2'

  • I_STRUCTURE_NAME =

  • I_CLIENT_NEVER_DISPLAY = 'X'

i_inclname = v_repid

i_bypassing_buffer = 'X'

i_buffer_active = ' '

changing

ct_fieldcat = i_fieldcat1

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.

call function 'REUSE_ALV_LIST_DISPLAY'

exporting

  • I_INTERFACE_CHECK = ' '

i_bypassing_buffer = 'X'

i_buffer_active = ' '

i_callback_program = v_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND =

  • I_STRUCTURE_NAME =

  • IS_LAYOUT =

it_fieldcat = i_fieldcat1

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

i_save = 'A'

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT

  • IS_REPREP_ID =

  • 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 =

tables

t_outtab = level2

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.

endcase.

endif.

endform. "USER_COMMAND

Read only

Former Member
0 Likes
757

here is the sample code .

AT LINE-SELECTION .

FORM USER_COMM USING P_COMM LIKE SY-UCOMM P_FIELD TYPE SLIS_SELFIELD .

IF P_COMM = '&IC1' .

SELECT OBJECT

OBJ_NAME FROM E071

INTO TABLE IT_TMP1

WHERE TRKORR = P_FIELD-VALUE

AND ( OBJECT EQ 'PROG' OR OBJECT EQ 'TRAN' OR OBJECT EQ 'TABL'

OR OBJECT EQ 'FUGR' OR OBJECT EQ 'REPS' OR OBJECT EQ 'DYNP' ).

i hope it will help u .

regards ,

srinivas

Read only

Former Member
0 Likes
757

hi,

try like this


*&---------------------------------------------------------------------*
*& Report  ZINT_ALV
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zint_alv.

TYPE-POOLS:slis.

TABLES:mara,
       makt,
       mseg.

DATA:BEGIN OF itab OCCURS 0,
      matnr LIKE mara-matnr,
      maktx LIKE makt-maktx,
      cellcolors TYPE lvc_t_scol,
     END OF itab.

DATA:BEGIN OF itab1 OCCURS 0,
      mblnr LIKE mseg-mblnr,
      menge LIKE mseg-menge,
      meins LIKE mseg-meins,
      werks LIKE mseg-werks,
     END OF itab1.

DATA:BEGIN OF itab2 OCCURS 0,
      mblnr LIKE mseg-mblnr,
      budat LIKE mkpf-budat,
     END OF itab2.

DATA:fcat TYPE slis_t_fieldcat_alv,
     fcat1 TYPE slis_t_fieldcat_alv,
     fcat2 TYPE slis_t_fieldcat_alv,
     eve TYPE slis_t_event,
     eve1 TYPE slis_t_event.

DATA:t_mat LIKE mara-matnr,
     t_doc LIKE mseg-mblnr,
     s_mat LIKE mara-matnr,
     g_repid LIKE sy-repid,
     subtot TYPE slis_t_sortinfo_alv,
     g_subtot LIKE LINE OF subtot.

SELECTION-SCREEN:BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:mat FOR mara-matnr OBLIGATORY.
SELECTION-SCREEN:END OF BLOCK blk1.



INITIALIZATION.
  PERFORM build_fcat USING fcat.
  PERFORM build_eve.

START-OF-SELECTION.

  PERFORM get_data.
  PERFORM dis_data.


*&---------------------------------------------------------------------*
*&      Form  build_fcat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->T_FCAT     text
*----------------------------------------------------------------------*
FORM build_fcat USING t_fcat TYPE slis_t_fieldcat_alv.

  DATA:wa_fcat TYPE slis_fieldcat_alv.

  wa_fcat-tabname = 'ITAB'.
  wa_fcat-fieldname = 'MATNR'.
  wa_fcat-ref_fieldname = 'MATNR'.
  wa_fcat-ref_tabname = 'MARA'.
  wa_fcat-seltext_m = 'Material'.
*  wa_fcat-input = ' '.
*  wa_fcat-edit = 'X'.
  wa_fcat-input = 'X'.
*  wa_fcat-key = 'X'.

  APPEND wa_fcat TO t_fcat.
  CLEAR wa_fcat.

  wa_fcat-tabname = 'ITAB'.
  wa_fcat-fieldname = 'MAKTX'.
  wa_fcat-seltext_m = 'Description'.
  APPEND wa_fcat TO t_fcat.
  CLEAR wa_fcat.

ENDFORM.                    "build_fcat

*&---------------------------------------------------------------------*
*&      Form  build_eve
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM build_eve.

  DATA:t_eve TYPE slis_alv_event.

  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
   EXPORTING
     i_list_type           = 0
   IMPORTING
     et_events             = eve
* EXCEPTIONS
*   LIST_TYPE_WRONG       = 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.                    "build_eve

*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_data.

  SELECT mara~matnr makt~maktx INTO CORRESPONDING FIELDS OF TABLE itab
  FROM mara INNER JOIN makt
  ON mara~matnr = makt~matnr
  WHERE mara~matnr IN mat.
ENDFORM.                    "get_data

*&---------------------------------------------------------------------*
*&      Form  dis_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM dis_data.

  g_repid = sy-repid.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     i_callback_program                = g_repid         
     i_callback_user_command           = 'USER_COMMAND'
     i_grid_title                      = 'Interactive ALV'
     it_fieldcat                       = fcat
     it_events                         = eve
    TABLES
      t_outtab                          = itab
* 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.                    "dis_data

*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->U_COM      text
*----------------------------------------------------------------------*
FORM user_command USING u_com LIKE sy-ucomm sel_field TYPE slis_selfield.

  CLEAR fcat1.

  CASE u_com.
    WHEN '&IC1'.
      READ TABLE itab INDEX sel_field-tabindex.
      IF sel_field-fieldname = 'MATNR'.
        IF sy-subrc = 0.
          t_mat = itab-matnr.
          PERFORM build_cat1 USING fcat1.
          PERFORM build_eve1.
          PERFORM get_data1.
          PERFORM dis_data1.

        ENDIF.
      ELSE.
        MESSAGE 'No data' TYPE 'I'.
      ENDIF.
*      SET PARAMETER ID 'MAT' FIELD t_mat.
*      CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
  ENDCASE.

ENDFORM.                    "user_command

*&---------------------------------------------------------------------*
*&      Form  build_fcat1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->T_FCAT1    text
*----------------------------------------------------------------------*
FORM build_cat1 USING t_fcat1 TYPE slis_t_fieldcat_alv.

  DATA:wa_fcat1 TYPE slis_fieldcat_alv.

  wa_fcat1-tabname = 'ITAB1'.
  wa_fcat1-fieldname = 'MBLNR'.
  wa_fcat1-seltext_m = 'Material Doc.'.
  APPEND wa_fcat1 TO t_fcat1.
  CLEAR wa_fcat1.

  wa_fcat1-tabname = 'ITAB1'.
  wa_fcat1-fieldname = 'MENGE'.
  wa_fcat1-seltext_m = 'Quantity'.
  wa_fcat1-do_sum    = 'X'.
  APPEND wa_fcat1 TO t_fcat1.
  CLEAR wa_fcat1.

  wa_fcat1-tabname = 'ITAB1'.
  wa_fcat1-fieldname = 'MEINS'.
  wa_fcat1-seltext_m = 'UOM'.
  APPEND wa_fcat1 TO t_fcat1.
  CLEAR wa_fcat1.

  wa_fcat1-tabname = 'ITAB1'.
  wa_fcat1-fieldname = 'WERKS'.
  wa_fcat1-seltext_m = 'Plant'.
  APPEND wa_fcat1 TO t_fcat1.
  CLEAR wa_fcat1.


ENDFORM.                    "build_fcat1

*&---------------------------------------------------------------------*
*&      Form  build_eve1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM build_eve1.

  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type     = 0
    IMPORTING
      et_events       = eve1
    EXCEPTIONS
      list_type_wrong = 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.                                                    "build_eve1

*&---------------------------------------------------------------------*
*&      Form  get_data1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_data1.

  SELECT mblnr menge meins werks FROM mseg
  INTO CORRESPONDING FIELDS OF TABLE itab1
  WHERE matnr = t_mat.

ENDFORM.                                                    "get_data1

*&---------------------------------------------------------------------*
*&      Form  dis_data1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM dis_data1.

  g_repid = sy-repid.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     i_callback_program                = g_repid                   it_fieldcat                       = fcat1
     it_events                         = eve1
     i_save                            = 'A'
     it_sort                            = subtot
    TABLES
      t_outtab                          = itab1
* 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.                                                    "dis_data1

reward if usefull.....

Read only

Former Member
0 Likes
757

Hi,

Please refer the code below:



*&---------------------------------------------------------------------*
*& Report  ZDEMO_ALVGRID                                               *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*& Example of a simple ALV Grid Report                                 *
*& ...................................                                 *
*&                                                                     *
*& The basic requirement for this demo is to display a number of       *
*& fields from the EKKO table.                                         *
*&---------------------------------------------------------------------*
REPORT  zdemo_alvgrid                 .

TABLES:     ekko.

type-pools: slis.                                 "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_ekko,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  statu TYPE ekpo-statu,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
  menge TYPE ekpo-menge,
  meins TYPE ekpo-meins,
  netpr TYPE ekpo-netpr,
  peinh TYPE ekpo-peinh,
 END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
      wa_ekko TYPE t_ekko.

*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
      gd_tab_group type slis_t_sp_group_alv,
      gd_layout    type slis_layout_alv,
      gd_repid     like sy-repid,
      gt_events     type slis_t_event,
      gd_prntparams type slis_print_alv.


************************************************************************
*Start-of-selection.
START-OF-SELECTION.

perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform build_events.
perform build_print_params.
perform display_alv_report.


*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form build_fieldcatalog.

* There are a number of ways to create a fieldcat.
* For the purpose of this example i will build the fieldcatalog manualy
* by populating the internal table fields individually and then
* appending the rows. This method can be the most time consuming but can
* also allow you  more control of the final product.

* Beware though, you need to ensure that all fields required are
* populated. When using some of functionality available via ALV, such as
* total. You may need to provide more information than if you were
* simply displaying the result
*               I.e. Field type may be required in-order for
*                    the 'TOTAL' function to work.

  fieldcatalog-fieldname   = 'EBELN'.
  fieldcatalog-seltext_m   = 'Purchase Order'.
  fieldcatalog-col_pos     = 0.
  fieldcatalog-outputlen   = 10.
  fieldcatalog-emphasize   = 'X'.
  fieldcatalog-key         = 'X'.
*  fieldcatalog-do_sum      = 'X'.
*  fieldcatalog-no_zero     = 'X'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'EBELP'.
  fieldcatalog-seltext_m   = 'PO Item'.
  fieldcatalog-col_pos     = 1.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'STATU'.
  fieldcatalog-seltext_m   = 'Status'.
  fieldcatalog-col_pos     = 2.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'AEDAT'.
  fieldcatalog-seltext_m   = 'Item change date'.
  fieldcatalog-col_pos     = 3.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MATNR'.
  fieldcatalog-seltext_m   = 'Material Number'.
  fieldcatalog-col_pos     = 4.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MENGE'.
  fieldcatalog-seltext_m   = 'PO quantity'.
  fieldcatalog-col_pos     = 5.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MEINS'.
  fieldcatalog-seltext_m   = 'Order Unit'.
  fieldcatalog-col_pos     = 6.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'NETPR'.
  fieldcatalog-seltext_m   = 'Net Price'.
  fieldcatalog-col_pos     = 7.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-do_sum      = 'X'.
  fieldcatalog-datatype     = 'CURR'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'PEINH'.
  fieldcatalog-seltext_m   = 'Price Unit'.
  fieldcatalog-col_pos     = 8.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.
endform.                    " BUILD_FIELDCATALOG


*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
  gd_layout-no_input          = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-totals_text       = 'Totals'(201).
*  gd_layout-totals_only        = 'X'.
*  gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
*                                         "click(press f2)
*  gd_layout-zebra             = 'X'.
*  gd_layout-group_change_edit = 'X'.
*  gd_layout-header_text       = 'helllllo'.
endform.                    " BUILD_LAYOUT


*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*       Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
  gd_repid = sy-repid.
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            i_callback_program      = gd_repid
            i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
            i_callback_user_command = 'USER_COMMAND'
*            i_grid_title           = outtext
            is_layout               = gd_layout
            it_fieldcat             = fieldcatalog[]
*            it_special_groups       = gd_tabgroup
            it_events               = gt_events
            is_print                = gd_prntparams
            i_save                  = 'X'
*            is_variant              = z_template
       tables
            t_outtab                = it_ekko
       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_ALV_REPORT


*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.

select ebeln ebelp statu aedat matnr menge meins netpr peinh
 up to 10 rows
  from ekpo
  into table it_ekko.
endform.                    " DATA_RETRIEVAL


*-------------------------------------------------------------------*
* Form  TOP-OF-PAGE                                                 *
*-------------------------------------------------------------------*
* ALV Report Header                                                 *
*-------------------------------------------------------------------*
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
      wa_header type slis_listheader,
      t_line like wa_header-info,
      ld_lines type i,
      ld_linesc(10) type c.

* Title
  wa_header-typ  = 'H'.
  wa_header-info = 'EKKO Table Report'.
  append wa_header to t_header.
  clear wa_header.

* Date
  wa_header-typ  = 'S'.
  wa_header-key = 'Date: '.
  CONCATENATE  sy-datum+6(2) '.'
               sy-datum+4(2) '.'
               sy-datum(4) INTO wa_header-info.   "todays date
  append wa_header to t_header.
  clear: wa_header.

* Total No. of Records Selected
  describe table it_ekko lines ld_lines.
  ld_linesc = ld_lines.
  concatenate 'Total No. of Records Selected: ' ld_linesc
                    into t_line separated by space.
  wa_header-typ  = 'A'.
  wa_header-info = t_line.
  append wa_header to t_header.
  clear: wa_header, t_line.

  call function 'REUSE_ALV_COMMENTARY_WRITE'
       exporting
            it_list_commentary = t_header.
*            i_logo             = 'Z_LOGO'.
endform.


*------------------------------------------------------------------*
*       FORM USER_COMMAND                                          *
*------------------------------------------------------------------*
*       --> R_UCOMM                                                *
*       --> RS_SELFIELD                                            *
*------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
                  rs_selfield TYPE slis_selfield.

* Check function code
  CASE r_ucomm.
    WHEN '&IC1'.
*   Check field clicked on within ALVgrid report
    IF rs_selfield-fieldname = 'EBELN'.
*     Read data table, using index of row user clicked on
      READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
*     Set parameter ID for transaction screen field
      SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
*     Sxecute transaction ME23N, and skip initial data entry screen
      CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
    ENDIF.
  ENDCASE.
ENDFORM.


*&---------------------------------------------------------------------*
*&      Form  BUILD_EVENTS
*&---------------------------------------------------------------------*
*       Build events table
*----------------------------------------------------------------------*
form build_events.
  data: ls_event type slis_alv_event.

  call function 'REUSE_ALV_EVENTS_GET'
       exporting
            i_list_type = 0
       importing
            et_events   = gt_events[].
  read table gt_events with key name =  slis_ev_end_of_page
                           into ls_event.
  if sy-subrc = 0.
    move 'END_OF_PAGE' to ls_event-form.
    append ls_event to gt_events.
  endif.

    read table gt_events with key name =  slis_ev_end_of_list
                           into ls_event.
  if sy-subrc = 0.
    move 'END_OF_LIST' to ls_event-form.
    append ls_event to gt_events.
  endif.
endform.                    " BUILD_EVENTS


*&---------------------------------------------------------------------*
*&      Form  BUILD_PRINT_PARAMS
*&---------------------------------------------------------------------*
*       Setup print parameters
*----------------------------------------------------------------------*
form build_print_params.
  gd_prntparams-reserve_lines = '3'.   "Lines reserved for footer
  gd_prntparams-no_coverpage = 'X'.
endform.                    " BUILD_PRINT_PARAMS


*&---------------------------------------------------------------------*
*&      Form  END_OF_PAGE
*&---------------------------------------------------------------------*
form END_OF_PAGE.
  data: listwidth type i,
        ld_pagepos(10) type c,
        ld_page(10)    type c.

  write: sy-uline(50).
  skip.
  write:/40 'Page:', sy-pagno .
endform.


*&---------------------------------------------------------------------*
*&      Form  END_OF_LIST
*&---------------------------------------------------------------------*
form END_OF_LIST.
  data: listwidth type i,
        ld_pagepos(10) type c,
        ld_page(10)    type c.

  skip.
  write:/40 'Page:', sy-pagno .
endform.


Thanks,

Sriram Ponna.