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: 

How to convert ALV report to Excel ??

Former Member
0 Kudos

Hi,

My requirement is to show ALV report in the excel .

I have 2 radio buttons in Selection screen :

1) ALV format 2) Excel.

If excel is selected then user will give a path : C :\newexcelreport.xls

I knew that there is a way to download report through ALV report using download into local file. But the requirement is to create a report in Excel same like ALV report .

I tried using GUI_Download . But it is displaying some fields wrongly, ex : Date , Time, without header .

Date is showing year month date format in the excel .

time is showing in a numeric format.

But the ALV report is showing correct report . When I download into local then the report is showing correct results .

Is there any function module to download exact ALV report into excel .??

Thanks & Regards,

Varma

8 REPLIES 8

Former Member
0 Kudos

well in this case i guess you have to do some changes in the settings of ur excel rather thanchanging anything in ur program .

Thanks

Rohit

Reward if helpfull

former_member404244
Active Contributor
0 Kudos

Hi,

Use the FM " EXCEL_OLE_STANDARD_DAT".

Reward if helpful.

Regards,

nagaraj

Former Member
0 Kudos

Hi

try using FM ALV_DOWNLOAD

Regards

SHiva

Former Member
0 Kudos

Hi,

I have done with this using GUI_DOWNLOAD ...

But I am not getting header ...

Any one know how to add column descriptions ????

Former Member
0 Kudos

Hi,

Use the code below... Using this you can also create a header line with the field names as well.

DATA: lv_text(30) TYPE c.

DATA : components LIKE rstrucinfo OCCURS 0 WITH HEADER LINE.

DATA : allfields(300) TYPE c.

DATA : fld(100) TYPE c.

DATA : begin of lt_header occurs 0,

allfields(300) type c,

end of lt_header.

    • Get the Components of the Structure passed which are used to

    • create the Header of the Excel being created.

CALL FUNCTION 'GET_COMPONENT_LIST'

EXPORTING

program = sy-repid

fieldname = STRUC

TABLES

components = components.

LOOP AT components.

CONCATENATE components-compname

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB INTO fld.

CONCATENATE allfields fld INTO allfields .

ENDLOOP.

lt_header-allfields = allfields.

append lt_header.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = file

WRITE_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = lt_header.

    • Append the records to the created Excel which has the header in it.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD

EXPORTING

  • BIN_FILESIZE =

FILENAME = file

FILETYPE = 'ASC'

WRITE_FIELD_SEPARATOR = 'X'

APPEND = 'X'

CHANGING

DATA_TAB = tab[]

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

NOT_SUPPORTED_BY_GUI = 22

ERROR_NO_GUI = 23

others = 24

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Former Member
0 Kudos

Use the FM - ALV_XXL_CALL. here is the sample -

REPORT ZSKC_ALV_XXL.

TYPE-POOLS : KKBLO.

DATA : ITAB LIKE T100 OCCURS 0,

T_FCAT_LVC TYPE LVC_S_FCAT OCCURS 0 WITH HEADER LINE,

T_FCAT_KKB TYPE KKBLO_T_FIELDCAT.

START-OF-SELECTION.

  • Get data.

SELECT * UP TO 20 ROWS

FROM T100

INTO TABLE ITAB

WHERE SPRSL = SY-LANGU.

CHECK SY-SUBRC EQ 0.

  • Create the field catalog.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

I_STRUCTURE_NAME = 'T100'

CHANGING

CT_FIELDCAT = T_FCAT_LVC[]

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 2

OTHERS = 3.

CHECK SY-SUBRC EQ 0.

  • make sure you pass the correct internal table name in the field catalog.

t_fcat_lvC-tabname = 'ITAB'.

MODIFY T_FCAT_LVC TRANSPORTING TABNAME WHERE TABNAME NE SPACE.

  • Transfer to KKBLO format.

CALL FUNCTION 'LVC_TRANSFER_TO_KKBLO'

EXPORTING

IT_FIELDCAT_LVC = T_FCAT_LVC[]

IMPORTING

ET_FIELDCAT_KKBLO = T_FCAT_KKB

EXCEPTIONS

IT_DATA_MISSING = 1

IT_FIELDCAT_LVC_MISSING = 2

OTHERS = 3.

CHECK SY-SUBRC EQ 0.

  • Call XXL.

CALL FUNCTION 'ALV_XXL_CALL'

EXPORTING

I_TABNAME = 'ITAB'

IT_FIELDCAT = T_FCAT_KKB

TABLES

IT_OUTTAB = ITAB[]

EXCEPTIONS

FATAL_ERROR = 1

NO_DISPLAY_POSSIBLE = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

ENDIF.

Former Member
0 Kudos

Former Member
0 Kudos

I have got with this using GUI_Download itself ...