Quantcast
Channel: ABAP Development
Viewing all articles
Browse latest Browse all 948

Background jobs with users for authorization - report

$
0
0

Recently I had an issue to make an report for background jobs that are planned to run from dialog user. All informations I needed was in transaction sm37, but for every job I had to double click on it and go to 'step' options to check background user name. I made an ABAP program which make this report for me. Some of those jobs have more than one step, my report takes them into account. Here you have my program code, to make it working you have to create screen with container for alv list, gui status, and structures in se11: zbackground_jobs and zbackground_jobs_3f. Screenshots with structures and gui are attached.

 

Background jobs report

REPORT Z_BGJ_REPORT.

data: container_r type ref to cl_gui_custom_container,

       grid_r type ref to cl_gui_alv_grid.

 

data: it_bgj type table of zbackground_jobs,

       it_bgjt type table of zbackground_jobs_3f,

       wa_bgj type zbackground_jobs,

       wa_usr02 type usr02,

       wa_tbtcpv type tbtcpv.

 

select JOBNAME JOBCOUNT STATUS from TBTCO into corresponding fields of table it_bgjt where status = 'S'.

 

Loop at it_bgjt into wa_bgj.

   select * from tbtcpv into wa_tbtcpv where JOBCOUNT = wa_bgj-JOBCOUNT and JOBNAME = wa_bgj-JOBNAME.

     wa_bgj-AUTHCKNAM = wa_tbtcpv-AUTHCKNAM.

   select single * from usr02 into wa_usr02 where bname = wa_bgj-authcknam.

     wa_bgj-ustyp = wa_usr02-ustyp.

   append wa_bgj to it_bgj.

   endselect.

endloop.

 

call screen 321.

 

*&---------------------------------------------------------------------*

*&      Module  alv_pbo_876  OUTPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE STATUS_0321 OUTPUT.

   SET PF-STATUS 'LIST_STATUS'.

   if container_r is initial.

CREATE OBJECT CONTAINER_R

   EXPORTING

*    PARENT                      =

     CONTAINER_NAME              = 'ALV_CONTAINER'

*    STYLE                       =

*    LIFETIME                    = lifetime_default

*    REPID                       =

*    DYNNR                       =

*    NO_AUTODEF_PROGID_DYNNR     =

*  EXCEPTIONS

*    CNTL_ERROR                  = 1

*    CNTL_SYSTEM_ERROR           = 2

*    CREATE_ERROR                = 3

*    LIFETIME_ERROR              = 4

*    LIFETIME_DYNPRO_DYNPRO_LINK = 5

*    others                      = 6

     .

IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

 

CREATE OBJECT GRID_R

   EXPORTING

*    I_SHELLSTYLE      = 0

*    I_LIFETIME        =

     I_PARENT          = container_r

*    I_APPL_EVENTS     = space

*    I_PARENTDBG       =

*    I_APPLOGPARENT    =

*    I_GRAPHICSPARENT  =

*    I_NAME            =

*    I_FCAT_COMPLETE   = SPACE

*  EXCEPTIONS

*    ERROR_CNTL_CREATE = 1

*    ERROR_CNTL_INIT   = 2

*    ERROR_CNTL_LINK   = 3

*    ERROR_DP_CREATE   = 4

*    others            = 5

     .

IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

 

   CALL METHOD GRID_R->SET_TABLE_FOR_FIRST_DISPLAY

     EXPORTING

*      I_BUFFER_ACTIVE               =

*      I_BYPASSING_BUFFER            =

*      I_CONSISTENCY_CHECK           =

       I_STRUCTURE_NAME              = 'zbackground_jobs'

*      IS_VARIANT                    =

*      I_SAVE                        =

*      I_DEFAULT                     = 'X'

*      IS_LAYOUT                     =

*      IS_PRINT                      =

*      IT_SPECIAL_GROUPS             =

*      IT_TOOLBAR_EXCLUDING          =

*      IT_HYPERLINK                  =

*      IT_ALV_GRAPHICS               =

*      IT_EXCEPT_QINFO               =

*      IR_SALV_ADAPTER               =

     CHANGING

       IT_OUTTAB                     = IT_BGJ

*      IT_FIELDCATALOG               =

*      IT_SORT                       =

*      IT_FILTER                     =

*    EXCEPTIONS

*      INVALID_PARAMETER_COMBINATION = 1

*      PROGRAM_ERROR                 = 2

*      TOO_MANY_LINES                = 3

*      others                        = 4

           .

   IF SY-SUBRC <> 0.

*   Implement suitable error handling here

   ENDIF.

   endif.

 

ENDMODULE.                 " alv_pbo_321  OUTPUT

*&---------------------------------------------------------------------*

*&      Module  USER_COMMAND_0321  INPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE USER_COMMAND_0321 INPUT.

case sy-ucomm.

     when 'E'.

       leave to screen 0.

     when 'B'.

       leave program.

     when 'C'.

       leave program.

   endcase.

ENDMODULE.                 " USER_COMMAND_0321  INPUT


 

If you have problem to run this code - just look what tables I am using and make a report on your own or just review the tables.

Good luck!

 

Regards

Gabriel


Viewing all articles
Browse latest Browse all 948

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>