Friday, November 8, 2013

Simple program to demonstrate the file creation in Abap




/* Declarations                */

PARAMETERSpar_file(255TYPE c.

TABLES LIKP.

DATA: D_MSG_TEXT(50),

            Wa_likp type likp.

             It_likp type table of likp.



/* Program       */

SELECT FROM LIKP INTO TABLE IT_likp UP TO ROWS.



OPEN DATASET par_file FOR OUTPUT IN LEGACY TEXT MODE code page '1100' .

IF Sy-subrc EQ 0.

LOOP AT IT_likp.
WRITE/ IT_likp-vbelnint_vbak-ernam.
TRANSFER IT_likp TO par_file.

ENDLOOP.



Close Dataset par_file.


ENDIF.



The Key thing used in file transmission programs are the keywords OPEN DATASET, TRANSFER,CLOSE DATASET. Even though the program will work without the close dataset, its considered as a best practice to write the code as it would close the resources allocated for the transfer operation. There are variants available for OPEN DATASET. The information is available in information section in SAP.One more thing to be considered, is the importance of using the sy-subrc check after checking the open dataset command.This helps us to understand whether it has been successful in establishing the connection to the concerned path and whether the file path is correct.The file mentioned here, which is ‘par_file’ should not be used file name, but the entire file path including file name and extension.

No comments:

Post a Comment