Code: Alles auswählen.
DATA: w_tablename TYPE tablename.
...... w_tablename wird gefüllt ....
DATA : begin of t_import .
INCLUDE STRUCTURE w_tablename.
data : description(30) type c,
end of t_import.
Code: Alles auswählen.
types:
begin of ts_import,
value type ref to data,
name type c length 30,
end of ts_import.
DATA:
ls_import TYPE ts_import,
w_tablename TYPE tablename,
w_fieldname TYPE fieldname.
FIELD-SYMBOLS: <ls_value> TYPE ANY.
CREATE DATA ls_import-value type (w_tablename).
ASSIGN ls_import-value->* to <ls_value>.
ASSIGN COMPONENT w_fieldname OF structure <ls_value> to <la_field>.
Code: Alles auswählen.
REPORT.
DATA: gt_struc TYPE cl_abap_structdescr=>component_table,
gs_part LIKE LINE OF gt_struc,
gr_dref_struc TYPE REF TO cl_abap_structdescr,
gr_dref TYPE REF TO data.
FIELD-SYMBOLS: <gs_extended_structure> TYPE ANY.
PARAMETERS: p_table TYPE dd03l-tabname DEFAULT 'SFLIGHT'.
END-OF-SELECTION.
CLEAR gs_part.
gs_part-name = space. " Wenn du hier einen Namen vergibst kannst du die ganze Struktur unter diesem ansprechen
gs_part-as_include = 'X'.
gs_part-type ?= cl_abap_structdescr=>describe_by_name( p_table ).
APPEND gs_part TO gt_struc.
DATA: description(30) TYPE c.
CLEAR gs_part.
gs_part-name = 'DESCRIPTION'.
gs_part-as_include = ' '.
gs_part-type ?= cl_abap_structdescr=>describe_by_data( description ).
APPEND gs_part TO gt_struc.
gr_dref_struc ?= cl_abap_structdescr=>create( gt_struc ).
CREATE DATA gr_dref TYPE HANDLE gr_dref_struc.
ASSIGN gr_dref->* TO <gs_extended_structure>.
BREAK-POINT.
Code: Alles auswählen.
FORM import USING w_path TYPE string.
DATA: gt_struc TYPE cl_abap_structdescr=>component_table,
gs_part LIKE LINE OF gt_struc,
gr_dref_struc TYPE REF TO cl_abap_structdescr,
gr_dref TYPE REF TO DATA,
w_table TYPE dd03l-tabname.
FIELD-SYMBOLS: <gs_extended_structure> TYPE ANY.
MOVE w_tablename TO w_table.
CLEAR gs_part.
gs_part-NAME = SPACE. " Wenn du hier einen Namen vergibst kannst du die ganze Struktur unter diesem ansprechen
gs_part-as_include = 'X'.
gs_part-TYPE ?= cl_abap_structdescr=>describe_by_name( w_table ).
APPEND gs_part TO gt_struc.
DATA: description(30) TYPE c.
CLEAR gs_part.
gs_part-NAME = 'DESCRIPTION'.
gs_part-as_include = ' '.
gs_part-TYPE ?= cl_abap_structdescr=>describe_by_data( description ).
APPEND gs_part TO gt_struc.
gr_dref_struc ?= cl_abap_structdescr=>create( gt_struc ).
CREATE DATA gr_dref TYPE HANDLE gr_dref_struc.
ASSIGN gr_dref->* TO <gs_extended_structure>.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = w_path
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
READ_BY_LINE = 'X'
TABLES
data_tab = gt_struc
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
Folgende Benutzer bedankten sich beim Autor black_adept für den Beitrag:
Bugfix13
Code: Alles auswählen.
DATA: gr_dref_table TYPE REF TO cl_abap_tabledescr
FIELD-SYMBOLS: <gt_extended_table> TYPE ANY TABLE.
gr_dref_struc ?= cl_abap_structdescr=>create( gt_struc ).
gr_dref_table ?= cl_abap_tabledescr=>create( gr_dref_struc ).
CREATE DATA gr_dref TYPE HANDLE gr_dref_table.
ASSIGN gr_dref->* TO <gt_extended_table>.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = w_path
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
READ_BY_LINE = 'X'
TABLES
data_tab = <gt_extended_table>
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17.
Folgende Benutzer bedankten sich beim Autor a-dead-trousers für den Beitrag:
Bugfix13