Code: Alles auswählen.
REPORT z_savelist LINE-SIZE 71 NO STANDARD PAGE HEADING MESSAGE-ID 00.
SELECTION-SCREEN BEGIN OF BLOCK mode WITH FRAME TITLE title.
PARAMETERS: report LIKE rs38m-programm OBLIGATORY.
PARAMETERS: variant LIKE raldb-variant OBLIGATORY.
SELECTION-SCREEN SKIP.
PARAMETERS: dataset(128) OBLIGATORY LOWER CASE.
PARAMETERS: dat_o RADIOBUTTON GROUP dat DEFAULT 'X',
dat_a RADIOBUTTON GROUP dat,
dat_k(128) LOWER CASE.
SELECTION-SCREEN END OF BLOCK mode.
* global data
DATA compressed_list LIKE soli OCCURS 0.
*--- initialization ----------------------------------------------------
INITIALIZATION.
title = 'Reportausgabe auf Datei'.
*---- start-of-selection -----------------------------------------------
START-OF-SELECTION.
PERFORM use_submit TABLES compressed_list.
*&---------------------------------------------------------------------*
*& Form USE_SUBMIT
*&---------------------------------------------------------------------*
* Use "submit <report> exporting list to memory"
*----------------------------------------------------------------------*
FORM use_submit TABLES compressed_list STRUCTURE soli.
* The listobject
DATA: listobject LIKE abaplist OCCURS 0 WITH HEADER LINE,
BEGIN OF ascitable OCCURS 0,
text(256),
END OF ascitable,
zaehler TYPE i VALUE 0.
******call report without displaying it on the screen********
* the created list is stored in the memory
* (e.g. report rswttr01, a list of sapconnect Traces)
SUBMIT (report) USING SELECTION-SET variant
EXPORTING LIST TO MEMORY AND RETURN.
*************************************************************
******Or via selection-screen. Press EXECUTE and BACK********
* (e.g. report balvhd01)
* SUBMIT (REPORT) VIA SELECTION-SCREEN
* EXPORTING LIST TO MEMORY AND RETURN.
*************************************************************
******Or specify selection explicitely***********************
* (e.g. report balvhd01)
* REPORT = 'balvhd01'.
* SUBMIT (REPORT)*
* WITH CARRID EQ 'LH'
* EXPORTING LIST TO MEMORY AND RETURN.
*
* --> With F1 on submit you will find more possibilities
*************************************************************
* Import the list from memory and store it in table listobject
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = listobject
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE e398 WITH 'Error in list_from_memory:' sy-subrc.
ENDIF.
* Free memory
CALL FUNCTION 'LIST_FREE_MEMORY'
TABLES
listobject = listobject
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE e398 WITH 'Error in list_free_memory:' sy-subrc.
ENDIF.
* Convert ABAP-List to ascii
CALL FUNCTION 'LIST_TO_ASCI'
EXPORTING
list_index = -1
TABLES
listasci = ascitable
listobject = listobject
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE e398 WITH 'Error in list_to_ascii:' sy-subrc.
ENDIF.
* Write ASCII-List to Dataset
IF dat_o = 'X'.
OPEN DATASET dataset FOR OUTPUT IN TEXT MODE.
ELSE.
OPEN DATASET dataset FOR APPENDING IN TEXT MODE.
ENDIF.
IF sy-subrc <> 0.
MESSAGE e398 WITH 'Error in OPEN DATASET:' sy-subrc.
ENDIF.
* Auf Wunsch eine Kopfzeile einfügen
IF NOT dat_k IS INITIAL.
WRITE sy-datum TO ascitable.
MOVE dat_k TO ascitable+12.
TRANSFER ascitable-text TO dataset.
zaehler = zaehler + 1.
ENDIF.
LOOP AT ascitable.
TRANSFER ascitable-text TO dataset.
zaehler = zaehler + 1.
IF sy-subrc <> 0.
MESSAGE e398 WITH 'Error in TRANSFER to DATASET:' sy-subrc.
ENDIF.
ENDLOOP.
CLOSE DATASET dataset.
IF sy-subrc <> 0.
MESSAGE e398 WITH 'Error in CLOSE DATASET:' sy-subrc.
ENDIF.
MESSAGE i398 WITH zaehler 'Zeilen in' dataset 'ausgegeben.'.
ENDFORM. " USE_SUBMIT
Selektionstexte anlegen:
DATASET Ausgabedatei auf SAP-Server
DAT_A - Daten anhängen
DAT_K Text für Kopfzeile
DAT_O - Daten überschreiben
REPORT Zu startender Report
VARIANT Reportvariante