Mathematical functions
ABAP contains a range of built-in functions that you can use as mathematical expressions, or as part of a mathematical expression:
[COMPUTE] n = func( m ).
The blanks between the parentheses and the argument m are obligatory. The result of calling the function func with the argument m is assigned to m.
Functions for all Numeric Data Types
The following built-in functions work with all three numeric data types (f, i, p) as arguments.
Functions for all Numeric Data Types
Function Result
abs Absolute value of argument.
sign Prefix of the argument : 1 x > 0
SIGN( x ) = 0 if x = 0
-1 x < 0
ceil Smallest integer value not smaller than the argument.
floor Largest integer value not larger than the argument.
trunc Integer part of argument.
FRAC Fraction part of argument.
The argument of these functions does not have to be a numeric data type. If you choose another type, it is converted to a numeric type. For performance reasons, however, you should use the correct type whenever possible. The functions itself do not have a data type of their own. They do not change the numerical precision of a numerical operation.
DATA n TYPE p DECIMALS 2.
DATA m TYPE p DECIMALS 2 VALUE '-5.55'.
n = abs( m ). WRITE: 'ABS: ', n.
n = sign( m ). WRITE: / 'SIGN: ', n.
n = ceil( m ). WRITE: / 'CEIL: ', n.
n = floor( m ). WRITE: / 'FLOOR:', n.
n = trunc( m ). WRITE: / 'TRUNC:', n.
n = frac( m ). WRITE: / 'FRAC: ', n.
The output appears as follows:
ABS: 5.55
SIGN: 1.00-
CEIL: 5.00-
FLOOR: 6.00-
TRUNC: 5.00-
FRAC: 0.55-
DATA: t1(10) TYPE c,
t2(10) TYPE c VALUE '-100'.
t1 = ABS( t2 ).
WRITE t1.
Result:
100
Two conversions are performed. First, the contents of field t2 (type c) are converted to type p. Then the system processes the abs function using the results of the conversion. Then, during the assignment to the type c field t1, the result of the function is converted back to type c.
Floating-Point Functions
The following built-in functions work with floating point numbers (data type f) as an argument.
Floating point functions
Function Meaning
acos, asin, atan; cos, sin, tan Trigonometric functions.
cosh, sinh, tanh Hyperbolic functions.
exp Exponential function with base e (e=2.7182818285).
log Natural logarithm with base e.
log10 Logarithm with base 10.
sqrt Square root.
For all functions, the normal mathematical constraints apply (for example, square root is only possible for positive numbers). If you fail to observe them, a runtime error occurs.
The argument of these functions does not have to be a floating point field. If you choose another type, it is converted to type f. The functions themselves have the data type f. This can change the numerical precision of a numerical operation.
DATA: result TYPE f,
pi(10) TYPE c VALUE '3.14159265'.
result = cos( pi ).
WRITE result.
The output is -1.00000000000000E+00. The character field pi is automatically converted to a type f field before the calculation is performed.
Sunday, January 16, 2011
Sunday, December 26, 2010
Checking the PR deletion indicator
Enhancement Name - MEREQ001
Exit Name - EXIT_SAPLMEREQ_005
Exit Import Parameter IM_REQ_ITEM reference to interface IF_PURCHASE_REQUISITION_ITEM.
I need to read PR number from this import parameter, the field corresponds to the PR number is BANFN.
DATA: wf_banfn LIKE eban-banfn.
DATA: obj_requisition TYPE REF TO if_purchase_requisition.
DATA: loc_data_doc TYPE mereq_header.
*--->>>
CALL METHOD im_req_item->get_requisition
RECEIVING
re_requisition = obj_requisition.
IF NOT obj_requisition IS INITIAL.
*--->>> Getting the purchasing Document number
CALL METHOD obj_requisition->get_data
RECEIVING
re_data = loc_data_doc.
wf_banfn = loc_data_doc-banfn. " this will return the PR Number
ENDIF.
Exit Name - EXIT_SAPLMEREQ_005
Exit Import Parameter IM_REQ_ITEM reference to interface IF_PURCHASE_REQUISITION_ITEM.
I need to read PR number from this import parameter, the field corresponds to the PR number is BANFN.
DATA: wf_banfn LIKE eban-banfn.
DATA: obj_requisition TYPE REF TO if_purchase_requisition.
DATA: loc_data_doc TYPE mereq_header.
*--->>>
CALL METHOD im_req_item->get_requisition
RECEIVING
re_requisition = obj_requisition.
IF NOT obj_requisition IS INITIAL.
*--->>> Getting the purchasing Document number
CALL METHOD obj_requisition->get_data
RECEIVING
re_data = loc_data_doc.
wf_banfn = loc_data_doc-banfn. " this will return the PR Number
ENDIF.
Tuesday, November 23, 2010
Function Module to Read Feature value
*&---------------------------------------------------------------------*
*& Report YTEST_FEATURE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT YTEST_FEATURE.
data structure like pme04.
data feature like t549b-namen.
data back like t549a-abkrs.
data status(1).
BREAK-POINT.
structure-molga = '01'.
structure-persk = 'DN'.
feature = 'ABKRS'.
call function 'HR_FEATURE_BACKFIELD'
exporting
feature = feature
struc_content = structure
kind_of_error = space
importing
back = back
changing
status = status
exceptions
dummy = 1
error_operation = 2
no_backvalue = 3
feature_not_generated = 4
invalid_sign_in_funid = 5
field_in_report_tab_in_pe03 = 6
others = 7.
case sy-subrc.
when 2.
when 3.
when 4.
when 5.
when 6.
endcase.
*& Report YTEST_FEATURE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT YTEST_FEATURE.
data structure like pme04.
data feature like t549b-namen.
data back like t549a-abkrs.
data status(1).
BREAK-POINT.
structure-molga = '01'.
structure-persk = 'DN'.
feature = 'ABKRS'.
call function 'HR_FEATURE_BACKFIELD'
exporting
feature = feature
struc_content = structure
kind_of_error = space
importing
back = back
changing
status = status
exceptions
dummy = 1
error_operation = 2
no_backvalue = 3
feature_not_generated = 4
invalid_sign_in_funid = 5
field_in_report_tab_in_pe03 = 6
others = 7.
case sy-subrc.
when 2.
when 3.
when 4.
when 5.
when 6.
endcase.
Sunday, October 10, 2010
Passing Mutiple values to Workflow in BADI
In BADI we cannot include INCLUDE . . So we need to use some other way to pass multiple values to Workflow.
For that, go to SE24 give the interface name.

Then go to goto --> Class-local types --> macros

In the editor, include INCLUDE cntn01_swc instead of INCLUDE

Macros written in the program is also different.
Please see one example code.
***********************************
***---INTERNAL TABLE DECLARATION
DATA : lit_event_container TYPE TABLE OF swcont. "event container
*--Creating a container
swc0_create_container lit_event_container.
*--Filling event container
swc0_set_element lit_event_container 'User' draw-dwnam.
swc0_set_element lit_event_container 'DocumentStatus' new_status.
swc0_set_element lit_event_container 'DocumentStatus_old' old_status.
swc0_set_element lit_event_container 'Document_Desc' lfs_drat-dktxt.
CALL FUNCTION 'SWE_EVENT_CREATE'
EXPORTING
objtype = l_objtype
objkey = l_objkey
event = l_event
* creator = ' '
* take_workitem_requester = ' '
* start_with_delay = ' '
* start_recfb_synchron = ' '
* no_commit_for_queue = ' '
* debug_flag = ' '
* no_logging = ' '
* ident =
IMPORTING
event_id = l_eventid
* receiver_count =
TABLES
event_container = lit_event_container
EXCEPTIONS
objtype_not_found = 1
others = 2
.
IF sy-subrc <> 0.
* message id sy-msgid type sy-msgty number sy-msgno
* with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
COMMIT WORK.
****************************************************
See the event parameter list
For that, go to SE24 give the interface name.

Then go to goto --> Class-local types --> macros

In the editor, include INCLUDE cntn01_swc instead of INCLUDE

Macros written in the program is also different.
Please see one example code.
***********************************
***---INTERNAL TABLE DECLARATION
DATA : lit_event_container TYPE TABLE OF swcont. "event container
*--Creating a container
swc0_create_container lit_event_container.
*--Filling event container
swc0_set_element lit_event_container 'User' draw-dwnam.
swc0_set_element lit_event_container 'DocumentStatus' new_status.
swc0_set_element lit_event_container 'DocumentStatus_old' old_status.
swc0_set_element lit_event_container 'Document_Desc' lfs_drat-dktxt.
CALL FUNCTION 'SWE_EVENT_CREATE'
EXPORTING
objtype = l_objtype
objkey = l_objkey
event = l_event
* creator = ' '
* take_workitem_requester = ' '
* start_with_delay = ' '
* start_recfb_synchron = ' '
* no_commit_for_queue = ' '
* debug_flag = ' '
* no_logging = ' '
* ident =
IMPORTING
event_id = l_eventid
* receiver_count =
TABLES
event_container = lit_event_container
EXCEPTIONS
objtype_not_found = 1
others = 2
.
IF sy-subrc <> 0.
* message id sy-msgid type sy-msgty number sy-msgno
* with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
COMMIT WORK.
****************************************************
See the event parameter list
Passing Multiple Values to Workflow
Passing Multiple values from the triggering program to Workflow.
First we need to declare the event container variables for the required event.
See the screen shots for creating event container variables.



Now we have defined the event container variables.
After that we need to do the coding in the workflow triggering point.
*-- For Passing Event Container Values
INCLUDE.
swc_container wf_contnr.
*-- create the container of type container
swc_create_container wf_contnr.
swc_set_element wf_contnr 'EvtParameter1' p_gwf_onrname.
*-- Triggering the workflow ( note that we are passing the event container )
CALL FUNCTION 'SWE_EVENT_CREATE'
EXPORTING
objtype = 'ZEHS_RA'
objkey = p_gwf_entryno
event = p_gwf_event
* CREATOR = ' '
* TAKE_WORKITEM_REQUESTER = ' '
* START_WITH_DELAY = ' '
* START_RECFB_SYNCHRON = ' '
* NO_COMMIT_FOR_QUEUE = ' '
* DEBUG_FLAG = ' '
* NO_LOGGING = ' '
* IDENT =
* IMPORTING
* EVENT_ID =
* RECEIVER_COUNT =
TABLES
event_container = wf_contnr
EXCEPTIONS
objtype_not_found = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
COMMIT WORK.
***************************************************
Please see one example program
***************************************************
*-- For Passing Event Container Values
INCLUDE.
swc_container wf_contnr.
* swc_container wf_contnr1.
swc_create_container wf_contnr.
* swc_create_container wf_contnr1.
IF p_gwf_onrname IS NOT INITIAL AND p_gwf_onrname NE space.
swc_set_element wf_contnr 'NextLevel' p_gwf_onrname.
swc_set_element wf_contnr 'Initiator' sy-uname.
ENDIF.
IF p_gwf_onrname IS INITIAL.
swc_set_element wf_contnr 'Initiator' sy-uname.
ENDIF.
*--------------------------------------------------------------*
CALL FUNCTION 'SWE_EVENT_CREATE'
EXPORTING
objtype = 'ZEHS_RA'
objkey = p_gwf_entryno
event = p_gwf_event
* CREATOR = ' '
* TAKE_WORKITEM_REQUESTER = ' '
* START_WITH_DELAY = ' '
* START_RECFB_SYNCHRON = ' '
* NO_COMMIT_FOR_QUEUE = ' '
* DEBUG_FLAG = ' '
* NO_LOGGING = ' '
* IDENT =
* IMPORTING
* EVENT_ID =
* RECEIVER_COUNT =
TABLES
event_container = wf_contnr
EXCEPTIONS
objtype_not_found = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
COMMIT WORK.
First we need to declare the event container variables for the required event.
See the screen shots for creating event container variables.



Now we have defined the event container variables.
After that we need to do the coding in the workflow triggering point.
*-- For Passing Event Container Values
INCLUDE
swc_container wf_contnr.
*-- create the container of type container
swc_create_container wf_contnr.
swc_set_element wf_contnr 'EvtParameter1' p_gwf_onrname.
*-- Triggering the workflow ( note that we are passing the event container )
CALL FUNCTION 'SWE_EVENT_CREATE'
EXPORTING
objtype = 'ZEHS_RA'
objkey = p_gwf_entryno
event = p_gwf_event
* CREATOR = ' '
* TAKE_WORKITEM_REQUESTER = ' '
* START_WITH_DELAY = ' '
* START_RECFB_SYNCHRON = ' '
* NO_COMMIT_FOR_QUEUE = ' '
* DEBUG_FLAG = ' '
* NO_LOGGING = ' '
* IDENT =
* IMPORTING
* EVENT_ID =
* RECEIVER_COUNT =
TABLES
event_container = wf_contnr
EXCEPTIONS
objtype_not_found = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
COMMIT WORK.
***************************************************
Please see one example program
***************************************************
*-- For Passing Event Container Values
INCLUDE
swc_container wf_contnr.
* swc_container wf_contnr1.
swc_create_container wf_contnr.
* swc_create_container wf_contnr1.
IF p_gwf_onrname IS NOT INITIAL AND p_gwf_onrname NE space.
swc_set_element wf_contnr 'NextLevel' p_gwf_onrname.
swc_set_element wf_contnr 'Initiator' sy-uname.
ENDIF.
IF p_gwf_onrname IS INITIAL.
swc_set_element wf_contnr 'Initiator' sy-uname.
ENDIF.
*--------------------------------------------------------------*
CALL FUNCTION 'SWE_EVENT_CREATE'
EXPORTING
objtype = 'ZEHS_RA'
objkey = p_gwf_entryno
event = p_gwf_event
* CREATOR = ' '
* TAKE_WORKITEM_REQUESTER = ' '
* START_WITH_DELAY = ' '
* START_RECFB_SYNCHRON = ' '
* NO_COMMIT_FOR_QUEUE = ' '
* DEBUG_FLAG = ' '
* NO_LOGGING = ' '
* IDENT =
* IMPORTING
* EVENT_ID =
* RECEIVER_COUNT =
TABLES
event_container = wf_contnr
EXCEPTIONS
objtype_not_found = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
COMMIT WORK.
Wednesday, June 30, 2010
How to apply SAP notes
Go through following Steps:
1. Check Note Validity
a. Log on to SAPNet (or use SAP Service Marketplace on the Web)
i. Click Gen. Functions
ii. Click Display
iii.Enter note # and click Execute
iv. Click Note Administration
v. Click Support Package Tab to display note package level
If no value exists for package level
a. Follow the steps in the Solution to apply the note
b. Go to transaction code spam
i. Click Package Level to display current package level
c. Compare note package level with current package level
i. If note package level < or = current package level, note hasalready been applied through support packages. No additional steps necessary
ii.If note package level > current package level, note must be applied. Go to Step 2
2. Go to transaction code snote
3. Download SAP note
a. Click Goto à Download SAP note
b. Enter note #
c. Click Execute
4. Implement SAP Note
a. Select note and click Implement SAP Note icon
b. Request – Click Create; Enter note # and description
c. Take note of transport #
5. Test transport before migration
a. Notify requestor to verify changes before migrating to the next environment
b. After thorough testing has been completed, release transport
c. Migrate transport to the other environments
1. Check Note Validity
a. Log on to SAPNet (or use SAP Service Marketplace on the Web)
i. Click Gen. Functions
ii. Click Display
iii.Enter note # and click Execute
iv. Click Note Administration
v. Click Support Package Tab to display note package level
If no value exists for package level
a. Follow the steps in the Solution to apply the note
b. Go to transaction code spam
i. Click Package Level to display current package level
c. Compare note package level with current package level
i. If note package level < or = current package level, note hasalready been applied through support packages. No additional steps necessary
ii.If note package level > current package level, note must be applied. Go to Step 2
2. Go to transaction code snote
3. Download SAP note
a. Click Goto à Download SAP note
b. Enter note #
c. Click Execute
4. Implement SAP Note
a. Select note and click Implement SAP Note icon
b. Request – Click Create; Enter note # and description
c. Take note of transport #
5. Test transport before migration
a. Notify requestor to verify changes before migrating to the next environment
b. After thorough testing has been completed, release transport
c. Migrate transport to the other environments
Subscribe to:
Posts (Atom)