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: 

how to use the funtion module REUSE_ALV_VARIANT_ALL_MAINTAIN?

0 Kudos
434

Please help me.

3 REPLIES 3

Former Member
0 Kudos
121

Hi,

REUSE_ALV_VARIANT_ALL_MAINTAIN Maintain all object display variants

Regards

Sudheer

Former Member
0 Kudos
121

HI,

Use:

Maintain all display variants for one object.

Functionality:

The ALV variant maintenance dialog (setting defaults, list user-specific variants, list standard variants, delete variants, etc.) runs outside ALV.

Sample code....

function bus_search_hl_variant_maintain.

*"----


""Lokale Schnittstelle:

*" IMPORTING

*" REFERENCE(I_OBJAP) TYPE BU_OBJAP

*" REFERENCE(I_ACTION)

*"----


type-pools: slis.

data: lt_tbzs4 type table of tbzs4 with header line.

data: ls_variant type disvariant.

data: lt_fieldcat type table of slis_fieldcat_alv with header line.

data: lt_default_fieldcat type table of slis_fieldcat_alv

with header line.

data: lt_sort type table of slis_sortinfo_alv with header line.

data: lv_layout type slis_layout_alv.

data: lx_save.

data: lx_exit.

  • Grund-Feldkatalog besorgen

select * from tbzs4 into table lt_tbzs4 where objap = i_objap.

loop at lt_tbzs4.

lt_fieldcat-ref_tabname = lt_tbzs4-tabname.

lt_fieldcat-ref_fieldname = lt_tbzs4-fieldname.

lt_fieldcat-fieldname = lt_tbzs4-hl_name.

append lt_fieldcat.

endloop.

lt_default_fieldcat[] = lt_fieldcat[].

ls_variant-report = 'SAPLBUH1'.

ls_variant-handle = i_objap.

  • Welche Aktion?

case i_action.

  • Action = 'CHANGE'

when 'CHANGE'.

do.

call function 'REUSE_ALV_VARIANT_SELECT'

exporting

i_dialog = 'X'

i_default = ' '

it_default_fieldcat = lt_default_fieldcat[]

i_layout = lv_layout

importing

e_exit = lx_exit

et_fieldcat = lt_fieldcat[]

et_sort = lt_sort[]

changing

cs_variant = ls_variant

exceptions

wrong_input = 1

fc_not_complete = 2

not_found = 3

program_error = 4

others = 5.

case sy-subrc.

when 3.

message i109(r11).

exit.

endcase.

if lx_exit = 'X'. exit. endif.

call function 'REUSE_ALV_VARIANT_MAINTAIN'

exporting

i_save = 'X'

i_popup = 'X'

it_sort = lt_sort[]

importing

e_save = lx_save

changing

ct_fieldcat = lt_fieldcat[]

exceptions

no_change = 1

program_error = 2

others = 3.

if sy-subrc <> 0.

endif.

if lx_save = 'X'.

  • Sortinfo setzen

refresh lt_sort. clear lt_sort.

loop at lt_fieldcat where no_out = ' '.

lt_sort-spos = lt_fieldcat-col_pos.

lt_sort-fieldname = lt_fieldcat-ref_fieldname.

lt_sort-tabname = lt_fieldcat-ref_tabname.

lt_sort-up = 'X'.

append lt_sort.

endloop.

call function 'REUSE_ALV_VARIANT_SAVE'

exporting

it_fieldcat = lt_fieldcat[]

it_sort = lt_sort[]

i_dialog = 'X'

changing

cs_variant = ls_variant

  • EXCEPTIONS

  • WRONG_INPUT = 1

  • FC_NOT_COMPLETE = 2

  • FOREIGN_LOCK = 3

  • VARIANT_EXISTS = 4

  • NAME_RESERVED = 5

  • PROGRAM_ERROR = 6

  • OTHERS = 7

.

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.

enddo.

  • Action = 'CREATE'

when 'CREATE'.

if lt_fieldcat[] is initial.

lt_fieldcat[] = lt_default_fieldcat[].

endif.

call function 'REUSE_ALV_VARIANT_MAINTAIN'

exporting

i_save = 'X'

i_popup = 'X'

it_sort = lt_sort[]

importing

e_save = lx_save

changing

ct_fieldcat = lt_fieldcat[]

exceptions

no_change = 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.

if lx_save = 'X'.

  • Sortinfo setzen

refresh lt_sort. clear lt_sort.

loop at lt_fieldcat where no_out = ' '.

lt_sort-spos = lt_fieldcat-col_pos.

lt_sort-fieldname = lt_fieldcat-ref_fieldname.

lt_sort-tabname = lt_fieldcat-ref_tabname.

lt_sort-up = 'X'.

append lt_sort.

endloop.

call function 'REUSE_ALV_VARIANT_SAVE'

exporting

it_fieldcat = lt_fieldcat[]

i_dialog = 'X'

it_sort = lt_sort[]

changing

cs_variant = ls_variant

  • EXCEPTIONS

  • WRONG_INPUT = 1

  • FC_NOT_COMPLETE = 2

  • FOREIGN_LOCK = 3

  • VARIANT_EXISTS = 4

  • NAME_RESERVED = 5

  • PROGRAM_ERROR = 6

  • OTHERS = 7

.

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.

  • Action = 'ADM'

when 'ADM'.

call function 'REUSE_ALV_VARIANT_ALL_MAINTAIN'

EXPORTING

IS_VARIANT = ls_variant

I_DEFAULT = 'X'

  • EXCEPTIONS

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

endcase.

endfunction.

REgards,

Sankar

Former Member
0 Kudos
121

Hi

The ALV Grid Control is a tool with which you can output non-hierarchical lists in a

standardized format. The list data is displayed as a table on the screen.

The ALV Grid Control offers a range of interactive standard list functions that users need

frequently (find, sort, filter, calculate totals and subtotals, print, print preview, send list,

export list (in different formats), and so on. These functions are implemented in the

proxy object class. You as the programmer have the possibility to turn off functions not

needed. In most cases the implementations of the standard functions provided by the

control are sufficient. However, if required, you can adjust these implementations to

meet application-specific needs.

You can add self-defined functions to the toolbar, if necessary.

The ALV Grid Control allows users to adjust the layout of lists to meet their individual

requirements (for example, they can swap columns, hide columns, set filters for the

data to be displayed, calculate totals, and so on). The settings (list customizing) made

by a specific user are called a display variant. Display variants can be saved on a userspecific

or on a global basis. If such display variants exist for a list, they can be offered

to the user for selection. If a display variant is set as the default variant, the associated

list is always displayed based on the settings of this variant.

2. REUSE_ALV_LIST_DISPLAY

REUSE_ALV_GRID_DISPLAY

REUSE_ALV_FIELDCATALOG_MERGE

REUSE_ALV_COMMENTARY_WRITE

3. Use of Field Catalog is to determines the technical properties & add formating information of the column.

6. all the definition of internal table, structure, constants are declared in a type-pool called SLIS.

7.fieldcat-fieldname

fieldcat-ref_fieldname

fieldcat-tabname

fieldcat-seltext_m

5. Form user_command using r_ucomm like sy-ucomm rs_selfield type slis_selfield.

Sap provides a set of ALV (ABAP LIST VIEWER) function modules which can be put into use to embellish the output of a report. This set of ALV functions is used to enhance the readability and functionality of any report output. Cases arise in sap when the output of a report contains columns extending more than 255 characters in length.

In such cases, this set of ALV functions can help choose selected columns and arrange the different columns from a report output and also save different variants for report display. This is a very efficient tool for dynamically sorting and arranging the columns from a report output.

The report output can contain up to 90 columns in the display with the wide array of display options.

The commonly used ALV functions used for this purpose are;

1. REUSE_ALV_VARIANT_DEFAULT_GET

2. REUSE_ALV_VARIANT_F4

3. REUSE_ALV_VARIANT_EXISTENCE

4. REUSE_ALV_EVENTS_GET

5. REUSE_ALV_COMMENTARY_WRITE

6. REUSE_ALV_FIELDCATALOG_MERGE

7. REUSE_ALV_LIST_DISPLAY

8. REUSE_ALV_GRID_DISPLAY

9. REUSE_ALV_POPUP_TO_SELECT

Purpose of the above Functions are differ not all the functions are required in all the ALV Report.

But either no.7 or No.8 is there in the Program.

How you call this function in your report?

After completion of all the data fetching from the database and append this data into an Internal Table. say I_ITAB.

Then use follwing function module.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = 'Prog.name'

I_STRUCTURE_NAME = 'I_ITAB'

I_DEFAULT = 'X'

I_SAVE = 'A'

TABLES

T_OUTTAB = I_ITAB.

IF SY-SUBRC <> 0.

WRITE: 'SY-SUBRC: ', SY-SUBRC .

ENDIF.

ENDFORM. " GET_FINAL_DATA

The object F_IT_ALV has a field, the activity ACTVT, which can

contain four permitted values: 01, 02, 03 and 70. Each of the

activities 01, 02 and 70 controls the availability of particular

functions (in the menu and the toolbar) of the ALV line item list:

a) 01: "Settings -> Display variant -> Save..."

b) 02: "Settings -> Display variant -> Current..." and

"Settings -> Display variant -> Current header rows "

c) 70: "Settings -> Display variant -> Administration..."

Activity 03 corresponds to the minimum authorization, which is the

most restricted one: The user can only select layouts which have

been configured already. In particular, all of the other functions

named above are inactive with activity 03.

Now if you want to permit a user to change the column selection and

the headers as well as to save the layout thus created, for example,

but if you do not want to permit the user to administrate the

layouts, you grant him or her the authorization for activities 01

and 02.

Check this link it will be mosty usefull for u

http://www.sap-img.com/fu017.htm

Check this sample report

tables:     ekko.
type-pools: slis.
 
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,
line_color(4) type c, "Used to store row color
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.
 
* Data declaration for EVENT and PRINT PARAMETER.
data: gt_events type slis_t_event,
       gd_prntparams type slis_print_alv.
 
* data declaration for sorting.
data : it_sortcat   type slis_sortinfo_alv occurs 1,
       wa_sort like line of it_sortcat.
data :  i_list_comments type slis_t_listheader.
 
start-of-selection.
  perform data_retrieval.
*  perform user_command.
  perform build_fieldcatalog.
  perform build_layout.
  perform build_events.
  perform build_print_params.
  perform build_sortcat.
  perform display_alv_report.
 
end-of-selection.
 
*TOP-OF-PAGE.
*  PERFORM top-of-page.
 
end-of-page.
*&----------------------------------------------------------
*&      Form  build_fieldcatalog
*&----------------------------------------------------------
*       text
*-----------------------------------------------------------
*  -->  p1        text
*  <--  p2        text
*-----------------------------------------------------------
form build_fieldcatalog.
 
  fieldcatalog-fieldname   = 'EBELN'.
  fieldcatalog-seltext_m   = 'Purchase Order'.
  fieldcatalog-col_pos     = 0.
  fieldcatalog-outputlen   = 10.
  fieldcatalog-emphasize   = '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.
  fieldcatalog-do_sum = 'X'.
  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-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
*&----------------------------------------------------------
*       text
*-----------------------------------------------------------
*  -->  p1        text
*  <--  p2        text
*-----------------------------------------------------------
form build_layout.
  gd_layout-no_input          = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-totals_text       = 'Totals'(201).
 
* Set layout field for row attributes(i.e. color)
  gd_layout-info_fieldname =      'LINE_COLOR'.
*  gd_layout-totals_only        = 'X'.
*  gd_layout-f2code            = 'DISP'.  "Sets fcode for
*when double
*                                         "click(press f2)*
*  gd_layout-group_change_edit = 'X'.
*  gd_layout-header_text       = 'helllllo'.
endform.                    " build_layout
*&----------------------------------------------------------
*&      Form  data_retrieval
*&----------------------------------------------------------
*       text
*-----------------------------------------------------------
*  -->  p1        text
*  <--  p2        text
*-----------------------------------------------------------
form data_retrieval.
  data: ld_color(1) type c.
 
  select ebeln ebelp statu aedat matnr menge meins netpr
peinh from ekpo  into table it_ekko.
*Populate field with color attributes
  loop at it_ekko into wa_ekko.
* Populate color variable with colour properties
* Char 1 = C (This is a color property)
* Char 2 = 3 (Color codes: 1 - 7)
* Char 3 = Intensified on/off ( 1 or 0 )
* Char 4 = Inverse display on/off ( 1 or 0 )
*           i.e. wa_ekko-line_color = 'C410'
    ld_color = ld_color + 1.
* Only 7 colours so need to reset color value
    if ld_color = 8.
      ld_color = 1.
    endif.
    concatenate 'C' ld_color '10' into wa_ekko-line_color.
* wa_ekko-line_color = 'C410'.
    modify it_ekko from wa_ekko.
  endloop.
 
endform.                    " data_retrieval
*&----------------------------------------------------------
*&      Form  display_alv_report
*&----------------------------------------------------------
*       text
*-----------------------------------------------------------
*  -->  p1        text
*  <--  p2        text
*-----------------------------------------------------------
form display_alv_report.
  gd_repid = sy-repid.
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            i_callback_program       = gd_repid
            is_layout                = gd_layout
            i_callback_top_of_page   = 'TOP-OF-PAGE'
            i_callback_user_command  = 'USER_COMMAND'
            i_callback_pf_status_set = 'SET_PF_STATUS'
            it_event                 = gt_events
            is_print                 = gd_prntparams
            it_fieldcat              = fieldcatalog[]
            it_sort                 = it_sortcat
            i_save                   = 'X'
       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  user_command
*&----------------------------------------------------------
*       text
*-----------------------------------------------------------
*  -->  p1        text
*  <--  p2        text
*-----------------------------------------------------------
*&----------------------------------------------------------
*&      Form  top-of-page
*&----------------------------------------------------------
*       text
*-----------------------------------------------------------
*  -->  p1        text
*  <--  p2        text
*-----------------------------------------------------------
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             = 'GANESH_LOGO'.
 
 
 
endform.                    " top-of-page
 
*---------------------------------------------------------------------*
*       FORM user_command                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  R_UCOMM                                                       *
*  -->  RS_SELFIELD                                                   *
*---------------------------------------------------------------------*
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
  case r_ucomm.
 
    when '&IC1'.
      if rs_selfield-fieldname = 'EBELN'.
        read table it_ekko into wa_ekko index rs_selfield-tabindex.
        set parameter id 'BES' field wa_ekko-ebeln.
        call transaction 'ME23N' and skip first screen.
      endif.
    when 'ULHAS'.
      if rs_selfield-fieldname = 'EBELN'.
        read table it_ekko into wa_ekko index rs_selfield-tabindex.
        set parameter id 'BES' field wa_ekko-ebeln.
        call transaction 'ME23N' and skip first screen.
      endif.
 
  endcase.
 
endform.
 
*---------------------------------------------------------------------*
*       FORM set_pf_status                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  RT_EXTAB                                                      *
*---------------------------------------------------------------------*
form set_pf_status using rt_extab type slis_t_extab.
  set pf-status 'ZNEWSTATUS'.
endform.
*&---------------------------------------------------------------------*
*&      Form  build_events
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
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[]
* 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.
  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
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
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.
*&---------------------------------------------------------------------*
*&      Form  build_sortcat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form build_sortcat.
wa_sort-spos      = 1.
wa_sort-fieldname = 'EBELN'.
append wa_sort to it_sortcat.
 
wa_sort-spos      = 2.
wa_sort-fieldname = 'EBELP'.
append wa_sort to it_sortcat.
 
endform.                    " build_sortcat

Reward all helpfull answers

Regards

Pavan