ABAP Editor: Create custom Pattern

0
484

Ever got frustrated with typing the same set of commands (like select-options, case, if condition, etc.) or comments (like header comments, insertion comments in between, etc.) ?

SAP provide and option called as ‘Pattern’ in ABAP Editor to reduce this redundant work. Pattern can be of two types, Static pattern and Dynamic pattern.

Create Pattern (common step for static & dynamic types)
Create Pattern (common step for static & dynamic types)

Steps for creating STATIC PATTERN:

1. Goto Menu: Utilities > More utilities > Edit Pattern > Create pattern. Specify the Name & layout of the the pattern. save the pattern.

Steps for creating DYNAMIC PATTERN:

1. First you have to create a pattern which contains only one line: *$&$MUSTER, using the path as specified in the creating static pattern.

2. Then create a function module with the name of the pattern followed by ‘_editor_exit’.

3. Add a tables parameter. parameter name: BUFFER type spec.: LIKE reference type: ABAPSOURCE. In the source you can add anything you like to the buffer table, upon executing the pattern in your ABAP, it copies everything you put in it. This is the result of the pattern I use:
*#######################################################################
* Report :
* Version : 1.00
* Author :
* Function : Developer Department :ABAP
* Date : 05.05.2003
*———————————————————————–
* Title :
* Purpose :
* Details :
*=======================================================================
* Change History
*———————————————————————–
* Correction on version : 1.00
* New version : 1.01
* Author :
* Date :
* Reason :
* Change :
*#######################################################################

And the code for this is :
FUNCTION zips_model_header_editor_exit .

*”———————————————————————-*”
*”Lokale interface:
*” TABLES
*” BUFFER STRUCTURE ABAPSOURCE
*”———————————————————————-*
DATA: l_commentline1 LIKE LINE OF buffer,
l_commentline2 LIKE LINE OF buffer,
l_commentline3 LIKE LINE OF buffer,
l_firstname LIKE adrp-name_first,
l_lastname LIKE adrp-name_last,
l_function LIKE adcp-function,
l_department LIKE adcp-department,
l_datum(10).

TABLES: usr21, “Assign user name address key
adrp, “Persons (central address administration)
adcp. “Person/Address assignment (central address administration)

*additional:, although using the comment charater ‘”‘, the system
* converts it to ‘*’
CONCATENATE ‘”##############################’ ‘#########################################’ INTO l_commentline1.
CONCATENATE ‘”————————————‘ ‘———————————–‘ INTO l_commentline2.
CONCATENATE ‘”==================================’ ‘=====================================’ INTO l_commentline3.

buffer = l_commentline1.
APPEND buffer.
buffer = ‘* Report : ‘.
APPEND buffer.
buffer = ‘* Version : 1.00’.
APPEND buffer.
* initialize first and last name, if not found in database l_firstname = ‘first name’.
l_lastname = ‘last name’.
* retrieval of first and last name in database
SELECT SINGLE * FROM usr21 WHERE bname = sy-uname.
IF sy-subrc = 0.
 SELECT SINGLE * FROM adrp WHERE persnumber = usr21-persnumber.
 IF sy-subrc = 0.
  l_firstname = adrp-name_first.
  l_lastname = adrp-name_last.
* retrtieval of function and department of user
  SELECT SINGLE * FROM adcp WHERE persnumber = usr21-persnumber.
  IF sy-subrc = 0.
   l_function = adcp-function.
   l_department = adcp-department.
  ENDIF.
 ENDIF.
ENDIF.

CONCATENATE ‘* Author :’ sy-uname’ -‘ l_firstname l_lastname INTO buffer SEPARATED BY space.
APPEND buffer.
CONCATENATE ‘* Function :’ l_function ‘ Department :’ l_department INTO buffer SEPARATED BY space.
APPEND buffer.
WRITE sy-datum DD/MM/YYYY TO l_datum.
CONCATENATE ‘* Date : ‘ l_datum INTO buffer SEPARATED BY space.
APPEND buffer.
buffer = l_commentline2.
APPEND buffer.
buffer = ‘* Title : ‘. APPEND buffer.
buffer = ‘* Purpose : ‘.
APPEND buffer.
buffer = ‘* Details : ‘.
APPEND buffer.
buffer = l_commentline3.
APPEND buffer.
buffer = ‘* Change History’.
APPEND buffer.
buffer = l_commentline2.
APPEND buffer.
buffer = ‘* Correction on version : 1.00’.
APPEND buffer.
buffer = ‘* New version : 1.01’.
APPEND buffer.
buffer = ‘* Author :’.
APPEND buffer.
buffer = ‘* Date :’.
APPEND buffer.
buffer = ‘* Reason :’.
APPEND buffer.
buffer = ‘* Change :’.
APPEND buffer.
buffer = l_commentline1.
APPEND buffer.

ENDFUNCTION.

 

Steps to apply Patterns:

1. Select Pattern on Editor Screen.

Click Pattern
Click Pattern

2. Select Other Pattern radio-button in the dialog box and enter/select your custom Pattern.

Enter Pattern Name
Enter Pattern Name

3. Click ok to apply the Pattern in the code.

 

Apply Pattern
Apply Pattern

Thats it ! Custom Pattern gets inserted.

 

*source = Joyjit Ghosh

LEAVE A REPLY

Please enter your comment!
Please enter your name here