Find LSMW for a Spesific T-CODE

There is no standard way to find LSMW for a t-code in SAP.

This program allows you to find LSMW for a spesific t-code.

 

*&---------------------------------------------------------------------*
*& Report  ZFIND_LSMW
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

report  zfind_lsmw.

type-pools: slis.

data: gv_ucomm_fname  type slis_formname value 'USER_COMMAND',
      gv_ucomm        type sy-ucomm      value '&IC1',
      gv_repid        type sy-repid.

data: gt_lsgbdca      type table of /sapdmc/lsgbdca,
      gt_lsorec       type table of /sapdmc/lsorec,
      ls_lsorec       type          /sapdmc/lsorec.

data: gv_title        type lvc_title,
      gs_layout       type slis_layout_alv.

data: it_fieldcat  type slis_t_fieldcat_alv,
      wa_fieldcat  type slis_fieldcat_alv.

parameters: p_tcode type /sapdmc/lsgbdca-recordingtcode
                         obligatory.

start-of-selection.

  gv_repid = sy-repid.

  select * from /sapdmc/lsgbdca
         into table gt_lsgbdca
         where recordingtcode = p_tcode.
  if sy-subrc = 0.

    select * from /sapdmc/lsorec
           into table gt_lsorec
           for all entries in gt_lsgbdca
           where recording = gt_lsgbdca-recording.
  endif.

  perform display_data.

*&---------------------------------------------------------------------*
*&      Form  display_data
*&---------------------------------------------------------------------*
form display_data.

  gs_layout-colwidth_optimize = 'X'.

  gv_title = 'LSMW Values'.

  perform build_field_catalog using:
     'PROJECT'   'GT_LSOREC' 'Project'(001),
     'SUBPROJ'   'GT_LSOREC' 'Sub Project'(002),
     'OBJECT'    'GT_LSOREC' 'Object'(003),
     'RECORDING' 'GT_LSOREC' 'recording'(004).

*Display table values in ALV
  call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      i_callback_program      = gv_repid
      i_callback_user_command = gv_ucomm_fname
      i_grid_title            = gv_title
      is_layout               = gs_layout
      it_fieldcat             = it_fieldcat
    tables
      t_outtab                = gt_lsorec
    exceptions
      program_error           = 1
      others                  = 2.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

endform.                    " display_data
*&---------------------------------------------------------------------*
*&      Form  build_fld_catalog
*&---------------------------------------------------------------------*
form build_field_catalog using    value(p_fieldname)
                                  value(p_tabname)
                                  value(p_description).
  clear wa_fieldcat.
  wa_fieldcat-fieldname = p_fieldname.
  wa_fieldcat-tabname   = p_tabname.
  wa_fieldcat-seltext_m = p_description.
  append wa_fieldcat to it_fieldcat.

endform.                    " build_fld_catalog
*&---------------------------------------------------------------------*
* Form  User Command
*&---------------------------------------------------------------------*
form user_command using r_ucomm     type sy-ucomm
                        rs_selfield type slis_selfield.
  if r_ucomm eq gv_ucomm.
    read table gt_lsorec into ls_lsorec index rs_selfield-tabindex.
    if sy-subrc = 0.

      call function '/SAPDMC/LSM_OBJ_STARTER'
        exporting
          project        = ls_lsorec-project
          subproj        = ls_lsorec-subproj
          object         = ls_lsorec-object
        exceptions
          no_such_object = 1
          others         = 2.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.

    endif.
  endif.

endform.

Leave a comment

Your email address will not be published. Required fields are marked *