0% found this document useful (0 votes)
127 views7 pages

Alv Sample

The document defines a program that collects master material data from tables, processes it, and displays it in an ALV grid. It declares global variables and tables, defines selection screens for material group and number filters, collects the material data and descriptions on start of selection, processes the data by adding descriptions and unit of measurements, and displays it using ALV functions with events for navigation and printing. Subroutines are used for the different processing steps and ALV configuration.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views7 pages

Alv Sample

The document defines a program that collects master material data from tables, processes it, and displays it in an ALV grid. It declares global variables and tables, defines selection screens for material group and number filters, collects the material data and descriptions on start of selection, processes the data by adding descriptions and unit of measurements, and displays it using ALV functions with events for navigation and printing. Subroutines are used for the different processing steps and ALV configuration.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

REPORT ypractice_502 .

*----------------------------------------------------------------------*
* Tables
*----------------------------------------------------------------------*
TABLES : mara, makt, t006a.
INCLUDE ypractice_502_alv.
*INCLUDE ypractice_501_alv.
*----------------------------------------------------------------------*
*GLOBAL VARIABLE DECRALATION
*----------------------------------------------------------------------*
TYPES: BEGIN OF ty_header,
matkl LIKE mara-matkl, " Material Group
matnr LIKE mara-matnr, " Material Number
maktx LIKE makt-maktx, " Material Description
bismt LIKE mara-bismt, " Old material number
meins LIKE mara-meins, " Base Unit of Measure
mseht LIKE t006a-mseht, " Unit of Measurement Text
END OF ty_header.
DATA: gi_header TYPE STANDARD TABLE OF ty_header WITH HEADER LINE,
gi_makt LIKE STANDARD TABLE OF makt WITH HEADER LINE,
gi_t006a LIKE STANDARD TABLE OF t006a WITH HEADER LINE.
DATA: gv_width TYPE i. " Width of list
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*Input Screen/Selection
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK groupbox1 WITH FRAME TITLE text_101. "Declare Group
Box 1
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(18) text_102 FOR FIELD so_matkl.
SELECT-OPTIONS so_matkl FOR mara-matkl.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(18) text_103 FOR FIELD so_matnr.
SELECT-OPTIONS so_matnr FOR mara-matnr.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK groupbox1. "End Group Box 1
*----------------------------------------------------------------------*
*EVENT
*----------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
text_101 = 'Selection Parameter'.
text_102 = 'Material Group'.
text_103 = 'Material Number'.
*----------------------------------------------------------------------*
*INITIALIZATION
*----------------------------------------------------------------------*
INITIALIZATION.
*========================================================
==============*
*MAIN PROGRAM
*Execute after Input Screen
*========================================================
==============*
START-OF-SELECTION.
gv_width = 113.
PERFORM fm_collect_data.
PERFORM fm_process_data.
PERFORM fm_display_data.
END-OF-SELECTION.
*========================================================
==============*
*SUB PROGRAM / SUB ROUTINE
*========================================================
==============*
*&--------------------------------------------------------------------*

*& Form fm_collect_data


*&--------------------------------------------------------------------*
text
*---------------------------------------------------------------------*
FORM fm_collect_data.
* Collect Master Material
SELECT matnr matkl bismt meins
INTO CORRESPONDING FIELDS OF TABLE gi_header
FROM mara
WHERE
matkl IN so_matkl AND
matnr IN so_matnr.
* "For SAP 4.6C
* DATA : lv_total_data type i.
* DESCRIBE TABLE gi_header LINES lv_total_data.
* IF lv_total_data > 0.
IF LINES( gi_header ) > 0." For SAP 4.7 above
* Collect Material Decription
SELECT matnr maktx
INTO CORRESPONDING FIELDS OF TABLE gi_makt
FROM makt
FOR ALL ENTRIES IN gi_header
WHERE
matnr = gi_header-matnr AND
spras = sy-langu.
* Collect Measurement Text
SELECT msehi mseht
INTO CORRESPONDING FIELDS OF TABLE gi_t006a
FROM t006a
FOR ALL ENTRIES IN gi_header
WHERE
msehi = gi_header-meins AND
spras = sy-langu.
ENDIF.
* Notes :
* Avoid using inner join
ENDFORM. "FM_COLLECT_DATA
*&--------------------------------------------------------------------*
*& Form FM_PROCESS_DATA
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM fm_process_data.
*Get other requirement information
LOOP AT gi_header.
* Get Material Description
READ TABLE gi_makt WITH KEY matnr = gi_header-matnr.
IF sy-subrc = 0.
gi_header-maktx = gi_makt-maktx.
ENDIF.
* Get Measurement Text
READ TABLE gi_t006a WITH KEY msehi = gi_header-meins.
IF sy-subrc = 0.
gi_header-mseht = gi_t006a-mseht.
ENDIF.
MODIFY gi_header.
ENDLOOP.
ENDFORM. "FM_PROCESS_DATA
*&--------------------------------------------------------------------*
*& Form fm_display_data
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM fm_display_data.
PERFORM fm_alv_reset_data.
* Set ALV Parameters and Data

PERFORM fm_alv_set_layout USING 'Display List of Master Material'.


PERFORM fm_alv_set_print.
PERFORM fm_alv_set_column.
gv_i_default = 'X'.
gv_i_save = 'A'.
PERFORM fm_alv_show TABLES gi_header.
ENDFORM. "fm_display_data
*========================================================
==============
*Set ALV
*========================================================
==============
*&--------------------------------------------------------------------*
*& Form fm_alv_set_column
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM fm_alv_set_column.
* matkl LIKE mara-matkl, " Material Group
* matnr LIKE mara-matnr, " Material Number
* maktx LIKE makt-maktx, " Material Description
* bismt LIKE mara-bismt, " Old material number
* meins LIKE mara-meins, " Base Unit of Measure
* mseht LIKE t006a-mseht, " Unit of Measurement Text
* Displaying Column by Fieldname
PERFORM fm_alv_add_fieldcat USING :
'MATKL' 'MARA' 'MATKL' '' '' 'Mat. Group' '' '' '' '' '' '' '' '' '' '' '' '' '' 'X' 'X',
'MATNR' 'MARA' 'MATNR' '' '' 'Mat. Number' '' '' '' '' '' '' '' '' '' '' '' '' '' 'X' 'X',
'MAKTX' 'MAKT' 'MAKTX' '' '' 'Decription' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',
'BISMT' 'MARA' 'BISMT' '' '' 'Old Mat. No' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',
'MEINS' 'MARA' 'MEINS' '' '' 'Base Unit' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',
'MSEHT' 'T006A' 'MSEHT' '' '' 'Measure' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''.
* Sort and Group by Field
* CLEAR gi_it_sort.
* gi_it_sort-fieldname = 'WERKS'. ">> Filled by Fieldname
* gi_it_sort-up = 'X'. ">> 'X' = Ascending ; ' ' = Descending
* gi_it_sort-subtot = 'X'.
* gi_it_sort-group = '*'. ">> '*' = Grouped by field ; ' ' = Not grouped by this field
* APPEND gi_it_sort.
ENDFORM. "fm_alv_set_column

*&---------------------------------------------------------------------*
*& Include YPRACTICE_502_ALV *
*&---------------------------------------------------------------------*
TYPE-POOLS : slis.
DATA : gw_is_layout TYPE slis_layout_alv,
gi_it_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gi_it_excluding TYPE slis_t_extab WITH HEADER LINE,
gi_it_special_groups TYPE slis_t_sp_group_alv WITH HEADER LINE,
gi_it_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE,
gi_it_filter TYPE slis_t_filter_alv WITH HEADER LINE,
gw_is_sel_hide TYPE slis_sel_hide_alv,
gv_i_default,
gv_i_save,
gw_is_variant LIKE disvariant,
gi_it_events TYPE slis_t_event WITH HEADER LINE,
gi_it_event_exit TYPE slis_t_event_exit WITH HEADER LINE,
gw_is_print TYPE slis_print_alv,
gw_is_reprep_id TYPE slis_reprep_id.
*&--------------------------------------------------------------------*
*& Form fm_alv_show
*&--------------------------------------------------------------------*

* text
*---------------------------------------------------------------------*
* -->FT_ITAB text
*---------------------------------------------------------------------*
FORM fm_alv_show TABLES ft_itab.
CLEAR gi_it_event_exit.
gi_it_event_exit-ucomm = '&OUP'.
gi_it_event_exit-after = 'X'.
APPEND gi_it_event_exit.
CLEAR gi_it_event_exit.
gi_it_event_exit-ucomm = '&ODN'.
gi_it_event_exit-after = 'X'.
APPEND gi_it_event_exit.
CLEAR gi_it_event_exit.
gi_it_event_exit-ucomm = '&ETA'.
gi_it_event_exit-after = 'X'.
APPEND gi_it_event_exit.
CLEAR gi_it_event_exit.
gi_it_event_exit-ucomm = '&IC1'.
gi_it_event_exit-after = 'X'.
APPEND gi_it_event_exit.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
i_callback_pf_status_set = 'FM_ALV_SET_PF_STATUS'
i_callback_user_command = 'FM_ALV_USER_COMMAND'
* I_STRUCTURE_NAME =
is_layout = gw_is_layout
it_fieldcat = gi_it_fieldcat[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
it_sort = gi_it_sort[]
it_filter = gi_it_filter[]
is_sel_hide = gw_is_sel_hide
i_default = gv_i_default
i_save = gv_i_save
is_variant = gw_is_variant
it_events = gi_it_events[]
it_event_exit = gi_it_event_exit[]
is_print = gw_is_print
is_reprep_id = gw_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 = ft_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. "fm_alv_show
*&--------------------------------------------------------------------*
*& Form fm_alv_reset_data
*&--------------------------------------------------------------------*
* text

*---------------------------------------------------------------------*
FORM fm_alv_reset_data.
CLEAR : gw_is_layout,
gi_it_fieldcat,
gi_it_excluding,
gi_it_special_groups,
gi_it_sort,
gi_it_filter,
gw_is_sel_hide,
gv_i_default,
gv_i_save,
gw_is_variant,
gi_it_events,
gi_it_event_exit,
gw_is_print,
gw_is_reprep_id.
REFRESH : gi_it_fieldcat,
gi_it_excluding,
gi_it_special_groups,
gi_it_sort,
gi_it_filter,
gi_it_events,
gi_it_event_exit.
ENDFORM. "fm_alv_reset_data
*&--------------------------------------------------------------------*
*& Form fm_alv_set_layout
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM fm_alv_set_layout USING fu_title.
gw_is_layout-window_titlebar = fu_title.
gw_is_layout-zebra = 'X'.
gw_is_layout-colwidth_optimize = 'X'.
gw_is_layout-no_colhead = space.
gw_is_layout-group_change_edit = 'X'.
* gw_is_layout-box_fieldname = 'CHBOX'.
ENDFORM. "fm_alv_set_layout
*&--------------------------------------------------------------------*
*& Form fm_alv_set_print
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM fm_alv_set_print.
gw_is_print-no_print_listinfos = 'X'.
gw_is_print-no_print_selinfos = 'X'.
gw_is_print-no_coverpage = 'X'.
gw_is_print-no_print_hierseq_item = 'X'.
ENDFORM. "fm_alv_set_print
*&--------------------------------------------------------------------*
*& Form fm_alv_add_fieldcat
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->FU_1 text
* -->FU_2 text
* -->FU_3 text
* -->FU_4 text
* -->FU_5 text
* -->FU_6 text
* -->FU_7 text
* -->FU_8 text
* -->FU_9 text
* -->FU_10 text
* -->FU_11 text
* -->FU_12 text
* -->FU_13 text

* -->FU_14 text
* -->FU_15 text
* -->FU_16 text
* -->FU_17 text
* -->FU_18 text
* -->FU_19 text
* -->FU_20 text
* -->FU_21 text
*---------------------------------------------------------------------*
FORM fm_alv_add_fieldcat USING fu_1 fu_2 fu_3 fu_4 fu_5 fu_6 fu_7 fu_8 fu_9 fu_10
fu_11 fu_12 fu_13 fu_14 fu_15 fu_16 fu_17 fu_18 fu_19 fu_20 fu_21.
CLEAR: gi_it_fieldcat.
gi_it_fieldcat-fieldname = fu_1. " Fieldname
gi_it_fieldcat-ref_tabname = fu_2. " Reference Tablename
gi_it_fieldcat-ref_fieldname = fu_3. " Reference Fieldname
gi_it_fieldcat-no_out = fu_4. " (O)blig.(X)no out
gi_it_fieldcat-outputlen = fu_5. " Output length
gi_it_fieldcat-seltext_l = fu_6. " long key word
gi_it_fieldcat-seltext_m = fu_7. " middle key word
gi_it_fieldcat-seltext_s = fu_8. " short key word
gi_it_fieldcat-reptext_ddic = fu_9. " heading (ddic)
gi_it_fieldcat-round = fu_10. " round in write statement
gi_it_fieldcat-do_sum = fu_11. " sum up
gi_it_fieldcat-hotspot = fu_12. " 'X' = hotspot is active -> Event click
gi_it_fieldcat-decimals_out = fu_13. " decimals in write statement
gi_it_fieldcat-currency = fu_14.
gi_it_fieldcat-quantity = fu_15.
gi_it_fieldcat-qfieldname = fu_16. " field with quantity unit
gi_it_fieldcat-cfieldname = fu_17. " field with currency unit
gi_it_fieldcat-checkbox = fu_18. " 'X' = checkbox or ' ' = not checkbox
gi_it_fieldcat-icon = fu_19. " 'X' = icon or ' ' = not icon
gi_it_fieldcat-fix_column = fu_20. " 'X' = Fix Column On or ' ' = Fix Column off gi_it_fieldcat-key
= &21. "
gi_it_fieldcat-key = fu_21. " 'X' = Key or ' ' = not Key
APPEND gi_it_fieldcat.
ENDFORM. "fm_alv_add_fieldcat
*&--------------------------------------------------------------------*
*& Form FM_ALV_SET_PF_STATUS
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->RT_EXTAB text
*---------------------------------------------------------------------*
FORM fm_alv_set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'YSTANDARD'.
ENDFORM. "fm_alv_set_pf_status
*&--------------------------------------------------------------------*
*& Form FM_USER_COMMAND
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM fm_alv_user_command USING fu_ucomm LIKE sy-ucomm
fu_selfield TYPE slis_selfield.
DATA: lt_dynpread LIKE dynpread OCCURS 0 WITH HEADER LINE,
lv_ok_code LIKE sy-ucomm.
MOVE fu_ucomm TO lv_ok_code.
CASE lv_ok_code.
WHEN '&IC1'.
* PERFORM fm_alv_event_double_click.
WHEN '&ETA'.
* PERFORM fm_alv_event_double_click.
WHEN '&F03' OR '&F15' OR '&F12'.
ENDCASE.
MOVE 'X' TO fu_selfield-refresh.
ENDFORM. "FM_USER_COMMAND

You might also like