Skip to Content
0
Former Member
Mar 13, 2007 at 02:14 PM

Error In report

13 Views

Hello all,

I am using GUI_DOWNLOAD in my report to download the data to pC.I am able to download the data correctly. i am able to get the fieldnames also. But they are coming in a worng way, i.e all field names are coming first in a column(not in a row)

wise then the data is coming.I am giving my code below, can anybody explain where i did wrong.

ABLES: mara, "GENERAL MASTER DATA

marc, "PLANT DATA FOR MATERIAL

mard, "STORAGE LOCATION DATA FOR MATERIAL

mvke, "SALES DATA FOR MATERIAL

makt, "MATERIAL DESCRIPTION

ekpo. "PURCHASING DOCUMENT ITEM.

TYPE-POOLS : SLIS.

  • ALL THE INTERNAL TABLES STRUCTURES AND CONSTANTS DEFINATIONS ARE **

  • DECLARED IN TYPE-POOL CALLED SLIS **

  • DATA: vt_fieldcatlog1 TYPE SLIS_T_FIELDCAT_ALV.

    • THIS INTERNAL TABLE CONTAINS THE FIELD ATTRIBUTES *

    DATA: v_layout TYPE SLIS_LAYOUT_ALV.

    DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

    DATA: BEGIN OF field_names OCCURS 0,

    text(100),

    END OF field_names.

    • INTERNAL TABLE FOR APPENDING FIELD NAMES IN THE FILE

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

    • I N T E R N A L T A B L E S *******************

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

    DATA:BEGIN OF i_marc OCCURS 0,

    matnr LIKE marc-matnr,

    werks LIKE marc-werks,

    dispo LIKE marc-dispo,

    END OF i_marc.

    DATA:BEGIN OF i_mard OCCURS 0,

    matnr LIKE mard-matnr,

    lgort LIKE mard-lgort,

    labst LIKE mard-labst,

    END OF i_mard.

    DATA: BEGIN OF i_mvke OCCURS 0,

    matnr LIKE mvke-matnr,

    vkorg LIKE mvke-vkorg,

    vtweg LIKE mvke-vtweg,

    END OF i_mvke.

    DATA: Begin of i_ekpo occurs 0,

    ebeln LIKE ekpo-ebeln,

    ebelp LIKE ekpo-ebelp,

    matnr LIKE ekpo-matnr,

    End of i_ekpo.

    DATA: BEGIN OF i_out occurs 0,

    matnr LIKE marc-matnr,

    werks LIKE marc-werks,

    dispo LIKE marc-dispo,

    mbrsh LIKE mara-mbrsh,

    meins LIKE mara-meins,

    matkl LIKE mara-matkl,

    vkorg LIKE mvke-vkorg,

    vtweg LIKE mvke-vtweg,

    spras LIKE makt-spras,

    maktx LIKE makt-maktx,

    lgort LIKE mard-lgort,

    labst LIKE mard-labst,

    ebeln LIKE ekpo-ebeln,

    ebelp LIKE ekpo-ebelp,

    END OF i_out.

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

    • S E L E C T I O N S C R E E N *******************

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

    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-100.

    PARAMETERS: p_werks LIKE marc-werks. "OBLIGATORY.

    SELECT-OPTIONS: s_matnr FOR marc-matnr, "OBLIGATORY,

    s_lgort FOR mard-lgort,

    s_dispo FOR marc-dispo,

    s_ebeln FOR ekpo-ebeln no intervals.

    SELECTION-SCREEN END OF BLOCK b1.

    *

    *SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-101.

    *

    *PARAMETER : savelist AS CHECKBOX.

    *PARAMETER : p_file LIKE RLGRAP-FILENAME DEFAULT 'C:\MATERIAL.TXT'.

    *

    *SELECTION-SCREEN END OF BLOCK b2.

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

    • S T A R T - O F - S E L EC T I O N *******************

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

    START-OF-SELECTION.

    SELECT matnr werks dispo

    FROM marc

    INTO TABLE i_marc

    WHERE matnr IN s_matnr

    AND werks EQ p_werks

    AND dispo IN s_dispo.

    IF i_marc[] IS INITIAL.

    WRITE:/'NO MATCHING DATA IS FOUND FROM TABLE MARC'.

    EXIT.

    ENDIF.

    SELECT matnr lgort labst

    FROM mard

    INTO TABLE i_mard

    FOR ALL ENTRIES IN i_marc

    WHERE matnr = i_marc-matnr

    AND werks EQ i_marc-werks

    AND lgort IN s_lgort.

    IF i_mard[] IS INITIAL.

    WRITE:/ 'NO MATCHING DATA IS SELECTED FROM TABLE MARD'.

    EXIT.

    ENDIF.

    SELECT matnr vkorg vtweg

    FROM mvke

    INTO TABLE i_mvke

    FOR ALL ENTRIES IN i_marc

    WHERE matnr = i_marc-matnr.

    IF i_mvke[] IS INITIAL.

    WRITE:/ 'NO MATCHING DATA IS SELECTED FROM TABLE MVKE'.

    EXIT.

    ENDIF.

    SELECT ebeln ebelp matnr

    FROM ekpo

    INTO TABLE i_ekpo

    FOR ALL ENTRIES IN i_marc

    WHERE matnr = i_marc-matnr

    AND ebeln IN s_ebeln.

    IF i_ekpo[] IS INITIAL.

    WRITE:/ 'NO MATCHING DATA IS SELECTED FROM TABLE EKPO'.

    EXIT.

    ENDIF.

    LOOP AT i_marc.

    MOVE-CORRESPONDING i_marc TO i_out.

    CLEAR marc.

    SELECT SINGLE matnr mbrsh meins matkl

    FROM mara

    INTO CORRESPONDING FIELDS OF mara

    WHERE matnr = i_out-matnr.

    IF SY-SUBRC = 0.

    MOVE-CORRESPONDING mara TO i_out.

    ELSE.

    CONTINUE.

    ENDIF.

    SELECT SINGLE matnr spras maktx

    FROM makt

    INTO CORRESPONDING FIELDS OF makt

    WHERE matnr = i_out-matnr

    AND spras = SY-LANGU.

    IF SY-SUBRC = 0.

    MOVE-CORRESPONDING makt TO i_out.

    ENDIF.

    LOOP AT i_mard WHERE matnr = i_marc-matnr.

    MOVE:i_mard-lgort TO i_out-lgort,

    i_mard-labst TO i_out-labst.

    ENDLOOP.

    LOOP AT i_mvke WHERE matnr = i_marc-matnr.

    MOVE:i_mvke-vkorg TO i_out-vkorg,

    i_mvke-vtweg TO i_out-vtweg.

    ENDLOOP.

    READ TABLE i_ekpo WITH KEY matnr = i_marc-matnr BINARY SEARCH.

    IF sy-subrc EQ 0.

    MOVE: i_ekpo-ebeln TO i_out-ebeln,

    i_ekpo-ebelp TO i_out-ebelp.

    ENDIF.

    APPEND i_out.

    DELETE ADJACENT DUPLICATES FROM I_OUT.

    CLEAR i_out.

    ENDLOOP.

    PERFORM list_output_headings.

    *Subroutine For Displaying Fieldnames on the output list

    PERFORM get_fieldcat1.

    *Subroutine For Displaying Fields in Respective Positions

    PERFORM get_fieldcat2.

    *Subroutine For Top of page and log Display

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

    • E N D - O F - S E L EC T I O N ***********************

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

    END-OF-SELECTION.

    ----


    • F O R M list_output_headings. *

    ----


    FORM list_output_headings.

    • IF savelist = 'X'.

    field_names-text = 'Material No'.

    APPEND field_names.

    CLEAR field_names.

    field_names-text = 'Plant'.

    APPEND field_names.

    CLEAR field_names.

    field_names-text = 'MRP Control'.

    APPEND field_names.

    CLEAR field_names.

    field_names-text = 'Industry'.

    APPEND field_names.

    CLEAR field_names.

    field_names-text = 'Unit of Measure'.

    APPEND field_names.

    CLEAR field_names.

    field_names-text = 'Material Group'.

    APPEND field_names.

    CLEAR field_names.

    field_names-text = 'Sales Org'.

    APPEND field_names.

    CLEAR field_names.

    field_names-text = 'Dst Channel'.

    APPEND field_names.

    CLEAR field_names.

    field_names-text = 'Material Desc'.

    APPEND field_names.

    CLEAR field_names.

    field_names-text = 'Storage Loct'.

    APPEND field_names.

    CLEAR field_names.

    field_names-text = 'Stock'.

    APPEND field_names.

    CLEAR field_names.

    field_names-text = 'Purchase Docu No'.

    APPEND field_names.

    CLEAR field_names.

    field_names-text = 'Item No'.

    APPEND field_names.

    CLEAR field_names.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    FILENAME = 'C:\RAV.XLS'

    FILETYPE = 'ASC'

    WRITE_FIELD_SEPARATOR = 'X'

    TABLES

    DATA_TAB = field_names

    EXCEPTIONS

    FILE_WRITE_ERROR = 1.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    FILENAME = 'C:\RAV.XLS'

    FILETYPE = 'ASC'

    APPEND = 'X'

    WRITE_FIELD_SEPARATOR = 'X'

    TABLES

    DATA_TAB = i_out

    EXCEPTIONS

    FILE_WRITE_ERROR = 1

    NO_BATCH = 2

    GUI_REFUSE_FILETRANSFER = 3.

    • ENDIF.

    ENDFORM. "list_output_headings

    ----


    • F O R M GET_FIELDCAT1. *

    ----


    FORM get_fieldcat1.

    DATA: v_fieldcatlog TYPE SLIS_FIELDCAT_ALV.

    *DATA: v_fieldcatlog TYPE STANDARD TABLE OF

    • SLIS_FIELDCAT_ALV WITH HEADER LINE.

    v_fieldcatlog-col_pos = '1'.

    v_fieldcatlog-fieldname = 'MATNR'.

    v_fieldcatlog-tabname = 'I_OUT'.

    v_fieldcatlog-ref_fieldname = 'MATNR'.

    v_fieldcatlog-ref_tabname = 'MARC'.

    v_fieldcatlog-hotspot = 'X'.

    APPEND v_fieldcatlog TO vt_fieldcatlog1.

    CLEAR v_fieldcatlog.

    v_fieldcatlog-col_pos = '2'.

    v_fieldcatlog-fieldname = 'WERKS'.

    v_fieldcatlog-tabname = 'I_OUT'.

    v_fieldcatlog-ref_fieldname = 'WERKS'.

    v_fieldcatlog-ref_tabname = 'MARC'.

    APPEND v_fieldcatlog TO vt_fieldcatlog1.

    CLEAR v_fieldcatlog.

    v_fieldcatlog-col_pos = '3'.

    v_fieldcatlog-fieldname = 'DISPO'.

    v_fieldcatlog-tabname = 'I_OUT'.

    v_fieldcatlog-ref_fieldname = 'DISPO'.

    v_fieldcatlog-ref_tabname = 'MARC'.

    APPEND v_fieldcatlog TO vt_fieldcatlog1.

    CLEAR v_fieldcatlog.

    v_fieldcatlog-col_pos = '4'.

    v_fieldcatlog-fieldname = 'MBRSH'.

    v_fieldcatlog-tabname = 'I_OUT'.

    v_fieldcatlog-ref_fieldname = 'MBRSH'.

    v_fieldcatlog-ref_tabname = 'MARA'.

    APPEND v_fieldcatlog TO vt_fieldcatlog1.

    CLEAR v_fieldcatlog.

    v_fieldcatlog-col_pos = '5'.

    v_fieldcatlog-fieldname = 'MEINS'.

    v_fieldcatlog-tabname = 'I_OUT'.

    v_fieldcatlog-ref_fieldname = 'MEINS'.

    v_fieldcatlog-ref_tabname = 'MARA'.

    APPEND v_fieldcatlog TO vt_fieldcatlog1.

    CLEAR v_fieldcatlog.

    v_fieldcatlog-col_pos = '6'.

    v_fieldcatlog-fieldname = 'MATKL'.

    v_fieldcatlog-tabname = 'I_OUT'.

    v_fieldcatlog-ref_fieldname = 'MATKL'.

    v_fieldcatlog-ref_tabname = 'MARA'.

    APPEND v_fieldcatlog TO vt_fieldcatlog1.

    CLEAR v_fieldcatlog.

    v_fieldcatlog-col_pos = '7'.

    v_fieldcatlog-fieldname = 'VKORG'.

    v_fieldcatlog-tabname = 'I_OUT'.

    v_fieldcatlog-ref_fieldname = 'VKORG'.

    v_fieldcatlog-ref_tabname = 'MVKE'.

    APPEND v_fieldcatlog TO vt_fieldcatlog1.

    CLEAR v_fieldcatlog.

    v_fieldcatlog-col_pos = '8'.

    v_fieldcatlog-fieldname = 'VTWEG'.

    v_fieldcatlog-tabname = 'I_OUT'.

    v_fieldcatlog-ref_fieldname = 'VTWEG'.

    v_fieldcatlog-ref_tabname = 'MVKE'.

    APPEND v_fieldcatlog TO vt_fieldcatlog1.

    CLEAR v_fieldcatlog.

    v_fieldcatlog-col_pos = '9'.

    v_fieldcatlog-fieldname = 'MAKTX'.

    v_fieldcatlog-tabname = 'I_OUT'.

    v_fieldcatlog-ref_fieldname = 'MAKTX'.

    v_fieldcatlog-ref_tabname = 'MAKT'.

    APPEND v_fieldcatlog TO vt_fieldcatlog1.

    CLEAR v_fieldcatlog.

    v_fieldcatlog-col_pos = '10'.

    v_fieldcatlog-fieldname = 'LGORT'.

    v_fieldcatlog-tabname = 'I_OUT'.

    v_fieldcatlog-seltext_L = 'Strg Loct'. "Changing the fieldname

    v_fieldcatlog-outputlen = 10.

    APPEND v_fieldcatlog TO vt_fieldcatlog1.

    CLEAR v_fieldcatlog.

    v_fieldcatlog-col_pos = '11'.

    v_fieldcatlog-fieldname = 'LABST'.

    v_fieldcatlog-tabname = 'I_OUT'.

    v_fieldcatlog-seltext_M = 'Stock'.

    v_fieldcatlog-outputlen = 15.

    v_fieldcatlog-do_sum = 'X'. "Displaying the Grand Total

    v_layout-totals_text = 'Total Stock:'.

    v_fieldcatlog-hotspot = 'X'.

    APPEND v_fieldcatlog TO vt_fieldcatlog1.

    CLEAR v_fieldcatlog.

    v_fieldcatlog-col_pos = '12'.

    v_fieldcatlog-fieldname = 'EBELN'.

    v_fieldcatlog-tabname = 'I_OUT'.

    v_fieldcatlog-ref_fieldname = 'EBELN'.

    v_fieldcatlog-ref_tabname = 'EKPO'.

    v_fieldcatlog-hotspot = 'X'.

    APPEND v_fieldcatlog TO vt_fieldcatlog1.

    CLEAR v_fieldcatlog.

    v_fieldcatlog-col_pos = '13'.

    v_fieldcatlog-fieldname = 'EBELP'.

    v_fieldcatlog-tabname = 'I_OUT'.

    v_fieldcatlog-ref_fieldname = 'EBELP'.

    v_fieldcatlog-ref_tabname = 'EKPO'.

    APPEND v_fieldcatlog TO vt_fieldcatlog1.

    CLEAR v_fieldcatlog.

    ENDFORM. "get_fieldcat1

    ----


    • F O R M GET_FIELDCAT2. *

    ----


    FORM get_fieldcat2.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    I_CALLBACK_PROGRAM = SY-REPID

    I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'

    I_CALLBACK_USER_COMMAND = 'DISPLAY'

    IS_LAYOUT = v_layout

    IT_FIELDCAT = vt_fieldcatlog1

    TABLES

    T_OUTTAB = i_out.

    IF SY-SUBRC <> 0.

    ENDIF.

    ENDFORM. "get_fieldcat2

    &----


    *& Form TOP_OF_PAGE *

    &----


    FORM TOP_OF_PAGE.

    DATA: SLISTHEADER TYPE SLIS_T_LISTHEADER,

    WLISTHEADER TYPE SLIS_LISTHEADER.

    WLISTHEADER-TYP = 'H'.

    WLISTHEADER-INFO =

    'MATERIAL EXTRACTION ALV REPORT'.

    APPEND WLISTHEADER TO SLISTHEADER.

    WLISTHEADER-TYP = 'A'.

    WLISTHEADER-INFO =

    'SELECT MATERIAL FOR DISPLAY MATERIAL DETAILS'.

    APPEND WLISTHEADER TO SLISTHEADER.

    WLISTHEADER-TYP = 'A'.

    WLISTHEADER-INFO =

    'SELECT PURCHASE DOCU NO FOR PURCHASE ORDER DETAILS'.

    APPEND WLISTHEADER TO SLISTHEADER.

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

    EXPORTING

    I_LOGO = 'ENJOYSAP_LOGO'

    IT_LIST_COMMENTARY = SLISTHEADER.

    ENDFORM. " TOP_OF_PAGE

    &----


    *& F O R M D I S P L A Y *

    &----


    FORM dispLAY USING ucomm LIKE sy-ucomm

    selfield TYPE slis_selfield.

    CASE ucomm.

    WHEN '&IC1'. "FOR DOUBLE CLICK

    READ TABLE i_out INDEX selfield-tabindex.

    IF sy-subrc = 0.

    IF selfield-fieldname = 'MATNR'.

    SET PARAMETER ID 'MXX' FIELD 'D'.

    SET PARAMETER ID 'MAT' FIELD selfield-value.

    SET PARAMETER ID 'WRK' FIELD p_werks.

    CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.

    ENDIF.

    IF selfield-fieldname = 'EBELN'.

    SET PARAMETER ID 'BES' FIELD selfield-value.

    CALL TRANSACTION 'ME22N' AND SKIP FIRST SCREEN.

    ENDIF.

    ENDIF.

    ENDCASE.