abapgit-agent 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/abap/guidelines/00_index.md +35 -0
- package/abap/guidelines/01_sql.md +72 -0
- package/abap/guidelines/02_exceptions.md +108 -0
- package/abap/guidelines/03_testing.md +252 -0
- package/abap/guidelines/04_cds.md +120 -0
- package/abap/guidelines/05_classes.md +50 -0
- package/abap/guidelines/06_objects.md +103 -0
- package/abap/guidelines/07_json.md +22 -0
- package/abap/guidelines/08_abapgit.md +193 -0
- package/bin/abapgit-agent +467 -30
- package/bin/abgagt +24 -0
- package/package.json +8 -2
- package/src/abap-client.js +65 -2
- package/src/agent.js +57 -3
- package/src/ref-search.js +989 -0
- package/.abapGitAgent.example +0 -11
- package/.github/workflows/release.yml +0 -60
- package/API.md +0 -710
- package/CLAUDE.md +0 -1058
- package/CLAUDE_MEM.md +0 -88
- package/ERROR_HANDLING.md +0 -30
- package/INSTALL.md +0 -155
- package/RELEASE_NOTES.md +0 -143
- package/abap/CLAUDE.md +0 -1010
- package/abap/copilot-instructions.md +0 -79
- package/abap/package.devc.xml +0 -10
- package/abap/zcl_abgagt_agent.clas.abap +0 -420
- package/abap/zcl_abgagt_agent.clas.xml +0 -15
- package/abap/zcl_abgagt_cmd_factory.clas.abap +0 -48
- package/abap/zcl_abgagt_cmd_factory.clas.xml +0 -15
- package/abap/zcl_abgagt_command_create.clas.abap +0 -95
- package/abap/zcl_abgagt_command_create.clas.xml +0 -15
- package/abap/zcl_abgagt_command_import.clas.abap +0 -138
- package/abap/zcl_abgagt_command_import.clas.xml +0 -15
- package/abap/zcl_abgagt_command_inspect.clas.abap +0 -456
- package/abap/zcl_abgagt_command_inspect.clas.testclasses.abap +0 -121
- package/abap/zcl_abgagt_command_inspect.clas.xml +0 -16
- package/abap/zcl_abgagt_command_preview.clas.abap +0 -386
- package/abap/zcl_abgagt_command_preview.clas.xml +0 -15
- package/abap/zcl_abgagt_command_pull.clas.abap +0 -80
- package/abap/zcl_abgagt_command_pull.clas.testclasses.abap +0 -87
- package/abap/zcl_abgagt_command_pull.clas.xml +0 -16
- package/abap/zcl_abgagt_command_tree.clas.abap +0 -237
- package/abap/zcl_abgagt_command_tree.clas.xml +0 -15
- package/abap/zcl_abgagt_command_unit.clas.abap +0 -297
- package/abap/zcl_abgagt_command_unit.clas.xml +0 -15
- package/abap/zcl_abgagt_command_view.clas.abap +0 -240
- package/abap/zcl_abgagt_command_view.clas.xml +0 -15
- package/abap/zcl_abgagt_resource_create.clas.abap +0 -71
- package/abap/zcl_abgagt_resource_create.clas.xml +0 -15
- package/abap/zcl_abgagt_resource_health.clas.abap +0 -25
- package/abap/zcl_abgagt_resource_health.clas.xml +0 -15
- package/abap/zcl_abgagt_resource_import.clas.abap +0 -66
- package/abap/zcl_abgagt_resource_import.clas.xml +0 -15
- package/abap/zcl_abgagt_resource_inspect.clas.abap +0 -63
- package/abap/zcl_abgagt_resource_inspect.clas.xml +0 -15
- package/abap/zcl_abgagt_resource_preview.clas.abap +0 -67
- package/abap/zcl_abgagt_resource_preview.clas.xml +0 -15
- package/abap/zcl_abgagt_resource_pull.clas.abap +0 -71
- package/abap/zcl_abgagt_resource_pull.clas.xml +0 -15
- package/abap/zcl_abgagt_resource_tree.clas.abap +0 -70
- package/abap/zcl_abgagt_resource_tree.clas.xml +0 -15
- package/abap/zcl_abgagt_resource_unit.clas.abap +0 -64
- package/abap/zcl_abgagt_resource_unit.clas.xml +0 -15
- package/abap/zcl_abgagt_resource_view.clas.abap +0 -68
- package/abap/zcl_abgagt_resource_view.clas.xml +0 -15
- package/abap/zcl_abgagt_rest_handler.clas.abap +0 -32
- package/abap/zcl_abgagt_rest_handler.clas.xml +0 -15
- package/abap/zcl_abgagt_util.clas.abap +0 -93
- package/abap/zcl_abgagt_util.clas.testclasses.abap +0 -84
- package/abap/zcl_abgagt_util.clas.xml +0 -16
- package/abap/zcl_abgagt_viewer_clas.clas.abap +0 -58
- package/abap/zcl_abgagt_viewer_clas.clas.xml +0 -15
- package/abap/zcl_abgagt_viewer_ddls.clas.abap +0 -83
- package/abap/zcl_abgagt_viewer_ddls.clas.xml +0 -15
- package/abap/zcl_abgagt_viewer_dtel.clas.abap +0 -98
- package/abap/zcl_abgagt_viewer_dtel.clas.xml +0 -15
- package/abap/zcl_abgagt_viewer_factory.clas.abap +0 -41
- package/abap/zcl_abgagt_viewer_factory.clas.xml +0 -15
- package/abap/zcl_abgagt_viewer_intf.clas.abap +0 -58
- package/abap/zcl_abgagt_viewer_intf.clas.xml +0 -15
- package/abap/zcl_abgagt_viewer_stru.clas.abap +0 -59
- package/abap/zcl_abgagt_viewer_stru.clas.xml +0 -15
- package/abap/zcl_abgagt_viewer_tabl.clas.abap +0 -59
- package/abap/zcl_abgagt_viewer_tabl.clas.xml +0 -15
- package/abap/zcl_abgagt_viewer_ttyp.clas.abap +0 -93
- package/abap/zcl_abgagt_viewer_ttyp.clas.xml +0 -15
- package/abap/zif_abgagt_agent.intf.abap +0 -53
- package/abap/zif_abgagt_agent.intf.xml +0 -15
- package/abap/zif_abgagt_cmd_factory.intf.abap +0 -7
- package/abap/zif_abgagt_cmd_factory.intf.xml +0 -15
- package/abap/zif_abgagt_command.intf.abap +0 -26
- package/abap/zif_abgagt_command.intf.xml +0 -15
- package/abap/zif_abgagt_util.intf.abap +0 -28
- package/abap/zif_abgagt_util.intf.xml +0 -15
- package/abap/zif_abgagt_viewer.intf.abap +0 -12
- package/abap/zif_abgagt_viewer.intf.xml +0 -15
- package/docs/commands.md +0 -142
- package/docs/create-command.md +0 -129
- package/docs/health-command.md +0 -89
- package/docs/import-command.md +0 -195
- package/docs/init-command.md +0 -189
- package/docs/inspect-command.md +0 -169
- package/docs/list-command.md +0 -289
- package/docs/preview-command.md +0 -528
- package/docs/pull-command.md +0 -202
- package/docs/status-command.md +0 -68
- package/docs/tree-command.md +0 -303
- package/docs/unit-command.md +0 -167
- package/docs/view-command.md +0 -501
- package/img/claude.png +0 -0
- package/scripts/claude-integration.js +0 -351
- package/scripts/release.js +0 -298
- package/scripts/release.sh +0 -60
- package/scripts/test-integration.js +0 -139
- package/scripts/unrelease.js +0 -277
package/abap/CLAUDE.md
DELETED
|
@@ -1,1010 +0,0 @@
|
|
|
1
|
-
# ABAP Project Guidelines - Template
|
|
2
|
-
|
|
3
|
-
This file provides guidelines for **generating ABAP code** in abapGit repositories.
|
|
4
|
-
|
|
5
|
-
**Use this file as a template**: Copy it to your ABAP repository root when setting up new projects with Claude Code.
|
|
6
|
-
|
|
7
|
-
## Quick Reference
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
# After editing ABAP files:
|
|
11
|
-
git add . && git commit -m "feat: description" && git push
|
|
12
|
-
abapgit-agent pull --files abap/zcl_my_class.clas.abap
|
|
13
|
-
|
|
14
|
-
# If pull fails with syntax error:
|
|
15
|
-
abapgit-agent inspect --files abap/zcl_my_class.clas.abap
|
|
16
|
-
|
|
17
|
-
# Explore tables/views:
|
|
18
|
-
abapgit-agent preview --objects ZTABLE
|
|
19
|
-
abapgit-agent view --objects ZTABLE --type TABL
|
|
20
|
-
abapgit-agent tree --package $MY_PACKAGE
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Common Workflow
|
|
24
|
-
|
|
25
|
-
1. Generate/edit ABAP code
|
|
26
|
-
2. Push to git: `git add . && git commit && git push`
|
|
27
|
-
3. Activate in ABAP: `abapgit-agent pull --files file.clas.abap`
|
|
28
|
-
4. Check for errors - fix if needed
|
|
29
|
-
5. Repeat
|
|
30
|
-
|
|
31
|
-
## ABAP Syntax Validation
|
|
32
|
-
|
|
33
|
-
This is an ABAP project. **Do not attempt local syntax validation** - ABAP code can only be validated in an SAP system.
|
|
34
|
-
|
|
35
|
-
**To validate ABAP code:**
|
|
36
|
-
|
|
37
|
-
1. After generating code, push changes to git
|
|
38
|
-
2. Pull only changed files (fast):
|
|
39
|
-
```bash
|
|
40
|
-
abapgit-agent pull --files abap/zcl_my_class.clas.abap
|
|
41
|
-
```
|
|
42
|
-
Or pull all files:
|
|
43
|
-
```bash
|
|
44
|
-
abapgit-agent pull
|
|
45
|
-
```
|
|
46
|
-
3. Review activation results carefully
|
|
47
|
-
4. **"Error updating where-used list" = SYNTAX ERROR** - This is NOT a warning!
|
|
48
|
-
5. If Failed Objects > 0, there are syntax errors - fix them before proceeding
|
|
49
|
-
|
|
50
|
-
## Inspect Command (Syntax Check)
|
|
51
|
-
|
|
52
|
-
Use the `inspect` command to perform syntax validation on ABAP objects and CDS views.
|
|
53
|
-
|
|
54
|
-
### Usage
|
|
55
|
-
```bash
|
|
56
|
-
# Syntax check single file
|
|
57
|
-
abapgit-agent inspect --files abap/zcl_my_class.clas.abap
|
|
58
|
-
|
|
59
|
-
# Syntax check multiple files
|
|
60
|
-
abapgit-agent inspect --files abap/zcl_class1.clas.abap,abap/zcl_class2.clas.abap
|
|
61
|
-
|
|
62
|
-
# Syntax check CDS view
|
|
63
|
-
abapgit-agent inspect --files abap/zc_my_view.ddls.asddls
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Supported Object Types
|
|
67
|
-
|
|
68
|
-
| Type | Description | Validation Method |
|
|
69
|
-
|------|-------------|------------------|
|
|
70
|
-
| CLAS | Class | Code Inspector (SCI) |
|
|
71
|
-
| INTF | Interface | Code Inspector (SCI) |
|
|
72
|
-
| PROG | Program | Code Inspector (SCI) |
|
|
73
|
-
| DDLS | CDS View/Entity | DDL Handler |
|
|
74
|
-
|
|
75
|
-
### CDS Views (DDLS) Validation
|
|
76
|
-
|
|
77
|
-
For CDS views, the inspect command uses `CL_DD_DDL_HANDLER_FACTORY`:
|
|
78
|
-
- Checks **inactive version first** (`get_state = 'M'`)
|
|
79
|
-
- Falls back to active version if no inactive version exists
|
|
80
|
-
- Uses `get_errors()` and `get_warnings()` methods for detailed error information
|
|
81
|
-
|
|
82
|
-
### Examples
|
|
83
|
-
|
|
84
|
-
**Passed:**
|
|
85
|
-
```
|
|
86
|
-
✅ CLAS ZCL_MY_CLASS - Syntax check passed
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
**With Warnings:**
|
|
90
|
-
```
|
|
91
|
-
⚠️ DDLS ZC_MY_VIEW - Syntax check passed with warnings (4):
|
|
92
|
-
Line 9 : ParentPackage
|
|
93
|
-
Line 11 : SoftwareComponent
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
**Failed:**
|
|
97
|
-
```
|
|
98
|
-
❌ DDLS ZC_MY_VIEW - Syntax check failed (1 error(s)):
|
|
99
|
-
Line 21, Column 12: Error message text
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## Fast Iteration Workflow
|
|
103
|
-
|
|
104
|
-
For quick ABAP code changes:
|
|
105
|
-
|
|
106
|
-
```bash
|
|
107
|
-
# 1. Make small change to ABAP file
|
|
108
|
-
# 2. Commit and push to git
|
|
109
|
-
git add abap/zcl_my_class.clas.abap
|
|
110
|
-
git commit -m "fix: ..."
|
|
111
|
-
git push # CRITICAL: Push BEFORE pulling!
|
|
112
|
-
|
|
113
|
-
# 3. Pull only changed file (seconds, not minutes)
|
|
114
|
-
abapgit-agent pull --files abap/zcl_my_class.clas.abap
|
|
115
|
-
|
|
116
|
-
# 4. Check for syntax errors (if pull shows "Error updating where-used list")
|
|
117
|
-
abapgit-agent inspect --files abap/zcl_my_class.clas.abap
|
|
118
|
-
|
|
119
|
-
# 5. Repeat until done
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
### Transport Request Support
|
|
123
|
-
|
|
124
|
-
When working with development packages that require transport requests:
|
|
125
|
-
|
|
126
|
-
```bash
|
|
127
|
-
# Pull with specific transport request
|
|
128
|
-
abapgit-agent pull --files abap/zcl_my_class.clas.abap --transport DEVK900001
|
|
129
|
-
|
|
130
|
-
# Pull all files with transport request
|
|
131
|
-
abapgit-agent pull --transport DEVK900001
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
If `--transport` is not specified, abapGit will use its default behavior (create a new transport or use the default transport for the user).
|
|
135
|
-
|
|
136
|
-
**Important:** Only run `abapgit-agent pull` when ABAP code has actually changed. If you're only modifying JavaScript, JSON, or markdown files, skip the pull step.
|
|
137
|
-
|
|
138
|
-
**Syntax Check Command:**
|
|
139
|
-
When pull shows "Error updating where-used list", use:
|
|
140
|
-
```bash
|
|
141
|
-
abapgit-agent inspect --files abap/zcl_my_class.clas.abap
|
|
142
|
-
```
|
|
143
|
-
This will show detailed syntax errors including line numbers and error messages.
|
|
144
|
-
|
|
145
|
-
## View ABAP Object Definitions
|
|
146
|
-
|
|
147
|
-
Use the `view` command to inspect ABAP object definitions (classes, interfaces, tables, data elements) directly from the ABAP system. **Very useful when working with unfamiliar tables** - shows complete structure including fields, types, and descriptions.
|
|
148
|
-
|
|
149
|
-
```bash
|
|
150
|
-
# View a table definition
|
|
151
|
-
abapgit-agent view --objects ZMY_TABLE --type TABL
|
|
152
|
-
|
|
153
|
-
# View a data element definition
|
|
154
|
-
abapgit-agent view --objects ZMY_DTEL --type DTEL
|
|
155
|
-
|
|
156
|
-
# View a class definition
|
|
157
|
-
abapgit-agent view --objects ZCL_MY_CLASS
|
|
158
|
-
|
|
159
|
-
# View an interface definition
|
|
160
|
-
abapgit-agent view --objects ZIF_MY_INTERFACE
|
|
161
|
-
|
|
162
|
-
# View a table type definition
|
|
163
|
-
abapgit-agent view --objects ZMY_TTYP --type TTYP
|
|
164
|
-
|
|
165
|
-
# View multiple objects
|
|
166
|
-
abapgit-agent view --objects ZCL_CLASS1,ZCL_CLASS2,ZIF_INTERFACE1
|
|
167
|
-
|
|
168
|
-
# JSON output for scripting
|
|
169
|
-
abapgit-agent view --objects ZMY_TABLE --type TABL --json
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### When to Use View Command
|
|
173
|
-
|
|
174
|
-
AI assistant SHOULD call `view` command when:
|
|
175
|
-
|
|
176
|
-
- User asks to "check", "look up", or "explore" an unfamiliar object
|
|
177
|
-
- Working with a table/structure and you don't know the field names/types
|
|
178
|
-
- Calling a class/interface method and you don't know the parameters
|
|
179
|
-
- User provides an object name that may not exist in the git repository
|
|
180
|
-
|
|
181
|
-
**Example workflow:**
|
|
182
|
-
```
|
|
183
|
-
User: "Check if SFLIGHT table has a PRICE field"
|
|
184
|
-
|
|
185
|
-
Assistant: <calls `abapgit-agent view --objects SFLIGHT --type TABL`>
|
|
186
|
-
→ Shows table structure with all fields including PRICE
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
## Explore Package Structure
|
|
190
|
-
|
|
191
|
-
Use the `tree` command to display package hierarchy from ABAP system:
|
|
192
|
-
|
|
193
|
-
```bash
|
|
194
|
-
# Display package hierarchy
|
|
195
|
-
abapgit-agent tree --package $MY_PACKAGE
|
|
196
|
-
|
|
197
|
-
# With object counts
|
|
198
|
-
abapgit-agent tree --package $MY_PACKAGE --include-objects
|
|
199
|
-
|
|
200
|
-
# Limit depth
|
|
201
|
-
abapgit-agent tree --package $MY_PACKAGE --depth 2
|
|
202
|
-
|
|
203
|
-
# JSON output for scripting
|
|
204
|
-
abapgit-agent tree --package $MY_PACKAGE --json
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
**Table Output Example:**
|
|
208
|
-
```
|
|
209
|
-
TABLE ZCAIS_D1:
|
|
210
|
-
|----------------+-----+----------------+----------+----------------+----------------------|
|
|
211
|
-
| Field | Key | Type | Length | Data Elem | Description |
|
|
212
|
-
|----------------+-----+----------------+----------+----------------+----------------------|
|
|
213
|
-
| CLIENT | X | CLNT | 3 | MANDT | Client |
|
|
214
|
-
| ID | X | NUMC | 4 | NUMC4 | Count parameters |
|
|
215
|
-
| NAME | | CHAR | 50 | CHAR50 | Comment |
|
|
216
|
-
|----------------+-----+----------------+----------+----------------+----------------------|
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
**Data Element Output Example:**
|
|
220
|
-
```
|
|
221
|
-
DATA ELEMENT ZMY_DTEL:
|
|
222
|
-
|----------------+----------------+----------+----------------+----------------------|
|
|
223
|
-
| Field | Type | Length | Domain | Description |
|
|
224
|
-
|----------------+----------------+----------+----------------+----------------------|
|
|
225
|
-
| DOMAIN | CHAR | 20 | ZMY_DOMAIN | Domain: ZMY_DOMAIN |
|
|
226
|
-
| DATA_TYPE | CHAR | 10 | | ABAP Type: CHAR |
|
|
227
|
-
| LENGTH | NUMC | 5 | | Length: 20 |
|
|
228
|
-
|----------------+----------------+----------+----------------+----------------------|
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
**Table Type Output Example:**
|
|
232
|
-
```
|
|
233
|
-
📖 ZMY_TTYP (Table Type)
|
|
234
|
-
Table Type ZMY_TTYP in $PACKAGE
|
|
235
|
-
|
|
236
|
-
Line Type: ZMY_STRUCTURE
|
|
237
|
-
Access Mode: STANDARD
|
|
238
|
-
Key Definition: WITH KEY
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
## CLI Commands Reference
|
|
242
|
-
|
|
243
|
-
This section documents the available CLI commands for ABAP development.
|
|
244
|
-
|
|
245
|
-
### Pull Command
|
|
246
|
-
|
|
247
|
-
Pull and activate ABAP objects from git repository.
|
|
248
|
-
|
|
249
|
-
```bash
|
|
250
|
-
# Pull all files
|
|
251
|
-
abapgit-agent pull
|
|
252
|
-
|
|
253
|
-
# Pull specific files (faster)
|
|
254
|
-
abapgit-agent pull --files abap/zcl_my_class.clas.abap
|
|
255
|
-
|
|
256
|
-
# Pull with transport request
|
|
257
|
-
abapgit-agent pull --files abap/zcl_my_class.clas.abap --transport DEVK900001
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
### Inspect Command
|
|
261
|
-
|
|
262
|
-
Run syntax check on ABAP objects.
|
|
263
|
-
|
|
264
|
-
```bash
|
|
265
|
-
# Syntax check single file
|
|
266
|
-
abapgit-agent inspect --files abap/zcl_my_class.clas.abap
|
|
267
|
-
|
|
268
|
-
# Syntax check multiple files
|
|
269
|
-
abapgit-agent inspect --files abap/zcl_class1.clas.abap,abap/zcl_class2.clas.abap
|
|
270
|
-
|
|
271
|
-
# Syntax check CDS view
|
|
272
|
-
abapgit-agent inspect --files abap/zc_my_view.ddls.asddls
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
### Unit Command
|
|
276
|
-
|
|
277
|
-
Run ABAP unit tests.
|
|
278
|
-
|
|
279
|
-
```bash
|
|
280
|
-
# Run unit tests for test class
|
|
281
|
-
abapgit-agent unit --files abap/zcl_my_test.clas.testclasses.abap
|
|
282
|
-
|
|
283
|
-
# Run unit tests for package
|
|
284
|
-
abapgit-agent unit --package $MY_PACKAGE
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
### Tree Command
|
|
288
|
-
|
|
289
|
-
Display package hierarchy.
|
|
290
|
-
|
|
291
|
-
```bash
|
|
292
|
-
# Display package tree
|
|
293
|
-
abapgit-agent tree --package $MY_PACKAGE
|
|
294
|
-
|
|
295
|
-
# With object counts
|
|
296
|
-
abapgit-agent tree --package $MY_PACKAGE --include-objects
|
|
297
|
-
|
|
298
|
-
# JSON output
|
|
299
|
-
abapgit-agent tree --package $MY_PACKAGE --json
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
### View Command
|
|
303
|
-
|
|
304
|
-
View ABAP object definitions directly from the system.
|
|
305
|
-
|
|
306
|
-
```bash
|
|
307
|
-
# View table structure
|
|
308
|
-
abapgit-agent view --objects ZMY_TABLE --type TABL
|
|
309
|
-
|
|
310
|
-
# View class definition
|
|
311
|
-
abapgit-agent view --objects ZCL_MY_CLASS
|
|
312
|
-
|
|
313
|
-
# View CDS view
|
|
314
|
-
abapgit-agent view --objects ZC_MY_CDS_VIEW --type DDLS
|
|
315
|
-
|
|
316
|
-
# JSON output
|
|
317
|
-
abapgit-agent view --objects ZCL_MY_CLASS --json
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
### Preview Command
|
|
321
|
-
|
|
322
|
-
Preview data from tables or CDS views.
|
|
323
|
-
|
|
324
|
-
```bash
|
|
325
|
-
# Preview table data
|
|
326
|
-
abapgit-agent preview --objects SFLIGHT
|
|
327
|
-
|
|
328
|
-
# Preview with row limit
|
|
329
|
-
abapgit-agent preview --objects SFLIGHT --limit 5
|
|
330
|
-
|
|
331
|
-
# Preview with WHERE filter
|
|
332
|
-
abapgit-agent preview --objects SFLIGHT --where "CARRID = 'AA'"
|
|
333
|
-
|
|
334
|
-
# Preview specific columns
|
|
335
|
-
abapgit-agent preview --objects SFLIGHT --columns CARRID,PRICE,FLDATE
|
|
336
|
-
|
|
337
|
-
# Vertical format (for wide tables)
|
|
338
|
-
abapgit-agent preview --objects SFLIGHT --vertical
|
|
339
|
-
|
|
340
|
-
# Compact mode (truncated values)
|
|
341
|
-
abapgit-agent preview --objects SFLIGHT --compact
|
|
342
|
-
|
|
343
|
-
# JSON output
|
|
344
|
-
abapgit-agent preview --objects SFLIGHT --json
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
## JSON Handling - ALWAYS Use /ui2/cl_json
|
|
348
|
-
|
|
349
|
-
**CRITICAL**: Always use `/ui2/cl_json` for JSON serialization and deserialization.
|
|
350
|
-
|
|
351
|
-
**Correct:**
|
|
352
|
-
```abap
|
|
353
|
-
" Deserialize JSON to ABAP structure
|
|
354
|
-
DATA ls_data TYPE ty_request.
|
|
355
|
-
ls_data = /ui2/cl_json=>deserialize( json = lv_json ).
|
|
356
|
-
|
|
357
|
-
" Serialize ABAP structure to JSON
|
|
358
|
-
lv_json = /ui2/cl_json=>serialize( data = ls_response ).
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
**Never use**:
|
|
362
|
-
- Manual string operations (CONCATENATE, SPLIT, etc.)
|
|
363
|
-
- String templates for complex structures
|
|
364
|
-
- Direct assignment without /ui2/cl_json
|
|
365
|
-
|
|
366
|
-
This is enforced by ABAP - manual string operations for JSON parsing will cause type conflicts.
|
|
367
|
-
|
|
368
|
-
## ABAP Class Definition - Must Use PUBLIC
|
|
369
|
-
|
|
370
|
-
**CRITICAL**: Global ABAP classes MUST use `PUBLIC` in the class definition:
|
|
371
|
-
|
|
372
|
-
```abap
|
|
373
|
-
" Correct - global class
|
|
374
|
-
CLASS zcl_my_class DEFINITION PUBLIC.
|
|
375
|
-
...
|
|
376
|
-
ENDCLASS.
|
|
377
|
-
|
|
378
|
-
" Wrong - treated as local class, will fail activation
|
|
379
|
-
CLASS zcl_my_class DEFINITION.
|
|
380
|
-
...
|
|
381
|
-
ENDCLASS.
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
**Error symptom**: `Error updating where-used list for CLAS ZCL_MY_CLASS`
|
|
385
|
-
|
|
386
|
-
**Fix**: Add `PUBLIC` keyword:
|
|
387
|
-
```abap
|
|
388
|
-
CLASS zcl_my_class DEFINITION PUBLIC. " <- PUBLIC required
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
## Interface Method Implementation
|
|
392
|
-
|
|
393
|
-
When implementing interface methods in ABAP classes, use the interface prefix:
|
|
394
|
-
|
|
395
|
-
```abap
|
|
396
|
-
" Interface definition
|
|
397
|
-
INTERFACE zif_my_interface PUBLIC.
|
|
398
|
-
METHODS do_something IMPORTING iv_param TYPE string.
|
|
399
|
-
ENDINTERFACE.
|
|
400
|
-
|
|
401
|
-
" Class implementation - use interface prefix
|
|
402
|
-
CLASS zcl_my_class DEFINITION PUBLIC.
|
|
403
|
-
PUBLIC SECTION.
|
|
404
|
-
INTERFACES zif_my_interface.
|
|
405
|
-
ENDCLASS.
|
|
406
|
-
|
|
407
|
-
CLASS zcl_my_class IMPLEMENTATION.
|
|
408
|
-
METHOD zif_my_interface~do_something. " <- Use interface prefix
|
|
409
|
-
" Implementation here
|
|
410
|
-
ENDMETHOD.
|
|
411
|
-
ENDCLASS.
|
|
412
|
-
```
|
|
413
|
-
|
|
414
|
-
**Wrong**: `METHOD do_something.` - parameter `iv_param` will be unknown
|
|
415
|
-
**Correct**: `METHOD zif_my_interface~do_something.` - parameters recognized
|
|
416
|
-
|
|
417
|
-
## Creating New ABAP Objects - XML Metadata Required
|
|
418
|
-
|
|
419
|
-
**CRITICAL CHECKLIST - Never Forget!**
|
|
420
|
-
|
|
421
|
-
When creating ANY new ABAP object file, you MUST also create its XML metadata file:
|
|
422
|
-
|
|
423
|
-
| ABAP File | Required XML File |
|
|
424
|
-
|-----------|------------------|
|
|
425
|
-
| `zcl_my_class.clas.abap` | `zcl_my_class.clas.xml` |
|
|
426
|
-
| `zif_my_intf.intf.abap` | `zif_my_intf.intf.xml` |
|
|
427
|
-
|
|
428
|
-
**Without XML files**, abapGit will NOT recognize the objects during pull, and they won't be activated.
|
|
429
|
-
|
|
430
|
-
### XML Metadata Format for CLAS
|
|
431
|
-
|
|
432
|
-
For `zcl_abgagt_util.clas.abap`, create `zcl_abgagt_util.clas.xml`:
|
|
433
|
-
|
|
434
|
-
```xml
|
|
435
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
436
|
-
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
|
437
|
-
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
|
438
|
-
<asx:values>
|
|
439
|
-
<VSEOCLASS>
|
|
440
|
-
<CLSNAME>ZCL_ABGAGT_UTIL</CLSNAME>
|
|
441
|
-
<LANGU>E</LANGU>
|
|
442
|
-
<DESCRIPT>Description</DESCRIPT>
|
|
443
|
-
<EXPOSURE>2</EXPOSURE>
|
|
444
|
-
<STATE>1</STATE>
|
|
445
|
-
<UNICODE>X</UNICODE>
|
|
446
|
-
</VSEOCLASS>
|
|
447
|
-
</asx:values>
|
|
448
|
-
</asx:abap>
|
|
449
|
-
</abapGit>
|
|
450
|
-
```
|
|
451
|
-
|
|
452
|
-
### XML Metadata Format for INTF
|
|
453
|
-
|
|
454
|
-
For `zif_abgagt_util.intf.abap`, create `zif_abgagt_util.intf.xml`:
|
|
455
|
-
|
|
456
|
-
```xml
|
|
457
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
458
|
-
<abapGit version="v1.0.0" serializer="LCL_OBJECT_INTF" serializer_version="v1.0.0">
|
|
459
|
-
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
|
460
|
-
<asx:values>
|
|
461
|
-
<VSEOINTERF>
|
|
462
|
-
<CLSNAME>ZIF_ABGAGT_UTIL</CLSNAME>
|
|
463
|
-
<LANGU>E</LANGU>
|
|
464
|
-
<DESCRIPT>Description</DESCRIPT>
|
|
465
|
-
<EXPOSURE>2</EXPOSURE>
|
|
466
|
-
<STATE>1</STATE>
|
|
467
|
-
<UNICODE>X</UNICODE>
|
|
468
|
-
</VSEOINTERF>
|
|
469
|
-
</asx:values>
|
|
470
|
-
</asx:abap>
|
|
471
|
-
</abapGit>
|
|
472
|
-
```
|
|
473
|
-
|
|
474
|
-
### Important Notes
|
|
475
|
-
|
|
476
|
-
1. **CRITICAL: Push to git BEFORE pulling into ABAP**
|
|
477
|
-
- Always commit and push ABAP files to git first
|
|
478
|
-
- Then run `abapgit-agent pull` to activate in ABAP
|
|
479
|
-
- Never run `abapgit-agent pull` without pushing changes first
|
|
480
|
-
|
|
481
|
-
2. **Only pull ABAP files** - The XML metadata stays in git:
|
|
482
|
-
```bash
|
|
483
|
-
abapgit-agent pull --files zcl_my_class.clas.abap
|
|
484
|
-
```
|
|
485
|
-
2. abapGit reads the XML from git to deserialize the ABAP code
|
|
486
|
-
3. XML files are NOT activated in ABAP - they are only for abapGit
|
|
487
|
-
|
|
488
|
-
```bash
|
|
489
|
-
# After making changes to ABAP files
|
|
490
|
-
git add .
|
|
491
|
-
git commit -m "Describe changes"
|
|
492
|
-
git push # CRITICAL: Push BEFORE pulling
|
|
493
|
-
|
|
494
|
-
# Then validate in ABAP system (single file - fast)
|
|
495
|
-
abapgit-agent pull --files abap/zcl_my_class.clas.abap
|
|
496
|
-
|
|
497
|
-
# Or validate all files
|
|
498
|
-
abapgit-agent pull
|
|
499
|
-
```
|
|
500
|
-
|
|
501
|
-
## Handling Persistent Syntax Errors
|
|
502
|
-
|
|
503
|
-
When fixing ABAP syntax errors using the commit-pull-commit loop:
|
|
504
|
-
|
|
505
|
-
1. **First 2-3 attempts**: Analyze the error message and try to fix based on the error details
|
|
506
|
-
2. **If errors persist after 2-3 iterations**:
|
|
507
|
-
- Stop repeating the same fix attempts
|
|
508
|
-
- Search the web for the specific ABAP error message or syntax issue
|
|
509
|
-
- Use keywords like "ABAP", the error code, and relevant context
|
|
510
|
-
- Examples: "ABAP error 'XXXX' CLAS", "ABAP syntax MESSAGE is not a declaration"
|
|
511
|
-
3. **After finding information**:
|
|
512
|
-
- Apply the correct fix based on documentation
|
|
513
|
-
- Test again with `abapgit-agent pull`
|
|
514
|
-
|
|
515
|
-
**Never guess** - ABAP syntax is strict. If you're unsure, search first.
|
|
516
|
-
|
|
517
|
-
## Understanding abapgit-agent Output
|
|
518
|
-
|
|
519
|
-
**Critical: Never ignore these messages!**
|
|
520
|
-
|
|
521
|
-
| Message | Meaning | Action Required |
|
|
522
|
-
|---------|---------|-----------------|
|
|
523
|
-
| `Error updating where-used list` | **SYNTAX ERROR** - object has errors | Fix the syntax error |
|
|
524
|
-
| `Failed Objects (N) > 0` | Objects failed to activate | Fix syntax errors |
|
|
525
|
-
| `Success: X` with all objects checked | All good | Proceed |
|
|
526
|
-
|
|
527
|
-
**Example error flow:**
|
|
528
|
-
```
|
|
529
|
-
❌ Pull completed with errors!
|
|
530
|
-
⚠️ Failed Objects (1):
|
|
531
|
-
✗ CLAS ZCL_MY_CLASS: Error updating where-used list
|
|
532
|
-
|
|
533
|
-
Action: The class has syntax errors. Use inspect to get details.
|
|
534
|
-
```
|
|
535
|
-
|
|
536
|
-
## Check Local Implementation First
|
|
537
|
-
|
|
538
|
-
When implementing new features or fixing issues:
|
|
539
|
-
|
|
540
|
-
1. **Always check local implementations first** - This project already contains working examples of:
|
|
541
|
-
- REST handlers (e.g., `zcl_abgagt_resource_pull`, `zcl_abgagt_resource_inspect`)
|
|
542
|
-
- JSON serialization using `/ui2/cl_json`
|
|
543
|
-
- ABAP object activation patterns
|
|
544
|
-
- Error handling approaches
|
|
545
|
-
|
|
546
|
-
2. **Before inventing something new:**
|
|
547
|
-
- Search the `abap/` folder for similar implementations
|
|
548
|
-
- Look at existing patterns in the codebase
|
|
549
|
-
- Reuse existing helper classes and methods
|
|
550
|
-
- Follow the established code style
|
|
551
|
-
|
|
552
|
-
3. **Examples:**
|
|
553
|
-
- Need to create a new REST endpoint? → Study `zcl_abgagt_resource_pull.clas.abap`
|
|
554
|
-
- Need to serialize JSON? → Use `/ui2/cl_json` as shown in existing handlers
|
|
555
|
-
- Need to query TADIR? → Check how other classes do it
|
|
556
|
-
|
|
557
|
-
**Don't guess patterns** - The codebase has proven implementations. Reuse them.
|
|
558
|
-
|
|
559
|
-
**Common mistakes to avoid:**
|
|
560
|
-
- Using wrong method parameter names (e.g., `set_string_data( iv_data = x )` should be `set_string_data( x )`)
|
|
561
|
-
- Forgetting to use `/ui2/cl_json` for JSON operations
|
|
562
|
-
- Using inline DATA declarations incorrectly
|
|
563
|
-
|
|
564
|
-
## Local Code Reference (Offline Support)
|
|
565
|
-
|
|
566
|
-
When network issues prevent accessing online resources, you can maintain a local folder with ABAP code examples for reference.
|
|
567
|
-
|
|
568
|
-
**Setup:**
|
|
569
|
-
|
|
570
|
-
1. Configure the reference folder path in `.abapGitAgent`:
|
|
571
|
-
```json
|
|
572
|
-
{
|
|
573
|
-
"referenceFolder": "<path-to-reference-folder>"
|
|
574
|
-
}
|
|
575
|
-
```
|
|
576
|
-
|
|
577
|
-
2. Clone ABAP repositories for reference into this folder:
|
|
578
|
-
```bash
|
|
579
|
-
# abapGit itself - best reference for ABAP patterns
|
|
580
|
-
git clone https://github.com/abapGit/abapGit.git
|
|
581
|
-
|
|
582
|
-
# ABAP coding style guides (Clean ABAP, code review)
|
|
583
|
-
git clone https://github.com/SAP/styleguides.git
|
|
584
|
-
|
|
585
|
-
# ABAP cheat sheets with code snippets for various topics
|
|
586
|
-
git clone https://github.com/SAP/abap-cheat-sheets.git
|
|
587
|
-
```
|
|
588
|
-
|
|
589
|
-
**Usage:**
|
|
590
|
-
|
|
591
|
-
- When Claude needs to reference ABAP patterns, read files from the folder configured in `.abapGitAgent` (`referenceFolder`)
|
|
592
|
-
- Useful for offline development or when network is unreliable
|
|
593
|
-
- Keep commonly used ABAP utilities, class patterns, and examples
|
|
594
|
-
|
|
595
|
-
## ABAP Object Types
|
|
596
|
-
|
|
597
|
-
Common object types in this project:
|
|
598
|
-
- `CLAS` - Classes
|
|
599
|
-
- `PROG` - Programs
|
|
600
|
-
- `FUGR` - Function Groups
|
|
601
|
-
- `INTF` - Interfaces
|
|
602
|
-
- `TABL` - Tables
|
|
603
|
-
- `DDLS` - Data Definitions
|
|
604
|
-
|
|
605
|
-
## Creating CDS Views (DDLS)
|
|
606
|
-
|
|
607
|
-
CDS views (Data Definition Language Source) require specific file naming and structure for abapGit.
|
|
608
|
-
|
|
609
|
-
### File Naming
|
|
610
|
-
|
|
611
|
-
CDS views require **two files**:
|
|
612
|
-
|
|
613
|
-
| File | Description |
|
|
614
|
-
|------|-------------|
|
|
615
|
-
| `zc_my_view.ddls.asddls` | DDL source code |
|
|
616
|
-
| `zc_my_view.ddls.xml` | XML metadata |
|
|
617
|
-
|
|
618
|
-
**Important:** Do NOT use `.ddls.abap` extension - use `.ddls.asddls` for the source.
|
|
619
|
-
|
|
620
|
-
### DDL Source File (`.ddls.asddls`)
|
|
621
|
-
|
|
622
|
-
```abap
|
|
623
|
-
@AbapCatalog.sqlViewName: 'ZCMYVIEW'
|
|
624
|
-
@AbapCatalog.compiler.compareFilter: true
|
|
625
|
-
@AccessControl.authorizationCheck: #NOT_REQUIRED
|
|
626
|
-
@EndUserText.label: 'My CDS View'
|
|
627
|
-
define view ZC_My_View as select from tdevc
|
|
628
|
-
{
|
|
629
|
-
key devclass as Devclass,
|
|
630
|
-
parentcl as ParentPackage,
|
|
631
|
-
ctext as Description
|
|
632
|
-
}
|
|
633
|
-
where devclass not like '$%'
|
|
634
|
-
```
|
|
635
|
-
|
|
636
|
-
### XML Metadata File (`.ddls.xml`)
|
|
637
|
-
|
|
638
|
-
```xml
|
|
639
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
640
|
-
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DDLS" serializer_version="v1.0.0">
|
|
641
|
-
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
|
642
|
-
<asx:values>
|
|
643
|
-
<DDLS>
|
|
644
|
-
<DDLNAME>ZC_MY_VIEW</DDLNAME>
|
|
645
|
-
<DDLANGUAGE>E</DDLANGUAGE>
|
|
646
|
-
<DDTEXT>My CDS View</DDTEXT>
|
|
647
|
-
</DDLS>
|
|
648
|
-
</asx:values>
|
|
649
|
-
</asx:abap>
|
|
650
|
-
</abapGit>
|
|
651
|
-
```
|
|
652
|
-
|
|
653
|
-
### Key Points
|
|
654
|
-
|
|
655
|
-
1. **Avoid reserved words** - Field names like `PACKAGE`, `CLASS`, `INTERFACE` are reserved in CDS. Use alternatives like `PackageName`, `ClassName`.
|
|
656
|
-
|
|
657
|
-
2. **Pull all files to activate** - When activating CDS views, use `abapgit-agent pull` (not single file) to ensure proper activation:
|
|
658
|
-
```bash
|
|
659
|
-
abapgit-agent pull # Pull all files
|
|
660
|
-
```
|
|
661
|
-
|
|
662
|
-
3. **System support** - CDS views require SAP systems with CDS capability (S/4HANA, SAP BW/4HANA, or ABAP 7.51+). Older systems will show error: "Object type DDLS is not supported by this system"
|
|
663
|
-
|
|
664
|
-
### Debugging Activation Errors
|
|
665
|
-
|
|
666
|
-
When pull shows generic errors like "Activation cancelled. Check the inactive objects":
|
|
667
|
-
|
|
668
|
-
1. **Check in ADT/Eclipse** - Open the DDL source in ADT and run syntax check for detailed errors
|
|
669
|
-
2. **Pull all files** - Sometimes `abapgit-agent pull` (all files) works better than single file for CDS views
|
|
670
|
-
|
|
671
|
-
## Creating CDS View Entities
|
|
672
|
-
|
|
673
|
-
CDS View Entities (`define view entity`) are the modern replacement for CDS Views with additional features like **associations for OData navigation**.
|
|
674
|
-
|
|
675
|
-
### Differences from CDS Views
|
|
676
|
-
|
|
677
|
-
| Aspect | CDS View | View Entity |
|
|
678
|
-
|--------|----------|-------------|
|
|
679
|
-
| Syntax | `define view` | `define view entity` |
|
|
680
|
-
| Associations | No | Yes (exposed for navigation) |
|
|
681
|
-
| OData/Navigation | Requires separate service | Auto-exposes associations |
|
|
682
|
-
| ABAP Version | 7.40+ | 7.55+ / S/4HANA Cloud |
|
|
683
|
-
|
|
684
|
-
### DDL Source File with Association
|
|
685
|
-
|
|
686
|
-
```abap
|
|
687
|
-
@EndUserText.label: 'Package Hierarchy'
|
|
688
|
-
@AccessControl.authorizationCheck: #NOT_REQUIRED
|
|
689
|
-
define view entity ZC_Pkg_Hierarchy_VE
|
|
690
|
-
as select from tdevc
|
|
691
|
-
association [0..1] to tdevc as _Parent
|
|
692
|
-
on _Parent.devclass = $projection.ParentPackage
|
|
693
|
-
{
|
|
694
|
-
key devclass as PackageName,
|
|
695
|
-
parentcl as ParentPackage,
|
|
696
|
-
ctext as Description,
|
|
697
|
-
dlvunit as SoftwareComponent,
|
|
698
|
-
|
|
699
|
-
// Exposed associations
|
|
700
|
-
_Parent
|
|
701
|
-
}
|
|
702
|
-
where devclass not like '$%'
|
|
703
|
-
```
|
|
704
|
-
|
|
705
|
-
### Key Points for View Entities
|
|
706
|
-
|
|
707
|
-
1. **Association syntax**: Use `$projection` to reference fields in the current entity
|
|
708
|
-
2. **Association cardinality**: `[0..1]`, `[1..1]`, `[0..n]`, `[1..n]`
|
|
709
|
-
3. **Expose associations**: Add the association name at the end of the SELECT to expose it for OData navigation
|
|
710
|
-
4. **Activation warnings**: Search help warnings are informational and don't block activation
|
|
711
|
-
|
|
712
|
-
## Naming Conventions
|
|
713
|
-
|
|
714
|
-
- Use `Z_` or `Y_` prefix for custom objects
|
|
715
|
-
- Class names: `ZCL_<NAME>`
|
|
716
|
-
- Interface names: `ZIF_<NAME>`
|
|
717
|
-
- Programs: `Z<NAME>`
|
|
718
|
-
- Package: `$<PROJECT_NAME>`
|
|
719
|
-
|
|
720
|
-
## Command Factory Pattern
|
|
721
|
-
|
|
722
|
-
### Command Class Naming
|
|
723
|
-
Command implementations should follow the naming convention:
|
|
724
|
-
- `ZCL_ABGAGT_COMMAND_<COMMAND>` where `<COMMAND>` is PULL, INSPECT, UNIT, etc.
|
|
725
|
-
|
|
726
|
-
Example:
|
|
727
|
-
```abap
|
|
728
|
-
CLASS zcl_abgagt_command_pull DEFINITION PUBLIC FINAL CREATE PUBLIC.
|
|
729
|
-
PUBLIC SECTION.
|
|
730
|
-
INTERFACES zif_abgagt_command.
|
|
731
|
-
ENDCLASS.
|
|
732
|
-
```
|
|
733
|
-
|
|
734
|
-
### Command Interface
|
|
735
|
-
Commands implement `ZIF_ABGAGT_COMMAND` with constants:
|
|
736
|
-
|
|
737
|
-
```abap
|
|
738
|
-
INTERFACE zif_abgagt_command PUBLIC.
|
|
739
|
-
CONSTANTS:
|
|
740
|
-
gc_pull TYPE string VALUE 'PULL',
|
|
741
|
-
gc_inspect TYPE string VALUE 'INSPECT',
|
|
742
|
-
gc_unit TYPE string VALUE 'UNIT'.
|
|
743
|
-
|
|
744
|
-
METHODS get_name RETURNING VALUE(rv_name) TYPE string.
|
|
745
|
-
METHODS execute IMPORTING it_files TYPE string_table
|
|
746
|
-
RETURNING VALUE(rv_result) TYPE string.
|
|
747
|
-
ENDINTERFACE.
|
|
748
|
-
```
|
|
749
|
-
|
|
750
|
-
### Factory with Dynamic Object Creation
|
|
751
|
-
Use dynamic object creation to avoid syntax errors in one command affecting others:
|
|
752
|
-
|
|
753
|
-
```abap
|
|
754
|
-
CLASS zcl_abgagt_cmd_factory DEFINITION PUBLIC CREATE PRIVATE.
|
|
755
|
-
PUBLIC SECTION.
|
|
756
|
-
INTERFACES zif_abgagt_cmd_factory.
|
|
757
|
-
CLASS-METHODS get_instance
|
|
758
|
-
RETURNING VALUE(ro_factory) TYPE REF TO zif_abgagt_cmd_factory.
|
|
759
|
-
PRIVATE SECTION.
|
|
760
|
-
TYPES: BEGIN OF ty_command_map,
|
|
761
|
-
command TYPE string,
|
|
762
|
-
class_name TYPE string,
|
|
763
|
-
END OF ty_command_map.
|
|
764
|
-
DATA mt_command_map TYPE TABLE OF ty_command_map.
|
|
765
|
-
ENDCLASS.
|
|
766
|
-
|
|
767
|
-
CLASS zcl_abgagt_cmd_factory IMPLEMENTATION.
|
|
768
|
-
METHOD constructor.
|
|
769
|
-
mt_command_map = VALUE #(
|
|
770
|
-
( command = zif_abgagt_command=>gc_pull class_name = 'ZCL_ABGAGT_COMMAND_PULL' )
|
|
771
|
-
( command = zif_abgagt_command=>gc_inspect class_name = 'ZCL_ABGAGT_COMMAND_INSPECT' )
|
|
772
|
-
( command = zif_abgagt_command=>gc_unit class_name = 'ZCL_ABGAGT_COMMAND_UNIT' )
|
|
773
|
-
).
|
|
774
|
-
ENDMETHOD.
|
|
775
|
-
|
|
776
|
-
METHOD zif_abgagt_cmd_factory~get_command.
|
|
777
|
-
READ TABLE mt_command_map WITH KEY command = iv_command
|
|
778
|
-
ASSIGNING FIELD-SYMBOL(<ls_map>).
|
|
779
|
-
IF sy-subrc = 0.
|
|
780
|
-
CREATE OBJECT ro_command TYPE (<ls_map>-class_name).
|
|
781
|
-
ENDIF.
|
|
782
|
-
ENDMETHOD.
|
|
783
|
-
ENDCLASS.
|
|
784
|
-
```
|
|
785
|
-
|
|
786
|
-
**Benefits:**
|
|
787
|
-
- Factory class activates independently of command classes
|
|
788
|
-
- Syntax errors in one command don't affect others
|
|
789
|
-
- Add new commands by updating the mapping table
|
|
790
|
-
|
|
791
|
-
## Exception Handling in ABAP
|
|
792
|
-
|
|
793
|
-
ABAP has two different ways to handle exceptions. Understanding the difference is critical.
|
|
794
|
-
|
|
795
|
-
### Classical ABAP Exceptions (EXCEPTIONS)
|
|
796
|
-
|
|
797
|
-
Used in older function modules and some OO classes. Defined in method signature using `EXCEPTIONS` keyword.
|
|
798
|
-
|
|
799
|
-
**Method Definition:**
|
|
800
|
-
```abap
|
|
801
|
-
METHODS method_name
|
|
802
|
-
IMPORTING iv_param TYPE string
|
|
803
|
-
EXCEPTIONS
|
|
804
|
-
exc1 = 1
|
|
805
|
-
exc2 = 2
|
|
806
|
-
OTHERS = 3.
|
|
807
|
-
```
|
|
808
|
-
|
|
809
|
-
**Method Call:**
|
|
810
|
-
```abap
|
|
811
|
-
method_name(
|
|
812
|
-
EXPORTING iv_param = lv_value
|
|
813
|
-
EXCEPTIONS
|
|
814
|
-
exc1 = 1
|
|
815
|
-
exc2 = 2
|
|
816
|
-
OTHERS = 3 ).
|
|
817
|
-
|
|
818
|
-
IF sy-subrc <> 0.
|
|
819
|
-
" Handle error - check sy-subrc for exception number
|
|
820
|
-
ENDIF.
|
|
821
|
-
```
|
|
822
|
-
|
|
823
|
-
**Characteristics:**
|
|
824
|
-
- Return code in `sy-subrc`
|
|
825
|
-
- No exception objects
|
|
826
|
-
- Legacy approach
|
|
827
|
-
|
|
828
|
-
### Modern ABAP Exceptions (TRY-CATCH)
|
|
829
|
-
|
|
830
|
-
Used in modern OO ABAP (7.40+). Uses exception classes and RAISING clause.
|
|
831
|
-
|
|
832
|
-
**Exception Class:**
|
|
833
|
-
```abap
|
|
834
|
-
CLASS cx_my_exception DEFINITION INHERITING FROM cx_dynamic_check.
|
|
835
|
-
PUBLIC SECTION.
|
|
836
|
-
METHODS constructor IMPORTING textid LIKE textid OPTIONAL.
|
|
837
|
-
ENDCLASS.
|
|
838
|
-
```
|
|
839
|
-
|
|
840
|
-
**Method Definition:**
|
|
841
|
-
```abap
|
|
842
|
-
METHODS method_name
|
|
843
|
-
IMPORTING iv_param TYPE string
|
|
844
|
-
RAISING cx_my_exception.
|
|
845
|
-
```
|
|
846
|
-
|
|
847
|
-
**Method Call:**
|
|
848
|
-
```abap
|
|
849
|
-
TRY.
|
|
850
|
-
method_name( iv_param = lv_value ).
|
|
851
|
-
CATCH cx_my_exception INTO lx_error.
|
|
852
|
-
lv_message = lx_error->get_text( ).
|
|
853
|
-
ENDTRY.
|
|
854
|
-
```
|
|
855
|
-
|
|
856
|
-
### How to Identify Which to Use
|
|
857
|
-
|
|
858
|
-
Look at the method signature:
|
|
859
|
-
|
|
860
|
-
| Syntax | Type |
|
|
861
|
-
|--------|------|
|
|
862
|
-
| `EXCEPTIONS exc1 = 1` | Classical |
|
|
863
|
-
| `RAISING cx_exception` | Modern (TRY-CATCH) |
|
|
864
|
-
|
|
865
|
-
### Real Example: cl_ci_checkvariant=>get_ref
|
|
866
|
-
|
|
867
|
-
This method uses **classical exceptions**:
|
|
868
|
-
|
|
869
|
-
```abap
|
|
870
|
-
" WRONG - using TRY-CATCH
|
|
871
|
-
TRY.
|
|
872
|
-
lo_variant = cl_ci_checkvariant=>get_ref(
|
|
873
|
-
p_user = ''
|
|
874
|
-
p_name = lv_variant ).
|
|
875
|
-
CATCH cx_root.
|
|
876
|
-
" This won't work!
|
|
877
|
-
ENDTRY.
|
|
878
|
-
|
|
879
|
-
" CORRECT - using EXCEPTIONS with EXPORTING and RECEIVING
|
|
880
|
-
cl_ci_checkvariant=>get_ref(
|
|
881
|
-
EXPORTING
|
|
882
|
-
p_user = ''
|
|
883
|
-
p_name = lv_variant
|
|
884
|
-
RECEIVING
|
|
885
|
-
p_ref = lo_variant
|
|
886
|
-
EXCEPTIONS
|
|
887
|
-
chkv_not_exists = 1
|
|
888
|
-
missing_parameter = 2
|
|
889
|
-
broken_variant = 3
|
|
890
|
-
OTHERS = 4 ).
|
|
891
|
-
|
|
892
|
-
IF sy-subrc <> 0.
|
|
893
|
-
" Handle error
|
|
894
|
-
ENDIF.
|
|
895
|
-
```
|
|
896
|
-
|
|
897
|
-
**Key Points:**
|
|
898
|
-
1. Use `EXPORTING` before importing parameters when using `EXCEPTIONS`
|
|
899
|
-
2. Use `RECEIVING` for RETURNING parameters (not direct assignment)
|
|
900
|
-
3. Check `sy-subrc` for exception codes
|
|
901
|
-
4. Not all OO methods use TRY-CATCH - some still use classical exceptions
|
|
902
|
-
|
|
903
|
-
## Best Practices
|
|
904
|
-
|
|
905
|
-
### Always Return Interface Types, Not Class Types
|
|
906
|
-
|
|
907
|
-
When defining factory methods or creating objects, return the interface type, not the class type:
|
|
908
|
-
|
|
909
|
-
```abap
|
|
910
|
-
" WRONG - returns concrete class
|
|
911
|
-
CLASS-METHODS get_instance
|
|
912
|
-
RETURNING VALUE(ro_factory) TYPE REF TO zcl_abgagt_cmd_factory.
|
|
913
|
-
|
|
914
|
-
" CORRECT - returns interface type
|
|
915
|
-
CLASS-METHODS get_instance
|
|
916
|
-
RETURNING VALUE(ro_factory) TYPE REF TO zif_abgagt_cmd_factory.
|
|
917
|
-
```
|
|
918
|
-
|
|
919
|
-
**Why?** Interface types provide better abstraction, easier testing, and follow the dependency inversion principle. Callers depend on the interface (abstraction), not the concrete class.
|
|
920
|
-
|
|
921
|
-
## Unit Testing with Local Test Classes
|
|
922
|
-
|
|
923
|
-
### File Structure
|
|
924
|
-
|
|
925
|
-
For ABAP local unit tests, use a **separate file** with `.testclasses.abap` extension:
|
|
926
|
-
|
|
927
|
-
```
|
|
928
|
-
abap/
|
|
929
|
-
zcl_my_class.clas.abap <- Main class (no test code)
|
|
930
|
-
zcl_my_class.clas.testclasses.abap <- Local test class
|
|
931
|
-
zcl_my_class.clas.xml <- XML with WITH_UNIT_TESTS = X
|
|
932
|
-
```
|
|
933
|
-
|
|
934
|
-
### Required Elements
|
|
935
|
-
|
|
936
|
-
1. **Test class file** (`zcl_my_class.clas.testclasses.abap`):
|
|
937
|
-
```abap
|
|
938
|
-
*"* use this source file for your test class implementation
|
|
939
|
-
*"* local test class
|
|
940
|
-
CLASS ltcl_zcl_my_class DEFINITION FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
941
|
-
PRIVATE SECTION.
|
|
942
|
-
DATA mo_cut TYPE REF TO zcl_my_class.
|
|
943
|
-
METHODS setup.
|
|
944
|
-
METHODS test_method1 FOR TESTING.
|
|
945
|
-
METHODS test_method2 FOR TESTING.
|
|
946
|
-
ENDCLASS.
|
|
947
|
-
|
|
948
|
-
CLASS ltcl_zcl_my_class IMPLEMENTATION.
|
|
949
|
-
METHOD setup.
|
|
950
|
-
CREATE OBJECT mo_cut.
|
|
951
|
-
ENDMETHOD.
|
|
952
|
-
METHOD test_method1.
|
|
953
|
-
" Test code using cl_abap_unit_assert
|
|
954
|
-
ENDMETHOD.
|
|
955
|
-
ENDCLASS.
|
|
956
|
-
```
|
|
957
|
-
|
|
958
|
-
2. **XML metadata** (`zcl_my_class.clas.xml`):
|
|
959
|
-
```xml
|
|
960
|
-
<VSEOCLASS>
|
|
961
|
-
...
|
|
962
|
-
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>
|
|
963
|
-
</VSEOCLASS>
|
|
964
|
-
```
|
|
965
|
-
|
|
966
|
-
### Naming Conventions
|
|
967
|
-
|
|
968
|
-
- Test class name: `LTCL_ZCL_<CLASSNAME>` (e.g., `LTCL_ZCL_COMMAND_PULL`)
|
|
969
|
-
- Test methods: `TEST_<methodname> FOR TESTING` or simply `test_method FOR TESTING`
|
|
970
|
-
- Test file: `<classname>.clas.testclasses.abap`
|
|
971
|
-
|
|
972
|
-
### CRITICAL: Method Name Length Limit
|
|
973
|
-
|
|
974
|
-
**Test method names MUST NOT exceed 30 characters!**
|
|
975
|
-
|
|
976
|
-
```abap
|
|
977
|
-
" WRONG - 34 characters (syntax error)
|
|
978
|
-
METHODS test_execute_with_minimal_params FOR TESTING.
|
|
979
|
-
|
|
980
|
-
" CORRECT - 18 characters
|
|
981
|
-
METHODS test_exec_minimal FOR TESTING.
|
|
982
|
-
```
|
|
983
|
-
|
|
984
|
-
Examples of compliant names:
|
|
985
|
-
- `test_get_name` (13 chars)
|
|
986
|
-
- `test_exec_minimal` (18 chars)
|
|
987
|
-
- `test_exec_files` (16 chars)
|
|
988
|
-
- `test_interface` (15 chars)
|
|
989
|
-
|
|
990
|
-
### Common Assertions
|
|
991
|
-
|
|
992
|
-
```abap
|
|
993
|
-
cl_abap_unit_assert=>assert_equals( act = lv_actual exp = lv_expected msg = 'Error message' ).
|
|
994
|
-
cl_abap_unit_assert=>assert_not_initial( act = lv_data msg = 'Should not be initial' ).
|
|
995
|
-
cl_abap_unit_assert=>assert_bound( act = lo_ref msg = 'Should be bound' ).
|
|
996
|
-
cl_abap_unit_assert=>assert_true( act = lv_bool msg = 'Should be true' ).
|
|
997
|
-
```
|
|
998
|
-
|
|
999
|
-
### What NOT To Do
|
|
1000
|
-
|
|
1001
|
-
- ❌ Don't add test methods directly in the main `.clas.abap` file
|
|
1002
|
-
- ❌ Don't use `CLASS ... DEFINITION ...` without the special comment header
|
|
1003
|
-
- ❌ Don't reference `<TESTCLASS>` in XML - abapGit auto-detects `.testclasses.abap`
|
|
1004
|
-
- ❌ Don't use nested local classes inside the main class definition
|
|
1005
|
-
|
|
1006
|
-
### Running Tests
|
|
1007
|
-
|
|
1008
|
-
In ABAP: SE24 → Test → Execute Unit Tests
|
|
1009
|
-
|
|
1010
|
-
Or via abapGit: Pull the files and run tests in the ABAP system.
|