cancel
Showing results for 
Search instead for 
Did you mean: 

BPS variable type EXIT to expand hierarchy

Former Member
0 Kudos

Hello,

Any idea how I can get all elements under a particular node (chosen by the user through a variable) of a hierarchy using a Function module in BPS?

I have been trying to do this using Function 'RSSH_HIERARCHY_READ' with the following code and parameters (see below)

Could anyone tell me how to proceed next?

Thanks in advance

Points will be assigned

*"----


""Local Interface:

*" IMPORTING

*" REFERENCE(I_TYPE) TYPE UPC_Y_VAR_TYPE

*" REFERENCE(I_AREA) TYPE UPC_Y_AREA

*" REFERENCE(I_VARIABLE) TYPE UPC_Y_VARIABLE

*" REFERENCE(IS_HIE_KEY) TYPE UPC_YS_HIE_KEY

*" EXPORTING

*" REFERENCE(ET_HIE_NODES) TYPE UPC_YT_HIESEL

*"----


DATA: BEGIN OF wa_val,

from TYPE rsleaffrom,

to TYPE rsleafto,

END OF wa_val,

wa_hierdir TYPE rshi_s_hiedir,

wa_hiedirkey TYPE rshi_s_rshiedirkey,

wt LIKE wa_hiedirkey OCCURS 0 WITH HEADER LINE,

ls_hie_nodes TYPE upc_ys_hiesel,

tb_node_val TYPE rshi_t_hienode,

tt LIKE LINE OF tb_node_val,

tb_interval TYPE rshi_th_interval.

SELECT SINGLE hieid objvers FROM /bic/hystopid

INTO wa_hiedirkey

WHERE nodename = '00001'.

CALL FUNCTION 'RSSH_HIERARCHY_READ'

EXPORTING

i_rshiedirkey = wa_hiedirkey

i_date = sy-datum

IMPORTING

e_rshiedir = wa_hierdir

e_t_rsnodes = tb_node_val

e_th_rsinterval = tb_interval

EXCEPTIONS

invalid_hierarchy = 1

name_error = 2

iobj_not_found = 3

OTHERS = 4.

Accepted Solutions (1)

Accepted Solutions (1)

former_member93896
Active Contributor
0 Kudos

Hi Nicolas,

It looks like you are trying to program an exit for a hierarchy variable. In there you don't need to return all nodes down to the leaves. You have to return only the top node(s) that should be selectable.

Anyway, if you want to read another BPS hiearchy variable, then use the following code:


FUNCTION z_variable_get_detail_hier.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     REFERENCE(I_AREA) TYPE  UPC_VAR-AREA
*"     REFERENCE(I_VARIABLE) TYPE  UPC_VAR-VAR
*"     REFERENCE(I_BUFFER) TYPE  BOOLE-BOOLE OPTIONAL
*"  EXPORTING
*"     REFERENCE(E_SUBRC) TYPE  SY-SUBRC
*"     REFERENCE(ES_RETURN) TYPE  BAPIRET2
*"     REFERENCE(E_TYPE) TYPE  UPC_VAR-VARTYPE
*"     VALUE(ET_HIESEL_ALL) TYPE  UPC_YT_HIESEL
*"     VALUE(ET_HIESEL) TYPE  UPC_YT_HIESEL
*"     VALUE(ETO_CHANM) TYPE  UPC_YTO_CHA
*"----------------------------------------------------------------------

  STATICS:
    p_subrc        LIKE sy-subrc,
    ps_return      LIKE bapiret2,
    p_type         LIKE upc_var-vartype,
    pt_hiesel_all  TYPE upc_yt_hiesel,
    pt_hiesel      TYPE upc_yt_hiesel,
    pto_chanm      TYPE upc_yto_cha,
    p_variable     TYPE upc_var-var,
    p_area         TYPE upc_y_area,
    p_first_read   LIKE boole-boole VALUE 'X'.

  DATA:
    lr_variable TYPE REF TO cl_sem_variable.

* We can't read the values from the buffer if ...
* - it is the first read
* - the buffer flag is initial
* - the stored area or varname differ from imported values.
  IF NOT i_buffer IS INITIAL
    AND p_first_read IS INITIAL
    AND p_area = i_area
    AND p_variable = i_variable.

    e_subrc        = p_subrc.
    es_return      = ps_return.
    et_hiesel_all  = pt_hiesel_all.
    et_hiesel      = pt_hiesel.
    eto_chanm      = pto_chanm.

  ELSE.
* clear all exporing tables of type reference
    CLEAR: eto_chanm, et_hiesel_all, et_hiesel.

    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_hie_nodes
      EXPORTING
        i_user     = sy-uname
        i_restrict = 'X'
      RECEIVING
        rt_value   = et_hiesel
      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_hie_nodes
      EXPORTING
        i_user     = sy-uname
        i_restrict = ' '
      RECEIVING
        rt_value   = et_hiesel_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
    CLEAR p_first_read.
    p_area         = i_area.
    p_variable     = i_variable.
    p_subrc        = e_subrc.
    ps_return      = es_return.
    pt_hiesel_all  = et_hiesel_all.
    pt_hiesel      = et_hiesel.
    pto_chanm      = eto_chanm.

  ENDIF.

ENDFUNCTION.

Regards,

Marc

SAP NetWeaver RIG

Former Member
0 Kudos

Hello Marc

First of all thanks for giving me a hand on this matter

I copied the below mentionned code and then ran the function for my

I_AREA ZGTBand I_VARIABLE STOPID

Then i got a return code 4 saying

"Restrict variable STOPID (area ZGTB ) to single value"

As you know when creating a hierarchy variable the system sets the indicator "Restriction required by user" automatically.

Master data exist for that YSTOPID characteristics but no value appears in the popup window so no selection is possible. I can not set any value for this variable.

Problem with the above mentionned code. Function keeps looping...

Any idea how i can fix this?

Thanks in advance

Nicolas

Edited by: Nicolas Nevers on Oct 17, 2008 3:11 PM

Answers (0)