Upgrade - Abap Role

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

OPEN DATASET

is to open a file in application server.

We can open a file in application server to READ or WRITE or APPEND data.


FOR OUTPUT: Open a file for writing FOR INPUT: Open an existing file for writing. FOR APPENDING: Open a file for writing at the end of file. IN BINARY MODE : This addition opens the file as a binary file. In this mode, the read and write operation doesnt require interpreting the file contents, the entire data is used in an unchanged form. IN TEXT MODE: This addition opens the file as a text file. AT POSITION: This addition is used for specifying an exact position in bytes to read or write. For an example AT POSITION 10 will skip first 10 bytes in the file and the initial read or write operation will start from this position only. TYPE: This addition is used for specifying further file attributes for passing to the operating system. MESSAGE: This addition is used for storing the system messages like error messages at the time of opening files. FILTER: This addition is for specifying the system commands like compress in UNIX. Points to Remember a. Its always a good practice to use CLOSE DATASET after the processing with the file opened with OPEN DATASET. b. Applying OPEN DATASET to a file already opened - in the same internal mode - triggers an exception of the type CX_SY_FILE_OPEN.

SY-SUBRC = 0: The file was opened. SY-SUBRC = 8: The file could not be opened.

c. To make your programs portable to different operating systems, use the function module FILE_GET_NAME, which returns the system-dependent name for an abstract file name. You can define file names using the transaction FILE.

The system automatically performs an authorization check. If this check fails, a runtime error occurs. You can prevent this by checking the authorization in advance using the function module AUTHORITY_CHECK_DATASET.
DATA: file TYPE string VALUE `test.dat`, result TYPE string. OPEN DATASET file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. TRANSFER `1234567890` TO file. CLOSE DATASET file. OPEN DATASET file FOR UPDATE IN TEXT MODE ENCODING DEFAULT AT POSITION 2. TRANSFER `ABCD` TO file. CLOSE DATASET file. OPEN DATASET file FOR INPUT IN TEXT MODE ENCODING DEFAULT. WHILE sy-subrc = 0. READ DATASET file INTO result. WRITE / result. ENDWHILE. CLOSE DATASET file.

Sap Technical.
REPORT ZDOWNLOAD_APPL_DEMO. TYPES : BEGIN OF ST_DEMO, REG_NO(10) TYPE C, NAME(20) TYPE C, ADDR(20) TYPE C, END OF ST_DEMO. DATA : WA_DEMO TYPE ST_DEMO, IT_DEMO TYPE TABLE OF ST_DEMO, L_FNAME TYPE STRING . PARAMETERS: P_FNAME(128) TYPE C DEFAULT '\usr\sap\SRI\SYS\src\DOWN.TXT' OBLIGATORY. L_FNAME = P_FNAME. WA_DEMO-REG_NO = '100001'. WA_DEMO-NAME = 'ANAND'. WA_DEMO-ADDR = 'NAGARKOVIL'. APPEND WA_DEMO TO IT_DEMO. WA_DEMO-REG_NO = '100002'. WA_DEMO-NAME = 'VIKRAM'. WA_DEMO-ADDR = 'CHENNAI'. APPEND WA_DEMO TO IT_DEMO. OPEN DATASET L_FNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. WRITE :5 'REG NUM',16 'NAME',37 'ADDRESS' . LOOP AT IT_DEMO INTO WA_DEMO. IF SY-SUBRC = 0. TRANSFER WA_DEMO TO L_FNAME. WRITE :/5 WA_DEMO-REG_NO,16 WA_DEMO-NAME,37 WA_DEMO-ADDR. ENDIF. ENDLOOP.

TYPE 2: TYPE X ERRORS: When creating files from within ABAP(SAP) programs it is sometimes necessary to insert Hex codes in-order for the target application software to deal with the file appropriately. For example if you are creating a excel spreadsheet file you will need to insert the hex code for 'TAB' so that excel knows where each new column starts. Type 'X' and 'Xstring' cannot be used in the upgraded version i.e. 6.0. All the Type X data needs to be converted to Character Type. The following table can be checked to see the conversion of hexadecimal data to character type: " ERROR: x_crlf must be a character-like data object (data type C, N, D, T, or STRING). 2.1 Example: DATA: x_crlf(2) TYPE x VALUE '0D0A'. "In 4.6 version The solution for such issues is :
CLASS: cl_abap_char_utilities DEFINITION LOAD. DATA: x_crlf TYPE string, _x_cr TYPE c VALUE cl_abap_char_utilities=>NEWLINE,_ _x_lf type c value cl_abap_char_utilities=>CR_LF._ CONCATENATE x_cr x_lf INTO x_crlf.

You might also like