21.2.11

SAP Note 22878 - RepWriter: Formula variables for non-numeric fields

Symptom:

You cannot maintain formula variables for non-numeric fields.

Cause and prerequisites

Such maintenance is not defined in the formula interpreter.

Solution
As of Release 4.5A, formula variables can also be created for non-numeric fields if the result of the formula is numeric (e.g. for the characteristics value type or record type). In addition, up to 5 variables can be transferred as parameters to user exits.
For non-numeric fields, formula variables can only be defined via user exits in releases prior to 4.5A. In this case, the corresponding source code must be filed in an ABAP FORM pool and the name of this FORM pool must be entered in Table T80I (Release 3.0C or later) or T80U (up to and including Release 3.0B) (replace template RGSVU000).
SAP delivers FORM pool RGSVU000 which you can copy to define your own user exits.
Since there is no possible reference to other variables in Standard, the user must carry out the modification described below.
If you want to use further variables known at the runtime in the user exit, you have to define an internal table with the following structure within the program code:
begin of var_memory_tab occurs 10,
var like t802g-global,
val(24),
end of var_memory_tab.

The internal table var_memory_tab can then be filled with the ABAP/4 statement
import var_memory_tab from memory id 'G_VARIABLE_VALUES_MEMORY'

from the global memory (field var = variable, field val = value of the variable).
To write the corresponding data to global memory under id
G_VARIABLE_VALUES_MEMORY, the following lines (marked with an arrow) must be inserted in Include FGSB0F02:
*eject
*---------------------------------------------------------------------*
* internal functions for variables and formulas *
*---------------------------------------------------------------------*
* eject
*---------------------------------------------------------------------*
* SUBROUTINE UPDATE-GLOBALS *
*---------------------------------------------------------------------*
* replaces globals in table TVAL by default-values *
* or by calculated values from formulas *
*---------------------------------------------------------------------*
* *
* Parameter: *
* --> UGTABLE SETTABLE *
* --> UGSETNR SETNAME : If Setname eq space -> all sets are *
* considered *
* --> UG_NO_RESTORE : FLAG: X = No restore *
* Y = No formula consideration *
* SPACE = Restore by Import *
* --> U_MODIFY_PARAMETER Flag for SET PARAMETER command *
* 'X' Modify SPA/GPA parameter (if there is one) *
* SPACE Do not modify SPA/GPA parameter *
*---------------------------------------------------------------------*
* *
* if UG_NO_RESTORE <> 'Y' the global return-codes are set *
* as follows: *
* *
* C-SUBRC contains error code of formula evaluation *
* 0: evaluation o.k. *
* 4: result of eval-result to long for field *
* 8: conversion of eval-result failed *
* 12: evaluation of formula failed (see EVALFAIL-SUBRC)*
* (see EVALFAIL-SUBRC and EVALFAIL-FORMULA) *
* EVALFAIL-SUBRC contains error code of formula evaluation *
* (from 'EVAL_FORMULA') *
* 8: result overflow *
* 11: DIVISION_BY_ZERO *
* 12: EXP_ERROR *
* 13: INVALID_EXPRESSION *
* 14: INVALID_VALUE *
* 15: LOG_ERROR *
* 16: PATRAMETER_ERROR *
* 17: SQRT_ERROR *
* 99: OTHERS *
* *
* EVALFAIL-FORMULA formula which has the errors *
* *
*---------------------------------------------------------------------*
form update-globals using value(ugtable)
value(ugsetnr)
value(ug_no_restore)
value(u_modify_parameter).

data: eval_failed like sy-subrc.

-> *Insert to export all Value-Variables into memory for exits JK
-> data: begin of var_memory_tab occurs 10,
-> var like t802g-global,
-> val like tvar-from,
-> end of var_memory_tab.
-> * End of insert to export Value-Variables JK


clear: c-subrc, evalfail-subrc, evalfail-formula.
if c-read-only-tmsb = 'Y' and
c-maintenance = space.
-> * Insert to export all Value-Variables into memory for exits JK
-> refresh var_memory_tab.
-> clear: var_memory_tab, tvar.

-> loop at tvar.
-> if tvar-tvar = tvar-fvar. " From = To -> Problem with formula
-> if tvar-fvar_fkt_line = 0. " Make sure there is only the
-> clear tvar-fvar. " Formula Variable with the
-> else. " Pointer to the formula tree
-> clear tvar-tvar.
-> endif.
-> endif.
-> * TVAR-To = Variable
-> if tvar-tvar(1) = var_beg.
-> if tvar-tvar_fkt_line = 0. " Value variable
-> var_memory_tab-var = tvar-tvar.
-> var_memory_tab-val = tvar-to.
-> read table var_memory_tab
-> with key var_memory_tab binary search.
-> if sy-subrc <> 0. " only new variables
-> insert var_memory_tab index sy-tabix.
-> endif.
-> else. " Formula variable, get Tree
-> loop at tvar_formula_tree
-> where init_var_l = tvar-tvar_fkt_line
-> *! and x_fkt = space. "<<<< V.12
-> and ( x_fkt = space or int_var = space ). "<<<< V.12
-> var_memory_tab-var = tvar_formula_tree-variable.
-> var_memory_tab-val = tvar_formula_tree-value.
-> read table var_memory_tab
-> with key var_memory_tab binary search.
-> if sy-subrc <> 0. " only insert new variables
-> insert var_memory_tab index sy-tabix.
-> endif.
-> endloop.
-> endif. " TVAR-TVAR_FKT_LINE = 0.
-> endif. " TVAR-TVAR(1) = VAR_BEG
-> * TVAR-From = Variable
-> if tvar-fvar(1) = var_beg.
-> if tvar-fvar_fkt_line = 0. " Value variable
-> var_memory_tab-var = tvar-fvar.
-> var_memory_tab-val = tvar-from.
-> read table var_memory_tab
-> with key var_memory_tab binary search.
-> if sy-subrc <> 0. " only new variables
-> insert var_memory_tab index sy-tabix.
-> endif.
-> else. " Formula variable, get Tree
-> loop at tvar_formula_tree
-> where init_var_l = tvar-fvar_fkt_line
-> *! and x_fkt = space. "<<<< V.12
-> and ( x_fkt = space or int_var = space ). "<<<< V.12
-> var_memory_tab-var = tvar_formula_tree-variable.
-> var_memory_tab-val = tvar_formula_tree-value.
-> read table var_memory_tab
-> with key var_memory_tab binary search.
-> if sy-subrc <> 0. " only insert new variables
-> insert var_memory_tab index sy-tabix.
-> endif.
-> endloop.
-> endif. " TVAR-FVAR_FKT_LINE = 0.
-> endif. " TVAR-FVAR(1) = VAR_BEG
-> endloop.

-> export var_memory_tab to memory id 'G_VARIABLE_VALUES_MEMORY'.
-> * End of insert to export

clear tvar.
loop at tvar.
if ugsetnr <> space.
.
.
.
.
.
.
else.

message e274 with tvar-table tvar-setnr tvar-from tvar-to.
perform restore-ptt.

endif.

endloop.

-> *Insert to export all Value-Variables to memory
-> CLEAR VAR_MEMORY_TAB.
-> REFRESH VAR_MEMORY_TAB.
-> EXPORT VAR_MEMORY_TAB TO MEMORY ID 'G_VARIABLE_VALUES_MEMORY'.
-> *End of insert to export Value-Variables

endif.

endform.

The user must make sure that the Exit always return a meaningful value; especially when the internal table VAR_MEMORY_TAB contains no entries.
The example below shows a user exit, which sets the plan version to the value of '000' when the period given in the report's selection screen (Variable &1PERIB) is greater than 6. Otherwise, the value given in the selection screen (Variable &1VERP) is used. The entry for table T80U is as follows:

Working- | Client- | Exit Form pool
area | dependent |
| |
GSV0 | | ZGSVU000

*---------------------------------------------------------------------*
* *
* SETS: EXIT-Formpool for customer defined exits *
* *
*---------------------------------------------------------------------*
* *
* How to create an exit for a formula variable: *
* 1) Define subroutine Unnn according to example below *
* (nnn = 3-digit-number 001 .. 999) *
* you can copy and modify sample exit U999 *
* 2) Modify subroutine GET_EXIT_TITLES to include the *
* new exit to the list of available exits *
* - This step is optional: if not done, exit can be *
* used but will not be listed *
* *
* To use exit value in formula variable, enter: '#Unnn' *
* *
* For more examples see program RGSVS000 (standard exits) *
* *
*---------------------------------------------------------------------*
program zgsvu000.

data: begin of exit_type,
numeric(1) type c value 'N', "variable has only numeric values
alpha(1) type c value 'A', "variable has alphanumeric values
end of exit_type.

*----------------------------------------------------------------------*
* FORM GET_EXIT_TITLES
*----------------------------------------------------------------------*
* returns name and title of all available standard exits
* every exit in this formpool has to be added to this form
*----------------------------------------------------------------------*
* --> EXIT_TAB table with exit-name and exit-titles
* (structure: NAME(4), TITLE(60), TYPE(1))
*----------------------------------------------------------------------*
form get_exit_titles tables etab.

data: begin of exits occurs 50,
name(4) type c,
title(60) type c,
type(1) type c,
end of exits.

* enter exit U001 for list of exits
exits-name = 'U001'. "name of exit
exits-title = text-001. "description of exit
exits-type = exit_type-alpha. "data type of exit value
append exits. "append to local list

* append local list to global list
refresh etab.
loop at exits.
etab = exits.
append etab.
endloop.

endform.


*eject
*----------------------------------------------------------------------*
* FORM U001
*----------------------------------------------------------------------*
* example of an exit for formula variables
*----------------------------------------------------------------------*
* <-- EXIT_VALUE evaluated value of exit
* <-- EXIT_TYP type of EXIT_VALUE ('N' or 'A')
* <-- SUBRC has to be set to '0'
*----------------------------------------------------------------------*
form u001 changing u_exit_value u_exit_type u_subrc.

* Insert to export all Value-Variables into memory for exits JK
data: begin of var_memory_tab occurs 10, "JK
var like t802g-global, "JK
val(24), "JK
end of var_memory_tab. "JK
* End of insert to export Value-Variables

u_subrc = 0. "return code has to be set to '0'
u_exit_type = exit_type-alpha. "assign proper data type

import var_memory_tab from memory id 'G_VARIABLE_VALUES_MEMORY'.

loop at var_memory_tab where var = '&1PERIB'.
exit.
endloop.

if sy-subrc <> 0 or var_memory_tab-val > 6.
u_exit_value = '000'.
else.
loop at var_memory_tab where var = '&1VERP '.
exit.
endloop.
if sy-subrc <> 0.
u_exit_value = '000'.
else.
u_exit_value = var_memory_tab-val.
endif.
endif.

endform.

Additional key words

Reportwriter, formula variable, formula exit ----- SUPPORTGUIDE 20010208103353 -----
REPORTWRITER, SGRW_VARIABLE, SGRW_EXTENSION, SGRW_DOCU_CONS_NOTE
SGRW_OM SGRW_PS SGRW_PC SGRW_SL SGRW_PCA SGRW_EC SGRW_LIS

No comments:

Post a Comment