06-25-2007 5:40 AM
Hi all,
I have to read a file from the application server.The file on application server has a different structure.It has got different types of data in different lines.It has got one line of header data ,then transaction data can be more than one line and the last line of file is having totals record.
I am reading the file using open dataset,read dataset and close dataset.I need to process the transaction data in the file.Please tell how to proceed with this.
Thanks
06-25-2007 5:46 AM
Hi
You have to split the file on application server into different fields of an internal table after opening the file
see the sample code:
OPEN DATASET P_FNAME FOR INPUT IN TEXT MODE.
if sy-subrc ne 0.
write : / 'File could not be uploaded.. Check file name.'.
stop.
endif.
DO.
READ DATASET P_FNAME INTO V_STR.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
SPLIT V_STR AT ' ' INTO itab-F1 itab-F2 itab-F3 itab-F4 itab-F5 .
APPEND itab.
CLEAR itab.
ENDDO.
Reward points for useful Answers
Regards
Anji
06-25-2007 5:50 AM
Hi Anu,
One Possible way i think of is as here:
Read all the data into an internal table declared with type string.
loop at internal table.
Then read inidividual lines from the transaction data till you reach the last line containing totals. To detect this you have to check certain hardcoded words in the file. once you reach the last line of transaction data set a variable having the current line which you can use to read the master data and the transaction data again available in sequential lines one after the other.
Thanks and Regards,
Kunjal patel
06-25-2007 5:53 AM
OPEN DATASET FILENAME1 FOR INPUT IN TEXT MODE.
if sy-subrc eq 0 .
skip.
else .
write 😕 'FILE NOT UPLOADED'. stop.
endif.
do.
read dataset FILENAME1 Into line.
if sy-subrc eq 0.
split line at ';' into itab-bldat
split line at ht into itab-bldat itab-budat
itab-kokrs
itab-skost
itab-eaufn
itab-lstar
itab-lvbsu
itab-amesu.
append itab.
else.
exit.
endif.
enddo.
CLOSE DATASET FILENAME1.
Please reward if useful.
regards.
Message was edited by:
Sachin123
06-25-2007 6:11 AM
hi anu,
u have all the lines of the files now in the internal table and now u want to differentiate the header data and item data,
1)...
to do this u have find some basic deference between item and header data.
now suppose the header data is generally contains more than 50 character in line and item data contains less then 30 so this type of deference u can find out, make sure the characteristics u find must be consistent for all the data possible.
now loop u'r internal table and check the characteristics of line if it satisfy the headerdatas characteristic then treat it like header otherwise its an item data.
2)...
the second aspect is if u'r file have only one header and multiple item data then u can also use this
files first line will always header and after that till the end all the item the u can check header by sy-tabix value is sy-tabix = 1 then it is header other wise it is item data..
use this
becoz it is an logical problem and u and only u can solve it out no buddy can give u a exact solution
i hope it will help u
thanks
by
06-25-2007 6:49 AM
This can be done easily with this logic. You can add a field in application server file with heading serial number. keep the serial number same for related header and item data nad no serial for totals.
After you get the data in internal table. Sort it according to Serial Number and while loop put a check on change of serial number. Like this you will be able to track the header for all items. To track the totals you can check the serial number to be nil.
Reward Points if useful.
Regards
Vijai