SAPHub

How to find LSMW for a SAP T-Code?

There is no standard way to find a LSMW for a SAP tcode. But we can achieve this by writing a small program.

Program

TYPE-POOLS: slis.
*----------------------------------------------------------------------*
*     Constants
*----------------------------------------------------------------------*
CONSTANTS: con_user_comm TYPE slis_formname VALUE 'USER_COMMAND',
           con_ucomm     TYPE sy-ucomm   VALUE '&IC1'.
*----------------------------------------------------------------------*
*     Data Declaration
*----------------------------------------------------------------------*
DATA: g_repid   TYPE sy-repid.

DATA: gt_tcode  TYPE TABLE OF /sapdmc/lsgbdca.
DATA: gt_object TYPE TABLE OF /sapdmc/lsorec,
      wa_object TYPE /sapdmc/lsorec.
DATA: g_title   TYPE lvc_title,
      g_layout  TYPE slis_layout_alv.

DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv.

*----------------------------------------------------------------------*
*     SELECTION SCREEN
*----------------------------------------------------------------------*
PARAMETERS: p_tcode TYPE /sapdmc/lsgbdca-recordingtcode
                         OBLIGATORY.
*----------------------------------------------------------------------*
*      START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.

  g_repid = sy-repid.
*Check if the tcode is used in any recording
  SELECT * FROM /sapdmc/lsgbdca
         INTO TABLE gt_tcode
         WHERE recordingtcode = p_tcode.
  IF sy-subrc = 0.
*Check if the recordings found are assigned to any objects
    SELECT * FROM /sapdmc/lsorec
           INTO TABLE gt_object
           FOR ALL ENTRIES IN gt_tcode
           WHERE recording = gt_tcode-recording.
  ENDIF.

  IF NOT gt_object IS INITIAL.
    PERFORM display_data.
  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  display_data
*&---------------------------------------------------------------------*
FORM display_data.

*Customize ALV Layout
  g_layout-colwidth_optimize = 'X'.
  g_layout-zebra = 'X'.

*Set Layout title
  g_title = 'LSMW Details'(000).

*Build Field Catalog
  PERFORM build_fld_catalog USING:
     'PROJECT'   'GT_OBJECT' 'Project'(001),
     'SUBPROJ'   'GT_OBJECT' 'Sub Project'(002),
     'OBJECT'    'GT_OBJECT' 'Object'(003),
     'RECORDING' 'GT_OBJECT' 'recording'(004).

*Display table values in ALV
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = g_repid
      i_callback_user_command = con_user_comm
      i_grid_title            = g_title
      is_layout               = g_layout
      it_fieldcat             = it_fieldcat
    TABLES
      t_outtab                = gt_object
    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_fld_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 con_ucomm.
    READ TABLE gt_object INTO wa_object INDEX rs_selfield-tabindex.
    IF sy-subrc = 0.
*    Start LSMW
      CALL FUNCTION '/SAPDMC/LSM_OBJ_STARTER'
        EXPORTING
          project        = wa_object-project
          subproj        = wa_object-subproj
          object         = wa_object-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.  "User_command

Output

Enter the tcode for which you want to find the LSMW.

The output will display all the LSMW project details for the given tcode. Double click on any line will take you to the LSMW project overview screen.

See step 3(Fields from flat file) and 5(All fields updating in current LSMW) to check whether the existing LSMW satisfy your requirement.