*
* This program attempts to locate the C program calls SAP is
* using, and list them without repeating them (not perfect)
* Then we can use these practical C calls in our own codes as well.
* Run it in batch! 
*
REPORT ZSTSEARC.

TABLES: TRDIR.
DATA: PROGRAM LIKE SY-REPID,
      BEGIN OF T OCCURS 1000,
        LINE(72),
      END   OF T,
INDX LIKE SY-TABIX.
DATA: KEY(25).
DATA: BEGIN OF LIST OCCURS 1000,
KEY(25),
LINE1(72), LINE2(72), LINE3(72), LINE4(72), LINE5(72),
LINE6(72), LINE7(72), LINE8(92), LINE9(72),
LINE10(72), LINE11(72), LINE12(72), LINE13(72), LINE14(72),
LINE15(72), LINE16(72), LINE17(92), LINE18(72),
LINE19(72), LINE20(72), LINE21(72), LINE22(72), LINE23(72),
LINE24(72), LINE25(72), LINE26(92), LINE27(72),
LINE28(72), LINE29(72), LINE30(72), LINE31(72), LINE32(72),
LINE33(72), LINE34(72), LINE35(92), LINE36(72),
LINE37(72), LINE38(72), LINE39(72), LINE40(72), LINE41(72),
LINE42(72), LINE43(72), LINE44(92), LINE45(72),
                                            PR(8),
END OF LIST.
DATA: NULL, TT(72).
DATA: LINECOUNT TYPE I, FILDNAME(10).
FIELD-SYMBOLS .

SELECT * FROM TRDIR WHERE NAME BETWEEN 'Y%' AND 'Z%'.
  CLEAR T.REFRESH T.
  READ REPORT TRDIR-NAME INTO T.
  LOOP AT T.
    IF T CP '*CALL* ID *'.
      IF T NP '#**'.
        CLEAR LIST.
        TT = T.
        SHIFT T LEFT  DELETING LEADING ' '.
        CONDENSE T.
        SHIFT TT UP TO ''''. SHIFT TT.
        SPLIT TT AT '''' INTO KEY NULL.
        LIST-KEY = KEY.
        LIST-LINE1 = T.
*       list-pr = trdir-name.
        IF T CP '*#. ' OR T CP '*#.*"*'.
          COLLECT LIST.
          CONTINUE.
        ENDIF.
        DO.
          INDX = SY-TABIX + 1.
          READ TABLE T INDEX INDX.
          LINECOUNT = SY-INDEX * 72 + 25.
          SHIFT T LEFT  DELETING LEADING ' '.
          CONDENSE T.
          SHIFT T RIGHT BY 5 PLACES.
          MOVE T(72) TO LIST+LINECOUNT(72).
          IF T CP '*#. ' OR T CP '*#.*"*' or t np '*ID*'.
            COLLECT LIST.
            EXIT.
          ENDIF.
        ENDDO.
      ENDIF.
    ENDIF.
  ENDLOOP.
ENDSELECT.

SORT LIST BY KEY.
LOOP AT LIST.
  WRITE: / LIST-PR.
  WRITE: / LIST-LINE1.
  IF NOT LIST-LINE2 IS INITIAL. WRITE: / LIST-LINE2. ENDIF.
  IF NOT LIST-LINE3 IS INITIAL. WRITE: / LIST-LINE3. ENDIF.
  IF NOT LIST-LINE4 IS INITIAL. WRITE: / LIST-LINE4. ENDIF.
  IF NOT LIST-LINE5 IS INITIAL. WRITE: / LIST-LINE5. ENDIF.
  IF NOT LIST-LINE6 IS INITIAL. WRITE: / LIST-LINE6. ENDIF.
  IF NOT LIST-LINE7 IS INITIAL. WRITE: / LIST-LINE7. ENDIF.
  IF NOT LIST-LINE8 IS INITIAL. WRITE: / LIST-LINE8. ENDIF.
  IF NOT LIST-LINE9 IS INITIAL. WRITE: / LIST-LINE9. ENDIF.
  SKIP.
ENDLOOP.