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

counting the comments in the source code

Former Member
0 Likes
889

Hi,

I have a scenario where i need to count the number of comment lines in the source code.can anyone help me regarding this.

Regards,

Sravanthi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
647

Hi,

Make use of 'Scan' statement to get the number of lines with out comments.

SCAN ABAP-SOURCE itab1 ...TOKENS INTO itab2

...STATEMENTS INTO itab3.

ABAP-SOURCE is the program name

You can use the statement 'With comments' and without it and do a computation to get the number of commented lines.

Regards

Sailaja.

4 REPLIES 4
Read only

Former Member
0 Likes
648

Hi,

Make use of 'Scan' statement to get the number of lines with out comments.

SCAN ABAP-SOURCE itab1 ...TOKENS INTO itab2

...STATEMENTS INTO itab3.

ABAP-SOURCE is the program name

You can use the statement 'With comments' and without it and do a computation to get the number of commented lines.

Regards

Sailaja.

Read only

0 Likes
647

Hi sailaja,

Thanx for your reply.can you explain it futher with an example.

regards,

sravanthi.

Read only

0 Likes
647

Hi,

Check below Code,

REPORT ZCOMMENT.

************************************************************************

  • This program subtracts the comment lines from a program source.

  • To get the line numbers right, run pp before the subtraction.

  • It can be useful to document abap developments

************************************************************************

PARAMETERS: PROGRAM LIKE SY-REPID DEFAULT SY-REPID.

DATA : BEGIN OF SOURCE OCCURS 1000,

LINE(72),

END OF SOURCE.

DATA: I TYPE I, J TYPE I, K TYPE I, L TYPE I, LNUM(6) TYPE N.

DATA: EMPTY(72) VALUE

'

'. "Some ugly long line

DATA: P_STATEMENTS LIKE SSTMNT OCCURS 100 WITH HEADER LINE.

DATA: P_TOKENS LIKE STOKEN OCCURS 100 WITH HEADER LINE.

*

READ REPORT PROGRAM INTO SOURCE.

SCAN ABAP-SOURCE SOURCE STATEMENTS INTO P_STATEMENTS "Comment in chain

TOKENS INTO P_TOKENS.

*

  • Remove the statement closing characters

LOOP AT P_STATEMENTS.

IF P_STATEMENTS-TROW <> 0.

READ TABLE SOURCE INDEX P_STATEMENTS-TROW.

SOURCE+P_STATEMENTS-TCOL(1) = ' '.

MODIFY SOURCE INDEX P_STATEMENTS-TROW.

ENDIF.

ENDLOOP.

*

  • Remove the tokens

LOOP AT P_TOKENS.

I = P_TOKENS-ROW.

J = P_TOKENS-COL.

K = P_TOKENS-LEN - 1.

L = J + K.

DO.

READ TABLE SOURCE INDEX I.

IF L > 72. "Multi line token

L = L - 72.

SOURCE+J(72) = EMPTY.

MODIFY SOURCE INDEX I.

I = I + 1.

K = L. J = 0.

ELSE.

IF L < 72.

K = K + 1.

ENDIF.

SOURCE+J(K) = EMPTY.

MODIFY SOURCE INDEX I.

EXIT.

ENDIF.

ENDDO.

ENDLOOP.

*

  • Remove ':' (chain statements)

LOOP AT SOURCE.

CONDENSE SOURCE NO-GAPS.

IF SOURCE(1) = ':'.

DELETE SOURCE.

ENDIF.

ENDLOOP.

*

  • Print the result

FORMAT INPUT ON.

LOOP AT SOURCE.

LNUM = LNUM + 10.

IF NOT SOURCE IS INITIAL.

FORMAT INTENSIFIED OFF.FORMAT INVERSE OFF.

TRANSLATE LNUM USING ' 0'.

WRITE /(6) LNUM COLOR 2.

IF SOURCE(1) = '*'.

FORMAT INTENSIFIED ON.

WRITE 8 SOURCE COLOR 6.

FORMAT INTENSIFIED OFF.

ELSE.

WRITE 8 SOURCE COLOR 2.

ENDIF.

ENDIF.

ENDLOOP.

Thanks and Regards,

Chandra

Read only

Former Member
0 Likes
647

Hi,

READ REPORT 'ZDACORPRICERECEIPTS_PRODUCTION' INTO tbl_data.

BREAK-POINT.

SCAN ABAP-SOURCE tbl_data

TOKENS INTO tbl_tk

STATEMENTS INTO tbl_stm

KEYWORDS FROM tbl_kw.

but in sap documentation thru tcode saphelp we can see the following.

SCAN ABAP-SOURCE itab1 ... TOKENS INTO itab2

...STATEMENTS INTO itab3.

... WITH COMMENTS

Effect

Returns comments also, with each individual comment representing a token.

Note

The addition ... WITH COMMENTS is unfortunately not supported at present!

Regds

Sivaparvathi

Please reward points if helpful