A real life example for using a temporary program

REPORT CHAP2503.* Variables for later usePARAMETERS TABNAME(10) DEFAULT ‘CUSTOMERS’.DATA: SOURCE_TABLE(72) OCCURS 100 WITH HEADER LINE,PROGRAM_NAME LIKE SY-CPROG,SYNTAX_CHECK_MESSAGE(128),LINE_NO TYPE I.* Building the source code PERFORM BUILD_THE_SOURCE_CODE USING TABNAME.* Generating the temporary program, checking syntax errorsGENERATE SUBROUTINE POOL SOURCE_TABLENAME PROGRAM_NAMEMESSAGE SYNTAX_CHECK_MESSAGELINE LINE_NO.IF SY-SUBRC NE 0.WRITE: / ‘Syntax error, message’, SYNTAX_CHECK_MESSAGE,/ ‘in line’, LINE_NO.EXIT.ENDIF.* Calling a form externallyPERFORM … Read more

Sample program for generating a persistent program

*&———————————————————————*REPORT CHAP2504.* Internal table for source code, field for name of temporary programDATA: SOURCE_TABLE(72) OCCURS 10 WITH HEADER LINE,PROGRAM_NAME LIKE SY-CPROG.* Building the source codeAPPEND ‘report zgenprog.’ TO SOURCE_TABLE.APPEND ‘write ”I am a generated program”.’ TO SOURCE_TABLE.* Insert the report, if necessaryREAD REPORT ‘zgenprog’ INTO SOURCE_TABLE.IF SY-SUBRC NE 0.APPEND ‘report zgenprog.’ TO SOURCE_TABLE.APPEND ‘write ”Here … Read more

Sample ABAP program for Transferring data to a file

REPORT CHAP2601.* Data declarations for later usePARAMETERS FILENAME(128) DEFAULT ‘/usr/tmp/testfile.dat’LOWER CASE.TABLES CUSTOMERS.DATA MSG_TEXT(50).* Get data for file transferDATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100WITH HEADER LINE.SELECT * FROM CUSTOMERS INTO TABLE ALL_CUSTOMERS.SORT ALL_CUSTOMERS BY CITY.LOOP AT ALL_CUSTOMERS.WRITE: / ALL_CUSTOMERS-CITY,ALL_CUSTOMERS-NAME.ENDLOOP.* Opening the FileOPEN DATASET FILENAME FOR OUTPUT IN TEXT MODEMESSAGE MSG_TEXT.IF SY-SUBRC NE 0.WRITE: ‘File cannot be … Read more

Sample ABAP program for Reading data from a file

REPORT CHAP2602.* Data declarations for later useTABLES CUSTOMERS.PARAMETERS FILENAME(128) DEFAULT ‘/usr/tmp/testfile.dat’LOWER CASE.DATA: MSG_TEXT(50),ALL_CUSTOMER_NAMES LIKE CUSTOMERS-NAME OCCURS 100WITH HEADER LINE. * Opening the FileOPEN DATASET FILENAME FOR INPUT IN TEXT MODEMESSAGE MSG_TEXT.IF SY-SUBRC NE 0.WRITE: ‘File cannot be opened. Reason:’, MSG_TEXT.EXIT.ENDIF.* Reading DataDO.READ DATASET FILENAME INTO ALL_CUSTOMER_NAMES.IF SY-SUBRC NE 0.EXIT.ENDIF.APPEND ALL_CUSTOMER_NAMES.ENDDO.* Closing the fileCLOSE DATASET FILENAME.* … Read more

Abap code for Transferring data to a file (presentation server)

REPORT CHAP2603.* Data declarations for later usePARAMETERS FILENAME(128) DEFAULT ‘c:usersdefaulttestfile.dat’LOWER CASE.TABLES CUSTOMERS.DATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100WITH HEADER LINE.* Get data for file transferSELECT * FROM CUSTOMERS INTO TABLE ALL_CUSTOMERS.SORT ALL_CUSTOMERS BY CITY.LOOP AT ALL_CUSTOMERS.WRITE: / ALL_CUSTOMERS-CITY,ALL_CUSTOMERS-NAME.ENDLOOP.* Transferring DataCALL FUNCTION ‘WS_DOWNLOAD’EXPORTINGFILENAME = FILENAMETABLESDATA_TAB = ALL_CUSTOMERSEXCEPTIONSFILE_OPEN_ERROR = 1OTHERS = 2.CASE SY-SUBRC.WHEN 1.WRITE ‘Error when file opened’.EXIT.WHEN … Read more