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

creating varient through ABAP

Former Member
0 Likes
1,239

Hello,

I am giving selection screen to users & after giving input screen values, I want to create a varient out of that input using ABAP.

How to create the varient this way?

Krutika

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,189

Hi,

In ALV you can create variant like:



DATA : s_variant TYPE disvariant.

PARAMETER  : s_var TYPE disvariant-variant.

INITIALIZATION.

  s_variant-report = sy-repid.

  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      i_save        = 'A'
    CHANGING
      cs_variant    = s_variant
    EXCEPTIONS
      wrong_input   = 1
      not_found     = 2
      program_error = 3
      OTHERS        = 4.
  IF sy-subrc = 0.              " IF DEFAULT VARIANT FOUND

    s_var = s_variant-variant.  " PASS THE DEFAULT VARIANT RECEIVED TO THE SELECTION SCREEN FIELD
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_var.

  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
    EXPORTING
      is_variant                = s_variant
*   I_TABNAME_HEADER          =
*   I_TABNAME_ITEM            =
*   IT_DEFAULT_FIELDCAT       =
     i_save                    = 'A'
*   I_DISPLAY_VIA_GRID        = ' '
   IMPORTING
*   E_EXIT                    =
     es_variant                = s_variant
   EXCEPTIONS
     not_found                 = 1
     program_error             = 2
     OTHERS                    = 3.
*********TO GET THE SELECTED VARIANT FROM THE LIST IN THE SELECTION FIELD********************            .
  IF sy-subrc = 0.
    s_var = s_variant-variant.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

AT SELECTION-SCREEN.
  s_variant-variant = s_var.
  CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
    EXPORTING
      i_save        = 'A'
    CHANGING
      cs_variant    = s_variant
    EXCEPTIONS
      wrong_input   = 1
      not_found     = 2
      program_error = 3
      OTHERS        = 4.
  IF sy-subrc <> 0.

    MESSAGE w000(zgg_msg).
    CLEAR s_variant.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

Hope it helps

Regards

Mansi

9 REPLIES 9
Read only

ThomasZloch
Active Contributor
0 Likes
1,189

What have you tried yourself so far in order to find out?

Thomas

Read only

Former Member
0 Likes
1,189

CLICK ON SAVE

Read only

Former Member
0 Likes
1,189

Hi,

Use this FM if you want to create variant through ABAP---> RS_CREATE_VARIANT

Regards,

lakshman.

Read only

0 Likes
1,189

I want the varient name in export when i give selection screen input parameters as import.

Is there any FM for that?

Regards,

Krutika

Read only

0 Likes
1,189

Pass program name to RS_ALL_VARIANTS_4_1_REPORT_WAO

check the export parameters for list of variants

For more function modules goto se37 - > search with pattern RSVARIANT

Read only

Former Member
0 Likes
1,190

Hi,

In ALV you can create variant like:



DATA : s_variant TYPE disvariant.

PARAMETER  : s_var TYPE disvariant-variant.

INITIALIZATION.

  s_variant-report = sy-repid.

  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      i_save        = 'A'
    CHANGING
      cs_variant    = s_variant
    EXCEPTIONS
      wrong_input   = 1
      not_found     = 2
      program_error = 3
      OTHERS        = 4.
  IF sy-subrc = 0.              " IF DEFAULT VARIANT FOUND

    s_var = s_variant-variant.  " PASS THE DEFAULT VARIANT RECEIVED TO THE SELECTION SCREEN FIELD
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_var.

  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
    EXPORTING
      is_variant                = s_variant
*   I_TABNAME_HEADER          =
*   I_TABNAME_ITEM            =
*   IT_DEFAULT_FIELDCAT       =
     i_save                    = 'A'
*   I_DISPLAY_VIA_GRID        = ' '
   IMPORTING
*   E_EXIT                    =
     es_variant                = s_variant
   EXCEPTIONS
     not_found                 = 1
     program_error             = 2
     OTHERS                    = 3.
*********TO GET THE SELECTED VARIANT FROM THE LIST IN THE SELECTION FIELD********************            .
  IF sy-subrc = 0.
    s_var = s_variant-variant.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

AT SELECTION-SCREEN.
  s_variant-variant = s_var.
  CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
    EXPORTING
      i_save        = 'A'
    CHANGING
      cs_variant    = s_variant
    EXCEPTIONS
      wrong_input   = 1
      not_found     = 2
      program_error = 3
      OTHERS        = 4.
  IF sy-subrc <> 0.

    MESSAGE w000(zgg_msg).
    CLEAR s_variant.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

Hope it helps

Regards

Mansi

Read only

kamesh_g
Contributor
0 Likes
1,189

HI

After giving values on selection screen

In the menu bar follow the below path ..

GOTO->Variants-> Save as variant

It will ask for varinat name then save it ...

Read only

Former Member
0 Likes
1,189

Use search pattern: RSVARIANT in SE37.

You will get a relevant function module for your requirement.

Sometimes FMs differs from system to system.

Read only

Former Member
0 Likes
1,189

Use function module RS_CHANGE_CREATED_VARIANT as following

CALL FUNCTION 'RS_CHANGE_CREATED_VARIANT'

EXPORTING

curr_report = cs_report_name

curr_variant = cs_variant_name

vari_desc = wa_varid

  • ONLY_CONTENTS = 'X'

TABLES

vari_contents = it_valutab[]

  • VARI_TEXT =

  • VARI_SEL_DESC =

  • OBJECTS =

EXCEPTIONS

illegal_report_or_variant = 1

illegal_variantname = 2

not_authorized = 3

not_executed = 4

report_not_existent = 5

report_not_supplied = 6

variant_doesnt_exist = 7

variant_locked = 8

selections_no_match = 9.

to fill the valuetab follow below logic

rs_table_valutab-selname = 'S_DATE'. " Name of SELECT-OPTION / PARAMETER

rs_table_valutab-kind = cs_kind_selection. " Type of selection 'S' for selectio-option

rs_table_valutab-sign = cs_sign_i. " this will be the sign

rs_table_valutab-option = cs_option_eq. " this will be the option

rs_table_valutab-low = S_DATE-low. " this will be the value

    • Save details to Internal Table IT_VALUTAB.

APPEND rs_table_valutab TO it_valutab.