Application Development and Automation 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: 
Read only

Problem in LOOPING in Tree View

Former Member
0 Likes
1,016

Dear Experts,

I am new to ABAP , hence some basic questions.

I have a Ztable and want its contents to be displayed in tree View form and also be able to maintain ( Delete, Change, add new items ) to it and hence it should pass to the Ztable too.

At present I am trying this code in se38

ZTables: ZLT_auftrag1: has fields A1, A2, A3, A4,P1, P2, P3

               A3 is the key field.

I want the fields to appear in tree view as:

     (A3)

          (A1 and A2)

               (P1 and P2)

i.e. when you click on (A3) then (A1 and A2) appears and when you clcik on (A1 and A2) then (P1 and P2) appears.

The code follows ( There is some problem in LOOPING)---> Can some on suggest me a better way to loop correctly to get the fields in proper order:

The actual ZTable: ZlT_auftrag1 (refer attachment)

And the outcome of the below code when K3 = MOS (refer Screen shot)

REPORT  ZTREE_AUFTRAG1.

TABLES: ZLT_auftrag1.

TYPES: Begin of ty_auftrag,

         Level(2),

         A1 LIKE ZLT_auftrag1-A1,

         A2 LIKE ZLT_auftrag1-A2,

         A3 LIKE ZLT_auftrag1-A3,

         A4 LIKE ZLT_auftrag1-A4,

         P1 LIKE ZLT_auftrag1-P1,

         P2 LIKE ZLT_auftrag1-P2,

         P3 LIKE ZLT_auftrag1-P3,

      End OF ty_auftrag.

DATA: it_auftrag  TYPE TABLE OF ty_auftrag,

      wa_auftrag  LIKE LINE  OF it_auftrag,

      it_temp     TYPE TABLE OF ty_auftrag,

      wa_temp     LIKE LINE  OF it_temp,

      it_work     TYPE TABLE OF ty_auftrag,

      wa_work     LIKE LINE  OF it_work.

DATA: Begin OF it_Nodes Occurs 0.

        Include Structure Snodetext.

DATA: END OF it_Nodes.

CONSTANTS: NUMBER_OF_LEVELS TYpe i Value 3.

data  Make_Node.

Parameter:  P_A3  LIKE  ZLT_Auftrag1-A3.

START-OF-SELECTION.

*Parent = 1. Hierarchy node.

  wa_temp-A3  = P_A3.

  Append wa_temp  To it_temp.

  WA_work-A3  = WA_temp-A3.

  WA_WORK-LEVEL = 1.

  Append WA_Work TO it_work.

*Reading Auftrag hierarcy (Maximum 6 Level)

DO Number_OF_LEVELS TIMES.

    Check NOT it_TEMP IS INITIAL.

    SELECT A3 A1 A2 P1

      From ZLT_Auftrag1

      INTO CORRESPONDING Fields Of Table it_auftrag

      For ALL Entries in it_temp

      Where A3 = it_temp-A3.

    LOOP AT IT_Auftrag into WA_Auftrag.

     WA_Auftrag-Level = sy-index + 1.

     Append WA_Auftrag to it_work.

    ENDLOOP.

   IT_TEMP[] = IT_Auftrag[].

ENDDO.

*Hierarchy  nodes--> Tree Control

LOOP at it_work Into wa_work where Level = 1.

    Perform Make_Node.

  LOOP at it_work Into wa_work Where Level = 2 AND

        A3 = WA_Work-A3.

*        A1 = WA_Work-A1.

        Perform Make_Node.

    LOOP at it_work INTO wa_work Where Level = 3 AND

            A3 = WA_Work-A3 AND

            P1 = WA_Work-P1.

            Perform Make_Node1.

   ENDLOOP.

  ENDLOOP.

ENDLOOP.

*Making the tree Control

CALL FUNCTION 'RS_TREE_CONSTRUCT'

* EXPORTING

*   INSERT_ID                = '000000'

*   RELATIONSHIP             = ' '

*   LOG                      =

  TABLES

    nodetab                  = it_nodes

EXCEPTIONS

   TREE_FAILURE             = 1

*   ID_NOT_FOUND             = 2

*   WRONG_RELATIONSHIP       = 3

*   OTHERS                   = 4

*Display the tree Control

DATA: F15 TYPE c.

CALL FUNCTION 'RS_TREE_LIST_DISPLAY'

EXPORTING

   CALLBACK_PROGRAM                = sy-repid

IMPORTING

   F15                             = F15

*******************************************************************          .

form Make_Node .

  it_nodes-name  = wa_work-A1.

  it_nodes-color = 1.

  it_nodes-intensiv  = 1.

  it_nodes-Text = wa_work-A1.

  it_nodes-Tlength = 30.

  it_nodes-tlevel = wa_work-Level.

  it_nodes-tcolor = 1.

  it_nodes-Tintensiv = 1.

  Append it_nodes.

endform.                    " Make_Node

*******************************************************************

form Make_Node1 .

  it_nodes-name  = wa_work-P1.

  it_nodes-color = 1.

  it_nodes-intensiv  = 1.

  it_nodes-Text = wa_work-P1.

  it_nodes-Tlength = 40.

  it_nodes-tlevel = wa_work-Level.

  it_nodes-tcolor = 1.

  it_nodes-Tintensiv = 1.

  Append it_nodes.

endform.                    " Make_Node1

LOOKing forward for advice from you experts.

Regards

Deepika

3 REPLIES 3
Read only

former_member206650
Active Participant
0 Likes
962

This message was moderated.

Read only

0 Likes
962

Hi Vishnu,

Thanks,

Is it possible to manage (add, edit, delete) the Ztables data through ALV tree

Regards

Deepika

Read only

former_member206650
Active Participant
0 Likes
962

hi,

you can use the class cl_gui_avi_tree....