Remotely Attachable ABAP Program 
Prerequisites
To process an external communications request, it is necessary to establish a connection to a service transaction of the SAP Basis system.
In the R/2 System, this connection is established to transaction X1SA (BS2000, CICS) or xxxX1SA (IMS).
In the R/3 System, the connection is established to the SAP dispatcher via the SAP Gateway.
The Service transaction needs a logon sequence to identify the client, the user and the ABAP program. The SAP Basis system then starts the ABAP program. The activated ABAP program must be executable (type 1 or M) and have at least one FORM routine.
This logon is part of the SAP logon protocol CPI-C. If logon is performed incorrectly, the SAP Basis system closes the connection with an appropriate error message.
Procedure
A subroutine (FORM routine), which is specified in the program start request, must be defined in an ABAP program. This routine is triggered automatically. Within the FORM routine, PERFORM can be used to call further subroutines (including external ones) or to establish communications links with other partners.
The main part of an ABAP program is not executed for CPI-C connections. It can therefore contain a different processing logic for normal online operation.
An activated FORM routine can only perform one ACCEPT command, after which it is in receive status.

An ABAP program can contain several such subroutines, which can be accessed via different logon sequences. This allows you to build up a function library for CPI-C processing.
Special Features of ABAP in R/2
If you want to create a remotely attachable ABAP CPI-C program in an R/2 System, you must know that some ABAP key words are not permitted or are processed differently than in normal online operation. This is because no online terminal is available for screen output, as for an update program. You must note the following:
Screen change
A session or screen change cannot be initiated within an SAP system during a
conversation. This means that you cannot call subsequent key words in the remote ABAP program, because this causes the conversation and the program to terminate.TRANSFER
You can use the TRANSFER command to write data to the SAP spool component (from R/2 Release 5.0)
WRITE
The key word WRITE is ignored or redirected to a spool member if the statement NEW-PAGE PRINT ON NO DIALOG is specified first (from R/2 Release 4.3J, 4.4D, 5.0).
BREAK-POINT
The statement BREAK-POINT writes log informatin to the SAP system log (from R/2 Release 4.3J, 4.4D, 5.0).
MESSAGE
Messages of type S, I or W are ignored. Messages of type E or A cause a program termination and an entry in the system log.