I would like to talk about creating our own dynamic patterns in the ABAP Editor and calling it via the "Pattern" button. In this write-u,p I will explain how to create a dynamic pattern for the "TYPES" statement in ABAP.
With Dynamic Pattern we can insert code into our program using the pattern option. This functionality is used each time we insert a function call.
This menu option is reached via the menu path SE38->Edit->Pattern*:*By entering a function module name or selecting one of the other options SAP will automatically enter the correct code into your program enabling you to just "fill in the blanks".
One of the things which we enter in any report program is what is called the Model Log i.e. Program header and procedure headers as a pattern using the Pattern Editor (SE38->Utilities->More Utilities->Edit Pattern_)._You provide a pattern name (such as 'Header'), enter the text using SE38, save it and then use it. By selecting the 'Other Pattern' radio button in the pattern selection window shown above and entering your pattern name in the relevant field, the lines of text you have defined will be entered into your source code at the current cursor location.
This works fine for static patterns i.e. patterns that do not have any variable text in them. However, we can do the same work with dynamic pattern, again a header which automatically fills in the various fields.
Steps to create DYNAMIC PATTERN:
1. Creation of pattern Menu -> SE38 Editor->Utilities->More Utilities->Edit Pattern->Create Pattern.
We will get this popup,
2) Then Pattern->Dynamic Pattern
The pattern name I gave is ZDYPAT01.The pattern should contain only one line of text:
Code: *$&$MUSTER or *$&$EXIT.A) When *$&$MUSTER.*If the pattern contains *$&$MUSTER at the start of line 1, then we have to create a Function module that is called. *Creation of function module:
Create a function module having a name exactly like <Pattern name>_editor_exit.Here the Function Module Name would be ZDYPAT01_EDITOR_EXIT. The function module should have a single
table parameter of structure RSWSOURCET. Anything that you place in this table will be copied back to your source.
3. Test Program calling the pattern:
Create a program in SE38.Click on the Pattern button and select the Other pattern radio button. Enter the pattern created by you in the input box and press ENTER.
The following popup screen will be displayed.
The following features are possible in this application.
*1.*You can include another type within your type by inputting the "Include Type" name.
*2.*Entering the table name and clicking on the "LIST" button will populate the fieldnames of the table along with their data elements.
*3.*You can edit the fieldnames as per your requirements.Clicking the 'ADD" button below the ALV grid will add the fields to the type.The "UNDO" button will clear the fields added to the type.
*4.*Clicking the "CONTINUE" arrow will insert the generated type within your program. *5.*Clicking the "CANCEL" cross will exit the popup box and clear the selection.
A sample test program is as shown below. Report ZTEST.
TYPES BEGIN OF t_purchase .
TYPES rejection TYPE abskz .
TYPES release TYPE abueb .
INCLUDE TYPE ekko .
TYPES END OF t_purchase . NOTE:
1) The DB table to look at to see the SAP patterns is TSE05. Upto 6.20 the pattern width was 72 characters, the same width in TSE05.
After this the dynamic pattern is of type string, so can be of greater length.
2) You can transport your created pattern by clicking on the "Transport" option
in the pattern editor