You are on page 1of 5

ALV in a Pop up window and ALV in a dialog box

By Swarna S, Tata Consultancy Services
*AS : User selects infotypes from a pop up alv .The details of
*infotypes selected are displayed in a ALV dialog box.
*author : Swarna.S.
*Published at SAPTechnical.COM
REPORT ZALV_POPDIALOG.
*Type pools for ALV declarations
TYPE-POOLS : slis.
*Internal table and wa declarations for T582A.
DATA : it_t582a TYPE STANDARD TABLE OF t582a INITIAL SIZE 0,
wa_t582a TYPE t582a.
*Internal table and wa declarations for T582S.
DATA : it_text TYPE STANDARD TABLE OF t582s,
wa_text TYPE t582s.
*Structure declaration for output
TYPES : BEGIN OF ty_output,
infty TYPE infty,
zeitb TYPE dzeitb,
itext TYPE intxt,
pnnnn TYPE pnnnn_d,
dname TYPE dianm,
namst TYPE namst,
edynr TYPE edynp,
ldynr TYPE ldynp,
stypt TYPE stypt,
sytxt TYPE sytxt,
zbtab TYPE dzbtab,
checkbox(1),
END OF ty_output.
*Internal table and work area declaration for output in pop up
DATA : it_output TYPE STANDARD TABLE OF ty_output INITIAL SIZE 0,
wa_output TYPE ty_output.
*Internal table and workarea declaration for alv dialog display
DATA : it_display TYPE STANDARD TABLE OF ty_output INITIAL SIZE 0,
wa_display TYPE ty_output.
*data declarations for ALV
DATA:ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv,
ls_fieldcatlog TYPE slis_fieldcat_alv,
lt_fieldcatlog TYPE slis_t_fieldcat_alv,
lt_layout TYPE slis_layout_alv.
*Initialization event
INITIALIZATION.
*Start of selection event
START-OF-SELECTION.
*Select to fetch all the infotypes and details in sap system
SELECT *
FROM t582a
INTO CORRESPONDING FIELDS OF TABLE it_t582a.
*Select to fetch the infotypes text
IF it_t582a[] IS NOT INITIAL.
SELECT * FROM t582s INTO CORRESPONDING FIELDS OF TABLE it_text
FOR ALL ENTRIES IN it_t582a WHERE infty = it_t582a-infty
AND sprsl = 'E'.
ENDIF.
*Appending the selected values to the output table
LOOP AT it_t582a INTO wa_t582a.
wa_output-infty = wa_t582a-infty.
wa_output-zeitb = wa_t582a-zeitb.
wa_output-pnnnn = wa_t582a-pnnnn.
wa_output-dname = wa_t582a-dname.
wa_output-namst = wa_t582a-namst.
wa_output-edynr = wa_t582a-edynr.

APPEND wa_output TO it_output. ENDLOOP. wa_display-pnnnn = wa_output-pnnnn. wa_display-sytxt = wa_output-sytxt. . ls_fieldcat-col_pos = '1'. *Subroutine to display the ALV dialog display PERFORM alv_output. ls_fieldcat-col_pos = '2'. *Subroutine to display the pop up values. wa_output-itext = wa_text-itext. APPEND ls_fieldcat TO lt_fieldcat. wa_display-dname = wa_output-dname. *fieldcatalogue for ALV dialog PERFORM build_fieldcat. *----------------------------------------------------------------* * Form popup_display *------------------------------------------------------------* FORM popup_display. READ TABLE it_text INTO wa_text WITH KEY infty = wa_t582a-infty. ls_fieldcat-tabname = 'IT_OUTPUT'. wa_output-sytxt = wa_t582a-sytxt. APPEND wa_display TO it_display. wa_display-ldynr = wa_output-ldynr. wa_display-zbtab = wa_output-zbtab. wa_display-edynr = wa_output-edynr. wa_output-zbtab = wa_t582a-zbtab. ENDLOOP. ls_fieldcat-seltext_m = 'DESCRIPTION'. ls_fieldcat-row_pos = '1'. wa_display-namst = wa_output-namst. *field catalogue for pop up CLEAR ls_fieldcat. ls_fieldcat-outputlen = 50.wa_output-ldynr = wa_t582a-ldynr. wa_display-itext = wa_output-itext. * Display data in a POPUP CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT' EXPORTING i_zebra = 'X' it_fieldcat = lt_fieldcat i_tabname = 'IT_OUTPUT' i_checkbox_fieldname = 'CHECKBOX' TABLES t_outtab = it_output. *Appending the selected infotypes only to internal table LOOP AT it_output INTO wa_output WHERE checkbox = 'X'. CLEAR ls_fieldcat. ls_fieldcat-seltext_m = 'SELECT'. wa_display-infty = wa_output-infty. APPEND ls_fieldcat TO lt_fieldcat. PERFORM popup_display. wa_display-stypt = wa_output-stypt. " popup_display *&-------------------------------------------------------------* *& Form alv_output *&-------------------------------------------------------------* FORM alv_output . ls_fieldcat-tabname = 'IT_OUTPUT'. wa_display-zeitb = wa_output-zeitb. ENDFORM. wa_output-stypt = wa_t582a-stypt. CLEAR wa_display. CLEAR wa_output. ls_fieldcat-row_pos = '1'. ls_fieldcat-fieldname = 'ITEXT'. ls_fieldcat-fieldname = 'CHECKBOX'. *Layout for ALV dialog PERFORM build_layout.

" alv_output *&------------------------------------------------------------* *& Form build_fieldcat *&------------------------------------------------------------* FORM build_fieldcat . ls_fieldcatlog-row_pos = '1'. ls_fieldcatlog-fieldname = 'EDYNR'. ls_fieldcatlog-col_pos = '8'. ls_fieldcatlog-row_pos = '1'. ls_fieldcatlog-tabname = 'IT_DISPLAY'. CLEAR ls_fieldcatlog. APPEND ls_fieldcatlog TO lt_fieldcatlog. . ls_fieldcatlog-fieldname = 'ITEXT'. APPEND ls_fieldcatlog TO lt_fieldcatlog. ls_fieldcatlog-tabname = 'IT_DISPLAY'. APPEND ls_fieldcatlog TO lt_fieldcatlog. ls_fieldcatlog-row_pos = '1'. ls_fieldcatlog-tabname = 'IT_DISPLAY'. ls_fieldcatlog-col_pos = '2'. ls_fieldcatlog-col_pos = '1'. ls_fieldcatlog-row_pos = '1'. ls_fieldcatlog-row_pos = '1'. CLEAR ls_fieldcatlog. ENDFORM. APPEND ls_fieldcatlog TO lt_fieldcatlog. ls_fieldcatlog-col_pos = '9'. ls_fieldcatlog-tabname = 'IT_DISPLAY'. ls_fieldcatlog-row_pos = '1'. ls_fieldcatlog-seltext_m = 'Infotype'. ls_fieldcatlog-tabname = 'IT_DISPLAY'. APPEND ls_fieldcatlog TO lt_fieldcatlog. ls_fieldcatlog-tabname = 'IT_DISPLAY'. ls_fieldcatlog-fieldname = 'NAMST'. APPEND ls_fieldcatlog TO lt_fieldcatlog. APPEND ls_fieldcatlog TO lt_fieldcatlog. ls_fieldcatlog-col_pos = '6'. ls_fieldcatlog-fieldname = 'ZEITB'. ls_fieldcatlog-seltext_m = 'Description'. ls_fieldcatlog-col_pos = '4'. CLEAR ls_fieldcatlog. ls_fieldcatlog-seltext_m = 'DialogModule'. ls_fieldcatlog-tabname = 'IT_DISPLAY'. ls_fieldcatlog-col_pos = '5'. CLEAR ls_fieldcatlog. ls_fieldcatlog-seltext_m = 'Structure'. CLEAR ls_fieldcatlog. ls_fieldcatlog-seltext_m = 'Singlescreenno'. CLEAR ls_fieldcatlog. ls_fieldcatlog-seltext_m = 'Listscreenno'. ls_fieldcatlog-col_pos = '3'. ls_fieldcatlog-row_pos = '1'. *fieldcatalogue for alv dialog CLEAR ls_fieldcatlog. ls_fieldcatlog-row_pos = '1'. CLEAR ls_fieldcatlog. ls_fieldcatlog-tabname = 'IT_DISPLAY'. APPEND ls_fieldcatlog TO lt_fieldcatlog. ls_fieldcatlog-col_pos = '7'.**ALV dialog output PERFORM alv. ls_fieldcatlog-row_pos = '1'. ls_fieldcatlog-seltext_m = 'Subtypefield'. ls_fieldcatlog-seltext_m = 'TimeConstraint'. ls_fieldcatlog-fieldname = 'PNNNN'. ls_fieldcatlog-fieldname = 'LDYNR'. ls_fieldcatlog-fieldname = 'DNAME'. ls_fieldcatlog-fieldname = 'INFTY'. CLEAR ls_fieldcatlog.

ls_fieldcatlog-tabname = 'IT_DISPLAY'. APPEND ls_fieldcatlog TO lt_fieldcatlog. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = sy-repid i_grid_title = 'INFOTYPE DETAILS' is_layout = lt_layout it_fieldcat = lt_fieldcatlog i_screen_start_column = 10 i_screen_start_line = 20 i_screen_end_column = 100 i_screen_end_line = 40 TABLES t_outtab = it_display EXCEPTIONS program_error = 1 OTHERS = 2. ls_fieldcatlog-tabname = 'IT_DISPLAY'. " build_layout *&---------------------------------------------------------------* *& Form alv *&---------------------------------------------------------------* *Alv dialog output. " alv Pop up ALV to select infotype . ENDIF. ls_fieldcatlog-seltext_m = 'Subtyptexttable'. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDFORM. ls_fieldcatlog-seltext_m = 'SubtypeTCTable'.ls_fieldcatlog-fieldname = 'STYPT'. ls_fieldcatlog-row_pos = '1'. ls_fieldcatlog-col_pos = '10'. IF sy-subrc <> 0. ls_fieldcatlog-row_pos = '1'. lt_layout-colwidth_optimize = 'X'. ls_fieldcatlog-seltext_m = 'SubtypTable'. lt_layout-zebra = 'X'. ls_fieldcatlog-col_pos = '11'. CLEAR ls_fieldcatlog. APPEND ls_fieldcatlog TO lt_fieldcatlog. ls_fieldcatlog-fieldname = 'SYTXT'. " build_fieldcat *&----------------------------------------------------------* *& Form build_layout *&----------------------------------------------------------* *Layout for ALV dialog FORM build_layout . FORM alv . ENDFORM. ENDFORM. APPEND ls_fieldcatlog TO lt_fieldcatlog. ls_fieldcatlog-tabname = 'IT_DISPLAY'. CLEAR ls_fieldcatlog. ls_fieldcatlog-fieldname = 'ZBTAB'.

ALV as dialog box to display the infotype details .