Register Login

Modify variants of a report program using ABAP

Updated May 18, 2018

How to modify variants of a report program using ABAP? 

Does anyone know which tables contain the variants for a report?

Check out TVARV if 4.6c and TVARVC if ECC.


Comments

  • 10 Jul 2008 4:48 am Guest Helpful Answer
    Goto SE38, choose radio button Variants and click on change button.
    Now you can change or modify as per your requirement.

    bye
    Venki
  • 15 Jul 2008 5:50 am MAYANK ONDORA
    TABLE VARID FIELD VARIANT CONTIAN DETAIL FOR VARIANT
  • 27 Nov 2009 7:46 am Guest
    Hello, I got this message when I want to modify this variant:
    "No authorization to change variant SAP&001"

    and when I would create a new same variant I got This:
    "Variant name does not comply with customer namespace naming conventions"

    Could you help me?
  • 09 Jul 2014 2:55 pm Guest

    class ZCL_CONSTANT definition
      public
      final
      create public .

    public section.

      class-data MS_RECORD type TVARVC .    " Constant record of the last search
      class-data MT_RECORD type TVARVC_T .  " Constant records of the last search
      class-data MV_VALUE type TVARV_VAL .  " Constant value of the last search
      class-data MT_BUFFER type TVARVC_T .  " Constant records found in the previous searches
      constants MC_SIGN_INCLUDE type DDSIGN value 'I'. "#EC NOTEXT
      constants MC_OPTION_EQUAL type DDOPTION value 'EQ'. "#EC NOTEXT
      constants MC_OPTION_CONTAIN type DDOPTION value 'CP'. "#EC NOTEXT

      class-methods CLEAR .
      type-pools ABAP .
      class-methods GET
        importing
          !IV_NAME type RVARI_VNAM
          !IB_USE_BUFFER type ABAP_BOOL default ABAP_TRUE
        exporting
          !EV_VALUE type ANY
          !ES_RECORD type TVARVC
          !ET_RECORD type TVARVC_T
          !ER_RANGE type STANDARD TABLE
        exceptions
          ER_RANGE_TYPE_NOT_VALID .
      class-methods GET_VALUE
        importing
          !IV_NAME type RVARI_VNAM
          !IB_USE_BUFFER type ABAP_BOOL default ABAP_TRUE
        returning
          value(RV_VALUE) type TVARV_VAL .
      class-methods GET_SEVERAL
        importing
          !IV_NAME_PATTERN type RVARI_VNAM
          !IB_USE_BUFFER type ABAP_BOOL default ABAP_TRUE
        returning
          value(RT_RECORD) type TVARVC_T .
      class-methods SEARCH
        importing
          !IV_NAME type RVARI_VNAM optional
          !IV_NAME_PATTERN type RVARI_VNAM optional
          !IR_RANGE_NAME type EFG_TAB_RANGES optional
          !IB_USE_BUFFER type ABAP_BOOL default ABAP_TRUE
        returning
          value(RB_FOUND) type ABAP_BOOL .
      PROTECTED SECTION.
    private section.
    ENDCLASS.

     

    CLASS ZCL_CONSTANT IMPLEMENTATION.


    * <SIGNATURE>---------------------------------------------------------------------------------------+
    * | Static Public Method ZCL_CONSTANT=>CLEAR
    * +-------------------------------------------------------------------------------------------------+
    * +--------------------------------------------------------------------------------------</SIGNATURE>
      method CLEAR.

    *******************************************************************************
    * Clear the previous search results
    *******************************************************************************

        CLEAR: mt_buffer, ms_record, mt_record, mv_value.

      endmethod.


    * <SIGNATURE>---------------------------------------------------------------------------------------+
    * | Static Public Method ZCL_CONSTANT=>GET
    * +-------------------------------------------------------------------------------------------------+
    * | [--->] IV_NAME                        TYPE        RVARI_VNAM
    * | [--->] IB_USE_BUFFER                  TYPE        ABAP_BOOL (default =ABAP_TRUE)
    * | [<---] EV_VALUE                       TYPE        ANY
    * | [<---] ES_RECORD                      TYPE        TVARVC
    * | [<---] ET_RECORD                      TYPE        TVARVC_T
    * | [<---] ER_RANGE                       TYPE        STANDARD TABLE
    * | [EXC!] ER_RANGE_TYPE_NOT_VALID
    * +--------------------------------------------------------------------------------------</SIGNATURE>
      METHOD get.

    *******************************************************************************
    * Get records of a single Constant
    *******************************************************************************

        DATA:
             lb_found_in_buffer            TYPE abap_bool      VALUE abap_false,
             ls_range                      TYPE REF TO data.

        FIELD-SYMBOLS:
             <lv_range_field>              TYPE any,
             <ls_range>                    TYPE any,
             <ls_record>                   TYPE tvarvc.


    * 1. If the buffer use is requested, look for the Constant records in the buffer
        CLEAR: es_record, et_record, ev_value, er_range,
               ms_record, mt_record, mv_value.

        IF ib_use_buffer = abap_true.
          LOOP AT mt_buffer ASSIGNING <ls_record> WHERE name = iv_name.
            APPEND <ls_record> TO mt_record.
          ENDLOOP.

          IF mt_record IS NOT INITIAL.
            lb_found_in_buffer = abap_true.
            READ TABLE mt_record INTO ms_record INDEX 1.
            mv_value = ms_record-low.
          ENDIF.
        ENDIF.


    * 2. If the Constant records have not been found in the buffer, look for the Constant records in the DB table TVARVC
        IF lb_found_in_buffer = abap_false.
          search( iv_name       = iv_name
                  ib_use_buffer = ib_use_buffer ).
        ENDIF.


    * 3. Set the requested exporting parameters
        " Structure of TVARVC
        IF es_record IS REQUESTED.
          es_record = ms_record.
        ENDIF.

        " Table of TVARVC
        IF et_record IS REQUESTED.
          et_record = mt_record.
        ENDIF.

        " Value of TVARVC-LOW
        IF ev_value IS REQUESTED.
          ev_value = mv_value.
        ENDIF.

        " Range table generated based on the found TVARVC records
        IF er_range IS REQUESTED.
          TRY.
              LOOP AT mt_record ASSIGNING <ls_record>.
                UNASSIGN <ls_range>.
                CREATE DATA ls_range LIKE LINE OF er_range.
                ASSIGN ls_range->* TO <ls_range>.
                IF <ls_range> IS ASSIGNED.
                  UNASSIGN <lv_range_field>.
                  ASSIGN COMPONENT 'SIGN' OF STRUCTURE <ls_range> TO <lv_range_field>.
                  IF <lv_range_field> IS ASSIGNED.
                    <lv_range_field> = <ls_record>-sign.
                  ENDIF.
                  UNASSIGN <lv_range_field>.
                  ASSIGN COMPONENT 'OPTION' OF STRUCTURE <ls_range> TO <lv_range_field>.
                  IF <lv_range_field> IS ASSIGNED.
                    <lv_range_field> = <ls_record>-opti.
                  ENDIF.
                  UNASSIGN <lv_range_field>.
                  ASSIGN COMPONENT 'LOW' OF STRUCTURE <ls_range> TO <lv_range_field>.
                  IF <lv_range_field> IS ASSIGNED.
                    <lv_range_field> = <ls_record>-low.
                  ENDIF.
                  UNASSIGN <lv_range_field>.
                  ASSIGN COMPONENT 'HIGH' OF STRUCTURE <ls_range> TO <lv_range_field>.
                  IF <lv_range_field> IS ASSIGNED.
                    <lv_range_field> = <ls_record>-high.
                  ENDIF.
                  APPEND <ls_range> TO er_range.
                ENDIF.
              ENDLOOP.
            CATCH cx_root.
              " Raise an exception if the range table could not be generated
              RAISE er_range_type_not_valid. " The range type of ER_RANGE is not adapted to the found value
          ENDTRY.

        ENDIF.

      ENDMETHOD.


    * <SIGNATURE>---------------------------------------------------------------------------------------+
    * | Static Public Method ZCL_CONSTANT=>GET_SEVERAL
    * +-------------------------------------------------------------------------------------------------+
    * | [--->] IV_NAME_PATTERN                TYPE        RVARI_VNAM
    * | [--->] IB_USE_BUFFER                  TYPE        ABAP_BOOL (default =ABAP_TRUE)
    * | [<-()] RT_RECORD                      TYPE        TVARVC_T
    * +--------------------------------------------------------------------------------------</SIGNATURE>
      METHOD get_several.

    *******************************************************************************
    * Get records of several Constants
    *******************************************************************************

    * Look for the requested Constants in the DB table TVARVC
        search( iv_name_pattern = iv_name_pattern
                ib_use_buffer   = ib_use_buffer   ).

    * Set the exporting parameter if requested
        IF rt_record IS REQUESTED.
          APPEND LINES OF mt_record TO rt_record.
        ENDIF.

      ENDMETHOD.


    * <SIGNATURE>---------------------------------------------------------------------------------------+
    * | Static Public Method ZCL_CONSTANT=>GET_VALUE
    * +-------------------------------------------------------------------------------------------------+
    * | [--->] IV_NAME                        TYPE        RVARI_VNAM
    * | [--->] IB_USE_BUFFER                  TYPE        ABAP_BOOL (default =ABAP_TRUE)
    * | [<-()] RV_VALUE                       TYPE        TVARV_VAL
    * +--------------------------------------------------------------------------------------</SIGNATURE>
      METHOD get_value.

    *******************************************************************************
    * Get value of a single Constant
    *******************************************************************************

    * Look for a single Constant value from the DB table TVARVC
        get( iv_name       = iv_name
             ib_use_buffer = ib_use_buffer ).

    * Set the exporting parameter if requested
        IF rv_value IS REQUESTED.
          rv_value = mv_value.
        ENDIF.

      ENDMETHOD.


    * <SIGNATURE>---------------------------------------------------------------------------------------+
    * | Static Public Method ZCL_CONSTANT=>SEARCH
    * +-------------------------------------------------------------------------------------------------+
    * | [--->] IV_NAME                        TYPE        RVARI_VNAM(optional)
    * | [--->] IV_NAME_PATTERN                TYPE        RVARI_VNAM(optional)
    * | [--->] IR_RANGE_NAME                  TYPE        EFG_TAB_RANGES(optional)
    * | [--->] IB_USE_BUFFER                  TYPE        ABAP_BOOL (default =ABAP_TRUE)
    * | [<-()] RB_FOUND                       TYPE        ABAP_BOOL
    * +--------------------------------------------------------------------------------------</SIGNATURE>
      METHOD search.

    *******************************************************************************
    * Search Constants in the DB table TVARVC
    * (also useful for buffer pre-load to avoid several accesses to the database)
    *******************************************************************************

        DATA:
             lr_name             TYPE RANGE OF rvari_vnam,
             ls_name             LIKE LINE OF lr_name,
             ls_range_name       LIKE LINE OF ir_range_name.


    * Look for the requested Constant records
        CLEAR: ms_record, mt_record, mv_value.

        " Prepare the search criteria
        IF iv_name IS NOT INITIAL.
          ls_name-sign = mc_sign_include.
          ls_name-option = mc_option_equal.
          ls_name-low = iv_name.
          APPEND ls_name TO lr_name.
        ENDIF.
        IF iv_name_pattern IS NOT INITIAL.
          ls_name-sign = mc_sign_include.
          ls_name-option = mc_option_contain.
          ls_name-low = iv_name_pattern.
          APPEND ls_name TO lr_name.
        ENDIF.
        IF ir_range_name IS NOT INITIAL.
          LOOP AT ir_range_name INTO ls_range_name.
            MOVE-CORRESPONDING ls_range_name TO ls_name.
            APPEND ls_name TO lr_name.
          ENDLOOP.
        ENDIF.

        " Look for the Constants in the DB table TVARVC
        IF lr_name IS NOT INITIAL.
          SELECT * FROM tvarvc
                   INTO TABLE mt_record
                   WHERE name IN lr_name.

          IF sy-subrc = 0.
            " Set the found results in the static class attributes
            READ TABLE mt_record INTO ms_record INDEX 1.
            mv_value = ms_record-low.

            " Add the found Constants to the buffer
            IF ib_use_buffer = abap_true.
              APPEND LINES OF mt_record TO mt_buffer.
              SORT mt_buffer.
              DELETE ADJACENT DUPLICATES FROM mt_buffer.
            ENDIF.
          ENDIF.
        ENDIF.

        IF rb_found IS REQUESTED.
          IF mt_record IS NOT INITIAL.
            rb_found = abap_true.
          ELSE.
            rb_found = abap_false.
          ENDIF.
        ENDIF.

      ENDMETHOD.
    ENDCLASS.


×