2008 Apr 03 6:44 AM
Hi,
My requirement is to generate some records eg. Vendor through XK01 in one report and catch the generated Vendors through open dataset - Close dataset and use them in another diferent report report . if anyone have a sample code or idea about that then plz help me
regards,
Paliwal
2008 Apr 03 6:52 AM
Hi,
To read data from a file on the application server, use the READ DATASET statement
READ DATASET <dsn> INTO <f> [LENGTH <len>].
This statement reads data from the file <dsn> into the variable <f>. In order to determine into which variable you should read data from a file, you need to know the structure of the file.
You can specify the transfer mode in the OPEN DATASET statement. If you have not already opened the file for reading, the system tries to open it either in binary mode, or using the additions from the last OPEN DATASET statement. However, it is good practice only to open files using the OPEN DATASET statement. For further information about the OPEN DATASET statement and the naming conventions for files, refer to Opening a File.
If the system was able to read data successfully, SY-SUBRC is set to 0. When the end of the file is reached, SY-SUBRC is set to 4. If the file could not be opened, SY-SUBRC is set to 8.
If you are working in binary mode, you can use the LENGTH addition to find out the length of the data transferred to <f>. The system sets the value of the variable <len> to this length.
DATA FNAME(60) VALUE 'myfile'.
DATA: TEXT1(12) VALUE 'abcdefghijkl',
TEXT2(5),
LENG TYPE I.
OPEN DATASET FNAME FOR OUTPUT IN BINARY MODE.
TRANSFER TEXT1 TO FNAME.
CLOSE DATASET FNAME.
OPEN DATASET FNAME FOR INPUT IN BINARY MODE.
DO.
READ DATASET FNAME INTO TEXT2 LENGTH LENG.
WRITE: / SY-SUBRC, TEXT2, LENG.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET FNAME.
The output is:
0 abcde 5
0 fghij 5
4 kl### 2
This example fills the file "myfile" with 12 bytes from the field TEXT1. It is then read into the field TEXT2 in 5-byte portions. Note here that the system fills up the last three bytes of TEXT2 with zeros after the end of the file has been reached. The number of bytes transferred is contained in the field LENG.
If you are working in text mode, you can use the LENGTH addition to find out the length of the current line in the file. The system sets the value of the variable <len> to the length of the line. The system calculates this by counting the number of bytes between the current position and the next end of line marker in the file.
DATA FNAME(60) VALUE 'myfile'.
DATA: TEXT1(4) VALUE '1234 ',
TEXT2(8) VALUE '12345678',
TEXT3(2),
LENG TYPE I.
OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE.
TRANSFER: TEXT1 TO FNAME,
TEXT2 TO FNAME.
CLOSE DATASET FNAME.
OPEN DATASET FNAME FOR INPUT IN TEXT MODE.
DO 2 TIMES.
READ DATASET FNAME INTO TEXT3 LENGTH LENG.
WRITE: / TEXT3, LENG.
ENDDO.
CLOSE DATASET FNAME.
The output appears as follows:
12 4
12 8
This example writes the strings TEXT1 and TEXT2 to the file "myfile" in text mode. They are then read into the string TEXT3 (length 2). The amount of memory occupied by the lines is read into the field LENG.
Reward Points if found helpfull..
Cheers,
Chandra Sekhar.
Hi,
My requirement is to generate some records eg. Vendor through XK01 in one report and catch the generated Vendors through open dataset - Close dataset and use them in another diferent report report . if anyone have a sample code or idea about that then plz help me
regards,
Paliwal
2008 Apr 03 6:48 AM
Hi,
open dataset e_file for output in text mode encoding default.
split fldnam at '|' into table it.
*printing the Header line data
loop at t_fieldcat into s_fieldcat.
concatenate txtstr s_fieldcat-seltext_l ',' into txtstr.
endloop.
if txtstr is not initial.
concatenate txtstr 'LastUpdate' into txtstr.
transfer txtstr to e_file.
endif.
*Printing the data
loop at i_tab.
clear txtstr.
loop at t_fieldcat into s_fieldcat.
concatenate 'I_TAB-' s_fieldcat-fieldname into txt.
assign (txt) to <fs>.
xval = <fs>.
if xval ca sy-abcde.
replace all occurrences of ',' in xval with '-' ignoring case.
endif.
if xval na sy-abcde and xval is not initial.
shift xval left deleting leading '0'.
endif.
if s_fieldcat-fieldname+0(5) = 'DATE1' or s_fieldcat-fieldname+0(4) = 'CNT1' or
s_fieldcat-fieldname+0(5) = 'AVLDT'.
concatenate xval+6(2) '/' xval+4(2) '/' xval+0(4) into txt.
xval = txt.
endif.
concatenate txtstr xval ',' into txtstr.
endloop.
transfer txtstr to e_file.
endloop.
close dataset e_file.Regards,
V.Balaji
Reward if Usefull...
2008 Apr 03 6:52 AM
Hi,
To read data from a file on the application server, use the READ DATASET statement
READ DATASET <dsn> INTO <f> [LENGTH <len>].
This statement reads data from the file <dsn> into the variable <f>. In order to determine into which variable you should read data from a file, you need to know the structure of the file.
You can specify the transfer mode in the OPEN DATASET statement. If you have not already opened the file for reading, the system tries to open it either in binary mode, or using the additions from the last OPEN DATASET statement. However, it is good practice only to open files using the OPEN DATASET statement. For further information about the OPEN DATASET statement and the naming conventions for files, refer to Opening a File.
If the system was able to read data successfully, SY-SUBRC is set to 0. When the end of the file is reached, SY-SUBRC is set to 4. If the file could not be opened, SY-SUBRC is set to 8.
If you are working in binary mode, you can use the LENGTH addition to find out the length of the data transferred to <f>. The system sets the value of the variable <len> to this length.
DATA FNAME(60) VALUE 'myfile'.
DATA: TEXT1(12) VALUE 'abcdefghijkl',
TEXT2(5),
LENG TYPE I.
OPEN DATASET FNAME FOR OUTPUT IN BINARY MODE.
TRANSFER TEXT1 TO FNAME.
CLOSE DATASET FNAME.
OPEN DATASET FNAME FOR INPUT IN BINARY MODE.
DO.
READ DATASET FNAME INTO TEXT2 LENGTH LENG.
WRITE: / SY-SUBRC, TEXT2, LENG.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET FNAME.
The output is:
0 abcde 5
0 fghij 5
4 kl### 2
This example fills the file "myfile" with 12 bytes from the field TEXT1. It is then read into the field TEXT2 in 5-byte portions. Note here that the system fills up the last three bytes of TEXT2 with zeros after the end of the file has been reached. The number of bytes transferred is contained in the field LENG.
If you are working in text mode, you can use the LENGTH addition to find out the length of the current line in the file. The system sets the value of the variable <len> to the length of the line. The system calculates this by counting the number of bytes between the current position and the next end of line marker in the file.
DATA FNAME(60) VALUE 'myfile'.
DATA: TEXT1(4) VALUE '1234 ',
TEXT2(8) VALUE '12345678',
TEXT3(2),
LENG TYPE I.
OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE.
TRANSFER: TEXT1 TO FNAME,
TEXT2 TO FNAME.
CLOSE DATASET FNAME.
OPEN DATASET FNAME FOR INPUT IN TEXT MODE.
DO 2 TIMES.
READ DATASET FNAME INTO TEXT3 LENGTH LENG.
WRITE: / TEXT3, LENG.
ENDDO.
CLOSE DATASET FNAME.
The output appears as follows:
12 4
12 8
This example writes the strings TEXT1 and TEXT2 to the file "myfile" in text mode. They are then read into the string TEXT3 (length 2). The amount of memory occupied by the lines is read into the field LENG.
Reward Points if found helpfull..
Cheers,
Chandra Sekhar.