abapgit-agent 1.3.0 → 1.5.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/abap/CLAUDE.md CHANGED
@@ -4,6 +4,30 @@ This file provides guidelines for **generating ABAP code** in abapGit repositori
4
4
 
5
5
  **Use this file as a template**: Copy it to your ABAP repository root when setting up new projects with Claude Code.
6
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
+
7
31
  ## ABAP Syntax Validation
8
32
 
9
33
  This is an ABAP project. **Do not attempt local syntax validation** - ABAP code can only be validated in an SAP system.
@@ -214,6 +238,112 @@ DATA ELEMENT ZMY_DTEL:
214
238
  Key Definition: WITH KEY
215
239
  ```
216
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
+
217
347
  ## JSON Handling - ALWAYS Use /ui2/cl_json
218
348
 
219
349
  **CRITICAL**: Always use `/ui2/cl_json` for JSON serialization and deserialization.
@@ -658,6 +788,118 @@ ENDCLASS.
658
788
  - Syntax errors in one command don't affect others
659
789
  - Add new commands by updating the mapping table
660
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
+
661
903
  ## Best Practices
662
904
 
663
905
  ### Always Return Interface Types, Not Class Types
@@ -29,6 +29,7 @@ CLASS zcl_abgagt_cmd_factory IMPLEMENTATION.
29
29
  ( command = zif_abgagt_command=>gc_import class_name = 'ZCL_ABGAGT_COMMAND_IMPORT' )
30
30
  ( command = zif_abgagt_command=>gc_tree class_name = 'ZCL_ABGAGT_COMMAND_TREE' )
31
31
  ( command = zif_abgagt_command=>gc_view class_name = 'ZCL_ABGAGT_COMMAND_VIEW' )
32
+ ( command = zif_abgagt_command=>gc_preview class_name = 'ZCL_ABGAGT_COMMAND_PREVIEW' )
32
33
  ).
33
34
  ENDMETHOD.
34
35
 
@@ -44,6 +44,7 @@ CLASS zcl_abgagt_command_inspect DEFINITION PUBLIC FINAL CREATE PUBLIC.
44
44
 
45
45
  TYPES: BEGIN OF ty_inspect_params,
46
46
  files TYPE string_table,
47
+ variant TYPE string,
47
48
  END OF ty_inspect_params.
48
49
 
49
50
  TYPES ty_object_keys TYPE TABLE OF scir_objs WITH NON-UNIQUE DEFAULT KEY.
@@ -53,6 +54,7 @@ CLASS zcl_abgagt_command_inspect DEFINITION PUBLIC FINAL CREATE PUBLIC.
53
54
 
54
55
  METHODS run_syntax_check
55
56
  IMPORTING it_objects TYPE ty_object_keys
57
+ iv_variant TYPE string DEFAULT 'SYNTAX_CHECK'
56
58
  RETURNING VALUE(rt_results) TYPE ty_inspect_results.
57
59
 
58
60
  " Validate DDLS (CDS views)
@@ -120,7 +122,9 @@ CLASS zcl_abgagt_command_inspect IMPLEMENTATION.
120
122
 
121
123
  " Run syntax check for non-DDLS objects
122
124
  IF lt_objects IS NOT INITIAL.
123
- DATA(lt_sci_results) = run_syntax_check( lt_objects ).
125
+ DATA(lt_sci_results) = run_syntax_check(
126
+ it_objects = lt_objects
127
+ iv_variant = ls_params-variant ).
124
128
  INSERT LINES OF lt_sci_results INTO TABLE lt_results.
125
129
  ENDIF.
126
130
 
@@ -300,6 +304,7 @@ CLASS zcl_abgagt_command_inspect IMPLEMENTATION.
300
304
  lo_inspection TYPE REF TO cl_ci_inspection,
301
305
  lt_list TYPE scit_alvlist,
302
306
  ls_error TYPE ty_error,
307
+ ls_warning TYPE ty_warning,
303
308
  ls_list TYPE scir_alvlist,
304
309
  lx_error TYPE REF TO cx_root,
305
310
  ls_result TYPE ty_inspect_result.
@@ -315,10 +320,36 @@ CLASS zcl_abgagt_command_inspect IMPLEMENTATION.
315
320
  p_name = lv_name
316
321
  p_objects = it_objects ).
317
322
 
318
- " Get check variant for syntax check
319
- lo_variant = cl_ci_checkvariant=>get_ref(
320
- p_user = ''
321
- p_name = 'SYNTAX_CHECK' ).
323
+ " Get check variant (default: SYNTAX_CHECK)
324
+ DATA lv_variant TYPE sci_chkv.
325
+ lv_variant = iv_variant.
326
+ IF lv_variant IS INITIAL.
327
+ lv_variant = 'SYNTAX_CHECK'.
328
+ ENDIF.
329
+
330
+ " Try to get the variant using EXCEPTIONS
331
+ cl_ci_checkvariant=>get_ref(
332
+ EXPORTING
333
+ p_user = ''
334
+ p_name = lv_variant
335
+ RECEIVING
336
+ p_ref = lo_variant
337
+ EXCEPTIONS
338
+ chkv_not_exists = 1
339
+ missing_parameter = 2
340
+ broken_variant = 3
341
+ OTHERS = 4 ).
342
+
343
+ IF sy-subrc <> 0.
344
+ " Variant not found, return error
345
+ ls_result-object_type = 'VARIANT'.
346
+ ls_result-object_name = lv_variant.
347
+ ls_result-success = abap_false.
348
+ ls_result-error_count = 1.
349
+ APPEND VALUE #( line = '0' column = '0' text = |Check variant "{ lv_variant }" not found (rc={ sy-subrc })| word = '' ) TO ls_result-errors.
350
+ APPEND ls_result TO rt_results.
351
+ RETURN.
352
+ ENDIF.
322
353
 
323
354
  " Create inspection
324
355
  cl_ci_inspection=>create(
@@ -355,14 +386,28 @@ CLASS zcl_abgagt_command_inspect IMPLEMENTATION.
355
386
  ls_result-object_name = ls_obj-objname.
356
387
  ls_result-success = abap_true.
357
388
 
358
- " Get errors for this object
389
+ " Get errors and warnings for this object
359
390
  LOOP AT lt_list INTO ls_list WHERE objname = ls_obj-objname.
360
- CLEAR ls_error.
361
- ls_error-line = ls_list-line.
362
- ls_error-column = ls_list-col.
363
- ls_error-text = ls_list-text.
364
- ls_error-word = ls_list-code.
365
- APPEND ls_error TO ls_result-errors.
391
+ " Check severity - 'E' = Error, 'W' = Warning, 'I' = Info
392
+ IF ls_list-kind = 'E'.
393
+ " Error
394
+ CLEAR ls_error.
395
+ ls_error-line = ls_list-line.
396
+ ls_error-column = ls_list-col.
397
+ ls_error-text = ls_list-text.
398
+ ls_error-word = ls_list-code.
399
+ APPEND ls_error TO ls_result-errors.
400
+ ELSEIF ls_list-kind = 'W' OR ls_list-kind = 'I'.
401
+ " Warning or Info
402
+ CLEAR ls_warning.
403
+ ls_warning-line = ls_list-line.
404
+ ls_warning-column = ls_list-col.
405
+ ls_warning-severity = ls_list-kind.
406
+ ls_warning-message = ls_list-text.
407
+ ls_warning-object_type = ls_obj-objtype.
408
+ ls_warning-object_name = ls_obj-objname.
409
+ APPEND ls_warning TO ls_result-warnings.
410
+ ENDIF.
366
411
  ENDLOOP.
367
412
 
368
413
  ls_result-error_count = lines( ls_result-errors ).