Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get the data in a selected node whenever I double click on a node?

former_member859593
Discoverer
0 Kudos
488

I am using cl_salv_tree and I have 3 level hierarchy in my program.

FORM get_data.
  IF s_budat IS INITIAL.

    SELECT zzcustomer_group~grpnam,
           acdoca~kunnr,
           kna1~name1,
        SUM( CASE
           WHEN dats_days_between( acdoca~budat, @p_budat ) < 30 THEN hsl
           ELSE 0 END ) AS hsl1,
        SUM( CASE
           WHEN dats_days_between( acdoca~budat, @p_budat ) > 30
           AND dats_days_between( acdoca~budat, @p_budat ) <= 60 THEN hsl
           ELSE 0 END ) AS hsl2,
        SUM( CASE
           WHEN dats_days_between( acdoca~budat, @p_budat ) > 60
           AND dats_days_between( acdoca~budat, @p_budat ) <= 90 THEN hsl
           ELSE 0 END ) AS hsl3,
        SUM( CASE
           WHEN dats_days_between( acdoca~budat, @p_budat ) > 90
           AND dats_days_between( acdoca~budat, @p_budat ) <= 120 THEN hsl
           ELSE 0 END ) AS hsl4,
        SUM( CASE
           WHEN dats_days_between( acdoca~budat, @p_budat ) > 120
           AND dats_days_between( acdoca~budat, @p_budat ) <= 150 THEN hsl
           ELSE 0 END ) AS hsl5,
        SUM( CASE
           WHEN dats_days_between( acdoca~budat, @p_budat ) > 150 THEN hsl
           ELSE 0 END ) AS hsl6,
        SUM( hsl ) AS hsl
    FROM acdoca
    INNER JOIN kna1 ON acdoca~kunnr = kna1~kunnr
    INNER JOIN zzcustomer_group ON kna1~kunnr = zzcustomer_group~kunnr
    WHERE acdoca~rbukrs IN @s_rbukrs
        AND ( acdoca~augdt IS INITIAL OR acdoca~augdt > @p_budat )
        AND acdoca~budat <= @p_budat
    GROUP BY acdoca~kunnr, kna1~name1, zzcustomer_group~grpnam
    ORDER BY acdoca~kunnr ASCENDING,
              kna1~name1   ASCENDING
    INTO TABLE @it_data_tree.

  ELSE.

    SELECT zzcustomer_group~grpnam,
           acdoca~kunnr,
           kna1~name1,
        SUM( CASE
           WHEN dats_days_between( acdoca~budat, @p_budat ) < 30 THEN hsl
           ELSE 0 END ) AS hsl1,
        SUM( CASE
           WHEN dats_days_between( acdoca~budat, @p_budat ) > 30
           AND dats_days_between( acdoca~budat, @p_budat ) <= 60 THEN hsl
           ELSE 0 END ) AS hsl2,
        SUM( CASE
           WHEN dats_days_between( acdoca~budat, @p_budat ) > 60
           AND dats_days_between( acdoca~budat, @p_budat ) <= 90 THEN hsl
           ELSE 0 END ) AS hsl3,
        SUM( CASE
           WHEN dats_days_between( acdoca~budat, @p_budat ) > 90
           AND dats_days_between( acdoca~budat, @p_budat ) <= 120 THEN hsl
           ELSE 0 END ) AS hsl4,
        SUM( CASE
           WHEN dats_days_between( acdoca~budat, @p_budat ) > 120
           AND dats_days_between( acdoca~budat, @p_budat ) <= 150 THEN hsl
           ELSE 0 END ) AS hsl5,
        SUM( CASE
           WHEN dats_days_between( acdoca~budat, @p_budat ) > 150 THEN hsl
           ELSE 0 END ) AS hsl6,
        SUM( hsl ) AS hsl
    FROM acdoca
    INNER JOIN kna1 ON acdoca~kunnr = kna1~kunnr
    INNER JOIN zzcustomer_group ON kna1~kunnr = zzcustomer_group~kunnr
    WHERE acdoca~rbukrs IN @s_rbukrs
        AND ( acdoca~augdt IS INITIAL OR acdoca~augdt > @p_budat )
        AND ( acdoca~budat IN @s_budat OR acdoca~budat <= @p_budat )
    GROUP BY acdoca~kunnr, kna1~name1, zzcustomer_group~grpnam
    ORDER BY acdoca~kunnr ASCENDING,
              kna1~name1   ASCENDING
    INTO TABLE @it_data_tree.

  ENDIF.


  DATA lv_text TYPE lvc_value.

  LOOP AT it_data_tree INTO DATA(wa_data).


    ON CHANGE OF wa_data-cgrp.
    CONCATENATE '' wa_data-cgrp INTO lv_text.
      obj_node = obj_nodes->add_node( related_node = ''
                                      text = lv_text
                                      relationship = ''  ).

      DATA(lv_order_key) = obj_node->get_key( ).


    ENDON.

    ON CHANGE OF wa_data-name1.
      obj_node1 = obj_nodes->add_node( related_node = lv_order_key
                                      data_row = ''
                                      relationship = cl_gui_column_tree=>relat_first_child ).

      DATA(lv_activity_key) = obj_node1->get_key( ).
    ENDON.

    obj_node2 = obj_nodes->add_node( related_node = lv_activity_key
                                    data_row = wa_data
                                    relationship = cl_gui_column_tree=>relat_first_child  ).

    DATA(lv_data_key) = obj_node2->get_key( ).
    obj_node->expand( ).


  ENDLOOP.

  obj_tree->display( ).

ENDFORM.


I want the index for my read table be equal to the row in my internal table whenever I double click on a node. How do I do it, is it possible to use the get_data_row for cl_salv_tree?

CLASS lcl_handler DEFINITION.
  PUBLIC SECTION.
    METHODS: on_double_click FOR EVENT double_click OF cl_salv_events_tree
      IMPORTING node_key columnname.
ENDCLASS.

CLASS lcl_handler IMPLEMENTATION.
  METHOD on_double_click.

    DATA: node_key_num TYPE i,
          node_key_n   TYPE i.

    node_key_num = node_key MOD 3.

    IF node_key_num = 0.
      DESCRIBE TABLE it_data_tree.
      node_key_n = node_key / 3.
      DATA: ls_kunnr TYPE acc_rec.
      READ TABLE it_data_tree INTO ls_kunnr INDEX node_key_n.

      IF columnname = 'HSL1'.
        REFRESH it_r_data.
        SELECT acdoca~rbukrs,
               acdoca~kunnr,
               kna1~name1,
               acdoca~belnr,
               acdoca~blart,
               acdoca~bschl,
               acdoca~bldat,
               acdoca~budat,
               acdoca~hsl,
               dats_days_between( acdoca~budat, @p_budat ) AS age,
               acdoca~prctr,
               cepct~ktext
        FROM acdoca
            INNER JOIN kna1 ON kna1~kunnr = acdoca~kunnr
            INNER JOIN cepct ON cepct~prctr = acdoca~prctr
        WHERE acdoca~rbukrs IN @s_rbukrs
            AND acdoca~kunnr = @ls_kunnr-kunnr
            AND kna1~name1 = @ls_kunnr-name1
            AND ( acdoca~augdt IS INITIAL OR acdoca~augdt > @p_budat )
            AND acdoca~budat <= @p_budat
            AND dats_days_between( acdoca~budat, @p_budat ) < 30
        ORDER BY acdoca~kunnr ASCENDING,
                 kna1~name1   ASCENDING,
                 acdoca~bldat ASCENDING
        INTO TABLE @it_r_data.

        LOOP AT it_r_data INTO wa_r_data.

        ENDLOOP.

      ELSEIF columnname = 'HSL2'.
        REFRESH it_r_data.
        SELECT acdoca~rbukrs,
               acdoca~kunnr,
               kna1~name1,
               acdoca~belnr,
               acdoca~blart,
               acdoca~bschl,
               acdoca~bldat,
               acdoca~budat,
               acdoca~hsl,
               dats_days_between( acdoca~budat, @p_budat ) AS age,
               acdoca~prctr,
               cepct~ktext
        FROM acdoca
            INNER JOIN kna1 ON kna1~kunnr = acdoca~kunnr
            INNER JOIN cepct ON cepct~prctr = acdoca~prctr
        WHERE acdoca~rbukrs IN @s_rbukrs
            AND acdoca~kunnr = @ls_kunnr-kunnr
            AND kna1~name1 = @ls_kunnr-name1
            AND ( acdoca~augdt IS INITIAL OR acdoca~augdt > @p_budat )
            AND acdoca~budat <= @p_budat
            AND dats_days_between( acdoca~budat, @p_budat ) > 30
            AND dats_days_between( acdoca~budat, @p_budat ) <= 60
        ORDER BY acdoca~kunnr ASCENDING,
                 kna1~name1   ASCENDING,
                 acdoca~bldat ASCENDING
        INTO TABLE @it_r_data.

        LOOP AT it_r_data INTO wa_r_data.

        ENDLOOP.

      ELSEIF columnname = 'HSL3'.
        REFRESH it_r_data.
        SELECT acdoca~rbukrs,
                 acdoca~kunnr,
                 kna1~name1,
                 acdoca~belnr,
                 acdoca~blart,
                 acdoca~bschl,
                 acdoca~bldat,
                 acdoca~budat,
                 acdoca~hsl,
                 dats_days_between( acdoca~budat, @p_budat ) AS age,
                 acdoca~prctr,
                 cepct~ktext
          FROM acdoca
              INNER JOIN kna1 ON kna1~kunnr = acdoca~kunnr
              INNER JOIN cepct ON cepct~prctr = acdoca~prctr
          WHERE acdoca~rbukrs IN @s_rbukrs
              AND acdoca~kunnr = @ls_kunnr-kunnr
              AND kna1~name1 = @ls_kunnr-name1
              AND ( acdoca~augdt IS INITIAL OR acdoca~augdt > @p_budat )
              AND acdoca~budat <= @p_budat
              AND dats_days_between( acdoca~budat, @p_budat ) > 60
              AND dats_days_between( acdoca~budat, @p_budat ) <= 90
          ORDER BY acdoca~kunnr ASCENDING,
                   kna1~name1   ASCENDING,
                   acdoca~bldat ASCENDING
          INTO TABLE @it_r_data.

        LOOP AT it_r_data INTO wa_r_data.

        ENDLOOP.

      ELSEIF columnname = 'HSL4'.
        REFRESH it_r_data.
        SELECT acdoca~rbukrs,
                   acdoca~kunnr,
                   kna1~name1,
                   acdoca~belnr,
                   acdoca~blart,
                   acdoca~bschl,
                   acdoca~bldat,
                   acdoca~budat,
                   acdoca~hsl,
                   dats_days_between( acdoca~budat, @p_budat ) AS age,
                   acdoca~prctr,
                   cepct~ktext
            FROM acdoca
                INNER JOIN kna1 ON kna1~kunnr = acdoca~kunnr
                INNER JOIN cepct ON cepct~prctr = acdoca~prctr
            WHERE acdoca~rbukrs IN @s_rbukrs
                AND acdoca~kunnr = @ls_kunnr-kunnr
                AND kna1~name1 = @ls_kunnr-name1
                AND ( acdoca~augdt IS INITIAL OR acdoca~augdt > @p_budat )
                AND acdoca~budat <= @p_budat
                AND dats_days_between( acdoca~budat, @p_budat ) > 90
                AND dats_days_between( acdoca~budat, @p_budat ) <= 120
            ORDER BY acdoca~kunnr ASCENDING,
                     kna1~name1   ASCENDING,
                     acdoca~bldat ASCENDING
            INTO TABLE @it_r_data.

        LOOP AT it_r_data INTO wa_r_data.

        ENDLOOP.

      ELSEIF columnname = 'HSL5'.
        REFRESH it_r_data.
        SELECT acdoca~rbukrs,
                   acdoca~kunnr,
                   kna1~name1,
                   acdoca~belnr,
                   acdoca~blart,
                   acdoca~bschl,
                   acdoca~bldat,
                   acdoca~budat,
                   acdoca~hsl,
                   dats_days_between( acdoca~budat, @p_budat ) AS age,
                   acdoca~prctr,
                   cepct~ktext
            FROM acdoca
                INNER JOIN kna1 ON kna1~kunnr = acdoca~kunnr
                INNER JOIN cepct ON cepct~prctr = acdoca~prctr
            WHERE acdoca~rbukrs IN @s_rbukrs
                AND acdoca~kunnr = @ls_kunnr-kunnr
                AND kna1~name1 = @ls_kunnr-name1
                AND ( acdoca~augdt IS INITIAL OR acdoca~augdt > @p_budat )
                AND acdoca~budat <= @p_budat
                AND dats_days_between( acdoca~budat, @p_budat ) > 120
                AND dats_days_between( acdoca~budat, @p_budat ) <= 150
            ORDER BY acdoca~kunnr ASCENDING,
                     kna1~name1   ASCENDING,
                     acdoca~bldat ASCENDING
            INTO TABLE @it_r_data.

        LOOP AT it_r_data INTO wa_r_data.

        ENDLOOP.

      ELSEIF columnname = 'HSL6'.
        REFRESH it_r_data.
        SELECT acdoca~rbukrs,
                   acdoca~kunnr,
                   kna1~name1,
                   acdoca~belnr,
                   acdoca~blart,
                   acdoca~bschl,
                   acdoca~bldat,
                   acdoca~budat,
                   acdoca~hsl,
                   dats_days_between( acdoca~budat, @p_budat ) AS age,
                   acdoca~prctr,
                   cepct~ktext
            FROM acdoca
                INNER JOIN kna1 ON kna1~kunnr = acdoca~kunnr
                INNER JOIN cepct ON cepct~prctr = acdoca~prctr
            WHERE acdoca~rbukrs IN @s_rbukrs
                AND acdoca~kunnr = @ls_kunnr-kunnr
                AND kna1~name1 = @ls_kunnr-name1
                AND ( acdoca~augdt IS INITIAL OR acdoca~augdt > @p_budat )
                AND acdoca~budat <= @p_budat
                AND dats_days_between( acdoca~budat, @p_budat ) > 150
            ORDER BY acdoca~kunnr ASCENDING,
                     kna1~name1   ASCENDING,
                     acdoca~bldat ASCENDING
            INTO TABLE @it_r_data.

        LOOP AT it_r_data INTO wa_r_data.

        ENDLOOP.

      ELSEIF columnname = 'HSL'.
        REFRESH it_r_data.
        SELECT acdoca~rbukrs,
                   acdoca~kunnr,
                   kna1~name1,
                   acdoca~belnr,
                   acdoca~blart,
                   acdoca~bschl,
                   acdoca~bldat,
                   acdoca~budat,
                   acdoca~hsl,
                   dats_days_between( acdoca~budat, @p_budat ) AS age,
                   acdoca~prctr,
                   cepct~ktext
            FROM acdoca
                INNER JOIN kna1 ON kna1~kunnr = acdoca~kunnr
                INNER JOIN cepct ON cepct~prctr = acdoca~prctr
            WHERE acdoca~rbukrs IN @s_rbukrs
                AND acdoca~kunnr = @ls_kunnr-kunnr
                AND kna1~name1 = @ls_kunnr-name1
                AND ( acdoca~augdt IS INITIAL OR acdoca~augdt > @p_budat )
                AND acdoca~budat <= @p_budat
            ORDER BY acdoca~kunnr ASCENDING,
                     kna1~name1   ASCENDING,
                     acdoca~bldat ASCENDING
            INTO TABLE @it_r_data.

        LOOP AT it_r_data INTO wa_r_data.

        ENDLOOP.

      ENDIF.

    ELSE.
    ENDIF.

    CALL SCREEN 100 STARTING AT 15 03 ENDING AT 165 50.
  ENDMETHOD.

ENDCLASS.
1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
415

I didn't look at your code, but maybe this is just the answer you are looking for:

METHOD on_double_click.
  data(ref_to_row) = salv_tree->get_nodes( )->get_node( node_key )->get_data_row( ).
  FIELD-SYMBOLS <line> TYPE type_of_your_alv_tree_line. " is a structure
  ASSIGN ref_to_row->* TO <line>.
  ... "(continue working with components of <line>)
1 REPLY 1

Sandra_Rossi
Active Contributor
416

I didn't look at your code, but maybe this is just the answer you are looking for:

METHOD on_double_click.
  data(ref_to_row) = salv_tree->get_nodes( )->get_node( node_key )->get_data_row( ).
  FIELD-SYMBOLS <line> TYPE type_of_your_alv_tree_line. " is a structure
  ASSIGN ref_to_row->* TO <line>.
  ... "(continue working with components of <line>)