Skip to Content
After a small blogging vacation…I’m back again -:) Yesterday…I was browsing the ABAP Forums, and someone ask how to know what tables were used in a program. The answer was, look a transaction SE49 …That’s when I thought…That could be a great transaction! I started by checking the transaction, because I wasn’t aware of it…After a few tests…I came to one simple but fatal error…My test error used four tables, but the SE49 transaction only showed me two of them…That’s why I made my own custom Run at your own risk function module. First things first…I create a structure called ZPROG_TABLES . image The I create my FM called ZPROGRAM_ANALYSIS FUNCTION ZPROGRAM_ANALYSIS. *”—- —————————————————————– *”*”Local interface: *” IMPORTING *” VALUE(PROGRAM) TYPE TRDIR-NAME OPTIONAL *” VALUE(TRANSACTION) TYPE TSTC-TCODE OPTIONAL *” TABLES *” PROG_TABLES STRUCTURE ZPROG_TABLES *” EXCEPTIONS *” PROGRAM_NOT_FOUND *” TWO_PARAMETERS *” TRANS_NOT_FOUND *”—- —————————————————————– TYPES: BEGIN OF KEY_TAB, KEYWORDS(30), END OF KEY_TAB. TYPES: BEGIN OF SOURCE_TAB, LINE(80), END OF SOURCE_TAB. DATA: V_NAME TYPE TRDIR-NAME, V_TCODE TYPE TSTC-TCODE, V_PGMNA TYPE TSTC-PGMNA, V_FLAG TYPE C, V_COUNTER TYPE I, V_TABIX TYPE SY-TABIX, W_TABIX TYPE SY-TABIX. DATA: T_KEY_TAB TYPE STANDARD TABLE OF KEY_TAB WITH HEADER LINE, T_STATEMENTS TYPE STANDARD TABLE OF SSTMNT WITH HEADER LINE, T_SOURCE_TAB TYPE STANDARD TABLE OF SOURCE_TAB WITH HEADER LINE, T_TOKENS TYPE STANDARD TABLE OF STOKEN WITH HEADER LINE. IF PROGRAM NE SPACE AND TRANSACTION NE SPACE. RAISE TWO_PARAMETERS. ENDIF. IF PROGRAM NE SPACE. SELECT SINGLE NAME INTO V_NAME FROM TRDIR WHERE NAME EQ PROGRAM. IF SY-SUBRC NE 0. RAISE PROGRAM_NOT_FOUND. ENDIF. ENDIF. IF TRANSACTION NE SPACE. SELECT SINGLE TCODE PGMNA INTO (V_TCODE, V_PGMNA) FROM TSTC WHERE TCODE EQ TRANSACTION. IF SY-SUBRC NE 0. RAISE TRANS_NOT_FOUND. ELSE. V_NAME = V_PGMNA. ENDIF. ENDIF. IF V_NAME NE SPACE. T_KEY_TAB-KEYWORDS = ‘SELECT’. APPEND T_KEY_TAB. T_KEY_TAB-KEYWORDS = ‘UPDATE’. APPEND T_KEY_TAB. T_KEY_TAB-KEYWORDS = ‘MODIFY’. APPEND T_KEY_TAB. T_KEY_TAB-KEYWORDS = ‘DELETE’. APPEND T_KEY_TAB. READ REPORT V_NAME INTO T_SOURCE_TAB. IF SY-SUBRC NE 0. EXIT. ELSE. SCAN ABAP-SOURCE T_SOURCE_TAB KEYWORDS FROM T_KEY_TAB TOKENS INTO T_TOKENS STATEMENTS INTO T_STATEMENTS WITH INCLUDES. LOOP AT T_KEY_TAB. CLEAR: V_FLAG,V_COUNTER. LOOP AT T_TOKENS. CLEAR: PROG_TABLES. V_TABIX = SY-TABIX. IF T_TOKENS-STR EQ T_KEY_TAB-KEYWORDS. SEARCH PROG_TABLES FOR T_KEY_TAB-KEYWORDS. IF SY-SUBRC EQ 0. CLEAR: V_COUNTER,PROG_TABLES. APPEND PROG_TABLES. ENDIF. V_FLAG = ‘X’. V_COUNTER = V_COUNTER + 1. MOVE V_COUNTER TO PROG_TABLES-COUNTER. READ TABLE T_SOURCE_TAB INDEX T_TOKENS-ROW. MOVE T_SOURCE_TAB-LINE TO PROG_TABLES-SOURCE. CONDENSE PROG_TABLES-SOURCE. APPEND PROG_TABLES. ELSE. IF V_FLAG EQ ‘X’. READ TABLE T_SOURCE_TAB INDEX T_TOKENS-ROW. MOVE T_SOURCE_TAB-LINE TO PROG_TABLES-SOURCE. SEARCH PROG_TABLES FOR T_TOKENS-STR. IF SY-SUBRC NE 0 OR T_TOKENS-STR EQ ‘FROM’. V_COUNTER = V_COUNTER + 1. MOVE V_COUNTER TO PROG_TABLES-COUNTER. CONDENSE PROG_TABLES-SOURCE. IF T_TOKENS-STR EQ ‘FROM’. SEARCH PROG_TABLES FOR T_SOURCE_TAB-LINE. IF SY-SUBRC EQ 0. W_TABIX = SY-TABIX. V_COUNTER = V_COUNTER – 1. V_TABIX = V_TABIX + 1. READ TABLE T_TOKENS INDEX V_TABIX. IF SY-SUBRC EQ 0. MOVE T_TOKENS-STR TO PROG_TABLES-TABLE_NAME. MODIFY PROG_TABLES INDEX W_TABIX TRANSPORTING TABLE_NAME. ENDIF. CONTINUE. ENDIF. V_TABIX = V_TABIX + 1. READ TABLE T_TOKENS INDEX V_TABIX. IF SY-SUBRC EQ 0. MOVE T_TOKENS-STR TO PROG_TABLES-TABLE_NAME. ENDIF. ENDIF. APPEND PROG_TABLES. ENDIF. ENDIF. ENDIF. ENDLOOP. ENDLOOP. ENDIF. ENDIF. ENDFUNCTION. After some tests, I create the PHP part of this emulator. index.php session_start();include(“Login_Class.php”);?> body {background} #login {background} body {background:#F5F9FF} #login {background} $SE49 = new SE49(); $Login = new Login(); $Log_Me = $Login->Log_In($_SESSION[“Server”],$_SESSION[“Sysnum”],$_SESSION[“Client”], $_SESSION[“User”],$_SESSION[“Pass”]); $RFC_Me = $Login->RFC_Connection($Log_Me); if(isset($_POST[‘APP’])) { $APP = $_POST[“APP”]; $TYPE = $_POST[“PROGRAM”]; $SE49->Show_Tables($RFC_Me,$APP,$TYPE); } ?> SE49.php Class SE49{var $fce;function Show_Tables($RFC_Me,$Name,$Type){ $this->fce = saprfc_function_discover($RFC_Me, “ZPROGRAM_ANALYSIS”); IF (! $this->fce ) { ECHO “The function module had failed.”; EXIT; } if($Type == “P”) { saprfc_import ($this->fce,”PROGRAM”,$Name); } else { saprfc_import ($this->fce,”TRANSACTION”,$Name); } saprfc_table_init ($this->fce,”PROG_TABLES”); $rfc_rc = “”; $rfc_rc = saprfc_call_and_receive ($this->fce); if ($rfc_rc != SAPRFC_OK) { if ($rfc == SAPRFC_EXCEPTION ) echo (“Exception raised: “.saprfc_exception($this->fce)); else echo (“Call error: “.saprfc_error($this->fce)); // exit; } $prog_rows = saprfc_table_rows ($this->fce,”PROG_TABLES”); for ($i=1; $i<=$prog_rows; $i++) { $LINES = saprfc_table_read ($this->fce,”PROG_TABLES”,$i); if($LINES[‘TABLE_NAME’] != null) { $aux += 1; $Table_Name[$aux] = $LINES[‘TABLE_NAME’]; } $Source[$i] = $LINES[‘SOURCE’]; } $source_long = count($Source); $table_long = count($Table_Name); $aux = 1; $counter = 1; for($i=1;$i<=$table_long;$i++) { $tab_count += 1; PRINT(“$Table_Name[$i]”); for($j=$aux;$j<=$source_long;$j++) { if($Source[$j] != null) { $counter += 1; PRINT(” “); PRINT(“”); PRINT(” | $Source[$j] | “); } else { $aux = $counter + $tab_count; break; } } PRINT(” “); } PRINT(“”); PRINT(” “); PRINT(”   “); PRINT(” “); } } ?> Now…Let’s show the info of the transaction SE49 running my simple program called ZDUMMY_ATG . image And now…Let’s see the SE49 emulation. image image image
To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

      1. Alvaro Tejada Galindo Post author
        Couldn’t activate SAPLink on my MiniSAP, so I have updated the blog with a .ZIP file. There you can find all the related code used in this weblog -;)

        Greetings,

        Blag.

        (0) 

Leave a Reply