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

Program or Table for Lines of Code in a Program or TCode

Former Member
0 Likes
1,553

Hi,

We have a list of programmes and Transaction codes. We would like to know the number of lines of code in each object. Is there any standard program or table which can give us this data?

Thanks in advance.

Mick

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
807

hi Mick,

i have written a code for downloading the source code in wiki

hope it will be usefull for you to identify the lines of code

this code is for downloading the source code

TABLES: TRDIR, TADIR.

DATA: BEGIN OF REPLIST OCCURS 200, NAME(40) TYPE C, END OF REPLIST.
DATA: BEGIN OF BUFFER OCCURS 0, LINE(72) TYPE C, END OF BUFFER.
DATA: FILENAME(128) TYPE C, FILELENGTH(40) TYPE C.

SELECT-OPTIONS : SO_NAME FOR TADIR-OBJ_NAME.
SELECT-OPTIONS : SO_DEVC FOR TADIR-DEVCLASS.

PARAMETERS : PATHNAME(40).
PARAMETERS: P_AUTHOR LIKE SY-UNAME DEFAULT SY-UNAME.

SELECT * FROM TADIR
 WHERE DEVCLASS IN SO_DEVC
   AND OBJECT = 'PROG'
   AND OBJ_NAME IN SO_NAME
   AND AUTHOR = P_AUTHOR.
 SELECT * FROM TRDIR
        WHERE NAME = TADIR-OBJ_NAME
          AND CNAM = P_AUTHOR.
   MOVE TRDIR-NAME TO REPLIST-NAME.
   APPEND REPLIST.

ENDSELECT.
ENDSELECT.

LOOP AT REPLIST.
 READ REPORT REPLIST-NAME INTO BUFFER.
 FILENAME = PATHNAME.
 FILENAME+40 = REPLIST-NAME.
 FILENAME+70 = '.'.
 FILENAME+71 = 'txt'. "helpful to replace with SY-SYSID
*  filename+51 = sy-sysid.
 CONDENSE FILENAME NO-GAPS.
 CALL FUNCTION 'WS_DOWNLOAD'
      EXPORTING
           FILENAME         = FILENAME
           FILETYPE         = 'ASC'
      IMPORTING
           FILELENGTH       = FILELENGTH
      TABLES
           DATA_TAB         = BUFFER
      EXCEPTIONS
           FILE_OPEN_ERROR  = 1
           FILE_WRITE_ERROR = 2.
 CASE SY-SUBRC.

WHEN 0.
   WHEN 1.
     WRITE : / 'did not download', FILENAME, 'error opening file.'.
   WHEN 2.
     WRITE : / 'did not download', FILENAME, 'error reading file.'.
   WHEN OTHERS.
 ENDCASE.
ENDLOOP.

so in this code the final table will be having the source code

so its table index gives you the lines of code

hope it will be useful for you

The link to the above code is here

https://wiki.sdn.sap.com/wiki/display/Snippets/TodownloadABAPsourcecode

cheers

S.Janagar

4 REPLIES 4
Read only

Former Member
0 Likes
808

hi Mick,

i have written a code for downloading the source code in wiki

hope it will be usefull for you to identify the lines of code

this code is for downloading the source code

TABLES: TRDIR, TADIR.

DATA: BEGIN OF REPLIST OCCURS 200, NAME(40) TYPE C, END OF REPLIST.
DATA: BEGIN OF BUFFER OCCURS 0, LINE(72) TYPE C, END OF BUFFER.
DATA: FILENAME(128) TYPE C, FILELENGTH(40) TYPE C.

SELECT-OPTIONS : SO_NAME FOR TADIR-OBJ_NAME.
SELECT-OPTIONS : SO_DEVC FOR TADIR-DEVCLASS.

PARAMETERS : PATHNAME(40).
PARAMETERS: P_AUTHOR LIKE SY-UNAME DEFAULT SY-UNAME.

SELECT * FROM TADIR
 WHERE DEVCLASS IN SO_DEVC
   AND OBJECT = 'PROG'
   AND OBJ_NAME IN SO_NAME
   AND AUTHOR = P_AUTHOR.
 SELECT * FROM TRDIR
        WHERE NAME = TADIR-OBJ_NAME
          AND CNAM = P_AUTHOR.
   MOVE TRDIR-NAME TO REPLIST-NAME.
   APPEND REPLIST.

ENDSELECT.
ENDSELECT.

LOOP AT REPLIST.
 READ REPORT REPLIST-NAME INTO BUFFER.
 FILENAME = PATHNAME.
 FILENAME+40 = REPLIST-NAME.
 FILENAME+70 = '.'.
 FILENAME+71 = 'txt'. "helpful to replace with SY-SYSID
*  filename+51 = sy-sysid.
 CONDENSE FILENAME NO-GAPS.
 CALL FUNCTION 'WS_DOWNLOAD'
      EXPORTING
           FILENAME         = FILENAME
           FILETYPE         = 'ASC'
      IMPORTING
           FILELENGTH       = FILELENGTH
      TABLES
           DATA_TAB         = BUFFER
      EXCEPTIONS
           FILE_OPEN_ERROR  = 1
           FILE_WRITE_ERROR = 2.
 CASE SY-SUBRC.

WHEN 0.
   WHEN 1.
     WRITE : / 'did not download', FILENAME, 'error opening file.'.
   WHEN 2.
     WRITE : / 'did not download', FILENAME, 'error reading file.'.
   WHEN OTHERS.
 ENDCASE.
ENDLOOP.

so in this code the final table will be having the source code

so its table index gives you the lines of code

hope it will be useful for you

The link to the above code is here

https://wiki.sdn.sap.com/wiki/display/Snippets/TodownloadABAPsourcecode

cheers

S.Janagar

Read only

0 Likes
807

Thanks Janagar.

I have a list of 600 reports and 500 TCodes. I would like to know the no of liness of code in each of these objects. I do not want the source code, as tht would be very time consuming to count the lines in the source code for so many objects.

Mick

Read only

0 Likes
807

hi mick,

u can use the same code for this purpose,

just neglect the last function module part and final internal table named Buffer is there right..

put describe statement on that gives you the total lines of your code.

it is more than enough i guess.

any guidance please get back to me

cheers

s.janagar

Read only

Former Member
0 Likes
807

Marking this as answered as there are no more answers