Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Read function module source code into an internal table

Former Member
0 Likes
2,658

hi all,

My requirement is to search a string in a function module source code. Is there any statment to read the source of the function module into a internal table . i kown one statement which read the report source code (read report 'z_..' into itab, similarly is there any stmt. / standard SAP program which do the same.

thanks

vijay.

7 REPLIES 7
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,510

Try using RPR_ABAP_SOURCE_SCAN. This will allow you to search many different ways.

Regards,

Rich Heilman

Read only

0 Likes
1,510

You could write your own function module to retrieve the source code of the program and all of the includes of a program. Just convert this sample program to a function module. You will need to do some coding to retrieve the includes of the program.



report zrich_0001
       no standard page heading
       line-size 300.

parameters: p_prog(60) type c.

data: begin of s occurs 0,
      txt(300) type c,
      end of s.

read report p_prog into s.         
loop at s.
  write:/ s-txt.
endloop.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,510

Hi mani,

Every function module is a program by itself. So if a function module belongs to function group XYZ, then the main program name will be SAPLXYZ and the function module's source code program will be in the form of LXYZUnnn(where nnn is a sequential number). You can get this information from the attributes tab of the function module in SE37.

You can use 'READ REPORT' to read the code of the function module. But if you are looking for all the subroutines that are written in includes of the main program, then you need to code for reading it. There is not standard way to get it.

Here is a logical flow.

1. Get the main program of the function module and the include name for the function module.

2. Read report 'main program'. on each line search for the pattern 'LXYZU' and read that include name. For each include you can do a 'read report'. That way you will get the source code of the complete function group, not just the function module. But if it is just the function module code, you are interested in, then simply do a 'read report <function module include name here>'.

Regards,

Srinivas

Message was edited by: Srinivas Adavi

Alternatively, you can also use the function module 'SCWB_GET_ABAP_CODE_OF_OBJECT'.

Read only

0 Likes
1,510

hi srinivas can u give me the right syntax for reading a function module code in internal table.

u can mail me on azeeash79@yahoo.com

regards,

azee

Read only

0 Likes
1,510

Here we go ...


 DATA : GV_PROG_NAME    TYPE TRDIR-name.
 
  SELECT SINGLE *
    FROM   TFDIR
    WHERE  funcname = P_PROGF.
    IF SY-subrc EQ 0.
      CONCATENATE TFDIR-pname 'U' tfdir-include INTO GV_PROG_NAME.
      GV_PROG_NAME = gv_prog_name+3(30).
      
    ELSE.
      MESSAGE e001(AQ) WITH
    'Function module does not exit'.
    ENDIF.

* read the report code lines in an internal table
  READ REPORT GV_PROG_NAME INTO GT_REP_TABLE.
  IF SY-subrc < >  0.
    MESSAGE e001(AQ) WITH
           'Code is blank'.
    EXIT.
  ENDIF.

This should be enough or else check this link:

http://www.geocities.com/rmtiwari/Resources/Utilities/WebViewer.html

Thanks,

Ram

Message was edited by: Ram Manohar Tiwari

Read only

andreas_mann3
Active Contributor
0 Likes
1,510

Hi vijay,

look here:

regards Andreas

Read only

VijayasekarK
Active Participant
0 Likes
1,510

Hi ,

You can use the standard SAP Program RKCTSEAR for searching strings contained in the source code of any program.

Regards,

K Vijayasekar