SAP => CSV für breite Tabellen?

Alles rund um die Sprache ABAP®: Funktionsbausteine, Listen, ALV
11 Beiträge • Seite 1 von 1
11 Beiträge Seite 1 von 1

SAP => CSV für breite Tabellen?

Beitrag von ralf.wenzel (Top Expert / 3776 / 176 / 262 ) »
Moin,

ich verwende gern den FuBau SAP_CONVERT_TO_CSV_FORMAT, um aus einer SAP-Tabelle eine Text-Tabelle im Format CSV zu machen. Leider habe ich jetzt eine Tabelle, die breiter ist als 4096 Zeichen, womit der Funktionsbaustein ausfällt.

Wer weiß eine gute Möglichkeit, die Konvertierung für sehr breite Tabellen zu machen? Ich will das alles nicht von Hand machen....


Gruß und vielen Dank

Ralf
Bild
Ralf Wenzel Heuristika SAP-Development
25 Jahre SAP-Entwickler • 20 Jahre Freiberufler
PublikationenUngarische NotationXing

gesponsert
Stellenangebote auf ABAPforum.com schalten
kostenfrei für Ausbildungsberufe und Werksstudenten


Re: SAP => CSV für breite Tabellen?

Beitrag von Alexander D. (Expert / 682 / 30 / 84 ) »
schöne Grüße
Alexander

ECC 6.0 EHP 7

Re: SAP => CSV für breite Tabellen?

Beitrag von ralf.wenzel (Top Expert / 3776 / 176 / 262 ) »
Moin,

zweiter Link ergibt:

Service cannot be reached


Gruß

Ralf
Bild
Ralf Wenzel Heuristika SAP-Development
25 Jahre SAP-Entwickler • 20 Jahre Freiberufler
PublikationenUngarische NotationXing

Re: SAP => CSV für breite Tabellen?

Beitrag von Alexander D. (Expert / 682 / 30 / 84 ) »
hatte ich auch gerade. Nachdem ich die Seite aktualisiert habe wurde sie dann doch noch angezeigt
schöne Grüße
Alexander

ECC 6.0 EHP 7

Re: SAP => CSV für breite Tabellen?

Beitrag von ralf.wenzel (Top Expert / 3776 / 176 / 262 ) »
Bei mir reichen 20 Reloads nicht, damit die Seite angezeigt wird.
Bild
Ralf Wenzel Heuristika SAP-Development
25 Jahre SAP-Entwickler • 20 Jahre Freiberufler
PublikationenUngarische NotationXing

Re: SAP => CSV für breite Tabellen?

Beitrag von Alexander D. (Expert / 682 / 30 / 84 ) »
wenn ich die Seite mit F5 aktualisiere tut sich tatsächlich nichts. Wenn ich aber im Browser die komplette Seitenadresse markiere und ENTER drücke, dann wird der Artikel angezeigt. Ich würde ihn ja hier mal als PDF anhängen, nur ist diese Dateiendung als Anhang nicht zugelassen
schöne Grüße
Alexander

ECC 6.0 EHP 7

Re: SAP => CSV für breite Tabellen?

Beitrag von ralf.wenzel (Top Expert / 3776 / 176 / 262 ) »
Alexander D. hat geschrieben:hallo Ralf,

hier sind zwei mögliche Ansätze zu dem Thema:

http://ww.apentia-forum.de/viewtopic.php?f=2&t=17922

http://www.benx.de/benx%28bD1lbiZjPTAwM ... id=1459759
Beides etwas unbefriedigend, aber ich werde mich wohl mit Möglichkeit 1 zufrieden geben müssen.

Wer denkt sich solche bescheuerten Beschränkungen aus???
Bild
Ralf Wenzel Heuristika SAP-Development
25 Jahre SAP-Entwickler • 20 Jahre Freiberufler
PublikationenUngarische NotationXing

Re: SAP => CSV für breite Tabellen?

Beitrag von horst1959 (ForumUser / 20 / 0 / 0 ) »

Code: Alles auswählen.

*&---------------------------------------------------------------------*
*&  Include           ZCL_NEW_CSVGEN                                   *
*&---------------------------------------------------------------------*

*----------------------------------------------------------------------
*
*       CLASS ZCL_NEW_CSVGEN DEFINITION
*----------------------------------------------------------------------
*
*
*----------------------------------------------------------------------
*
class zcl_new_csvgen definition.

  type-pools : abap,
               sydes.

  public section.

    types   : i_self       type ref to zcl_new_csvgen,
              ty_shortterm type ref to zcl_new_shortterm.


    types   : begin of ty_csv,
                data type di_data,
              end of ty_csv.
    types   : ty_table type standard table of ty_csv.

    class-methods create returning value(ref) type i_self.

    methods : head importing e_structur type any
                   exporting i_head     type di_data.

    methods : csv  importing e_anytab  type any table
                   exporting i_csvtab  type ty_table.

    methods free.

  private section.

    types   : ty_str256(256) type c.

    types   : begin of ty_in_out,
                input     type ty_str256,
                f_dec     type i,
                counter   type i,
                shortterm type ty_shortterm,
              end of ty_in_out.
    data    : ta_in_out type hashed table of ty_in_out
                     with unique key input f_dec.

    types   : begin of ty_lang,
                row  type i,
                len  type i,
              end of ty_lang.
    data    : ta_lang type standard table of ty_lang.

    data    : my_error   type sysubrc,
              my_counter type i.

    methods : kompakt importing p_table          type any table.

    methods : wandel  importing p_input          type any
                      returning value(my_string) type ty_str256.

endclass.                    "ZCL_NEW_CSVGEN DEFINITION


*----------------------------------------------------------------------*
*       CLASS ZCL_NEW_CSVGEN IMPLEMANTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
*
class zcl_new_csvgen implementation.

  method create.
    create object ref.
  endmethod.                    "create

  method wandel.

    data : f_times      type i,
           f_type       type c,
           f_dec        type i,
           f_len        type i,
           l_puffer     type ty_str256.

    data          : wa_in_out   type ty_in_out.
    field-symbols : <fs_in_out> type ty_in_out.

    my_counter = my_counter + 1.
    if my_counter >= 100000.
      my_counter = 0.
      delete ta_in_out where counter = 0.
    endif.

    clear my_string.
    check not p_input is initial.

    describe field p_input type f_type.

    case f_type.

      when 'T'.
        read table ta_in_out with table key input = p_input
                                            f_dec = 0
                             assigning <fs_in_out>.
        if sy-subrc = 0.
          call method <fs_in_out>-shortterm->get_data
            importing
              i_data = my_string.
          <fs_in_out>-counter = <fs_in_out>-counter + 1.
        else.
          search p_input for ':'.
          if sy-subrc <> 0.
            concatenate p_input+0(2) ':' p_input+2(2) ':' p_input+4(2)
                        into my_string.
          else.
            my_string = p_input.
          endif.
          clear wa_in_out.
          wa_in_out-input     = p_input.
          wa_in_out-f_dec     = 0.
          wa_in_out-counter   = 0.
          wa_in_out-shortterm = zcl_new_shortterm=>create( ).
          call method wa_in_out-shortterm->set_data
            exporting
              e_data  = my_string
            importing
              i_error = my_error.
          if my_error = 0.
            insert wa_in_out into table ta_in_out.
          endif.
        endif.

      when 'D'.
        read table ta_in_out with table key input = p_input
                                            f_dec = 0
                       assigning <fs_in_out>.
        if sy-subrc = 0.
          call method <fs_in_out>-shortterm->get_data
            importing
              i_data = my_string.
          <fs_in_out>-counter = <fs_in_out>-counter + 1.
        else.
          search p_input for '.'.
          if sy-subrc <> 0.
            concatenate p_input+6(2) '.' p_input+4(2) '.' p_input+0(4)
                        into my_string.
          else.
            my_string = p_input.
          endif.
          clear wa_in_out.
          wa_in_out-input     = p_input.
          wa_in_out-f_dec     = 0.
          wa_in_out-counter   = 0.
          wa_in_out-shortterm = zcl_new_shortterm=>create( ).
          call method wa_in_out-shortterm->set_data
            exporting
              e_data  = my_string
            importing
              i_error = my_error.
          if my_error = 0.
            insert wa_in_out into table ta_in_out.
          endif.
        endif.

      when 'F'.
        unpack p_input to my_string.
        describe field p_input decimals f_dec.
        read table ta_in_out with table key input = my_string
                                            f_dec = f_dec
                assigning <fs_in_out>.
        if sy-subrc = 0.
          call method <fs_in_out>-shortterm->get_data
            importing
              i_data = my_string.
          <fs_in_out>-counter = <fs_in_out>-counter + 1.
        else.
          l_puffer = my_string.
          shift my_string left deleting leading '0'.
          f_len = strlen( my_string ).
          if f_len < f_dec.
            f_times = f_dec - f_len.
            do f_times times.
              concatenate '0' my_string into my_string.
            enddo.
            f_len = f_dec.
          endif.
          if f_dec > 0.
            f_times = f_len - f_dec.
            if f_times = 0.
              concatenate '0,' my_string into my_string.
            else.
              concatenate my_string+0(f_times) ','
                          my_string+f_times(f_dec)
                     into my_string.
            endif.
          endif.
          if p_input < 0.
            concatenate '-' my_string into my_string.
          endif.
          clear wa_in_out.
          wa_in_out-input     = l_puffer.
          wa_in_out-f_dec     = f_dec.
          wa_in_out-counter   = 0.
          wa_in_out-shortterm = zcl_new_shortterm=>create( ).
          call method wa_in_out-shortterm->set_data
            exporting
              e_data  = my_string
            importing
              i_error = my_error.
          if my_error = 0.
            insert wa_in_out into table ta_in_out.
          endif.
        endif.

      when 'P'.
        unpack p_input to my_string.
        describe field p_input decimals f_dec.
        read table ta_in_out with table key input = p_input
                                            f_dec = f_dec
                                  assigning <fs_in_out>.
        if sy-subrc = 0.
          call method <fs_in_out>-shortterm->get_data
            importing
              i_data = my_string.
          <fs_in_out>-counter = <fs_in_out>-counter + 1.
        else.
          l_puffer = my_string.
          shift my_string left deleting leading '0'.
          f_len = strlen( my_string ).
          if f_len < f_dec.
            f_times = f_dec - f_len.
            do f_times times.
              concatenate '0' my_string into my_string.
            enddo.
            f_len = f_dec.
          endif.
          if f_dec > 0.
            f_times = f_len - f_dec.
            if f_times = 0.
              concatenate '0,' my_string into my_string.
            else.
              concatenate my_string+0(f_times) ','
                          my_string+f_times(f_dec)
                     into my_string.
            endif.
          endif.
          if p_input < 0.
            concatenate '-' my_string into my_string.
          endif.
          clear wa_in_out.
          wa_in_out-input     = l_puffer.
          wa_in_out-f_dec     = f_dec.
          wa_in_out-counter   = 0.
          wa_in_out-shortterm = zcl_new_shortterm=>create( ).
          call method wa_in_out-shortterm->set_data
            exporting
              e_data  = my_string
            importing
              i_error = my_error.
          if my_error = 0.
            insert wa_in_out into table ta_in_out.
          endif.
        endif.

      when others.
        read table ta_in_out with table key input = p_input
                                            f_dec = 0
                             assigning <fs_in_out>.
        if sy-subrc = 0.
          call method <fs_in_out>-shortterm->get_data
            importing
              i_data = my_string.
          <fs_in_out>-counter = <fs_in_out>-counter + 1.
        else.
          my_string = p_input.
          if f_type = 'C'
          or f_type = 'G'.
            find ';' in my_string.
            if sy-subrc = 0.
              concatenate '"' my_string '"' into my_string.
            endif.
          endif.
          condense my_string.
        endif.
        clear wa_in_out.
        wa_in_out-f_dec = 0.
        wa_in_out-counter   = 0.
        wa_in_out-input = p_input.
        wa_in_out-shortterm = zcl_new_shortterm=>create( ).
        call method wa_in_out-shortterm->set_data
          exporting
            e_data  = my_string
          importing
            i_error = my_error.
        if my_error = 0.
          insert wa_in_out into table ta_in_out.
        endif.

    endcase.

  endmethod.                    "wandel


  method kompakt.
    data          : wa_lang    type ty_lang.
    "                    l_type(1)  TYPE c.

    field-symbols : <fs_co>    type any,
                    <fs_wa>    type any,
                    <fs_la>    type ty_lang.

    data          : my_string  type ty_str256,
                    my_erster  type boolean,
                    olen       type i.
    "                    offset     TYPE i.

    free ta_lang.
    my_erster = abap_false.
    loop at p_table assigning <fs_wa>.
      do.
        assign component sy-index
               of structure <fs_wa>
               to <fs_co>.
        if sy-subrc <> 0.
          exit.
        endif.
        my_string = me->wandel( <fs_co> ).
        olen      = strlen( my_string ).
        if my_erster = abap_false.
          wa_lang-row = sy-index.
          wa_lang-len = olen.
          append wa_lang to ta_lang .
        else.
          read table ta_lang index sy-index assigning <fs_la>.
          if olen > <fs_la>-len.
            <fs_la>-len = olen.
          endif.
        endif.
      enddo.
      my_erster = abap_true.
    endloop.
  endmethod.                    "kompakt


  method head.
    types :    feld_name   type sydes_nameinfo.
    data  :    td          type sydes_desc,
               f_names_tab type standard table of feld_name,
               f_names     type feld_name,
"               f_name(15)  TYPE c,
               l_longname(61) type c,
               l_index        type i.

    data  :    ref_fieldname type fieldname,
               ref_tabname   type tabname,
               rollname      type rollname,
               l_lang        type i,
               scrtext_m     type scrtext_m.


    field-symbols : <fs_field> type any.

    clear i_head.
    do.
      clear : scrtext_m,
              rollname.
      assign component sy-index of structure e_structur to <fs_field>.
      if sy-subrc <> 0.
        exit.
      endif.
      describe field <fs_field> into td.
      f_names_tab[] = td-names[].
      l_index = 2.
      read table f_names_tab index l_index into f_names.
      if sy-subrc = 0.
        l_longname = f_names-name.
      endif.

      if f_names-continue = '*'.
        do.
          l_index = l_index + 1.
          read table f_names_tab index l_index into f_names.
          concatenate l_longname f_names-name into l_longname.
          if f_names-continue <> '*'.
            exit.
          endif.
        enddo.
      endif.

      find '-' in l_longname.
      if sy-subrc = 0.
        split l_longname at '-' into ref_tabname ref_fieldname.

        select single rollname                              "#EC *
          into rollname
          from dd03l
          where tabname   = ref_tabname
          and   fieldname = ref_fieldname
          and   as4local  = 'A'.
        if  sy-subrc <> 0.
          l_lang = strlen( ref_fieldname ).
          l_lang = l_lang - 1.
          if l_lang > 1.
            ref_fieldname+l_lang(1) = '%'.
            select single rollname                          "#EC *
              into rollname
              from dd03l
              where tabname   = ref_tabname
              and   fieldname like ref_fieldname
              and   as4local  = 'A'.
            if sy-subrc <> 0.
              rollname = '???'.

            endif.
          endif.
        endif.
      else.
        rollname = l_longname.
      endif.

      if rollname <> ''.
        select single scrtext_m                             "#EC *
          into scrtext_m
          from dd04t
          where rollname   = rollname
          and   ddlanguage = sy-langu
          and   as4local   = 'A'.
        if sy-subrc <> 0.
          scrtext_m = '???'.
        endif.
      else.
        scrtext_m = '???'.
      endif.
      concatenate i_head scrtext_m ';' into i_head.
    enddo.
  endmethod.                    "head


  method csv.
    field-symbols : <fs_co>     type any,
                    <fs_wa>     type any,
                    <fs_la>     type ty_lang.

    data          : my_string   type ty_str256,
                    wa_csv      type ty_csv,
                    olen        type i,
                    offset      type i.

    call method me->kompakt
      exporting
        p_table = e_anytab.

    loop at e_anytab assigning <fs_wa>.
      offset = 0.
      clear wa_csv-data.
      do.
        assign component sy-index of structure <fs_wa> to <fs_co>.
        if sy-subrc <> 0.
          olen = strlen( wa_csv ).
          olen = olen - 1.
          wa_csv = wa_csv+0(olen).
          append wa_csv to i_csvtab.
          exit.
        endif.
        my_string = me->wandel( <fs_co> ).
        write my_string to wa_csv-data+offset.
        read table ta_lang index sy-index assigning <fs_la>.
        offset = offset + <fs_la>-len.
        write ';' to wa_csv-data+offset.
        offset = offset + 1.
      enddo.
    endloop.
  endmethod.                    "csv


  method free.
    field-symbols : <fs_in_out> type ty_in_out.
    loop at ta_in_out assigning <fs_in_out>.
      call method <fs_in_out>-shortterm->free.
    endloop.
    free : ta_in_out,
           ta_lang.
    call method cl_abap_memory_utilities=>do_garbage_collection.
  endmethod.                    "free

endclass.                    "ZCL_NEW_CSVGEN IMPLEMENTATION



Re: SAP => CSV für breite Tabellen?

Beitrag von horst1959 (ForumUser / 20 / 0 / 0 ) »
* Sorry das Beispiel für den Aufruf vergessen

Code: Alles auswählen.

*&---------------------------------------------------------------------*
*&      Form  DOWNLOAD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form download .

  types : begin of ty_short,
            class type klasse_d,  " Klassennummer
            abtei type abteilung, " Anwendungssicht
            atnam type atnam,     " Merkmalname
          end of ty_short.
  data          ta_short   type standard table of ty_short.
  field-symbols <fs_short> type ty_short.

  types : begin of ty_csv,
            data type di_data.
  types : end of ty_csv.
  data          : ta_csv     type standard table of ty_csv.

  data          : head       type di_data,
                  l_error    type sysubrc.

  data          : file_dir   type string value 'c:\temp\',
                  file_name  type string value '',
                  file_ext   type string value 'csv'.

  data          : o_new_csv  type ref to zcl_new_csvgen,
                  o_new_down type ref to zcl_new_asciidown.

  field-symbols : <fs_line>  type ty_csv.

  o_new_csv = zcl_new_csvgen=>create( ).

  loop at ta_table assigning <fs_table>.
    append initial line to ta_short assigning <fs_short>.
    <fs_short>-class = <fs_table>-class.
    <fs_short>-abtei = <fs_table>-abtei.
    <fs_short>-atnam = <fs_table>-atnam.
  endloop.

  o_new_csv = zcl_new_csvgen=>create( ).

  read table ta_short index 1 assigning <fs_short>.
  call method o_new_csv->head
    exporting
      e_structur = <fs_short>
    importing
      i_head     = head.

  call method o_new_csv->csv
    exporting
      e_anytab = ta_short
    importing
      i_csvtab = ta_csv.

  call method o_new_csv->free.
  clear   o_new_csv.

  o_new_down = zcl_new_asciidown=>create( ).
  call method o_new_down->set_dos_modus.

*  CALL METHOD o_new_down->asc_addline
*    EXPORTING
*      p_line  = head
*    IMPORTING
*      p_error = l_error.

  loop at ta_csv assigning <fs_line>.
    call method o_new_down->asc_addline
      exporting
        p_line  = <fs_line>-data
      importing
        p_error = l_error.
  endloop.

  call method o_new_down->asc_downlocal
    exporting
      p_dir     = file_dir
      p_filenam = file_name
      p_fileext = file_ext
    importing
      p_error   = l_error.

  call method o_new_down->free.
  clear o_new_down.

endform.                    " DOWNLOAD

Re: SAP => CSV für breite Tabellen?

Beitrag von Dele (Specialist / 307 / 4 / 47 ) »
Nicht getestet, sehen aber gut aus:
FBMW_CONVERT_INTERN_TO_CSV
FKK_AWM_CONVERT_INTERN_TO_CSV

Re: SAP => CSV für breite Tabellen?

Beitrag von horst1959 (ForumUser / 20 / 0 / 0 ) »
Ich denke es ging hier drum, über die vereinbarte Länge der Ausgabezeile x-beliebig breite CSV zu erzeugen.
Das war das Problem und das ist mit dem Beispiel möglich!

Gruß
HK

Seite 1 von 1

Vergleichbare Themen

4
Antw.
2410
Views
ALV Breite anpassen
von SAP_ENTWICKLER » 06.06.2013 12:10 • Verfasst in ABAP® Core
1
Antw.
2835
Views
ALV maximale breite?
von Viktoria » 23.11.2006 15:00 • Verfasst in ABAP® Core
4
Antw.
2478
Views
listenbreite --> alv_list breite
von abap-strizi » 13.07.2005 13:29 • Verfasst in ABAP Objects®
0
Antw.
1610
Views
Breite Screen/Subscreen
von erp-bt » 16.01.2013 12:06 • Verfasst in ABAP® Core
3
Antw.
315
Views
Breite des ALV-Grids anpassen
von Fero » 01.04.2022 11:22 • Verfasst in ABAP® für Anfänger

Newsletter Anmeldung

Keine Beiträge verpassen! Wöchentlich versenden wir lesenwerte Beiträge aus unserer Community.
Die letzte Ausgabe findest du hier.
Details zum Versandverfahren und zu Ihren Widerrufsmöglichkeiten findest du in unserer Datenschutzerklärung.

Unbeantwortete Forenbeiträge

Zwischensumme Adobe Forms
vor 4 Wochen von Lucyalison 1 / 134
Group Items auf einer Filterbar
vor 5 Wochen von Bright4.5 1 / 168