SUBMIT Beispiele

Nützliche Abap Codes und Code Fragmente

SUBMIT Beispiele

Postby Tron » Tue Jun 18, 2019 3:51 am

Die ABAP-Anweisung SUBMIT wird verwendet, um einen Report oder ein Programm aus Ihrem ABAP-Code heraus auszuführen.

Beispielsweise kann ein Benutzer innerhalb eines ALV-Ausgabeberichts auf eine Schaltfläche klicken oder eine bestimmte Taste drücken. Diese Aktion könnte dann einen zweiten Bericht ausführen, um weitere Details anzuzeigen oder zusätzliche Funktionen auszuführen. Bitte beachten Sie, dass Sie nur Reports vom Typ'1' (d.h. ausführbar) ausführen können


Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. *Code used to execute a report
  2. SUBMIT Zreport.
  3.  
  4.  
  5. *Code used to populate 'select-options' & execute report
  6. DATA: seltab type table of rsparams,
  7.       seltab_wa like line of seltab.
  8.  
  9.   seltab_wa-selname = 'PNPPERNR'.
  10.   seltab_wa-sign    = 'I'.
  11.   seltab_wa-option  = 'EQ'.
  12.  
  13. * load each personnel number accessed from the structure into
  14. * parameters to be used in the report
  15.   loop at pnppernr.
  16.     seltab_wa-low = pnppernr-low.
  17.     append seltab_wa to seltab.
  18.   SUBMIT zreport with selection-table seltab
  19.                                 via selection-screen.
  20.  
  21.  
  22. *Code used to populate 'parameters' & execute report
  23.  SUBMIT zreport with p_param1 = 'value'
  24.                 with p_param2 = 'value'.
  25.  
  26.  
  27.  *Submit report and return to current program afterwards
  28.  SUBMIT zreport AND RETURN.
  29.  
  30. *Submit report via its own selection screen
  31.   SUBMIT zreport VIA SELECTION-SCREEN.
  32.  
  33.  
  34. *Submit report using selection screen variant
  35.  SUBMIT zreport USING SELECTION-SET 'VARIANT1'.
  36.  
  37. *Submit report but export resultant list to memory, rather than
  38. *it being displayed on screen
  39.  SUBMIT zreport EXPORTING LIST TO MEMORY.
  40. *  Once report has finished and control has returned to calling
  41. *  program, use function modules LIST_FROM_MEMORY, WRITE_LIST and
  42. *  DISPLAY_LIST to retrieve and display report.
  43.  
  44. *Example Code (Retrieving list from memory)
  45. DATA  BEGIN OF itab_list OCCURS 0.
  46.         INCLUDE STRUCTURE abaplist.
  47. DATA  END OF itab_list.
  48.  
  49. DATA: BEGIN OF vlist OCCURS 0,
  50.         filler1(01)   TYPE c,
  51.         field1(06)    TYPE c,
  52.         filler(08)    TYPE c,
  53.         field2(10)    TYPE c,
  54.         filler3(01)   TYPE c,
  55.         field3(10)    TYPE c,
  56.         filler4(01)   TYPE c,
  57.         field4(3)     TYPE c,
  58.         filler5(02)   TYPE c,
  59.         field5(15)    TYPE c,
  60.         filler6(02)   TYPE c,
  61.         field6(30)    TYPE c,
  62.         filler7(43)   TYPE c,
  63.         field7(10)    TYPE c,
  64.       END OF vlist.
  65.  
  66. SUBMIT zreport EXPORTING LIST TO MEMORY.
  67.  
  68. CALL FUNCTION 'LIST_FROM_MEMORY'
  69.     listobject = itab_list
  70.   EXCEPTIONS
  71.     not_found  = 4
  72.     OTHERS     = 8.
  73.  
  74. CALL FUNCTION 'LIST_TO_ASCI'
  75.   EXPORTING
  76.     list_index         = -1
  77.     listasci           = vlist
  78.     listobject         = itab_list
  79.   EXCEPTIONS
  80.     empty_list         = 1
  81.     list_index_invalid = 2
  82.     OTHERS             = 3.
  83.  
  84. IF sy-subrc NE '0'.
  85.   WRITE:/ 'LIST_TO_ASCI error !! ', sy-subrc.
  86.  
  87. Submit report as job(i.e. in background)
  88. data: jobname like tbtcjob-jobname value
  89.                              'TRANSFER DATA'.
  90. data: jobcount like tbtcjob-jobcount,
  91.       host like msxxlist-host.
  92. data: begin of starttime.
  93.         include structure tbtcstrt.
  94. data: end of starttime.
  95. data: starttimeimmediate like btch0000-char1 value 'X'.
  96.  
  97. * Job open
  98.   call function 'JOB_OPEN'
  99.        exporting
  100.             delanfrep        = ' '
  101.             jobgroup         = ' '
  102.             jobname          = jobname
  103.             sdlstrtdt        = sy-datum
  104.             sdlstrttm        = sy-uzeit
  105.        importing
  106.             jobcount         = jobcount
  107.        exceptions
  108.             cant_create_job  = 01
  109.             invalid_job_data = 02
  110.             jobname_missing  = 03.
  111.   if sy-subrc ne 0.
  112.                                        "error processing
  113.   endif.
  114.  
  115. * Insert process into job
  116.  SUBMIT zreport and return
  117.                 with p_param1 = 'value'
  118.                 with p_param2 = 'value'
  119.                 user sy-uname
  120.                 via job jobname
  121.                 number jobcount.
  122.   if sy-subrc > 0.
  123.                                        "error processing
  124.   endif.
  125.  
  126. * Close job
  127.   starttime-sdlstrtdt = sy-datum + 1.
  128.   starttime-sdlstrttm = '220000'.
  129.   call function 'JOB_CLOSE'
  130.        exporting
  131. "            event_id             = starttime-eventid
  132. "            event_param          = starttime-eventparm
  133. "            event_periodic       = starttime-periodic
  134.             jobcount             = jobcount
  135.             jobname              = jobname
  136. "            laststrtdt           = starttime-laststrtdt
  137. "            laststrttm           = starttime-laststrttm
  138. "            prddays              = 1
  139. "            prdhours             = 0
  140. "            prdmins              = 0
  141. "            prdmonths            = 0
  142. "            prdweeks             = 0
  143. "            sdlstrtdt            = starttime-sdlstrtdt
  144. "            sdlstrttm            = starttime-sdlstrttm
  145.             strtimmed            = starttimeimmediate
  146. "            targetsystem         = host
  147.        exceptions
  148.             cant_start_immediate = 01
  149.             invalid_startdate    = 02
  150.             jobname_missing      = 03
  151.             job_close_failed     = 04
  152.             job_nosteps          = 05
  153.             job_notex            = 06
  154.             lock_failed          = 07
  155.             others               = 99.
  156.   if sy-subrc eq 0.
  157.                                        "error processing
  158.   endif.
  159.  
  160.  
  161.  
  162. Submit report as background job, handle spool output(write commands) and run as different user
  163. data: jobname type tbtcjob-jobname value 'JOBNAME'.
  164. data: jobcount type tbtcjob-jobcount,
  165.       host type msxxlist-host.
  166.  
  167. data: starttimeimmediate type btch0000-char1 value 'X',
  168.       print_parameters TYPE pri_params.
  169. DATA: seltab type table of rsparams,
  170.       seltab_wa like line of seltab,
  171.       ld_pernr type pernr-pernr.
  172.  
  173. seltab_wa-selname = 'SO_PERNR'.
  174. seltab_wa-sign    = 'I'.
  175. seltab_wa-option  = 'EQ'.
  176. seltab_wa-low    = ld_pernr.
  177. append seltab_wa to seltab.
  178.  
  179. * Job open
  180. call function 'JOB_OPEN'
  181.   EXPORTING
  182.     delanfrep        = ' '
  183.     jobgroup         = ' '
  184.     jobname          = jobname
  185.     sdlstrtdt        = sy-datum
  186.     sdlstrttm        = sy-uzeit
  187.   IMPORTING
  188.     jobcount         = jobcount
  189.   EXCEPTIONS
  190.     cant_create_job  = 01
  191.     invalid_job_data = 02
  192.     jobname_missing  = 03.
  193.  
  194. *Setup print parameters
  195. *Only values used in example are to tell it not to print immediately
  196. *and not display a print dialog box)
  197. CALL FUNCTION 'GET_PRINT_PARAMETERS'
  198.  EXPORTING
  199. *   ARCHIVE_ID                     = C_CHAR_UNKNOWN
  200. *   ARCHIVE_INFO                   = C_CHAR_UNKNOWN
  201. *   ARCHIVE_MODE                   = C_CHAR_UNKNOWN
  202. *   ARCHIVE_TEXT                   = C_CHAR_UNKNOWN
  203. *   AR_OBJECT                      = C_CHAR_UNKNOWN
  204. *   ARCHIVE_REPORT                 = C_CHAR_UNKNOWN
  205. *   AUTHORITY                      = C_CHAR_UNKNOWN
  206. *   COPIES                         = C_NUM3_UNKNOWN
  207. *   COVER_PAGE                     = C_CHAR_UNKNOWN
  208. *   DATA_SET                       = C_CHAR_UNKNOWN
  209. *   DEPARTMENT                     = C_CHAR_UNKNOWN
  210. *   DESTINATION                    = C_CHAR_UNKNOWN
  211. *   EXPIRATION                     = C_NUM1_UNKNOWN
  212.     IMMEDIATELY                    = ' '   " leave blank so is not sent to print
  213. *   IN_ARCHIVE_PARAMETERS          = ' '
  214. *   IN_PARAMETERS                  = ' '
  215. *   LAYOUT                         = C_CHAR_UNKNOWN
  216. *   LINE_COUNT                     = C_INT_UNKNOWN
  217. *   LINE_SIZE                      = C_INT_UNKNOWN
  218. *   LIST_NAME                      = C_CHAR_UNKNOWN
  219. *   LIST_TEXT                      = C_CHAR_UNKNOWN
  220. *   MODE                           = ' '
  221. *   NEW_LIST_ID                    = C_CHAR_UNKNOWN
  222. *   PROTECT_LIST                   = C_CHAR_UNKNOWN
  223.     NO_DIALOG                      = 'X'
  224. *   RECEIVER                       = C_CHAR_UNKNOWN
  225. *   RELEASE                        = C_CHAR_UNKNOWN
  226. *   REPORT                         = C_CHAR_UNKNOWN
  227. *   SAP_COVER_PAGE                 = C_CHAR_UNKNOWN
  228. *   HOST_COVER_PAGE                = C_CHAR_UNKNOWN
  229. *   PRIORITY                       = C_NUM1_UNKNOWN
  230. *   SAP_OBJECT                     = C_CHAR_UNKNOWN
  231. *   TYPE                           = C_CHAR_UNKNOWN
  232. *   USER                           = SY-UNAME
  233. *   USE_OLD_LAYOUT                 = ' '
  234. *   UC_DISPLAY_MODE                = C_CHAR_UNKNOWN
  235. *   DRAFT                          = C_CHAR_UNKNOWN
  236. *   ABAP_LIST                      = ' '
  237. *   USE_ARCHIVENAME_DEF            = ' '
  238. *   DEFAULT_SPOOL_SIZE             = C_CHAR_UNKNOWN
  239. *   WITH_STRUCTURE                 = C_CHAR_UNKNOWN
  240. *   SUPPRESS_SHADING               = C_CHAR_UNKNOWN
  241. *   PO_FAX_STORE                   = ' '
  242. *   NO_FRAMES                      = C_CHAR_UNKNOWN
  243.  IMPORTING
  244. *   OUT_ARCHIVE_PARAMETERS         =
  245.    OUT_PARAMETERS                 = print_parameters
  246. *   VALID                          =
  247. *   VALID_FOR_SPOOL_CREATION       =
  248.  EXCEPTIONS
  249.    ARCHIVE_INFO_NOT_FOUND         = 1
  250.    INVALID_PRINT_PARAMS           = 2
  251.    INVALID_ARCHIVE_PARAMS         = 3
  252.    OTHERS                         = 4.
  253.  
  254. *Execute abap program ZTESTREP in background job storing any output to spool
  255. submit ZTESTREP to sap-spool and return
  256.        with selection-table seltab
  257.        user 'ADMIN'                "user name with correct/additional authorisation
  258.        SPOOL PARAMETERS print_parameters
  259.        WITHOUT SPOOL DYNPRO
  260.        via job jobname
  261.        number jobcount.
  262.  
  263. * Close job
  264. call function 'JOB_CLOSE'
  265.   EXPORTING
  266.     jobcount             = jobcount
  267.     jobname              = jobname
  268.     strtimmed            = starttimeimmediate
  269.   EXCEPTIONS
  270.     cant_start_immediate = 01
  271.     invalid_startdate    = 02
  272.     jobname_missing      = 03
  273.     job_close_failed     = 04
  274.     job_nosteps          = 05
  275.     job_notex            = 06
  276.     lock_failed          = 07
  277.     others               = 99.
  278.  
  279.  
GeSHi ©
Tron
.....
.....
 
Posts: 1081
Joined: Sat Aug 04, 2007 10:21 pm

Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest

cron
  • Latest Topics