Application Development 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: 

ALV Hierarchy

Former Member
0 Kudos

Hi Experts,

Can any send me the Hierachy sequential report (code)

Thanks in advance

Regards

Rams

5 REPLIES 5

former_member156446
Active Contributor
0 Kudos

************************************************************************

  • message e159(at) not in table T100 "XJD 14.11.2001 *

************************************************************************

REPORT zm07mkon MESSAGE-ID m7.

*ENHANCEMENT-POINT RM07MKON_G4 SPOTS ES_RM07MKON STATIC.

*ENHANCEMENT-POINT RM07MKON_G5 SPOTS ES_RM07MKON.

*ENHANCEMENT-POINT RM07MKON_G6 SPOTS ES_RM07MKON STATIC.

*ENHANCEMENT-POINT RM07MKON_G7 SPOTS ES_RM07MKON.

CLASS cl_mmim_auth DEFINITION LOAD.

TABLES: msku, makt, mara, t001w, kna1.

SELECTION-SCREEN: BEGIN OF BLOCK dba WITH FRAME TITLE text-001.

SELECT-OPTIONS: matnr FOR mara-matnr,

werks FOR t001w-werks MEMORY ID wrk,

charg FOR msku-charg,

kunnr FOR msku-kunnr.

PARAMETERS: sobkz_w LIKE am07m-kukns AS CHECKBOX DEFAULT 'X',

sobkz_v LIKE am07m-lhgut AS CHECKBOX DEFAULT 'X'.

SELECTION-SCREEN: END OF BLOCK dba.

SELECTION-SCREEN: BEGIN OF BLOCK anz WITH FRAME TITLE text-005.

PARAMETERS: alv_def LIKE disvariant-variant,

zero LIKE am07m-xmnul AS CHECKBOX.

SELECTION-SCREEN: END OF BLOCK anz.

INCLUDE rm07alvi.

DATA: BEGIN OF itab OCCURS 0.

INCLUDE STRUCTURE msku.

DATA: maktx LIKE makt-maktx,

name1_w LIKE t001w-name1,

name1_k LIKE kna1-name1,

meins LIKE mara-meins,

dummy TYPE alv_dummy,

farbe TYPE slis_t_specialcol_alv, " color

kunres LIKE mbew-salk3, "total unrestricted stock

kinqul LIKE mbew-salk3, "total in quality inspection

krest LIKE mbew-salk3. "total restricted stock

  • ctotal LIKE mbew-salk3.

DATA: END OF itab.

DATA: BEGIN OF list OCCURS 0.

INCLUDE STRUCTURE itab.

DATA: END OF list.

DATA: BEGIN OF header OCCURS 0,

kunnr LIKE kna1-kunnr,

name1_k LIKE kna1-name1,

ctotal LIKE mbew-salk3,

END OF header.

DATA: fc TYPE slis_fieldcat_alv OCCURS 0 WITH HEADER LINE.

DATA: detail.

INITIALIZATION.

*ENHANCEMENT-POINT RM07MKON_01 SPOTS ES_RM07MKON.

PERFORM alv_init.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR alv_def.

PERFORM alv_f4.

AT SELECTION-SCREEN.

CALL FUNCTION 'MMIM_ENTRYCHECK_MAIN'

TABLES

it_matnr = matnr

it_werks = werks

it_kunnr = kunnr.

IF sobkz_w = space AND sobkz_v = space.

  • message changed from e159(at) to e831 "XJD 14.11.2001

SET CURSOR FIELD 'SOBKZ_W'. "XJD 14.11.2001

MESSAGE e831. "Please choose at least one stock type

ENDIF.

PERFORM alv_check.

START-OF-SELECTION.

PERFORM data_selection.

END-OF-SELECTION.

PERFORM calculate_and_colorize.

PERFORM fieldcatalog.

PERFORM list_display.

************************************************************************

FORM data_selection.

DATA: BEGIN OF makt_key OCCURS 0,

matnr LIKE makt-matnr,

END OF makt_key.

DATA: BEGIN OF imakt OCCURS 0,

matnr LIKE makt-matnr,

maktx LIKE makt-maktx,

END OF imakt.

DATA: BEGIN OF mara_key OCCURS 0,

matnr LIKE mara-matnr,

END OF mara_key.

DATA: BEGIN OF imara OCCURS 0,

matnr LIKE mara-matnr,

meins LIKE mara-meins,

END OF imara.

DATA: BEGIN OF t001w_key OCCURS 0,

werks LIKE t001w-werks,

END OF t001w_key.

DATA: BEGIN OF it001w OCCURS 0,

werks LIKE t001w-werks,

name1 LIKE t001w-name1,

END OF it001w.

DATA: BEGIN OF kna1_key OCCURS 0,

kunnr LIKE kna1-kunnr,

END OF kna1_key.

DATA: BEGIN OF ikna1 OCCURS 0,

kunnr LIKE kna1-kunnr,

name1 LIKE kna1-name1,

END OF ikna1.

  • New table to hold the costs

DATA: BEGIN OF imbew_key OCCURS 0,

charg LIKE mchb-charg,

END OF imbew_key.

DATA: BEGIN OF imbew OCCURS 0,

matnr LIKE mbew-matnr,

bwkey LIKE mbew-bwkey,

salk3 LIKE mbew-salk3,

charg LIKE mchb-charg,

END OF imbew.

  • DATA: imbew TYPE STANDARD TABLE OF smbew.

RANGES sobkz FOR msku-sobkz.

  • Main data

REFRESH sobkz.

sobkz-sign = 'I'. sobkz-option = 'EQ'.

IF sobkz_w = 'X'. sobkz-low = 'W'. APPEND sobkz. ENDIF.

IF sobkz_v = 'X'. sobkz-low = 'V'. APPEND sobkz. ENDIF.

SELECT * FROM msku INTO CORRESPONDING FIELDS OF TABLE itab

WHERE matnr IN matnr

AND werks IN werks

AND charg IN charg

AND sobkz IN sobkz

AND kunnr IN kunnr.

  • Additional info: material text, plant name, debitor name

LOOP AT itab.

makt_key-matnr = itab-matnr. COLLECT makt_key.

mara_key-matnr = itab-matnr. COLLECT mara_key.

t001w_key-werks = itab-werks. COLLECT t001w_key.

kna1_key-kunnr = itab-kunnr. COLLECT kna1_key.

imbew_key-charg = itab-charg. COLLECT imbew_key.

ENDLOOP.

READ TABLE makt_key INDEX 1.

IF sy-subrc = 0.

SELECT matnr maktx INTO CORRESPONDING FIELDS OF TABLE imakt

FROM makt FOR ALL ENTRIES IN makt_key

WHERE matnr = makt_key-matnr

AND spras = sy-langu.

SORT imakt BY matnr.

ENDIF.

READ TABLE mara_key INDEX 1.

IF sy-subrc = 0.

SELECT matnr meins INTO CORRESPONDING FIELDS OF TABLE imara

FROM mara FOR ALL ENTRIES IN mara_key

WHERE matnr = mara_key-matnr.

SORT imara BY matnr.

ENDIF.

READ TABLE t001w_key INDEX 1.

IF sy-subrc = 0.

SELECT werks name1 INTO CORRESPONDING FIELDS OF TABLE it001w

FROM t001w FOR ALL ENTRIES IN t001w_key

WHERE werks = t001w_key-werks.

SORT it001w BY werks.

**new code to get costs

*selecting data into imbew, later reading imbew based on batch number

and placing the necessary values in the final structure itab-.

  • SELECT amatnr abwkey asalk3 bcharg INTO TABLE imbew

  • FROM mbew AS a

  • JOIN mchb AS b

  • ON amatnr = bmatnr AND

  • abwkey = bwerks

  • FOR ALL ENTRIES IN imbew_key

  • WHERE b~charg = imbew_key-charg AND

  • a~bwkey = t001w_key-werks.

SORT imbew BY matnr bwkey charg.

ENDIF.

READ TABLE kna1_key INDEX 1.

IF sy-subrc = 0.

SELECT kunnr name1 INTO CORRESPONDING FIELDS OF TABLE ikna1

FROM kna1 FOR ALL ENTRIES IN kna1_key

WHERE kunnr = kna1_key-kunnr.

SORT ikna1 BY kunnr.

ENDIF.

LOOP AT itab.

READ TABLE imakt WITH KEY matnr = itab-matnr BINARY SEARCH.

IF sy-subrc = 0. itab-maktx = imakt-maktx. ENDIF.

READ TABLE imara WITH KEY matnr = itab-matnr BINARY SEARCH.

IF sy-subrc = 0. itab-meins = imara-meins. ENDIF.

READ TABLE it001w WITH KEY werks = itab-werks BINARY SEARCH.

IF sy-subrc = 0. itab-name1_w = it001w-name1. ENDIF.

READ TABLE ikna1 WITH KEY kunnr = itab-kunnr BINARY SEARCH.

IF sy-subrc = 0. itab-name1_k = ikna1-name1. ENDIF.

*new code

*get data from imbew to final structure

  • READ TABLE imbew WITH KEY matnr = itab-matnr

  • bwkey = itab-werks

  • charg = itab-charg BINARY SEARCH.

  • IF sy-subrc = 0. itab-kunres = imbew-salk3. ENDIF.

MODIFY itab.

ENDLOOP.

SORT itab BY kunnr matnr charg.

ENDFORM. "data_selection

************************************************************************

FORM fieldcatalog.

REFRESH fc. CLEAR fc.

fc-tabname = 'HEADER'.

fc-fieldname = 'KUNNR'.

fc-ref_tabname = 'MSKU'.

APPEND fc. CLEAR fc.

fc-tabname = 'HEADER'.

fc-fieldname = 'NAME1_K'.

fc-ref_tabname = 'KNA1'.

fc-ref_fieldname = 'NAME1'.

  • APPEND fc. CLEAR fc.

  • fc-tabname = 'HEADER'.

  • fc-fieldname = 'TOTAL'.

  • fc-ref_tabname = 'MBEW'.

  • fc-ref_fieldname = 'SALK3'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'MATNR'.

fc-ref_tabname = 'MSKU'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'MAKTX'.

fc-ref_tabname = 'MAKT'.

fc-no_out = 'X'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'CHARG'.

fc-ref_tabname = 'MSKU'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'WERKS'.

fc-ref_tabname = 'MSKU'.

fc-no_out = 'X'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'NAME1_W'.

fc-ref_tabname = 'T001W'.

fc-ref_fieldname = 'NAME1'.

fc-no_out = 'X'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'SOBKZ'.

fc-ref_tabname = 'MSKU'.

fc-no_out = 'X'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'KULAB'.

fc-qfieldname = 'MEINS'.

fc-ref_tabname = 'MSKU'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'KUINS'.

fc-qfieldname = 'MEINS'.

fc-ref_tabname = 'MSKU'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'KUEIN'.

fc-qfieldname = 'MEINS'.

fc-ref_tabname = 'MSKU'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'MEINS'.

fc-ref_tabname = 'MARA'.

fc-seltext_l = 'WMU'.

fc-seltext_m = 'WMU'.

fc-seltext_s = 'WMU'.

APPEND fc. CLEAR fc.

  • fc-tabname = 'HEADER'.

  • fc-fieldname = 'CTOTAL'.

  • fc-ref_tabname = 'MARA'.

  • fc-seltext_l = 'WMU'.

  • fc-seltext_m = 'WMU'.

  • fc-seltext_s = 'WMU'.

  • APPEND fc. CLEAR fc.

*New code

fc-fieldname = 'DUMMY'.

fc-tabname = 'LIST'.

fc-row_pos = '2'.

fc-outputlen = 59.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'KUNRES'.

fc-row_pos = '2'.

fc-seltext_s = 'Total'.

fc-do_sum = 'X'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'KINQUL'.

fc-row_pos = '2'.

fc-seltext_s = 'Total'.

fc-outputlen = 18.

fc-do_sum = 'X'.

APPEND fc. CLEAR fc.

fc-tabname = 'LIST'.

fc-fieldname = 'KREST'.

fc-row_pos = '2'.

fc-seltext_s = 'Total'.

fc-outputlen = 18.

fc-do_sum = 'X'.

APPEND fc. CLEAR fc.

ENDFORM. "fieldcatalog

************************************************************************

FORM list_display.

REFRESH header.

LOOP AT list.

ON CHANGE OF list-kunnr.

MOVE-CORRESPONDING list TO header.

APPEND header.

ENDON.

ENDLOOP.

alv_keyinfo-header01 = 'KUNNR'.

alv_keyinfo-item01 = 'KUNNR'.

alv_keyinfo-item02 = 'MATNR'.

CLEAR detail.

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

EXPORTING

i_interface_check = ' '

i_callback_program = alv_repid

i_callback_pf_status_set = 'SET_STATUS'

i_callback_user_command = 'USER_COMMAND'

is_layout = alv_layout

it_fieldcat = fc[]

i_default = 'X'

i_save = 'A'

is_variant = alv_variant

i_tabname_header = 'HEADER'

i_tabname_item = 'LIST'

is_keyinfo = alv_keyinfo

is_print = alv_print

TABLES

t_outtab_header = header

t_outtab_item = list.

ENDFORM. "list_display

************************************************************************

************************************************************************

FORM calculate_and_colorize.

DATA: sum LIKE msku-kulab,

cust_sum LIKE mbew-salk3.

REFRESH list.

LOOP AT itab.

  • CHECK cl_mmim_auth=>check( i_object = 'M_MATE_WRK'

  • i_value1 = itab-werks ) IS INITIAL.

  • Authorization for total fields

  • CHECK ZCL_NAME1_AUTH=>check( i_object = 'ZSALK3'

  • i_value1 = itab-kunres ) IS INITIAL.

cust_sum = itab-kunres + cust_sum.

AT NEW kunnr.

  • itab-ctotal = cust_sum.

  • CLEAR cust_sum.

ENDAT.

IF zero = ' '.

sum = itab-kulab + itab-kuein + itab-kuins.

CHECK sum <> 0.

ENDIF.

MOVE-CORRESPONDING itab TO list.

PERFORM convert_to_ea.

APPEND list.

ENDLOOP.

ENDFORM. "calculate_and_colorize

************************************************************************

FORM set_status USING rt_extab TYPE slis_t_extab.

DATA: wa TYPE slis_extab.

IF cl_mmim_auth=>level( ) IS INITIAL.

APPEND 'AUTH' TO rt_extab.

ENDIF.

IF cl_mmim_auth=>level( ) = cl_mmim_auth=>c_error.

MESSAGE s124(m7).

ENDIF.

  • Deactivate detail list if in detail list

IF detail = 'X'.

wa-fcode = 'DETAIL'.

APPEND wa TO rt_extab.

ENDIF.

SET PF-STATUS 'STANDARD' EXCLUDING rt_extab.

ENDFORM. "set_status

************************************************************************

FORM user_command USING rf_ucomm LIKE sy-ucomm

rs TYPE slis_selfield.

  • Call from detail list: Change tablename

IF rs-tabname = '1'.

rs-tabname = 'LIST'.

ENDIF.

  • Read the correct table

CLEAR: list, header.

CASE rs-tabname.

WHEN 'HEADER'.

READ TABLE header INDEX rs-tabindex.

MOVE-CORRESPONDING header TO list.

WHEN 'LIST'.

READ TABLE list INDEX rs-tabindex.

ENDCASE.

CHECK sy-subrc = 0.

  • Double click targets

IF rf_ucomm = '&IC1'.

CASE rs-tabname.

WHEN 'HEADER'.

rf_ucomm = 'ADDR'.

WHEN 'LIST'.

CASE rs-fieldname.

WHEN 'MATNR'.

rf_ucomm = 'MMBE'.

WHEN OTHERS.

rf_ucomm = 'DOCU'.

ENDCASE.

ENDCASE.

ENDIF.

  • Commands

CASE rf_ucomm.

WHEN 'MMBE'.

CHECK rs-tabname = 'LIST'. "only for items

SET PARAMETER ID 'MAT' FIELD list-matnr.

SET PARAMETER ID 'WRK' FIELD list-werks.

CALL TRANSACTION 'MMBE' AND SKIP FIRST SCREEN.

WHEN 'DOCU'.

CHECK rs-tabname = 'LIST'.

SUBMIT rm07docs WITH matnr = list-matnr

WITH werks = list-werks

WITH charg = list-charg

WITH sobkz = list-sobkz

WITH kunnr = list-kunnr

AND RETURN.

WHEN 'ADDR'.

SET PARAMETER ID 'KUN' FIELD list-kunnr.

CALL TRANSACTION 'VD03' AND SKIP FIRST SCREEN.

WHEN 'AUTH'.

CALL METHOD cl_mmim_auth=>display.

WHEN 'DETAIL'.

PERFORM detail_list.

ENDCASE.

CLEAR rf_ucomm.

ENDFORM. "user_command

************************************************************************

FORM detail_list.

DATA: fc_detail TYPE slis_fieldcat_alv OCCURS 0 WITH HEADER LINE.

DATA: variant_detail LIKE disvariant.

DATA: lt_base_list LIKE list[]. "401421

  • The detail ALV may modify the list (sorting). If returned to the

  • base list, the original list needs to be restored.

lt_base_list[] = list[]. "401421

REFRESH fc_detail.

LOOP AT fc.

MOVE-CORRESPONDING fc TO fc_detail.

CLEAR fc_detail-tabname.

APPEND fc_detail.

ENDLOOP.

CLEAR variant_detail.

variant_detail-report = alv_repid.

variant_detail-handle = 'DETA'.

detail = 'X'. "needed for GUI status differentiation

CALL FUNCTION alv_detail_func

EXPORTING

i_callback_program = alv_repid

i_callback_pf_status_set = 'SET_STATUS'

i_callback_user_command = 'USER_COMMAND'

it_fieldcat = fc_detail[]

i_default = 'X'

is_variant = variant_detail

i_save = 'A'

is_layout = alv_layout

is_print = alv_print

TABLES

t_outtab = list[].

CLEAR detail.

list[] = lt_base_list[]. "401421

ENDFORM. "detail_list

&----


*& Form convert_to_ea

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM convert_to_ea .

DATA: l_lvsme TYPE lvs_lvsme,

l_lgnum TYPE lgnum,

l_lbkum TYPE lbkum,

l_salk3 TYPE salk3,

l_peinh TYPE peinh,

l_verpr TYPE verpr,

l_bwtty TYPE bwtty_d,

factor TYPE f.

l_lgnum = list-werks+1.

SELECT SINGLE lvsme

INTO l_lvsme

FROM mlgn

WHERE matnr = list-matnr

AND lgnum = l_lgnum.

*...for Standard materials...

SELECT SINGLE lbkum salk3 peinh verpr bwtty

INTO (l_lbkum, l_salk3, l_peinh, l_verpr, l_bwtty)

FROM mbew

WHERE matnr = list-matnr

AND bwkey = list-werks.

IF l_lbkum = 0.

factor = l_verpr / l_peinh.

ELSE.

factor = l_salk3 / l_lbkum.

ENDIF.

*Totals

  • Total unrestricted stock

list-kunres = list-kulab * factor.

  • Total stock in quality

list-kinqul = list-kuins * factor.

  • Total restricted stock

list-krest = list-kuein * factor.

*.......for Configurable items.........

IF l_bwtty = 'X'.

SELECT SINGLE salk3 INTO (l_salk3)

FROM mbew

WHERE matnr = list-matnr AND

bwkey = list-werks AND

bwtar = list-charg.

list-kunres = l_salk3.

ENDIF.

*.........................................

IF NOT l_lvsme IS INITIAL.

CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'

EXPORTING

input = list-kulab

matnr = list-matnr

meinh = l_lvsme

meins = list-meins

charge = list-charg

werks = list-werks

IMPORTING

output = list-kulab

EXCEPTIONS

conversion_not_found = 1

input_invalid = 2

material_not_found = 3

meinh_not_found = 4

meins_missing = 5

no_meinh = 6

output_invalid = 7

overflow = 8

OTHERS = 9.

CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'

EXPORTING

input = list-kuins

matnr = list-matnr

meinh = l_lvsme

meins = list-meins

charge = list-charg

werks = list-werks

IMPORTING

output = list-kuins

EXCEPTIONS

conversion_not_found = 1

input_invalid = 2

material_not_found = 3

meinh_not_found = 4

meins_missing = 5

no_meinh = 6

output_invalid = 7

overflow = 8

OTHERS = 9.

CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'

EXPORTING

input = list-kuein

matnr = list-matnr

meinh = l_lvsme

meins = list-meins

charge = list-charg

werks = list-werks

IMPORTING

output = list-kuein

EXCEPTIONS

conversion_not_found = 1

input_invalid = 2

material_not_found = 3

meinh_not_found = 4

meins_missing = 5

no_meinh = 6

output_invalid = 7

overflow = 8

OTHERS = 9.

list-meins = l_lvsme.

ENDIF.

ENDFORM. " convert_to_ea

Former Member
0 Kudos

Hi,

Please go through the link updated by me for the example.

http://theguruspeaksaboutsap.blogspot.com/2008/01/report-zfirpprofitcenterdocs-no.html

Reward if helpful.

Regards,

Harini.S

Former Member
0 Kudos

Hi

Check these standard reports

BALVHD01

BALVHD01_GROUP

Use this FM REUSE_ALV_HIERSEQ_LIST_DISPLAY

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

EXPORTING

i_interface_check = 'I'

i_callback_program = gv_repid

i_callback_pf_status_set = 'STATUS_DATA'

i_callback_user_command = 'COMMAND_DATA'

is_layout = gs_layout

it_fieldcat = gt_fieldcat

i_default = ' '

i_save = 'A'

i_tabname_header = v_headers_itable

i_tabname_item = v_items_itable

i_structure_name_header = v_headers_table

i_structure_name_item = v_items_table

is_keyinfo = gs_keyinfo

i_bypassing_buffer = 'X'

TABLES

t_outtab_header = i_headers

t_outtab_item = i_result

t_outtab_item = i_report

EXCEPTIONS

program_error = 1

OTHERS = 2.

Check this sample report

-


***INCLUDE ZDEMO_ALVTREEO01 .

-


&----


*& Module STATUS_0100 OUTPUT

&----


text

-


MODULE status_0100 OUTPUT.

SET PF-STATUS 'STATUS1'.

SET TITLEBAR 'xxx'.

If ALVtree already exists then it mush not be re-created as this

  • will cause a runtime error.

IF gd_tree IS INITIAL.

Create ALVtree (must be performed within screen PBO module)

PERFORM create_alvtree_container.

PERFORM create_object_in_container.

PERFORM create_empty_alvtree_control.

PERFORM create_alvtree_hierarchy.

ENDIF.

CALL METHOD cl_gui_cfw=>flush.

ENDMODULE. " STATUS_0100 OUTPUT

-


INCLUDE ZDEMO_ALVTREEF01 *

-


&----


*& Form CREATE_ALVTREE_CONTAINER

&----


Create container for ALVtree report

-


form create_alvtree_container.

Create container for alv-tree

gd_tree_container_name = 'SCREEN_CONTAINER'.

create object gd_custom_container

exporting

container_name = gd_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'.

endif.

endform. " CREATE_ALVTREE_CONTAINER

&----


*& Form CREATE_OBJECT_IN_CONTAINER

&----


Create ALVtree object in container

-


form create_object_in_container.

Create tree control

create object gd_tree

exporting

parent = gd_custom_container

node_selection_mode = cl_gui_column_tree=>node_sel_mode_single

item_selection = 'X'

no_html_header = ''

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'.

endif.

endform. " CREATE_OBJECT_IN_CONTAINER

&----


*& Form BUILD_REPORT_TITLE

&----


Build table for ALVtree header

-


<-> p1 Header details

  • <-> p2 Logo value

-


FORM build_report_title CHANGING

pt_report_title TYPE slis_t_listheader

pa_logo TYPE sdydo_value.

DATA: ls_line TYPE slis_listheader,

ld_date(10) TYPE c.

List Heading Line(TYPE H)

CLEAR ls_line.

ls_line-typ = 'H'.

ls_line-key "Not Used For This Type(H)

ls_line-info = 'PO ALVTree Display'.

APPEND ls_line TO pt_report_title.

Status Line(TYPE S)

ld_date(2) = sy-datum+6(2).

ld_date+2(1) = '/'.

ld_date3(2) = sy-datum4(2).

ld_date+5(1) = '/'.

ld_date+6(4) = sy-datum(4).

ls_line-typ = 'S'.

ls_line-key = 'Date'.

ls_line-info = ld_date.

APPEND ls_line TO pt_report_title.

Action Line(TYPE A)

CLEAR ls_line.

ls_line-typ = 'A'.

CONCATENATE 'Report: ' sy-repid INTO ls_line-info SEPARATED BY space.

APPEND ls_line TO pt_report_title.

ENDFORM. " BUILD_REPORT_TITLE

&----


*& Form CREATE_EMPTY_ALVTREE_CONTROL

&----


Create empty tree control

-


FORM create_empty_alvtree_control.

Create emty tree-control

CLEAR: it_emptytab.

REFRESH: it_emptytab.

CALL METHOD gd_tree->set_table_for_first_display

EXPORTING

is_hierarchy_header = gd_hierarchy_header

it_list_commentary = gd_report_title

i_logo = gd_logo

i_background_id = 'ALV_BACKGROUND'

i_save = 'A'

is_variant = gd_variant

CHANGING

it_outtab = it_emptytab "Must be empty

it_fieldcatalog = gd_fieldcat.

ENDFORM. " CREATE_EMPTY_ALVTREE_CONTROL

&----


*& Form CREATE_ALVTREE_HIERARCHY

&----


text

-


Builds ALV tree display, (inserts nodes, subnodes etc)

-


form create_alvtree_hierarchy.

data: ls_sflight type sflight,

lt_sflight type sflight occurs 0.

data: ld_ebeln_key type lvc_nkey,

ld_ebelp_key type lvc_nkey.

loop at it_ekko into wa_ekko.

perform add_ekko_node using wa_ekko

''

changing ld_ebeln_key.

loop at it_ekpo into wa_ekpo where ebeln eq wa_ekko-ebeln.

perform add_ekpo_line using wa_ekpo

ld_ebeln_key

changing ld_ebelp_key.

endloop.

endloop.

calculate totals

call method gd_tree->update_calculations.

this method must be called to send the data to the frontend

call method gd_tree->frontend_update.

endform. " CREATE_ALVTREE_HIERARCHY

&----


*& Form ADD_EKKO_NODE

&----


text

-


-->P_WA_EKPO text

  • -->P_0553 text

  • <--P_EBELN_KEY text

-


form add_ekko_node using ps_ekko like wa_ekko

value(p_relate_key)

changing p_node_key.

data: ld_node_text type lvc_value,

ls_sflight type sflight.

Set item-layout

data: lt_item_layout type lvc_t_layi,

ls_item_layout type lvc_s_layi.

ls_item_layout-t_image = '@3P@'.

ls_item_layout-fieldname = gd_tree->c_hierarchy_column_name.

ls_item_layout-style = cl_gui_column_tree=>style_default.

ld_node_text = ps_ekko-ebeln.

append ls_item_layout to lt_item_layout.

Add node

call method gd_tree->add_node

exporting

i_relat_node_key = p_relate_key

i_relationship = cl_gui_column_tree=>relat_last_child

i_node_text = ld_node_text

is_outtab_line = ps_ekko

it_item_layout = lt_item_layout

importing

e_new_node_key = p_node_key.

endform. " ADD_EKKO_NODE

&----


*& Form ADD_EKPO_LINE

&----


text

-


-->P_WA_EKPO text

  • -->P_LD_EBELN_KEY text

  • <--P_LD_EBELP_KEY text

-


form add_ekpo_line using ps_ekpo like wa_ekpo

value(p_relate_key)

changing p_node_key.

data: ld_node_text type lvc_value,

ls_sflight type sflight.

Set item-layout

data: lt_item_layout type lvc_t_layi,

ls_item_layout type lvc_s_layi.

ls_item_layout-t_image = '@3P@'.

ls_item_layout-fieldname = gd_tree->c_hierarchy_column_name.

ls_item_layout-style = cl_gui_column_tree=>style_default.

ld_node_text = ps_ekpo-ebelp.

append ls_item_layout to lt_item_layout.

Add node

call method gd_tree->add_node

exporting

i_relat_node_key = p_relate_key

i_relationship = cl_gui_column_tree=>relat_last_child

i_node_text = ld_node_text

is_outtab_line = ps_ekpo

it_item_layout = lt_item_layout

importing

e_new_node_key = p_node_key.

endform. " ADD_EKPO_LINE

Check this link

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

Regards

Pavan

Edited by: Pavan praveen on Jan 17, 2008 10:59 AM

Former Member
0 Kudos

Hi

Hope this will help you.

Reward if help,.

REPORT ZBHALV_GRID.

TABLES:LFA1,EKKO.

SELECT-OPTIONS:LIFNR FOR LFA1-LIFNR.

DATA:BEGIN OF ITAB OCCURS 0,

LIFNR LIKE LFA1-LIFNR,

NAME1 LIKE LFA1-NAME1,

LAND1 LIKE LFA1-LAND1,

ORT01 LIKE LFA1-ORT01,

REGIO LIKE LFA1-REGIO,

SORTL LIKE LFA1-SORTL,

END OF ITAB.

*DATA:BEGIN OF JTAB OCCURS 0,

  • LIFNR LIKE EKKO-LIFNR,

  • EBELN LIKE EKKO-EBELN,

  • BUKRS LIKE EKKO-BUKRS,

  • BSTYP LIKE EKKO-BSTYP,

  • BSART LIKE EKKO-BSART,

*END OF JTAB.

DATA:JTAB LIKE EKKO OCCURS 0 WITH HEADER LINE.

SELECT * FROM LFA1 INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE LIFNR

IN LIFNR.

SELECT * FROM EKKO INTO CORRESPONDING FIELDS OF TABLE JTAB WHERE LIFNR

IN LIFNR.

TYPE-POOLS:SLIS.

DATA:FCAT TYPE SLIS_T_FIELDCAT_ALV.

DATA:KINFO TYPE SLIS_KEYINFO_ALV.

DATA:LAYOUT TYPE SLIS_LAYOUT_ALV.

DATA:EVE TYPE SLIS_T_EVENT WITH HEADER LINE.

DATA:HEAD TYPE SLIS_T_LISTHEADER WITH HEADER LINE.

LAYOUT-ZEBRA = 'X'.

LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

LAYOUT-WINDOW_TITLEBAR = 'VENDORS AND PURCHASE DOCCUMENTS

DETAILS'.

LAYOUT-numc_sum = 'X'.

KINFO-HEADER01 = 'LIFNR'.

KINFO-ITEM01 = 'LIFNR'.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 0

IMPORTING

ET_EVENTS = EVE[]

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.

READ TABLE EVE WITH KEY NAME = 'TOP_OF_PAGE'.

EVE-FORM = 'TOPOFPAGE'.

MODIFY EVE TRANSPORTING FORM WHERE NAME = 'TOP_OF_PAGE'.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = SY-REPID

I_INTERNAL_TABNAME = 'ITAB'

  • I_STRUCTURE_NAME =

  • I_CLIENT_NEVER_DISPLAY = 'X'

I_INCLNAME = SY-REPID

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

CT_FIELDCAT = FCAT

  • 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_HIERSEQ_LIST_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

I_CALLBACK_PROGRAM = SY-REPID

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

IS_LAYOUT = LAYOUT

IT_FIELDCAT = FCAT

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_SCREEN_START_COLUMN = 5

  • I_SCREEN_START_LINE = 5

  • I_SCREEN_END_COLUMN = 120

  • I_SCREEN_END_LINE = 25

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

IT_EVENTS = EVE[]

  • IT_EVENT_EXIT =

I_TABNAME_HEADER = 'ITAB'

I_TABNAME_ITEM = 'JTAB'

I_STRUCTURE_NAME_HEADER = 'LFA1'

I_STRUCTURE_NAME_ITEM = 'EKKO'

IS_KEYINFO = KINFO

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB_HEADER = ITAB[]

T_OUTTAB_ITEM = JTAB[]

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

FORM TOPOFPAGE.

REFRESH HEAD.

HEAD-TYP = 'H'.

HEAD-INFO = 'VENDORS & PURCHASE DOCC. DETAILS'.

APPEND HEAD.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = HEAD[]

  • I_LOGO = ' '

  • I_END_OF_LIST_GRID =

.

ENDFORM.

Former Member
0 Kudos

Hi Ramesh,

Here is the explanation of what is Hierarchy sequencial report and a sa,ple code below which might help you...

HIERARCHICAL REPORTS

A. REUSE_ALV_HIERSEQ_LIST_DISPLAY

1. Export:

a. I_CALLBACK_PROGRAM

b. I_CALLBACK_PF_STATUS_SET

c. I_CALLBACK_USER_COMMAND

d. IS_LAYOUT

e. IT_FIELDCAT

f. IT_EVENTS

g. I_TABNAME_HEADER : Name of the internal table in the program containing the output data of the

highest hierarchy level.

h. I_TABNAME_ITEM : Name of the internal table in the program containing the output data of the

lowest hierarchy level.

i. IS_KEYINFO : This structure contains the header and item table field names which link the two tables

(shared key).

2. Tables

a. T_OUTTAB_HEADER : Header table with data to be output

b. T_OUTTAB_ITEM : Name of the internal table in the program containing the output data of the

lowest hierarchy level.

Sample code:

TYPE-POOLS: slis.

TABLES : ekko, ekpo.

DATA : BEGIN OF i_ekko OCCURS 0,

ebeln LIKE ekko-ebeln,

ernam LIKE ekko-ernam,

bsart LIKE ekko-bsart,

var1,

END OF i_ekko.

DATA : BEGIN OF i_ekpo OCCURS 0,

ebeln LIKE ekpo-ebeln,

ebelp LIKE ekpo-ebelp,

matnr LIKE ekpo-matnr,

aedat LIKE ekpo-aedat,

var2,

END OF i_ekpo.

DATA : BEGIN OF i_final OCCURS 0,

ebeln LIKE ekko-ebeln,

ernam LIKE ekko-ernam,

bsart LIKE ekko-bsart,

ebelp LIKE ekpo-ebelp,

matnr LIKE ekpo-matnr,

aedat LIKE ekpo-aedat,

END OF i_final.

SELECT-OPTIONS : S_EBELN FOR EKKO-EBELN.

DATA : fcat TYPE slis_t_fieldcat_alv, "FIELDCATALOG(TABLE)

  • fcat1 TYPE slis_t_fieldcat_alv, "FIELDCATALOG(TABLE)

cat TYPE slis_fieldcat_alv. "FIELDCATALOG(WORK AREA)

DATA : LAYOUT1 TYPE SLIS_LAYOUT_ALV, "LAYOUT 1

  • LAYOUT2 TYPE SLIS_LAYOUT_ALV, "LAYOUT 2

KEY TYPE SLIS_KEYINFO_ALV , "KEY INFORMATION

GT_EVENT1 TYPE SLIS_T_EVENT.

START-OF-SELECTION.

PERFORM GETTING_DATA.

PERFORM append_field.

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-CPROG

IS_LAYOUT = LAYOUT1

IT_FIELDCAT = FCAT

  • IT_EVENTS = GT_EVENT1

i_tabname_header = 'I_EKKO'

i_tabname_item = 'I_EKPO'

is_keyinfo = KEY

tables

t_outtab_header = I_EKKO

t_outtab_item = I_EKPO.

*&----


*

*& Form GETTING_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GETTING_DATA .

SELECT EBELN BSART ERNAM UP TO 100 ROWS

INTO CORRESPONDING FIELDS OF TABLE I_EKKO

FROM EKKO

WHERE EBELN IN S_EBELN.

SELECT EBELN EBELP MATNR AEDAT

INTO CORRESPONDING FIELDS OF TABLE I_EKPO

FROM EKPO

FOR ALL ENTRIES IN I_EKKO

WHERE EBELN = I_EKKO-EBELN .

SORT I_EKKO BY EBELN.

LOOP AT I_EKKO.

READ TABLE I_EKPO WITH KEY EBELN = I_EKKO-EBELN.

IF SY-SUBRC EQ 0.

MOVE: I_EKKO-EBELN TO I_FINAL-EBELN,

I_EKKO-BSART TO I_FINAL-BSART,

I_EKKO-ERNAM TO I_FINAL-ERNAM,

I_EKPO-EBELP TO I_FINAL-EBELP,

I_EKPO-MATNR TO I_FINAL-MATNR,

I_EKPO-AEDAT TO I_FINAL-AEDAT.

APPEND I_FINAL.

ENDIF.

ENDLOOP.

ENDFORM. " GETTING_DATA

&----


*& Form APPEND_FIELD

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM append_field .

CLEAR cat.

cat-col_pos = 1.

cat-fieldname = 'EBELN'.

cat-tabname = 'I_EKKO'.

cat-ref_fieldname = 'EBELN'.

cat-ref_tabname = 'EKKO'.

cat-key = 'X'. "define field as key

APPEND cat TO fcat.

CLEAR cat.

cat-col_pos = 2.

cat-fieldname = 'BSART'.

cat-tabname = 'I_EKKO'.

cat-ref_fieldname = 'BSART'.

cat-ref_tabname = 'EKKO'.

APPEND cat TO fcat.

CLEAR cat.

cat-col_pos = 3.

cat-fieldname = 'ERNAM'.

cat-tabname = 'I_EKKO'.

cat-ref_fieldname = 'ERNAM'.

cat-ref_tabname = 'EKKO'.

APPEND cat TO fcat.

CLEAR cat.

cat-col_pos = 4.

cat-fieldname = 'EBELP'.

cat-tabname = 'I_EKPO'.

cat-ref_fieldname = 'EBELP'.

cat-ref_tabname = 'EKPO'.

cat-key = 'X'. "define field as key

APPEND cat TO fcat.

CLEAR cat.

cat-col_pos = 5.

cat-fieldname = 'MATNR'.

cat-tabname = 'I_EKPO'.

cat-ref_fieldname = 'MATNR'.

cat-ref_tabname = 'EKPO'.

APPEND cat TO fcat.

CLEAR cat.

cat-col_pos = 6.

cat-fieldname = 'AEDAT'.

cat-tabname = 'I_EKPO'.

cat-ref_fieldname = 'AEDAT'.

cat-ref_tabname = 'EKPO'.

APPEND cat TO fcat.

CLEAR cat.

layout1-expand_fieldname = 'VAR1'.

layout1-lights_fieldname = '3'.

layout1-lights_tabname = 'I_EKPO'.

key-header01 = 'EBELN'.

key-item01 = 'EBELN'.

ENDFORM. " APPEND_FIELD

This helps u a lot..

Thankyou,

Regards.