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

ALV

Former Member
0 Likes
1,183

Hi Friends,

Could u pls give me step by step guide for creating hierarchial alv report.

TIA.

Regards,

Mark K

Hi Friends,

Could u pls give me step by step guide for creating hierarchial alv report.

TIA.

Regards,

Mark K

8 REPLIES 8
Read only

Former Member
0 Likes
1,157

Please have a look at the following Sample SAP Programs dealing with hierarchial alv grid:

BCALV_TEST_HIERSEQ_LIST

BCALV_TREE_01

BCALV_TREE_DND

BC_ALVEXCELTOP

BC_ALVEXCEL_D100

BC_ALVEXCEL_D210

BC_ALVEXCEL_HIER

BC_ALVHIERGRID1_D100

BC_ALVHIERGRID1_D210

BC_ALVHIERGRID1_HIER

BC_ALVHIERTOP

also see the transaction DWDM

Read only

0 Likes
1,157

The listed programs are bit complicated. could u pls guide me a simple hierarchial alv report.

Regards,

Read only

0 Likes
1,157

Hi Friends,

what is the significance of the following and why it is required.

create object g_custom_container

exporting

container_name = l_tree_container_name

exceptions

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5.

if sy-subrc <> 0.

message x208(00) with 'ERROR'(100).

endif.

  • create tree control

create object g_alv_tree

exporting

parent = g_custom_container

node_selection_mode = cl_gui_column_tree=>node_sel_mode_single

item_selection = 'X'

no_html_header = 'X'

no_toolbar = ''

exceptions

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

illegal_node_selection_mode = 5

failed = 6

illegal_column_name = 7.

if sy-subrc <> 0.

message x208(00) with 'ERROR'. "#EC NOTEXT

endif.

Regards,

Read only

Former Member
0 Likes
1,157

REFER SAP HELP

Read only

Former Member
0 Likes
1,157

Check Program <b>BCALV_TEST_HIERSEQ_LIST</b>

Refer this link for reference

http://www.sap-img.com/abap/how-to-use-alv-for-hierarchical-lists.htm

Regards,

Santosh

Message was edited by: Santosh Kumar P

Read only

Former Member
0 Likes
1,157

Hi,

Just see The demo Program <b>BALVHD01</b>.

Regards

vijay

Read only

Former Member
0 Likes
1,157

Hi,

Check this sample code..

REPORT Z_ALVTEST2 .
tables:vbak,vbap.
type-pools: slis.
data: begin of it_header occurs 0,
vbeln like vbak-vbeln,
vkorg like vbak-vkorg,
vtweg like vbak-vtweg,
spart like vbak-spart,
end of it_header.

data: begin of it_item occurs 0,
matnr like vbap-matnr,
werks like vbap-werks,
lgort like vbap-lgort,
end of it_item.


data: it_fieldcat type slis_fieldcat_alv occurs 0 with header line.
data: wa_fieldcat type slis_fieldcat_alv.
data: x_keyinfo type slis_keyinfo_alv.
data: p_repid like sy-repid.
p_repid = sy-repid.


start-of-selection.
perform get_data.
perform get_fieldcat.
perform get_keyinfo.
perform key_modify.
perform display.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_data.
select vbeln vkorg vtweg spart from vbak into table it_header.
if not it_header[] is initial.
read table it_header index sy-tabix.
select matnr werks lgort from vbap into table it_item
where vbeln = it_header-vbeln.
endif.
ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form get_fieldcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_fieldcat.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = p_repid
I_INTERNAL_TABNAME = 'IT_HEADER'
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = p_repid
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = it_fieldcat[]

.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = p_repid
I_INTERNAL_TABNAME = 'IT_ITEM'
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = p_repid
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = it_fieldcat[]
* EXCEPTIONS
* INCONSISTENT_INTERFACE = 1
* PROGRAM_ERROR = 2
* OTHERS = 3
.
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. " get_fieldcat
*&---------------------------------------------------------------------*
*& Form get_keyinfo
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_keyinfo.
x_keyinfo-header01 = 'VBELN'.
x_keyinfo-item01 = 'MATNR'.
ENDFORM. " get_keyinfo
*&---------------------------------------------------------------------*
*& Form display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
I_CALLBACK_PROGRAM = p_repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* IS_LAYOUT =
IT_FIELDCAT = it_fieldcat[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
I_TABNAME_HEADER = 'IT_HEADER'
I_TABNAME_ITEM = 'IT_ITEM'
* I_STRUCTURE_NAME_HEADER =
* I_STRUCTURE_NAME_ITEM =
IS_KEYINFO = x_keyinfo
* IS_PRINT =
* IS_REPREP_ID =
* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB_HEADER = it_header
T_OUTTAB_ITEM = it_item
* 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
*&---------------------------------------------------------------------*
*& Form key_modify
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM key_modify.
loop at it_fieldcat .
case: it_fieldcat-fieldname.
when 'MATNR'.
if it_fieldcat-tabname = 'IT_ITEM'.
it_fieldcat-no_out = 'X'.
it_fieldcat-key = space.
modify it_fieldcat index sy-tabix.
endif.
endcase.
endloop.
ENDFORM. " key_modify

Regards

vijay

Read only

Former Member
0 Likes
1,157

Hi,

Try this sample code for creating Hierarchical ALV.

tables : ekko,
         ekpo.

select-options: s_ebeln for ekko-ebeln.
type-pools: slis.

data: begin of headertab occurs 0,
       ebeln like ekko-ebeln,
       bstyp like ekko-bstyp,
       bsart like ekko-bsart,
       statu like ekko-statu,
      end of headertab.

data: begin of itemtab occurs 0,
       ebeln like ekpo-ebeln,
       ebelp like ekpo-ebelp,
       matnr like ekpo-matnr,
       werks like ekpo-werks,
       menge like ekpo-menge,
       netpr like ekpo-netpr,
       peinh like ekpo-peinh,
       netwr like ekpo-netwr,
      end of itemtab.

data: i_fieldcat type slis_t_fieldcat_alv.
data: v_repid like sy-repid.
data: g_tabname_header type slis_tabname,
      g_tabname_item   type slis_tabname,
      gs_keyinfo type slis_keyinfo_alv.

start-of-selection.

  v_repid = sy-repid.

  select ebeln bstyp bsart statu
     into table headertab
     from ekko
     where ebeln in s_ebeln.

  if not headertab[] is initial.
    select ebeln ebelp matnr werks menge netpr peinh netwr
       into table itemtab
       from ekpo
       for all entries in headertab
       where ebeln = headertab-ebeln.
  endif.

  call function 'REUSE_ALV_FIELDCATALOG_MERGE'
    exporting
      i_program_name               =  v_repid
      i_internal_tabname           = 'HEADERTAB'
      i_inclname                   = v_repid
      i_bypassing_buffer           = 'X'
      i_buffer_active              = ' '
    changing
      ct_fieldcat                  = i_fieldcat
    exceptions
      inconsistent_interface       = 1
      program_error                = 2
      others                       = 3
           .
  if sy-subrc <> 0.
  message id sy-msgid type sy-msgty number sy-msgno
          with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

   call function 'REUSE_ALV_FIELDCATALOG_MERGE'
    exporting
      i_program_name               =  v_repid
      i_internal_tabname           = 'ITEMTAB'
      i_inclname                   = v_repid
      i_bypassing_buffer           = 'X'
      i_buffer_active              = ' '
    changing
      ct_fieldcat                  = i_fieldcat
    exceptions
      inconsistent_interface       = 1
      program_error                = 2
      others                       = 3
            .
  if sy-subrc <> 0.
   message id sy-msgid type sy-msgty number sy-msgno
          with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

  gs_keyinfo-header01 = 'EBELN'.
  gs_keyinfo-item01   = 'EBELN'.
  g_tabname_header = 'HEADERTAB'.
  g_tabname_item   = 'ITEMTAB'.

  call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
    exporting
      i_callback_program             = v_repid
      it_fieldcat                    = i_fieldcat
      i_save                         = 'A'
      i_tabname_header               = g_tabname_header
      i_tabname_item                 = g_tabname_item
      is_keyinfo                     = gs_keyinfo
      i_bypassing_buffer             = 'X'
      i_buffer_active                = ' '
    tables
      t_outtab_header                = headertab
      t_outtab_item                  = itemtab
  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.

Regards,

Sailaja.