Skip to Content
Technical Articles

Tip: How to Determine all Dynpro Fields of a Development Class

Often we have the problem that our test processes, at the test automation, don’t work correctly, because the development changed the dynpro (SAP GUI) of a report and we don’t know that. This is a common case in a development scenario. Therefore I developed a tiny approach which detects all dynpro fields of a development class and delivers it as a csv file. On this way it is possible to create a list at a certain time and at a later time too. Now the two files can be compared to find the differences. If none differences are available, we can assume that the test processes continue to work respectively not abort based on a UI change.

The following report delivers in the first column the development class, in the second the report name and in the third the dynpro number. In the fourth the dynpro name and in the fifth the field name. In the sixth the field type and in the last column the field text. Here an example of the GUIBIBS transaction.

That is exactly what we see in the SAP GUI Scripting hierarchy.

Here now the report. It is necessary to define the development class and the destination file name at the selection screen.

"-Begin-----------------------------------------------------------------
REPORT z_export_fields.



  INCLUDE MSEUSBIT.



  DATA: BEGIN OF id,
          p TYPE progname,
          d TYPE sydynnr,
        END OF id.

  TYPES: BEGIN OF ty_id,
           prog TYPE progname,
           dnum TYPE sydynnr,
         END OF ty_id.

  TYPES: BEGIN OF ty_prog,
           object   TYPE trobjtype,
           devclass TYPE devclass,
           obj_name TYPE sobj_name,
         END OF ty_prog.

  TYPES: BEGIN OF ty_res,
           devclass   TYPE devclass,     "Development Class
           prog       TYPE progname,     "Programname
           obj_type   TYPE trobjtype,    "PROG or FUGR
           dnum       TYPE sychar04,     "Dynpro-Number
           cupo       TYPE fnam_____4,   "Dynpro-Name
           fname      TYPE fnam_____4,   "Fieldname
           type_short TYPE scrfgtyp,     "Fieldtype short
           type_long  TYPE scrfgtyp,     "Fieldtype long
           stext      TYPE stxt_____1,   "Fieldtext
           ddicfield  TYPE boolean,      "Flag if data dictionary field
           rollname   TYPE rollname,     "Data element
           checktable TYPE checktable,   "Table name of the foreign key
           inttype    TYPE inttype,      "ABAP data type
           intlen     TYPE intlen,       "Length in Bytes
         END OF ty_res.

  DATA:
    lv_header         TYPE d020s,
    ls_field          TYPE d021s,
    lt_field          TYPE TABLE OF d021s,
    lt_flow_logic     TYPE TABLE OF d022s,
    lt_matchcode_info TYPE TABLE OF d023s,
    ls_id             TYPE ty_id,
    lt_id             TYPE STANDARD TABLE OF ty_id,
    ls_res            TYPE ty_res,
    lt_res            TYPE STANDARD TABLE OF ty_res,
    lv_res_fname      TYPE fnam_____4,
    lv_file           TYPE string,
    ls_prog           TYPE ty_prog,
    lt_prog           TYPE STANDARD TABLE OF ty_prog,
    lv_tablename      TYPE tabname,
    lv_fieldname      TYPE fieldname,
    ls_dd03l          TYPE dd03l,
    lv_off            TYPE i,
    lv_len            TYPE i.

  FIELD-SYMBOLS:
    <ls_prog>  TYPE ty_prog,
    <ls_res>   TYPE ty_res.



  SELECTION-SCREEN BEGIN OF SCREEN 1001.
    SELECTION-SCREEN BEGIN OF LINE.
      SELECTION-SCREEN COMMENT 1(30) cm_devcl FOR FIELD p_devcl.
      PARAMETERS: p_devcl TYPE DEVCLASS OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
      SELECTION-SCREEN COMMENT 1(30) cm_file FOR FIELD p_file.
      PARAMETERS: p_file TYPE sapb-sappfad OBLIGATORY LOWER CASE.
    SELECTION-SCREEN END OF LINE.
  SELECTION-SCREEN END OF SCREEN 1001.

  CALL SELECTION-SCREEN 1001.



  INITIALIZATION.
    cm_devcl = 'Development Class:'.
    cm_file = 'Filename:'.



  START-OF-SELECTION.

    "-Select programs (PROG) and function groups (FUGR)-----------------
    SELECT object, devclass, obj_name
      FROM TADIR
      INTO CORRESPONDING FIELDS OF TABLE @lt_prog
      WHERE devclass LIKE @p_devcl AND
        ( object = 'PROG' OR object = 'FUGR' )
      ORDER BY devclass, obj_name.
    CHECK sy-subrc = 0.

    "-Modify program names of function groups---------------------------
    LOOP AT lt_prog ASSIGNING <ls_prog>.
      CHECK <ls_prog>-object = 'FUGR'.
      IF <ls_prog>-obj_name(1) = '/'.
        FIND FIRST OCCURRENCE OF REGEX '(?!.*\/).*' IN <ls_prog>-obj_name
          MATCH OFFSET lv_off MATCH LENGTH lv_len.
        <ls_prog>-obj_name = <ls_prog>-obj_name+0(lv_off) && 'SAPL' &&
          <ls_prog>-obj_name+lv_off(lv_len).
        CONDENSE <ls_prog>-obj_name.
      ELSE.
        <ls_prog>-obj_name = 'SAPL' && <ls_prog>-obj_name.
      ENDIF.
    ENDLOOP.

    LOOP AT lt_prog INTO ls_prog.

      SELECT prog, dnum
        FROM D020S
        INTO CORRESPONDING FIELDS OF TABLE @lt_id
        WHERE prog = @ls_prog-obj_name
        ORDER BY prog, dnum.
      CHECK sy-subrc = 0.

      LOOP AT lt_id INTO ls_id.

        id-p = ls_id-prog.
        id-d = ls_id-dnum.

        "-Gets data from DYNPSOURCE table-------------------------------
        IMPORT DYNPRO lv_header lt_field lt_flow_logic lt_matchcode_info ID id.

        LOOP AT lt_field INTO ls_field.

          ls_res-devclass = ls_prog-devclass.
          ls_res-prog = lv_header-prog.
          ls_res-obj_type = ls_prog-object.
          ls_res-dnum = lv_header-dnum.
          ls_res-cupo = lv_header-cupo.
          ls_res-fname = ls_field-fnam.
          IF ls_field-stxt CN '_ '.
            ls_res-stext = ls_field-stxt.
          ELSE.
            ls_res-stext = ''.
          ENDIF.

          CALL FUNCTION 'RS_SCRP_GET_FIELD_TYPE_TEXT'
            EXPORTING
              field = ls_field
              text_kind = 'SHORT'
            IMPORTING
              field_type_without_modif = ls_res-type_short
            EXCEPTIONS
              OTHERS = 1.
          TRANSLATE ls_res-type_short TO UPPER CASE.

          CALL FUNCTION 'RS_SCRP_GET_FIELD_TYPE_TEXT'
            EXPORTING
              field = ls_field
            IMPORTING
              field_type_without_modif = ls_res-type_long
            EXCEPTIONS
              OTHERS = 1.

          IF ls_field-flg1 O FLG1DDF.
            CASE ls_res-type_short.
              WHEN 'I/O' OR 'TEXT' OR 'OK' OR 'CHECK' OR 'RADIO'.
                ls_res-ddicfield = abap_true.
              WHEN OTHERS.
                ls_res-ddicfield = abap_false.
            ENDCASE.
          ELSE.
            ls_res-ddicfield = abap_false.
          ENDIF.

          APPEND ls_res TO lt_res.

        ENDLOOP.

      ENDLOOP.

    ENDLOOP.



    LOOP AT lt_res ASSIGNING <ls_res> WHERE ddicfield = abap_true.
      IF <ls_res>-fname(1) = '*'.
        lv_len = strlen( <ls_res>-fname ) - 1.
        lv_res_fname = <ls_res>-fname+1(lv_len).
      ELSE.
        lv_res_fname = <ls_res>-fname.
      ENDIF.
      SPLIT lv_res_fname AT '-' INTO lv_tablename lv_fieldname.
      SELECT SINGLE tabname, fieldname, as4local, rollname, checktable,
        inttype, intlen
        FROM dd03l
        INTO CORRESPONDING FIELDS OF @ls_dd03l
        WHERE tabname = @lv_tablename AND
          fieldname = @lv_fieldname AND
          as4local = 'A'.
      CHECK sy-subrc = 0.
      <ls_res>-rollname = ls_dd03l-rollname.
      <ls_res>-checktable = ls_dd03l-checktable.
      <ls_res>-inttype = ls_dd03l-inttype.
      <ls_res>-intlen = ls_dd03l-intlen.
    ENDLOOP.



    lv_file = p_file.

    Call Method cl_gui_frontend_services=>gui_download
      EXPORTING
        filename                  = lv_file
        filetype                  = 'ASC'
        write_field_separator     = 'X'
        trunc_trailing_blanks     = 'X'
        trunc_trailing_blanks_eol = 'X'
      CHANGING
        data_tab                  = lt_res
      EXCEPTIONS
        others                    = 1.

"-End-------------------------------------------------------------------

If you use this approach with SAP eCATT you can execute it on any connected SAP system. On this way we use it in our development landscape, to detect SAP GUI differences between maintenance and development systems.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.