2009 Jan 26 10:48 AM
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.
2009 Jan 26 11:08 AM
The code is correct, and tested the system on which I am working correctly extract the data.
the only problem that I have permission to change is as follows :
select vbeln erdat waerk netwr from vbak into corresponding fields of
table it_vbak
where vbeln in Order_no.
this was not the cause of error .
2009 Jan 26 11:08 AM
The code is correct, and tested the system on which I am working correctly extract the data.
the only problem that I have permission to change is as follows :
select vbeln erdat waerk netwr from vbak into corresponding fields of
table it_vbak
where vbeln in Order_no.
this was not the cause of error .
2009 Jan 26 11:08 AM
Hi
That works, you need to indicate the reference dictionary table and field for catalog table and correct the selection where condition (use option IN):
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
*----------------------------------------------------------------------*
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
*----------------------------------------------------------------------*
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'.
wa_fieldcat-ref_fieldname = wa_fieldcat-fieldname. "<--------------
wa_fieldcat-ref_tabname = 'VBAK'. "<--------------
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'.
wa_fieldcat-ref_fieldname = wa_fieldcat-fieldname.
wa_fieldcat-ref_tabname = 'VBAK'.
APPEND wa_fieldcat TO it_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'.
wa_fieldcat-ref_fieldname = wa_fieldcat-fieldname.
wa_fieldcat-ref_tabname = 'VBAK'.
APPEND wa_fieldcat TO it_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'.
wa_fieldcat-ref_fieldname = wa_fieldcat-fieldname.
wa_fieldcat-ref_tabname = 'VBAK'.
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'.
wa_fieldcat-ref_fieldname = wa_fieldcat-fieldname.
wa_fieldcat-ref_tabname = 'VBAP'.
APPEND wa_fieldcat TO it_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'.
wa_fieldcat-ref_fieldname = wa_fieldcat-fieldname.
wa_fieldcat-ref_tabname = 'VBAP'.
APPEND wa_fieldcat TO it_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'.
wa_fieldcat-ref_fieldname = wa_fieldcat-fieldname.
wa_fieldcat-ref_tabname = 'VBAP'.
APPEND wa_fieldcat TO it_fieldcat.
ENDFORM. " build_fieldcat
*&---------------------------------------------------------------------*
*& Form build_layout
*&---------------------------------------------------------------------*
* 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
*----------------------------------------------------------------------*
FORM build_key .
*key infomation for the header and item table
key-header01 = 'VBELN'.
key-item01 = 'VBELN'.
ENDFORM. " build_key
*&---------------------------------------------------------------------*
*& Form list_display
*&---------------------------------------------------------------------*
* 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
*----------------------------------------------------------------------*
FORM fetch_tabledata .
*select table data
SELECT vbeln erdat waerk netwr FROM vbak INTO CORRESPONDING FIELDS OF TABLE it_vbak
WHERE vbeln IN order_no. "<------------------------------------
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.
2009 Jan 26 11:48 AM
it is still not working. every time i execute the code, it says.....'list contain no data'. but there is data in the table for that perticular sales order number. please help me out with this.
2009 Jan 27 9:29 AM
Hi
U need to check how u select the data from VBAK and VBAP:
FORM fetch_tabledata .
*select table data
SELECT vbeln erdat waerk netwr FROM vbak INTO CORRESPONDING FIELDS OF TABLE it_vbak
WHERE vbeln IN order_no.
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.
Max
2009 Jan 26 11:15 AM
Hello,
If you declare a select-option, you should use the 'IN'-opeator in your select-statement.
select vbeln erdat waerk netwr from vbak into corresponding fields of table it_vbak
where vbeln in Order_no.
Regards Wolfgang
2009 Jan 26 9:45 PM
oops....wrong post....sorry.
Edited by: Mubeen Ahmed on Jan 26, 2009 10:45 PM