TVARV And TVARVC Table In SAP

Normally, you will notice this when you create a program variant and want to include a Constant data field in your variant.

Type of Variable Description
T                       T: Table Variable from TVARVC

Table Name

TVARV  - Table of variables in selection criteria

TVARVC - Table of Variant Variables (Client-Specific)

SAP has provided this table to avoid hard coding of constant values in programs.

TVARV table entries are transportable.

Rules you may want to keep in mind:

We don't want to insert TVARV entries if the data elements / values already exist in SAP.

We should build the logic to extract the necessary information from SAP. Some developers try to put such entries into TVARV table to simplify their coding efforts. But, that is not a recommended approach.

We don't; want to insert if you have several records of similar type. Custom table is an option in such case. E.g. Activity Types & Descriptions.

Good for all Constant values. E.g. Please check TVARV table entries (with Z* on name) in your dev. system.

Updating TVARV table

You can make use of tcode STVARV to update the data manually.

Alternatively, you can get request your ABAP programmer to create a program to update it.

Sample program for your reference.

REPORT ZTVARV_VARIABLES NO STANDARD PAGE HEADING
                          LINE-SIZE 132
                          MESSAGE-ID Z004.

*&---------------------------------------------------------------------*
*& technical description:                                              *
*&  This report updates the variant variables in tvar table before the *
*&  month end reports are run.
*&
*&---------------------------------------------------------------------*
*& Modification History:
*&---------------------------------------------------------------------*

TABLES : ZU0TVARV, tvarvc, T001.

constants : gc_fp(2) value 'FP',              "financial period
            gc_fy(2) value 'FY',              "financial year
            gc_cy(2) value 'CY',              "Calendar year
            gc_cm(2) value 'CM',              "Calendar month
            gc_cd_last(7) value 'CD_LAST',    "last Calendar day
            gc_fp1(7) value 'FP+1(2)',        "financial period(2)
           gc_01(2)  value '01',             "fixed value -> 01
            gc_001(3) value '001',            "fixed value -> 001
            gc_ny(2)  value 'NY',             "next financial year
            gc_np(7) value 'NP+1(2)',         "next financial period(2)
            gc_fullstop(1) value '.',         "fixed value -> .
            gc_underscore(1) value '_',       "fixed value -> _
            gc_dash(1) value '-',             "fixed value -> -
            gc_category_1 type zu0tvarv-category value '1',
            gc_category_2 type zu0tvarv-category value '2',
            gc_fynp(4) value 'FYNP',          "FY based on next period
            gc_ncy(3) value 'NCY',            "Next Calendar year
            gc_ncm(3) value 'NCM'.            "Next Calendar month

* variables
data : ls_periv type t001-periv value 'Z3',
       fp(3) type n,                          "financial period
       fy type t009b-bdatj,                   "financial year
       cy type t009b-bdatj,                   "Calendar year
       cm(2),                                 "Calendar month
       cd_last(2),                            "last Calendar day
       v_date1 type sy-datum,                 "date
       v_date2 type sy-datum,                 "date
       ny type t009b-bdatj,                   "next financial year
       np(3) type n,                          "next financial period
       ls_bldat type sy-datum,
       found(1),                              "indicator
       w_lines type i,
       gc_title type sy-title,
       heading1(80),
       gv_bldat(10),
       gs_invalid(1),
       gs_heading(1),
       fynp type t009b-bdatj,                  "FY based on next period
       ncy type t009b-bdatj,                   "Next Calendar year
       ncm(2),                                 "Next Calendar month
       eheading(132).

data : begin of xtvarvc occurs 0.
          include structure tvarvc.
data : end of xtvarvc.

data : begin of lt_zu0tvarv occurs 0.
          include structure zu0tvarv.
data : end of lt_zu0tvarv.

data : begin of lt_error occurs 0.
          include structure zu0tvarv.
data :    remark(132).
data : end of lt_error.
*&---------------------------------------------------------------------*
selection-screen begin of block main with frame title text-s01.
select-options : s_tvarv for ZU0TVARV-NAME no intervals.

parameters : p_bldat like sy-datum obligatory default sy-datum,
             p_test  default 'X'.

selection-screen skip.
selection-screen begin of block block1 with frame title text-s02.
parameters:      p_daily  radiobutton group radi,
                 p_month  radiobutton group radi default 'X',
                 p_year   radiobutton group radi.
selection-screen end of block block1.

selection-screen end of block main.
*&---------------------------------------------------------------------*
*
top-of-page.
   perform write_header.

at selection-screen.
   perform modify_system_heading.
*&---------------------------------------------------------------------*
*start of selection
*&---------------------------------------------------------------------*
start-of-selection.

* step 1
  perform get_records.

*  describe table lt_zu0tvarv lines w_lines.
*  if w_lines = 0.
*     call function 'POPUP_NO_LIST'
*      exporting
*        on_empty_list = 'X'.
*     exit.
*  endif.

* step 2
  clear ls_bldat.
  ls_bldat = p_bldat.
  perform get_last_day_per using ls_bldat.

* step 3
  perform update_value_in_zu0tvarv using gc_category_2.

* step 4 - Check for catelog = 1, if found then process....
  clear found.
  perform check_for_gc_category_1.
  if found = 'X'.
     clear ls_bldat.
     perform get_month_pus_determined using p_bldat
                                   changing ls_bldat.
     perform get_last_day_per using ls_bldat.
     perform update_value_in_zu0tvarv using gc_category_1.
  endif.

end-of-selection.

  if p_test eq 'X'.
     gs_heading = '1'.
     perform  write_new_val.
     if gs_invalid = 'X'.
        new-page.
        gs_heading = '2'.
        perform  write_invalid_val.
     endif.
  else.
     gs_heading = '1'.
     perform  write_new_val.
     perform update_tvarvc.
     if gs_invalid = 'X'.
        new-page.
        gs_heading = '2'.
        perform  write_invalid_val.
     endif.
  endif.
*&---------------------------------------------------------------------*
*&      Form  write_new_val
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM write_new_val.

  loop at xtvarvc.
    write :/(30) xtvarvc-name,
            (45) xtvarvc-low,
            (45) xtvarvc-high.
  endloop.

ENDFORM.                    " write_new_val

*&---------------------------------------------------------------------*
*&      Form  write_invalid_val
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM write_invalid_val.

  loop at lt_error.
    write :/(30) lt_error-name,
            (100) lt_error-remark.
  endloop.

ENDFORM.                    " write_invalid_val
*&---------------------------------------------------------------------*
*&      Form  write_header
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM write_header.

  sy-title = heading1.
  if gs_heading = '1'.
     write:/(30) text-003,      "'Variable name',
            (45) text-004,      "'Low Value',
            (45) text-005.      "'High Value'.
  else.
     write :1 text-001.
     write :/1 text-002. skip.
     write:/(30) text-003,      "'Variable name'.
            (45) text-006.      "Remarks
  endif.
  new-line.
  uline.

ENDFORM.                    " write_header
*&---------------------------------------------------------------------*
*&      Form  update_tvarvc
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM update_tvarvc.

  if not xtvarvc[] is initial.
     modify tvarvc from table xtvarvc.
  endif.

ENDFORM.                    " update_tvarvc

*&---------------------------------------------------------------------*
*&      Form  GET_LAST_DAY_PER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_last_day_per using ls_bldat_date.

data : next_bldat_period TYPE SY-DATUM.

* get financial period & financial year
  call function 'DETERMINE_PERIOD'
  exporting
     date                      = ls_bldat_date
     version                   = ls_periv
   importing
     period                    = fp
     year                      = fy.

* calculate next financial year
  ny = fy + 1.

* next financial period
  if fp = '012'.
     np = '001'.
  else.
     np = fp + 1.
  endif.

* K80K9A12XG - start
* FYNP must be derived only after value for FP and NP is determined
  if fp = '012' and np = '001'.
     fynp = ny.
  else.
     fynp = fy.
  endif.
* K80K9A12XG - end

* get calendar date last day
  call function 'LAST_DAY_IN_PERIOD_GET'
     exporting
          i_gjahr        = fy
          i_periv        = ls_periv
          i_poper        = fp
     importing
          e_date         = v_date1
     exceptions
          input_false    = 1
          t009_notfound  = 2
          t009b_notfound = 3
          others         = 4.

*    v_last_day = v_date1.
     cy      = v_date1(4).        " calendar year
     cm      = v_date1+4(2).      " calendar month
     cd_last = v_date1+6(2).      " calendar day

* NCY (Next calendar year) derived based using NP and FYNP
* NCM (Next calendar month) derived based using NP and FYNP
* get calendar date last day
  call function 'LAST_DAY_IN_PERIOD_GET'
     exporting
          i_gjahr        = fynp
          i_periv        = ls_periv
          i_poper        = np
     importing
          e_date         = v_date2
     exceptions
          input_false    = 1
          t009_notfound  = 2
          t009b_notfound = 3
          others         = 4.

     ncy      = v_date2(4).        " next calendar year
     ncm      = v_date2+4(2).      " next calendar month

endform.                    " get_last_day_per

*&---------------------------------------------------------------------*
*&      Form  UPDATE_VALUE_IN_ZU0TVARV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form UPDATE_VALUE_IN_ZU0TVARV using ls_category.

  data : ls_value(45), ls_error(1), ls_error1(1), ls_error2(1),
         ls_error_value(45), ls_error_value1(45), ls_error_value2(45).

  loop at lt_zu0tvarv where category = ls_category.
    if lt_zu0tvarv-type = 'P'.
       xtvarvc-name = lt_zu0tvarv-name.
       xtvarvc-type = lt_zu0tvarv-type.
       xtvarvc-numb = '0'.
       clear : ls_value, ls_error, ls_error_value.
       perform get_value using lt_zu0tvarv-single_format
                      changing ls_value
                               ls_error ls_error_value.
       if ls_error is initial.
          xtvarvc-low  = ls_value.
          append xtvarvc.  clear xtvarvc.
       else.
          lt_error-name   = lt_zu0tvarv-name.
          clear eheading.
          move text-e03 to eheading.
          replace '&4' with ls_error_value into eheading.
          condense eheading.
          lt_error-remark = eheading.
          append lt_error.  clear lt_error.
          delete lt_zu0tvarv index sy-tabix.
          gs_invalid = 'X'.
       endif.
    elseif lt_zu0tvarv-type = 'S'.
       xtvarvc-name = lt_zu0tvarv-name.
       xtvarvc-type = lt_zu0tvarv-type.
       xtvarvc-numb = '0'.
       xtvarvc-sign = 'I'.
       xtvarvc-opti = 'BT'.
       clear : ls_value, ls_error1, ls_error_value1.
       perform get_value using lt_zu0tvarv-format_from
                      changing ls_value
                               ls_error1 ls_error_value1.
       xtvarvc-low  = ls_value.
       clear : ls_value, ls_error2, ls_error_value2.
       perform get_value using lt_zu0tvarv-format_to
                      changing ls_value
                               ls_error2 ls_error_value2.
       if ls_error1 is initial and ls_error2 is initial.
          xtvarvc-high = ls_value.
          append xtvarvc.  clear xtvarvc.
       else.
          lt_error-name   = lt_zu0tvarv-name.
          clear eheading.
          move text-e03 to eheading.
          if not ls_error_value1 is initial.
             replace '&4' with ls_error_value1 into eheading.
          else.
             replace '&4' with ls_error_value2 into eheading.
          endif.
          condense eheading.
          lt_error-remark = eheading.
          append lt_error.  clear lt_error.
          delete lt_zu0tvarv index sy-tabix.
          gs_invalid = 'X'.
       endif.
    endif.
  endloop.

endform.                    " UPDATE_VALUE_IN_ZU0TVARV
*&---------------------------------------------------------------------*
*&      Form  GET_VALUE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LT_ZU0TVARV_SINGLE_FORMAT  text
*      <--P_LS_VALUE  text
*----------------------------------------------------------------------*
form GET_VALUE  using    p_lt_zu0tvarv_single_format
                changing p_ls_value
                         p_ls_error p_ls_error_value.

DATA: qname(20), sname(20), idx(1) TYPE n.
FIELD-SYMBOLS: <fq>, <fs>.
  data: p_ls_value1(8),  p_ls_value2(8),  p_ls_value3(8),
        p_ls_value4(8),  p_ls_value5(8),
        ls_p_value1(8),  ls_p_value2(8),  ls_p_value3(8),
        ls_p_value4(8),  ls_p_value5(8).

  clear : p_ls_value, p_ls_error, p_ls_error_value.
  clear : ls_p_value1, ls_p_value2, ls_p_value3, ls_p_value4,
          ls_p_value5.
  split p_lt_zu0tvarv_single_format at '&' into ls_p_value1 ls_p_value2
  ls_p_value3 ls_p_value4 ls_p_value5.

  Do 5 times.

    idx = idx + 1.
    CONCATENATE: 'ls_p_value' idx INTO qname.
    CONCATENATE: 'p_ls_value' idx INTO sname.
    CONDENSE: qname NO-GAPS, sname NO-GAPS.
    ASSIGN: (qname) TO <fq>,
            (sname) to <fs>.

    case <fq>.
       when gc_fp.
           <fs> = fp.            "financial period
       when gc_fy.
           <fs> = fy.            "financial year
       when gc_cy.
           <fs> = cy.            "calendar year
       when gc_cm.
           <fs> = cm.            "calendar month
       when gc_cd_last.
           <fs> = cd_last.       "last day of calendar month
       when gc_fp1.
           <fs> = fp+1(2).       "financial period+1(2)
       when gc_01.
           <fs> = gc_01.         "01 - fixed value
       when gc_001.
           <fs> = gc_001.        "001 - fixed value
       when gc_ny.
           <fs> = ny.            "next financial year
       when gc_np.
           <fs> = np+1(2).       "next period
       when gc_fullstop.
           <fs> = gc_fullstop.   "full stop
       when gc_underscore.
           <fs> = gc_underscore. "under score
       when gc_dash.
           <fs> = gc_dash.       "dash
       when gc_fynp.
           <fs> = fynp.          "Financial year based on next period
       when gc_ncy.
           <fs> = ncy.           "Next calendar year
       when gc_ncm.
           <fs> = ncm.           "Next calendar month

       when others.              "Symbol not found.....error
           if not <fq> is initial.
              p_ls_error = 'X'.
           endif.
    endcase.
    concatenate p_ls_value <fs> into p_ls_value.
    concatenate p_ls_error_value <fq> into p_ls_error_value.

  enddo.

endform.                    " GET_VALUE
*&---------------------------------------------------------------------*
*&      Form  GET_MONTH_PUS_DETERMINED
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_P_BLDAT  text
*      <--P_LS_BLDAT  text
*----------------------------------------------------------------------*
form GET_MONTH_PUS_DETERMINED  using    p_p_bldat
                               changing p_ls_bldat.

  CALL FUNCTION 'MONTH_PLUS_DETERMINE'
         EXPORTING
           MONTHS        = -1
           OLDDATE       = p_p_bldat
        IMPORTING
          NEWDATE       =  p_ls_bldat.

endform.                    " GET_MONTH_PUS_DETERMINED
*&---------------------------------------------------------------------*
*&      Form  CHECK_FOR_GC_CATEGORY_1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form CHECK_FOR_GC_CATEGORY_1 .

  loop at lt_zu0tvarv where category = gc_category_1.
  endloop.
  if sy-subrc = 0.
     found = 'X'.
  endif.

endform.                    " CHECK_FOR_GC_CATEGORY_1
*&---------------------------------------------------------------------*
*&      Form  GET_RECORDS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form GET_RECORDS .

data: ls_frequency(1).

if p_daily = 'X'.
    ls_frequency = 'D'.
elseif p_month = 'X'.
    ls_frequency = 'M'.
else.
    ls_frequency = 'Y'.
endif.

select * from zu0tvarv into table lt_zu0tvarv where name in s_tvarv
                                        and frequency = ls_frequency.
if not s_tvarv is initial.
    loop at s_tvarv.
      select * from tvarvc where name = s_tvarv-low.
      endselect.
      if sy-subrc ne 0.
         lt_error-name = s_tvarv-low.
         clear eheading.
         move text-e02 to eheading.
*        replace '&3' with lt_error-name into eheading.
         condense eheading.
         lt_error-remark = eheading.
         append lt_error.  clear lt_error.
* Once check not in SAP table TVARVC, shown records as error,
* Continue checking next records....
         continue.
      endif.

      select * from zu0tvarv where name = s_tvarv-low
                               and frequency = ls_frequency.
      endselect.
      if sy-subrc ne 0.
         lt_error-name = s_tvarv-low.
         clear eheading.
         move text-e01 to eheading.
*        replace '&2' with lt_error-name into eheading.
         condense eheading.
         lt_error-remark = eheading.
         append lt_error.  clear lt_error.
      endif.

    endloop.
endif.

* Check invalid selection entries enter? If yes, invalid indicator = 'X'
describe table lt_error lines w_lines.
if w_lines > 0.
    gs_invalid = 'X'.
endif.

* Remove entries in table lt_zu0tvarv where the same variable found in
* Error table lt_error
  loop at lt_error.
     read table lt_zu0tvarv with key name = lt_error-name.
     if sy-subrc = 0.
        delete lt_zu0tvarv index sy-tabix.
     endif.
  endloop.

endform.                    " GET_RECORDS
*&---------------------------------------------------------------------*
*&      Form  MODIFY_SYSTEM_HEADING
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form MODIFY_SYSTEM_HEADING .

  MOVE TEXT-H01 TO HEADING1.
  if p_daily = 'X'.
     replace '&1' with 'Daily' into heading1.
  elseif p_month = 'X'.
     replace '&1' with 'Monthly' into heading1.
  elseif p_year = 'X'.
     replace '&1' with 'Yearly' into heading1.
  endif.
  write p_bldat to gv_bldat DD/MM/YYYY.
  replace '&2' with gv_bldat into heading1.
  condense heading1. sy-title = heading1.

endform.                    " MODIFY_SYSTEM_HEADING

*-- End of program

Create your own customized table structure ZU0TVARV
 
MANDT MANDT  CLNT 3 0 Client
NAME RVARI_VNAM  CHAR 30 0 ABAP: Name of Variant Variable
TYPE Z_TVARV_TYPE CHAR 1 0 Type
CATEGORY Z_TVARV_CATEGORY CHAR 1 Category
FREQUENCY Z_TVARV_FREQUENCY CHAR 1 0 Frequency
SINGLE_FORMAT Z_TVARV_S_FORMAT CHAR 45 0 Single Format
FORMAT_FROM Z_TVARV_FORMAT_FR CHAR 45 Format From
FORMAT_TO Z_TVARV_FORMAT_TO CHAR 45 0 Format To
 

ABAP Tips

Related ABAP Topics:
Table CDHDR and CDPOS Usage

Get help for your ABAP problems
Do you have a ABAP Question?

SAP Books
SAP Certification, Interview Questions, Functional, Basis Administration and ABAP Programming Reference Books

More ABAP Tips

Main Index
SAP ERP Modules, Basis, ABAP and Other IMG Stuff

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.