Visit the SAP Forum

Languages : English | Dutch | French | Portugese | Italian



INTERVIEW EBOOK
Get 30,000 Interview Questions & Answers in an eBook.

Interview Success Kit - Get Success in Job Interviews



Send your Resume to 6000 Companies
START YOUR WEBSITE
India's Best Web Hosting Company

Tree type report in ABAP


Home »ABAP Programming » Tree type report in ABAP


"Tree type report in ABAP

REPORT ZRJNTRIAL_TREE LINE-COUNT 65
LINE-SIZE 80
 NO STANDARD PAGE
HEADING.



********************************************************************* DATA: BEGIN OF ITEMS OCCURS 100, ID(10), PARENT_ID(10), TEXT(20), SYMBOL, END OF ITEMS, TABIX_STACK LIKE SY-TABIX OCCURS 10 WITH HEADER LINE, ITEMS_SHOW LIKE ITEMS OCCURS 100 WITH HEADER LINE. INCLUDE <SYMBOL>. * append sample items (mixed order) PERFORM APPEND_ITEM USING: '1' '' 'Food', '2' '' 'Drinks', '12' '9' 'Jack Daniels', '17' '11' 'Bosch', '3' '' 'Tools', '4' '1' 'Meat', '16' '11' 'Metabo', '5' '1' 'Chocolate', '6' '2' 'Alcoholic', '8' '4' 'Pork', '10' '5' 'Milka', '11' '3' 'Drills', '13' '9' 'Jim Beam', '7' '4' 'Beef', '14' '2' 'Non-alcoholic', '35' '31' 'Teran', '9' '6' 'Whiskey', '15' '14' 'Coca-cola', '18' '6' 'Wine', '28' '18' 'Croatia', '33' '28' 'Slavonia', '34' '28' 'Istria', '29' '18' 'Hungary', '30' '29' 'Tokaj', '19' '33' 'Enjingi', '20' '33' 'Zdjelarevic', '22' '19' 'Riesling', '23' '19' 'Chardonnay', '24' '20' 'Riesling', '32' '31' 'Malvazija', '25' '20' 'Merlot', '31' '34' 'Tomasevic'. * show initial list (items with level 0 - parentless items) LOOP AT ITEMS WHERE PARENT_ID = ''. MOVE-CORRESPONDING ITEMS TO ITEMS_SHOW. ITEMS_SHOW-SYMBOL = '+'. APPEND ITEMS_SHOW. ENDLOOP. PERFORM PRINT_TREE TABLES ITEMS_SHOW. * at line-selection - when the node is opened/closed or item double-clk AT LINE-SELECTION. READ TABLE ITEMS WITH KEY PARENT_ID = ITEMS_SHOW-ID. "see 'hide' IF SY-SUBRC = 0. "item has children - expand or collapse SY-LSIND = 0. PERFORM EXPAND_COLLAPSE USING ITEMS_SHOW-ID. PERFORM PRINT_TREE TABLES ITEMS_SHOW. ELSE. "item has NO children - perform some action READ TABLE ITEMS WITH KEY ID = ITEMS_SHOW-ID. WRITE: 'Action performed on item "' NO-GAP, ITEMS-TEXT NO-GAP, '", id.', ITEMS-ID. ENDIF. * form print_tree FORM PRINT_TREE TABLES ITEMS STRUCTURE ITEMS. DATA: V_TABIX LIKE SY-TABIX, START_TABIX LIKE SY-TABIX, V_LEVEL LIKE SY-TFILL, V_OFFSET TYPE I, V_ID LIKE ITEMS-ID, V_PARENT_ID LIKE ITEMS-PARENT_ID, V_PARENT_ID_FOR_VLINE LIKE ITEMS-PARENT_ID, V_PREV_LEVEL TYPE I, V_ITEMS_COUNT LIKE SY-TFILL, V_VLINES_STRING(200). CHECK NOT ITEMS[] IS INITIAL. SORT ITEMS BY PARENT_ID ID. READ TABLE ITEMS INDEX 1. V_PARENT_ID = ITEMS-PARENT_ID. START_TABIX = 1. REFRESH TABIX_STACK. DO. LOOP AT ITEMS FROM START_TABIX. V_TABIX = START_TABIX = SY-TABIX."remember current index V_ID = ITEMS-ID. V_PARENT_ID_FOR_VLINE = ITEMS-PARENT_ID. * decrease level and exit loop if parent not the same as previous IF ITEMS-PARENT_ID NE V_PARENT_ID. PERFORM READ_FROM_STACK CHANGING START_TABIX. "level = NoOfRecs READ TABLE ITEMS INDEX START_TABIX. V_PARENT_ID = ITEMS-PARENT_ID. ADD 1 TO START_TABIX. "next loop starts from parent index + 1 * clear vline IF V_LEVEL > 1. V_OFFSET = 2 + ( V_LEVEL - 2 ) * 3. IF V_LEVEL = 1. V_OFFSET = 1. ENDIF. V_VLINES_STRING+V_OFFSET = ' '. ENDIF. EXIT. ENDIF. V_PARENT_ID = ITEMS-PARENT_ID. * write item FORMAT COLOR OFF. DESCRIBE TABLE TABIX_STACK LINES V_LEVEL."level is no of StackRecs WRITE: / V_VLINES_STRING. V_OFFSET = V_LEVEL * 3. IF V_LEVEL NE 0. IF V_PREV_LEVEL < V_LEVEL. WRITE: AT V_OFFSET '|', / ''. WRITE: / V_VLINES_STRING. ENDIF. V_OFFSET = V_LEVEL * 3. WRITE AT V_OFFSET '|--'. ENDIF. V_OFFSET = V_OFFSET + 3. CASE ITEMS-SYMBOL. WHEN '+'. WRITE AT V_OFFSET SYM_PLUS_FOLDER AS SYMBOL COLOR 4 INTENSIFIED HOTSPOT. WHEN '-'. WRITE AT V_OFFSET SYM_MINUS_FOLDER AS SYMBOL COLOR 4 INTENSIFIED HOTSPOT. WHEN OTHERS. FORMAT COLOR 5. ENDCASE. WRITE: ITEMS-TEXT. V_PREV_LEVEL = V_LEVEL. HIDE: ITEMS-ID. ADD 1 TO V_ITEMS_COUNT. READ TABLE ITEMS WITH KEY PARENT_ID = ITEMS-ID. * increase level and exit loop if item has children IF SY-SUBRC = 0. START_TABIX = SY-TABIX. APPEND V_TABIX TO TABIX_STACK. "level is no of recs in stack V_PARENT_ID = ITEMS-PARENT_ID. * set vline V_TABIX = V_TABIX + 1. READ TABLE ITEMS INDEX V_TABIX. V_OFFSET = 2 + ( V_LEVEL - 1 ) * 3. IF V_LEVEL > 0. IF ITEMS-PARENT_ID = V_PARENT_ID_FOR_VLINE AND SY-SUBRC = 0. V_VLINES_STRING+V_OFFSET = '|'. ELSE. V_VLINES_STRING+V_OFFSET = ' '. ENDIF. ENDIF. EXIT. ENDIF. * at last - decrease level AT LAST. * clear vline IF V_LEVEL > 1. V_OFFSET = 2 + ( V_LEVEL - 2 ) * 3. IF V_LEVEL = 1. V_OFFSET = 1. ENDIF. V_VLINES_STRING+V_OFFSET = ' '. ENDIF. " next loop starts from parent index, not parent index + 1 " because of different parents level will decrease anyway PERFORM READ_FROM_STACK CHANGING START_TABIX. APPEND START_TABIX TO TABIX_STACK. "must return index to stack ENDAT. ENDLOOP. DESCRIBE TABLE ITEMS. IF START_TABIX > SY-TFILL OR V_ITEMS_COUNT >= SY-TFILL. EXIT. ENDIF. ENDDO. ENDFORM. * form expand_collapse FORM EXPAND_COLLAPSE USING VALUE(V_ID). DATA: V_NO_MORE_ORPHANS, ITEMS_TEMP LIKE ITEMS OCCURS 100 WITH HEADER LINE. DELETE ITEMS_SHOW WHERE PARENT_ID = V_ID. "try to collapse IF SY-SUBRC = 0. "succesfull first collapse DO. "cascade collapse - delete 'orphans' that are left REFRESH ITEMS_TEMP. MOVE ITEMS_SHOW[] TO ITEMS_TEMP[]. SORT ITEMS_TEMP BY ID. V_NO_MORE_ORPHANS = 'X'. LOOP AT ITEMS_SHOW WHERE PARENT_ID NE ''. READ TABLE ITEMS_TEMP WITH KEY ID = ITEMS_SHOW-PARENT_ID BINARY SEARCH TRANSPORTING NO FIELDS. IF SY-SUBRC NE 0. "no parent - it's an orphan CLEAR V_NO_MORE_ORPHANS. DELETE ITEMS_SHOW. ENDIF. ENDLOOP. IF V_NO_MORE_ORPHANS = 'X'. EXIT. ENDIF. ENDDO. ITEMS_SHOW-SYMBOL = '+'. MODIFY ITEMS_SHOW TRANSPORTING SYMBOL WHERE ID = V_ID. ELSE. "unsuccessfull collapse - expand ITEMS_SHOW-SYMBOL = '-'. MODIFY ITEMS_SHOW TRANSPORTING SYMBOL WHERE ID = V_ID. LOOP AT ITEMS WHERE PARENT_ID = V_ID. "show children APPEND ITEMS TO ITEMS_SHOW. ENDLOOP. LOOP AT ITEMS_SHOW WHERE PARENT_ID = V_ID. "check grandchildren READ TABLE ITEMS WITH KEY PARENT_ID = ITEMS_SHOW-ID. IF SY-SUBRC = 0. ITEMS_SHOW-SYMBOL = '+'. ELSE. ITEMS_SHOW-SYMBOL = ''. ENDIF. MODIFY ITEMS_SHOW. ENDLOOP. ENDIF. ENDFORM. * form append_item FORM APPEND_ITEM USING VALUE(ID) VALUE(PARENT_ID) VALUE(TEXT). ITEMS-ID = ID. ITEMS-PARENT_ID = PARENT_ID. ITEMS-TEXT = TEXT. APPEND ITEMS. ENDFORM. * form read_from_stack FORM READ_FROM_STACK CHANGING TABIX LIKE SY-TABIX. DESCRIBE TABLE TABIX_STACK. CHECK SY-TFILL NE 0. READ TABLE TABIX_STACK INDEX SY-TFILL. TABIX = TABIX_STACK. DELETE TABIX_STACK INDEX SY-TFILL. ENDFORM.
A D V E R T I S E M E N T

A D V E R T I S E M E N T

S A P - R E S O U R C E S


Get Free SAP Resources:

Are you looking for:
  • SAP Jobs
  • Free SAP eBooks
  • SAP Softwares
  • SAP Tutorials
  • ERP Implementation Examples
Enter Email Address:
(Enter your email address above and we will instantly send you the download link to you, when you confirm your email.)
Search SAP Resources:
discussionDiscussion Center
Discuss
Discuss

Query

Feedback
Yahoo Groups
Y! Group
Sirfdosti Groups
Sirfdosti
Contact Us
Contact
Sign in

User Name:
Password:
Forget password? | Register


INTERVIEW EBOOK

Get 30,000 Interview Questions & Answers in an eBook.

Interview Success Kit - Get Success in Job Interviews


Send your Resume to 6000 Companies

SAP Resources

  • SAP Articles
  • SAP Books
  • SAP Certifications
  • SAP Companies
  • SAP Study Materials
  • SAP Events
  • SAP Faqs
  • SAP Jobs
  • SAP Job Consultants
  • SAP Links
  • SAP News
  • SAP Sample Papers
  • SAP Interview Questions
  • SAP Training Institutes
  •  
    SAP Tutorial

  • Introduction
  • SAP History
  • SAP Facts
  • SAP Tables
  • SAP Function
  • SAP Report
  • Reasons To Use SAP
  • SAP Landscape
  • SAP Transaction Code
  • SAP Lotus Notes Integration
  • Business Connector and XML
  • Enterprise Release 4.7

  • SAP Training Institutes

  • SAP Training Institutes
  • Job Consultants Address
  • SAP Companies Address

  • Business Process Cycle

  • Analyze
  • Design
  • Implement
  • Operate
  • Optimize
  • Skills And Education

  • Logistics Module

  • Sales and Distribution
  • Quality Management
  • Materail Management
  • Plant Maintenance
  • Financial Modules (FI/CO)
  • Project system
  • Production Planning
  • Service Management

  • SAP NetWeaver

  • Introduction
  • Object Model
  • Interoperability
  • Creating Web Apps
  • Java Connector
  • Advantages & Conclusion
  • Life Cycle Management
  • Composite Application Framework

  • SAP Tools

  • SQL Trace Tool
  • SAP CRM
  • SAP SRM
  • SAP SCM
  • SAP ERP
  • SAP BW

  • SAP Modules

  • SAP FI Module
  • SAP CO Module

  • SAP Technical

  • SAP ITS Architecture
  • Financial Management
  • Manufacturing Planning and Execution
  • Customer Order Management
  • Lackbox Processing
  • SD and Financial Accounting Integration
  • SAP - HR (Human Resource)

  • SAP Miscellanous

  • Web Application Server(WAS)
  • Data Archiving
  • Mobile Engine
  • SAP Script
  • SAP Transactions
  • SAP Business Warehouse(BW)

  • SAP Reference

  • SAP Facts
  • SAP Tables
  • SAP Function
  • SAP Report
  • SAP Landscape

  • SAP Others

  • SAP Treasury
  • SAP Finance
  • SAP WAS
  • SAP Data Archiving
  • SAP ALE
  • SAP EDI
  • SAP Exchange
  • SAP X-APPS
  • SAP Applications Components
  • SAP Software
  • Dunning
  • SAP IDES
  • SAP Payroll Basics
  • SAP BASIS and Security Authorization
  • SAP Backup
  • SAP Router

  • ABAP Tutorials

  • Introduction
  • ABAP Transaction
  • ABAP Function
  • ABAP File Processing
  • ABAP Objects
  • ABAP Syntax
  • ABAP Queries
  • SAPMail Using ABAP
  • ABAP Programming Hints

  • SAP Projects & Codes

  • Finding the user-exits
  • Purchase Order Display
  • Batch Input
  • Dynamic Open SQL
  • Creating Extract Dataset
  • Reading database tables
  • Load table from a UNIX file
  • Create subscreen

  • SAP Resources

  • SAP Books
  • SAP Links

  • Interview Question



  • Common Interview Que.
  • ABAP Interview Que.
  • ERP Interview Que.
  • HR Interview Que.
  • MM Interview Que.
  • PP Interview Que.
  • ALE Interview Que.
  • EDI Interview Que.
  • Basis Interview Questions
  • SAP-SD Interview Questions
  • FI&CO Interview Questions
  • BW Interview Questions
  • CRM Interview Questions
  • Interview Questions

  • Careers at SAP

  • Careers in SAP (SAP Jobs)
  • Advertise
  •