SAP ABAP Tree Report

 ABAP Code to Display Data in Tree format.




*&---------------------------------------------------------------------*
*& Report ZDEMO_TREE_REPORT1
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZDEMO_TREE_REPORT1.

tables : ekko.


data : gt_node type STANDARD TABLE OF SNODETEXT,
       gs_node type SNODETEXT.


SELECTION-SCREEN begin of BLOCK b1 with FRAME TITLE text-001.
  SELECT-OPTIONS : s_ebeln for ekko-ebeln,
                   s_aedat for ekko-aedat,
                   s_lifnr for ekko-lifnr,
                   s_bukrs for ekko-bukrs.
SELECTION-SCREEN end of BLOCK b1.


START-OF-SELECTION.

     perform get_build_data.


end-of-SELECTION.
*&---------------------------------------------------------------------*
*& Form get_build_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM get_build_data .


"PO header
    select ebeln, bukrs, aedat, lifnr, rlwrt
    from ekko into table @data(gt_ekko)
    WHERE ebeln in @s_ebeln
      and bukrs in @s_bukrs
      and aedat in @s_aedat
      and lifnr in @s_lifnr.


  IF gt_ekko[] is NOT INITIAL.

  sort gt_ekko by lifnr.

"Vendor names
  select lifnr, name1 from lfa1 into TABLE @data(gt_lfa1)
  FOR ALL ENTRIES IN @gt_ekko WHERE lifnr = @gt_ekko-lifnr.


  sort gt_ekko by ebeln.

"po line items
  select ebeln, ebelp, txz01, matnr, menge, meins, netwr
  from ekpo into table @data(gt_ekpo)
  for all entries in @gt_ekko where ebeln = @gt_ekko-ebeln.

  sort gt_lfa1 by lifnr.
  sort gt_ekko by lifnr ebeln.
  sort gt_ekpo by ebeln ebelp.

"build node
  clear : gs_node.

  gs_node-tlevel  = 1.
  gs_node-name    = 'Vendor PO Details'.
  gs_node-nlength = 40.
  gs_node-color   = 'C5'.
  append gs_node to gt_node.

  loop at gt_lfa1 ASSIGNING FIELD-SYMBOL(<fs_lfa1>).

  clear : gs_node.
  gs_node-tlevel     = 2.

  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
    EXPORTING
      input         = <fs_lfa1>-lifnr
   IMPORTING
     OUTPUT        = gs_node-name.

  gs_node-nlength    = 10.
  gs_node-color      = 'C3'.

  gs_node-text1      = <fs_lfa1>-name1.
  gs_node-tlength1   = 40.
  append gs_node to gt_node.

"PO header
  LOOP AT GT_EKKO ASSIGNING FIELD-SYMBOL(<FS_EKKO>) WHERE lifnr = <fs_lfa1>-lifnr.

  clear : gs_node.
  gs_node-tlevel   = 3.
  gs_node-name     = <fs_ekko>-ebeln.
  gs_node-nlength  = 10.

  write <fs_ekko>-aedat to gs_node-text1.
  gs_node-tlength1   = 10.

  gs_node-text2      = <fs_ekko>-bukrs.
  gs_node-tlength2   = 4.


  write <fs_ekko>-rlwrt to gs_node-text3.
  CONDENSE gs_node-text3.
  gs_node-tlength3   = 25.

  append gs_node to gt_node.

"PO items
  loop at gt_ekpo ASSIGNING FIELD-SYMBOL(<fs_ekpo>) WHERE ebeln = <fs_ekko>-ebeln.

  clear : gs_node.
  gs_node-tlevel   = 4.
  gs_node-name     = <fs_ekpo>-ebelp.
  gs_node-nlength  = 10.

  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
    EXPORTING
      input         = <fs_ekpo>-matnr
   IMPORTING
     OUTPUT        =  gs_node-text1.

  gs_node-tlength1   = 18.

  gs_node-text2      = <fs_ekpo>-TXZ01.
  gs_node-tlength2   = 40.

  write <fs_ekpo>-MENGE to gs_node-text3.
  CONDENSE gs_node-text3.
  gs_node-tlength3   = 20.


  gs_node-text4      = <fs_ekpo>-meins.
  gs_node-tlength4   = 5.

  write <fs_ekpo>-netwr to gs_node-text5.
  CONDENSE gs_node-text5.
  gs_node-tlength5   = 20.

  append gs_node to gt_node.


  endloop.


  endloop.

  endloop.


  if gt_node[] is NOT INITIAL.
     perform display_tree.
  endif.


  else.
    message 'No record found' TYPE 'I'.
    set SCREEN 0.

  endif.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form display_tree
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM display_tree .

CALL FUNCTION 'RS_TREE_CONSTRUCT'
* EXPORTING
*   INSERT_ID                = '000000'
*   RELATIONSHIP             = ' '
*   LOG                      =
  TABLES
    nodetab                  = gt_node
 EXCEPTIONS
   TREE_FAILURE             = 1
   ID_NOT_FOUND             = 2
   WRONG_RELATIONSHIP       = 3
   OTHERS                   = 4
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
 EXPORTING
   CALLBACK_PROGRAM                = sy-repid
*   CALLBACK_USER_COMMAND           =
*   CALLBACK_TEXT_DISPLAY           =
*   CALLBACK_MOREINFO_DISPLAY       =
*   CALLBACK_COLOR_DISPLAY          =
*   CALLBACK_TOP_OF_PAGE            =
*   CALLBACK_GUI_STATUS             =
*   CALLBACK_CONTEXT_MENU           =
*   STATUS                          = 'IMPLICIT'
*   CHECK_DUPLICATE_NAME            = '1'
*   COLOR_OF_NODE                   = '4'
*   COLOR_OF_MARK                   = '3'
*   COLOR_OF_LINK                   = '1'
*   COLOR_OF_MATCH                  = '5'
*   LOWER_CASE_SENSITIVE            = ' '
*   MODIFICATION_LOG                = ' '
*   NODE_LENGTH                     = 30
*   TEXT_LENGTH                     = 75
*   TEXT_LENGTH1                    = 0
*   TEXT_LENGTH2                    = 0
*   RETURN_MARKED_SUBTREE           = ' '
*   SCREEN_START_COLUMN             = 0
*   SCREEN_START_LINE               = 0
*   SCREEN_END_COLUMN               = 0
*   SCREEN_END_LINE                 = 0
*   SUPPRESS_NODE_OUTPUT            = ' '
*   LAYOUT_MODE                     = ' '
*   USE_CONTROL                     = STREE_USE_LIST
* IMPORTING
*   F15                             =
          .


ENDFORM.




Post a Comment

0 Comments

Total Pageviews