Welcome To My BLOG

This site is to give a brief idea for the abap learners who are looking for some real time programs .It consists of collection of programs from my side . I hope these programs are very much used for all of the learners. Please check the links for any information in ABAP.
Please vote for my Blog. And please input me on this mail addrssess.Email me

Share this link with your friends

http://www.rebtel.com/u/15163104576

For every friend who signs up using this link and makes a payment, we'll give you 8 €!


Monday, December 13, 2010

ABAP - ICON'S, Symbols, Top Of Page, End Of Page In ALV Grid/List Display.

REPORT ysubalv.

*-------------------------------------------------------------------
* type-pools
*-------------------------------------------------------------------

TYPE-POOLS: slis.
*-------------------------------------------------------------------
* variables
*-------------------------------------------------------------------

* To pass name of the report in function module for ALV
DATA: v_repid LIKE sy-repid .

*-------------------------------------------------------------------
* internal table
*-------------------------------------------------------------------

* To pass the overall structure of the ALV report
DATA: struct_layout TYPE slis_layout_alv.
DATA: struct_layout1 TYPE slis_layout_alv.

* Internal table to capture various events in ALV
DATA : i_events TYPE slis_t_event.

* Table for catalog of the fields to be displayed
DATA: i_fieldcat TYPE slis_t_fieldcat_alv.
DATA : x_fieldcat TYPE slis_fieldcat_alv.

DATA: i_fieldcat1 TYPE slis_t_fieldcat_alv.
DATA : x_fieldcat1 TYPE slis_fieldcat_alv.

* Internal table to mention the sort sequence
DATA : it_sort TYPE slis_t_sortinfo_alv.
DATA : x_sort TYPE slis_sortinfo_alv.

* Internal table to display top of page
DATA : i_list_top_of_page TYPE slis_t_listheader.

* Structure to display variants
DATA : i_variant LIKE disvariant,
i_variant1 LIKE disvariant.

* Internal table to pass data
DATA: BEGIN OF i_tab OCCURS 0,
mblnr LIKE mseg-mblnr ,
matnr LIKE mseg-matnr,
maktg LIKE makt-maktg ,
charg LIKE mseg-charg ,
werks LIKE mseg-werks,
lgort LIKE mseg-lgort,
menge LIKE mseg-menge ,
meins LIKE mseg-meins ,
dmbtr LIKE mseg-dmbtr,
ebeln LIKE mseg-ebeln,
icn(4) TYPE c ,
sym(4) TYPE c ,
excpt(2) TYPE c ,
box(1),
END OF i_tab.

DATA : BEGIN OF i_doc OCCURS 0 .
INCLUDE STRUCTURE mseg.
DATA : END OF i_doc.

*-------------------------------------------------------------------
* selection screen
*-------------------------------------------------------------------

PARAMETERS : p_var LIKE disvariant-variant.
*-------------------------------------------------------------------
* initialization
*-------------------------------------------------------------------

INITIALIZATION.

v_repid = sy-repid.

* Display default variant
PERFORM sub_variant_init.
*-------------------------------------------------------------------
* at selection screen on field
*-------------------------------------------------------------------

AT SELECTION-SCREEN ON p_var.
* Once the user has entered variant, check about its existence
PERFORM sub_check_pvar.
*-------------------------------------------------------------------
* at selection screen value help for field
*-------------------------------------------------------------------

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_var.
* Display a list of various variants of the report when the
* user presses F4 key in the variant field
PERFORM sub_variant_f4.

*-------------------------------------------------------------------
* start of selection
*-------------------------------------------------------------------

START-OF-SELECTION.
* Prepare field catalog for the main report. State the name of
* the field , name of internal table , various formatting options etc
PERFORM sub_prepare_fieldcatalog.

* Fetches records from database into table i_tab to be passed as export
* parameter t_outtab in function module : REUSE_ALV_GRID_DISPLAY
PERFORM sub_select_record.

* Populate stat and icon columns of internal table i_tab with specific
* columns and symbols based on some logic for quantity and value fields.
PERFORM sub_modify_records.

* Defines the overall layout of the report
PERFORM sub_determine_alv_layout.

* Defines the sort sequence of the report
PERFORM sub_determine_sort_sequence.

* Defines the event table
PERFORM sub_eventtab_build USING i_events.

* Things to be written at the top of the page
PERFORM sub_comment_build USING i_list_top_of_page.

* Display the ALV list
PERFORM sub_show_alv_list.

*-------------------------------------------------------------------
* at line selection
*-------------------------------------------------------------------

AT LINE-SELECTION.

PERFORM sub_hotspot.


*&---------------------------------------------------------------------*
*& Form SUB_VARIANT_INIT
*&---------------------------------------------------------------------*
* Display default variant
*----------------------------------------------------------------------*
FORM sub_variant_init.
i_variant1-report = sy-repid.

* Search default variant for the report
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save = 'A'
CHANGING
cs_variant = i_variant1
EXCEPTIONS
not_found = 2.
* If default variant is found , use it as default.
* Else , use the variant LAYOUT1.
IF sy-subrc = 0.
p_var = i_variant1-variant.
ELSE.
p_var = 'LAYOUT1'.
ENDIF.

ENDFORM. " SUB_VARIANT_INIT

*&---------------------------------------------------------------------*
*& Form SUB_CHECK_PVAR
*&---------------------------------------------------------------------*
* Once the user has entered variant, check about its existence
*----------------------------------------------------------------------*
FORM sub_check_pvar.
* If the name of the variable is not blank, check about its existence
IF NOT p_var IS INITIAL.
CLEAR i_variant.
i_variant-report = sy-repid.
i_variant-variant = p_var.
CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
EXPORTING
i_save = 'A'
CHANGING
cs_variant = i_variant.
* If no such variant found , flash error message
IF sy-subrc NE 0 .
MESSAGE e398(00) WITH 'No such variant exists'.
ELSE.
* If variant exists , use the variant name to populate structure
* I_VARIANT1 which will be used for export parameter : IS_VARIANT
* in the function module : REUSE_ALV_GRID_DISPLAY
CLEAR i_variant1.
MOVE p_var TO i_variant1-variant.
MOVE sy-repid TO i_variant1-report.
ENDIF.
ELSE.
CLEAR i_variant.
ENDIF.
ENDFORM. " SUB_CHECK_PVAR

*&---------------------------------------------------------------------*
*& Form SUB_PREPARE_FIELDCATALOG
*&---------------------------------------------------------------------*
* Prepare field catalog for the main report. State the name of
* the field , name of internal table , various formatting options etc
*----------------------------------------------------------------------*
FORM sub_prepare_fieldcatalog.

* First field to appear in ALV list
x_fieldcat-col_pos = 1.
* Name of the internal table field
x_fieldcat-fieldname = 'SYM'.
* Name of the internal table
x_fieldcat-tabname = 'I_TAB'.
* Heading for the field
x_fieldcat-seltext_m = 'Stat'.
* The field is going to contain a symbol
x_fieldcat-symbol = 'X'.
* Append the specifications to the internal table for field catalog.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


* Second field to appear in ALV list
x_fieldcat-col_pos = 2.
* Name of the field in the internal table
x_fieldcat-fieldname = 'MATNR'.
* Name of the internal table
x_fieldcat-tabname = 'I_TAB'.
* Heading for the column
x_fieldcat-seltext_m = 'MatItem'.
* It is going to be the key field.The color for this field is going to
* be different
x_fieldcat-key = 'X'.
x_fieldcat-key_sel = 'X'.
* Single click on the field will trigger double click event.Also, a hand
* will appear when the cursor navigates to the field
x_fieldcat-hotspot = 'X'.
* The column and those left to it will not scroll
x_fieldcat-fix_column = 'X'.
* F1 help will come as it is referenced to DDIC table
x_fieldcat-ref_tabname = 'MSEG'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


x_fieldcat-col_pos = 3.
x_fieldcat-fieldname = 'MAKTG'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Description'.
* The field is centre(C for centre, R and L for left and
* right) justified
x_fieldcat-just = 'C'.
x_fieldcat-key = 'X'.
x_fieldcat-fix_column = 'X'.
* X_fieldcat-no_out = 'X'.
x_fieldcat-fix_column = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


x_fieldcat-col_pos = 4.
x_fieldcat-fieldname = 'CHARG'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Batch'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


x_fieldcat-col_pos = 5.
x_fieldcat-fieldname = 'EBELN'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Purchase Order'.
* The field will be colored differently(Cxyz)
x_fieldcat-emphasize = 'C511'.
* Initially the field will be hidden
x_fieldcat-no_out = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


x_fieldcat-col_pos = 6.
x_fieldcat-fieldname = 'MBLNR'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Document no'.
x_fieldcat-emphasize = 'C711'.
x_fieldcat-no_out = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


x_fieldcat-col_pos = 7.
x_fieldcat-fieldname = 'WERKS'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Plant'.
x_fieldcat-emphasize = 'C310'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


x_fieldcat-col_pos = 8.
x_fieldcat-fieldname = 'LGORT'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'St.Loc'.
x_fieldcat-no_out = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


x_fieldcat-col_pos = 9.
x_fieldcat-fieldname = 'MENGE'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Quantity'.
x_fieldcat-outputlen = 12.
* Summation is allowed for this field
x_fieldcat-do_sum = 'X'.
x_fieldcat-ref_tabname = 'MSEG'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


x_fieldcat-col_pos = 10.
x_fieldcat-fieldname = 'ICN'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = ''.
x_fieldcat-outputlen = 2.
x_fieldcat-no_out = 'X'.
x_fieldcat-icon = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.

x_fieldcat-col_pos = 11.
x_fieldcat-fieldname = 'MEINS'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Unit'.
x_fieldcat-qfieldname = 'MEINS'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.

x_fieldcat-col_pos = 12.
x_fieldcat-fieldname = 'DMBTR'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Local curr'.
x_fieldcat-outputlen = 12.
x_fieldcat-inttype = 'P'.
x_fieldcat-just = 'R'.
x_fieldcat-do_sum = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.

x_fieldcat-col_pos = 13.
x_fieldcat-fieldname = 'EXCPT'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-no_out = 'X'.
x_fieldcat-outputlen = 3.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.


ENDFORM. " SUB_PREPARE_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form SUB_SELECT_RECORD
*&---------------------------------------------------------------------*
* Fetches records from database into table i_tab to be passed as export
* parameter t_outtab in function module : REUSE_ALV_GRID_DISPLAY
*----------------------------------------------------------------------*
FORM sub_select_record.
SELECT b~mblnr
a~matnr
a~maktg
b~charg
b~werks
b~lgort
b~menge
b~meins
b~dmbtr
b~ebeln
FROM makt AS a JOIN mseg AS b
ON ( a~matnr = b~matnr )
INTO TABLE i_tab
UP TO 300 ROWS
WHERE b~bwart = '101' .

ENDFORM. " SUB_SELECT_RECORD
*&---------------------------------------------------------------------*
*& Form SUB_MODIFY_RECORDS
*&---------------------------------------------------------------------*
* Populate stat and icon columns of internal table i_tab with specific
* columns and symbols based on some logic for quantity and value fields.
*----------------------------------------------------------------------*
FORM sub_modify_records.

LOOP AT i_tab.
IF i_tab-dmbtr GT 10000.
* Field icn of internal table is going to contain icon . For this column
*icon_allowed is set in the field catalog table. For various icons,see
* type pool
i_tab-icn = ' (1V)'.
MODIFY i_tab TRANSPORTING icn.
ENDIF.
IF i_tab-menge GT 50.
* Field icn of internal table is going to contain symbol . For this
* column symbol_allowed is set in the field catalog table. For various
* icons,see type pool
i_tab-sym = 'N'.
MODIFY i_tab TRANSPORTING sym.
ENDIF.

IF i_tab-werks NE 'SDC1'.
* This field will contain lights , traffic signals : red.yellow,green
* That this field will be used as a light will be specified in the
* column of structure STRUCT_LAYOUT.
i_tab-excpt = '1'.
MODIFY i_tab TRANSPORTING excpt.
ENDIF.
ENDLOOP.

ENDFORM. " SUB_MODIFY_RECORDS

*&---------------------------------------------------------------------*
*& Form SUB_DETERMINE_ALV_LAYOUT *
*&---------------------------------------------------------------------*
*& Defines the overall structure of the report layout *
*----------------------------------------------------------------------*
FORM sub_determine_alv_layout.
* Field EXCPT will show the light signal
struct_layout-lights_fieldname = 'EXCPT'.
* Field BOS of the internal table will act as pushbutton and will appear
* at the left of the grid display. User will press that to select a
* record
struct_layout-box_fieldname = 'BOX'.
struct_layout-totals_text = 'Totqty '.
struct_layout-zebra = 'X'.
struct_layout-confirmation_prompt = 'X'.
struct_layout-detail_titlebar = 'Details of Storing'.
struct_layout-no_sumchoice = 'X'.
struct_layout-totals_only = 'X'.
ENDFORM. " SUB_DETERMINE_ALV_LAYOUT
*&---------------------------------------------------------------------*
*& Form SUB_DETERMINE_SORT_SEQUENCE
*&---------------------------------------------------------------------*
* Defines the sort sequence of the report
*----------------------------------------------------------------------*
FORM sub_determine_sort_sequence.
x_sort-spos = 1. " Sort order
x_sort-fieldname = 'MATNR'.
x_sort-tabname = 'I_TAB'.
x_sort-up = 'X'.
x_sort-subtot = 'X'. " Sub total allowed

APPEND x_sort TO it_sort.
CLEAR x_sort.

ENDFORM. " SUB_DETERMINE_SORT_SEQUENCE
*&---------------------------------------------------------------------*
*& Form SUB_SHOW_ALV_LIST
*&---------------------------------------------------------------------*
* Shows ALV list in grid form
*----------------------------------------------------------------------*
FORM sub_show_alv_list.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* Name of the program
i_callback_program = v_repid
* title
i_grid_title = 'Details of Storing'
* calls subroutine : PF_STATUS_SET
i_callback_pf_status_set = 'PF_STATUS_SET'
* Calls subroutine : user_command
i_callback_user_command = 'USER_COMMAND'
* Overall structure of the report
is_layout = struct_layout
* Passes the field catg internal table
it_fieldcat = i_fieldcat
* Passws the sort sequence internal table
it_sort = it_sort
i_default = 'X'
i_save = 'A'
* Passes the internal table for variants
is_variant = i_variant1
* fetches different events into internal table i_events
it_events = i_events[]
TABLES
* Passes data table for ALV display
t_outtab = i_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. " SUB_SHOW_ALV_LIST

*&---------------------------------------------------------------------*
*& Form set_status
*&---------------------------------------------------------------------*
* Form used to set the Custom pf-status of the List Display
*----------------------------------------------------------------------*
* rt_extab :
*----------------------------------------------------------------------*
FORM pf_status_set USING i_rt_extab TYPE slis_t_extab.
DATA : x_extab TYPE slis_extab.
x_extab-fcode = '&LFO'.
APPEND x_extab TO i_rt_extab.
* Pf-status STANDARD of program SAPLSALV is copied to ZSTANDARD of the
* current program and the pushbutton for Information (okcode=&LFO) is
* excluded
SET PF-STATUS 'ZSTANDARD' EXCLUDING i_rt_extab .

ENDFORM. "pf_status_set

*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* Form used to handle USER_COMMAND events
*----------------------------------------------------------------------*
* rf_ucomm: Function Code
* rs : Internal Table containing the selection information.
*----------------------------------------------------------------------*

FORM user_command USING rf_ucomm LIKE sy-ucomm
rs TYPE slis_selfield.
DATA : v_mblnr LIKE mseg-mblnr.
CASE rf_ucomm.

* A custom pushbutton for record deletion is set in the GUI status.
* When a record is selected , the field BOC for that record becomes 'X'.
* The records are traced and deleted and the fields are refreshed( rs
* of type slis_selfield is refreshed)
WHEN '&DEL'. "Print button clicked.
DELETE i_tab WHERE box = 'X'.
rs-refresh = 'X'.

* When the user selects a row and presses the Select pushbutton ( user
* defined ) from the application toolbar, the details of the document
* will be shown in another ALV list
WHEN '&SEL'.
PERFORM sub_select_document.

* set parameter id 'MBN' field i_tab-mblnr.
* call transaction 'MB03'.

* Ok code for double click is &IC1 for ALV report
WHEN '&IC1'.
PERFORM sub_hotspot.
ENDCASE.

ENDFORM. "user_command
*&---------------------------------------------------------------------*
*& Form SUB_HOTSPOT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text *----------------------------------------------------------------------*
FORM sub_hotspot.

MESSAGE i398(00) WITH 'Hello'.
ENDFORM. " SUB_HOTSPOT

*&---------------------------------------------------------------------*
*& Form SUB_VARIANT_F4
*&---------------------------------------------------------------------*
* Display a list of various variants of the report when the
* user presses F4 key in the variant field
*----------------------------------------------------------------------*
FORM sub_variant_f4.

i_variant-report = sy-repid.
* Utilising the name of the report , this function module will
* search for a list of variants and will fetch the selected one into
* the parameter field for variants

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = i_variant
i_save = 'A'
i_display_via_grid = 'X'

IMPORTING
es_variant = i_variant1

EXCEPTIONS
not_found = 1
program_error = 2
OTHERS = 3.

IF sy-subrc = 0.
p_var = i_variant1-variant.
ENDIF.
ENDFORM. " SUB_VARIANT_F4

*&---------------------------------------------------------------------*
*& Form SUB_SELECT_DOCUMENT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text *----------------------------------------------------------------------*
FORM sub_select_document.

DATA : v_lines TYPE i .

READ TABLE i_tab WITH KEY box = 'X'.
SELECT * FROM mseg INTO TABLE i_doc WHERE mblnr = i_tab-mblnr.

IF sy-subrc EQ 0 .
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_internal_tabname = 'I_DOC'
i_structure_name = 'MSEG'
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.

CLEAR struct_layout1.
struct_layout1-colwidth_optimize = 'X'.
REFRESH it_sort.
CLEAR it_sort.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = v_repid
i_grid_title = 'Details of Document'
is_layout = struct_layout1
it_fieldcat = i_fieldcat1
i_structure_name = 'MSEG'
i_default = 'X'
i_save = 'A'
TABLES
t_outtab = i_doc
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.
ENDIF.
ENDFORM. " SUB_SELECT_DOCUMENT
*&---------------------------------------------------------------------*
*& Form SUB_COMMENT_BUILD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_I_LIST_TOP_OF_PAGE text
*----------------------------------------------------------------------*
FORM sub_comment_build USING i_top_of_page TYPE slis_t_listheader.
DATA: ls_line TYPE slis_listheader.

***Header
CLEAR ls_line.
ls_line-typ = 'H'.
* LS_LINE-KEY: not used for this type
ls_line-info = 'Heading list'.
APPEND ls_line TO i_top_of_page.

***Selection
CLEAR ls_line.
ls_line-typ = 'S'.
ls_line-key = 'Key 1'.
ls_line-info = 'Material '.
APPEND ls_line TO i_top_of_page.
ls_line-key = 'Key 2'.
ls_line-info = 'Document no'.
APPEND ls_line TO i_top_of_page.

***Action
CLEAR ls_line.

ENDFORM. " SUB_COMMENT_BUILD
*&---------------------------------------------------------------------*
*& Form SUB_EVENTTAB_BUILD
*&---------------------------------------------------------------------*
* Defines the event table
*----------------------------------------------------------------------*
FORM sub_eventtab_build USING l_events TYPE slis_t_event.
DATA: ls_event TYPE slis_alv_event.
* Get the different events of the ALV
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = l_events.
* Search the top of page events
READ TABLE l_events WITH KEY name = slis_ev_top_of_page INTO ls_event.
IF sy-subrc = 0.
MOVE 'TOP_OF_PAGE' TO ls_event-form.
APPEND ls_event TO l_events.
ENDIF.
ENDFORM. " SUB_EVENTTAB_BUILD

*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
* When TOP-OF-PAGE will be fired , this event will be called and it
* will use the contents of i_list_top_of_page for output in the header
*---------------------------------------------------------------------*
FORM top_of_page.
*
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo = 'ENJOYSAP_LOGO'
it_list_commentary = i_list_top_of_page.

ENDFORM. "top_of_page

No comments: