‎2007 Jun 27 3:06 PM
hi,
what are the modes in sequential files and give brief description.
‎2007 Jun 27 3:08 PM
Hi,
The processing mode can take the following values:
'A' Display screen
'E' Display only if an error occurs
'N' Do not display
'P' Do not display; debugging possible
If the MODE addition is omitted, then the processing mode is 'A'.
If a screen is displayed in processing mode 'E' because the system reached the end of the BDC data, the system automatically switches to processing mode 'A'.
If breakpoints are set in a transaction tcod called using the CALL TRANSACTION tcod USING itab variant, these are not actually reached in 'N' mode. The system tries to insert data in the Debugger screen; the call ends with SY-SUBRC = 1001 and the message "Batch input data is not available for screen SAPMSSY3 0131" (S 00 344).
Conversely, in 'P' mode, transaction screens are processed in the background (as in 'N' mode) and debugging is possible.
The update mode f specifies the type of update. It can take the following values:
'A' (asynchronous update)
'S' (ssynchronous update)
'L' (local update)
If the UPDATE addition is omitted, the update mode is 'A'.
Regards
Sudheer
‎2007 Jun 27 3:10 PM
Hi
OPEN dataset
READ
TRANSFER
CLOSE
see the sample code
ABAP code for uploading a TAB delimited file into an internal table. See code below for structures.
&----
*& Report ZUPLOADTAB *
*& *
&----
*& Example of Uploading tab delimited file *
*& *
&----
REPORT zuploadtab .
PARAMETERS: p_infile LIKE rlgrap-filename
OBLIGATORY DEFAULT '/usr/sap/'..
DATA: ld_file LIKE rlgrap-filename.
*Internal tabe to store upload data
TYPES: BEGIN OF t_record,
name1 like pa0002-VORNA,
name2 like pa0002-name2,
age type i,
END OF t_record.
DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,
wa_record TYPE t_record.
*Text version of data table
TYPES: begin of t_uploadtxt,
name1(10) type c,
name2(15) type c,
age(5) type c,
end of t_uploadtxt.
DATA: wa_uploadtxt TYPE t_uploadtxt.
*String value to data in initially.
DATA: wa_string(255) type c.
constants: con_tab TYPE x VALUE '09'.
*If you have Unicode check active in program attributes then you will
*need to declare constants as follows:
*class cl_abap_char_utilities definition load.
*constants:
con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.
************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
ld_file = p_infile.
OPEN DATASET ld_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
ELSE.
DO.
CLEAR: wa_string, wa_uploadtxt.
READ DATASET ld_file INTO wa_string.
IF sy-subrc NE 0.
EXIT.
ELSE.
SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1
wa_uploadtxt-name2
wa_uploadtxt-age.
MOVE-CORRESPONDING wa_uploadtxt TO wa_upload.
APPEND wa_upload TO it_record.
ENDIF.
ENDDO.
CLOSE DATASET ld_file.
ENDIF.
************************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
*!! Text data is now contained within the internal table IT_RECORD
Display report data for illustration purposes
loop at it_record into wa_record.
write:/ sy-vline,
(10) wa_record-name1, sy-vline,
(10) wa_record-name2, sy-vline,
(10) wa_record-age, sy-vline.
endloop.
Reward points for useful Answers
Regards
Anji
‎2007 Jun 27 3:17 PM
‎2007 Jun 27 3:23 PM
‎2007 Jun 27 3:24 PM
Hi Naveen,
To perform any operations like read, write on Application Server. Sequential files are stored in Application Server and You can see them using AL11 transaction.
In ABAP, there is a range of statements for processing data that is stored in sequential files on the application server instead of the database.
These are the modes of operation you can perform on Sequential files:
· OPEN DATASET
opens a file for a particular type of access and storage.· TRANSFER
transfers the contents of a data object to a file.· READ DATASET
transfers data from a file to a data object.· GET DATASET
using the addition POSITION the current position of the file pointer in a file is ascertained. Using the addition ATTRIBUTES further characteristics of the file are obtained.· SET DATASET
using the addition POSITION the position of the file pointer is specified. Using the addition ATTRIBUTES further characteristics of the file can be specified.· TRUNCATE DATASET
sets the end of a file to a specified value, thereby changing the size of the file.· CLOSE DATASET
closes a file.· DELETE DATASET
deletes a file.Thanks,
Vinay
‎2007 Jun 27 3:12 PM
Binary mode (addition IN BINARY MODE in the OPEN DATASET statement:
Read from file in length of field f.
Text mode (addition IN TEXT MODE in the OPEN DATASET statement):
Read a line.
BINARY MODE: The READ or TRANSFER will be character wise. Each time n characters are READ or transferred. The next READ or TRANSFER will start from the next character position and not on the next line.
IN TEXT MODE: The READ or TRANSFER will start at the beginning of a new line each time. If for READ, the destination is shorter than the source, it gets truncated. If destination is longer, then it is padded with spaces.
Defaults: If nothing is mentioned, then defaults are FOR INPUT and in BINARY MODE.
Thanks
Seshu
‎2007 Jun 27 3:12 PM
Hi,
There are 2 modes:
1. Text mode
2. Binary mode
Using Text Mode
To open a file in text mode, use the IN TEXT MODE addition to the OPEN DATASET statement.
Syntax
OPEN DATASET <dsn> FOR .... IN TEXT MODE.
If you read from or write to a file that is open in text mode, the data is transferred line by line. The system assumes that the file has a line structure.
In each TRANSFER statement, the system transfers all bytes (apart from spaces at the end) into the file, and places an end of line marker at the end. For information about the TRANSFER statement, refer to Writing Data to Files.
In each READ DATASET statement, the system reads all of the data up to the next end of line marker. For information about the READ DATASET statement, refer to Reading Data from Files. If the target field is too small, the line is truncated. If it is longer than the line in the file, it is filled with trailing spaces.
You should always use text mode if you want to write strings to files or where you know that an existing file has a line construction. You can, for example, use text mode to read files that you have created using any editor on your application server.
The following example works in R/3 Systems that are running on UNIX systems using ASCII.
DATA FNAME(60) VALUE 'myfile'.
DATA: TEXT(4),
HEX TYPE X.
OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE.
TRANSFER '12 ' TO FNAME.
TRANSFER '123456 9 ' TO FNAME.
TRANSFER '1234 ' TO FNAME.
OPEN DATASET FNAME FOR INPUT IN TEXT MODE.
READ DATASET FNAME INTO TEXT.
WRITE / TEXT.
READ DATASET FNAME INTO TEXT.
WRITE TEXT.
READ DATASET FNAME INTO TEXT.
WRITE TEXT.
OPEN DATASET FNAME FOR INPUT IN BINARY MODE.
SKIP.
DO.
READ DATASET FNAME INTO HEX.
If SY-SUBRC <> 0.
EXIT.
ENDIF.
WRITE HEX.
ENDDO.
The output appears as follows:
12 1234 1234
31 32 0A 31 32 33 34 35 36 20 20 39 0A 31 32 33 34 0A
This example opens a file "myfile" for writing in text mode. Three literals with length 10 characters are written to it. After the file has been opened for reading in text mode, the lines are read into the field TEXT (length 4). The first line is filled with two trailing spaces. The last five characters of the second line are truncated. The structure of the file is displayed by opening it in binary mode and reading its contents into the hexadecimal field HEX. The numbers 31 - 36 are the ASCII codes for the digits 1 - 6. 20 is the code for the space character. The end of each line is marked by 0A. Note that any spaces at the end of strings are not written to the file.
Using Binary Mode
To open a file in binary mode, use the IN BINARY MODE addition to the OPEN DATASET statement.
Syntax
OPEN DATASET <dsn> IN BINARY MODE [FOR ....].
If you read from or write to a file that is open in binary mode, the data is transferred byte by byte. The system does not interpret the contents of the file while it is being transferred. If you write the contents of a field to a file, the system transfers all of the bytes in the source field. When you transfer data from a file to a field, the number of bytes transferred depends on the length of the target field. If you then use another ABAP statement to address the target field, the system interprets the field contents according to the data type of the field.
DATA FNAME(60) VALUE 'myfile'.
DATA: NUM1 TYPE I,
NUM2 TYPE I,
TEXT1(4) TYPE C,
TEXT2(8) TYPE C,
HEX TYPE X.
OPEN DATASET FNAME FOR OUTPUT IN BINARY MODE.
NUM1 = 111.
TEXT1 = 'TEXT'.
TRANSFER NUM1 TO FNAME.
TRANSFER TEXT1 TO FNAME.
OPEN DATASET FNAME FOR INPUT IN BINARY MODE.
READ DATASET FNAME INTO TEXT2.
WRITE / TEXT2.
OPEN DATASET FNAME FOR INPUT IN BINARY MODE.
READ DATASET FNAME INTO NUM2.
WRITE / NUM2.
OPEN DATASET FNAME FOR INPUT IN BINARY MODE.
SKIP.
DO.
READ DATASET FNAME INTO HEX.
If SY-SUBRC <> 0.
EXIT.
ENDIF.
WRITE HEX.
ENDDO.
The output appears as follows:
###oTEXT
111
00 00 00 6F 54 45 58 54
The program opens the file "myfile" in binary mode and writes the contents of the fields NUM1 and TEXT1 into the file. For information about the TRANSFER statement, refer to Writing Data to Files. The file is then opened for reading, and its entire contents are read into the field TEXT2. For information about the READ DATASET statement, refer to Reading Data from Files. The first four characters of the string TEXT2 are nonsense, since the corresponding bytes are the platform-specific representation of the number 111. The system tries to interpret all of the bytes as characters. However, this only works for the last four bytes. After the OPEN statement, the position is reset to the start of the file, and the first four bytes of the file are transferred into NUM2. The value of NUM2 is correct, since it has the same data type as NUM1. Finally, the eight bytes of the file are read into the field HEX. On the screen, you can see the hexadecimal representation of the file contents. The last four bytes are the ASCII representation of the characters in the word "TEXT".
Regards,
Bhaskar
‎2007 Jun 27 3:13 PM
Hi Naveen,
Handling of Sequential file
Three steps are involved in sequential file handling
<b> OPEN
PROCESS
CLOSE</b>
<b>OPEN:</b>
OPEN DATASET <file name> FOR {OUTPUT/INPUT/APPENDING}
IN {TEXT/BINARY} MODE
<b>PROCESS:</b>
TRANSFER <field> TO <file name>.
<Field> can also be a field string / work area / DDIC structure
READ DATASET <file name> INTO <field>.
<Field> can also be a field string / work area / DDIC structure.
<b>CLOSE:</b>
CLOSE DATASET <file name>.
Thanks,
Vinay