F4 for ALV Layout Variant

By | Last Updated on August 21, 2014 | 22,938

Comprehensive code snippet for value help F4 for Layout Variant of all different type of ALV (SALV Model, ALV GUI Grid, ALV using REUSE FM)

ALV using SALV Model

 
CLASS lcl_layout_f4 DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      for_salv
        CHANGING cv_layout TYPE disvariant-variant.
ENDCLASS.                    "lcl_layout_f4 DEFINITION
 
PARAMETERS: p_layout TYPE disvariant-variant.
 
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_layout.
  lcl_layout_f4=>for_salv( CHANGING cv_layout = p_layout ).
 
*
CLASS lcl_layout_f4 IMPLEMENTATION.
  METHOD for_salv.
 
    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 = if_salv_c_layout=>restrict_none  ).
 
    cv_layout = ls_layout-layout.
 
 
  ENDMETHOD.                    "for_salv
 
ENDCLASS.                    "lcl_layout_f4 IMPLEMENTATION
 
 

ALV using GUI ALV Grid

 
    CLASS-METHODS:
      for_alv
        CHANGING cv_layout TYPE disvariant-variant,
***
  METHOD for_alv_lvc.
 
    DATA: ls_variant TYPE disvariant,
          lv_exit    TYPE char1.
 
    ls_variant-report = sy-repid.
 
    CALL FUNCTION 'LVC_VARIANT_F4'
      EXPORTING
        is_variant = ls_variant
        i_save     = 'A'
      IMPORTING
        e_exit     = lv_exit
        es_variant = ls_variant
      EXCEPTIONS
        not_found  = 1
        OTHERS     = 2.
    IF sy-subrc NE 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ELSE.
      CHECK lv_exit EQ space.
      cv_layout = ls_variant-variant.
    ENDIF.
 
  ENDMETHOD.                    "for_alv_lvc
 

ALV using REUSE FM

 
    CLASS-METHODS:
      for_alv_lvc
        CHANGING cv_layout TYPE disvariant-variant.
***
  METHOD for_alv.
 
    DATA: ls_variant TYPE disvariant,
          lv_exit    TYPE char1.
 
    ls_variant-report = sy-repid.
 
    CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
      EXPORTING
        is_variant = ls_variant
        i_save     = 'A'
      IMPORTING
        e_exit     = lv_exit
        es_variant = ls_variant
      EXCEPTIONS
        not_found  = 1.
    IF sy-subrc NE 0.
*     errror handling
      MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ELSE.
 
      CHECK lv_exit EQ space.
      cv_layout = ls_variant-variant.
 
    ENDIF.
 
  ENDMETHOD.                    "for_alv
 
 

Do you have a Code Snippet which you want to share, Submit Code Snippet here

Share It!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 274 articles.

Load comments

Comments on this Post are now closed. If you have something important to share, you can always contact me.