Wednesday, August 31, 2011

Unicode Conversion - Set Unicode Flag for error-free programs in just one click!

Unicode conversion is one of the important activity during upgrade. A part of this activity involves manually setting unicode flag for each error-free program listed in transaction code 'UCCHECK'. Generally in R/3 systems there are 1500+ programs under this category for unicode conversion. The tedious activity of setting unicode flag for each program ends up eating a lot of time and efforts of developers. Instead of completing this activity manually, it can be completed using Unicode Flag tool in few seconds!

Pre-requisites:
All you have to do is to copy error-free program names (from tcode UCCHECK) and paste it into excel.
Provide file-name along with Development Task, Repair Task, and system id in which conversion is being carried out. Execute tool and job done! All the programs will be unicode enabled and added to respective tasks (development/repair task of TR)


*&---------------------------------------------------------------------*
*& Report  ZUNICODE_FLAG
*&---------------------------------------------------------------------*
*&Program to set unicode attribute of objects in bulk
*&---------------------------------------------------------------------*

REPORT  zunicode_flag.

*===Tables Declaration
TABLES: tadir,
                trdir.

TYPE-POOLS:   truxs,
                            slis.

*===Structure Declaration                                                            
TYPES: BEGIN  OF ty_progs,
        obj_name     TYPE tadir-obj_name.
TYPES: END    OF ty_progs.

TYPES: BEGIN  OF ty_tadir,
       pgmid            TYPE tadir-pgmid,
       object            TYPE tadir-object,
       obj_name       TYPE tadir-obj_name,
       srcsystem       TYPE tadir-srcsystem,
       devclass         TYPE tadir-devclass.
TYPES: END    OF ty_tadir.

TYPES: BEGIN  OF ty_layer,
       devclass         TYPE tdevc-devclass,
       pdevclass       TYPE tdevc-pdevclass.
TYPES: END    OF ty_layer.

TYPES: BEGIN  OF ty_outtab,
       obj_name        TYPE tadir-obj_name,
       uccheck           TYPE trdir-uccheck,
       comment(50)   TYPE c.
TYPES: END    OF ty_outtab.


DATA: t_trdir               TYPE STANDARD TABLE OF trdir,
            t_ko200_ssys   TYPE STANDARD TABLE OF ko200,
            t_ko200_dsys   TYPE STANDARD TABLE OF ko200,
            x_ko200           TYPE ko200,
            x_trdir               TYPE trdir.

DATA: t_raw_data      TYPE truxs_t_text_data,
            filename           TYPE rlgrap-filename,
            t_progs            TYPE STANDARD TABLE OF ty_progs,
            x_progs           TYPE ty_progs,
            t_tadir              TYPE STANDARD TABLE OF ty_tadir,
            t_lclobj            TYPE STANDARD TABLE OF ty_tadir,
            t_layer             TYPE STANDARD TABLE OF ty_layer,
            t_outtab           TYPE STANDARD TABLE OF ty_outtab,
            t_fieldcatalog    TYPE slis_t_fieldcat_alv,
            x_fieldcatalog   TYPE slis_fieldcat_alv,
            x_tadir             TYPE ty_tadir,
            x_lclobj            TYPE ty_tadir,
            x_layer             TYPE ty_layer,
            x_outtab           TYPE ty_outtab.


*===CONSTANTS
CONSTANTS: c_space      TYPE    c VALUE ' ',
                         c_x              TYPE   c VALUE 'X',
                         c_local(21)  TYPE   c VALUE 'Not to be transported',
                         c_set(16)     TYPE   c VALUE 'Unicode flag set'.


*----------------------------------------------------------------------*
*  SELECTION-SCREEN                                                    *
*----------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF   BLOCK b1 WITH FRAME TITLE text-001.
PARAMETER:   p_devcor   TYPE ko200-trkorr     OBLIGATORY, "Development Task
                          p_repair     TYPE ko200-trkorr     OBLIGATORY,       "Repair Task
                          p_file          TYPE rlgrap-filename  OBLIGATORY,       "Excel Filename with list of objects
                          p_srcsys     TYPE tadir-srcsystem  OBLIGATORY.      "Source System
SELECTION-SCREEN END OF     BLOCK b1.

*----------------------------------------------------------------------*
*   AT SELECTION-SCREEN                                                *
*----------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*F4 for file name
  PERFORM sub_get_filename.

*----------------------------------------------------------------------*
*                        START-OF-SELECTION.                           *
*----------------------------------------------------------------------*
START-OF-SELECTION.

*Upload Object list
  PERFORM sub_upload_excel.

*Fetch data
  PERFORM sub_get_data.

*Insert objects in appropriate task
  PERFORM sub_insert_objects_in_tr.

*Update Unicode flag of objects in TR
  PERFORM sub_update_unicode_flag.

*Prepare output table for display
  PERFORM sub_output_table.

*----------------------------------------------------------------------*
*                        END-OF-SELECTION.                             *
*----------------------------------------------------------------------*
END-OF-SELECTION.

*Build field catalog
  PERFORM sub_build_catalog.

*Display report
  PERFORM sub_display.

*&---------------------------------------------------------------------*
*&      Form  SUB_GET_FILENAME
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

FORM sub_get_filename .

  DATA: t_table TYPE STANDARD TABLE OF sdokpath,
        x_table LIKE sdokpath.

  CALL FUNCTION 'TMP_GUI_FILE_OPEN_DIALOG'
       EXPORTING
            init_directory = p_file
       TABLES
            file_table     = t_table
       EXCEPTIONS
            cntl_error     = 1
            OTHERS         = 2.

  IF sy-subrc EQ 0.
    READ TABLE t_table INTO x_table INDEX 1 .
    p_file = x_table-pathname.
  ENDIF.


ENDFORM.                    " SUB_GET_FILENAME
*&---------------------------------------------------------------------*
*&      Form  SUB_UPLOAD_EXCEL
*&---------------------------------------------------------------------*
*       Upload Excel
*----------------------------------------------------------------------*

FORM sub_upload_excel .

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
       EXPORTING
            i_field_seperator    = c_x
            i_tab_raw_data       = t_raw_data
            i_filename           = p_file
       TABLES
            i_tab_converted_data = t_progs
       EXCEPTIONS
            conversion_failed    = 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.                    " SUB_UPLOAD_EXCEL
*&---------------------------------------------------------------------*
*&      Form  SUB_INSERT_OBJECTS_IN_TR
*&---------------------------------------------------------------------*
*       Insert objects in TR
*----------------------------------------------------------------------*

FORM sub_insert_objects_in_tr .

*Insert objects with system same as source system
  CALL FUNCTION 'TR_OBJECTS_CHECK'
       TABLES
            wt_ko200                = t_ko200_ssys
       EXCEPTIONS
            cancel_edit_other_error = 1
            show_only_other_error   = 2
            OTHERS                  = 3.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  CALL FUNCTION 'TR_OBJECTS_INSERT'
       TABLES
            wt_ko200                = t_ko200_ssys
       EXCEPTIONS
            cancel_edit_other_error = 1
            show_only_other_error   = 2
            OTHERS                  = 3.

*Insert objects with system different from source system
  CALL FUNCTION 'TR_OBJECTS_CHECK'
       TABLES
            wt_ko200                = t_ko200_dsys
       EXCEPTIONS
            cancel_edit_other_error = 1
            show_only_other_error   = 2
            OTHERS                  = 3.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  CALL FUNCTION 'TR_OBJECTS_INSERT'
       TABLES
            wt_ko200                = t_ko200_dsys
       EXCEPTIONS
            cancel_edit_other_error = 1
            show_only_other_error   = 2
            OTHERS                  = 3.

ENDFORM.                    " SUB_INSERT_OBJECTS_IN_TR
*&---------------------------------------------------------------------*
*&      Form  SUB_OUTPUT_TABLE
*&---------------------------------------------------------------------*
*       Populate Output table
*----------------------------------------------------------------------*

FORM sub_output_table .

*Populate Local objects into output table
  LOOP AT t_lclobj INTO x_lclobj.
    x_outtab-obj_name = x_lclobj-obj_name.
    x_outtab-uccheck  = c_space.
    x_outtab-comment  = c_local.
    APPEND x_outtab TO t_outtab.
    CLEAR: x_outtab,
           x_lclobj.
  ENDLOOP.

*Populate Unicode enabled objects into output table
  LOOP AT t_tadir INTO x_tadir.
    x_outtab-obj_name = x_tadir-obj_name.
    x_outtab-uccheck  = c_x.
    x_outtab-comment  = c_set.
    APPEND x_outtab TO t_outtab.
    CLEAR: x_outtab,
           x_tadir.
  ENDLOOP.

ENDFORM.                    " SUB_OUTPUT_TABLE
*&---------------------------------------------------------------------*
*&      Form  SUB_BUILD_CATALOG
*&---------------------------------------------------------------------*
*       Build field catalog
*----------------------------------------------------------------------*

FORM sub_build_catalog .

  x_fieldcatalog-tabname   =  text-002.      "T_OUTTAB
  x_fieldcatalog-fieldname =  text-003.      "OBJ_NAME
  x_fieldcatalog-seltext_l =  text-004.      "Object Name
  APPEND x_fieldcatalog TO t_fieldcatalog.
  CLEAR x_fieldcatalog.

  x_fieldcatalog-tabname   =  text-002.      "T_OUTTAB
  x_fieldcatalog-fieldname =  text-005.      "UCCHECK
  x_fieldcatalog-seltext_l =  text-006.      "Unicode Flag
  APPEND x_fieldcatalog TO t_fieldcatalog.
  CLEAR x_fieldcatalog.

  x_fieldcatalog-tabname   =  text-002.      "T_OUTTAB
  x_fieldcatalog-fieldname =  text-007.      "COMMENT
  x_fieldcatalog-seltext_l =  text-008.      "Comment
  APPEND x_fieldcatalog TO t_fieldcatalog.
  CLEAR x_fieldcatalog.

ENDFORM.                    " SUB_BUILD_CATALOG
*&---------------------------------------------------------------------*
*&      Form  SUB_UPDATE_UNICODE_FLAG
*&---------------------------------------------------------------------*
*       Set Uniode attribute
*----------------------------------------------------------------------*

FORM sub_update_unicode_flag .

  LOOP AT t_tadir INTO x_tadir.

    SELECT SINGLE *
    FROM trdir
    INTO x_trdir
    WHERE name = x_tadir-obj_name.

    x_trdir-uccheck = c_x.

    MODIFY trdir FROM x_trdir.
    COMMIT WORK.

    CLEAR: x_tadir,
           x_trdir.

  ENDLOOP.

ENDFORM.                    " SUB_UPDATE_UNICODE_FLAG
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_DATA
*&---------------------------------------------------------------------*
*       Get repository details for objects
*----------------------------------------------------------------------*

FORM sub_get_data .

*Remove namespace objects
  DELETE t_progs WHERE obj_name(1) EQ '/'.


*Fetch details of Repository Objects
  SELECT pgmid
         object
         obj_name
         srcsystem
         devclass
         FROM tadir
         INTO TABLE t_tadir
         FOR ALL ENTRIES IN t_progs
         WHERE obj_name EQ t_progs-obj_name.

*Fetch transport layer of packages to identify local objects
  SELECT devclass pdevclass
      FROM tdevc INTO TABLE t_layer
      FOR ALL ENTRIES IN t_tadir
      WHERE devclass EQ t_tadir-devclass.

*Separate local objects from transportable one
  LOOP AT t_layer INTO x_layer.

    IF x_layer-pdevclass = 'SAP' OR x_layer-pdevclass = ' '.
*Local objects not to be inserted in TR
      READ TABLE t_tadir INTO x_tadir WITH KEY devclass =
 x_layer-devclass.
      MOVE x_tadir TO x_lclobj.
      APPEND x_lclobj TO t_lclobj.
      DELETE t_tadir WHERE devclass EQ x_layer-devclass.
    ENDIF.

  ENDLOOP.

* Select Task (Dev/Corr or Repair) based on Source System
  LOOP AT t_tadir INTO x_tadir.

    IF x_tadir-srcsystem EQ p_srcsys.
      x_ko200-trkorr = p_devcor.
      x_ko200-object   =  x_tadir-object.
      x_ko200-pgmid    =  x_tadir-pgmid.
      x_ko200-obj_name =  x_tadir-obj_name.
      APPEND x_ko200 TO t_ko200_ssys.
    ELSE.
      x_ko200-trkorr = p_repair.
      x_ko200-object   =  x_tadir-object.
      x_ko200-pgmid    =  x_tadir-pgmid.
      x_ko200-obj_name =  x_tadir-obj_name.
      APPEND x_ko200 TO t_ko200_dsys.
    ENDIF.

    CLEAR: x_ko200,
           x_tadir.

  ENDLOOP.


ENDFORM.                    " SUB_GET_DATA
*&---------------------------------------------------------------------*
*&      Form  SUB_DISPLAY
*&---------------------------------------------------------------------*
*       Display report
*----------------------------------------------------------------------*

FORM sub_display .


  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            it_fieldcat   = t_fieldcatalog
       TABLES
            t_outtab      = t_outtab
       EXCEPTIONS
            program_error = 1
            OTHERS        = 2.

ENDFORM.                    " SUB_DISPLAY

No comments:

Post a Comment