Bonjour,

Ceci n'est pas une question, je partage juste un JOB ABAP que voici dont le but est d'exporter des tables SAP quelque soit sa structure (limitée à 100 colonnes) en fichier plat.

Les tables à exporter en fichiers plats sont passées en paramètre par une variante.

En espérant que cela soit utile

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
REPORT  nomreport   .
TABLES: table.
* data declaration
DATA : s_table TYPE REF TO DATA,
       s_table_line TYPE REF TO DATA,
       filename1 type string,
       filename2 type string,
       s_file LIKE rlgrap-filename,
       t_file LIKE rlgrap-filename.
data : t_filename type table of string.
constants: c_directory(20) value 'le chemin destination'.
FIELD-SYMBOLS : <fs> TYPE standard table.
field-symbols : <fs_line> type any.
field-symbols : <fs_field> type any.
data: v_line(500).

select-options : table_select for table-TABNAME.
*             p_dfile LIKE rlgrap-filename .

start-of-selection.

  loop at table_select.

* Create dynamic structure
    CREATE DATA s_table TYPE table of (table_select-low).
    CREATE DATA s_table_line type (table_select-low).

    ASSIGN s_table->* TO  <fs>.
    assign s_table_line->* to <fs_line>.

* Select data into internal table
    SELECT * FROM (table_select-low) INTO table <fs>.


* export into excel file
    move c_directory to  filename1.
    concatenate filename1 table_select-low '.xls' into filename2.

    OPEN DATASET filename2 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

    loop at <fs> into <fs_line>.

      clear: v_line.
      do 100 times.
        ASSIGN COMPONENT SY-INDEX OF
                   STRUCTURE <fs_line> TO <FS_field>.
        if sy-subrc = 0.
          concatenate v_line  '|' <FS_field> into v_line.
        else.
          exit.
        endif.
      enddo.
      transfer v_line to filename2.
    endloop.

    Close DATASET filename2.
  endloop.