This program will require you to create the excel file first, just create a blank workbook and put it on your local drive folder.
1. Open your ABAP editor (se38)
2. Copy this code below.
Parameters: P_file like RLGRAP-FILENAME. data : begin of t_header occurs 0, text_col(20) type c, " Header Data end of t_header. data : begin of t_data occurs 0, vbeln type lips-vbeln, matnr type lips-matnr, arktx TYPE lips-ARKTX, lfimg type lips-LFIMG, vrkme type lips-vrkme, end of t_data. data: BEGIN OF i_data OCCURS 0, col1(100) TYPE c, col2(100) type c, col3(100) type c, col4(100) TYPE c, col5(100) type c, END OF i_data. SELECT lips~vbeln lips~matnr lips~ARKTX lips~LFIMG lips~VRKME INTO CORRESPONDING FIELDS OF TABLE t_data from LIPS. t_header-text_col = 'DO Number'. APPEND t_header. CLEAR t_header. t_header-text_col = 'Material'. APPEND t_header. CLEAR t_header. t_header-text_col = 'Description'. APPEND t_header. CLEAR t_header. t_header-text_col = 'Qty'. APPEND t_header. CLEAR t_header. t_header-text_col = 'Unit'. APPEND t_header. CLEAR t_header. LOOP AT t_data. i_data-col1 = t_data-vbeln. i_data-col2 = t_data-matnr. i_data-col3 = t_data-arktx. i_data-col4 = t_data-lfimg. i_data-col5 = t_data-vrkme. Append i_data. Clear i_data. ENDLOOP. * CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT' EXPORTING file_name = p_file TABLES data_tab = i_data "This is the data result fieldnames = t_header "This is the header EXCEPTIONS file_not_exist = 1 filename_expected = 2 communication_error = 3 ole_object_method_error = 4 ole_object_property_error = 5 invalid_filename = 6 invalid_pivot_fields = 7 download_problem = 8 OTHERS = 9 . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.3. Click F8 to test the program. Type in the Excel file you’ve created before, remember it’s a blank workbook.
4. Now click execute (f8)
5. Here’s the result on the Excel Worksheet.
Post a Comment