SAP BPS 变量出口

       用户需要用到rolling forcast ,所以 不得不定义一个变量是User Exit ,因为用户输入的是一个预算编制月份,而我们要的是预算月份。
 
      先上一个Sample:(SE80->函数组->UPFX)
 
SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style. italic; color: #808080; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } FUNCTION upf_variable_user_exit_char.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(I_AREA) TYPE  UPC_Y_AREA
*"     VALUE(I_VARIABLE) TYPE  UPC_Y_VARIABLE
*"     VALUE(I_CHANM) TYPE  UPC_Y_CHANM OPTIONAL
*"     VALUE(ITO_CHANM) TYPE  UPC_YTO_CHA
*"  EXPORTING
*"     REFERENCE(ETO_CHARSEL) TYPE  UPC_YTO_CHARSEL
*"  EXCEPTIONS
*"      FAILED
*"----------------------------------------------------------------------

* this example shows how the function module for variables of
* type User-Exit should look like
* this example shows variable of type CHAR - characteristic values

* input parameters:
* i_area     : Planning area, in which the variable is defined.
* i_variable : The name of the variable.
* i_chanm    : From the release 3.0B variables have been enhanced
*              and can contain more than one characteristic (in release
*              3.0A they could contain only one char.).
*              To keep all already written user-exits properly running,
*              in the case that variable contains only one char. the
*              parameter i_chanm is filled with that characteristic.
* ito_chanm  : The table of characteristics, for that variable is
*              defined. It's always filled regardless of number of
*              characteristics.

* export parameters :
* eto_charsel : selection table for the variable in the form of
*               structure upc_ys_charsel

* exceptions:
* when it's necessary to raise an exception within exit function module,
* it's possible by the statement message ... raising
* name_of_the_exception. Every exception can be used and the error will
* be handled

* -------------------------------------------------------------------
* fill export table eto_charsel of structure UPC_YS_CHARSEL
*   fields: CHANM -  Characteristic
*           SEQNO -  Sequence Number
*           SIGN  -  +/- Sign of Selection Criterion
*           OPT   -  Selection Condition (EQ, BT, ...)
*           LOW   -  Lower Limit of the Selection Conditions
*           HIGH  -  Upper Limit of Selection Conditions
* --------------------------------------------------------------------

* clear export table
   CLEAR eto_charsel.

*----------------------------------------------------------------------
* Example: This example is based on the infoobject 0D_COUNTRY of the
*          SAP DEMO Cubes. The export table is filled with the selection
*          'DE' (Germany) to GB (Great Britain).
*----------------------------------------------------------------------

   DATA l_eto_charsel_wa  TYPE upc_ys_charsel.

* fill selection table with 'DE' BT (between) 'GB'
  l_eto_charsel_wa-chanm = i_chanm.
  l_eto_charsel_wa-seqno =  '0001'.
  l_eto_charsel_wa-sign  =  'I'.
  l_eto_charsel_wa-opt   =  'BT'.
  l_eto_charsel_wa-low   =  'DE'.
  l_eto_charsel_wa-high  =  'GB'.
   INSERT l_eto_charsel_wa  INTO  TABLE eto_charsel.

* check correct infoobject
   IF i_chanm  IS  INITIAL  OR i_chanm  NE  '0D_COUNTRY'.
* Fehler in User-Exit für Variablen aufgetreten
* Add your own error message here
     Message e538(upc)  raising FAILED.
  ENDIF.

ENDFUNCTION.
 
这个函数比较简单,直接赋值。
 
那我们的实际情况是需要先获取另外一个变量的值,这里需要使用另外一个函数去获取变量值
获取系统已有变量值:
 
SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style. italic; color: #808080; } .L0S32 { color: #3399FF; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } FUNCTION z_variable_get_detail.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(I_AREA) TYPE  UPC_VAR-AREA
*"     REFERENCE(I_VARIABLE) TYPE  UPC_VAR-VAR
*"     VALUE(I_BUFFER) TYPE  BOOLE-BOOLE
*"  EXPORTING
*"     VALUE(E_SUBRC) TYPE  SY-SUBRC
*"     VALUE(ES_RETURN) TYPE  BAPIRET2
*"     VALUE(E_TYPE) TYPE  UPC_VAR-VARTYPE
*"     REFERENCE(ETO_VARSEL_ALL) TYPE  UPC_YTO_CHARSEL
*"     REFERENCE(ETO_VARSEL) TYPE  UPC_YTO_CHARSEL
*"     REFERENCE(ETO_CHANM) TYPE  UPC_YTO_CHA
*"----------------------------------------------------------------------

  TYPES:
  BEGIN OF ys_buffer,
  area TYPE upc_var-area,
  variable TYPE upc_var-var,
  subrc LIKE sy-subrc,
  s_return LIKE bapiret2,
  type LIKE upc_var-vartype,
  to_varsel_all TYPE upc_yto_charsel,
  to_varsel TYPE upc_yto_charsel,
  to_chanm TYPE upc_yto_cha,
  END OF ys_buffer.
  STATICS:
  st_buffer TYPE SORTED TABLE OF ys_buffer
  WITH UNIQUE KEY area variable.
  DATA:
  ls_buffer TYPE ys_buffer,
  lr_variable TYPE REF TO cl_sem_variable.
* Check buffer
  READ TABLE st_buffer INTO ls_buffer WITH TABLE KEY
  area = i_area
  variable = i_variable.
* Found :-)
  IF sy-subrc = AND i_buffer = 'X'.
    e_subrc = ls_buffer-subrc.
    es_return = ls_buffer-s_return.
    e_type = ls_buffer-type.
    eto_varsel_all = ls_buffer-to_varsel_all.
    eto_varsel = ls_buffer-to_varsel.
    eto_chanm = ls_buffer-to_chanm.
    EXIT.
  ENDIF.
* Not found :-(
  CLEAR: e_subrc, es_return, e_type, eto_chanm, eto_varsel_all, eto_varsel.
  CALL METHOD cl_sem_variable=>get_instance
    EXPORTING
      i_area       = i_area
      i_variable   = i_variable
    RECEIVING
      rr_variable  = lr_variable
    EXCEPTIONS
      not_existing = 1
      OTHERS       2.
  IF sy-subrc <> 0.
    e_subrc = 4.
    CALL FUNCTION 'BALW_BAPIRETURN_GET2'
      EXPORTING
        type   = sy-msgty
        cl     = sy-msgid
        number = sy-msgno
        par1   = sy-msgv1
        par2   = sy-msgv2
        par3   = sy-msgv3
        par4   = sy-msgv4
      IMPORTING
        return = es_return.
    EXIT.
  ENDIF.
* read details of variable
  CALL METHOD lr_variable->get_attributes
    IMPORTING
      e_type    = e_type
      eto_chanm = eto_chanm.
* read restricted values
  CALL METHOD lr_variable->get_value
    EXPORTING
      i_user     = sy-uname
      i_restrict = 'X'
    RECEIVING
      rto_value  = eto_varsel
    EXCEPTIONS
      error      = 1
      OTHERS     2.
  IF sy-subrc <> 0.
    e_subrc = 4.
    CALL FUNCTION 'BALW_BAPIRETURN_GET2'
      EXPORTING
        type   = sy-msgty
        cl     = sy-msgid
        number = sy-msgno
        par1   = sy-msgv1
        par2   = sy-msgv2
        par3   = sy-msgv3
        par4   = sy-msgv4
      IMPORTING
        return = es_return.
    EXIT.
  ENDIF.
* read all values
  CALL METHOD lr_variable->get_value
    EXPORTING
      i_user     = sy-uname
      i_restrict = ' '
    RECEIVING
      rto_value  = eto_varsel_all
    EXCEPTIONS
      error      = 1
      OTHERS     2.
  IF sy-subrc <> 0.
    e_subrc = 4.
    CALL FUNCTION 'BALW_BAPIRETURN_GET2'
      EXPORTING
        type   = sy-msgty
        cl     = sy-msgid
        number = sy-msgno
        par1   = sy-msgv1
        par2   = sy-msgv2
        par3   = sy-msgv3
        par4   = sy-msgv4
      IMPORTING
        return = es_return.
    EXIT.
  ENDIF.
* -- no error occured => store results to buffer
  IF i_buffer = 'X'.
    CLEAR ls_buffer.
    ls_buffer-area = i_area.
    ls_buffer-variable = i_variable.
    ls_buffer-subrc = e_subrc.
    ls_buffer-s_return = es_return.
    ls_buffer-type = e_type.
    ls_buffer-to_varsel_all = eto_varsel_all.
    ls_buffer-to_varsel = eto_varsel.
    ls_buffer-to_chanm = eto_chanm.
    INSERT ls_buffer INTO TABLE st_buffer.
  ENDIF.

ENDFUNCTION.
 
先设置一个变量 ZMONTH1,类型为Fixed Value , 1-12 个单值。
在设计Web Interface 时,将ZMONTH1定义在第一个变量页 , 通过跳转Page进入到预算Page。
 
预算的Planning Level 使用第二个变量 ZMONTH2 ,类型为UserExit , Function:Z_VARIABLE_USER_EXIT_MONTH。
 
SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style. italic; color: #808080; } .L0S32 { color: #3399FF; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } FUNCTION z_variable_user_exit_month.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(I_AREA) TYPE  UPC_Y_AREA
*"     VALUE(I_VARIABLE) TYPE  UPC_Y_VARIABLE
*"     VALUE(I_CHANM) TYPE  UPC_Y_CHANM OPTIONAL
*"     VALUE(ITO_CHANM) TYPE  UPC_YTO_CHA
*"  EXPORTING
*"     REFERENCE(ETO_CHARSEL) TYPE  UPC_YTO_CHARSEL
*"  EXCEPTIONS
*"      FAILED
*"----------------------------------------------------------------------
* clear export table
   CLEAR eto_charsel.

*----------------------------------------------------------------------
* Example: This example is based on the infoobject 0D_COUNTRY of the
*          SAP DEMO Cubes. The export table is filled with the selection
*          'DE' (Germany) to GB (Great Britain).
*----------------------------------------------------------------------

   DATA l_eto_charsel_wa  TYPE upc_ys_charsel.

  DATA: l_month(2).
*
  DATA:
  l_source_var  TYPE upc_y_variable  VALUE  'ZMONTH1',
  l_source_area  TYPE upc_y_area  VALUE  'ZSDPLAN1',
  l_use_restricted_values  TYPE boole-boole  VALUE  'X',
  l_buffer_call  TYPE boole-boole  VALUE  'X'.
  DATA:
  l_subrc  LIKE sy-subrc,
  ls_return  LIKE bapiret2,
  l_type  LIKE upc_var-vartype,
  lto_varsel_all  TYPE upc_yto_charsel,
  lto_varsel  TYPE upc_yto_charsel,
  lto_var  TYPE upc_yto_charsel,
  lto_chanm  TYPE upc_yto_cha.
  DATA: ls_varsel  TYPE upc_ys_charsel,
  l_next_month(2)  TYPE n,
  l_entries  TYPE i.

   CASE   i_variable .
     WHEN   'ZMONTH2'.
* read source value
      l_source_var =  'ZMONTH1'.
      l_source_area = i_area .
       CALL  FUNCTION  'Z_VARIABLE_GET_DETAIL'
         EXPORTING
          i_area         = l_source_area
          i_variable     = l_source_var
          i_buffer       = l_buffer_call
         IMPORTING
          e_subrc        = l_subrc
          es_return      = ls_return
          e_type         = l_type
          eto_varsel_all = lto_varsel_all
          eto_varsel     = lto_varsel
          eto_chanm      = lto_chanm.
       IF l_subrc <>  0.
         MESSAGE i136(upc_fw)  WITH l_source_var.
* Values of variable &1 cannot be determined
        EXIT.
      ENDIF.



* We have a single value for the year and only one characteristic
* => our value is stored in the first line
       IF l_use_restricted_values  IS INITIAL.
        lto_var = lto_varsel_all.
      ELSE.
        lto_var = lto_varsel.
      ENDIF.
       READ  TABLE lto_var  INTO ls_varsel  INDEX  1.
* check prerequisites:
* - record found?
       IF sy-subrc <>  0.
         MESSAGE i147(upc_fw)  WITH l_source_var.
* Variable &1 does not contain any values
        EXIT.
      ENDIF.
* - exactly one record and characteristic?
       DESCRIBE  TABLE lto_var  LINES l_entries.
       IF l_entries <>  1.
         MESSAGE i534(upc)  WITH l_source_var.
* Variable &1 must be restricted to a value
        EXIT.
      ENDIF.
* is there a next year?
      l_next_month = ls_varsel-low.

       IF l_next_month 12 .
        l_next_month = l_next_month +  1.
        CLEAR:l_eto_charsel_wa.
        l_eto_charsel_wa-chanm = i_chanm.
        l_eto_charsel_wa-seqno =  '0001'.
        l_eto_charsel_wa-sign  =  'I'.
        l_eto_charsel_wa-opt   =  'EQ'.
         IF l_next_month 10.
           CONCATENATE  '0' l_next_month   INTO l_eto_charsel_wa-low .
        ELSE.
          l_eto_charsel_wa-low = l_next_month.
        ENDIF.
         INSERT l_eto_charsel_wa  INTO  TABLE eto_charsel.
      ENDIF.

       IF l_next_month 12 .
        l_next_month = l_next_month +  1.
        l_eto_charsel_wa-seqno =  '0002'.
         IF l_next_month 10.
           CONCATENATE  '0' l_next_month   INTO l_eto_charsel_wa-low .
        ELSE.
          l_eto_charsel_wa-low = l_next_month .
        ENDIF.
         INSERT l_eto_charsel_wa  INTO  TABLE eto_charsel.
      ENDIF.

       IF l_next_month 12 .
        l_next_month = l_next_month +  1.
        l_eto_charsel_wa-seqno =  '0003'.

         IF l_next_month 10.
           CONCATENATE  '0' l_next_month   INTO l_eto_charsel_wa-low .
        ELSE.
          l_eto_charsel_wa-low = l_next_month .
        ENDIF.

         INSERT l_eto_charsel_wa  INTO  TABLE eto_charsel.
      ENDIF.

** check correct infoobject
       IF i_chanm  IS  INITIAL  OR i_chanm  NE  '0CALMONTH2'.
* Fehler in User-Exit für Variablen aufgetreten
* Add your own error message here
         MESSAGE e538(upc)  RAISING failed.
      ENDIF.

  ENDCASE.


ENDFUNCTION.
 
 
通过以上的样例可以实现获取后三个月的值。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/554557/viewspace-693849/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/554557/viewspace-693849/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值