+ -

Pages

Sunday, July 27, 2014

Which standard texts are used by a SapScript form

The following program prints out the standard texts used by a form. Copy the code and insert it into an ABAP program. The report can show the texts for 2 different languages. As the report is based on an ALV grid, the standard functions in the ALV grid can be used to export the report.

Code

REPORT zform_texts LINE-SIZE 260.

************************************************************************
* Program name : ZFORM_TEXTS
* Description  : Prints all standard texts in a SapScript form
* Author       : Henrik Frank
* Date         : 2006-05-30
************************************************************************
* Change log:
*
************************************************************************


TYPES:
  BEGIN OF t_texts,
    tdname LIKE thead-tdname,   "Name of standard text 
    tdline TYPE tdline,         "Text
    tdline2 TYPE tdline,        "Text in alternatove language
  END OF t_texts.


DATA:
 it_lines TYPE STANDARD TABLE OF tline,
 wa_lines TYPE tline,
 it_texts TYPE STANDARD TABLE OF t_texts,
 wa_texts TYPE t_texts,

 test(7) TYPE c,
 startpos TYPE i,
 endpos TYPE i,
 len TYPE i,
 myline TYPE string.

*-----  ALV Grid Declarations
DATA:      r_container TYPE REF TO cl_gui_custom_container,
           r_grid      TYPE REF TO cl_gui_alv_grid.

DATA:      alv_fieldcat TYPE slis_t_fieldcat_alv,
           alv_layout   TYPE slis_layout_alv,
           gd_repid     LIKE sy-repid.

DATA:      l_wa TYPE slis_fieldcat_alv.



*******************************************************
SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME.
*******************************************************
PARAMETERS:
  pform TYPE tdform OBLIGATORY,
  plang TYPE tdspras OBLIGATORY DEFAULT 'EN',
  plang2 TYPE tdspras.


SELECTION-SCREEN END OF BLOCK 1.


START-OF-SELECTION.
  IF plang2 IS INITIAL.
    plang2 = plang.
  ENDIF.


  PERFORM read_form_source.
  PERFORM extract_texts_from_source.


END-OF-SELECTION.
  PERFORM alv_setup.
  PERFORM display_alv.

*&---------------------------------------------------------------------*
*&      Form  read_form_source
*&---------------------------------------------------------------------*
*       Read SapsScript source code
*----------------------------------------------------------------------*
FORM read_form_source.
  DATA:
    form LIKE thead-tdname.

  form = pform.

  CALL FUNCTION 'READ_TEXT'
    EXPORTING
     client                        = sy-mandt
      id                            = 'TXT '
      language                      =  plang
      name                          =  form
      object                        = 'FORM'
*   ARCHIVE_HANDLE                = 0
*   LOCAL_CAT                     = ' '
* IMPORTING
*   HEADER                        =
    TABLES
      lines                         = it_lines
   EXCEPTIONS
     id                            = 1
     language                      = 2
     name                          = 3
     not_found                     = 4
     object                        = 5
     reference_check               = 6
     wrong_access_to_archive       = 7
     OTHERS                        = 8
            .
  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.                    " read_form
*&---------------------------------------------------------------------*
*&      Form  extract_texts_from_source
*&---------------------------------------------------------------------*
*       Extract standard texts from source code
*----------------------------------------------------------------------*
FORM extract_texts_from_source.
  startpos = 8.

  LOOP AT it_lines INTO wa_lines.
    MOVE wa_lines-tdline TO test.

    IF test = 'INCLUDE' AND wa_lines-tdformat <> '/*'.
      SEARCH wa_lines-tdline FOR 'OBJECT'.
      endpos = sy-fdpos.

      IF endpos > 8.
        CLEAR wa_texts.
        len = endpos - startpos.
        MOVE wa_lines-tdline+startpos(len) TO wa_texts-tdname.
        SHIFT wa_texts-tdname LEFT DELETING LEADING space.

        PERFORM read_standard_texts
          USING wa_texts-tdname
                plang
          CHANGING wa_texts-tdline.

*       Read tet in alternative language
        IF NOT plang2 IS INITIAL.
          PERFORM read_standard_texts
            USING wa_texts-tdname
                  plang2
            CHANGING wa_texts-tdline2.
        ENDIF.


        APPEND wa_texts TO it_texts.

      ENDIF.
    ENDIF.
  ENDLOOP.

  SORT it_texts BY tdname.
  DELETE ADJACENT DUPLICATES FROM it_texts COMPARING tdname.



ENDFORM.                    " extract_texts

*&---------------------------------------------------------------------*
*&      Form  read_standard_texts
*&---------------------------------------------------------------------*
*       Read longtext for standard txts
*----------------------------------------------------------------------*
FORM read_standard_texts
   USING    p_tdname
            p_language
   CHANGING p_tdline.

  DATA: it_line TYPE STANDARD TABLE OF tline,
        wa_line TYPE tline,
        name LIKE thead-tdname.

  MOVE p_tdname TO name.



  CALL FUNCTION 'READ_TEXT'
    EXPORTING
     client                        = sy-mandt
      id                            = 'ST  '
      language                      =  p_language
      name                          =  name
      object                        = 'TEXT'
*   ARCHIVE_HANDLE                = 0
*   LOCAL_CAT                     = ' '
* IMPORTING
*   HEADER                        =
    TABLES
      lines                         = it_line
   EXCEPTIONS
     id                            = 1
     language                      = 2
     name                          = 3
     not_found                     = 4
     object                        = 5
     reference_check               = 6
     wrong_access_to_archive       = 7
     OTHERS                        = 8
            .
  IF sy-subrc <> 0.
*      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.

    READ TABLE it_line INDEX 1
      INTO wa_line.
    IF sy-subrc = 0.
      MOVE wa_line-tdline TO p_tdline.
    ENDIF.
  ENDIF.

ENDFORM.                    " read_standard_texts

*&---------------------------------------------------------------------*
*&      Form  alv_setup
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM alv_setup.
  DATA tmp TYPE string.

  CLEAR l_wa.
  REFRESH alv_fieldcat.

  l_wa-key = 'X'.
  l_wa-fieldname = 'TDNAME'.
  l_wa-seltext_s = 'Standard text'.
  l_wa-seltext_m = 'Standard text'.
  l_wa-seltext_l = 'Standard text'.
  APPEND l_wa TO alv_fieldcat.

  l_wa-key = ''.
  l_wa-fieldname = 'TDLINE'.
  CONCATENATE 'Text language: ' plang INTO tmp.
  l_wa-seltext_s = tmp.
  l_wa-seltext_m = tmp.
  l_wa-seltext_l = tmp.
  APPEND l_wa TO alv_fieldcat.

  l_wa-key = ''.
  l_wa-fieldname = 'TDLINE2'.
  CONCATENATE 'Text language: ' plang2 INTO tmp.
  l_wa-seltext_s = tmp.
  l_wa-seltext_m = tmp.
  l_wa-seltext_l = tmp.
  APPEND l_wa TO alv_fieldcat.


ENDFORM.                    " alv_setup
*&---------------------------------------------------------------------*
*&      Form  display_alv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_alv.
  gd_repid = sy-repid.

* Configure layout of screen
  alv_layout-colwidth_optimize = 'X'.
  alv_layout-zebra             = 'X'.
  alv_layout-no_min_linesize   = 'X'.

* Now call display function
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
           i_callback_program      = gd_repid
           i_callback_top_of_page   = 'TOP_OF_PAGE'
           is_layout                = alv_layout
           it_fieldcat              = alv_fieldcat
*           i_grid_title             = text-005
      TABLES
            t_outtab                = it_texts
     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_alv

*---------------------------------------------------------------------*
*       FORM top_of_page                                              *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM top_of_page.
  DATA: t_header TYPE slis_t_listheader,
        wa_header TYPE slis_listheader,
        l_tmp(50) TYPE c.

* Title
  CONCATENATE 'Standard texts used by form : ' pform INTO l_tmp.

  wa_header-typ  = 'H'.
  wa_header-info = l_tmp.
  APPEND wa_header TO t_header.
  CLEAR wa_header.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
       EXPORTING
            it_list_commentary = t_header.



ENDFORM.

5 ABAP Tips: Which standard texts are used by a SapScript form The following program prints out the standard texts used by a form. Copy the code and insert it into an ABAP program. The report can show t...

No comments:

Post a Comment

< >