Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

uploading data from application server.....plz correct this code

Former Member
0 Likes
513

hi all,

here i m sending code for uploading data from flatfile in to table .plz check it and modify it

REPORT ZFM_KFZ.

TABLES: ZFM_KFZ.

PARAMETERS: FILEDATA(128) default ''

lower case .

DATA: begin of rec,

filler(300),

end of rec.

DATA : begin of itab occurs 0,

kfznr like zfm_kfz-kfznr,

geraet like zfm_kfz-geraet,

kostentraeger type c,

tuvdatummmyyyy type c ,

asudatummmyyyy type c,

kmstand type c,

reifen type c,

end of itab.

  • -------------------- MAIN

OPEN DATASET FILEDATA FOR INPUT IN TEXT MODE encoding default.

IF sy-subrc ne 0. "### Error opening

WRITE: 'The Input file cannot be opened:',FILEDATA.

EXIT.

ELSEIF sy-subrc = 0.

DO.

READ DATASET FILEDATA INTO rec.

IF sy-subrc <> 0. "### EOF

EXIT.

ELSE.

split rec at ';' into table itab.

append itab.

ENDIF.

ENDDO.

CLOSE DATASET FILEDATA.

ENDIF.

loop at itab.

  • write itab.

CLEAR ZFM_KFZ.

ZFM_KFZ-KFZNR = itab-KFZNR.

ZFM_KFZ-GERAET = itab-GERAET.

ZFM_KFZ-KOSTENTRAEGER = itab-KOSTENTRAEGER.

ZFM_KFZ-TUVDATUMMMYYYY = itab-TUVDATUMMMYYYY.

ZFM_KFZ-ASUDATUMMMYYYY = itab-ASUDATUMMMYYYY.

ZFM_KFZ-REIFEN = itab-REIFEN.

INSERT ZFM_KFZ.

if sy-subrc ne 0.

write: / 'NOT INSERTED '.

endif.

endloop.

3 REPLIES 3
Read only

Former Member
0 Likes
489

nothing wrong in this one ? Are u getting data in proper format ? just check .

split rec at ';' into table itab.

.

Regards

prabhu

Read only

Former Member
0 Likes
489
REPORT ZFM_KFZ.

TABLES: ZFM_KFZ.

PARAMETERS: FILEDATA(128) default ''

lower case .


DATA: begin of rec,
filler(300),
end of rec.

DATA : begin of itab occurs 0,
kfznr like zfm_kfz-kfznr,
geraet like zfm_kfz-geraet,
kostentraeger type c,
tuvdatummmyyyy type c ,
asudatummmyyyy type c,
kmstand type c,
reifen type c,
end of itab.



* -------------------- MAIN

OPEN DATASET FILEDATA FOR INPUT IN TEXT MODE encoding default.
IF sy-subrc ne 0. "### Error opening
WRITE: 'The Input file cannot be opened:',FILEDATA.
EXIT.
ELSEIF sy-subrc = 0.
DO.
READ DATASET FILEDATA INTO rec.
IF sy-subrc <> 0. "### EOF
EXIT.
ELSE.

<b>split rec at ';' into table itab-KFZNR itab-GERAET itab-KOSTENTRAEGER itab-TUVDATUMMMYYYY itab-ASUDATUMMMYYYY itab-REIFEN.</b>

append itab.

ENDIF.
ENDDO.
CLOSE DATASET FILEDATA.
ENDIF.

loop at itab.
* write itab.

CLEAR ZFM_KFZ.
ZFM_KFZ-KFZNR = itab-KFZNR.

ZFM_KFZ-GERAET = itab-GERAET.

ZFM_KFZ-KOSTENTRAEGER = itab-KOSTENTRAEGER.

ZFM_KFZ-TUVDATUMMMYYYY = itab-TUVDATUMMMYYYY.

ZFM_KFZ-ASUDATUMMMYYYY = itab-ASUDATUMMMYYYY.

ZFM_KFZ-REIFEN = itab-REIFEN.
<b>modify ZFM_KFZ from ZFM_KFZ.</b>
if sy-subrc ne 0.
write: / 'NOT INSERTED '.
endif.

endloop.

Reward if it helps...

Regards

Ashok P

Read only

Former Member
0 Likes
489

split rec at ';' into table itab.

the above statement is not going to insert the values of rec into respective fields of itab. Please see F1 help for documentation.

Suppose your REC has record

1000;1001;1002;.

Then itab will contain.

Record1: 1000

record2: 1001

record3: 1002

instead of Record1: 1000 1001 1002.

So dont use this option instead direclty use the field names of itab.

SPLIT REC AT ';' into itab-kfznr itab-geraet etc etc.

apppend itab.