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

cl_salv_table - Save Layout

Former Member
47,947

I am using cl_salv_table to display an ALV but I can't get the save layout option to be available (in the menu path or on the toolbar). Is this not possible? Below is the code I am using to display:


  call method cl_salv_table=>factory
*    EXPORTING
*      list_display   = IF_SALV_C_BOOL_SAP=>FALSE
*      r_container    =
*      container_name =
    importing
      r_salv_table   = gr_table
    changing
      t_table        = it_out.

gr_functions = gr_table->get_functions( ).
  gr_functions->set_all( abap_true ).

  gr_display = gr_table->get_display_settings( ).
  gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
  gr_display->set_list_header( 'Cash Receipts Log' ).

  gr_sorts = gr_table->get_sorts( ).
*  TRY.

  call method gr_sorts->add_sort
  exporting
    columnname = 'BUKRS'
*      position   =
*      sequence   = IF_SALV_C_SORT=>SORT_UP
    subtotal   = if_salv_c_bool_sap=>false
*      group      = IF_SALV_C_SORT=>GROUP_NONE
*      obligatory = IF_SALV_C_BOOL_SAP=>FALSE
*    receiving
*      value      =
    .

  call method gr_sorts->add_sort
  exporting
    columnname = 'GKONT'
*      position   =
*      sequence   = IF_SALV_C_SORT=>SORT_UP
    subtotal   = if_salv_c_bool_sap=>false
*      group      = IF_SALV_C_SORT=>GROUP_NONE
*      obligatory = IF_SALV_C_BOOL_SAP=>FALSE
*    receiving
*      value      =
    .

  call method gr_sorts->add_sort
  exporting
    columnname = 'XREF1'
*      position   =
*      sequence   = IF_SALV_C_SORT=>SORT_UP
    subtotal   = if_salv_c_bool_sap=>false
*      group      = IF_SALV_C_SORT=>GROUP_NONE
*      obligatory = IF_SALV_C_BOOL_SAP=>FALSE
*    receiving
*      value      =
    .

  call method gr_sorts->add_sort
  exporting
    columnname = 'ZUONR'
*      position   =
*      sequence   = IF_SALV_C_SORT=>SORT_UP
    subtotal   = if_salv_c_bool_sap=>false
*      group      = IF_SALV_C_SORT=>GROUP_NONE
*      obligatory = IF_SALV_C_BOOL_SAP=>FALSE
*    receiving
*      value      =
    .

  call method gr_sorts->add_sort
  exporting
    columnname = 'BUDAT'
*      position   =
*      sequence   = IF_SALV_C_SORT=>SORT_UP
    subtotal   = if_salv_c_bool_sap=>true
*      group      = IF_SALV_C_SORT=>GROUP_NONE
*      obligatory = IF_SALV_C_BOOL_SAP=>FALSE
*    receiving
*      value      =
    .


  gr_columns = gr_table->get_columns( ).
  gr_column ?= gr_columns->get_column( 'GKONT').
  gr_column->set_long_text( 'Account Assignment Number' ).
  gr_column->set_medium_text( 'Account Assignment' ).
  gr_column->set_short_text( 'Account #' ).


  gr_agg = gr_table->get_aggregations( ).
  gr_agg->add_aggregation( 'WRBTR' ).

* Display
  gr_table->display( ).

Regards,

Davis

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
20,634

If I want to allow the user to specify a variant, how do I do that. Right now I am using the f4_layouts method, passing the variant.

PARAMETERS:       p_layout    TYPE disvariant-variant.

*----------------------------------------------------------------------*
* AT SELECTION-SCREEN ON VALUE-REQUEST                                 *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_layout.
  PERFORM f4_layouts USING cl_salv_layout=>restrict_none CHANGING p_layout.


*&---------------------------------------------------------------------*
*&      Form  F4_LAYOUTS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_IF_SALV_C_LAYOUT=>RESTRICT_NON  text
*      <--P_P_LAYOUT  text
*----------------------------------------------------------------------*
FORM f4_layouts USING i_restrict TYPE salv_de_layout_restriction
CHANGING c_layout TYPE disvariant-variant.

  DATA: ls_layout TYPE salv_s_layout_info,
        ls_key    TYPE salv_s_layout_key.

  ls_key-report = sy-repid.

  ls_layout = cl_salv_layout_service=>f4_layouts(
  s_key    = ls_key
  restrict = i_restrict ).

  c_layout = ls_layout-layout.

ENDFORM.                    " F4_LAYOUTS

It is allowing the user to press F4 but the layout doesn't get transferred to the ALV. I included the code that Rich posted and it does now allow for a save.

Regards,

Davis

8 REPLIES 8
Read only

RichHeilman
Developer Advocate
Developer Advocate
20,632

use the following coding to enable the save layout functionality.

DATA: gr_layout TYPE REF TO cl_salv_layout.
DATA: key TYPE salv_s_layout_key.

gr_layout = gr_table->get_layout( ).
key-report = sy-repid.
gr_layout->set_key( key ).
* You can pass the folling values to the SET_SAVE_RESTRICTION method.
*RESTRICT_NONE
*RESTRICT_USER_DEPENDANT
*RESTRICT_USER_INDEPENDANT
gr_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).

Also, you may want to look at this for reference.

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/eac1fa0b-0e01-0010-0990-8530de49...

Regards,

Rich Heilman

Read only

20,632

niubility 🙂 thank you

Read only

0 Likes
20,632

Thank you!

Read only

Former Member
0 Likes
20,635

If I want to allow the user to specify a variant, how do I do that. Right now I am using the f4_layouts method, passing the variant.

PARAMETERS:       p_layout    TYPE disvariant-variant.

*----------------------------------------------------------------------*
* AT SELECTION-SCREEN ON VALUE-REQUEST                                 *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_layout.
  PERFORM f4_layouts USING cl_salv_layout=>restrict_none CHANGING p_layout.


*&---------------------------------------------------------------------*
*&      Form  F4_LAYOUTS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_IF_SALV_C_LAYOUT=>RESTRICT_NON  text
*      <--P_P_LAYOUT  text
*----------------------------------------------------------------------*
FORM f4_layouts USING i_restrict TYPE salv_de_layout_restriction
CHANGING c_layout TYPE disvariant-variant.

  DATA: ls_layout TYPE salv_s_layout_info,
        ls_key    TYPE salv_s_layout_key.

  ls_key-report = sy-repid.

  ls_layout = cl_salv_layout_service=>f4_layouts(
  s_key    = ls_key
  restrict = i_restrict ).

  c_layout = ls_layout-layout.

ENDFORM.                    " F4_LAYOUTS

It is allowing the user to press F4 but the layout doesn't get transferred to the ALV. I included the code that Rich posted and it does now allow for a save.

Regards,

Davis

Read only

0 Likes
20,632

Call this method of CL_SALV_LAYOUT.


GS_LAYOUT->SET_INITIAL_LAYOUT ( C_layout ).

Regards,

Naimesh Patel

Read only

0 Likes
20,632

Yes, I would think that you would then need to set the layout to the grid.

gr_layout->set_initial_layout( p_layout ).

Regards,

Rich Heilman

Read only

0 Likes
20,632

Thanks. I was reading the documentation and it sounded like doing that overwrote any user-defined layout.

Regards,

Davis

Read only

ucha_andrbessa
Explorer
0 Likes
20,632

rich.heilmanIt worked for me.