SAP-File Transfer Techniques-Interview Questions With Answers - 2.


6. What Are The Various Opening Modes In OPEN DATASET Statement/Syntax?

The various opening modes in OPEN DATASET Statement are:

Use the ‘FOR’ options to specify the access mode.
  • FOR INPUT (Default) – Opens an existing file for reading.
  • FOR OUTPUT – Opens a file for writing. If the file does not exist, it is created.  If the file already exists, its contents are deleted.
  • FOR APPENDING – Opens a file for writing. If the file does not exist, it is created.  If the file already exists, the system goes to the end of the file to add to it.

Use the ‘IN’ options to specify the structure of the file.
  • IN BINARY MODE (Default) – Indicates that the file is not structured in lines (i.e., it is set up byte-by-byte).
  • IN TEXT MODE – Indicates that the file is structured in lines.
  • AT POSITION - To open a file at specific position.


7. What Is The Difference Between Opening A Sequential File In Text Mode & Binary Mode In Application Server?

To determine whether to open a sequential file ‘IN TEXT MODE’ or ‘IN BINARY MODE’, one need to understand what kind of data is to be saved in the file or we can say how the file is to be structured.
  • If there is a need to save data in the file as records or rows like (saving internal table data), or say If the file is structured in lines (or records), then open the file in ‘TEXT MODE’.
  • If the file is structured byte-by-byte, open the file in ‘IN BINARY MODE’.

These two structure modes affect the processing of sequential files.

With the TRANSFER statement:
  • If you transfer a structure to a file opened ‘IN TEXT MODE’, the whole structure will be transferred and the system will mark the end of the line.  On the next transfer, the system will start at the next line.
  • If you transfer a structure to a file opened ‘IN BINARY MODE’, the whole structure will be transferred.  On the next transfer, the system will start at the next character position.

With the READ DATASET statement:
  • If you read from a file opened ‘IN TEXT MODE’, one record of the file will be read into the structure.  If the record is shorter than the structure, the structure is padded with spaces.  If the record is longer than the structure, the record is truncated.  On the next read, the next record is read into the structure.
  • If you read from a file opened ‘IN BINARY MODE’, the length of the structure determines how many characters are read.  On the next read, the system starts with the next character and again reads as many characters as can fill the structure.


8. What ABAP Statement Is Used To Close A File On The Application Server?  What Statement Is Used To Delete A File On The Application Server?

To close a sequential file on the application server, the ‘CLOSE DATASET’ statement can be used.
The basic syntax of this statement is:

CLOSE DATASET <file_name>.
The field containing the file name specified in the field <file_name> is closed.

If a file is successfully deleted, SY-SUBRC will be 0.

Any sequential file is also implicitly closed:
  • At the end of a program
  • When a screen changes

To delete a sequential file on the application server, the ‘DELETE DATASET’ statement can be used.
The basic syntax of this statement is:

DELETE DATASET <file_name>.
The field containing the file name specified in the field <file_name> is deleted.

If a file is successfully deleted, SY-SUBRC will be 0.


9. What ABAP Statement Is Used To Write A Record To A File On The Application Server?

To write to a sequential file on the application server, the ‘TRANSFER’ statement can be used.

The basic syntax of this statement is:
TRANSFER <data> TO <file_name>.

The <data> is the data object that is transferred to the file, either as a record or character-by-character. <data> can be a field, a string, or a structure.

If <data>is a deep structure or a reference, a syntax error occurs. An error on the transfer results in an abnormal termination of the program.


10. What ABAP Statement Is Used To Read A Record From A File On The Application Server?

To read a sequential file on the application server, the ‘READ DATASET’ statement can be used.

The basic syntax of this statement is:
READ DATASET <file_name> INTO <data>.

This statement imports a record from a sequential file whose index and name are specified in <file_name> into the data object <data>.
  • <file_name> can be a field or literal containing the file name.
  • <data> can be a field, a string, a structure, or a flat structure.

A syntax error is triggered if f is defined as a deep structure, table, or reference.

If the file is set up in lines, a record of the file is read into the <data>.
  • If the record is longer than the <data>, the record is truncated.
  • If the record is shorter than the <data>, the <data> is padded with spaces.
  • On the next read, the next record is read into the <data>.

If the file is not set up in lines, the length of the <data> determines how many characters are read from the file. On the next read, the system starts with the next character and again reads as many characters as can fill the <data>.

If a record (or character) is found, SY-SUBRC is set to 0.  If a record (or character) is not found (i.e., the end of the file was reached on the last read), SY-SUBRC is set to 4.