Skip to Content
author's profile photo Former Member
Former Member

ALV with tree structure

hi gurus,

i want your help in developing alv, my requirement is output is

c1 c2 c3

r2c1 r2c2 r2c3

when user click on c1 which has a button to expand, it should expand like

c1 c2 c3

c11 c21 c31

c22 c22 c32

r2c1 r2c2 r2c3

can any body give me some sample

rewards for sure

Mandy

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 22, 2007 at 04:02 AM

    see example program.

    bcalv_tree

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 22, 2007 at 04:11 AM

    Hi,

    Following this is sample report for alv tree.

    REPORT yms_alvtreefooter.

    TABLES vbak.

    TYPE-POOLS slis.

    • Data Declaration

    TYPES: BEGIN OF t_vbak,

    vbeln TYPE vbak-vbeln,

    erdat TYPE vbak-erdat,

    ernam TYPE vbak-ernam,

    audat TYPE vbak-audat,

    vbtyp TYPE vbak-vbtyp,

    netwr TYPE vbak-netwr,

    vkorg TYPE vbak-vkorg,

    vkgrp TYPE vbak-vkgrp,

    line_color(4) TYPE c,

    END OF t_vbak.

    DATA: it_vbak TYPE STANDARD TABLE OF t_vbak INITIAL SIZE 0,

    wa_vbak TYPE t_vbak.

    • ALV Data Declaration

    DATA: fldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,

    gd_layout TYPE slis_layout_alv,

    gd_repid TYPE sy-repid,

    i_events TYPE slis_t_event,

    w_events LIKE LINE OF i_events.

    DATA: i_comment TYPE slis_t_listheader,

    wa_comment TYPE slis_listheader.

    START-OF-SELECTION.

    PERFORM data_retrieval.

    PERFORM bld_fldcat.

    PERFORM bld_layout.

    PERFORM call_events.

    PERFORM display_alv_report.

    • Build Field Catalog for ALV Report

    FORM bld_fldcat.

    fldcat-fieldname = 'VBELN'.

    fldcat-seltext_m = 'Sales Document'.

    fldcat-col_pos = 0.

    *FLDCAT-EMPHASIZE = 'C411'.

    fldcat-outputlen = 20.

    fldcat-key = 'X'.

    APPEND fldcat TO fldcat.

    CLEAR fldcat.

    fldcat-fieldname = 'ERDAT'.

    fldcat-seltext_l = 'Record Date created'.

    fldcat-col_pos = 1.

    fldcat-key = 'X'.

    APPEND fldcat TO fldcat.

    CLEAR fldcat.

    fldcat-fieldname = 'ERNAM'.

    fldcat-seltext_l = 'Cteated Object Person Name'.

    APPEND fldcat TO fldcat.

    CLEAR fldcat.

    fldcat-fieldname = 'AUDAT'.

    fldcat-seltext_m = 'Document Date'.

    fldcat-col_pos = 3.

    fldcat-emphasize = 'C110'.

    APPEND fldcat TO fldcat.

    CLEAR fldcat.

    fldcat-fieldname = 'VBTYP'.

    fldcat-seltext_l = 'SD Document category'.

    fldcat-col_pos = 4.

    APPEND fldcat TO fldcat.

    CLEAR fldcat.

    fldcat-fieldname = 'NETWR'.

    fldcat-seltext_l = 'Net Value of the SO in Document Currency'.

    fldcat-col_pos = 5.

    fldcat-outputlen = 60.

    fldcat-do_sum = 'X'.

    fldcat-datatype = 'CURR'.

    APPEND fldcat TO fldcat.

    CLEAR fldcat.

    fldcat-fieldname = 'VKORG'.

    fldcat-seltext_l = 'Sales Organization'.

    fldcat-col_pos = 6.

    APPEND fldcat TO fldcat.

    CLEAR fldcat.

    fldcat-fieldname = 'VKGRP'.

    fldcat-seltext_m = 'Sales Group'.

    fldcat-col_pos = 7.

    fldcat-emphasize = 'C801'.

    APPEND fldcat TO fldcat.

    CLEAR fldcat.

    ENDFORM. "BLD_FLDCAT

    • Build Layout for ALV Grid Report

    FORM bld_layout.

    gd_layout-no_input = 'X'.

    gd_layout-colwidth_optimize = 'X'.

    gd_layout-info_fieldname = 'LINE_COLOR'.

    ENDFORM. "BLD_LAYOUT

    • Display report using ALV grid

    FORM display_alv_report.

    DATA t_event TYPE slis_t_event.

    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

    EXPORTING

    i_list_type = 0

    IMPORTING

    et_events = t_event.

    IF sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    gd_repid = sy-repid.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    i_callback_program = gd_repid

    is_layout = gd_layout

    • I_CALLBACK_HTML_TOP_OF_PAGE = 'TOP_OF_PAGE_SPLIT'

    • I_CALLBACK_TOP_OF_PAGE = 'TOP-OF-PAGE'

    • I_CALLBACK_HTML_END_OF_LIST = 'END_OF_LIST_HTML'

    it_events = i_events

    it_fieldcat = fldcat[]

    i_save = 'X'

    TABLES

    t_outtab = it_vbak

    EXCEPTIONS

    program_error = 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.

    ENDFORM. "DISPLAY_ALV_REPORT

    • Retrieve data from VBAK table and populate itab IT_VBAK

    FORM data_retrieval.

    DATA ld_color(1) TYPE c.

    SELECT vbeln erdat ernam audat vbtyp netwr vkorg

    UP TO 100 ROWS

    FROM vbak

    INTO TABLE it_vbak.

    LOOP AT it_vbak INTO wa_vbak.

    ld_color = ld_color + 1.

    IF ld_color = 8.

    ld_color = 1.

    ENDIF.

    CONCATENATE 'C' ld_color '10' INTO wa_vbak-line_color.

    MODIFY it_vbak FROM wa_vbak.

    ENDLOOP.

    ENDFORM. "DATA_RETRIEVAL

    &----


    *& Form CALL_EVENTS

    &----


    • text

    ----


    FORM call_events.

    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

    EXPORTING

    i_list_type = 0

    IMPORTING

    et_events = i_events

    • EXCEPTIONS

    • LIST_TYPE_WRONG = 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.

    IF NOT i_events[] IS INITIAL.

    READ TABLE i_events INTO w_events WITH KEY name = 'END_OF_LIST'.

    w_events-form = 'GENERATE_USERCOMMAND_FOOTER'.

    MODIFY i_events FROM w_events INDEX sy-tabix.

    ENDIF.

    ENDFORM. "CALL_EVENTS

    &----


    *& Form GENERATE_USERCOMMAND_FOOTER

    &----


    • text

    ----


    FORM generate_usercommand_footer.

    CLEAR i_comment[].

    wa_comment-typ = 'S'.

    wa_comment-info = sy-pagno.

    APPEND wa_comment TO i_comment.

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

    EXPORTING

    it_list_commentary = i_comment

    • I_LOGO = ''

    i_end_of_list_grid = 'X'.

    ENDFORM. "GENERATE_USERCOMMAND_FOOTER

    Thanks,

    Sankar M

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Expert .

      Boss , i run this code , it is running fine , but the issue is still remain same .

      My Issue is How to expend the ALV display Or some [+] will appear to expend this ALV display .

      This is End-User requirement .

      Please Help me boss .

      Thanx Boss .

      Regards : rajneesh

  • author's profile photo Former Member
    Former Member
    Posted on Nov 22, 2007 at 04:34 AM

    HI

    refer this site

    http://www.sapdev.co.uk/reporting/alv/alvtree.htm

    <b>Reward iuf usefull</b>

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 23, 2007 at 01:53 PM

    Hi Mittal and all,

    thanks for reply, but i got solution

    here is the modified code

    *& REPORT ZDEMO_TREE_LIST_ALV .

    TABLES vbak.

    TYPE-POOLS slis.

    • Data Declaration

    TYPES: BEGIN OF t_vbak,

    vbeln TYPE vbak-vbeln,

    erdat TYPE vbak-erdat,

    ernam TYPE vbak-ernam,

    audat TYPE vbak-audat,

    vbtyp TYPE vbak-vbtyp,

    netwr TYPE vbak-netwr,

    vkorg TYPE vbak-vkorg,

    vkgrp TYPE vbak-vkgrp,

    line_color(4) TYPE c,

    END OF t_vbak.

    DATA: it_vbak TYPE STANDARD TABLE OF t_vbak INITIAL SIZE 0,

    wa_vbak TYPE t_vbak.

    • ALV Data Declaration

    DATA: fldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,

    gd_layout TYPE slis_layout_alv,

    gd_repid TYPE sy-repid,

    i_events TYPE slis_t_event,

    it_sortinfo type slis_t_sortinfo_alv with header line,

    w_events LIKE LINE OF i_events.

    DATA: i_comment TYPE slis_t_listheader,

    wa_comment TYPE slis_listheader.

    START-OF-SELECTION.

    PERFORM data_retrieval.

    PERFORM bld_fldcat.

    PERFORM it_sortinfo.

    PERFORM bld_layout.

    PERFORM call_events.

    PERFORM display_alv_report.

    • Build Field Catalog for ALV Report

    FORM bld_fldcat.

    fldcat-fieldname = 'VBELN'.

    fldcat-seltext_m = 'Sales Document'.

    fldcat-col_pos = 0.

    *FLDCAT-EMPHASIZE = 'C411'.

    fldcat-outputlen = 20.

    fldcat-key = 'X'.

    APPEND fldcat TO fldcat.

    CLEAR fldcat.

    fldcat-fieldname = 'ERDAT'.

    fldcat-seltext_l = 'Record Date created'.

    fldcat-col_pos = 1.

    fldcat-key = 'X'.

    APPEND fldcat TO fldcat.

    CLEAR fldcat.

    fldcat-fieldname = 'ERNAM'.

    fldcat-seltext_l = 'Cteated Object Person Name'.

    APPEND fldcat TO fldcat.

    CLEAR fldcat.

    fldcat-fieldname = 'AUDAT'.

    fldcat-seltext_m = 'Document Date'.

    fldcat-col_pos = 3.

    fldcat-emphasize = 'C110'.

    APPEND fldcat TO fldcat.

    CLEAR fldcat.

    fldcat-fieldname = 'VBTYP'.

    fldcat-seltext_l = 'SD Document category'.

    fldcat-col_pos = 4.

    APPEND fldcat TO fldcat.

    CLEAR fldcat.

    fldcat-fieldname = 'NETWR'.

    fldcat-seltext_l = 'Net Value of the SO in Document Currency'.

    fldcat-col_pos = 5.

    fldcat-outputlen = 60.

    fldcat-do_sum = 'X'.

    fldcat-datatype = 'CURR'.

    APPEND fldcat TO fldcat.

    CLEAR fldcat.

    fldcat-fieldname = 'VKORG'.

    fldcat-seltext_l = 'Sales Organization'.

    fldcat-col_pos = 6.

    APPEND fldcat TO fldcat.

    CLEAR fldcat.

    fldcat-fieldname = 'VKGRP'.

    fldcat-seltext_m = 'Sales Group'.

    fldcat-col_pos = 7.

    fldcat-emphasize = 'C801'.

    APPEND fldcat TO fldcat.

    CLEAR fldcat.

    ENDFORM. "BLD_FLDCAT

    • Build Layout for ALV Grid Report

    FORM bld_layout.

    gd_layout-no_input = 'X'.

    gd_layout-colwidth_optimize = 'X'.

    gd_layout-info_fieldname = 'LINE_COLOR'.

    ENDFORM. "BLD_LAYOUT

    • Display report using ALV grid

    FORM display_alv_report.

    DATA t_event TYPE slis_t_event.

    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

    EXPORTING

    i_list_type = 0

    IMPORTING

    et_events = t_event.

    IF sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    gd_repid = sy-repid.

    • PERFORM z_alv_grid_display TABLES it_vbak..

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    i_callback_program = gd_repid

    is_layout = gd_layout

    it_events = i_events

    it_fieldcat = fldcat[]

    • I_INTERFACE_CHECK = ' '

    • I_BYPASSING_BUFFER = ' '

    • I_BUFFER_ACTIVE = ' '

    • I_CALLBACK_PF_STATUS_SET = ' '

    • I_CALLBACK_USER_COMMAND = ' '

    • I_CALLBACK_TOP_OF_PAGE = ' '

    • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

    • I_CALLBACK_HTML_END_OF_LIST = ' '

    • I_STRUCTURE_NAME =

    • I_BACKGROUND_ID = ' '

    • I_GRID_TITLE =

    • I_GRID_SETTINGS =

    • IT_EXCLUDING =

    • IT_SPECIAL_GROUPS =

    IT_SORT = it_sortinfo[]

    • IT_FILTER =

    • IS_SEL_HIDE =

    • I_DEFAULT = 'X'

    I_SAVE = 'X'

    • IS_VARIANT =

    • IT_EVENT_EXIT =

    • IS_PRINT =

    • IS_REPREP_ID =

    • I_SCREEN_START_COLUMN = 0

    • I_SCREEN_START_LINE = 0

    • I_SCREEN_END_COLUMN = 0

    • I_SCREEN_END_LINE = 0

    • IT_ALV_GRAPHICS =

    • IT_HYPERLINK =

    • IT_ADD_FIELDCAT =

    • IT_EXCEPT_QINFO =

    • I_HTML_HEIGHT_TOP =

    • I_HTML_HEIGHT_END =

    TABLES

    T_OUTTAB = IT_VBAK

    • EXCEPTIONS

    • PROGRAM_ERROR = 1

    • OTHERS = 2

    .

    IF SY-SUBRC <> 0.

    EXIT.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    ENDFORM. "DISPLAY_ALV_REPORT

    • Retrieve data from VBAK table and populate itab IT_VBAK

    FORM data_retrieval.

    DATA ld_color(1) TYPE c.

    SELECT vbeln erdat ernam audat vbtyp netwr vkorg

    UP TO 100 ROWS

    FROM vbak

    INTO TABLE it_vbak.

    LOOP AT it_vbak INTO wa_vbak.

    ld_color = ld_color + 1.

    IF ld_color = 8.

    ld_color = 1.

    ENDIF.

    CONCATENATE 'C' ld_color '10' INTO wa_vbak-line_color.

    MODIFY it_vbak FROM wa_vbak.

    ENDLOOP.

    ENDFORM. "DATA_RETRIEVAL

    &----


    *& Form CALL_EVENTS

    &----


    • text

    ----


    FORM call_events.

    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

    EXPORTING

    i_list_type = 0

    IMPORTING

    et_events = i_events

    • EXCEPTIONS

    • LIST_TYPE_WRONG = 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.

    IF NOT i_events[] IS INITIAL.

    READ TABLE i_events INTO w_events WITH KEY name = 'END_OF_LIST'.

    w_events-form = 'GENERATE_USERCOMMAND_FOOTER'.

    MODIFY i_events FROM w_events INDEX sy-tabix.

    ENDIF.

    ENDFORM. "CALL_EVENTS

    &----


    *& Form GENERATE_USERCOMMAND_FOOTER

    &----


    • text

    ----


    FORM generate_usercommand_footer.

    CLEAR i_comment[].

    wa_comment-typ = 'S'.

    wa_comment-info = sy-pagno.

    APPEND wa_comment TO i_comment.

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

    EXPORTING

    it_list_commentary = i_comment

    • I_LOGO = ''

    i_end_of_list_grid = 'X'.

    ENDFORM. "GENERATE_USERCOMMAND_FOOTER

    &----


    *& Form it_sortinfo

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM it_sortinfo .

    it_sortinfo-fieldname = 'ERNAM'.

    it_sortinfo-tabname = 'IT_VBAK'.

    it_sortinfo-subtot = 'X'.

    it_sortinfo-obligatory = 'X'.

    it_sortinfo-up = 'X'.

    it_sortinfo-spos = '1'.

    it_sortinfo-expa = 'X'.

    append it_sortinfo.

    ENDFORM. " it_sortinfo

    reward point if u can.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.