Tips and Tricks for the ABAP® Programming Language

ZUPDOWNALL – Upload und download any report with text-symbols

This program does an upload and download a abap source code and also includes possible text sysmbols.

ABAP-Source-Code

You can copy and paste the source code directly into the ABAP-Workbench.

REPORT ZUPDOWNALL LINE-SIZE 80 NO STANDARD PAGE HEADING.
*
**********************         HEADER                    **************
*     You can use or modify this report for your own work as long
*               as you don't try to sell or republish it.
*      In no event will the author be liable for indirect, special,
*        Incidental, or consequental damages (if any) arising out of
*                       the use of this report.
*//////////////////////////////////////////////////////////////////////*

*----------------------------------------------------------------------*
TABLES:
  TRDIR,
  RLGRAP.
*----------------------------------------------------------------------*

PARAMETERS P_REPID LIKE TRDIR-NAME      DEFAULT 'Z*'.
PARAMETERS P_UPLOAD AS CHECKBOX.
SELECTION-SCREEN ULINE.
SELECT-OPTIONS: S_CNAM FOR TRDIR-CNAM DEFAULT SY-UNAME,
                S_UNAM FOR TRDIR-UNAM DEFAULT SY-UNAME.
PARAMETERS:     P_DATUM LIKE TRDIR-UDAT DEFAULT SY-DATUM OBLIGATORY.
PARAMETERS P_PFAD  LIKE RLGRAP-FILENAME DEFAULT
                   'c:\*'.
PARAMETERS P_EXT(3)                     DEFAULT 'txt'
                                        LOWER CASE OBLIGATORY.
*----------------------------------------------------------------------*
DATA: BEGIN OF REPPU OCCURS 1000,
         PU(72),
      END OF REPPU.
*
DATA: BEGIN OF XTEXTPOOL OCCURS 100.
        INCLUDE STRUCTURE TEXTPOOL.
DATA: END OF XTEXTPOOL.
*
DATA: BEGIN OF XTRDIR OCCURS 1000.
        INCLUDE STRUCTURE TRDIR.
DATA: END OF XTRDIR.
*
DATA: BEGIN OF REPORTS OCCURS 100,
       REPID(08),
       SPACE2(02),
       TEXT(70),
      END OF REPORTS.
*----------------------------------------------------------------------*
DATA:
  EXT(04)    VALUE '.',
  FOUND(1)   TYPE C,
  INHALT(12) VALUE 'Inhalt',
  MARK       TYPE C VALUE ' ',
  ANSWER(1)  TYPE C,
  STRING(60)  TYPE C,
  FIRST(1)   VALUE 'X'.
DATA:
  PFAD  LIKE P_PFAD,
  I     TYPE I,
  TITLE LIKE TEXTPOOL-ENTRY.

NEW-PAGE LINE-COUNT 50.

*----------------------------------------------------------------------*
START-OF-SELECTION.

  IF SY-UNAME <> 'IBM-BC'.              " <-------------> Username
    SKIP 2.
    FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
    WRITE: / 'Abbruch wegen Berechtigungsproblem !!! '(002).
    CHECK 1 = 2.
  ENDIF.

  WRITE: P_EXT TO EXT+1.
  WRITE: EXT   TO INHALT+6.

  PERFORM READ_DIR  TABLES REPORTS.

*
  IF P_UPLOAD = 'X'.
    PERFORM UPLOAD.
  ELSE.
    PERFORM DOWNLOAD.
    MARK = ''.
    PERFORM REPORTS_ANZEIGEN TABLES XTRDIR USING MARK.
  ENDIF.

AT LINE-SELECTION.
  IF P_UPLOAD = 'X'.
    PERFORM REPORT_ANZEIGEN.
  ELSE.
    PERFORM REPORTS_MERKEN.
  ENDIF.

END-OF-SELECTION.

TOP-OF-PAGE.
  PERFORM KOPF_ZEILE.

TOP-OF-PAGE DURING LINE-SELECTION.
  PERFORM KOPF_ZEILE.

*----------------------------------------------------------------------*
FORM UPLOAD.
  DATA:
    PFAD  LIKE P_PFAD,
    TITLE LIKE TEXTPOOL-ENTRY.
*
  PFAD = P_PFAD.
  REPLACE '*' WITH P_REPID INTO PFAD.
  CONDENSE PFAD NO-GAPS.
  CONCATENATE PFAD EXT INTO PFAD.

  SELECT SINGLE * FROM TRDIR
    WHERE NAME = P_REPID.
  IF SY-SUBRC = 0.
    CALL FUNCTION 'POPUP_TO_CONFIRM'
         EXPORTING
              TITLEBAR       = 'Report already exists'
              TEXT_QUESTION  = 'Overwrite?'
         IMPORTING
              ANSWER         = ANSWER
         EXCEPTIONS
              TEXT_NOT_FOUND = 1
              OTHERS         = 2.
    IF ANSWER <> '1'.
      STOP.
    ENDIF.

  ENDIF.

*
  CALL FUNCTION 'WS_UPLOAD'
       EXPORTING
            FILENAME            = PFAD
            FILETYPE            = 'ASC'
       TABLES
            DATA_TAB            = REPPU
       EXCEPTIONS
            CONVERSION_ERROR    = 01
            FILE_OPEN_ERROR     = 02
            FILE_READ_ERROR     = 03
            INVALID_TABLE_WIDTH = 04
            INVALID_TYPE        = 05
            NO_BATCH            = 06
            UNKNOWN_ERROR       = 07.

  REFRESH XTEXTPOOL.
  LOOP AT REPPU.
    IF REPPU(06) <> '*$*$IO'.
      EXIT.
    ENDIF.
    DELETE REPPU.
*
    XTEXTPOOL = REPPU.
    SHIFT XTEXTPOOL BY 06 PLACES LEFT.
    APPEND XTEXTPOOL.
*
    IF XTEXTPOOL-ID = 'R'.
      TITLE = XTEXTPOOL-ENTRY.
    ENDIF.
  ENDLOOP.
*
  IF P_REPID(01) = 'Y' OR P_REPID(01) = 'Z'.
    INSERT REPORT   P_REPID FROM REPPU.
    INSERT TEXTPOOL P_REPID FROM XTEXTPOOL LANGUAGE SY-LANGU.
    CONCATENATE P_REPID(20)  TITLE(40)
                INTO STRING
                  SEPARATED BY SPACE.

    WRITE: /3 STRING,  'has imported' INTENSIFIED OFF.

    XTRDIR-NAME = P_REPID.
    HIDE:
      XTRDIR-NAME.
  ENDIF.

ENDFORM.
*----------------------------------------------------------------------*
FORM DOWNLOAD.
*
  DO.
    REPLACE '+' WITH '_' INTO P_REPID.
    IF SY-SUBRC <> 0.
      EXIT.
    ENDIF.
  ENDDO.
  REPLACE '*' WITH '%' INTO P_REPID.
*
  SELECT * FROM TRDIR
    INTO TABLE XTRDIR
    WHERE NAME LIKE P_REPID
    AND   CNAM IN   S_CNAM
    AND   UNAM IN   S_UNAM
    AND   UDAT GE   P_DATUM.

*

ENDFORM.
*----------------------------------------------------------------------*
FORM READ_DIR
  TABLES REPORTS STRUCTURE REPORTS.
  DATA:
    PFAD LIKE P_PFAD.
*
  PFAD = P_PFAD.
  IF NOT PFAD CS '*'.
    WRITE:/
      'Please insert ''*'' into path'.
    STOP.
  ENDIF.

  REPLACE '*' WITH INHALT INTO PFAD.
  CONDENSE PFAD NO-GAPS.

*
  CALL FUNCTION 'WS_UPLOAD'
       EXPORTING
            FILENAME            = PFAD
            FILETYPE            = 'ASC'
       TABLES
            DATA_TAB            = REPORTS
       EXCEPTIONS
            CONVERSION_ERROR    = 01
            FILE_OPEN_ERROR     = 02
            FILE_READ_ERROR     = 03
            INVALID_TABLE_WIDTH = 04
            INVALID_TYPE        = 05
            NO_BATCH            = 06
            UNKNOWN_ERROR       = 07.
  CASE SY-SUBRC.
    WHEN 0.
    WHEN 2.
      REFRESH REPORTS.
    WHEN OTHERS.
      WRITE:/
        'Error reading file SY-SUBRC=' NO-GAP,
        SY-SUBRC.
      STOP.
  ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  REPORTS_ANZEIGEN
*&---------------------------------------------------------------------*
FORM REPORTS_ANZEIGEN TABLES XTRDIR STRUCTURE TRDIR USING MARK.

  LOOP AT XTRDIR.
    WRITE: / MARK AS CHECKBOX,
             XTRDIR-NAME(20),
             XTRDIR-CNAM,              "Ersteller
             XTRDIR-CDAT,              "Erstellungsdatum
             XTRDIR-UNAM,              "Änderer
             XTRDIR-UDAT,              "Änderungsdatum
             XTRDIR-VERN.              "Version
  ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  REPORTS_MERKEN
*&---------------------------------------------------------------------*
FORM REPORTS_MERKEN.

  CHECK P_UPLOAD = ' '.

  DATA: REPORT LIKE TRDIR-NAME,
   INDEX TYPE I VALUE 1.

  CLEAR: FOUND.

  SY-LSIND = 0.

  DO.

    CLEAR: MARK, REPORT.
    READ LINE INDEX FIELD VALUE MARK XTRDIR-NAME INTO REPORT.
    IF SY-SUBRC NE 0.
      EXIT.
    ENDIF.

    IF NOT MARK IS INITIAL.
      FOUND = 'X'.
      PERFORM REPORT_DOWNLOAD USING REPORT.
    ENDIF.
    ADD 1 TO INDEX.
  ENDDO.

  IF FOUND IS INITIAL.
    MESSAGE E300(M1) WITH  TEXT-001.
  ELSE.
*...Verzeichnis schreiben
    PFAD = P_PFAD.
    REPLACE '*' WITH INHALT INTO PFAD.
    SORT REPORTS.
    PERFORM WS_DOWNLOAD TABLES REPORTS USING PFAD.
    MARK = ''.
    PERFORM REPORTS_ANZEIGEN TABLES XTRDIR USING MARK.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  REPORT_DOWNLOAD
*&---------------------------------------------------------------------*
FORM REPORT_DOWNLOAD USING REPORT LIKE TRDIR-NAME.

  READ REPORT REPORT INTO REPPU.
*   Textelemente lesen
  READ TEXTPOOL REPORT INTO XTEXTPOOL LANGUAGE SY-LANGU.
  DESCRIBE TABLE XTEXTPOOL LINES I.
  WHILE I > 0.
    READ TABLE XTEXTPOOL INDEX I.
    IF XTEXTPOOL-ID = 'R'.
      REPORTS-TEXT = XTEXTPOOL-ENTRY(70).
    ENDIF.
*
    SUBTRACT 1 FROM I.
    SHIFT XTEXTPOOL BY 06 PLACES RIGHT.
    XTEXTPOOL(06) = '*$*$IO'.
    REPPU = XTEXTPOOL.
    INSERT REPPU INDEX 1.
  ENDWHILE.
*
  REPORTS-REPID = REPORT.
  COLLECT REPORTS.
*
  PFAD = P_PFAD.
  REPLACE '*' WITH '**'        INTO PFAD.
  REPLACE '*' WITH REPORT      INTO PFAD.
  CONDENSE PFAD NO-GAPS.
  REPLACE '*' WITH EXT         INTO PFAD.

  PERFORM WS_DOWNLOAD TABLES REPPU USING PFAD.
*
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  WS_DOWNLOAD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_PFAD  text                                                 *
*      -->P_TABELLE  text                                              *
*----------------------------------------------------------------------*
FORM WS_DOWNLOAD TABLES TABELLE
           USING  PFAD LIKE RLGRAP-FILENAME.

  CALL FUNCTION 'WS_DOWNLOAD'
       EXPORTING
            FILENAME            = PFAD
            FILETYPE            = 'ASC'
       TABLES
            DATA_TAB            = TABELLE
       EXCEPTIONS
            FILE_OPEN_ERROR     = 01
            FILE_WRITE_ERROR    = 02
            INVALID_FILESIZE    = 03
            INVALID_TABLE_WIDTH = 04
            INVALID_TYPE        = 05
            NO_BATCH            = 06
            UNKNOWN_ERROR       = 07.
  IF SY-SUBRC <> 0.
    WRITE:/
      'Fehler in WS_DOWNLOAD', SY-SUBRC.
    STOP.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  KOPF_ZEILE
*&---------------------------------------------------------------------*
FORM KOPF_ZEILE.

  WRITE: / 'Report:', SY-REPID(8).
  WRITE:   55 'Datum:', SY-DATUM, SY-UZEIT.

  WRITE: /15 SY-TITLE(50) , 69 'Seite', SY-PAGNO(4).

  ULINE.

  IF P_UPLOAD = 'X'.
    WRITE: /3 'Report Bezeichnung'.
  ELSE.
    WRITE: /3 'Report',
           24 'Erfasser',
           37 'Erst.Datum',
           48 'Änderer',
           61 'Änd.Datum  Version'.
  ENDIF.
  ULINE.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  REPORT_ANZEIGEN
*&---------------------------------------------------------------------*
FORM REPORT_ANZEIGEN.

  READ REPORT XTRDIR-NAME INTO REPPU.
  EDITOR-CALL FOR REPPU TITLE REPORTS-REPID DISPLAY-MODE.

ENDFORM.

************************************************************************
***************  END OF PROGRAM ****************************************
************************************************************************
pixelstats trackingpixel