Zi fi final prog

462 views

Published on

program for cash flow

Published in: Technology, Sports
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
462
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Zi fi final prog

  1. 1. *&--------------------------------------------------------------------- * *& Report ZFI_REPORT *& *&--------------------------------------------------------------------- * *& *& *&--------------------------------------------------------------------- * REPORT ZFI_REPORT LINE-COUNT 65 LINE-SIZE 80 NO STANDARD PAGE HEADING. INCLUDE <LIST>. TABLES: SKB1, BSIS. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TASK 1 DECLARATION &&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&& TYPES: BEGIN OF ST1, GL_CODE TYPE SKB1-SAKNR, GL_DESC TYPE SKAT-TXT50, BALANCE_AMOUNT TYPE NETWR, "BAPI3006_3-BALANCE, "TYPE N LENGTH 12, END OF ST1. TYPES: BEGIN OF ST_I, BUKRS TYPE BAPI3006_0-COMP_CODE, "SKB1-BUKRS, SAKNR TYPE BAPI3006_0-GL_ACCOUNT, "SKB1-SAKNR, CR_TYPE TYPE BAPI3006_5-CURR_TYPE, "/SAPPCE/TDPC22-CURR_TYPE, END OF ST_I. TYPES: BEGIN OF ST_D, SAKNR TYPE SKAT-SAKNR, TXT50 TYPE SKAT-TXT50, END OF ST_D. TYPES: BEGIN OF ST2, BUKRS TYPE SKB1-BUKRS, SAKNR TYPE SKB1-SAKNR, END OF ST2. DATA: IT1F TYPE TABLE OF ST1, WA1F TYPE ST1, IT1I TYPE TABLE OF ST_I, WA1I TYPE ST_I, IT1D TYPE TABLE OF ST_D, WA1D TYPE ST_D, IT12 TYPE TABLE OF ST2, WA12 TYPE ST2, IT12_INPUT TYPE STANDARD TABLE OF ST2, WA12_INPUT TYPE ST2, IT_BALANCE TYPE BAPI3006_3, IT_RETURN LIKE BAPIRETURN. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&
  2. 2. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TASK 2 DECLARATION &&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&& TYPES: BEGIN OF ST21, BUKRS TYPE BSID-BUKRS, KUNNR TYPE BSID-KUNNR, ZFBDT TYPE BSID-ZFBDT, END OF ST21. TYPES: BEGIN OF ST2F, KUNNR TYPE BSID-KUNNR, NAME1 TYPE KNA1-NAME1, FAEDT TYPE RFPOS-FAEDT, PSWBT TYPE RFPOS-PSWBT, BELNR TYPE BSID-BELNR, END OF ST2F. TYPES: BEGIN OF ST22, NAME1 TYPE KNA1-NAME1, KUNNR TYPE KNA1-KUNNR, END OF ST22. DATA: IT21 TYPE TABLE OF ST21, WA21 TYPE ST21, IT22 TYPE TABLE OF ST22, WA22 TYPE ST22, IT21_T TYPE TABLE OF ST21, WA21_T TYPE ST21, IT2_O TYPE STANDARD TABLE OF RFPOS , WA2_O TYPE RFPOS, IT2F TYPE TABLE OF ST2F, WA2F TYPE ST2F, W_DATE1 TYPE BSID-ZFBDT." LENGTH 12. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&& *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TASK 3 DECLARATION &&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&& TYPES: BEGIN OF S1, BUKRS TYPE BAPI3008_1-COMP_CODE, "BSIK-BUKRS, LIFNR TYPE BAPI3008_1-VENDOR , "BSIK-LIFNR, ZFBDT TYPE BAPI3008-KEY_DATE , " BSIK-ZFBDT, BELNR TYPE BSIK-BELNR, END OF S1. TYPES: BEGIN OF ST3, LIFNR TYPE LFA1-LIFNR, NAME1 TYPE LFA1-LIFNR, END OF ST3. TYPES: BEGIN OF STF,
  3. 3. LIFNR TYPE BAPI3008_1-VENDOR , "BSIK-LIFNR, NAME1 TYPE LFA1-LIFNR, LC_AMOUNT TYPE BAPI3008_2-LC_AMOUNT, BLINE_DATE TYPE BAPI3008_2-BLINE_DATE, BELNR TYPE BSIK-BELNR, END OF STF. DATA: IT1 TYPE STANDARD TABLE OF S1, WA1 TYPE S1, ITO TYPE TABLE OF BAPI3008_2, WAO TYPE BAPI3008_2, IT2 TYPE STANDARD TABLE OF ST3, WA2 TYPE ST3, ITF TYPE STANDARD TABLE OF STF, WAF TYPE STF, TOTAL1 TYPE N LENGTH 12, TOTAL2 TYPE N LENGTH 12, TOTAL3 TYPE N LENGTH 12, TOTAL4 TYPE N LENGTH 12, TOTAL TYPE P LENGTH 12. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&& *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TASK 4 DECLARATION &&&&&&&&&&& &&&&&&&&&&&&&&& TYPES: BEGIN OF ST41, BUKRS TYPE BSIS-BUKRS, HKONT TYPE BSIS-HKONT, BUDAT TYPE BSIS-BUDAT, DMBTR TYPE BSIS-DMBTR, BELNR TYPE BSIS-BELNR, END OF ST41. TYPES: BEGIN OF ST42, BUKRS TYPE BSIS-BUKRS, HKONT TYPE BSIS-HKONT, BUDAT TYPE BSIS-BUDAT, DMBTR TYPE BSIS-DMBTR, TXT50 TYPE SKAT-TXT50, END OF ST42. TYPES: BEGIN OF ST43, TXT50 TYPE SKAT-TXT50, SAKNR TYPE SKAT-SAKNR, END OF ST43. DATA: IT41 TYPE STANDARD TABLE OF ST41, WA41 TYPE ST41, IT42 TYPE STANDARD TABLE OF ST42, WA42 TYPE ST42, IT43 TYPE STANDARD TABLE OF ST43, WA43 TYPE ST43.
  4. 4. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&& *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TASK5 DECLARATION &&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&& TYPES: BEGIN OF S51, TXT50 TYPE SKAT-TXT50, TOTAL TYPE NETWR, END OF S51. DATA: IT51 TYPE STANDARD TABLE OF S51, WA51 TYPE S51. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *** Data Declarations *** TYPES: BEGIN OF S_items, id TYPE N LENGTH 3, parent_id TYPE N LENGTH 3, text TYPE C LENGTH 50, symbol TYPE C, END OF S_items. *DATA: tabix_stack LIKE sy-tabix OCCURS 10 WITH HEADER LINE, * items_show LIKE items OCCURS 100 WITH HEADER LINE. DATA: TABIX_STACK TYPE STANDARD TABLE OF SY-TABIX WITH HEADER LINE , ITEMS TYPE STANDARD TABLE OF S_ITEMS WITH HEADER LINE, ITEMS_SHOW TYPE STANDARD TABLE OF S_ITEMS WITH HEADER LINE. SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001. SELECT-OPTIONS: S_BUKRS FOR SKB1-BUKRS , S_BUDAT FOR BSIS-BUDAT , B_SAKNR FOR SKB1-SAKNR , P_SAKNR FOR SKB1-SAKNR . SELECTION-SCREEN END OF BLOCK B1. *START-OF-SELECTION. *PERFORM TASK1. *PERFORM TASK2. *PERFORM TASK3. *PERFORM TASK4. *PERFORM TASK5. *PERFORM APPEND. *FORM TASK1. IF B_SAKNR IS NOT INITIAL. SELECT TXT50 SAKNR FROM SKAT INTO CORRESPONDING FIELDS OF TABLE IT1D
  5. 5. WHERE SAKNR IN B_SAKNR. ENDIF. SELECT BUKRS SAKNR FROM SKB1 INTO CORRESPONDING FIELDS OF TABLE IT12 WH ERE SAKNR IN B_SAKNR. IF IT12 IS NOT INITIAL. LOOP AT B_SAKNR. LOOP AT IT12 INTO WA12 WHERE SAKNR = B_SAKNR-LOW. WA12_INPUT-BUKRS = WA12-BUKRS. WA12_INPUT-SAKNR = WA12-SAKNR. APPEND WA12_INPUT TO IT12_INPUT. CLEAR WA12_INPUT. ENDLOOP. ENDLOOP. LOOP AT IT12_INPUT INTO WA12_INPUT. WA1I-BUKRS = WA12_INPUT-BUKRS. WA1I-SAKNR = WA12_INPUT-SAKNR. WA1I-CR_TYPE = 10. APPEND WA1I TO IT1I. CLEAR WA1I. ENDLOOP. ENDIF. *PERFORM BAPI1. *ENDFORM. *FORM BAPI1. CLEAR TOTAL1. LOOP AT IT1I INTO WA1I. READ TABLE IT1D INTO WA1D WITH KEY SAKNR = WA1I-SAKNR."INDEX SY- TABIX. CALL FUNCTION 'BAPI_GL_ACC_GETCURRENTBALANCE' EXPORTING COMPANYCODE = WA1I-BUKRS GLACCT = WA1I-SAKNR CURRENCYTYPE = WA1I-CR_TYPE IMPORTING ACCOUNT_BALANCE = IT_BALANCE. * RETURN = CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING WAIT = 'X'.
  6. 6. * IMPORTING * RETURN = WA1F-GL_DESC = WA1D-TXT50. WA1F-GL_CODE = WA1I-SAKNR. WA1F-BALANCE_AMOUNT = IT_BALANCE-BALANCE. TOTAL1 = TOTAL1 + IT_BALANCE-BALANCE. APPEND WA1F TO IT1F. CLEAR: WA1F,IT_BALANCE,WA1D. DELETE IT1F WHERE BALANCE_AMOUNT = 0. ENDLOOP. *ENDFORM. ***FORM TASK2. ** SELECT BUKRS KUNNR ZFBDT FROM BSID INTO CORRESPONDING FIELDS OF TABLE I T21 WHERE BUKRS IN S_BUKRS. DELETE ADJACENT DUPLICATES FROM IT21 COMPARING KUNNR. IF IT21 IS NOT INITIAL. SELECT KUNNR NAME1 FROM KNA1 INTO CORRESPONDING FIELDS OF TABLE IT22 FOR ALL ENTRIES IN IT21 WHERE KUNNR = IT21-KUNNR. LOOP AT IT21 INTO WA21. LOOP AT IT22 INTO WA22 WHERE KUNNR = WA21-KUNNR. concatenate WA21-ZFBDT+6(2) WA21-ZFBDT+4(2) WA21-ZFBDT+0(4) into w_date1 separated by '.'. CALL FUNCTION 'CUSTOMER_OPEN_ITEMS' EXPORTING BUKRS = WA21-BUKRS KUNNR = WA21-KUNNR * KKBER = STIDA = W_DATE1 "WA21-ZFBDT TABLES T_POSTAB = IT2_O EXCEPTIONS NO_OPEN_ITEMS = 1 OTHERS = 2 . IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. LOOP AT IT2_O INTO WA2_O. WA2F-KUNNR = WA22-KUNNR. WA2F-NAME1 = WA22-NAME1. WA2F-FAEDT = WA21-ZFBDT."WA2_O-FAEDT. WA2F-PSWBT = WA2_O-PSWBT. WA2F-BELNR = WA2_O-BELNR.
  7. 7. TOTAL2 = TOTAL2 + WA2_O-PSWBT. APPEND WA2F TO IT2F. CLEAR: WA2F,WA2_O. ENDLOOP. ENDLOOP. DELETE ADJACENT DUPLICATES FROM IT2F COMPARING BELNR. ENDLOOP. ENDIF. *ENDFORM. **************FORM TASK3. ************* *************SELECT BUKRS LIFNR ZFBDT BELNR ************* FROM BSIK INTO CORRESPONDING FIELDS OF TABLE IT1 ************* WHERE BUKRS IN S_BUKRS. ************* *************IF IT1 IS NOT INITIAL. ************* SELECT LIFNR NAME1 ************* FROM LFA1 INTO CORRESPONDING FIELDS OF TABLE IT2 ************* FOR ALL ENTRIES IN IT1 ************* WHERE LIFNR = IT1-LIFNR. ************* *************ENDIF. ************* *************LOOP AT IT1 INTO WA1. ************* LOOP AT IT2 INTO WA2 WHERE LIFNR = WA1-LIFNR. ************* IF WA1-BELNR NE SPACE. ************* CALL FUNCTION 'BAPI_AP_ACC_GETOPENITEMS' ************* EXPORTING ************* COMPANYCODE = WA1-BUKRS ************* VENDOR = WA1-LIFNR ************* KEYDATE = WA1-ZFBDT ************** NOTEDITEMS = ' ' ************** IMPORTING ************** RETURN = ************* TABLES ************* LINEITEMS = ITO. ************* ************* LOOP AT ITO INTO WAO. ************* ************* WAF-LIFNR = WAO-VENDOR. ************* WAF-BLINE_DATE = WAO-BLINE_DATE. ************* WAF-LC_AMOUNT = WAO-LC_AMOUNT. ************* WAF-NAME1 = WA2-NAME1. ************* WAF-BELNR = WA1-BELNR. ************* TOTAL3 = TOTAL3 + WAO-LC_AMOUNT. ************* ************* APPEND WAF TO ITF. ************* CLEAR: WAF, WA1. ************* ************* ENDLOOP. ************* ENDIF. ************* ENDLOOP. *************ENDLOOP. *************
  8. 8. *************DELETE ADJACENT DUPLICATES FROM ITF COMPARING BELNR. ************* ************** ENDFORM. ************* **************FORM TASK4. ************* *************SELECT HKONT BUDAT DMBTR BUKRS BELNR FROM BSIS INTO CORRES PONDING FIELDS OF TABLE IT41 ************* WHERE BUKRS IN S_BUKRS AND HKONT IN P_SAKNR. ************* *************SELECT TXT50 SAKNR FROM SKAT INTO CORRESPONDING FIELDS OF TABLE IT43 WHERE SAKNR IN P_SAKNR. ************* *************IF SY-SUBRC EQ 0. ************* DELETE ADJACENT DUPLICATES FROM IT41 COMPARING BELNR. ************* ************* ************* LOOP AT IT41 INTO WA41. ************* READ TABLE IT43 INTO WA43 WITH KEY SAKNR = WA41-HKONT. ************* ************* WA42-HKONT = WA41-HKONT. ************* WA42-BUDAT = WA41-BUDAT. ************* WA42-DMBTR = WA41-DMBTR. ************* WA42-BUKRS = WA41-BUKRS. ************* WA42-TXT50 = WA43-TXT50. ************* ************* TOTAL4 = TOTAL4 + WA41-DMBTR. ************* ************* APPEND WA42 TO IT42. ************* CLEAR WA42. ************* ************* ENDLOOP. ************* *************ENDIF. ************** ENDFORM. ************* ************* ************** FORM TASK5. ************* *************TOTAL = TOTAL1 + TOTAL2. *************TOTAL = TOTAL - TOTAL3. *************TOTAL = TOTAL - TOTAL4. ************* *************WA51-TXT50 = 'CASH FLOW STATEMENT OF MICROSUPREME'. *************WA51-TOTAL = TOTAL. *************APPEND WA51 TO IT51. ************* ************* ************** ENDFORM. *&&&&&&&&&&&&&&&&&&&&&&&&&&& APPEND FIRST TABLE DATA &&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&& *FORM APPEND1. DATA: COUNT1 TYPE N LENGTH 4, text_temp1 type string , temp1 type c length 15. COUNT1 = 4.
  9. 9. TYPES:BEGIN OF S_COUNT, GL_CODE TYPE SKB1-SAKNR, GL_DESC TYPE SKAT-TXT50, BALANCE_AMOUNT TYPE NETWR, COUNT TYPE N LENGTH 3, END OF S_COUNT. DATA: IT_COUNT11 TYPE STANDARD TABLE OF S_COUNT, WA_COUNT11 TYPE S_COUNT, IT_COUNT12 TYPE STANDARD TABLE OF S_COUNT, WA_COUNT12 TYPE S_COUNT. TEMP1 = 'BANK BALANCE'. CONCATENATE TEMP1 TOTAL1 INTO TEXT_TEMP1 SEPARATED BY SPACE. PERFORM append_item USING: '1' '' TEXT_TEMP1. "'BANK BALANCE'. LOOP AT IT1F INTO WA1F. CLEAR TEMP1. temp1 = WA1F-BALANCE_AMOUNT. CONCATENATE WA1F-GL_CODE WA1F-GL_DESC temp1 into text_temp1 SEPARATED by space. PERFORM append_item USING: COUNT1 '1' text_temp1. "WA1F-GL_CODE. * WA_COUNT11-GL_CODE = WA1F-GL_CODE. * WA_COUNT11-COUNT = COUNT1. * APPEND WA_COUNT11 TO IT_COUNT11. * CLEAR: WA1F, WA_COUNT11. * COUNT1 = COUNT1 + 1. ENDLOOP. *COUNT1 = COUNT1 + 2. *LOOP AT IT1F INTO WA1F. * LOOP AT IT_COUNT11 INTO WA_COUNT11 WHERE GL_CODE = WA1F-GL_CODE. * PERFORM append_item USING: COUNT1 WA_COUNT11-COUNT WA1F-GL_DESC. "COUNT1 WA_COUNT11-COUNT * * WA_COUNT12-GL_DESC = WA1F-GL_DESC. * WA_COUNT12-COUNT = COUNT1 . * APPEND WA_COUNT12 TO IT_COUNT12. * CLEAR: WA1F, WA_COUNT12. * COUNT1 = COUNT1 + 1. * ENDLOOP. *ENDLOOP. * * * *COUNT1 = COUNT1 + 2. *LOOP AT IT1F INTO WA1F. * LOOP AT IT_COUNT12 INTO WA_COUNT12 WHERE GL_DESC = WA1F-GL_DESC. * PERFORM append_item USING: COUNT1 WA_COUNT12-COUNT WA1F- BALANCE_AMOUNT. "COUNT1 WA_COUNT12-COUNT * COUNT1 = COUNT1 + 1. *
  10. 10. * CLEAR: WA_COUNT11, WA1F, WA_COUNT12. * * ENDLOOP. *ENDLOOP. *REFRESH: IT_COUNT11[],IT_COUNT12[]. **ENDFORM. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&& **&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& APPEND SECOND TABLE DATA &&&&&&& &&&&&&&&&&&&&&&&&&&&&&&& DATA: COUNT2 TYPE N LENGTH 4, temp2 type c length 20, text_temp2 type string. COUNT2 = 7. TYPES: BEGIN OF S_COUNT2, KUNNR TYPE BSID-KUNNR, NAME1 TYPE KNA1-NAME1, FAEDT TYPE RFPOS-FAEDT, PSWBT TYPE RFPOS-PSWBT, COUNT TYPE N LENGTH 3, END OF S_COUNT2. DATA: IT_COUNT21 TYPE STANDARD TABLE OF S_COUNT2, WA_COUNT21 TYPE S_COUNT2, IT_COUNT22 TYPE STANDARD TABLE OF S_COUNT2, WA_COUNT22 TYPE S_COUNT2. PERFORM append_item USING: '2' '' 'VENDOR BALANCE'. LOOP AT IT2F INTO WA2F. temp2 = wa2f-pswbt. CONCATENATE WA2F-KUNNR WA2F-NAME1 WA2F-FAEDT temp2 into text_temp2. PERFORM append_item USING: COUNT2 '2' text_temp2. "WA2F-KUNNR. COUNT2 = COUNT2 + 1. WA_COUNT21-KUNNR = WA2F-KUNNR. WA_COUNT21-COUNT = COUNT2. APPEND WA_COUNT21 TO IT_COUNT21. CLEAR: WA2F,WA_COUNT21. ENDLOOP. *COUNT2 = COUNT2 + 2. *LOOP AT IT2F INTO WA2F. * LOOP AT IT_COUNT21 INTO WA_COUNT21 WHERE KUNNR = WA2F-KUNNR. * PERFORM append_item USING: COUNT2 WA_COUNT21-COUNT WA2F-NAME1. * COUNT2 = COUNT2 + 1. * * WA_COUNT22-NAME1 = WA2F-NAME1. * WA_COUNT22-COUNT = COUNT2. * APPEND WA_COUNT22 TO IT_COUNT22. * CLEAR: WA2F,WA_COUNT21.
  11. 11. *ENDLOOP. *ENDLOOP. * *REFRESH IT_COUNT21[]. *COUNT2 = COUNT2 + 1. *LOOP AT IT2F INTO WA2F. * LOOP AT IT_COUNT22 INTO WA_COUNT22 WHERE NAME1 = WA2F-NAME1. * PERFORM append_item USING: COUNT2 WA_COUNT22-COUNT WA2F-FAEDT. * COUNT2 = COUNT2 + 1. * * WA_COUNT21-FAEDT = WA2F-FAEDT. * WA_COUNT21-COUNT = COUNT2. * CLEAR WA2F. *ENDLOOP. *ENDLOOP. * *COUNT2 = COUNT2 + 1. *LOOP AT IT2F INTO WA2F. * LOOP AT IT_COUNT21 INTO WA_COUNT21 WHERE FAEDT = WA2F-FAEDT. * PERFORM append_item USING: COUNT2 WA_COUNT21-COUNT WA2F-PSWBT. * COUNT2 = COUNT2 + 1. * * CLEAR WA2F. *ENDLOOP. *ENDLOOP. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&& *&&&&&&&&&&&&&&&&&&&&&&&&&&& APPEND DATA FOR THIRD TABLE &&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&& *&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&& *** To Append The Items *** *PERFORM append_item USING: * **** Items Under 1st Level 0 Node * '1' '' 'Drinks', * '4' '1' 'Cold Drinks', * '7' '4' 'Coke', * '8' '4' 'Milk Shakes', * '5' '1' 'Hot Drinks',
  12. 12. * '10' '5' 'Hot Coffee', * * * * **** Items Under 2nd Level 0 Node * '2' '' 'Yummys', * '14' '2' 'Puffs', * '15' '14' 'Veg Puff', * '6' '2' 'Pizza', * '18' '6' 'Veg', * '28' '18' 'Special Pizzas', * '33' '28' 'Thick Crust', * '19' '33' 'Medium', * '22' '19' 'Veg Cheesy', * '23' '19' 'Schezwan Treat', * '20' '33' 'Large', * '24' '20' 'Veg Supreme', * '25' '20' 'Pep n Corn', * '34' '28' 'Thin Crust', * '31' '34' 'Medium', * '32' '31' 'Jain Special', * '35' '31' 'Veggie Delite', * '29' '18' 'Indian', * '30' '29' 'Punjabi Paneer Pizza', * '9' '6' 'Non-Veg', * '12' '9' 'Shredded Chicken Pizza', * '13' '9' 'Spicy Chicken Pizza', * * **** Items Under 3rd Level 0 Node * '11' '3' 'Payment', * '3' '' 'Bill', * '16' '11' 'By Cash', * '17' '11' 'By Card'. *** To Show Items At Level 0, Which Are Also Known As 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. *** When A Node Is Expanded / Collapsed / Any Item Is Double Clicked ** * AT LINE-SELECTION. READ TABLE items WITH KEY parent_id = items_show-id. "se e 'hide' IF sy-subrc = 0. "it em has children - expand or collapse sy-lsind = 0.
  13. 13. 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. *** To 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. "to remember current index v_id = items-id. v_parent_id_for_vline = items-parent_id. *** Decrease The Level & Exit The Loop If The Parent Is Not Same As The Previous *** IF items-parent_id NE v_parent_id. PERFORM read_from_stack CHANGING start_tabix. "level equals to number of records READ TABLE items INDEX start_tabix. v_parent_id = items-parent_id. ADD 1 TO start_tabix. "next loop starts from parent index + 1 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.
  14. 14. ENDIF. v_parent_id = items-parent_id. *** To Write Item *** FORMAT COLOR OFF. DESCRIBE TABLE tabix_stack LINES v_level. "level is no of Stack Records 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 The Level & Exit The Loop If The Item Has Children *** IF sy-subrc = 0. start_tabix = sy-tabix. APPEND v_tabix TO tabix_stack. "level is no of records in stack v_parent_id = items-parent_id. 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.
  15. 15. *** Decrease Level *** AT LAST. 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. "PRINT_TREE *** Form For Expanding & Collapsing The Tree Nodes *** 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. "first collapse sussessful 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. "u nsuccessful collapse - expand items_show-symbol = '-'. MODIFY items_show TRANSPORTING symbol WHERE id = v_id.
  16. 16. LOOP AT items WHERE parent_id = v_id. "s how children APPEND items TO items_show. ENDLOOP. LOOP AT items_show WHERE parent_id = v_id. "c heck 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. "EXPAND_COLLAPSE *&--------------------------------------------------------------------* *& Form APPEND_ITEM *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * -->VALUE(ID) text * -->VALUE(PARENtext) * -->VALUE(TEXT)text *---------------------------------------------------------------------* 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. "APPEND_ITEM *&--------------------------------------------------------------------* *& Form READ_FROM_STACK *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * -->TABIX text *---------------------------------------------------------------------* 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. "READ_FROM_STACK

×