Code: Alles auswählen.
REPORT z_anlaginv.
TABLES: anla.
DATA: wa_timedepentdata TYPE bapi1022_feglg003,
wa_timedepentdatax TYPE bapi1022_feglg003x,
wa_inventory TYPE bapi1022_feglg011,
wa_inventoryx TYPE bapi1022_feglg011x.
DATA: wa_return TYPE bapiret2.
PARAMETERS: datei(40) TYPE c.
DATA: BEGIN OF itab_anlaginv OCCURS 10,
bukrs LIKE anla-bukrs,
anhaupt LIKE anla-anln1,
anunter LIKE anla-anln2,
END OF itab_anlaginv.
DATA: wa_anlaginv LIKE LINE OF itab_anlaginv.
DATA:upload TYPE string.
upload = datei.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = upload
filetype = 'ASC'
TABLES
data_tab = itab_anlaginv
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.
MESSAGE i040(/sapdmc/lsmw_glo_010) WITH '&' '&'.
* Fehler beim Upload der Datei '&' (Return-Code &).
ENDIF.
DATA: BEGIN OF itab_fnam OCCURS 10,
END OF itab_fnam.
DATA: BEGIN OF itab_fval OCCURS 10,
END OF itab_fval.
FIELD-SYMBOLS <fs> TYPE ANY.
LOOP AT itab_anlaginv INTO wa_anlaginv.
AT NEW subnumber.
IF itab_fnam CS 'TIMEDEPENTDATA'.
ASSIGN COMPONENT itab_fnam OF STRUCTURE wa_timedepentdata TO <fs>.
<fs> = itab_fval.
ELSEIF itab_fnam CS 'TIMEDEPENTDATAX'.
ASSIGN COMPONENT itab_fnam OF STRUCTURE wa_timedepentdatax TO <fs>.
<fs> = itab_fval.
ELSEIF itab_fnam CS 'INVENTORY'.
ASSIGN COMPONENT itab-fnam OF STRUCTURE wa_inventory TO <fs>.
<fs> = itab_fval.
ELSEIF itab-fnam CS 'INVENTORYX'.
ASSIGN COMPONENT itab_fnam OF STRUCTURE wa_inventoryx TO <fs>.
<fs> = itab_fval.
ELSE.
MESSAGE.
ENDIF.
AT END OF subnumber.
DATA: wa_companycode LIKE anla-bukrs,
wa_asset LIKE anla-anln1,
wa_subnumber LIKE anla-anln2.
CALL FUNCTION 'BAPI_FIXEDASSET_CHANGE'
EXPORTING
companycode = wa_companycode
asset = wa_asset
subnumber = wa_subnumber
inventory = wa_inventory
inventoryx = wa_inventoryx
timedependentdata = wa_timedepentdata
timedependentdatax = wa_timedepentdatax
IMPORTING
return = wa_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDLOOP.
Code: Alles auswählen.
TABLES: anla.
DATA: wa_timedepentdata TYPE bapi1022_feglg003,
wa_timedepentdatax TYPE bapi1022_feglg003x,
wa_inventory TYPE bapi1022_feglg011,
wa_inventoryx TYPE bapi1022_feglg011x.
DATA: wa_return TYPE bapiret2.
PARAMETERS: datei(40) TYPE c.
DATA: BEGIN OF itab_anlaginv OCCURS 10,
bukrs LIKE anla-bukrs,
anhaupt LIKE anla-anln1,
anunter LIKE anla-anln2,
timedepentdata LIKE bapi1022_feglg003,
timedepentdatax LIKE bapi1022_feglg003x,
inventory LIKE bapi1022_feglg011,
inventoryx LIKE bapi1022_feglg011x,
END OF itab_anlaginv.
DATA: wa_anlaginv LIKE LINE OF itab_anlaginv.
DATA: itab_fval LIKE TABLE OF wa_anlaginv.
FIELD-SYMBOLS <fs> TYPE ANY.
LOOP AT itab_anlaginv INTO wa_anlaginv.
AT NEW anunter.
ENDAT.
IF itab_anlaginv CS 'TIMEDEPENTDATA'.
ASSIGN COMPONENT itab_anlaginv OF STRUCTURE wa_timedepentdata TO
<fs>.
<fs> = itab_fval.
ELSEIF itab_anlaginv CS 'TIMEDEPENTDATAX'.
ASSIGN COMPONENT itab_anlaginv OF STRUCTURE wa_timedepentdatax TO
<fs>.
<fs> = itab_fval.
ELSEIF itab_anlaginv CS 'INVENTORY'.
ASSIGN COMPONENT itab_anlaginv OF STRUCTURE wa_inventory TO <fs>.
<fs> = itab_fval.
ELSEIF itab_anlaginv CS 'INVENTORYX'.
ASSIGN COMPONENT itab_anlaginv OF STRUCTURE wa_inventoryx TO <fs>.
<fs> = itab_fval.
ELSE.
MESSAGE e393(01).
* Fehler beim Starten des Textabgleichs
ENDIF.
AT END OF anunter.
Code: Alles auswählen.
DATA: BEGIN OF itab_anlaginv OCCURS 10,
bukrs LIKE anla-bukrs,
anhaupt LIKE anla-anln1,
anunter LIKE anla-anln2,
* timedependentdata LIKE bapi1022_feglg003,
* timedependentdatax LIKE bapi1022_feglg003x,
* inventory LIKE bapi1022_feglg011,
* inventoryx LIKE bapi1022_feglg011x,
END OF itab_anlaginv.
Du hast also eine durch Semikolon getrennte Datei, die pro Zeile je fünf Spalten hat.robin1at hat geschrieben: Hoffe mein Problem ist jetzt klarer und Ihr könnt mir weiterhelfen.
Code: Alles auswählen.
ASSIGN COMPONENT itab_anlaginv OF STRUCTURE wa_timedepentdata TO
<fs>.
Code: Alles auswählen.
ASSIGN COMPONENT 'ITAB_ANLAGINV' OF STRUCTURE wa_timedepentdata TO
<fs>.
Code: Alles auswählen.
REPORT z_anlaginv.
TABLES: anla.
DATA: wa_timedepentdata TYPE bapi1022_feglg003,
wa_timedepentdatax TYPE bapi1022_feglg003x,
wa_inventory TYPE bapi1022_feglg011,
wa_inventoryx TYPE bapi1022_feglg011x.
DATA: wa_return TYPE bapiret2.
PARAMETERS: p_datei(40) TYPE c.
DATA: BEGIN OF itab_anlaginv OCCURS 10,
bukrs LIKE anla-bukrs,
anhaupt LIKE anla-anln1,
anunter LIKE anla-anln2,
feldname(60),
feldwert(60),
END OF itab_anlaginv.
DATA: BEGIN OF wa_gw_alt,
bukrs LIKE anla-bukrs,
anhaupt LIKE anla-anln1,
anunter LIKE anla-anln2,
END OF wa_gw_alt.
DATA: wa_gw_neu LIKE wa_gw_alt.
DATA: wa_anlaginv LIKE LINE OF itab_anlaginv.
DATA: upload TYPE string.
DATA: wa_companycode LIKE anla-bukrs,
wa_asset LIKE anla-anln1,
wa_subnumber LIKE anla-anln2.
DATA: itab_fval LIKE TABLE OF wa_anlaginv.
FIELD-SYMBOLS <fs> TYPE ANY.
START-OF-SELECTION.
*###################
upload = p_datei.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = upload
filetype = 'ASC'
TABLES
data_tab = itab_anlaginv
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.
MESSAGE i040(/sapdmc/lsmw_glo_010).
* Fehler beim Upload der Datei
ENDIF.
SORT itab_anlaginv BY bukrs anhaupt anunter.
LOOP AT itab_anlaginv INTO wa_anlaginv.
MOVE-CORRESPONDING wa_anlaginv TO wa_gw_neu.
IF wa_gw_neu <> wa_gw_alt
AND NOT wa_gw_neu IS INITIAL.
CALL FUNCTION 'BAPI_FIXEDASSET_CHANGE'
EXPORTING
companycode = wa_companycode
asset = wa_asset
subnumber = wa_subnumber
inventory = wa_inventory
inventoryx = wa_inventoryx
timedependentdata = wa_timedepentdata
timedependentdatax = wa_timedepentdatax
IMPORTING
return = wa_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
IF itab_anlaginv CS 'TIMEDEPENTDATA'.
ASSIGN COMPONENT itab_anlaginv OF STRUCTURE wa_timedepentdata TO
<fs>.
<fs> = itab_fval.
ELSEIF itab_anlaginv CS 'TIMEDEPENTDATAX'.
ASSIGN COMPONENT itab_anlaginv OF STRUCTURE wa_timedepentdatax TO
<fs>.
<fs> = itab_fval.
ELSEIF itab_anlaginv CS 'INVENTORY'.
ASSIGN COMPONENT itab_anlaginv OF STRUCTURE wa_inventory TO <fs>.
<fs> = itab_fval.
ELSEIF itab_anlaginv CS 'INVENTORYX'.
ASSIGN COMPONENT itab_anlaginv OF STRUCTURE wa_inventoryx TO <fs>.
<fs> = itab_fval.
ELSE.
MESSAGE e393(01).
* Fehler beim Starten des Textabgleichs
ENDIF.
ELSE.
IF itab_anlaginv CS 'TIMEDEPENTDATA'.
ASSIGN COMPONENT itab_anlaginv OF STRUCTURE wa_timedepentdata TO
<fs>.
<fs> = itab_fval.
ELSEIF itab_anlaginv CS 'TIMEDEPENTDATAX'.
ASSIGN COMPONENT itab_anlaginv OF STRUCTURE wa_timedepentdatax TO
<fs>.
<fs> = itab_fval.
ELSEIF itab_anlaginv CS 'INVENTORY'.
ASSIGN COMPONENT itab_anlaginv OF STRUCTURE wa_inventory TO <fs>.
<fs> = itab_fval.
ELSEIF itab_anlaginv CS 'INVENTORYX'.
ASSIGN COMPONENT itab_anlaginv OF STRUCTURE wa_inventoryx TO <fs>.
<fs> = itab_fval.
ELSE.
MESSAGE e393(01).
* Fehler beim Starten des Textabgleichs
ENDIF.
ENDIF.
wa_gw_alt = wa_gw_neu.
ENDLOOP.
CALL FUNCTION 'BAPI_FIXEDASSET_CHANGE'
EXPORTING
companycode = wa_companycode
asset = wa_asset
subnumber = wa_subnumber
inventory = wa_inventory
inventoryx = wa_inventoryx
timedependentdata = wa_timedepentdata
timedependentdatax = wa_timedepentdatax
IMPORTING
return = wa_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
Code: Alles auswählen.
DATA: BEGIN OF itab_anlaginv OCCURS 10,
bukrs LIKE anla-bukrs,
anhaupt LIKE anla-anln1,
anunter LIKE anla-anln2,
feldname(60),
feldwert(60),
END OF itab_anlaginv.
*** Neue Tabelle
TYPES: BEGIN OF t_file,
line(255) type c,
END OF t_file.
DATA: gt_file TYPE TABLE OF t_file,
gw_fiel TYPE t_file.
*** File in die neue Tabelle laden
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = upload
filetype = 'ASC'
TABLES
* data_tab = itab_anlaginv
data_tab = gt_file
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.
MESSAGE i040(/sapdmc/lsmw_glo_010).
* Fehler beim Upload der Datei
ENDIF.
*** Jetzt jede Zeile in einzelne Felder splitten
LOOP AT gt_file INTO gw_file.
SPLIT gw_file AT ';' INTO itab_anlaginv-bukrs
itab_anlaginv-anhaupt
itab_anlaginv-anunter
itab_anlaginv-feldname
itab_anlaginv-feldwert.
* Gesplitte Tabzeile übernehmen
APPEND itab_anlaginv.
ENDLOOP.
* Das brauchst du nur wenn das file noch nicht sortiert ist
SORT itab_anlaginv BY bukrs anhaupt anunter.
* Dann einen LOOP über die itab_anlaginv.
LOOP AT itab_anlaginv.
AT NEW anhaupt.
* Hier die Daten für das BAPI refreschen/clearen
ENDAT.
* Hier die Daten für das Bapi aufbauen. z.B. mit Case
AT end of anhaupt.
* Hier das BAPI aufrufen um die Daten zuverarbeiten
ENDAT.
ENDLOOP.