Application Development 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: 

Updating TVARV table....

Former Member
0 Kudos

hello all,

My requirement is to load data to App. Server. After initial load, only deltas will be loaded. My parameters are: begin date, end date, begin time, end time. I have maintained these parameters in TVARV as well (I have initially entered values for all the variables in TVARV table)

I set up the variants for these parameters in my program.

After executing the program once, the end_date should move to begin_date and same thing for the begin/end time.

End_date and End_time should be set to sy-datum and sy-uzeit, respectively.

Following is the code, in which I have also included function module for change pointers to read the changes:

********************************************************

TABLES: TVARVC.

parameters: beg_date like CDHDR-UDATE obligatory, "Begin Date

end_date like CDHDR-UDATE obligatory, "End Date

beg_time like CDHDR-UTIME obligatory, "Begin Time

end_time like CDHDR-UTIME obligatory. "End Time

start-of-selection.

CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'

EXPORTING

DATE_OF_CHANGE = beg_date

OBJECTCLASS = 'material'

TIME_OF_CHANGE = beg_time

USERNAME = SY-UNAME

DATE_UNTIL = end_date

TIME_UNTIL = end_time

TABLES

I_CDHDR = pt_cdhdr

EXCEPTIONS

NO_POSITION_FOUND = 1

WRONG_ACCESS_TO_ARCHIVE = 2

TIME_ZONE_CONVERSION_ERROR = 3

OTHERS = 4.

*Update TVARV table to reflect changes done

Select single * from tvarvc

where name = 'Z_BEGIN_DATE'

and type = 'P'.

tvarvc-low = beg_date.

tvarvc-high = end_date.

move tvarvc-high to tvarvc-low.

update tvarvc.

commit work.

Select single * from tvarvc

where name = 'Z_END_DATE'

and type = 'P'.

tvarvc-low = sy-datum.

update tvarvc.

commit work.

Select single * from tvarvc

where name = 'Z_BEGIN_TIME'

and type = 'P'.

tvarvc-low = beg_time.

tvarvc-high = end_time.

move tvarvc-high to tvarvc-low.

update tvarvc.

commit work.

Select single * from tvarvc

where name = 'Z_END_TIME'

and type = 'P'.

tvarvc-low = sy-uzeit.

update tvarvc.

commit work.

*********************************************************

Apparently, it is not working. I am also confused about the high/low values for setting up date and time.

Your help is greatly appreciated.

Thanks.

Regards,

Fred.

1 ACCEPTED SOLUTION

suresh_datti
Active Contributor
0 Kudos

Hi Fred,

You have to lock & unlock before & after upate of TVARVc.. Pl take a look at the following code & modify it to suit your reqt..


*Lock TVARVC rcord with ESVARV.
  CLEAR TVARVC.

  CALL FUNCTION 'ENQUEUE_ESVARVC'
       EXPORTING
            MODE_TVARVC     = 'E'
            NAME           = VAR_NAME
            TYPE           = VAR_TYPE
            NUMB           = VAR_NUMB
            _SCOPE         = '2'
       EXCEPTIONS
            FOREIGN_LOCK   = 1
            SYSTEM_FAILURE = 2
            OTHERS         = 3.

* Select from TVARV all the fields, as all of them are needed
  SELECT SINGLE * FROM TVARVC WHERE NAME = VAR_NAME AND
                                    TYPE = VAR_TYPE AND
                                    NUMB = VAR_NUMB.

  IF SY-SUBRC <> 0.
    RAISE RECORD_NOT_FOUND.
  ENDIF.

* If variable option is Initial
  IF VAR_OPTION IS INITIAL.
    TVARVC-OPTI = 'EQ'.
  ELSE.
    TVARVC-OPTI = VAR_OPTION.
  ENDIF.

* If variable Sign is Initial
  IF VAR_SIGN IS INITIAL.
    TVARVC-SIGN = 'I'.
  ELSE.
    TVARVC-SIGN = VAR_SIGN.
  ENDIF.

  TVARVC-LOW = LOW_VALUE.

  IF VAR_TYPE = 'S'.
    TVARVC-HIGH = HIGH_VALUE.
  ENDIF.

* Update TVARVC
  update TVARVC.
  IF SY-SUBRC <> 0.
    RAISE UPDATE_FAILED.
  ENDIF.

*Unlock TVARVC rcord with ESVARVC.
  CALL FUNCTION 'DEQUEUE_ESVARVC'
       EXPORTING
            MODE_TVARVC = 'E'
            NAME        = VAR_NAME
            TYPE        = VAR_TYPE
            NUMB        = VAR_NUMB
            _SCOPE      = '3'
            _SYNCHRON   = ' '.

Regards,

Suresh Datti

6 REPLIES 6

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Since you are using ranges, the TYPE should be "S" instead of "P".


....
and type = 'S'.

Regards,

Rich Heilman

suresh_datti
Active Contributor
0 Kudos

Hi Fred,

You have to lock & unlock before & after upate of TVARVc.. Pl take a look at the following code & modify it to suit your reqt..


*Lock TVARVC rcord with ESVARV.
  CLEAR TVARVC.

  CALL FUNCTION 'ENQUEUE_ESVARVC'
       EXPORTING
            MODE_TVARVC     = 'E'
            NAME           = VAR_NAME
            TYPE           = VAR_TYPE
            NUMB           = VAR_NUMB
            _SCOPE         = '2'
       EXCEPTIONS
            FOREIGN_LOCK   = 1
            SYSTEM_FAILURE = 2
            OTHERS         = 3.

* Select from TVARV all the fields, as all of them are needed
  SELECT SINGLE * FROM TVARVC WHERE NAME = VAR_NAME AND
                                    TYPE = VAR_TYPE AND
                                    NUMB = VAR_NUMB.

  IF SY-SUBRC <> 0.
    RAISE RECORD_NOT_FOUND.
  ENDIF.

* If variable option is Initial
  IF VAR_OPTION IS INITIAL.
    TVARVC-OPTI = 'EQ'.
  ELSE.
    TVARVC-OPTI = VAR_OPTION.
  ENDIF.

* If variable Sign is Initial
  IF VAR_SIGN IS INITIAL.
    TVARVC-SIGN = 'I'.
  ELSE.
    TVARVC-SIGN = VAR_SIGN.
  ENDIF.

  TVARVC-LOW = LOW_VALUE.

  IF VAR_TYPE = 'S'.
    TVARVC-HIGH = HIGH_VALUE.
  ENDIF.

* Update TVARVC
  update TVARVC.
  IF SY-SUBRC <> 0.
    RAISE UPDATE_FAILED.
  ENDIF.

*Unlock TVARVC rcord with ESVARVC.
  CALL FUNCTION 'DEQUEUE_ESVARVC'
       EXPORTING
            MODE_TVARVC = 'E'
            NAME        = VAR_NAME
            TYPE        = VAR_TYPE
            NUMB        = VAR_NUMB
            _SCOPE      = '3'
            _SYNCHRON   = ' '.

Regards,

Suresh Datti

0 Kudos

Hi Suresh,

I will do the enqueue/dequeue part, but how do I move the end date/time to begin date/time and set the end date/time to sy-datum and sy-uzeit after executing the program.

I am using type = 'P' since I want all of them to be parameters. If you go and check the table itself, it has high and low values for the all the variables. Why is there a high/low value for each variable??

Regards,

Fred.

0 Kudos

>>> Why is there a high/low value for each variable??

Because, the code I used had SELECT-OPTIONs.. In your case, change the TYPE = 'P', since it is a parameter.

Regards,

Suresh Datti

0 Kudos

If it is a parameter, and not a select-option, then you shouldn't be filling the HIGH, just the LOW. In order for you to use a range, it must be a SELECT-OPTION.

Regards,

Rich Heilman

0 Kudos

Hello,

I try to apply your code to my trouble.

I obtain a raised error when i update the table.

i need to load customer number into one variable and after i have to print a report with it.

this the code i wrote from yours:

LOOP AT lt_data.
  IF z_bukrs = lt_data-bukrs AND z_gest = lt_data-busab.
    IF lt_data-kunnr NE w_kunnr.
      MOVE: lt_data-kunnr TO w_kunnr.

      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = w_kunnr
        IMPORTING
          output = w_kunnr.

      MOVE:
          sy-mandt TO w_tvarv-mandt,
          lt_data-kunnr TO w_kunnr,
          'KUNNR' TO w_tvarv-name,
          'EQ' TO w_tvarv-opti,
          'S' TO w_tvarv-type,
          'I' TO w_tvarv-sign,
          w_num TO w_tvarv-numb.
      w_num = w_num + 1.
      CALL FUNCTION 'ENQUEUE_ESVARVC'
        EXPORTING
          mode_tvarvc    = 'E'
          name           = w_tvarv-name
          type           = w_tvarv-type
          numb           = w_tvarv-numb
          _scope         = '2'
        EXCEPTIONS
          foreign_lock   = 1
          system_failure = 2
          OTHERS         = 3.
* Select from TVARV all the fields, as all of them are needed
      SELECT SINGLE * FROM tvarvc WHERE name = w_tvarv-name AND
                                        type = w_tvarv-type AND
                                        numb = w_tvarv-numb.

      IF sy-subrc <> 0.
        MOVE :
          w_tvarv-name TO tvarvc-name,
          w_tvarv-mandt TO tvarvc-mandt,
          w_tvarv-type TO tvarvc-type,
          w_tvarv-numb TO tvarvc-numb,
          w_tvarv-sign TO tvarvc-sign.




      ENDIF.

* If variable option is Initial
      tvarvc-opti = 'EQ'.
* If variable Sign is Initial
      tvarvc-sign = 'I'.

      tvarvc-low = w_kunnr.

* Update TVARVC
      UPDATE tvarvc.
      BREAK-POINT.
      IF sy-subrc <> 0.
        RAISE update_failed.
      ENDIF.

*Unlock TVARVC rcord with ESVARVC.
      CALL FUNCTION 'DEQUEUE_ESVARVC'
        EXPORTING
          mode_tvarvc = 'E'
          name        = w_tvarv-name
          type        = w_tvarv-type
          numb        = w_tvarv-numb
          _scope      = '3'
          _synchron   = ' '.


      APPEND w_tvarv.
    ELSE.
*      BREAK-POINT.




      INSERT  tvarvc FROM w_tvarv.

    ENDIF.

  ENDIF.


ENDLOOP.

I'm a beginner into ABAP, could you help me ?

BR

Philippe