Good evening visitors. This is a simple ATC checker report which can perform ABAP Test Cockpit code level checks based on the transport request. This program is quite useful than ordinary program checks which we can do from SE37, SE38, SE24, etc. since we can use this program to check for all objects present in transport request. This is helpful in ascertaining whether there are P1s, P2s or P3s in the programs present in the transport. Movement to production is based on transport request so this tool provides a quick way to check the objects instead of checking one by one.
Given below is the code for the program. Feel free to modify it as per your requirement. Note that this program is just a test program so it can contain unnecessary codes.
*&---------------------------------------------------------------------*
*& Report ZGB_ATC_CHECKER
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zgb_atc_checker.
* DATA TYPES
* Selection Screen Select Options
TYPES:
BEGIN OF lty_sel,
trkorr TYPE e070-trkorr,
trfunction TYPE e070-trfunction,
as4user TYPE e070-as4user,
as4date TYPE e070-as4date,
trstatus TYPE e070-trstatus,
END OF lty_sel.
*TYPES:
* BEGIN OF lty_object,
* obj_name(40) TYPE c,
* obj_type(4) TYPE c,
* END OF lty_object.
DATA: lt_trans TYPE tr_objects. "Line type e071
DATA:
ls_sel TYPE lty_sel.
*DATA: ls_object TYPE lty_object.
DATA: lt_obj TYPE if_satc_object_set=>ty_object_keys.
DATA: lt_objects TYPE if_satc_object_set=>ty_object_keys.
* CONSTANTS
CONSTANTS:
* lc_i TYPE char1 VALUE 'I',
* lc_eq TYPE char2 VALUE 'EQ',
* lc_cp TYPE char2 VALUE 'CP',
* lc_sys TYPE char10 VALUE 'SCD*',
* lc_r TYPE c VALUE 'R',
* lc_t TYPE c VALUE 'T',
* lc_blank TYPE c VALUE ' ',
* lc_email TYPE /iam/email VALUE 'PUT YOUR MAIL ID HERE',
* lc_no TYPE char10 VALUE 'No',
* lc_yes TYPE char10 VALUE 'Yes',
lc_e TYPE c VALUE 'E'.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-b01.
SELECT-OPTIONS:
so_treq FOR ls_sel-trkorr,
so_trfn FOR ls_sel-trfunction,
so_user FOR ls_sel-as4user,
so_date FOR ls_sel-as4date,
so_stat FOR ls_sel-trstatus.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-b02.
PARAMETERS:
pa_vari TYPE satc_ci_chk_variant DEFAULT 'Z_HPI_CUSTOM_ATC_VARIANT' OBLIGATORY,
cb_base AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK b2.
AT SELECTION-SCREEN.
IF so_treq[] IS INITIAL
AND so_trfn[] IS INITIAL
AND so_user[] IS INITIAL
AND so_date[] IS INITIAL
AND so_stat[] IS INITIAL.
MESSAGE 'Please provide some input'(m01) TYPE lc_e.
ENDIF.
START-OF-SELECTION.
SELECT a1~trkorr,
a1~as4pos,
a1~pgmid,
a1~object,
a1~obj_name,
a1~objfunc,
a1~lockflag,
a1~gennum,
a1~lang,
a1~activity
FROM e071 AS a1
LEFT OUTER JOIN e070 AS a ON a1~trkorr = a~trkorr
INTO TABLE @lt_trans
WHERE ( a~trkorr IN @so_treq OR a~strkorr IN @so_treq )
AND a~trfunction IN @so_trfn
AND a~as4user IN @so_user
AND a~as4date IN @so_date
AND a~trstatus IN @so_stat.
SORT lt_trans BY trkorr.
DELETE ADJACENT DUPLICATES FROM lt_trans COMPARING trkorr.
" IF type EQ 'S'. "Scans only Tasks(TRFUNCTION is "S")
* DATA is_all_well TYPE abap_bool VALUE abap_true.
* DATA: lv_baseline_flag TYPE flag VALUE 'X'. "Baseline is to be considered
* DATA: r_pragma TYPE char2.
DATA: lv_pragma TYPE char2 VALUE 'RV'. "Do not hide ATC findings using pragma
TRY.
DATA(or_factory) = NEW cl_satc_api_factory( ).
* List of Objects
LOOP AT lt_trans ASSIGNING FIELD-SYMBOL(<lfs_trans>).
CLEAR lt_obj.
TRY.
lt_obj = cl_satc_object_set_factory=>create_for_transport( <lfs_trans>-trkorr )->if_satc_object_set~get_object_keys( ).
LOOP AT lt_obj ASSIGNING FIELD-SYMBOL(<lfs_obj>).
INSERT <lfs_obj> INTO TABLE lt_objects.
ENDLOOP.
CATCH cx_satc_empty_object_set cx_satc_invalid_argument INTO DATA(cx1). "ok, if transport is empty or contains only non-checkable objects
ENDTRY.
ENDLOOP.
* SORT lt_objects.
DELETE ADJACENT DUPLICATES FROM lt_objects.
DATA(or_objects) = cl_satc_object_set_factory=>create_for_object_keys( lt_objects ).
DATA(or_variant) = NEW cl_satc_ci_check_variant( ).
or_variant->set_name( pa_vari ). "check variant name for HP
DATA(or_run_config) = or_factory->create_run_config_with_chk_var( EXPORTING i_object_set = or_objects
i_check_variant = or_variant
i_description = TEXT-t01 ).
* CALL METHOD or_run_config->get_consider_baseline
* RECEIVING
* result = DATA(r_baseline). "Just reading if Baseline is being considered
* CALL METHOD or_run_config->get_pragma_option
* RECEIVING
* r_option = r_pragma. "Get pragma setting to see if developer is hiding/suppress ATC findings
CALL METHOD or_run_config->set_pragma_option
EXPORTING
i_option = lv_pragma. "Would not let pragma hide/suppress findings.
CALL METHOD or_run_config->set_consider_baseline
EXPORTING
i_consider_baseline = cb_base. "lv_baseline_flag. "Trying to consider Baseline here
******----Running ATC Check and getting results. Baseline is considered & pragmas are neutralized
DATA(or_run_controller) = or_factory->create_run_controller( or_run_config ).
or_run_controller->run( IMPORTING e_result_access = DATA(or_result_access) ).
or_result_access->get_findings( IMPORTING e_findings = DATA(it_f)
e_findings_extension = DATA(it_f_extension)
e_ext_field_list = DATA(it_ext_field_list) ).
* LOOP AT it_f ASSIGNING FIELD-SYMBOL(<wa_f>) WHERE ( kind = 'E' ). " Errors only(ATC P1s)
** AND exceptn <> 'P'. "pseudo comments and pragmas
* DATA(lv_tabix) = sy-tabix.
* READ TABLE it_f_extension INTO DATA(ls_f_extension) INDEX lv_tabix.
* IF sy-subrc IS INITIAL AND ls_f_extension-exc_validity NE 'E'. "Means the exemption is "Not Approved" for the P1 error
* is_all_well = abap_false.
* EXIT.
* ENDIF.
* ENDLOOP.
CATCH cx_satc_failure cx_satc_not_found INTO DATA(cx).
DATA(exc_text) = cx->get_text( ).
MESSAGE exc_text TYPE 'E'.
* is_all_well = abap_false.
CATCH cx_satc_empty_object_set cx_satc_invalid_argument INTO cx. "ok, if transport is empty or contains only non-checkable objects
ENDTRY.
* IF is_all_well = abap_true.
* "All is well. No need for message display
* MESSAGE 'All OK' TYPE 'I'.
*
* ELSE.
"we only get the execution ID with this “dirty” cast:
DATA(or_result_access_int) = CAST cl_satc_ci_result_acc_complete( or_result_access ).
IF or_result_access_int IS NOT INITIAL.
CALL FUNCTION 'SATC_AC_DISPL_RESULT_BY_EXEC'
EXPORTING
i_execution_id = or_result_access_int->if_satc_result_access~result_id
EXCEPTIONS
xpt_no_results = 1
xpt_not_authorized = 2
xpt_display_used = 3
OTHERS = 4.
IF sy-subrc NE 0.
"Do nothing
ENDIF.
ELSE.
MESSAGE 'All OK' TYPE 'S'.
ENDIF.
* MESSAGE 'Please fix the ATC P1s before releasing the task'(001) TYPE 'I'.
* RAISE cancel.
* ENDIF.
" ENDIF. "Scans only Tasks(TRFUNCTION is "S")
The output is same like ATC Tool:
No comments:
Post a Comment