2009 Apr 15 4:15 PM
Hello,
I have two different files, which I want to read in a structure one after another. Later I have to distinguish which entry is from which file.
First I thought I can use function READ DATASET dsn INTO f for that purpose. But it seems that you have to use the same structures in this case, but then I have no differentiating factor within my structure.
I think there must be an easy way to do what. Unfortanately, I have not found something so far.
Does anyone has an idea? Thanks.
Regards,
Tobias
2009 Apr 15 4:28 PM
Hi
U can use different structure as workarea for reading file, anyway you know which kind file you're reading in order to know which structure has to be used.
Usually there's a symbol or a sign at the beginning of the file in order to define the kind of file
* Open file:
OPEN DATASET <FILE> ..........
IF SY-SUBRC = 0.
* Check first record
READ DATASET <FILE> INTO F.
* Suppose the first four characters indicate the kind of file
IF F(4) = 'HEAD'.
FL_KIND = 'H'. "<-------Header
ELSE.
FL_KIND = 'I'. "<--------Item
ENDIF.
IF FL_KIND = 'H'.
H = F.
ELSE.
I = F.
ENDIF.
* Read the next record
DO.
READ DATASET <FILE> INTO F.
IF FL_KIND = 'H'.
H = F.
ELSE.
I = F.
ENDIF.
ENDDO.This is only a sample we should know how your files are and when u read them.
Max
Hello,
I have two different files, which I want to read in a structure one after another. Later I have to distinguish which entry is from which file.
First I thought I can use function READ DATASET dsn INTO f for that purpose. But it seems that you have to use the same structures in this case, but then I have no differentiating factor within my structure.
I think there must be an easy way to do what. Unfortanately, I have not found something so far.
Does anyone has an idea? Thanks.
Regards,
Tobias
2009 Apr 15 4:27 PM
hi Tobias,
if you have to differentiate later you entries anyway, why cant you use 2 different structures at first.
read datased 1 into f1
read dataset 2 into f2
and now you can move them to internal tables or structures with some differentiating flag.
Regards,
MaryM
2009 Apr 15 4:28 PM
Hi
U can use different structure as workarea for reading file, anyway you know which kind file you're reading in order to know which structure has to be used.
Usually there's a symbol or a sign at the beginning of the file in order to define the kind of file
* Open file:
OPEN DATASET <FILE> ..........
IF SY-SUBRC = 0.
* Check first record
READ DATASET <FILE> INTO F.
* Suppose the first four characters indicate the kind of file
IF F(4) = 'HEAD'.
FL_KIND = 'H'. "<-------Header
ELSE.
FL_KIND = 'I'. "<--------Item
ENDIF.
IF FL_KIND = 'H'.
H = F.
ELSE.
I = F.
ENDIF.
* Read the next record
DO.
READ DATASET <FILE> INTO F.
IF FL_KIND = 'H'.
H = F.
ELSE.
I = F.
ENDIF.
ENDDO.This is only a sample we should know how your files are and when u read them.
Max
2009 Apr 17 12:58 PM
OK, MaryM`s idea was simple and good. Thank you.
But anyway I am interested if it would be possible to read in two files, which have the following structure
DATE
ISO_CODE
RATE
NOTATION
into a structure (internal table):
DATA: BEGIN OF ITAB OCCURS 1000,
DAT TYPE D,
CUR LIKE TCURR-FCURR,
RATE(16) TYPE C,
NOT(1) TYPE C
FIL(1) TYPE C.
DATA: END OF ITAB.
with the following commands:
DO.
READ DATASET DAT_IN1 INTO ITAB.
move '1' to ITAB-FIL.
ENDDO.
DO.
READ DATASET DAT_IN2 INTO ITAB.
MOVE '2' to ITAB-FIL.
ENDDO.
Thanks again for your help.
Regards,
Tobias
Edited by: Tobias Meiler on Apr 17, 2009 1:58 PM
2009 Apr 17 1:06 PM
Hi,
that should be totally possible.
data: wa like line of itab.
DO.
READ DATASET DAT_IN1 INTO wa.
move '1' to wa-FIL.
append wa to itab.
ENDDO.
DO.
READ DATASET DAT_IN2 INTO ITAB.
MOVE '2' to wa-FIL.
append wa to itab.
ENDDO.
Let us know if it dosen't work.
Regards,
MaryM
2009 Apr 17 1:09 PM
A part of the question is answered but not overall. There is a point I am still interested in.
2009 Apr 17 1:13 PM
Hello,
What i believe is that for the solution u can add one more column in the structure say the Differentiator, and pass some value into it depending upon the file from which it is getting
for eg:
u can pass F1 if it is being read from file one
and F2 if it is being read from file two.
Then you can carry on with the calculation giving the conditions as
if Differentiator = F1
Do sme calculation
else
do the other calculation
Endif.
Regards
Edited by: Richa Wahi on Apr 17, 2009 2:13 PM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |