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 -Excel download -header & data comming in Different columns

Former Member
0 Kudos
682

Hi,

I have an ALV report with FM.When I download it to excel through LIST/EXPORT/LOCALFILE some columns are getting messed up (ex: header is in one column and data is comming in different column).

When i do with LIST/EXPORT/SPREADSHEET option it is working fine.

but users want to use the first option only.

I am use FM's in this report.

Regards

Praveen

1 ACCEPTED SOLUTION

Former Member
0 Kudos
214

Hi,

Check the sequence & length of fields in fieldcatalog & the internal table used to display excel.These should match exactly.

Hope this helps.

Reward if helpful.

Regards,

Sipra

4 REPLIES 4

Former Member
0 Kudos
214

Please check your internal table that you are passing in the Fm.

It should be exactly in the same order as it is displayed in ALV.

Check the sequence of fields in Internal table.That should be the only problem.

Former Member
0 Kudos
214

hi,

Chk this sample code.

REPORT  Z_GUI_DOWNLOAD_TO_EXCEL.
 
data : itab type mara occurs 0 with header line.
 
select * into itab
         from mara
         up to 10 rows.
         append itab.
endselect.
 
data : begin of itab1 occurs 0,
         line(50) type c,
       end of itab1.
 
itab1-line = 'field1 description'.
append itab1.
itab1-line = 'field2 desc'.
append itab1.
itab1-line = 'field3 desc'.
append itab1.
*--and so on you have to add up the records in itab1.
 
CALL FUNCTION 'GUI_DOWNLOAD'
 EXPORTING
   FILENAME                      = 'C:ABCD.XLS '
   FILETYPE                      = 'DAT'
  TABLES
    DATA_TAB                      = ITAB
   FIELDNAMES                    = ITAB1
          .

Regards

Reshma

Former Member
0 Kudos
214

Hi

What is the statement you used to dowload data .Check the field catalog that u are passing to downloaad function module.

or check in the debuging mode..

change these options in excel sheet and checkout if it can help u

1. Go to Tools -> Macro -> Security in Excel

2. Select the ‘Trusted Sources’ tab and ensure that the checkbox titled ‘Trust access to Visual Basic Project’ is ticked.

3. With the feature switched on, the data is passed to Excel.

check this sample one

TABLES : MAST , "Material to BOM Link
STKO , "BOM Header
MARA . "General Material Data
*
**---------------------------------------------------------------------*
* Types Begin with TY_ *
**---------------------------------------------------------------------*
*
TYPES : BEGIN OF TY_MASTER ,
MATNR TYPE MAST-MATNR , "Material Number
WERKS TYPE MAST-WERKS , "Plant
STLAN TYPE MAST-STLAN , "BOM Usage
STLNR TYPE MAST-STLNR , "Bill of material
STLAL TYPE MAST-STLAL , "Alternative BOM
ANDAT TYPE MAST-ANDAT , "Date record created on
AEDAT TYPE MAST-AEDAT , "Date of Last Change
AENAM TYPE MAST-AENAM , "Name of Person Who Changed Object
STLST TYPE STKO-STLST , "BOM status
ZPLP1 TYPE MBEW-ZPLP1 , "Future Planned Price 1
DWERK TYPE MVKE-DWERK , "Delivering Plant (Own or External)
END OF TY_MASTER .
*
TYPES : MY_TYPE(20) TYPE C.
*
**---------------------------------------------------------------------*
* Constants Begin with C_ *
**---------------------------------------------------------------------*
*
**---------------------------------------------------------------------*
* Internal tables Begin with IT_ *
**---------------------------------------------------------------------*
* *
DATA : IT_MASTER TYPE STANDARD TABLE OF TY_MASTER,
WA_MASTER TYPE TY_MASTER .
*
DATA : IT_HEADER TYPE TABLE OF MY_TYPE.
*
*
**---------------------------------------------------------------------*
* Data Begin with W_ *
**---------------------------------------------------------------------*
* *
DATA : W_PTH TYPE RLGRAP-FILENAME.
DATA : W_FILE TYPE RLGRAP-FILENAME.
* *
**---------------------------------------------------------------------*
* Field Symbols Begin with FS_ *
**---------------------------------------------------------------------*
* *
* *
**---------------------------------------------------------------------*
* Select Options Begin with SO_ *
**---------------------------------------------------------------------*
*
*
**---------------------------------------------------------------------*
* Parameter Begin with PR_ *
**---------------------------------------------------------------------*
* *
**---------------------------------------------------------------------*
* I N I T I A L I Z A T I O N *
**---------------------------------------------------------------------*
*
*--- Add Header Fields to Header Table ---
*
APPEND 'Material Number' TO IT_HEADER .
APPEND 'Plant' TO IT_HEADER .
APPEND 'BOM Usage' TO IT_HEADER .
APPEND 'Bill Code' TO IT_HEADER .
APPEND 'Alternative BOM' TO IT_HEADER .
APPEND 'Created On' TO IT_HEADER .
APPEND 'Changed On' TO IT_HEADER .
APPEND 'Changed By' TO IT_HEADER .
APPEND 'BOM Status' TO IT_HEADER .
APPEND 'Planned Price' TO IT_HEADER .
APPEND 'Delivery Plant' TO IT_HEADER .
*
IF SY-MANDT = '700'.
W_PTH = '\lkdb01ISDISSoftware DevelopmentsDevelopmentsData FilesSAP DumpsBOM_Available'.
ELSE.
W_PTH = 'C:'.
ENDIF.
*
**---------------------------------------------------------------------*
* A T S E L E C T I O N S C R E E N *
**---------------------------------------------------------------------*
*
*
************************************************************************
* s t a r t o f s e l e c t i o n
************************************************************************
* *
START-OF-SELECTION.
*
*--- Load Data to Internal Table ---
*
* SELECT MAST~MATNR MAST~WERKS MAST~STLAN MAST~STLNR MAST~STLAL MAST~ANDAT MAST~AEDAT MAST~AENAM STKO~STLST
* INTO TABLE IT_MASTER
* FROM MAST
* INNER JOIN STKO ON STKO~STLNR EQ MAST~STLNR
* AND STKO~STLAL EQ MAST~STLAL
* INNER JOIN MARA ON MARA~MATNR EQ MAST~MATNR
* WHERE MARA~MTART LIKE 'ZFG%'
* AND STKO~LKENZ NE 'X'
* AND STKO~LOEKZ NE 'X'
* AND STKO~STLST EQ '1'.
*
**************************************************************************************************************
*
SELECT MAST~MATNR MAST~WERKS MAST~STLAN MAST~STLNR MAST~STLAL MAST~ANDAT MAST~AEDAT MAST~AENAM STKO~STLST MBEW~ZPLP1 MVKE~DWERK
INTO TABLE IT_MASTER
FROM MAST
INNER JOIN STKO ON STKO~STLNR EQ MAST~STLNR
AND STKO~STLAL EQ MAST~STLAL
INNER JOIN MARA ON MARA~MATNR EQ MAST~MATNR
INNER JOIN MBEW ON MBEW~MATNR EQ MAST~MATNR
AND MBEW~BWKEY EQ MAST~WERKS
INNER JOIN MVKE ON MVKE~MATNR EQ MAST~MATNR
WHERE MARA~MTART LIKE 'ZFG%'
AND STKO~LKENZ NE 'X'
AND STKO~LOEKZ NE 'X'
AND STKO~STLST EQ '1'.
*
**************************************************************************************************************
IF SY-SUBRC <> 0.
MESSAGE I014(ZLOAD).
ENDIF.
*
*--- Set Path to Function Module ---
*
CONCATENATE W_PTH SY-DATUM ' - ' 'BOM_AVAILABLE_PLANT.XLS' INTO W_FILE.
*
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
FILENAME = W_FILE
FILETYPE = 'DAT'
TABLES
DATA_TAB = IT_MASTER
FIELDNAMES = IT_HEADER
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_EIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
OTHERS = 10.
*
IF SY-SUBRC = 0.
SUBMIT ZI005_MARA_DUMP_SOLIDEAL_N.
MESSAGE I023(ZLOAD) WITH text-001.
ELSE.
MESSAGE I022(ZLOAD) WITH W_FILE. "Errors while downloading.
ENDIF.
*
END-OF-SELECTION.
*
SUBMIT ZI005_MARA_DUMP_SOLIDEAL_N.

Reward all helpfull answers

Regards

Pavan

Message was edited by:

Pavan praveen

Former Member
0 Kudos
215

Hi,

Check the sequence & length of fields in fieldcatalog & the internal table used to display excel.These should match exactly.

Hope this helps.

Reward if helpful.

Regards,

Sipra