Free SAP Training & Tutorial A Free SAP Functional And Technical Tutorial And Training For ABAP, SAP QUERY, ALV, SMARTFORMS, SD, PP, MM, QM, FICO
26.07.2010 | Author: | Posted in ABAP 

Today I want to teach you how to populate MS Excel worksheet from ABAP, it’s a very straight forward method using ‘MS_EXCEL_OLE_STANDARD_DAT’ function module.

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.

ate-01

4. Now click execute (f8)

5. Here’s the result on the Excel Worksheet.

ate-02

Popularity: 4% [?]

 


 
 

Related Tutorial " ABAP" 

  •  
     
    Recent Tutorials
    Create Table Maintenance Display In SAP Create table display to maintain tables values using SM30
    Create Table Maintenance Generator In SAP Maintaining SAP Transparent table values using maintenance generator
    Table Relationship In SAP Learn How To Find Tables Relationships in SAP
    Convert Number To words Using ABAP Find out how to convert numbers into words Using ABAP
    How To Maintain Long Text Object in SAP Maintain long text object in SAP
    How To Know What TCODE Used In ABAP Program Find TCODE For your ABAP Program Report
    How does CRM Work? Learn how CRM system works to run your business
    Why SAP CRM is the Best Choice? The reasons why CRM application is the best choice
    Difference Between CRM System and CRM Strategy What's the difference between CRM system and its strategy
    CRM for a Better Customer Service Learn how CRM could make your customer service much better
    Costs of Implementing CRM Software Learn the how much cost you need to prepare when implementing CRM
     
    Popular Tutorials
  • (none)
  •  
    Categories
    ABAP   Basis & Configuration  
    ALV SAP BW (Business Warehouse)
    BAPI   SAP Interview Questions
    SAP Tables   SAP Overview
    Transaction Codes FI SAP Query
      MM SAP Script  
      PP SAP Tutorial FI Module
      QM   MM Module
      SD   PM Module
    SAP Functional MM   PP Module
      SD   QM Module
    White Papers     SD Module
    Uncategorized   SmartForms  
      User-Exits  
     
     

     

    Home | About | Contribute | Privacy

    Copyright 2011 freesaptutorial.com.

    Free SAP Tutorial is not associated with SAP AG in Germany or in any other country.

    SAP is a registered trade mark of SAP AG.