Showing posts with label sap. Show all posts
Showing posts with label sap. Show all posts

Friday, December 05, 2014

Wednesday, July 20, 2011

Filtering on hierarchy values in DTP

Having spent some time unsuccessfully googleing for a way to use a hierarchy as filter in a DTP I've come up with a (rather inelegant) solution myself.
Posting it here in hope it's helpful.
Code:

DATA: l_idx like sy-tabix.

DATA: lw_hier_id TYPE rshi_s_rshiedirkey.
DATA: lt_nodes_a_leaves TYPE rshi_t_hienode.
DATA: lw_nodes_a_leaves LIKE LINE OF lt_nodes_a_leaves.

DATA: l_hier_name TYPE rshienm.
DATA: lw_hier_type TYPE rshiedir.

read table l_t_range with key
fieldname = '/BIC/ZFIELD_NAME'.
l_idx = sy-tabix.
*....

l_hier_name = 'ZH_HIER_NAME'.

SELECT SINGLE * FROM rshiedir INTO lw_hier_type
WHERE hienm = l_hier_name
AND objvers = 'A'.

IF sy-subrc = 0.
lw_hier_id-hieid = lw_hier_type-hieid.
lw_hier_id-objvers = 'A'.


CALL FUNCTION 'RSSH_HIERARCHY_READ'
EXPORTING
i_rshiedirkey = lw_hier_id
IMPORTING
e_t_rsnodes = lt_nodes_a_leaves
EXCEPTIONS
invalid_hierarchy = 1
name_error = 2
iobj_not_found = 3
OTHERS = 4
.
IF sy-subrc <> 0.

DELETE lt_nodes_a_leaves WHERE iobjnm = '0HIER_NODE'.

Loop at lt_nodes_a_leaves INTO lw_nodes_a_leaves.

l_t_range-fieldname = '/BIC/ZFIELD_NAME'.
l_t_range-sign = 'I'.
l_t_range-option = 'EQ'.
* substring is due to compounding, generally unneeded
l_t_range-low = lw_nodes_a_leaves-nodename+2(4).

append l_t_range.

endloop.

ENDIF.

ENDIF.


* if l_idx <> 0.
* modify l_t_range index l_idx.
* else.
* append l_t_range.
* endif.
p_subrc = 0.
OK, this is all SAP BW jargon ;-)

Friday, May 04, 2007

SAP BW, IF for your BEx formulas

Have you ever felt the need for an IF in your BEx formulas? Didn't find it? That's because SAP expects you to know about boolean math ...
See, we are subtracting two quantities and we want our result to be shown as 0 if the actual result is negative, the trick is very simple, look at this example:


( ( 'GR quantity' - 'PO quantity' ) > 0 ) * ( 'GR quantity' - 'PO quantity' )


The first block will evaluate to 1 when GR quantity is greater than PO quantity and to 0 when it's smaller, so the result will be something like:

GR quantity: 6
PO quantity: 4

(( 6 - 1) > 0) * (6 - 4) will turn into 1 (true) * (6 - 4) = 2

The other case:

GR quantity: 4
PO quantity: 7

(( 4 - 7) > 0) * (4 - 7) will turn into 0 (false) * (4 - 7) = 0