SAP Jobsuche bei DV-Treff
DominicK
  • DominicK
  • SAP Forum - Neuling Thema Starter
vor 11 Jahre
Bekomme folgenden Fehler beim ausführen des angefügten Programmes:

Zitat:

In dem laufenden Programm "Z_PROGRAMM_EXPORT" ist beim Setzen des Feldsymbols

"

"

mit ASSIGN bzw. ASSIGNING (ggf. in Kombination mit dem Zusatz CASTING)

ein Fehler aufgetreten.

Beim Umsetzen des Basiseintrags des Feldsymbols "

" (Nummer in der

Basistabelle: 14) wurde festgestellt, daß der Zieltyp die

Speicherausrichtung 8 fordert.

Das Quelldatenobjekt hat aber eine unzulässige, d.h. nicht durch 8

teilbare, Speicherausrichtung.

Bei den Tabellen MARA, MARC, BSEG wird es ausgeführt, bei MARD nicht. Mir sagt der Fehler nichts.

Anbei der Code:



*&---------------------------------------------------------------------*
*& Report  Z_PROGRAMM_EXPORT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  Z_PROGRAMM_EXPORT.

TABLES: DD02L.


TYPES: BEGIN OF T_HEADER,
         HEADER(3000) TYPE C,
        END OF T_HEADER,
*        COND(72) TYPE C,
*        COLUMS(72) TYPE C.
        COND(200) TYPE C,
        COLUMS(200) TYPE C.

DATA: BEGIN OF TABLE_STRUCTURE OCCURS 0,
   TABNAME TYPE DD03L-TABNAME,
   FIELDNAME TYPE DD03L-FIELDNAME,
   POSITION TYPE DD03L-POSITION,
   INTTYPE TYPE DD03L-INTTYPE,
   INTLEN TYPE DD03L-INTLEN,
   DATATYPE TYPE DD03L-DATATYPE,
   DECIMALS TYPE DD03L-DECIMALS,
   END OF TABLE_STRUCTURE.


DATA: BEGIN OF TABLE_BUFFER,
"BUFFER(65535),
  BUFFER(30000),
END OF TABLE_BUFFER.

DATA: C TYPE CURSOR,
      I TYPE INTEGER VALUE 0,
      STRTEMP TYPE STRING VALUE '',
      FIELDCONTENT TYPE STRING VALUE '',
      TAB TYPE  C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
      FILE(60) TYPE C,
      FIELDCOUNT TYPE INTEGER VALUE 0,
      POSITION TYPE INTEGER VALUE 0,
      LVDD03L LIKE DD03L,
      IT_HEADER TYPE STANDARD TABLE OF T_HEADER INITIAL SIZE 0,
      WA_HEADER TYPE T_HEADER,
      SOURCE_LINE TYPE EDPLINE, WHERE_TAB TYPE TABLE OF EDPLINE,
      "cond(72) TYPE c,
      CONDTAB TYPE TABLE OF COND,
      COLUMSTAB TYPE TABLE OF COLUMS,
      columscondtab TYPE TABLE OF COLUMS,
      ROWCOUNTINT TYPE INTEGER.


DATA:     W_ANS.
FIELD-SYMBOLS <TABLE> TYPE ANY.
FIELD-SYMBOLS <FIELDCONTENT> TYPE ANY.
FIELD-SYMBOLS <TABLE_STRUCTURE>.

SELECTION-SCREEN BEGIN OF BLOCK B00 WITH FRAME TITLE TEXT-B00.

SELECTION-SCREEN BEGIN OF BLOCK B01 WITH FRAME TITLE TEXT-B01.
PARAMETERS: PTABLE    LIKE DD02L-TABNAME OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B01.

*SELECTION-SCREEN BEGIN OF BLOCK B02 WITH FRAME TITLE TEXT-B02.
*PARAMETERS: COLUMS TYPE COLUMS DEFAULT 'MANDT MATNR ERSDA'.
*SELECTION-SCREEN END OF BLOCK B02.
*
*SELECTION-SCREEN BEGIN OF BLOCK B03 WITH FRAME TITLE TEXT-B03.
*PARAMETERS: colcond TYPE COND DEFAULT
*'(ROLLNAME NE '''' AND TABNAME = ''PTABLE'') AND FIELDNAME = ''MANDT'' OR FIELDNAME = ''MATNR'' OR FIELDNAME = ''ERSDA'''.
*SELECTION-SCREEN END OF BLOCK B03.

SELECTION-SCREEN BEGIN OF BLOCK B04 WITH FRAME TITLE TEXT-B04.
PARAMETERS: COND TYPE COND. "DEFAULT MATNR LIKE '%038'
SELECTION-SCREEN END OF BLOCK B04.

SELECTION-SCREEN BEGIN OF BLOCK B05 WITH FRAME TITLE TEXT-B05.
PARAMETERS: PATH(30)    TYPE C DEFAULT '/usr/sap/trans/'.
SELECTION-SCREEN END OF BLOCK B05.

SELECTION-SCREEN BEGIN OF BLOCK B06 WITH FRAME TITLE TEXT-B06.
PARAMETERS: ROWCOUNT LIKE SOID-ACCNT DEFAULT 1000.
SELECTION-SCREEN END OF BLOCK B06.

SELECTION-SCREEN BEGIN OF BLOCK B07 WITH FRAME TITLE TEXT-B07.
PARAMETERS: NO_DATA TYPE SONV-FLAG DEFAULT SPACE.
SELECTION-SCREEN END OF BLOCK B07.




SELECTION-SCREEN END OF BLOCK B00.



*---------------------------------------------------------------------*
* Prüfen, ob die Tabelle vorhanden ist                                    *
*---------------------------------------------------------------------*

AT SELECTION-SCREEN ON PTABLE.
  PERFORM CHECK_TABLE_EXISTS.


START-OF-SELECTION.

*---------------------------------------------------------------------*
* Prüfen, ob Berechtigung                                 *
*---------------------------------------------------------------------*

  CALL FUNCTION 'VIEW_AUTHORITY_CHECK'
    EXPORTING
      VIEW_ACTION                    = 'S'
      VIEW_NAME                      = PTABLE
    EXCEPTIONS
      NO_AUTHORITY                   = 2
      NO_CLIENTINDEPENDENT_AUTHORITY = 2
      NO_LINEDEPENDENT_AUTHORITY     = 2
      OTHERS                         = 1.

  IF SY-SUBRC = 2.
    RAISE NOT_AUTHORIZED.
  ELSEIF SY-SUBRC = 1.
    RAISE TABLE_NOT_AVAILABLE.
  ENDIF.

*---------------------------------------------------------------------*
* Zusammenbau Pfad                              *
*---------------------------------------------------------------------*

  PERFORM BUILD_FILE_NAME.

*---------------------------------------------------------------------*
* Prüfen, ob File bereits existiert, wenn ja löschen                             *
*---------------------------------------------------------------------*
  "CONCATENATE PATH PTABLE '.txt' INTO FILE.
  PERFORM FILE_EXISTS.


*"-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*
*Daten Aufbereitung und Ausgabe
*
*Struktur analysieren
*"-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FORM DATA_PROCESSING.

  IF NO_DATA EQ SPACE.


    APPEND COND TO CONDTAB.
*    APPEND COLUMS TO COLUMSTAB.
*    APPEND colcond TO columscondtab.
  CLEAR  COND.
*  CLEAR  COLUMS.
*  CLEAR COLCOND.
*"Überprüfen der WHERE-Bedingung.

*  LOOP AT CONDTAB INTO COND.
*    WRITE COND.
*  ENDLOOP.
*  SKIP.


    SELECT TABNAME FIELDNAME POSITION INTTYPE INTLEN DATATYPE DECIMALS
      INTO CORRESPONDING FIELDS OF TABLE TABLE_STRUCTURE FROM DD03L WHERE
      ROLLNAME NE '' AND TABNAME = 'PTABLE' "AND FIELDNAME IN ('MANDT', 'MATNR', 'WERKS', 'LGORT')
      ORDER BY POSITION.

    FIELDCOUNT = SY-DBCNT.

    ASSIGN TABLE_BUFFER TO <TABLE> CASTING TYPE (PTABLE).
    "ASSIGN (PTABLE) TO <TABLE> CASTING TYPE (PTABLE).

*"-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* Mit Cursor auf Datensatz zeigen
*"-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    "SELECT * FROM MARA INTO <TABLE> UP TO 1 ROWS ORDER BY PRIMARY KEY.

    OPEN CURSOR C FOR SELECT *  "(COLUMSTAB) "MANDT MATNR WERKS LGORT
    FROM (PTABLE) WHERE (CONDTAB)
    ORDER BY PRIMARY KEY.

    DO.

      ROWCOUNTINT = ROWCOUNTINT + 1.

      "ASSIGN TABLE_BUFFER TO <TABLE> CASTING TYPE MARA.
      FETCH NEXT CURSOR C INTO <TABLE>.
      IF SY-SUBRC <> 0.
        EXIT.
      ELSE.
        CLEAR STRTEMP.
        I = 0.

        LOOP AT TABLE_STRUCTURE.
          I = I + 1.

          CASE TABLE_STRUCTURE-INTTYPE.

*"-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* Casting, damit die Felder konkatiniert werden können und in einer Zeile ausgegeben werden können.
*"-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*"----------------------------------------------------------------------------------------------------------------------------------------
*"Packed numbers
*"----------------------------------------------------------------------------------------------------------------------------------------
            WHEN 'P'.
              ASSIGN COMPONENT TABLE_STRUCTURE-FIELDNAME
              OF STRUCTURE <TABLE> TO <FIELDCONTENT>
              TYPE TABLE_STRUCTURE-INTTYPE
              DECIMALS TABLE_STRUCTURE-DECIMALS.
              MOVE <FIELDCONTENT> TO FIELDCONTENT.
*"----------------------------------------------------------------------------------------------------------------------------------------
*"Byte Sequences
*"----------------------------------------------------------------------------------------------------------------------------------------
            WHEN 'X'.
              CASE TABLE_STRUCTURE-DATATYPE.
                WHEN 'INT1'.
                  ASSIGN COMPONENT TABLE_STRUCTURE-FIELDNAME
                  OF STRUCTURE <TABLE> TO <FIELDCONTENT>
                  CASTING TYPE BYTE.
                WHEN 'INT2'.
                  ASSIGN COMPONENT TABLE_STRUCTURE-FIELDNAME
               OF STRUCTURE <TABLE> TO <FIELDCONTENT>
               CASTING TYPE SHORT_INTEGER.
                WHEN OTHERS.
                  ASSIGN COMPONENT TABLE_STRUCTURE-FIELDNAME
                OF STRUCTURE <TABLE> TO <FIELDCONTENT>
                CASTING TYPE INTEGER.
              ENDCASE.
              MOVE <FIELDCONTENT> TO FIELDCONTENT.

*"----------------------------------------------------------------------------------------------------------------------------------------
*"Characters und numeric characters
*"----------------------------------------------------------------------------------------------------------------------------------------
            WHEN 'C' OR 'N'.
              ASSIGN COMPONENT TABLE_STRUCTURE-FIELDNAME
           OF STRUCTURE <TABLE> TO <FIELDCONTENT>
           TYPE TABLE_STRUCTURE-INTTYPE.
              MOVE <FIELDCONTENT> TO FIELDCONTENT.

*"----------------------------------------------------------------------------------------------------------------------------------------
*"OTHERS
*"----------------------------------------------------------------------------------------------------------------------------------------
            WHEN OTHERS.
              ASSIGN COMPONENT TABLE_STRUCTURE-FIELDNAME
              OF STRUCTURE <TABLE> TO <FIELDCONTENT>
              TYPE TABLE_STRUCTURE-INTTYPE.
              MOVE <FIELDCONTENT> TO FIELDCONTENT.
          ENDCASE.

*"-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* "Zusammenbau Datensatz und Ausgabe in File
*"-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
          IF I = 1.
            MOVE FIELDCONTENT TO STRTEMP.
          ELSEIF I <> FIELDCOUNT.
            "Concatenate strTemp ';' Into strTemp.
            CONCATENATE STRTEMP FIELDCONTENT INTO STRTEMP SEPARATED BY TAB.
          ELSE."NEU
            CONCATENATE STRTEMP FIELDCONTENT INTO STRTEMP.
          ENDIF.
        ENDLOOP.
        CLOSE DATASET FILE.
        OPEN DATASET FILE FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
        IF SY-SUBRC = 8.
          WRITE: /'Datei kann nicht geöffnet werden.'.
          EXIT.
        ELSE.
          TRANSFER STRTEMP TO FILE.
          CLOSE DATASET FILE.

          IF ROWCOUNT > 0 AND ROWCOUNTINT GE ROWCOUNT.
            EXIT.
          ENDIF.


        ENDIF.


      ENDIF.
    ENDDO.
    "ENDSELECT.
    PERFORM COPY_RESULT_TO_FRONTEND.
  ELSE.
    PERFORM COPY_RESULT_TO_FRONTEND.
  ENDIF.

ENDFORM.                    "DATA_PROCESSING
"-ENDE_

*&---------------------------------------------------------------------*
*&      Form  check_table_exists
*&---------------------------------------------------------------------*
*       Prüfung, ob vorhanden
*----------------------------------------------------------------------*
FORM CHECK_TABLE_EXISTS.
  SELECT SINGLE * FROM DD02L
  INTO CORRESPONDING FIELDS OF DD02L
  WHERE TABNAME = PTABLE.
  CHECK SYST-SUBRC NE 0.
  MESSAGE E402(MO) WITH PTABLE.
ENDFORM.                    "check_table_exists

*&---------------------------------------------------------------------*
*&      Form  build_file_name
*&---------------------------------------------------------------------*
*       Datei-Pfad zusammenbauen
*----------------------------------------------------------------------*
FORM BUILD_FILE_NAME.
  FILE = PATH.
  CONCATENATE FILE PTABLE '.txt' INTO FILE.
  TRANSLATE FILE TO LOWER CASE. "Unbedingt! Pfade sind keysensitive...
ENDFORM.                    "build_file_name

*----------------------------------------------------------------------*
* Prüfen, ob File existiert
*----------------------------------------------------------------------*
FORM FILE_EXISTS.

  OPEN DATASET FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
  IF SY-SUBRC NE 0.
    CLOSE DATASET FILE.
    PERFORM HEADER_EXPORT.
    EXIT.

  ELSE.

    CALL FUNCTION 'POPUP_CONTINUE_YES_NO'
      EXPORTING
        DEFAULTOPTION = 'N'
        TEXTLINE1     = FILE
        TEXTLINE2     = 'bereits vorhanden!'
        TITEL         = 'File existiert bereits! Soll es neu angelegt werden?'
      IMPORTING
        ANSWER        = W_ANS
      EXCEPTIONS
        OTHERS        = 1.

  ENDIF.
  CLOSE DATASET FILE.
  CHECK W_ANS = 'J'.
*----------------------------------------------------------------------*
* Löschen
*----------------------------------------------------------------------*
  DELETE DATASET FILE.

  IF SY-SUBRC NE 0.
    MESSAGE E899(BD) WITH 'Ungültiger File-Name' FILE.
  ELSE.
    CLOSE DATASET FILE.
    MESSAGE I899(BD) WITH PATH PTABLE '.txt gelöscht'.
    PERFORM HEADER_EXPORT.
  ENDIF.
ENDFORM.                    "FILE_EXISTS

*&---------------------------------------------------------------------*
*&      Form  HEADER_EXPORT
*&---------------------------------------------------------------------*
*       Header des Export-Files erstellen!
*----------------------------------------------------------------------*

FORM HEADER_EXPORT.

  SELECT * FROM  DD03L INTO LVDD03L
   WHERE ROLLNAME NE '' AND TABNAME EQ PTABLE ORDER BY POSITION.
    IF WA_HEADER-HEADER EQ ''.
      WA_HEADER-HEADER = LVDD03L-FIELDNAME.
    ELSE.
      CONCATENATE WA_HEADER-HEADER LVDD03L-FIELDNAME
       INTO WA_HEADER-HEADER SEPARATED BY TAB. " IN CHARACTER MODE.
    ENDIF.
  ENDSELECT.
  APPEND WA_HEADER TO IT_HEADER.

* Interne Tabelle mit allen Feldeinträgen, getrennt durch TAB-Delimiter.
* Muss noch ins File geschrieben werden.

  OPEN DATASET FILE FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
  IF SY-SUBRC = 8.
    WRITE: /'Datei kann nicht geöffnet werden.'.
    EXIT.
  ELSE.
    LOOP AT IT_HEADER INTO WA_HEADER.
      TRANSFER WA_HEADER TO FILE.
    ENDLOOP.
    CLOSE DATASET FILE.
  ENDIF.
  PERFORM DATA_PROCESSING.
ENDFORM.                    "HEADER_EXPORT

*&---------------------------------------------------------------------*
*&      Form  COPY_RESULT_TO_FRONTEND
*&---------------------------------------------------------------------*
*       Ergebnis vom Server kopieren
*----------------------------------------------------------------------*
FORM COPY_RESULT_TO_FRONTEND.
*  TYPES COPY_SOURCE TYPE STRING.
  DATA COPY_SOURCE TYPE STRING.
  DATA: STRG1 TYPE STRING VALUE '', STRG2 TYPE STRING VALUE ''.
  COPY_SOURCE = FILE.
  TRANSLATE COPY_SOURCE TO LOWER CASE.
*  WRITE COPY_SOURCE.
*  DATA: COPY_DESTIN TYPE STRING VALUE 'C:\tmp\marc.txt'.

  CONCATENATE 'Soll' COPY_SOURCE INTO STRG1 SEPARATED BY ' '.
  Strg2 = 'auf ihren Rechner kopiert werden?'.


  CALL FUNCTION 'POPUP_CONTINUE_YES_NO'
    EXPORTING
      DEFAULTOPTION = 'N'
      TEXTLINE1     = STRG1
      TEXTLINE2     = STRG2
      TITEL         = 'File auf Frontend übertragen?'
    IMPORTING
      ANSWER        = W_ANS
    EXCEPTIONS
      OTHERS        = 1.


  CHECK W_ANS = 'J'.

  LEAVE TO TRANSACTION 'CG3Y'.

  CHECK W_ANS = 'N'.

  EXIT.

ENDFORM.                    "COPY_RESULT_TO_FRONTEND


Förderer

.fetox
vor 10 Jahre