Problem solve Get help with specific problems with your technologies, process and projects.

Download inernal tables to MS Excel

Sample code to download an internal table into Excel as part of the program execution.

Here is some sample code for downloading an internal table into MS Excel as part of the program execution. No debugging here.
The code was written in R/3 4.6B.
DATA ITAB LIKE ZCRINFO OCCURS 0 WITH HEADER LINE.

SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-001.

  SELECT-OPTIONS :  KKB FOR KNKK-KKBER, " CREDIT AREA.
                    SO_KUNNR FOR KNKK-KUNNR.

SELECTION-SCREEN END OF BLOCK BL1.

START-OF-SELECTION.

      SELECT B~KUNNR C~BUKRS B~NAME1 B~ORT01 B~NAME2 B~TELF1
             B~TELFX B~LAND1 A~KLIMK A~AEDAT A~KKBER A~CTLPC
             A~CASHC A~ERDAT
             INTO (ITAB-PSCSCD, ITAB-PSCPCD, ITAB-PSCSNM,
                   ITAB-PSCITY, ITAB-PSADDR, ITAB-PSPHON,
                   ITAB-PSFAX, ITAB-PSLAND, ITAB-PSARLT,
                   ITAB-PSLIMT, ITAB-PKKBER, ITAB-PCTLPC,
                   ITAB-PSCURR, ITAB-PFUNC1)
             FROM ( KNKK AS A INNER JOIN KNA1 AS B
             ON A~KUNNR = B~KUNNR ) INNER JOIN KNB1 AS C
             ON C~KUNNR = A~KUNNR
             WHERE B~KUNNR IN SO_KUNNR
               AND C~BUKRS IN KKB.

          APPEND ITAB.
       ENDSELECT.

* Excel direct download
  DATA : EXCEL_FILE_AND_PATH(128).
  DATA : TMP_NAME LIKE RLGRAP-FILENAME.
  CALL FUNCTION 'REGISTRY_GET'
       EXPORTING
            KEY     = 'protocolStdFileEditingserver'
            SECTION = 'ExcelWorksheet'
       IMPORTING
            VALUE   = EXCEL_FILE_AND_PATH.
  DATA : FILE_NAME    LIKE RLGRAP-FILENAME VALUE 'C:TEMPCUS.xls'.
  DATA : ACT_FILENAME LIKE RLGRAP-FILENAME,
         CANCEL.
  CALL FUNCTION 'DOWNLOAD'
       EXPORTING
            FILENAME     = FILE_NAME
            FILETYPE     = 'DAT'
       IMPORTING
            ACT_FILENAME = FILE_NAME
            CANCEL       = CANCEL
       TABLES
            DATA_TAB     = ITAB.

  CALL FUNCTION 'WS_EXECUTE'
       EXPORTING
            COMMANDLINE = FILE_NAME
            PROGRAM     = EXCEL_FILE_AND_PATH.
This was last published in May 2003

Dig Deeper on SAP ABAP

PRO+

Content

Find more PRO+ content and other member only offers, here.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close