Application Development 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: 

FM to determine actual program lines

Former Member
0 Kudos

Hi all,

Is there a FM or a standard program which can give me the exact program code lines,removing the comment lines in a report.

Thanks,

Bhumika

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello,

You can use the READ REPORT command and then delete the lines that start with * and then count the lines:


DATA prog TYPE c LENGTH 30. 
DATA itab TYPE TABLE OF string. 

prog = '...'. 

READ REPORT prog INTO itab. 

IF sy-subrc = 0. 
... delete the lines and count
ENDIF. 

Regards.

4 REPLIES 4

Former Member
0 Kudos

There is no such program/FM as such in SAP which gives the no. of lines...

Former Member
0 Kudos

Hello,

You can use the READ REPORT command and then delete the lines that start with * and then count the lines:


DATA prog TYPE c LENGTH 30. 
DATA itab TYPE TABLE OF string. 

prog = '...'. 

READ REPORT prog INTO itab. 

IF sy-subrc = 0. 
... delete the lines and count
ENDIF. 

Regards.

former_member705122
Active Contributor
0 Kudos

Hi,

Iam not sure about standard program or FM , but you can try this custom program.

*----------------------------------------------------------------------*
*                           T Y P E S                                  *
*----------------------------------------------------------------------*
types:
  begin of type_prog,
    w_line(200) type c,                " Lines
  end of type_prog.

*----------------------------------------------------------------------*
*                   I N T E R N A L   T A B L E S                      *
*----------------------------------------------------------------------*
data:
  i_prog    type standard table of type_prog,
  wa_prog   type type_prog.

*----------------------------------------------------------------------*
*                            D A T A                                   *
*----------------------------------------------------------------------*
data:
  prog_name   type c length 30,        " Program name
  w_temp(200) type c,                  " Lines
  w_count     type i,                  " Counter
  w_name      type trdir-name.         " ABAP Program Name

*---------------------------------------------------------------------*
*                 S E L E C T I O N     S C R E E N                   *
*---------------------------------------------------------------------*
parameters:
  p_pname like trdir-name.

*----------------------------------------------------------------------*
*               A T   S E L E C T I O N   S C R E E N                  *
*----------------------------------------------------------------------*
at selection-screen.
  perform f010_validate_program_name.

*----------------------------------------------------------------------*
*               A T   S E L E C T I O N   S C R E E N                  *
*----------------------------------------------------------------------*
at selection-screen on value-request for p_pname.
  perform f020_f4_value_help changing p_pname.

*---------------------------------------------------------------------*
*                S T A R T   O F   S E L E C T I O N                  *
*---------------------------------------------------------------------*
start-of-selection .
  perform f210_read_and_count.

*&--------------------------------------------------------------------*
*&      Form  f010_validate_program_name                              *
*&--------------------------------------------------------------------*
*       - Validate Program Name                                       *
*---------------------------------------------------------------------*
form f010_validate_program_name .

* Validate Program Name
  if p_pname is not initial.

    select single name
      into w_name
      from trdir
     where name eq p_pname.

    check sy-subrc ne 0.

    set cursor field 'P_PNAME'.
    message e290(zmsg).                " Invalid Program name

  endif.                               " IF p_name IS NOT INITIAL.

endform.                               " f010_validate_program_name

*&--------------------------------------------------------------------*
*&      Form  f210_read_and_count                                     *
*&--------------------------------------------------------------------*
*       -Read Program Name and Count Lines                            *
*---------------------------------------------------------------------*
form f210_read_and_count .
  data:
    w_comment type i,
    w_space   type i,
    w_add     type i,
    w_total   type i.
  read report p_pname into i_prog.

  if sy-subrc eq 0.

*    LOOP AT i_prog INTO wa_prog.
*      w_temp = wa_prog-w_line.
*
*      IF w_temp+0(1)  NE '*' AND w_temp  NE ' '.
*        w_count = w_count + 1.
*      ENDIF.                           " IF w_temp+0(1)
*
*    ENDLOOP.                           " LOOP AT i_prog
*    WRITE: 'TOTAL NUMBER OF LINES', w_count.
*  ENDIF.                               "  IF sy-subrc EQ 0.

    loop at i_prog into wa_prog.

      w_temp = wa_prog-w_line.

      if w_temp+0(1)  eq '*' .
        w_comment = w_comment + 1.

      endif.                           " IF w_temp+0(1)  EQ '*'

      if w_temp eq ' '.
        w_space = w_space + 1.
      endif.                           " IF w_temp EQ ' '

      w_count = w_count + 1.

    endloop.                           " LOOP AT i_prog

    w_add   = w_comment + w_space.
    w_total = w_count   - w_add.

    write:
      / 'Comment lines ',    30 w_comment ,
      / 'Blank Space',       30 w_space,
      / 'Add = comment + spaces',30 w_add,
      / 'Actual line written ',30 w_total,
      / 'Total line ', 30 w_count.
  endif.                               "  IF sy-subrc EQ 0.

endform.                               " f210_read_and_count

*&--------------------------------------------------------------------*
*&      Form  f020_f4_value_help                                      *
*&--------------------------------------------------------------------*
*       -F4 Value Help                                                *
*---------------------------------------------------------------------*
form f020_f4_value_help  changing p_p_pname.

  call function 'REPOSITORY_INFO_SYSTEM_F4'
    exporting
     object_type                     = 'PROG'
     object_name                     = p_p_pname
*   ENCLOSING_OBJECT                = ENCLOSING_OBJECT
*   SUPPRESS_SELECTION              = 'X'
*   VARIANT                         = ' '
*   LIST_VARIANT                    = ' '
*   DISPLAY_FIELD                   = DISPLAY_FIELD
*   MULTIPLE_SELECTION              = MULTIPLE_SELECTION
*   SELECT_ALL_FIELDS               = ' '
*   WITHOUT_PERSONAL_LIST           = ' '
*   PACKAGE                         = ' '
*   USE_ALV_GRID                    = ' '
   importing
     object_name_selected            = p_p_pname
*   ENCLOSING_OBJECT_SELECTED       = ENCLOSING_OBJECT_SELECTED
*   STRUCINF                        = STRUCINF
* TABLES
*   OBJECTS_SELECTED                = OBJECTS_SELECTED
*   RECORD_TAB                      = RECORD_TAB
 exceptions
   cancel                          = 1
   wrong_type                      = 2
            .
endform.                               " f020_f4_value_help

Regards

Adil

Former Member
0 Kudos

Thanks