Problem solve Get help with specific problems with your technologies, process and projects.

Dynamic pattern in ABAP Editor

This tip will allow you to add a new pattern in Se38 Editor.

This tip will allow you to add a new pattern in Se38 Editor. This example asks the programmer for a function module...

and generates the data declarations of the import/export/changing and table parameters. Step 1. Create a pattern in ABAP Editor. Menu: Utilities > More utilities > Edit Pattern > Create pattern

Step 2. Create dynamic pattern.
In the pattern editor, go to dynamic. Menu: Pattern > dynamic.

Change the word EXIT for MUSTER. This means you are going to use a function where you are going to program the logic of the pattern.

Step 3. Create the function <PATTERN>_EDITOR_EXIT

In this example (pattern is called ZFUNCTION), a pattern that creates automatically the data declaration of the import, export, changing and table parameters of a function.

Source code of function module:

FUNCTION ZFUNCTION_EDITOR_EXIT.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  TABLES
*"      BUFFER STRUCTURE  ABAPSOURCE
*"----------------------------------------------------------------------

*-- ask for function name


  TABLES: fupararef.

  data: tbl_fupararef type fupararef occurs 0 with header line.

  DATA: L_LIN1(72),
        l_lin2(72),
        name(30).

  data:  it_fields type sval occurs 0 with header line.

  refresh: it_fields. clear it_fields.

  it_fields-tabname = 'FUPARAREF'.
  it_fields-fieldname = 'FUNCNAME'.
  it_fields-field_obl = 'X'.
  append it_fields. clear it_fields.

  call function 'POPUP_GET_VALUES'
       EXPORTING
            popup_title     = 'Function Name'
            start_column    = '5'
            start_row       = '5'
       TABLES
            fields          = it_fields
       EXCEPTIONS
            error_in_fields = 1
            others          = 2.

  CHECK SY-SUBRC = 0.


  read table it_fields index 1.
  SELECT        * FROM  fupararef into table tbl_fupararef
         WHERE  funcname  = it_fields-VALUE.

  loop at   tbl_fupararef.

    CLEAR: L_LIN1, name, l_lin2.
    CASE tbl_fupararef-PARAMTYPE.
      WHEN 'E' OR 'I'.
        if  tbl_fupararef-STRUCTURE ne space.
          L_LIN1 = 'DATA: &1 TYPE &2 .'.
        else.
          L_LIN1 = 'DATA: &1 .'.
        endif.

        refresh: it_fields. clear it_fields.
        CONCATENATE 'L' tbl_fupararef-PARAMETER into it_fields-value
              separated by '_'.

        it_fields-tabname = 'DD03L'.
        it_fields-fieldname = 'FIELDNAME'.
        it_fields-field_obl = 'X'.
        append it_fields. clear it_fields.


        call function 'POPUP_GET_VALUES'
             EXPORTING
                  popup_title     = 'Parameter Name'
                  start_column    = '5'
                  start_row       = '5'
             TABLES
                  fields          = it_fields
             EXCEPTIONS
                  error_in_fields = 1
                  others          = 2.

        read table it_fields index 1.


      WHeN 'T'.
        L_LIN1 = 'DATA: &1 TYPE &2'.
        l_lin2 = 'OCCURS 0 WITH HEADER LINE.'.
        refresh: it_fields. clear it_fields.
        CONCATENATE 'TBL' tbl_fupararef-PARAMETER into
                 it_fields-value
       separated by '_'.
        it_fields-tabname = 'DD03L'.
        it_fields-fieldname = 'FIELDNAME'.
        it_fields-field_obl = 'X'.
        append it_fields. clear it_fields.


        call function 'POPUP_GET_VALUES'
             EXPORTING
                  popup_title     = 'Internal Table Name'
                  start_column    = '5'
                  start_row       = '5'
             TABLES
                  fields          = it_fields
             EXCEPTIONS
                  error_in_fields = 1
                  others          = 2.

        read table it_fields index 1.


      when others.
        check 1 = 2.
    ENDCASE.

    REPLACE '&1' WITH it_fields-value(25) INTO L_LIN1.
    condense L_LIN1.

    REPLACE '&2' WITH tbl_fupararef-STRUCTURE(29) INTO L_LIN1.
    condense L_LIN1.

    aPPEND L_LIN1 TO BUFFER.
    if L_LIN2 ne space.
      APPEND L_LIN2 TO BUFFER.
    endif.
  ENDloop.


  CALL FUNCTION 'FUNCTION_STUB_GENERATE'
    EXPORTING
      FUNCNAME                 = tbl_fupararef-funcname
*     IC_MODE                  = 'X'
    TABLES
      SOURCE                   = BUFFER
*   EXCEPTIONS
*     FUNCTION_NOT_EXIST       = 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.

ENDFUNCTION.
This was last published in May 2005

Dig Deeper on SAP ABAP

PRO+

Content

Find more PRO+ content and other member only offers, here.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close