Skip to Content
0
Former Member
Jan 26, 2009 at 10:48 AM

program is not giving the desired output

25 Views

i have written the following code. it is syntactically correct. but not giving the actual output. actually, the internal tables are not filling. please someone check the code where it is not working.

  • type-pools declarations for alv and icon

TYPE-POOLS: slis.

Tables: vbak, vbap.

*structure declaration for table details

Data : BEGIN OF it_vbak occurs 0,

vbeln like vbak-vbeln,

erdat like vbak-erdat,

waerk like vbak-waerk,

netwr like vbak-netwr,

expand,

END OF it_vbak.

*structure declarations for field details

Data : BEGIN OF it_vbap occurs 0,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

matnr like vbap-matnr,

netwr like vbap-netwr,

END OF it_vbap.

*data declarations for ALV

DATA : it_fieldcat TYPE slis_t_fieldcat_alv,

wa_fieldcat TYPE slis_fieldcat_alv,

it_layout TYPE slis_layout_alv,

key TYPE slis_keyinfo_alv.

*Input the tables.User cannot enter a range but can enter any number

*of tables one by one in this select-options

SELECT-OPTIONS : Order_no for vbak-vbeln.

*initializatin event

INITIALIZATION.

*start-of-selection event

START-OF-SELECTION.

*subroutine to fetch the data from the tables

PERFORM fetch_tabledata.

*subroutine to build alv hierarchy output

PERFORM hierarchyalv_build.

&----


*& Form hierarchyalv_build

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form hierarchyalv_build .

*fieldcatalogue

perform build_fieldcat.

*layout

perform build_layout.

*key information for hierarchy

perform build_key.

*output

perform list_display.

endform. " hierarchyalv_build

&----


*& Form build_fieldcat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form build_fieldcat .

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 1.

wa_fieldcat-fieldname = 'VBELN'.

wa_fieldcat-tabname = 'IT_VBAK'.

wa_fieldcat-seltext_m = 'Sales Order No'.

wa_fieldcat-key = 'X'.

wa_fieldcat-emphasize = 'C610'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 2.

wa_fieldcat-fieldname = 'ERDAT'.

wa_fieldcat-tabname = 'IT_VBAK'.

wa_fieldcat-seltext_m = 'Creation Date'.

wa_fieldcat-emphasize = 'C600'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 3.

wa_fieldcat-fieldname = 'WAERK'.

wa_fieldcat-tabname = 'IT_VBAK'.

wa_fieldcat-seltext_m = 'Document Currency'.

wa_fieldcat-emphasize = 'C510'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 4.

wa_fieldcat-fieldname = 'NETWR'.

wa_fieldcat-tabname = 'IT_VBAK'.

wa_fieldcat-seltext_m = 'Amount'.

wa_fieldcat-emphasize = 'C500'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 5.

wa_fieldcat-fieldname = 'VBELN'.

wa_fieldcat-tabname = 'IT_VBAP'.

wa_fieldcat-seltext_m = 'Sales Order No'.

wa_fieldcat-key = 'X'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 5.

wa_fieldcat-fieldname = 'POSNR'.

wa_fieldcat-tabname = 'IT_VBAP'.

wa_fieldcat-seltext_m = 'Item'.

wa_fieldcat-emphasize = 'C410'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 6.

wa_fieldcat-fieldname = 'MATNR'.

wa_fieldcat-tabname = 'IT_VBAP'.

wa_fieldcat-seltext_m = 'Material No'.

wa_fieldcat-emphasize = 'C400'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 7.

wa_fieldcat-fieldname = 'NETWR'.

wa_fieldcat-tabname = 'IT_VBAP'.

wa_fieldcat-seltext_m = 'Amount'.

wa_fieldcat-emphasize = 'C310'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

endform. " build_fieldcat

&----


*& Form build_layout

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form build_layout .

*to expand the header table for item details

it_layout-expand_fieldname = 'EXPAND'.

it_layout-window_titlebar = 'Hierarchical ALV list display'.

it_layout-lights_tabname = 'IT_VBAP'.

it_layout-colwidth_optimize = 'X'.

endform. " build_layout

&----


*& Form build_key

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form build_key .

*key infomation for the header and item table

key-header01 = 'VBELN'.

key-item01 = 'VBELN'.

endform. " build_key

&----


*& Form list_display

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form list_display .

*ALV output

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

EXPORTING

i_callback_program = sy-cprog

is_layout = it_layout

it_fieldcat = it_fieldcat

i_tabname_header = 'IT_VBAK'

i_tabname_item = 'IT_VBAP'

is_keyinfo = key

TABLES

t_outtab_header = it_vbak

t_outtab_item = it_vbap.

endform. " list_display

&----


*& Form fetch_tabledata

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form fetch_tabledata .

*select table data

select vbeln erdat waerk netwr from vbak into corresponding fields of table it_vbak

where vbeln between Order_no-low and Order_no-high.

if not it_vbak[] is initial.

select vbeln posnr matnr netwr from vbap into table it_vbap for all entries in it_vbak

where vbeln = it_vbak-vbeln.

endif.

endform.