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 problems

Former Member
0 Kudos

hey guys

I am facing a small problem:

i written a code in to display the output in alv format.

In that i have two tables in nested format. That is during declaration i have two tables see the sample of field-catalog declaration.

fieldcat-tabname = 'IITEM'.

fieldcat-fieldname = 'KUNNR'.

fieldcat-ref_fieldname ='KUNNR'.

fieldcat-ref_tabname ='ZVBRKVBRP'.

fieldcat-col_pos = '1'.

fieldcat-seltext_m = 'Billing Doc'.

fieldcat-seltext_l = 'Billing Doc'.

fieldcat-seltext_s = 'Billing Doc'.

APPEND fieldcat TO fieldtab.

CLEAR fieldcat.

fieldcat-tabname = 'IVBELN'.

fieldcat-fieldname = 'POSNR'.

fieldcat-col_pos = '2'.

fieldcat-seltext_m = 'Billing Item'.

fieldcat-seltext_l = 'Billing Item'.

fieldcat-seltext_s = 'Billing Item'.

APPEND fieldcat TO fieldtab.

CLEAR fieldcat.

here IITEM is outer internal table and

IVBELN is inner internal table.

Although my final output of the program is working fine, but the problem is:

i cant able to do subtotal (ctlshiftf6) according to inner internal table. is there any problem in settings or it should be hard-coded.

I am using TYPE-POOLS : SLIS.

Pls help me.

Deepak

1 REPLY 1

former_member221770
Contributor
0 Kudos

Hi Depaak,

I am going to assume you are using the basic function module REUSE_ALV_LIST_DISPLAY, have you tried to use the function module REUSE_ALV_HIERSEQ_LIST_DISPLAY instead? This FM allows you to define 2 internal tables with a "header" and "item" relationship.

Here is some code demonstrating how to use this FM. You can sort and do totaling and subtotaling the usual way. Let me know if you get any problems.

Cheers,

Pat

&----


*& Report ZPAT2 *

*& *

&----


*& *

*& *

&----


  • Modification History

*----


  • Date | Author | Chg Req # | Description

*----


  • 15.08.2001| Pat Yee | $TMP | Program Creation

*----


  • This program is an example of how the ALV Hierarchy Display works.

  • It will display a sales order and it's associated line items

REPORT zpat2.

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

  • Types

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

TYPE-POOLS: kkblo.

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

  • Database Tables

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

TABLES: vbak, vbap.

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

  • Structures

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

DATA: st_fieldcat TYPE slis_fieldcat_alv.

DATA: st_keyinfo TYPE slis_keyinfo_alv.

DATA: st_sort TYPE slis_sortinfo_alv.

DATA: st_layout TYPE slis_layout_alv.

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

  • Internal tables

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

DATA: tbl_fieldcat TYPE slis_t_fieldcat_alv.

DATA: tbl_sort TYPE slis_t_sortinfo_alv.

DATA: BEGIN OF tbl_header OCCURS 0.

INCLUDE STRUCTURE vbak.

DATA: END OF tbl_header.

DATA: BEGIN OF tbl_item OCCURS 0.

INCLUDE STRUCTURE vbap.

DATA: END OF tbl_item.

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

  • Constants

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

CONSTANTS: c_y VALUE 'X'. "Yes

CONSTANTS: c_n VALUE ' '. "No

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

  • Simple Variables

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

DATA: field_name(30) TYPE c,

g_repid like sy-repid.

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

  • Selection Screen

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

SELECTION-SCREEN BEGIN OF BLOCK sel_options WITH FRAME TITLE text-tt1.

SELECT-OPTIONS s_vbeln FOR vbak-vbeln.

SELECTION-SCREEN END OF BLOCK sel_options.

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

  • Start of Selection

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

START-OF-SELECTION.

  • Get the Report ID

g_repid = sy-repid.

  • Select data from the Sales Document Header Table

SELECT * FROM vbak INTO TABLE tbl_header

WHERE vbeln IN s_vbeln.

  • Select the relevant Sales Document Item data

SELECT * FROM vbap INTO TABLE tbl_item

FOR ALL ENTRIES IN tbl_header

WHERE vbeln = tbl_header-vbeln.

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

  • End of Selection

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

END-OF-SELECTION.

PERFORM get_keyinfo.

PERFORM get_layout.

PERFORM get_sort.

PERFORM get_fieldcat.

PERFORM create_report.

&----


*& Form get_fieldcat

&----


  • text

----


FORM get_fieldcat.

  • Here the field catalog is created. To display more fields simply

  • 'uncomment' the additional lines and add the field name. Also note

  • that the field catalog is much more powerful than this. You can

  • intensify fields, change the colour, assign reference fields, etc.

  • Look at type slis_fieldcat_alv for more options.

  • Header

PERFORM write_fieldcat USING 'VBELN' 'TBL_HEADER' 'VBAK' c_y 1

c_n c_y c_n c_n.

PERFORM write_fieldcat USING 'ERDAT' 'TBL_HEADER' 'VBAK' c_n 2

c_n c_n c_n c_y.

PERFORM write_fieldcat USING 'AUDAT' 'TBL_HEADER' 'VBAK' c_n 3

c_n c_n c_n c_n.

PERFORM write_fieldcat USING 'VBTYP' 'TBL_HEADER' 'VBAK' c_n 4

c_n c_n c_n c_n.

PERFORM write_fieldcat USING 'WAERK' 'TBL_HEADER' 'VBAK' c_n 5

c_n c_n c_n c_n.

PERFORM write_fieldcat USING 'VKBUR' 'TBL_HEADER' 'VBAK' c_n 6

c_n c_n c_n c_y.

  • perform write_fieldcat using ' ' 'TBL_HEADER' 'VBAK' ' ' 7.

  • perform write_fieldcat using ' ' 'TBL_HEADER' 'VBAK' ' ' 8.

  • perform write_fieldcat using ' ' 'TBL_HEADER' 'VBAK' ' ' 9.

  • perform write_fieldcat using ' ' 'TBL_HEADER' 'VBAK' ' ' 10.

  • Item

PERFORM write_fieldcat USING 'POSNR' 'TBL_ITEM' 'VBAP' c_y 1

c_n c_n c_n c_n.

PERFORM write_fieldcat USING 'MATNR' 'TBL_ITEM' 'VBAP' c_n 2

'C411' c_n c_n c_n.

PERFORM write_fieldcat USING 'NETPR' 'TBL_ITEM' 'VBAP' c_n 3

'C300' c_n c_y c_n.

PERFORM write_fieldcat USING 'PRCTR' 'TBL_ITEM' 'VBAP' c_n 4

c_n c_n c_n 'X'.

PERFORM write_fieldcat USING 'GSBER' 'TBL_ITEM' 'VBAP' c_n 5

c_n c_n c_n 'X'.

PERFORM write_fieldcat USING 'WERKS' 'TBL_ITEM' 'VBAP' c_n 6

c_n c_n c_n 'X'.

PERFORM write_fieldcat USING 'AUFNR' 'TBL_ITEM' 'VBAP' c_n 7

'C611' c_n c_n c_n.

  • perform write_fieldcat using ' ' 'TBL_ITEM' 'VBAP' ' ' 8.

  • perform write_fieldcat using ' ' 'TBL_ITEM' 'VBAP' ' ' 9.

  • perform write_fieldcat using ' ' 'TBL_ITEM' 'VBAP' ' ' 10.

  • perform write_fieldcat using ' ' 'TBL_ITEM' 'VBAP' ' ' 11.

  • perform write_fieldcat using ' ' 'TBL_ITEM' 'VBAP' ' ' 12.

ENDFORM. " get_fieldcat

&----


*& Form write_fieldcat

&----


  • text

----


  • -->name Field name

  • -->tab Table name

  • -->st Structure Name

  • -->key Is this field a Key?

  • -->pos Position Number

  • -->emp Emphasize

  • -->hot Hotspot

  • -->sum Do_sum

  • -->hide No_out

----


FORM write_fieldcat USING name tab st key pos emp hot sum hide.

st_fieldcat-fieldname = name.

st_fieldcat-tabname = tab.

st_fieldcat-ref_tabname = st.

st_fieldcat-key = key.

st_fieldcat-col_pos = pos.

st_fieldcat-emphasize = emp.

st_fieldcat-hotspot = hot.

st_fieldcat-do_sum = sum.

st_fieldcat-no_out = hide.

APPEND st_fieldcat TO tbl_fieldcat.

CLEAR st_fieldcat.

ENDFORM. " write_fieldcat

&----


*& Form create_report

&----


  • Hummmm I wonder what this subroutine does?

----


FORM create_report.

  • Here we call the Function Module to create the Hierarchical

  • Sequential List

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

EXPORTING

i_interface_check = ' '

i_callback_program = g_repid

i_callback_user_command = 'PROCESS_USER_COMMANDS'

is_layout = st_layout

it_fieldcat = tbl_fieldcat

it_sort = tbl_sort

i_default = 'X'

i_save = 'A'

is_variant = ' '

i_tabname_header = 'TBL_HEADER'

i_tabname_item = 'TBL_ITEM'

is_keyinfo = st_keyinfo

TABLES

t_outtab_header = tbl_header

t_outtab_item = tbl_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. " create_report

&----


*& Form get_keyinfo

&----


  • text

----


FORM get_keyinfo.

  • This defines the "link" between the "header" and "item" tables

st_keyinfo-header01 = 'VBELN'.

ENDFORM. " get_keyinfo

&----


*& Form get_sort

&----


  • text

----


FORM get_sort.

  • Here we sort the report by the Document Number...why not?

REFRESH tbl_sort.

CLEAR st_sort.

st_sort-spos = 1.

st_sort-fieldname = 'VBELN'.

st_sort-up = 'X'.

APPEND st_sort TO tbl_sort.

ENDFORM. " get_sort

----


  • FORM process_user_commands *

----


  • Interactive Reporting commands

----


  • --> SYST-UCOMM *

  • --> SELFIELD *

----


FORM process_user_commands USING syst-ucomm LIKE syst-ucomm

selfield TYPE slis_selfield.

  • This subroutine is called when there is user interaction in the output

  • In this case if the user double clicks the Document Number then the

  • program will call transaction VA03 and display the Sales Document

CASE syst-ucomm.

WHEN '&IC1'.

GET CURSOR FIELD field_name.

IF field_name = 'TBL_HEADER-VBELN'.

READ TABLE tbl_header INDEX selfield-tabindex.

CHECK tbl_header-vbeln NE 0.

SET PARAMETER ID 'AUN' FIELD tbl_header-vbeln.

CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.

ENDIF.

WHEN OTHERS.

ENDCASE.

ENDFORM. "process_user_commands

&----


*& Form get_layout

&----


  • text

----


FORM get_layout.

  • Here we manipulate the layout of the list. In this instance we are

  • giving the list a 'zebra' format. Once again like the field catalog

  • there are many more options available. Look at type slis_layout_alv

  • for more options.

CLEAR st_layout.

st_layout-zebra = 'X'.

ENDFORM. " get_layout