SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Использование FORMULA_BUILDER для вычисления формул



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sun Dec 23, 2007 8:04 pm    Post subject: Использование FORMULA_BUILDER для вычисления формул Reply with quote

Use
You can use the Formula Builder to implement methods for Business Add-Ins without writing a single line of ABAP code. The methods are implemented by means of socalled formulas.

This type of implementation does not require you to have programming knowledge. However, the functions it offers are more restricted than if you implement a method by writing ABAP code. If the range of functions provided by the Formula Builder is not sufficient, you can change the implementation type of the method at any time.

Features
A formula can consist of the following steps:

Condition
You define a Boolean formula expression whose result can be true or false. This formula expression is a logical condition based on the importing and changing parameters of the method. Depending on whether the condition is true or false, the system triggers different steps. If you do not specify a dependent step for one of these two possibilities, the system continues with the next superior step.

Substitution
The system replaces the value of a specific parameter with another value which you define as a constant value or by means of a mathematic formula. Substitution is only possible if the method contains changing, exporting or returning parameters.

Message
The system issues a message. All messages issued are collected in a log table. You define the message variables as constant values or by means of mathematic formulas. The system can only issue a message if you created a log table during method definition.

Exception
The system exits the method. No further steps are executed, and the application program continues in accordance with the exception defined. You can additionally display a message whose variables you define as constant values or by means of mathematic formulas. An exception can only be triggered if the method contains exceptions.

A formula editor is available which you can use to enter formula expressions. After starting the formula editor, you can display information on how to use it by choosing the pushbutton next to the status display (traffic light).

Activities
You implement the method using the BAdI Builder. For information on this topic, see Implementing Business Add-Ins. To implement a method as a formula, choose the Formula implementation type on the Interface tab. Double-clicking the method name takes to to the Formula Builder: BadI Implementation screen.

You can change the implementation type of the method on the Interface tab. You can implement a method both using a formula and using ABAP code. At the runtime of the application program, the system executes the implementation type currently chosen.

You create the necessary steps in the left section of the screen. To do this, choose and then select the appropriate step type from the dropdown list. Using the other icons available or the context menu (which you can call by clicking the right mouse button), you then determine the arrangement and the descriptions of the steps. You can also copy steps to use them as templates for other steps, or you can delete individual steps.

To specify the parameters for the individual steps, double-click the corresponding entry in the left section of the screen. You then enter the data required in the right section of the screen.

The formula builder has two modes: Standard and expert mode. In the standard mode, you can only enter the formulas using the pushbuttons and by double clicking on functions and fields. In the expert mode, however, you can enter formulas directly. You can also toggle between the tow modes when entering a formula.

The company code field (0COMP_CODE) is not included in your data target or InfoSource. However you can determine the company code from the first four character spaces of the cost center (0COSTCENTER).

You create the following formula for this purpose:
SUBSTRING( cost center, '0' , '4')

Syntax:
SUBSTRING( String, Offset , Länge )

Step-by-Step Procedure in Standard mode:
In the transformation library, on the right hand side under Show Me, choose the category Strings. From the list, select the Substring function by double-clicking on it. The syntax of the formula is displayed in the formula window: SUBSTRING( , , )
The cursor automatically appears over the first parameter that needs to be specified.

From the list on the left-hand side of the screen, choose the Cost Center field by double-clicking on it.
Place the cursor where you want to enter the next parameter.
Enter the number 0 using the Constant button (for the Offset parameter). The commas are added automatically.
Place the cursor where you want to enter the next parameter.
Enter the number 4 using the Constant button (for the Length parameter).
Choose Back. The formula is now checked and saved if it is correct. You receive a message if errors occurred during the check, and the system highlights the erroneous element in color.

Code:
REPORT ztesteander.

TYPE-POOLS: gblfb.

DATA: constants TYPE gblfb_constants_struct OCCURS 1
WITH HEADER LINE.

DATA: set_operands TYPE gblfb_operands_struct OCCURS 0
WITH HEADER LINE.

DATA formula TYPE gblfb_formula WITH HEADER LINE.

DATA: operator_table TYPE gblfb_operators_table WITH HEADER LINE.

constants-text = 'Constantes'.
constants-callback = 'GET_CONSTANT'.
constants-token = 'CONST'.
constants-left_delim = ''''.
constants-right_delim = ''''.
APPEND constants.

constants-text = 'Comentário'.
constants-callback = 'GET_COMMENT'.
constants-token = '$COMMENT'.
constants-left_delim = '"'.
constants-right_delim = '"'.
APPEND constants.

CLEAR set_operands.
set_operands-key = 'TABLES'.
set_operands-text = 'Cpos.tabelas'.
set_operands-callback = 'ZANDER'. "Function ZANDER
set_operands-list_text = 'Estrutura'.
APPEND set_operands.

operator_table-token = 'PLUS'.
operator_table-text = '+'. APPEND operator_table.
operator_table-token = 'MINUS'.
operator_table-text = '-'. APPEND operator_table.
operator_table-token = 'MULTIPLY'.
operator_table-text = '*'. APPEND operator_table.
operator_table-token = 'DIVIDE'.
operator_table-text = '/'. APPEND operator_table.
operator_table-token = 'BRACKETL'.
operator_table-text = '('. APPEND operator_table.
operator_table-token = 'BRACKETR'.
operator_table-text = ')'. APPEND operator_table.

CALL FUNCTION 'FORMULA_BUILDER'
EXPORTING
iface_title = 'Teste'
read_only = ''
cb_save = 'G_FB_SAVE'
cb_validate = 'GB_VALIDATE_ELEMENT'
syntax = 'ZANDER' "Program ZANDER, ZANDERI, ZANDERC
PFSTAT = 'BASIC' "Status copy o program SAPLGBL8
PFSTAT_PROG = 'ZTESTEANDER'
TABLES
iface_constants = constants
iface_operators = operator_table
iface_operands = set_operands
iface_formula = formula
EXCEPTIONS
cancelled = 1
error_in_operands = 2
error_in_operators = 3
error_in_syntax = 4
error_in_constants = 5
OTHERS = 6.

LOOP AT formula.
WRITE: / formula.
ENDLOOP.


*---------------------------------------------------------------------------------
REPORT zander. "only for call on parameter syntax

*---------------------------------------------------------------------------------
REPORT zanderc.

INCLUDE lgbl8k02.

TYPE-POOLS gblfb.

DEFINE rule1.

perform &1 tables formula using pos length
changing pos1 coref.

check ( pos1 0 ).

if ( pos1 > 0 ).
newpos = pos1.
exit.
endif.
END-OF-DEFINITION.

begin_rules s.
rule1 valida.
end_rules.

---------------------------------------------------------------------
FORM valida *
---------------------------------------------------------------------
Valida Fórmula entrada *
---------------------------------------------------------------------
FORM valida TABLES formula TYPE gblfb_formula USING pos length
CHANGING newpos coref.

DATA:
formula_result TYPE string ,
t_var LIKE rpoc_variable OCCURS 0.

CLEAR: newpos, formula_result.

LOOP AT formula.

CONCATENATE formula_result formula-value INTO formula_result.

ENDLOOP.

CHECK sy-subrc = 0.

CALL FUNCTION 'POC_FORMULA_CHECK'
EXPORTING
formula = formula_result
TABLES
var_table = t_var
EXCEPTIONS
error_in_formula = 1
OTHERS = 2.

IF sy-subrc 0.
newpos = -1.
ENDIF.

ENDFORM.

*------------------------------------------------------------------------------
REPORT zanderi.

INCLUDE lgbl8k02.

TYPE-POOLS gblfb.

DEFINE rule1.
check ( pos1 0 ).

if ( pos1 > 0 ).
newpos = pos1.
exit.
endif.
END-OF-DEFINITION.

begin_rules s.
rule1 .
end_rules.

*--------------------------------------------------------------------------------
FUNCTION zander.
*"----------------------------------------------------------------------
""Interface local:
*" IMPORTING
*" VALUE(KEY) TYPE C
*" VALUE(CLS_ATTR) TYPE GB001_CLASS_ATTR_TYP OPTIONAL
*" TABLES
*" OPERANDS_TABLE TYPE GBLFB_OPERANDS_TABLE_INTERN
*"----------------------------------------------------------------------

DATA: BEGIN OF exits_lst OCCURS 50.
INCLUDE STRUCTURE gble.
DATA: END OF exits_lst.

DATA: l_1 TYPE i,
l_subrc LIKE syst-subrc,
dummy_exit LIKE gble-name,
poolname LIKE sy-repid,
error_desc(105) TYPE c,
l_mtab LIKE gb01-bcltab.

DATA: BEGIN OF table_lst OCCURS 0.
DATA: name LIKE gb01-bcltab.
DATA: END OF table_lst.
DATA: l_dd02v TYPE dd02v,
g_class_attr TYPE gb001_class_attr_typ.

DATA: d_int LIKE sy-tabix,
d_bool TYPE c.

DATA: b_true LIKE d_bool VALUE 'T', " true,
b_false LIKE b_true VALUE 'F'. " false

DATA:
t_z4a18 TYPE STANDARD TABLE OF z4a18 WITH DEFAULT KEY
WITH HEADER LINE.

clear operands_table. refresh operands_table.
CASE key.
WHEN 'TABLES'.

SELECT * INTO TABLE t_z4a18
FROM z4a18
WHERE tpform = 'S'.

LOOP AT t_z4a18.

CALL FUNCTION 'TB_FIELD_GET_INFO'
EXPORTING
fieldname = t_z4a18-nmcmp
tabname = t_z4a18-nmtab
IMPORTING
text_middle = operands_table-description
EXCEPTIONS
not_found = 1
OTHERS = 2.

IF sy-subrc 0.
ENDIF.

CONCATENATE t_z4a18-nmtab '-' t_z4a18-nmcmp
INTO operands_table-tech_name.

operands_table-token = 'FIELD_TAB'.

APPEND operands_table.
ENDLOOP.

ENDCASE.
ENDFUNCTION.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.