ABAP Editor/Workbench Custom Dynamic Patterns
In my last post ABAP Editor dynamic patterns, We saw how we can
use the patterns to our advantage.
Today, I wanted to expand upon further features of dynamic patterns, which is the ability to write and add your own dynamic patterns.
Let's say you want to define a template for the generation of DB validation code and provide your table name as input.
Select Utilities > More Utilities > Edit Pattern > Create Pattern and enter a name for your pattern.

You will be presented with a text editor screen, Add the following code:
*$&$MUSTER
The above code tells the runtime to call a function module with the naming convention:
<pattern_name>_editor_exit. >
The next obvious step is to create the FM with the above-discussed name.
The FM has a defined interface of a TABLES parameter BUFFER of type RSWSOURCET.
The table is used to pass back the code to the editor.

Insert Below code in the source code tab.

Input table name:
Offcourse, You can expand upon it or create your own pattern with extra functionalities.
As always, Hope you like the post and use the information in your day-to-day work.
Today, I wanted to expand upon further features of dynamic patterns, which is the ability to write and add your own dynamic patterns.
Let's say you want to define a template for the generation of DB validation code and provide your table name as input.
Creating the Pattern.
From the ABAP editor,Select Utilities > More Utilities > Edit Pattern > Create Pattern and enter a name for your pattern.
Type name for the pattern:
You will be presented with a text editor screen, Add the following code:
*$&$MUSTER
The above code tells the runtime to call a function module with the naming convention:
<pattern_name>_editor_exit. >
The next obvious step is to create the FM with the above-discussed name.
The FM has a defined interface of a TABLES parameter BUFFER of type RSWSOURCET.
The table is used to pass back the code to the editor.
Insert Below code in the source code tab.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DATA lt_sval TYPE STANDARD TABLE OF sval. | |
DATA ls_sval TYPE sval. | |
DATA: | |
lv_ret TYPE char1, | |
lv_buffer TYPE LINE OF rswsourcet. | |
"Get tablename using Popup. | |
ls_sval-tabname = 'DD02L'. | |
ls_sval-fieldname = 'TABNAME'. | |
ls_sval-field_attr = '00'. | |
APPEND ls_sval TO lt_sval. | |
CALL FUNCTION 'POPUP_GET_VALUES_DB_CHECKED' | |
EXPORTING popup_title = 'Table Name' | |
IMPORTING returncode = lv_ret | |
TABLES fields = lt_sval | |
EXCEPTIONS OTHERS = 2. | |
IF sy-subrc <> 0. | |
RETURN. | |
ENDIF. | |
READ TABLE lt_sval INTO ls_sval INDEX 1. | |
IF syst-subrc <> 0. | |
RETURN. | |
ENDIF. | |
"Create COde.. | |
lv_buffer = '"Validate Input against Table:' && ` ` && ls_sval-value. | |
APPEND lv_buffer TO buffer. | |
APPEND 'Select COUNT(*)' TO buffer. | |
APPEND ' UPTO 1 ROWS' TO buffer. | |
lv_buffer = | FROM { to_upper( ls_sval-value ) } |. | |
APPEND lv_buffer TO buffer. | |
APPEND ' WHERE col_name = p_inp.' TO buffer. | |
APPEND '"Error Handling.' TO buffer. | |
APPEND 'IF SYST-DBCNT <> 1.' TO buffer. | |
APPEND ' MESSAGE E000(DB) WITH ''No data fround for input.''.' TO buffer. | |
APPEND 'ENDIF.' TO buffer. |
Call the new pattern:
Input table name:
Generated Code:
So there you have it, Your own Dynamic pattern to help you out with writing DB
Existence check.
Offcourse, You can expand upon it or create your own pattern with extra functionalities.
As always, Hope you like the post and use the information in your day-to-day work.