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

Update TVARV variables...

Former Member
0 Likes
1,261

Hello all,

I would greatly appreciate it if someone could send me a sample program to update table TVARV with a variable for 'From' and 'To' date and time. I have already declared 4 parameters in TVARV.

i.e. User will enter 'From' and 'To' dates and time in parameters and TVARV table will be updated, and when report is run next time, the 'To' date/time will become 'From' date/time. In other words, it will take the latest value of the variables.

Regards,

Eddie.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
938

We actually use a BDC do update the table using SM31. I have it encapsulated in a subroutine(form) .

Send the variable name, the variable type(P or S) and the low and high. The BDC code will take care of the rest. It will handle Parameters and Select-options.




************************************************************************
*      Form REUSE_BDC_SESSION
************************************************************************
form reuse_bdc_session using var_name
                             var_type
                             variable
                             variable_low
                             variable_high.

  perform bdc_dynpro      using 'SAPMSVMA' '0100'.
  perform bdc_field       using 'BDC_CURSOR'
                                'VIEWNAME'.
  perform bdc_field       using 'BDC_OKCODE'
                                '=UPD'.
  perform bdc_field       using 'VIEWNAME'
                            'TVARV'.
  perform bdc_field       using 'VIMDYNFLDS-LTD_DTA_NO'
                                'X'.
  perform bdc_dynpro      using 'SAPMS38V' '1100'.
  perform bdc_field       using 'BDC_CURSOR'
                                '%#AUTOTEXT001'.
  perform bdc_field       using 'BDC_OKCODE'
                                '=TOGGLE'.
  perform bdc_dynpro      using 'SAPMS38V' '1100'.
  perform bdc_field       using 'BDC_CURSOR'
                                '%#AUTOTEXT001'.
  perform bdc_field       using 'BDC_OKCODE'
                                '=SINGLE'.
  perform bdc_dynpro      using 'SAPMS38V' '1001'.
  perform bdc_field       using 'BDC_CURSOR'
                                'TVARV-NAME'.
  perform bdc_field       using 'BDC_OKCODE'
                                '=CHNG'.
  perform bdc_field       using 'TVARV-NAME'
                            var_name.
  if var_type = 'P'.
    perform bdc_field       using 'RB_TYPE_P'
                                  'X '.
    perform bdc_field       using 'RB_TYPE_S'
                                      ' '.
    perform bdc_dynpro      using 'SAPMS38V' '0600'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'PAR_VAL'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=USAV'.
    perform bdc_field       using 'PAR_VAL'
                                variable.
  endif.

  if var_type = 'S'.
    perform bdc_field       using 'RB_TYPE_P'
                                  ' '.
    perform bdc_field       using 'RB_TYPE_S'
                                  'X'.
    perform bdc_dynpro      using 'SAPMS38V' '0600'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'SEL_VAL-LOW'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=%015'.
    perform bdc_dynpro      using 'SAPLALDB' '3000'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=INTL'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'RSCSEL-SLOW_I(01)'.
    perform bdc_dynpro      using 'SAPLALDB' '3000'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=ACPT'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'RSCSEL-IHIGH_I(01)'.
    perform bdc_field       using 'RSCSEL-ILOW_I(01)'
                              variable_low.
    perform bdc_field       using 'RSCSEL-IHIGH_I(01)'
                             variable_high.
    perform bdc_dynpro      using 'SAPMS38V' '0600'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'SEL_VAL-LOW'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=USAV'.
  endif.

  perform bdc_dynpro      using 'SAPMS38V' '1001'.
  perform bdc_field       using 'BDC_CURSOR'
                                'TVARV-NAME'.
  perform bdc_field       using 'BDC_OKCODE'
                                '=RETN'.
  perform bdc_dynpro      using 'SAPMS38V' '1100'.
  perform bdc_field       using 'BDC_CURSOR'
                                '%#AUTOTEXT001'.
  perform bdc_field       using 'BDC_OKCODE'
                                '=SAVE'.
  perform bdc_dynpro      using 'SAPMS38V' '1100'.
  perform bdc_field       using 'BDC_CURSOR'
                                '%#AUTOTEXT001'.
  perform bdc_field       using 'BDC_OKCODE'
                                '=RETN'.
  perform bdc_dynpro      using 'SAPMSVMA' '0100'.
  perform bdc_field       using 'BDC_OKCODE'
                                '/EBACK'.
  perform bdc_field       using 'BDC_CURSOR'
                                'VIEWNAME'.

  call transaction 'SM31' using  bdcdata
                          mode   mode
                          update 'S'.

  if sy-subrc = 0.
    write:/ i_tvarv-name, at 40 'Variable updated successfully'.
    case var_type.
      when 'P'.
        write:80 variable.
      when 'S'.
        write:80 variable_low, at 100 variable_high.
    endcase.

  else.
    write:/ i_tvarv-name, at 40 'Error occured during update process'.
  endif.

  commit work and wait.
  clear bdcdata. refresh bdcdata.

endform.

Regards,

Rich Heilman

Message was edited by: Rich Heilman

Hello all,

I would greatly appreciate it if someone could send me a sample program to update table TVARV with a variable for 'From' and 'To' date and time. I have already declared 4 parameters in TVARV.

i.e. User will enter 'From' and 'To' dates and time in parameters and TVARV table will be updated, and when report is run next time, the 'To' date/time will become 'From' date/time. In other words, it will take the latest value of the variables.

Regards,

Eddie.

4 REPLIES 4
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
939

We actually use a BDC do update the table using SM31. I have it encapsulated in a subroutine(form) .

Send the variable name, the variable type(P or S) and the low and high. The BDC code will take care of the rest. It will handle Parameters and Select-options.




************************************************************************
*      Form REUSE_BDC_SESSION
************************************************************************
form reuse_bdc_session using var_name
                             var_type
                             variable
                             variable_low
                             variable_high.

  perform bdc_dynpro      using 'SAPMSVMA' '0100'.
  perform bdc_field       using 'BDC_CURSOR'
                                'VIEWNAME'.
  perform bdc_field       using 'BDC_OKCODE'
                                '=UPD'.
  perform bdc_field       using 'VIEWNAME'
                            'TVARV'.
  perform bdc_field       using 'VIMDYNFLDS-LTD_DTA_NO'
                                'X'.
  perform bdc_dynpro      using 'SAPMS38V' '1100'.
  perform bdc_field       using 'BDC_CURSOR'
                                '%#AUTOTEXT001'.
  perform bdc_field       using 'BDC_OKCODE'
                                '=TOGGLE'.
  perform bdc_dynpro      using 'SAPMS38V' '1100'.
  perform bdc_field       using 'BDC_CURSOR'
                                '%#AUTOTEXT001'.
  perform bdc_field       using 'BDC_OKCODE'
                                '=SINGLE'.
  perform bdc_dynpro      using 'SAPMS38V' '1001'.
  perform bdc_field       using 'BDC_CURSOR'
                                'TVARV-NAME'.
  perform bdc_field       using 'BDC_OKCODE'
                                '=CHNG'.
  perform bdc_field       using 'TVARV-NAME'
                            var_name.
  if var_type = 'P'.
    perform bdc_field       using 'RB_TYPE_P'
                                  'X '.
    perform bdc_field       using 'RB_TYPE_S'
                                      ' '.
    perform bdc_dynpro      using 'SAPMS38V' '0600'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'PAR_VAL'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=USAV'.
    perform bdc_field       using 'PAR_VAL'
                                variable.
  endif.

  if var_type = 'S'.
    perform bdc_field       using 'RB_TYPE_P'
                                  ' '.
    perform bdc_field       using 'RB_TYPE_S'
                                  'X'.
    perform bdc_dynpro      using 'SAPMS38V' '0600'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'SEL_VAL-LOW'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=%015'.
    perform bdc_dynpro      using 'SAPLALDB' '3000'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=INTL'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'RSCSEL-SLOW_I(01)'.
    perform bdc_dynpro      using 'SAPLALDB' '3000'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=ACPT'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'RSCSEL-IHIGH_I(01)'.
    perform bdc_field       using 'RSCSEL-ILOW_I(01)'
                              variable_low.
    perform bdc_field       using 'RSCSEL-IHIGH_I(01)'
                             variable_high.
    perform bdc_dynpro      using 'SAPMS38V' '0600'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'SEL_VAL-LOW'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=USAV'.
  endif.

  perform bdc_dynpro      using 'SAPMS38V' '1001'.
  perform bdc_field       using 'BDC_CURSOR'
                                'TVARV-NAME'.
  perform bdc_field       using 'BDC_OKCODE'
                                '=RETN'.
  perform bdc_dynpro      using 'SAPMS38V' '1100'.
  perform bdc_field       using 'BDC_CURSOR'
                                '%#AUTOTEXT001'.
  perform bdc_field       using 'BDC_OKCODE'
                                '=SAVE'.
  perform bdc_dynpro      using 'SAPMS38V' '1100'.
  perform bdc_field       using 'BDC_CURSOR'
                                '%#AUTOTEXT001'.
  perform bdc_field       using 'BDC_OKCODE'
                                '=RETN'.
  perform bdc_dynpro      using 'SAPMSVMA' '0100'.
  perform bdc_field       using 'BDC_OKCODE'
                                '/EBACK'.
  perform bdc_field       using 'BDC_CURSOR'
                                'VIEWNAME'.

  call transaction 'SM31' using  bdcdata
                          mode   mode
                          update 'S'.

  if sy-subrc = 0.
    write:/ i_tvarv-name, at 40 'Variable updated successfully'.
    case var_type.
      when 'P'.
        write:80 variable.
      when 'S'.
        write:80 variable_low, at 100 variable_high.
    endcase.

  else.
    write:/ i_tvarv-name, at 40 'Error occured during update process'.
  endif.

  commit work and wait.
  clear bdcdata. refresh bdcdata.

endform.

Regards,

Rich Heilman

Message was edited by: Rich Heilman

Read only

0 Likes
938

Hi Rich,

Thanx for the bdc code.

I was thinking, is there a way to update it through 'select' statements. I have something like this:

parameters: p_matl like mara-mtart,

beg_date like sy-datum,

end_date like sy-datum,

beg_time like sy-uzeit,

end_time like sy-uzeit.

data: pt_cdhdr TYPE cdhdr_tab.

start-of-selection.

SELECT * FROM cdhdr APPENDING TABLE pt_cdhdr

WHERE objectclas = 'material'

AND username = sy-uname

AND (

(

udate = beg_date

AND

utime >= beg_time

)

OR

udate > beg_date

)

AND (

(

udate = end_date

AND

utime <= end_time

)

OR

udate < end_date

).

I have already declared parameters for begin/end dates and times.

Regards,

Eddie.

Read only

0 Likes
938

<i>

I was thinking, is there a way to update it through 'select' statements.

</i>

Not sure what you mean here. I guess you can do a direct database update using MODIFY or UPDATE statements, but direct db updates are frowned apond, hence the reason for the BDC code. But I guess if you are allowed to do it via SM31, then why not directly update it, right?

You can update the table using MODIFY or UPDATE like normal.

http://help.sap.com/saphelp_46c/helpdata/en/fc/eb3a94358411d1829f0000e829fbfe/frameset.htm

http://help.sap.com/saphelp_46c/helpdata/en/fc/eb3ac8358411d1829f0000e829fbfe/frameset.htm

REgards,

Rich Heilman

Read only

0 Likes
938

Hi Eddie,

Pl check the following code & use whta is relevant for you..


*Lock TVARV rcord with ESVARV.
  CALL FUNCTION 'ENQUEUE_ESVARV'
       EXPORTING
            MODE_TVARV     = 'E'
            NAME           = VAR_NAME "name
            TYPE           = VAR_TYPE  " 'S' or 'P'
            _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 TVARV WHERE NAME = VAR_NAME AND
                                   TYPE = VAR_TYPE .
  IF SY-SUBRC <> 0.
    FL_NO_RECORD_TVARV = 'X'.                             
*   RAISE RECORD_NOT_FOUND.               
  ENDIF.

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

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

  TVARV-LOW = LOW_VALUE.

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

* Update TVARV
  IF FL_NO_RECORD_TVARV = SPACE.               
     update TVARV.
     IF SY-SUBRC <> 0.
      RAISE UPDATE_FAILED.
    ENDIF.
  ENDIF.                                       
*Unlock TVARV rcord with ESVARV.
  CALL FUNCTION 'DEQUEUE_ESVARV'
       EXPORTING
            MODE_TVARV = 'E'
            NAME       = VAR_NAME
            TYPE       = VAR_TYPE
            _SCOPE     = '3'
            _SYNCHRON  = ' '.

Regards,

Suresh Datti