REPORT ZTRHORSE.
*
* This program is the Trojan horse of Agamemnon sitting in
* system B. It receives the source code of an abap program
* from Zagamemn from system A, creates the abap in
* system B, runs it, reads the result from the memory
* and sends it back to Agamemnon using CPIC. 
*
*
DATA: CONV(8), INPUT(100), DINF(4), SINF(4) TYPE X,
      RLEN(4) TYPE X, SLEN(4) TYPE X, A(100).
DATA: PROGRAM LIKE SY-REPID VALUE 'ZREMABAP',
      BEGIN OF T OCCURS 500,
        LINE(72),
      END   OF T.
DATA: BEGIN OF TAB OCCURS 10.
        INCLUDE STRUCTURE ABAPLIST.
DATA: END OF TAB.
DATA: BEGIN OF LISTASCI OCCURS 10,
        LINE(72),
END OF LISTASCI.

EXIT.

*---------------------------------------------------------------------*
*       FORM ZTRHORSE                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM ZTRHORSE.
* Accept allocate
  COMMUNICATION ACCEPT ID CONV.
  IF SY-SUBRC <> 0. EXIT. ENDIF.
* Receive abap
  SINF = 0.
  WHILE SINF = 0.
    COMMUNICATION RECEIVE ID CONV
      BUFFER INPUT
      DATAINFO DINF
      STATUSINFO SINF
      RECEIVED RLEN.
    IF SY-SUBRC <> 0. EXIT. ENDIF.
    T = INPUT.
    APPEND T.
  ENDWHILE.
* Create and run abap
  INSERT REPORT PROGRAM FROM T.
  SUBMIT (PROGRAM) EXPORTING LIST TO MEMORY AND RETURN.
  CALL FUNCTION 'LIST_FROM_MEMORY'
       TABLES
            LISTOBJECT = TAB.
  CALL FUNCTION 'LIST_TO_ASCI'
       TABLES
            LISTASCI   = LISTASCI
            LISTOBJECT = TAB.
* Send back the result
LOOP AT LISTASCI.
  A = LISTASCI. SLEN = 72.
  COMMUNICATION SEND ID CONV BUFFER A LENGTH SLEN.
  IF SY-SUBRC <> 0. COMMUNICATION DEALLOCATE ID CONV. EXIT. ENDIF.
ENDLOOP.
* Wait for delallocation
  SINF = 0.
  WHILE SINF = 0.
    COMMUNICATION RECEIVE ID CONV
      BUFFER INPUT
      DATAINFO DINF
      STATUSINFO SINF
      RECEIVED RLEN.
    IF SY-SUBRC <> 0. EXIT. ENDIF.
  ENDWHILE.
ENDFORM.