Posted By

Birdych on 01/12/18


Tagged

Nachrichtensammler Applikationslog


Versions (?)

ZCL_MESSAGES


 / Published in: Pseudocode
 

Beschreibung Nachrichtensammler für Applikationslog Inst.-Erzeugung Public

Nachrichtenklasse ZCAMSG Programmstatus Kategorie Allg. Objekttyp Paket ZCAMESSAGES Originalsprache DE

  1. class ZCL_MESSAGES definition
  2. public
  3. create public .
  4.  
  5. *"* public components of class ZCL_MESSAGES
  6. *"* do not include other source files here!!!
  7. public section.
  8. type-pools ABAP .
  9.  
  10. constants:
  11. BEGIN OF gc_default,
  12. BEGIN OF applog,
  13. object TYPE balobj_d VALUE 'ZCA_APPLOG', "#EC NOTEXT
  14. subobj TYPE balsubobj VALUE 'ZCL_MESSAGES', "#EC NOTEXT
  15. END OF applog,
  16. context TYPE tabname VALUE 'ZCA_MSG_CONTEXT_S', "#EC NOTEXT
  17. END OF gc_default .
  18. constants:
  19. BEGIN OF gc_fieldname,
  20. condition TYPE fieldname VALUE 'CONDITION', "#EC NOTEXT
  21. id TYPE fieldname VALUE 'ID', "#EC NOTEXT
  22. row TYPE fieldname VALUE 'ROW', "#EC NOTEXT
  23. END OF gc_fieldname .
  24. constants:
  25. BEGIN OF gc_msg_type,
  26. success TYPE symsgty VALUE 'S', "#EC NOTEXT
  27. info TYPE symsgty VALUE 'I', "#EC NOTEXT
  28. warning TYPE symsgty VALUE 'W', "#EC NOTEXT
  29. error TYPE symsgty VALUE 'E', "#EC NOTEXT
  30. abort TYPE symsgty VALUE 'A', "#EC NOTEXT
  31. dump TYPE symsgty VALUE 'X', "#EC NOTEXT
  32. END OF gc_msg_type .
  33. constants GC_MESSAGE_TYPES type CHAR6 value 'XAEWIS'. "#EC NOTEXT
  34. data GV_CONTEXT type TABNAME .
  35. data GV_LOGCLASS type BALSUBOBJ .
  36.  
  37. class-methods READ_BY_EXTNUMBER
  38. importing
  39. !IV_EXTNUMBER type BALNREXT
  40. !IV_SUBOBJECT type BALSUBOBJ default GC_DEFAULT-APPLOG-SUBOBJ
  41. !IV_OBJECT type BALOBJ_D default GC_DEFAULT-APPLOG-OBJECT
  42. exporting
  43. !EV_LOG_HANDLE type BALLOGHNDL
  44. raising
  45. ZCX_NOT_FOUND .
  46. class-methods FILL_BAPIRET2
  47. importing
  48. !IV_MSGID type SYMSGID default SY-MSGID
  49. !IV_MSGNO type SYMSGNO default SY-MSGNO
  50. !IV_MSGTY type SYMSGTY default SY-MSGTY
  51. !IV_MSGV1 type SYMSGV default SY-MSGV1
  52. !IV_MSGV2 type SYMSGV default SY-MSGV2
  53. !IV_MSGV3 type SYMSGV default SY-MSGV3
  54. !IV_MSGV4 type SYMSGV default SY-MSGV4
  55. exporting
  56. !ES_RETURN type BAPIRET2 .
  57. class-methods GET_BAPIRET2_FROM_EXCEPTION
  58. importing
  59. !IO_EXCEPTION type ref to CX_ROOT
  60. exporting
  61. !ES_RETURN type BAPIRET2 .
  62. class-methods GET_INSTANCE
  63. importing
  64. !IV_ID type CSEQUENCE
  65. !IV_LOGCLASS type BALSUBOBJ default GC_DEFAULT-APPLOG-SUBOBJ
  66. !IV_CONTEXT type TABNAME default GC_DEFAULT-CONTEXT
  67. !IV_REOPEN type BOOLE_D default ABAP_FALSE
  68. returning
  69. value(RO_INSTANCE) type ref to ZCL_MESSAGES
  70. raising
  71. ZCX_PARAMETER_MISSING
  72. ZCX_NOT_FOUND .
  73. class-methods SHOW_EXCEPTION
  74. importing
  75. !IO_EX type ref to CX_ROOT
  76. !IV_MSGTY type MSGTY default 'I' .
  77. methods ADD
  78. importing
  79. !IV_CONDITION type ZCA_MSG_CONDITION_D default SPACE
  80. !IV_MSGID type SYMSGID default SY-MSGID
  81. !IV_MSGTY type SYMSGTY default SY-MSGTY
  82. !IV_MSGNO type SYMSGNO default SY-MSGNO
  83. !IV_MSGV1 type SYMSGV default SY-MSGV1
  84. !IV_MSGV2 type SYMSGV default SY-MSGV2
  85. !IV_MSGV3 type SYMSGV default SY-MSGV3
  86. !IV_MSGV4 type SYMSGV default SY-MSGV4
  87. !IV_ROW type ZCA_MSG_TABIX_D optional
  88. preferred parameter IV_CONDITION
  89. raising
  90. ZCX_ERROR .
  91. methods ADD_BAPIRETURN
  92. importing
  93. !IV_CONDITION type ZCA_MSG_CONDITION_D default SPACE
  94. !IT_BAPIRETURN type BAPIRETTAB optional
  95. !IS_BAPIRETURN type ANY optional
  96. preferred parameter IV_CONDITION
  97. returning
  98. value(EV_SEVERITY) type SYMSGTY .
  99. methods ADD_FREE_TEXT
  100. importing
  101. !IV_CONDITION type ZCA_MSG_CONDITION_D default SPACE
  102. !IV_ROW type ZCA_MSG_TABIX_D optional
  103. !IV_MSGTY type SYMSGTY default 'I'
  104. !IV_TEXT type CSEQUENCE .
  105. methods ADD_FROM_BDC
  106. importing
  107. !IT_MSG type ETTCD_MSG_TABTYPE
  108. !IV_ALWAYS type ABAP_BOOL default ABAP_FALSE
  109. !IV_BATCH_TEST type ABAP_BOOL default ABAP_FALSE
  110. returning
  111. value(EV_MSGS) type I .
  112. methods ADD_FROM_EXCEPTION
  113. importing
  114. !IO_EXCEPTION type ref to CX_ROOT
  115. !IV_CONDITION type ZCA_MSG_CONDITION_D default SPACE
  116. !IV_ROW type ZCA_MSG_TABIX_D optional
  117. !IV_MSGTY type SYMSGTY default 'E' .
  118. methods CONSTRUCTOR
  119. importing
  120. !IV_ID type CSEQUENCE
  121. !IV_LOGCLASS type BALSUBOBJ default GC_DEFAULT-APPLOG-SUBOBJ
  122. !IV_CONTEXT type TABNAME default GC_DEFAULT-CONTEXT
  123. !IV_LOG_HANDLE type BALLOGHNDL optional
  124. raising
  125. ZCX_NOT_FOUND
  126. ZCX_STOP_NO_CHECK .
  127. methods COPY
  128. importing
  129. !IO_TARGET type ref to ZCL_MESSAGES
  130. !IV_CONDITION type ZCA_MSG_CONDITION_D default '*'
  131. !IV_ROW type ZCA_MSG_TABIX_D optional
  132. raising
  133. ZCX_ERROR .
  134. methods DELETE
  135. importing
  136. !IV_CONDITION type ZCA_MSG_CONDITION_D default '*'
  137. !IV_ROW type ZCA_MSG_TABIX_D optional
  138. preferred parameter IV_CONDITION .
  139. methods DELETE_SINGLE
  140. importing
  141. !IS_MSGH type BALMSGHNDL .
  142. methods DISPLAY
  143. importing
  144. !IV_FULLSCREEN type FLAG default 'X'
  145. !IS_PROF type BAL_S_PROF optional
  146. preferred parameter IV_FULLSCREEN .
  147. methods GET_HANDLE
  148. returning
  149. value(EV_LOG_HANDLE) type BALLOGHNDL .
  150. methods GET_HIGHEST_TYPE
  151. importing
  152. !IV_CONDITION type ZCA_MSG_CONDITION_D default '*'
  153. !IV_ROW type ZCA_MSG_TABIX_D optional
  154. preferred parameter IV_CONDITION
  155. returning
  156. value(EV_TYPE) type SYMSGTY .
  157. methods GET_LAST_MESSAGE
  158. exporting
  159. !ES_MSG type BAL_S_MSG
  160. !ES_MSGH type BALMSGHNDL
  161. raising
  162. ZCX_NOT_FOUND .
  163. methods GET_MESSAGE
  164. importing
  165. !IV_CONDITION type ZCA_MSG_CONDITION_D default '*'
  166. !IV_ROW type ZCA_MSG_TABIX_D optional
  167. exporting
  168. !EV_MSG_TYPE type SYMSGTY
  169. !EV_MSG_TEXT type STRING .
  170. methods GET_MESSAGES
  171. importing
  172. !IV_CONDITION type ZCA_MSG_CONDITION_D default '*'
  173. returning
  174. value(ET_MESSAGES) type ZCA_MSG_MESSAGES_Y .
  175. methods GET_MESSAGES_DETAILED
  176. importing
  177. !IV_CONDITION type ZCA_MSG_CONDITION_D default '*'
  178. !IV_ROW type ZCA_MSG_TABIX_D optional
  179. preferred parameter IV_CONDITION
  180. returning
  181. value(ET_MSG) type AQTBAL_S_MSG .
  182. methods GET_MESSAGES_DETAILED_WITH_HDL
  183. importing
  184. !IV_CONDITION type ZCA_MSG_CONDITION_D default '*'
  185. !IV_ROW type ZCA_MSG_TABIX_D optional
  186. exporting
  187. !ET_MESSAGES type SWF_APP_LOG_EXT_MSG_T .
  188. methods GET_MESSAGE_DETAILED
  189. importing
  190. !IV_CONDITION type ZCA_MSG_CONDITION_D default '*'
  191. !IV_ROW type ZCA_MSG_TABIX_D optional
  192. preferred parameter IV_CONDITION
  193. returning
  194. value(ES_MSG) type BAL_S_MSG .
  195. methods GET_MESSAGE_WITH_HANDLE
  196. importing
  197. !IV_CONDITION type ZCA_MSG_CONDITION_D default '*'
  198. !IV_ROW type ZCA_MSG_TABIX_D optional
  199. exporting
  200. value(ES_MSGH) type BALMSGHNDL
  201. !ES_MSG type BAL_S_MSG .
  202. methods INITIALIZE .
  203. methods RESET_SECTION .
  204. methods SAVE
  205. importing
  206. !IV_UPDATE_TASK type BOOLE_D default ABAP_TRUE
  207. exporting
  208. !EV_LOGNUMBER type BALOGNR
  209. !EV_LOG_HANDLE type BALLOGHNDL
  210. raising
  211. ZCX_ERROR .
  212. methods SET_CONTEXT
  213. importing
  214. !IS_CONTEXT type CLIKE .
  215. methods SET_SECTION
  216. importing
  217. !IV_CONDITION type ZCA_MSG_CONDITION_D default '*' .
  218. protected section.
  219. *"* protected components of class ZCL_MESSAGES
  220. *"* do not include other source files here!!!
  221.  
  222. data GV_LOG_HANDLE type BALLOGHNDL .
  223. private section.
  224. *"* private components of class ZCL_MESSAGES
  225. *"* do not include other source files here!!!
  226.  
  227. data GS_CONTEXT type ref to DATA .
  228. data GS_LAST_MSGH type BALMSGHNDL .
  229. class-data GT_INSTANCES type ZCA_MSG_INSTANCES_Y .
  230. data GV_END_LAST_SECTION type I value -1. "#EC NOTEXT
  231. data GV_FOREIGN_LOG type FLAG .
  232. data GV_ID type STRING .
  233.  
  234. class-methods GET_LOG_BY_EXTNUMBER
  235. importing
  236. !IV_EXTNUMBER type BALNREXT
  237. !IV_OBJECT type BALOBJ_D default GC_DEFAULT-APPLOG-OBJECT
  238. !IV_SUBOBJECT type BALSUBOBJ
  239. returning
  240. value(RV_LOG_HANDLE) type BALLOGHNDL
  241. raising
  242. ZCX_NOT_FOUND .
  243. methods ADD_MSG_TO_HANDLER
  244. importing
  245. !IV_SUBOBJECT type BALSUBOBJ optional
  246. !IV_EXTNUMBER type BALNREXT optional
  247. !IV_LOG_HANDLE type BALLOGHNDL optional
  248. !IV_MSGID type SYMSGID default SY-MSGID
  249. !IV_MSGNO type SYMSGNO default SY-MSGNO
  250. !IV_MSGTY type SYMSGTY default SY-MSGTY
  251. !IV_MSGV1 type SYMSGV default SY-MSGV1
  252. !IV_MSGV2 type SYMSGV default SY-MSGV2
  253. !IV_MSGV3 type SYMSGV default SY-MSGV3
  254. !IV_MSGV4 type SYMSGV default SY-MSGV4
  255. !IV_PROBCLASS type BALPROBCL default '4'
  256. !IV_CONTEXT_NAME type TABNAME optional
  257. !IV_CONTEXT_VALUE type ANY optional
  258. !IT_BAPIRETURN type BAPIRET2_T optional
  259. !IS_BAPIRETURN type ANY optional
  260. !IV_FREE_TEXT type TEXT200 optional
  261. exporting
  262. !ET_MSGH type BAL_T_MSGH
  263. !EV_LOG_HANDLE type BALLOGHNDL
  264. !EV_SEVERITY type SYMSGTY
  265. raising
  266. ZCX_PARAMETER_MISSING
  267. ZCX_ERROR .
  268. methods CREATE_LOG
  269. importing
  270. !IV_SUBOBJECT type BALSUBOBJ
  271. !IV_EXTNUMBER type BALNREXT optional
  272. !IV_REUSE_LOG type BOOLE_D default ABAP_TRUE
  273. returning
  274. value(RV_LOG_HANDLE) type BALLOGHNDL
  275. raising
  276. ZCX_NOT_FOUND .
  277. methods GET_LOG_HANDLE
  278. importing
  279. !IV_SUBOBJECT type BALSUBOBJ optional
  280. !IV_EXTNUMBER type BALNREXT optional
  281. !IV_LOG_HANDLE type BALLOGHNDL optional
  282. !IV_NEW_LOG type BOOLE_D default ABAP_TRUE
  283. returning
  284. value(RV_LOG_HANDLE) type BALLOGHNDL
  285. raising
  286. ZCX_NOT_FOUND
  287. ZCX_ERROR .
  288. methods SEARCH_MESSAGES
  289. importing
  290. !IV_CONDITION type ZCA_MSG_CONDITION_D default '*'
  291. !IV_ROW type ZCA_MSG_TABIX_D optional
  292. preferred parameter IV_CONDITION
  293. returning
  294. value(ET_MSGH) type ref to BAL_T_MSGH .
  295. methods SET_LOG_HANDLE
  296. importing
  297. !IV_LOG_HANDLE type BALLOGHNDL
  298. raising
  299. ZCX_NOT_FOUND .
  300. ENDCLASS.
  301.  
  302.  
  303.  
  304. CLASS ZCL_MESSAGES IMPLEMENTATION.
  305.  
  306.  
  307. * <SIGNATURE>---------------------------------------------------------------------------------------+
  308. * | Instance Public Method ZCL_MESSAGES->ADD
  309. * +-------------------------------------------------------------------------------------------------+
  310. * | [--->] IV_CONDITION TYPE ZCA_MSG_CONDITION_D (default =SPACE)
  311. * | [--->] IV_MSGID TYPE SYMSGID (default =SY-MSGID)
  312. * | [--->] IV_MSGTY TYPE SYMSGTY (default =SY-MSGTY)
  313. * | [--->] IV_MSGNO TYPE SYMSGNO (default =SY-MSGNO)
  314. * | [--->] IV_MSGV1 TYPE SYMSGV (default =SY-MSGV1)
  315. * | [--->] IV_MSGV2 TYPE SYMSGV (default =SY-MSGV2)
  316. * | [--->] IV_MSGV3 TYPE SYMSGV (default =SY-MSGV3)
  317. * | [--->] IV_MSGV4 TYPE SYMSGV (default =SY-MSGV4)
  318. * | [--->] IV_ROW TYPE ZCA_MSG_TABIX_D(optional)
  319. * | [!CX!] ZCX_ERROR
  320. * +--------------------------------------------------------------------------------------</SIGNATURE>
  321. METHOD add.
  322.  
  323. DATA: lt_msgh TYPE bal_t_msgh,
  324. ls_context TYPE zca_msg_context_s.
  325.  
  326. FIELD-SYMBOLS: <ls_context> TYPE any.
  327.  
  328. ls_context-condition = iv_condition.
  329. TRANSLATE ls_context-condition TO LOWER CASE.
  330. ls_context-id = gv_id.
  331. ls_context-row = iv_row.
  332.  
  333. IF gv_context = gc_default-context.
  334. ASSIGN ls_context TO <ls_context>.
  335. ELSE.
  336. ASSIGN gs_context->* TO <ls_context>.
  337. MOVE-CORRESPONDING ls_context TO <ls_context>.
  338. ENDIF.
  339.  
  340. add_msg_to_handler( EXPORTING
  341. iv_subobject = gv_logclass
  342. iv_log_handle = gv_log_handle
  343. iv_msgid = iv_msgid
  344. iv_msgno = iv_msgno
  345. iv_msgty = iv_msgty
  346. iv_msgv1 = iv_msgv1
  347. iv_msgv2 = iv_msgv2
  348. iv_msgv3 = iv_msgv3
  349. iv_msgv4 = iv_msgv4
  350. iv_context_name = gv_context
  351. iv_context_value = <ls_context>
  352. IMPORTING
  353. et_msgh = lt_msgh ).
  354.  
  355. READ TABLE lt_msgh INTO gs_last_msgh INDEX 1.
  356.  
  357. ENDMETHOD.
  358.  
  359.  
  360. * <SIGNATURE>---------------------------------------------------------------------------------------+
  361. * | Instance Public Method ZCL_MESSAGES->ADD_BAPIRETURN
  362. * +-------------------------------------------------------------------------------------------------+
  363. * | [--->] IV_CONDITION TYPE ZCA_MSG_CONDITION_D (default =SPACE)
  364. * | [--->] IT_BAPIRETURN TYPE BAPIRETTAB(optional)
  365. * | [--->] IS_BAPIRETURN TYPE ANY(optional)
  366. * | [<-()] EV_SEVERITY TYPE SYMSGTY
  367. * +--------------------------------------------------------------------------------------</SIGNATURE>
  368. METHOD add_bapireturn .
  369.  
  370. DATA: ls_context TYPE zca_msg_context_s,
  371. lt_msgh TYPE bal_t_msgh.
  372.  
  373. FIELD-SYMBOLS: <ls_context> TYPE any.
  374.  
  375. CHECK it_bapireturn IS NOT INITIAL OR
  376. is_bapireturn IS NOT INITIAL.
  377.  
  378. ls_context-condition = iv_condition.
  379. TRANSLATE ls_context-condition TO LOWER CASE.
  380. ls_context-id = gv_id.
  381.  
  382. IF gv_context = 'ZCA_MSG_CONTEXT_S'.
  383. ASSIGN ls_context TO <ls_context>.
  384. ELSE.
  385. ASSIGN gs_context->* TO <ls_context>.
  386. MOVE-CORRESPONDING ls_context TO <ls_context>.
  387. ENDIF.
  388.  
  389. add_msg_to_handler( EXPORTING
  390. iv_subobject = gv_logclass
  391. iv_log_handle = gv_log_handle
  392. iv_context_name = gv_context
  393. iv_context_value = <ls_context>
  394. it_bapireturn = it_bapireturn
  395. is_bapireturn = is_bapireturn
  396. IMPORTING
  397. et_msgh = lt_msgh
  398. ev_log_handle = gv_log_handle
  399. ev_severity = ev_severity ).
  400.  
  401. sy-tfill = lines( lt_msgh ).
  402. IF sy-tfill > 0.
  403. READ TABLE lt_msgh INTO gs_last_msgh INDEX sy-tfill.
  404. ENDIF.
  405.  
  406. ENDMETHOD.
  407.  
  408.  
  409. * <SIGNATURE>---------------------------------------------------------------------------------------+
  410. * | Instance Public Method ZCL_MESSAGES->ADD_FREE_TEXT
  411. * +-------------------------------------------------------------------------------------------------+
  412. * | [--->] IV_CONDITION TYPE ZCA_MSG_CONDITION_D (default =SPACE)
  413. * | [--->] IV_ROW TYPE ZCA_MSG_TABIX_D(optional)
  414. * | [--->] IV_MSGTY TYPE SYMSGTY (default ='I')
  415. * | [--->] IV_TEXT TYPE CSEQUENCE
  416. * +--------------------------------------------------------------------------------------</SIGNATURE>
  417. METHOD add_free_text.
  418.  
  419. DATA: lt_msgh TYPE bal_t_msgh,
  420. ls_context TYPE zca_msg_context_s,
  421. lv_text TYPE text200.
  422.  
  423. FIELD-SYMBOLS: <ls_context> TYPE any.
  424.  
  425. ls_context-condition = iv_condition.
  426. TRANSLATE ls_context-condition TO LOWER CASE.
  427. ls_context-id = gv_id.
  428. ls_context-row = iv_row.
  429. lv_text = iv_text.
  430.  
  431. IF gv_context = gc_default-context.
  432. ASSIGN ls_context TO <ls_context>.
  433. ELSE.
  434. ASSIGN gs_context->* TO <ls_context>.
  435. MOVE-CORRESPONDING ls_context TO <ls_context>.
  436. ENDIF.
  437.  
  438. add_msg_to_handler( EXPORTING
  439. iv_subobject = gv_logclass
  440. iv_log_handle = gv_log_handle
  441. iv_context_name = gv_context
  442. iv_context_value = <ls_context>
  443. iv_free_text = lv_text
  444. iv_msgty = iv_msgty
  445. IMPORTING
  446. et_msgh = lt_msgh ).
  447.  
  448. READ TABLE lt_msgh INTO gs_last_msgh INDEX 1.
  449.  
  450. ENDMETHOD.
  451.  
  452.  
  453. * <SIGNATURE>---------------------------------------------------------------------------------------+
  454. * | Instance Public Method ZCL_MESSAGES->ADD_FROM_BDC
  455. * +-------------------------------------------------------------------------------------------------+
  456. * | [--->] IT_MSG TYPE ETTCD_MSG_TABTYPE
  457. * | [--->] IV_ALWAYS TYPE ABAP_BOOL (default =ABAP_FALSE)
  458. * | [--->] IV_BATCH_TEST TYPE ABAP_BOOL (default =ABAP_FALSE)
  459. * | [<-()] EV_MSGS TYPE I
  460. * +--------------------------------------------------------------------------------------</SIGNATURE>
  461. METHOD add_from_bdc.
  462.  
  463. DATA: lv_batch TYPE sy-batch.
  464.  
  465. FIELD-SYMBOLS: <ls_msg> TYPE bdcmsgcoll .
  466.  
  467. lv_batch = sy-batch.
  468. IF iv_batch_test = abap_true. " Batch-Modus simulieren
  469. lv_batch = abap_true.
  470. ENDIF.
  471. IF iv_always = abap_true. " Batch-Modus ignorieren (wird höher gewichtet als Simulation)
  472. CLEAR lv_batch.
  473. ENDIF.
  474.  
  475. LOOP AT it_msg
  476. TRANSPORTING NO FIELDS
  477. WHERE msgtyp CA 'EAX'.
  478. EXIT.
  479. ENDLOOP.
  480.  
  481. IF sy-subrc IS INITIAL OR " Die Tabelle enthält Fehlermeldungen -> Log in jedem Fall schreiben
  482. lv_batch IS INITIAL. " Sonst Log nur im Dialog-Modus schreiben.
  483.  
  484. LOOP AT it_msg ASSIGNING <ls_msg>.
  485. MESSAGE ID <ls_msg>-msgid TYPE <ls_msg>-msgtyp NUMBER <ls_msg>-msgnr
  486. WITH <ls_msg>-msgv1 <ls_msg>-msgv2 <ls_msg>-msgv3 <ls_msg>-msgv4
  487. INTO sy-msgli.
  488. ev_msgs = sy-tabix.
  489. add( ).
  490. ENDLOOP.
  491. ENDIF.
  492.  
  493. ENDMETHOD.
  494.  
  495.  
  496. * <SIGNATURE>---------------------------------------------------------------------------------------+
  497. * | Instance Public Method ZCL_MESSAGES->ADD_FROM_EXCEPTION
  498. * +-------------------------------------------------------------------------------------------------+
  499. * | [--->] IO_EXCEPTION TYPE REF TO CX_ROOT
  500. * | [--->] IV_CONDITION TYPE ZCA_MSG_CONDITION_D (default =SPACE)
  501. * | [--->] IV_ROW TYPE ZCA_MSG_TABIX_D(optional)
  502. * | [--->] IV_MSGTY TYPE SYMSGTY (default ='E')
  503. * +--------------------------------------------------------------------------------------</SIGNATURE>
  504. METHOD add_from_exception.
  505.  
  506. DATA: lv_text TYPE string.
  507.  
  508. FIELD-SYMBOLS: <lv_msgid> TYPE symsgid,
  509. <lv_msgno> TYPE symsgno,
  510. <lv_msgv1> TYPE symsgv,
  511. <lv_msgv2> TYPE symsgv,
  512. <lv_msgv3> TYPE symsgv,
  513. <lv_msgv4> TYPE symsgv,
  514. <lv_text> TYPE csequence.
  515.  
  516. *--------------------------------------------------------------------*
  517. * Strategie: Zuerst die T100-Attribute anschauen,
  518. * danach den Wert eines allfälligen TEXT-Attributs,
  519. * dann erst den allgemeinen, im DDIC gepflegten Text verwenden...
  520. *--------------------------------------------------------------------*
  521.  
  522. ASSIGN io_exception->('T100_MSGID') TO <lv_msgid>.
  523. IF sy-subrc IS INITIAL AND <lv_msgid> IS NOT INITIAL.
  524. ASSIGN io_exception->('T100_MSGNO') TO <lv_msgno>.
  525. ASSIGN io_exception->('T100_MSGV1') TO <lv_msgv1>.
  526. ASSIGN io_exception->('T100_MSGV2') TO <lv_msgv2>.
  527. ASSIGN io_exception->('T100_MSGV3') TO <lv_msgv3>.
  528. ASSIGN io_exception->('T100_MSGV4') TO <lv_msgv4>.
  529. add( iv_condition = iv_condition
  530. iv_row = iv_row
  531. iv_msgid = <lv_msgid>
  532. iv_msgno = <lv_msgno>
  533. iv_msgty = iv_msgty
  534. iv_msgv1 = <lv_msgv1>
  535. iv_msgv2 = <lv_msgv2>
  536. iv_msgv3 = <lv_msgv3>
  537. iv_msgv4 = <lv_msgv4> ).
  538. ELSE.
  539. ASSIGN io_exception->('TEXT') TO <lv_text>.
  540. IF sy-subrc IS INITIAL AND <lv_text> IS NOT INITIAL.
  541. lv_text = <lv_text>.
  542. ELSE.
  543. lv_text = io_exception->get_text( ).
  544. ENDIF.
  545. add_free_text( iv_condition = iv_condition
  546. iv_row = iv_row
  547. iv_msgty = iv_msgty
  548. iv_text = lv_text ).
  549. ENDIF.
  550.  
  551. ENDMETHOD.
  552.  
  553.  
  554. * <SIGNATURE>---------------------------------------------------------------------------------------+
  555. * | Instance Private Method ZCL_MESSAGES->ADD_MSG_TO_HANDLER
  556. * +-------------------------------------------------------------------------------------------------+
  557. * | [--->] IV_SUBOBJECT TYPE BALSUBOBJ(optional)
  558. * | [--->] IV_EXTNUMBER TYPE BALNREXT(optional)
  559. * | [--->] IV_LOG_HANDLE TYPE BALLOGHNDL(optional)
  560. * | [--->] IV_MSGID TYPE SYMSGID (default =SY-MSGID)
  561. * | [--->] IV_MSGNO TYPE SYMSGNO (default =SY-MSGNO)
  562. * | [--->] IV_MSGTY TYPE SYMSGTY (default =SY-MSGTY)
  563. * | [--->] IV_MSGV1 TYPE SYMSGV (default =SY-MSGV1)
  564. * | [--->] IV_MSGV2 TYPE SYMSGV (default =SY-MSGV2)
  565. * | [--->] IV_MSGV3 TYPE SYMSGV (default =SY-MSGV3)
  566. * | [--->] IV_MSGV4 TYPE SYMSGV (default =SY-MSGV4)
  567. * | [--->] IV_PROBCLASS TYPE BALPROBCL (default ='4')
  568. * | [--->] IV_CONTEXT_NAME TYPE TABNAME(optional)
  569. * | [--->] IV_CONTEXT_VALUE TYPE ANY(optional)
  570. * | [--->] IT_BAPIRETURN TYPE BAPIRET2_T(optional)
  571. * | [--->] IS_BAPIRETURN TYPE ANY(optional)
  572. * | [--->] IV_FREE_TEXT TYPE TEXT200(optional)
  573. * | [<---] ET_MSGH TYPE BAL_T_MSGH
  574. * | [<---] EV_LOG_HANDLE TYPE BALLOGHNDL
  575. * | [<---] EV_SEVERITY TYPE SYMSGTY
  576. * | [!CX!] ZCX_PARAMETER_MISSING
  577. * | [!CX!] ZCX_ERROR
  578. * +--------------------------------------------------------------------------------------</SIGNATURE>
  579. METHOD add_msg_to_handler.
  580.  
  581. DATA: lt_bapireturn TYPE bapiret2_t,
  582. ls_msg TYPE bal_s_msg,
  583. ls_msgh TYPE balmsghndl,
  584. lv_off_max TYPE i,
  585. lv_off TYPE i,
  586. lv_ref TYPE REF TO data.
  587.  
  588. FIELD-SYMBOLS: <ls_bapireturn> TYPE bapiret2,
  589. <ls_context> TYPE any,
  590. <lv_row> TYPE any.
  591.  
  592. IF iv_subobject IS INITIAL AND iv_log_handle IS INITIAL.
  593. " Log Handle und Subobjekt dürfen nicht beide leer sein!
  594. MESSAGE e403 INTO sy-msgli.
  595. raise_exception parameter_missing.
  596. ENDIF.
  597.  
  598. " Log Handle ermitteln
  599. get_log_handle( iv_subobject = iv_subobject
  600. iv_extnumber = iv_extnumber
  601. iv_log_handle = iv_log_handle
  602. iv_new_log = abap_false ).
  603.  
  604. *----------------------------------------------------------------------
  605. * BAPI-Einzelnachricht sammeln, falls übergeben
  606. *----------------------------------------------------------------------
  607. lt_bapireturn = it_bapireturn.
  608. IF is_bapireturn IS NOT INITIAL.
  609. APPEND INITIAL LINE TO lt_bapireturn ASSIGNING <ls_bapireturn>.
  610. MOVE-CORRESPONDING is_bapireturn TO <ls_bapireturn>.
  611. ENDIF.
  612.  
  613. *----------------------------------------------------------------------
  614. * Tabelle von Nachrichten sammeln, falls übergeben
  615. *----------------------------------------------------------------------
  616. LOOP AT lt_bapireturn ASSIGNING <ls_bapireturn>.
  617. CLEAR ls_msg.
  618. ls_msg-msgid = <ls_bapireturn>-id.
  619. ls_msg-msgty = <ls_bapireturn>-type.
  620. ls_msg-msgno = <ls_bapireturn>-number.
  621. ls_msg-msgv1 = <ls_bapireturn>-message_v1.
  622. ls_msg-msgv2 = <ls_bapireturn>-message_v2.
  623. ls_msg-msgv3 = <ls_bapireturn>-message_v3.
  624. ls_msg-msgv4 = <ls_bapireturn>-message_v4.
  625. IF NOT iv_context_name IS INITIAL.
  626. ls_msg-context-tabname = iv_context_name.
  627. CREATE DATA lv_ref LIKE iv_context_value.
  628. ASSIGN lv_ref->* TO <ls_context>.
  629. <ls_context> = iv_context_value.
  630. ASSIGN COMPONENT 'ROW' OF STRUCTURE <ls_context> TO <lv_row>.
  631. IF sy-subrc EQ 0.
  632. <lv_row> = <ls_bapireturn>-row.
  633. ENDIF.
  634. ls_msg-context-value = <ls_context>.
  635. ENDIF.
  636. IF <ls_bapireturn>-id NE space.
  637. CALL FUNCTION 'BAL_LOG_MSG_ADD'
  638. EXPORTING
  639. i_log_handle = gv_log_handle
  640. i_s_msg = ls_msg
  641. IMPORTING
  642. e_s_msg_handle = ls_msgh
  643. EXCEPTIONS
  644. OTHERS = 4.
  645. ELSE.
  646. CALL FUNCTION 'BAL_LOG_MSG_ADD_FREE_TEXT'
  647. EXPORTING
  648. i_log_handle = gv_log_handle
  649. i_msgty = <ls_bapireturn>-type
  650. i_text = <ls_bapireturn>-message
  651. i_probclass = iv_probclass
  652. i_s_context = ls_msg-context
  653. IMPORTING
  654. e_s_msg_handle = ls_msgh
  655. EXCEPTIONS
  656. OTHERS = 4.
  657. ENDIF.
  658. check_subrc error.
  659. IF et_msgh IS REQUESTED.
  660. INSERT ls_msgh INTO TABLE et_msgh.
  661. ENDIF.
  662. IF ev_severity IS REQUESTED.
  663. FIND ls_msg-msgty IN gc_msg_type MATCH OFFSET lv_off.
  664. IF lv_off > lv_off_max.
  665. lv_off_max = lv_off.
  666. ENDIF.
  667. ENDIF.
  668. ENDLOOP.
  669.  
  670. *----------------------------------------------------------------------
  671. * Einzelnachricht sammeln, falls übergeben
  672. *----------------------------------------------------------------------
  673. IF
  674. * Wenn explizit in iv_msgid etc. Werte übergeben wurden, ist die
  675. * Nachricht auf jeden Fall zu sammeln
  676. iv_msgid IS SUPPLIED
  677. OR
  678. * Wenn auf keine andere Weise eine Nachricht übergeben wurde, wird davon aus-
  679. * gegangen, dass die in iv_msgid etc. enthaltene Nachricht zu sammeln ist.
  680. * ACHTUNG: In diesem Fall braucht iv_msgid nicht supplied zu sein, denn eine
  681. * Nachricht kann auch implizit über die Defaultwerte übergeben worden sein
  682. lt_bapireturn IS INITIAL AND
  683. iv_free_text IS INITIAL AND
  684. iv_msgid IS NOT INITIAL.
  685. CLEAR ls_msg.
  686. ls_msg-msgid = iv_msgid.
  687. ls_msg-msgty = iv_msgty.
  688. ls_msg-msgno = iv_msgno.
  689. ls_msg-msgv1 = iv_msgv1.
  690. ls_msg-msgv2 = iv_msgv2.
  691. ls_msg-msgv3 = iv_msgv3.
  692. ls_msg-msgv4 = iv_msgv4.
  693. ls_msg-probclass = iv_probclass.
  694. IF NOT iv_context_name IS INITIAL.
  695. ls_msg-context-tabname = iv_context_name.
  696. ls_msg-context-value = iv_context_value.
  697. ENDIF.
  698. CALL FUNCTION 'BAL_LOG_MSG_ADD'
  699. EXPORTING
  700. i_log_handle = gv_log_handle
  701. i_s_msg = ls_msg
  702. IMPORTING
  703. e_s_msg_handle = ls_msgh
  704. EXCEPTIONS
  705. OTHERS = 4.
  706. check_subrc error.
  707. IF et_msgh IS REQUESTED.
  708. INSERT ls_msgh INTO TABLE et_msgh.
  709. ENDIF.
  710. IF ev_severity IS REQUESTED.
  711. FIND ls_msg-msgty IN gc_msg_type MATCH OFFSET lv_off.
  712. IF lv_off > lv_off_max.
  713. lv_off_max = lv_off.
  714. ENDIF.
  715. ENDIF.
  716. ENDIF.
  717.  
  718. IF iv_free_text NE space AND iv_msgty IS SUPPLIED.
  719. IF iv_msgid IS SUPPLIED.
  720. " Freitext und Nachrichten-Parameter können nicht gleichzeitig übergeben werden!
  721. MESSAGE e103 INTO sy-msgli.
  722. raise_exception error.
  723. ENDIF.
  724. IF NOT iv_context_name IS INITIAL.
  725. ls_msg-context-tabname = iv_context_name.
  726. ls_msg-context-value = iv_context_value.
  727. ENDIF.
  728. CALL FUNCTION 'BAL_LOG_MSG_ADD_FREE_TEXT'
  729. EXPORTING
  730. i_log_handle = gv_log_handle
  731. i_msgty = iv_msgty
  732. i_text = iv_free_text
  733. i_s_context = ls_msg-context
  734. i_probclass = iv_probclass
  735. IMPORTING
  736. e_s_msg_handle = ls_msgh
  737. EXCEPTIONS
  738. OTHERS = 4.
  739. check_subrc error.
  740. IF et_msgh IS REQUESTED.
  741. INSERT ls_msgh INTO TABLE et_msgh.
  742. ENDIF.
  743. IF ev_severity IS REQUESTED.
  744. FIND ls_msg-msgty IN gc_msg_type MATCH OFFSET lv_off.
  745. IF lv_off > lv_off_max.
  746. lv_off_max = lv_off.
  747. ENDIF.
  748. ENDIF.
  749. ENDIF.
  750.  
  751. IF ev_severity IS REQUESTED AND lv_off_max > 0.
  752. ev_severity = gc_msg_type+lv_off_max(1).
  753. ENDIF.
  754.  
  755. IF ev_log_handle IS REQUESTED.
  756. ev_log_handle = gv_log_handle.
  757. ENDIF.
  758.  
  759. ENDMETHOD.
  760.  
  761.  
  762. * <SIGNATURE>---------------------------------------------------------------------------------------+
  763. * | Instance Public Method ZCL_MESSAGES->CONSTRUCTOR
  764. * +-------------------------------------------------------------------------------------------------+
  765. * | [--->] IV_ID TYPE CSEQUENCE
  766. * | [--->] IV_LOGCLASS TYPE BALSUBOBJ (default =GC_DEFAULT-APPLOG-SUBOBJ)
  767. * | [--->] IV_CONTEXT TYPE TABNAME (default =GC_DEFAULT-CONTEXT)
  768. * | [--->] IV_LOG_HANDLE TYPE BALLOGHNDL(optional)
  769. * | [!CX!] ZCX_NOT_FOUND
  770. * | [!CX!] ZCX_STOP_NO_CHECK
  771. * +--------------------------------------------------------------------------------------</SIGNATURE>
  772. METHOD constructor.
  773.  
  774. DATA: lo_ex TYPE REF TO cx_root,
  775. ls_instance TYPE zca_msg_instance_s,
  776. lv_extnumber TYPE balnrext,
  777. lv_text TYPE text255.
  778.  
  779. gv_context = iv_context.
  780. IF gv_context <> gc_default-context.
  781. " Benutzerdefinierte Contextstruktur erzeugen
  782. TRY.
  783. CREATE DATA gs_context TYPE (gv_context).
  784. CATCH cx_sy_create_data_error INTO lo_ex.
  785. " Das Datenobjekt konnte nicht erzeugt werden. Die Struktur &1 existiert nicht
  786. lv_text = lo_ex->get_text( ).
  787. RAISE EXCEPTION TYPE zcx_not_found EXPORTING text = lv_text.
  788. ENDTRY.
  789. ENDIF.
  790.  
  791. IF iv_log_handle IS INITIAL.
  792. gv_logclass = iv_logclass.
  793.  
  794. " ID für Protokollverwaltung (wird Ext. ID auf der DB)
  795. gv_id = iv_id.
  796. ls_instance-id = iv_id.
  797. ls_instance-messages = me.
  798. lv_extnumber = iv_id.
  799.  
  800. TRY.
  801. gv_log_handle = create_log( iv_subobject = gv_logclass
  802. iv_extnumber = lv_extnumber ).
  803. CATCH zcx_error INTO lo_ex.
  804. " Fataler Fehler: Log kann nicht angelegt werden ==> Bearbeitung abbrechen
  805. lv_text = lo_ex->get_text( ).
  806. RAISE EXCEPTION TYPE zcx_stop_no_check EXPORTING text = lv_text.
  807. ENDTRY.
  808. ELSE.
  809. set_log_handle( iv_log_handle ).
  810. gv_foreign_log = abap_true.
  811. ENDIF.
  812.  
  813. READ TABLE gt_instances TRANSPORTING NO FIELDS
  814. WITH TABLE KEY id = ls_instance-id.
  815. IF sy-subrc IS INITIAL.
  816. " Durch Aufruf des Konstruktors ist explizit eine neue Sammler-Instanz gewünscht
  817. MODIFY TABLE gt_instances FROM ls_instance.
  818. ELSE.
  819. INSERT ls_instance INTO TABLE gt_instances.
  820. ENDIF.
  821.  
  822. ENDMETHOD.
  823.  
  824.  
  825. * <SIGNATURE>---------------------------------------------------------------------------------------+
  826. * | Instance Public Method ZCL_MESSAGES->COPY
  827. * +-------------------------------------------------------------------------------------------------+
  828. * | [--->] IO_TARGET TYPE REF TO ZCL_MESSAGES
  829. * | [--->] IV_CONDITION TYPE ZCA_MSG_CONDITION_D (default ='*')
  830. * | [--->] IV_ROW TYPE ZCA_MSG_TABIX_D(optional)
  831. * | [!CX!] ZCX_ERROR
  832. * +--------------------------------------------------------------------------------------</SIGNATURE>
  833. METHOD copy.
  834.  
  835. DATA: lt_msg TYPE aqtbal_s_msg,
  836. ls_context TYPE REF TO data,
  837. lv_log_handle TYPE balloghndl,
  838. lv_tabname TYPE baltabname.
  839.  
  840. FIELD-SYMBOLS: <ls_msg> TYPE bal_s_msg,
  841. <ls_context> TYPE any,
  842. <lv_id> TYPE zca_msg_message_id_d.
  843.  
  844. * Meldungen holen
  845. IF iv_row IS SUPPLIED.
  846. CALL METHOD get_messages_detailed
  847. EXPORTING
  848. iv_condition = iv_condition
  849. iv_row = iv_row
  850. RECEIVING
  851. et_msg = lt_msg.
  852. ELSE.
  853. CALL METHOD get_messages_detailed
  854. EXPORTING
  855. iv_condition = iv_condition
  856. RECEIVING
  857. et_msg = lt_msg.
  858. ENDIF.
  859.  
  860. lv_log_handle = io_target->get_handle( ).
  861.  
  862. * ... und auf BAL-Ebene in das andere Log übertragen
  863. LOOP AT lt_msg ASSIGNING <ls_msg>.
  864.  
  865. * ID im Msg-Context ändern
  866. IF <ls_msg>-context-tabname NE space.
  867. IF lv_tabname NE <ls_msg>-context-tabname.
  868. lv_tabname = <ls_msg>-context-tabname.
  869. CREATE DATA ls_context TYPE (lv_tabname).
  870. IF ls_context IS BOUND.
  871. ASSIGN ls_context->* TO <ls_context>.
  872. ASSIGN COMPONENT gc_fieldname-id OF STRUCTURE <ls_context>
  873. TO <lv_id>.
  874. ENDIF.
  875. ENDIF.
  876. IF <lv_id> IS ASSIGNED.
  877. MOVE <ls_msg>-context-value TO <ls_context>.
  878. <lv_id> = io_target->gv_id.
  879. MOVE <ls_context> TO <ls_msg>-context-value.
  880. ENDIF.
  881. ENDIF.
  882.  
  883. CALL FUNCTION 'BAL_LOG_MSG_ADD'
  884. EXPORTING
  885. i_log_handle = lv_log_handle
  886. i_s_msg = <ls_msg>
  887. IMPORTING
  888. e_s_msg_handle = io_target->gs_last_msgh
  889. EXCEPTIONS
  890. log_not_found = 1
  891. msg_inconsistent = 2
  892. log_is_full = 3
  893. OTHERS = 4.
  894. IF sy-subrc <> 0.
  895. RAISE EXCEPTION TYPE zcx_error
  896. EXPORTING
  897. t100_msgid = sy-msgid
  898. t100_msgno = sy-msgno
  899. t100_msgv1 = sy-msgv1
  900. t100_msgv2 = sy-msgv2
  901. t100_msgv3 = sy-msgv3
  902. t100_msgv4 = sy-msgv4.
  903. ENDIF.
  904. ENDLOOP.
  905.  
  906. ENDMETHOD. " ADD_FROM_BDC
  907.  
  908.  
  909. * <SIGNATURE>---------------------------------------------------------------------------------------+
  910. * | Instance Private Method ZCL_MESSAGES->CREATE_LOG
  911. * +-------------------------------------------------------------------------------------------------+
  912. * | [--->] IV_SUBOBJECT TYPE BALSUBOBJ
  913. * | [--->] IV_EXTNUMBER TYPE BALNREXT(optional)
  914. * | [--->] IV_REUSE_LOG TYPE BOOLE_D (default =ABAP_TRUE)
  915. * | [<-()] RV_LOG_HANDLE TYPE BALLOGHNDL
  916. * | [!CX!] ZCX_NOT_FOUND
  917. * +--------------------------------------------------------------------------------------</SIGNATURE>
  918. METHOD create_log.
  919.  
  920. DATA: ls_log TYPE bal_s_log.
  921.  
  922. " Wenn das aktuelle Log passt, soll dieses verwendet werden
  923. IF iv_reuse_log = abap_true AND
  924. gv_log_handle IS NOT INITIAL.
  925.  
  926. CALL FUNCTION 'BAL_LOG_HDR_READ'
  927. EXPORTING i_log_handle = gv_log_handle
  928. IMPORTING e_s_log = ls_log
  929. EXCEPTIONS OTHERS = 2.
  930.  
  931. IF sy-subrc IS NOT INITIAL.
  932. raise_exception not_found.
  933. ENDIF.
  934.  
  935. " Prüfe, ob ExtNumber und Subobjekt passt
  936. IF ( iv_extnumber IS INITIAL OR iv_extnumber = ls_log-extnumber ) AND
  937. iv_subobject = ls_log-subobject.
  938. rv_log_handle = gv_log_handle.
  939. RETURN.
  940. ENDIF.
  941. ENDIF.
  942.  
  943. rv_log_handle = get_log_handle( iv_subobject = iv_subobject
  944. iv_extnumber = iv_extnumber
  945. iv_new_log = abap_true ).
  946. ENDMETHOD.
  947.  
  948.  
  949. * <SIGNATURE>---------------------------------------------------------------------------------------+
  950. * | Instance Public Method ZCL_MESSAGES->DELETE
  951. * +-------------------------------------------------------------------------------------------------+
  952. * | [--->] IV_CONDITION TYPE ZCA_MSG_CONDITION_D (default ='*')
  953. * | [--->] IV_ROW TYPE ZCA_MSG_TABIX_D(optional)
  954. * +--------------------------------------------------------------------------------------</SIGNATURE>
  955. METHOD delete.
  956.  
  957. DATA: ls_cfil TYPE bal_s_cfil,
  958. ls_mfil TYPE bal_s_mfil,
  959. ls_msgn TYPE bal_s_msgn,
  960. ls_range TYPE bal_rfield,
  961. lt_cfil TYPE bal_t_cfil,
  962. lt_logh TYPE bal_t_logh,
  963. lt_msgh TYPE bal_t_msgh.
  964.  
  965. FIELD-SYMBOLS: <ls_msgh> TYPE balmsghndl.
  966.  
  967. * Wenn Meldungen gesammelt wurden, gibt es ein Log Handle
  968. CHECK gv_log_handle IS NOT INITIAL.
  969. INSERT gv_log_handle INTO TABLE lt_logh.
  970.  
  971. * Kontext als Filter aufbereiten
  972. IF iv_condition NE '*'.
  973. ls_cfil-tabname = gv_context.
  974. ls_cfil-fieldname = gc_fieldname-condition.
  975. ls_range-option = 'EQ'.
  976. ls_range-sign = 'I'.
  977. ls_range-low = iv_condition.
  978. TRANSLATE ls_range-low TO LOWER CASE.
  979. APPEND ls_range TO ls_cfil-t_range.
  980. INSERT ls_cfil INTO TABLE lt_cfil.
  981. ENDIF.
  982.  
  983. * ID als Filter
  984. ls_cfil-tabname = gv_context.
  985. ls_cfil-fieldname = gc_fieldname-id.
  986. ls_range-option = 'EQ'.
  987. ls_range-sign = 'I'.
  988. ls_range-low = gv_id.
  989. APPEND ls_range TO ls_cfil-t_range.
  990. INSERT ls_cfil INTO TABLE lt_cfil.
  991.  
  992. * Zeilenfeld als Filter
  993. IF iv_row IS NOT INITIAL.
  994. CLEAR ls_cfil.
  995. ls_cfil-tabname = gv_context.
  996. ls_cfil-fieldname = gc_fieldname-row.
  997. ls_range-option = 'EQ'.
  998. ls_range-sign = 'I'.
  999. ls_range-low = iv_row.
  1000. APPEND ls_range TO ls_cfil-t_range.
  1001. INSERT ls_cfil INTO TABLE lt_cfil.
  1002. ENDIF.
  1003.  
  1004. IF gv_end_last_section >= 0.
  1005. ls_msgn-sign = 'I'.
  1006. ls_msgn-option = 'GT'.
  1007. ls_msgn-low = gv_end_last_section.
  1008. APPEND ls_msgn TO ls_mfil-msgnumber.
  1009. ENDIF.
  1010.  
  1011. * Meldungen suchen
  1012. CALL FUNCTION 'BAL_GLB_SEARCH_MSG'
  1013. EXPORTING
  1014. i_s_msg_filter = ls_mfil
  1015. i_t_log_handle = lt_logh
  1016. i_t_msg_context_filter = lt_cfil
  1017. IMPORTING
  1018. e_t_msg_handle = lt_msgh
  1019. EXCEPTIONS
  1020. msg_not_found = 1
  1021. OTHERS = 2.
  1022. IF sy-subrc <> 0.
  1023. EXIT.
  1024. ENDIF.
  1025.  
  1026. * Meldungen löschen
  1027. LOOP AT lt_msgh ASSIGNING <ls_msgh>.
  1028. CALL FUNCTION 'BAL_LOG_MSG_DELETE'
  1029. EXPORTING
  1030. i_s_msg_handle = <ls_msgh>
  1031. EXCEPTIONS
  1032. OTHERS = 0.
  1033. ENDLOOP.
  1034.  
  1035. ENDMETHOD. "constructor
  1036.  
  1037.  
  1038. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1039. * | Instance Public Method ZCL_MESSAGES->DELETE_SINGLE
  1040. * +-------------------------------------------------------------------------------------------------+
  1041. * | [--->] IS_MSGH TYPE BALMSGHNDL
  1042. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1043. METHOD delete_single .
  1044.  
  1045. * Dieser Aufruf könnte natürlich auch direkt ausgeführt
  1046. * werden. Aus Sicht der Kapselung ist es aber besser, ihn
  1047. * durch ZCL_MESSAGES noch einmal zu verschalen: Wenn schon
  1048. * ZCL_MESSAGES die Klasse zum Sammeln von Nachrichten ist,
  1049. * so legt ihre Implementierung fest, WIE eine Nachricht zu
  1050. * behandeln ist
  1051.  
  1052. CALL FUNCTION 'BAL_LOG_MSG_DELETE'
  1053. EXPORTING
  1054. i_s_msg_handle = is_msgh
  1055. EXCEPTIONS
  1056. OTHERS = 0.
  1057.  
  1058. ENDMETHOD.
  1059.  
  1060.  
  1061. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1062. * | Instance Public Method ZCL_MESSAGES->DISPLAY
  1063. * +-------------------------------------------------------------------------------------------------+
  1064. * | [--->] IV_FULLSCREEN TYPE FLAG (default ='X')
  1065. * | [--->] IS_PROF TYPE BAL_S_PROF(optional)
  1066. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1067. METHOD display .
  1068.  
  1069. DATA: ls_prof TYPE bal_s_prof,
  1070. lt_logh TYPE bal_t_logh.
  1071.  
  1072. INSERT gv_log_handle INTO TABLE lt_logh.
  1073.  
  1074. IF is_prof IS SUPPLIED.
  1075. ls_prof = is_prof.
  1076. ELSE.
  1077. IF iv_fullscreen EQ 'X'.
  1078. CALL FUNCTION 'BAL_DSP_PROFILE_NO_TREE_GET'
  1079. IMPORTING
  1080. e_s_display_profile = ls_prof.
  1081. ELSE.
  1082. CALL FUNCTION 'BAL_DSP_PROFILE_POPUP_GET'
  1083. IMPORTING
  1084. e_s_display_profile = ls_prof.
  1085. ENDIF.
  1086. ls_prof-use_grid = 'X'.
  1087. ENDIF.
  1088. CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
  1089. EXPORTING
  1090. i_s_display_profile = ls_prof
  1091. i_t_log_handle = lt_logh
  1092. EXCEPTIONS
  1093. profile_inconsistent = 1
  1094. internal_error = 2
  1095. no_data_available = 3
  1096. no_authority = 4
  1097. OTHERS = 5.
  1098. IF sy-subrc <> 0.
  1099. MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
  1100. WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  1101. ENDIF.
  1102.  
  1103. ENDMETHOD.
  1104.  
  1105.  
  1106. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1107. * | Static Public Method ZCL_MESSAGES=>FILL_BAPIRET2
  1108. * +-------------------------------------------------------------------------------------------------+
  1109. * | [--->] IV_MSGID TYPE SYMSGID (default =SY-MSGID)
  1110. * | [--->] IV_MSGNO TYPE SYMSGNO (default =SY-MSGNO)
  1111. * | [--->] IV_MSGTY TYPE SYMSGTY (default =SY-MSGTY)
  1112. * | [--->] IV_MSGV1 TYPE SYMSGV (default =SY-MSGV1)
  1113. * | [--->] IV_MSGV2 TYPE SYMSGV (default =SY-MSGV2)
  1114. * | [--->] IV_MSGV3 TYPE SYMSGV (default =SY-MSGV3)
  1115. * | [--->] IV_MSGV4 TYPE SYMSGV (default =SY-MSGV4)
  1116. * | [<---] ES_RETURN TYPE BAPIRET2
  1117. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1118. METHOD fill_bapiret2.
  1119.  
  1120. *--------------------------------------------------------------------*
  1121. * Hülle für den folgenden Aufruf, der kein Defaulting aus den
  1122. * Systemfeldern unterstützt:
  1123. *--------------------------------------------------------------------*
  1124.  
  1125. CALL FUNCTION 'BALW_BAPIRETURN_GET2'
  1126. EXPORTING
  1127. type = iv_msgty
  1128. cl = iv_msgid
  1129. number = iv_msgno
  1130. par1 = iv_msgv1
  1131. par2 = iv_msgv2
  1132. par3 = iv_msgv3
  1133. par4 = iv_msgv4
  1134. IMPORTING
  1135. return = es_return.
  1136.  
  1137. ENDMETHOD.
  1138.  
  1139.  
  1140. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1141. * | Static Public Method ZCL_MESSAGES=>GET_BAPIRET2_FROM_EXCEPTION
  1142. * +-------------------------------------------------------------------------------------------------+
  1143. * | [--->] IO_EXCEPTION TYPE REF TO CX_ROOT
  1144. * | [<---] ES_RETURN TYPE BAPIRET2
  1145. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1146. METHOD get_bapiret2_from_exception.
  1147.  
  1148. DATA: lv_text TYPE string.
  1149.  
  1150. FIELD-SYMBOLS: <lv_field> TYPE any.
  1151.  
  1152. DEFINE access_attrib.
  1153. assign io_exception->(&1) to <lv_field>.
  1154. END-OF-DEFINITION.
  1155.  
  1156.  
  1157. es_return-type = 'E'.
  1158. " T100-Felder abfüllen, falls vorhanden
  1159. access_attrib 'T100_MSGID'.
  1160. IF sy-subrc IS INITIAL.
  1161. es_return-id = <lv_field>.
  1162. access_attrib 'T100_MSGNO'.
  1163. es_return-number = <lv_field>.
  1164. access_attrib 'T100_MSGV1'.
  1165. es_return-message_v1 = <lv_field>.
  1166. access_attrib 'T100_MSGV2'.
  1167. es_return-message_v2 = <lv_field>.
  1168. access_attrib 'T100_MSGV3'.
  1169. es_return-message_v3 = <lv_field>.
  1170. access_attrib 'T100_MSGV4'.
  1171. es_return-message_v4 = <lv_field>.
  1172. ENDIF.
  1173. es_return-message = io_exception->get_text( ).
  1174.  
  1175. ENDMETHOD.
  1176.  
  1177.  
  1178. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1179. * | Instance Public Method ZCL_MESSAGES->GET_HANDLE
  1180. * +-------------------------------------------------------------------------------------------------+
  1181. * | [<-()] EV_LOG_HANDLE TYPE BALLOGHNDL
  1182. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1183. METHOD get_handle.
  1184.  
  1185. ev_log_handle = gv_log_handle.
  1186.  
  1187. ENDMETHOD.
  1188.  
  1189.  
  1190. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1191. * | Instance Public Method ZCL_MESSAGES->GET_HIGHEST_TYPE
  1192. * +-------------------------------------------------------------------------------------------------+
  1193. * | [--->] IV_CONDITION TYPE ZCA_MSG_CONDITION_D (default ='*')
  1194. * | [--->] IV_ROW TYPE ZCA_MSG_TABIX_D(optional)
  1195. * | [<-()] EV_TYPE TYPE SYMSGTY
  1196. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1197. METHOD get_highest_type .
  1198.  
  1199. DATA: lt_msg TYPE aqtbal_s_msg,
  1200. lv_off TYPE i VALUE -1.
  1201.  
  1202. FIELD-SYMBOLS: <ls_msg> TYPE bal_s_msg.
  1203.  
  1204. CONSTANTS: lc_types TYPE string VALUE 'SIWEAX'.
  1205.  
  1206. IF iv_row IS SUPPLIED.
  1207. lt_msg = get_messages_detailed( iv_condition = iv_condition
  1208. iv_row = iv_row ).
  1209. ELSE.
  1210. lt_msg = get_messages_detailed( iv_condition ).
  1211. ENDIF.
  1212. LOOP AT lt_msg ASSIGNING <ls_msg>.
  1213. * Dieses if muss immer erfüllt sein
  1214. IF lc_types CA <ls_msg>-msgty.
  1215. IF sy-fdpos > lv_off.
  1216. lv_off = sy-fdpos.
  1217. ENDIF.
  1218. ELSE.
  1219. * Unbekannter Nachrichtentyp - Bearbeitung abbrechen
  1220. MESSAGE e001 WITH <ls_msg>-msgty INTO sy-msgli.
  1221. RAISE EXCEPTION TYPE zcx_stop_no_check
  1222. EXPORTING
  1223. t100_msgid = sy-msgid
  1224. t100_msgno = sy-msgno
  1225. t100_msgv1 = sy-msgv1.
  1226. ENDIF.
  1227. ENDLOOP.
  1228.  
  1229. IF lv_off EQ -1.
  1230. ev_type = space.
  1231. ELSE.
  1232. ev_type = lc_types+lv_off(1).
  1233. ENDIF.
  1234.  
  1235. ENDMETHOD.
  1236.  
  1237.  
  1238. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1239. * | Static Public Method ZCL_MESSAGES=>GET_INSTANCE
  1240. * +-------------------------------------------------------------------------------------------------+
  1241. * | [--->] IV_ID TYPE CSEQUENCE
  1242. * | [--->] IV_LOGCLASS TYPE BALSUBOBJ (default =GC_DEFAULT-APPLOG-SUBOBJ)
  1243. * | [--->] IV_CONTEXT TYPE TABNAME (default =GC_DEFAULT-CONTEXT)
  1244. * | [--->] IV_REOPEN TYPE BOOLE_D (default =ABAP_FALSE)
  1245. * | [<-()] RO_INSTANCE TYPE REF TO ZCL_MESSAGES
  1246. * | [!CX!] ZCX_PARAMETER_MISSING
  1247. * | [!CX!] ZCX_NOT_FOUND
  1248. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1249. METHOD get_instance.
  1250.  
  1251. DATA: ls_instance TYPE zca_msg_instance_s,
  1252. lv_handle TYPE balloghndl,
  1253. lv_extnumber TYPE balnrext.
  1254.  
  1255. READ TABLE gt_instances INTO ls_instance WITH TABLE KEY id = iv_id.
  1256.  
  1257. IF sy-subrc IS INITIAL.
  1258. ro_instance = ls_instance-messages. RETURN.
  1259. ENDIF.
  1260.  
  1261. CHECK iv_logclass IS NOT INITIAL.
  1262.  
  1263. IF iv_reopen = abap_true.
  1264. " ExtNumber übergeben? Dann schauen, ob es das Log auf der DB gibt
  1265. lv_extnumber = iv_id.
  1266.  
  1267. lv_handle = get_log_by_extnumber( iv_extnumber = lv_extnumber
  1268. iv_subobject = iv_logclass ).
  1269. ENDIF.
  1270.  
  1271. " Log instanziieren
  1272. ls_instance-id = iv_id.
  1273. CREATE OBJECT ls_instance-messages EXPORTING
  1274. iv_id = ls_instance-id
  1275. iv_logclass = iv_logclass
  1276. iv_context = iv_context
  1277. iv_log_handle = lv_handle.
  1278.  
  1279. INSERT ls_instance INTO TABLE gt_instances.
  1280.  
  1281. ro_instance = ls_instance-messages.
  1282.  
  1283. ENDMETHOD.
  1284.  
  1285.  
  1286. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1287. * | Instance Public Method ZCL_MESSAGES->GET_LAST_MESSAGE
  1288. * +-------------------------------------------------------------------------------------------------+
  1289. * | [<---] ES_MSG TYPE BAL_S_MSG
  1290. * | [<---] ES_MSGH TYPE BALMSGHNDL
  1291. * | [!CX!] ZCX_NOT_FOUND
  1292. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1293. METHOD get_last_message .
  1294.  
  1295. IF gs_last_msgh IS INITIAL.
  1296. RAISE EXCEPTION TYPE zcx_not_found.
  1297. ELSE.
  1298. es_msgh = gs_last_msgh.
  1299. CALL FUNCTION 'BAL_LOG_MSG_READ'
  1300. EXPORTING
  1301. i_s_msg_handle = gs_last_msgh
  1302. IMPORTING
  1303. e_s_msg = es_msg
  1304. EXCEPTIONS
  1305. log_not_found = 1
  1306. msg_not_found = 2
  1307. OTHERS = 3.
  1308. IF sy-subrc <> 0.
  1309. RAISE EXCEPTION TYPE zcx_not_found.
  1310. ENDIF.
  1311. ENDIF.
  1312.  
  1313. ENDMETHOD.
  1314.  
  1315.  
  1316. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1317. * | Static Private Method ZCL_MESSAGES=>GET_LOG_BY_EXTNUMBER
  1318. * +-------------------------------------------------------------------------------------------------+
  1319. * | [--->] IV_EXTNUMBER TYPE BALNREXT
  1320. * | [--->] IV_OBJECT TYPE BALOBJ_D (default =GC_DEFAULT-APPLOG-OBJECT)
  1321. * | [--->] IV_SUBOBJECT TYPE BALSUBOBJ
  1322. * | [<-()] RV_LOG_HANDLE TYPE BALLOGHNDL
  1323. * | [!CX!] ZCX_NOT_FOUND
  1324. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1325. METHOD get_log_by_extnumber.
  1326.  
  1327. DATA: lt_logh TYPE balhdr_t,
  1328. ls_extn TYPE bal_s_extn,
  1329. ls_lfil TYPE bal_s_lfil,
  1330. ls_obj TYPE bal_s_obj,
  1331. ls_sub TYPE bal_s_sub.
  1332.  
  1333. " Objekt abfüllen
  1334. ls_obj = 'IEQ'.
  1335. ls_obj-low = iv_object.
  1336. APPEND ls_obj TO ls_lfil-object.
  1337.  
  1338. " Subobjekt abfüllen
  1339. ls_sub = 'IEQ'.
  1340. ls_sub-low = iv_subobject.
  1341. APPEND ls_sub TO ls_lfil-subobject.
  1342.  
  1343. " Extnumber abfüllen
  1344. ls_extn = 'IEQ'.
  1345. ls_extn-low = iv_extnumber.
  1346. APPEND ls_extn TO ls_lfil-extnumber.
  1347.  
  1348. CALL FUNCTION 'BAL_DB_SEARCH'
  1349. EXPORTING i_s_log_filter = ls_lfil
  1350. IMPORTING e_t_log_header = lt_logh
  1351. EXCEPTIONS OTHERS = 3.
  1352.  
  1353. IF sy-subrc IS NOT INITIAL.
  1354. raise_exception not_found. " Protokoll nicht in DB --> Fehler
  1355. ELSE.
  1356. rv_log_handle = lt_logh[ 1 ]-log_handle.
  1357. ENDIF.
  1358.  
  1359. ENDMETHOD.
  1360.  
  1361.  
  1362. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1363. * | Instance Private Method ZCL_MESSAGES->GET_LOG_HANDLE
  1364. * +-------------------------------------------------------------------------------------------------+
  1365. * | [--->] IV_SUBOBJECT TYPE BALSUBOBJ(optional)
  1366. * | [--->] IV_EXTNUMBER TYPE BALNREXT(optional)
  1367. * | [--->] IV_LOG_HANDLE TYPE BALLOGHNDL(optional)
  1368. * | [--->] IV_NEW_LOG TYPE BOOLE_D (default =ABAP_TRUE)
  1369. * | [<-()] RV_LOG_HANDLE TYPE BALLOGHNDL
  1370. * | [!CX!] ZCX_NOT_FOUND
  1371. * | [!CX!] ZCX_ERROR
  1372. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1373. METHOD get_log_handle.
  1374.  
  1375. DATA: ls_log TYPE bal_s_log,
  1376. ls_log_filter TYPE bal_s_lfil,
  1377. ls_s_logh TYPE bal_s_logh,
  1378. ls_s_obj TYPE bal_s_obj,
  1379. ls_s_sub TYPE bal_s_sub,
  1380. ls_s_extn TYPE bal_s_extn,
  1381. lt_logh TYPE bal_t_logh,
  1382. lt_log_hdr TYPE balhdr_t.
  1383.  
  1384. * Beim Aufruf muss
  1385. * - entweder ein Handle
  1386. * - oder das Paar Subobject/Extnumber (letzteres darf auch space sein)
  1387. * angegeben werden:
  1388. ASSERT ID ztw_test CONDITION iv_subobject IS NOT INITIAL
  1389. OR iv_log_handle IS NOT INITIAL.
  1390.  
  1391. *---------------------------------------------------------------------
  1392. * Wenn kein Log Handle angegeben wurde, prüfen, ob
  1393. * gv_log_handle wiederverwendet werden kann
  1394. *---------------------------------------------------------------------
  1395. IF iv_log_handle IS INITIAL AND
  1396. gv_log_handle IS NOT INITIAL AND
  1397. iv_new_log EQ abap_false.
  1398.  
  1399. " Existiert bereits ein Protokoll im Arbeitsspeicher?
  1400. " Wenn Ja -> Prüfen, ob externe Nummer und Subobjekt passt
  1401. CALL FUNCTION 'BAL_LOG_HDR_READ'
  1402. EXPORTING
  1403. i_log_handle = gv_log_handle
  1404. IMPORTING
  1405. e_s_log = ls_log
  1406. EXCEPTIONS
  1407. OTHERS = 2.
  1408.  
  1409. IF sy-subrc IS NOT INITIAL.
  1410. " Fehler in globalen Daten - Protokoll zu Handle '&1' nicht mehr im Memory
  1411. MESSAGE e204 WITH gv_log_handle INTO sy-msgli.
  1412. raise_exception not_found.
  1413. ENDIF.
  1414.  
  1415. IF ls_log-subobject <> iv_subobject OR
  1416. ls_log-extnumber <> iv_extnumber.
  1417. " gv_log_handle passt nicht -> zurücksetzen
  1418. CLEAR gv_log_handle.
  1419. ENDIF.
  1420. ENDIF.
  1421.  
  1422. *---------------------------------------------------------------------
  1423. * Wenn das Log Handle angegeben wurde und im Arbeitsspeicher
  1424. * existiert, so ist dieses zu verwenden
  1425. *---------------------------------------------------------------------
  1426. IF iv_log_handle IS NOT INITIAL.
  1427.  
  1428. CALL FUNCTION 'BAL_LOG_HDR_READ'
  1429. EXPORTING
  1430. i_log_handle = iv_log_handle
  1431. IMPORTING
  1432. e_s_log = ls_log
  1433. EXCEPTIONS
  1434. OTHERS = 2.
  1435.  
  1436. IF sy-subrc IS INITIAL.
  1437. IF iv_subobject IS INITIAL OR
  1438. ( iv_subobject EQ ls_log-subobject AND iv_extnumber = ls_log-extnumber ).
  1439. rv_log_handle = gv_log_handle = iv_log_handle. RETURN.
  1440. ENDIF.
  1441. ENDIF.
  1442.  
  1443. CLEAR gv_log_handle.
  1444. ENDIF.
  1445.  
  1446. *---------------------------------------------------------------------
  1447. * Im Arbeitsspeicher und bei Misserfolg auf DB
  1448. * nach dem angegebenen Log suchen, wenn es nicht neu anzulegen ist
  1449. *---------------------------------------------------------------------
  1450. IF iv_new_log = abap_false.
  1451. " Filter für Suche aufbauen
  1452. IF iv_log_handle IS NOT INITIAL.
  1453. ls_s_logh = 'IEQ'.
  1454. ls_s_logh-low = iv_log_handle.
  1455. APPEND ls_s_logh TO ls_log_filter-log_handle.
  1456. ELSE.
  1457. ls_s_obj = 'IEQ'.
  1458. ls_s_obj-low = gc_default-applog.
  1459. APPEND ls_s_obj TO ls_log_filter-object.
  1460. ls_s_sub = 'IEQ'.
  1461. ls_s_sub-low = iv_subobject.
  1462. APPEND ls_s_sub TO ls_log_filter-subobject.
  1463. ls_s_extn = 'IEQ'.
  1464. ls_s_extn-low = iv_extnumber.
  1465. APPEND ls_s_extn TO ls_log_filter-extnumber.
  1466. ENDIF.
  1467.  
  1468. " Schritt 1: Log im Arbeitsspeicher suchen
  1469. CALL FUNCTION 'BAL_GLB_SEARCH_LOG'
  1470. EXPORTING
  1471. i_s_log_filter = ls_log_filter
  1472. IMPORTING
  1473. e_t_log_handle = lt_logh
  1474. EXCEPTIONS
  1475. OTHERS = 2.
  1476.  
  1477. IF sy-subrc IS INITIAL.
  1478. READ TABLE lt_logh INTO gv_log_handle INDEX 1.
  1479. rv_log_handle = gv_log_handle. RETURN.
  1480. ENDIF.
  1481.  
  1482. " Schritt 2: Nicht im Arbeitsspeicher, dann auf Platte suchen
  1483. CALL FUNCTION 'BAL_DB_SEARCH'
  1484. EXPORTING
  1485. i_s_log_filter = ls_log_filter
  1486. IMPORTING
  1487. e_t_log_header = lt_log_hdr
  1488. EXCEPTIONS
  1489. OTHERS = 3.
  1490.  
  1491. IF sy-subrc IS INITIAL.
  1492. " Protokoll in den Hauptspeicher laden:
  1493. CALL FUNCTION 'BAL_DB_LOAD'
  1494. EXPORTING
  1495. i_t_log_header = lt_log_hdr
  1496. IMPORTING
  1497. e_t_log_handle = lt_logh
  1498. EXCEPTIONS
  1499. no_logs_specified = 1
  1500. log_not_found = 2
  1501. log_already_loaded = 3
  1502. OTHERS = 4.
  1503.  
  1504. IF sy-subrc IS NOT INITIAL.
  1505. raise_exception error.
  1506. ENDIF.
  1507.  
  1508. READ TABLE lt_logh INTO gv_log_handle INDEX 1.
  1509. rv_log_handle = gv_log_handle. RETURN.
  1510. ENDIF.
  1511. ENDIF.
  1512.  
  1513. *---------------------------------------------------------------------
  1514. * Application Log muss neu angelegt werden
  1515. *---------------------------------------------------------------------
  1516. ls_log-object = gc_default-applog.
  1517. ls_log-subobject = iv_subobject.
  1518. ls_log-extnumber = iv_extnumber.
  1519.  
  1520. CALL FUNCTION 'BAL_LOG_CREATE'
  1521. EXPORTING
  1522. i_s_log = ls_log
  1523. IMPORTING
  1524. e_log_handle = gv_log_handle
  1525. EXCEPTIONS
  1526. OTHERS = 2.
  1527.  
  1528. IF sy-subrc IS NOT INITIAL.
  1529. raise_exception error.
  1530. ENDIF.
  1531.  
  1532. rv_log_handle = gv_log_handle.
  1533.  
  1534. ENDMETHOD.
  1535.  
  1536.  
  1537. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1538. * | Instance Public Method ZCL_MESSAGES->GET_MESSAGE
  1539. * +-------------------------------------------------------------------------------------------------+
  1540. * | [--->] IV_CONDITION TYPE ZCA_MSG_CONDITION_D (default ='*')
  1541. * | [--->] IV_ROW TYPE ZCA_MSG_TABIX_D(optional)
  1542. * | [<---] EV_MSG_TYPE TYPE SYMSGTY
  1543. * | [<---] EV_MSG_TEXT TYPE STRING
  1544. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1545. METHOD get_message.
  1546.  
  1547. DATA: ls_msg TYPE bal_s_msg.
  1548.  
  1549. IF iv_row IS SUPPLIED.
  1550. CALL METHOD get_message_with_handle
  1551. EXPORTING
  1552. iv_condition = iv_condition
  1553. iv_row = iv_row
  1554. IMPORTING
  1555. es_msg = ls_msg.
  1556. ELSE.
  1557. CALL METHOD get_message_with_handle
  1558. EXPORTING
  1559. iv_condition = iv_condition
  1560. IMPORTING
  1561. es_msg = ls_msg.
  1562. ENDIF.
  1563.  
  1564. IF NOT ls_msg IS INITIAL.
  1565. MESSAGE ID ls_msg-msgid TYPE ls_msg-msgty NUMBER ls_msg-msgno
  1566. WITH ls_msg-msgv1 ls_msg-msgv2 ls_msg-msgv3 ls_msg-msgv4
  1567. INTO ev_msg_text.
  1568. ELSE.
  1569. ev_msg_text = space.
  1570. ENDIF.
  1571.  
  1572. ev_msg_type = ls_msg-msgty.
  1573.  
  1574. ENDMETHOD.
  1575.  
  1576.  
  1577. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1578. * | Instance Public Method ZCL_MESSAGES->GET_MESSAGES
  1579. * +-------------------------------------------------------------------------------------------------+
  1580. * | [--->] IV_CONDITION TYPE ZCA_MSG_CONDITION_D (default ='*')
  1581. * | [<-()] ET_MESSAGES TYPE ZCA_MSG_MESSAGES_Y
  1582. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1583. METHOD get_messages.
  1584.  
  1585. DATA: lt_msg TYPE aqtbal_s_msg,
  1586. ls_message TYPE zca_msg_message_struc_s.
  1587.  
  1588. FIELD-SYMBOLS: <ls_msg> TYPE bal_s_msg.
  1589.  
  1590. lt_msg = get_messages_detailed( iv_condition ).
  1591.  
  1592. LOOP AT lt_msg ASSIGNING <ls_msg>.
  1593. ls_message-type = <ls_msg>-msgty.
  1594. MESSAGE ID <ls_msg>-msgid TYPE <ls_msg>-msgty NUMBER <ls_msg>-msgno
  1595. WITH <ls_msg>-msgv1 <ls_msg>-msgv2 <ls_msg>-msgv3 <ls_msg>-msgv4
  1596. INTO ls_message-text.
  1597. INSERT ls_message INTO TABLE et_messages.
  1598. ENDLOOP.
  1599.  
  1600. ENDMETHOD.
  1601.  
  1602.  
  1603. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1604. * | Instance Public Method ZCL_MESSAGES->GET_MESSAGES_DETAILED
  1605. * +-------------------------------------------------------------------------------------------------+
  1606. * | [--->] IV_CONDITION TYPE ZCA_MSG_CONDITION_D (default ='*')
  1607. * | [--->] IV_ROW TYPE ZCA_MSG_TABIX_D(optional)
  1608. * | [<-()] ET_MSG TYPE AQTBAL_S_MSG
  1609. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1610. METHOD get_messages_detailed . "#EC CI_VALPAR
  1611.  
  1612. DATA: lt_messages TYPE swf_app_log_ext_msg_t.
  1613.  
  1614. FIELD-SYMBOLS: <ls_message> TYPE swf_app_log_ext_msg.
  1615.  
  1616. IF iv_row IS SUPPLIED.
  1617. CALL METHOD get_messages_detailed_with_hdl
  1618. EXPORTING
  1619. iv_condition = iv_condition
  1620. iv_row = iv_row
  1621. IMPORTING
  1622. et_messages = lt_messages.
  1623. ELSE.
  1624. CALL METHOD get_messages_detailed_with_hdl
  1625. EXPORTING
  1626. iv_condition = iv_condition
  1627. IMPORTING
  1628. et_messages = lt_messages.
  1629. ENDIF.
  1630.  
  1631. LOOP AT lt_messages ASSIGNING <ls_message>.
  1632. INSERT <ls_message>-msg INTO TABLE et_msg.
  1633. ENDLOOP.
  1634.  
  1635. ENDMETHOD.
  1636.  
  1637.  
  1638. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1639. * | Instance Public Method ZCL_MESSAGES->GET_MESSAGES_DETAILED_WITH_HDL
  1640. * +-------------------------------------------------------------------------------------------------+
  1641. * | [--->] IV_CONDITION TYPE ZCA_MSG_CONDITION_D (default ='*')
  1642. * | [--->] IV_ROW TYPE ZCA_MSG_TABIX_D(optional)
  1643. * | [<---] ET_MESSAGES TYPE SWF_APP_LOG_EXT_MSG_T
  1644. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1645. METHOD get_messages_detailed_with_hdl .
  1646.  
  1647. DATA: ls_message TYPE swf_app_log_ext_msg,
  1648. lt_msgh TYPE REF TO bal_t_msgh.
  1649.  
  1650. * Meldungen suchen
  1651. IF iv_row IS SUPPLIED.
  1652. lt_msgh = search_messages( iv_condition = iv_condition
  1653. iv_row = iv_row ).
  1654. ELSE.
  1655. lt_msgh = search_messages( iv_condition ).
  1656. ENDIF.
  1657.  
  1658. * Meldungs-Details für jede Meldung dazulesen
  1659. CLEAR et_messages.
  1660. LOOP AT lt_msgh->* INTO ls_message-msg_handle
  1661. WHERE log_handle = gv_log_handle AND
  1662. msgnumber > gv_end_last_section.
  1663. CALL FUNCTION 'BAL_LOG_MSG_READ'
  1664. EXPORTING
  1665. i_s_msg_handle = ls_message-msg_handle
  1666. i_langu = sy-langu
  1667. IMPORTING
  1668. e_s_msg = ls_message-msg
  1669. EXCEPTIONS
  1670. log_not_found = 1
  1671. msg_not_found = 2
  1672. OTHERS = 3.
  1673. IF sy-subrc <> 0.
  1674. CONTINUE.
  1675. ENDIF.
  1676. INSERT ls_message INTO TABLE et_messages.
  1677. ENDLOOP.
  1678.  
  1679. ENDMETHOD. "#EC CI_VALPAR
  1680.  
  1681.  
  1682. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1683. * | Instance Public Method ZCL_MESSAGES->GET_MESSAGE_DETAILED
  1684. * +-------------------------------------------------------------------------------------------------+
  1685. * | [--->] IV_CONDITION TYPE ZCA_MSG_CONDITION_D (default ='*')
  1686. * | [--->] IV_ROW TYPE ZCA_MSG_TABIX_D(optional)
  1687. * | [<-()] ES_MSG TYPE BAL_S_MSG
  1688. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1689. METHOD get_message_detailed .
  1690.  
  1691. * Verschalung - da Aufruf mit Returning-Parameter schon
  1692. * verbreitet ist (und auch komfortabel im Aufruf), als
  1693. * dass eine Schnittstellenänderung sich gelohnt hätte.
  1694.  
  1695. IF iv_row IS SUPPLIED.
  1696. CALL METHOD get_message_with_handle
  1697. EXPORTING
  1698. iv_condition = iv_condition
  1699. iv_row = iv_row
  1700. IMPORTING
  1701. es_msg = es_msg.
  1702. ELSE.
  1703. CALL METHOD get_message_with_handle
  1704. EXPORTING
  1705. iv_condition = iv_condition
  1706. IMPORTING
  1707. es_msg = es_msg.
  1708. ENDIF.
  1709.  
  1710. ENDMETHOD.
  1711.  
  1712.  
  1713. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1714. * | Instance Public Method ZCL_MESSAGES->GET_MESSAGE_WITH_HANDLE
  1715. * +-------------------------------------------------------------------------------------------------+
  1716. * | [--->] IV_CONDITION TYPE ZCA_MSG_CONDITION_D (default ='*')
  1717. * | [--->] IV_ROW TYPE ZCA_MSG_TABIX_D(optional)
  1718. * | [<---] ES_MSGH TYPE BALMSGHNDL
  1719. * | [<---] ES_MSG TYPE BAL_S_MSG
  1720. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1721. METHOD get_message_with_handle .
  1722.  
  1723. DATA: ls_msg TYPE bal_s_msg,
  1724. lt_msgh TYPE REF TO bal_t_msgh,
  1725. lv_offset TYPE i.
  1726.  
  1727. FIELD-SYMBOLS: <ls_msgh> TYPE balmsghndl.
  1728.  
  1729. * Meldungen suchen
  1730. IF iv_row IS SUPPLIED.
  1731. lt_msgh = search_messages( iv_condition = iv_condition
  1732. iv_row = iv_row ).
  1733. ELSE.
  1734. lt_msgh = search_messages( iv_condition = iv_condition ).
  1735. ENDIF.
  1736.  
  1737. * Meldung von höchstem Meldungsgrad zurückgeben
  1738. CLEAR es_msg.
  1739. CLEAR es_msgh.
  1740. lv_offset = 10.
  1741. LOOP AT lt_msgh->* ASSIGNING <ls_msgh>
  1742. WHERE log_handle = gv_log_handle AND
  1743. msgnumber > gv_end_last_section.
  1744. CALL FUNCTION 'BAL_LOG_MSG_READ'
  1745. EXPORTING
  1746. i_s_msg_handle = <ls_msgh>
  1747. i_langu = sy-langu
  1748. IMPORTING
  1749. e_s_msg = ls_msg
  1750. EXCEPTIONS
  1751. log_not_found = 1
  1752. msg_not_found = 2
  1753. OTHERS = 3.
  1754. IF sy-subrc <> 0.
  1755. CONTINUE.
  1756. ENDIF.
  1757. FIND ls_msg-msgty IN gc_message_types MATCH OFFSET sy-fdpos.
  1758. IF sy-fdpos < lv_offset.
  1759. lv_offset = sy-fdpos.
  1760. es_msg = ls_msg.
  1761. es_msgh = <ls_msgh>.
  1762. ENDIF.
  1763. ENDLOOP.
  1764.  
  1765. ENDMETHOD.
  1766.  
  1767.  
  1768. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1769. * | Instance Public Method ZCL_MESSAGES->INITIALIZE
  1770. * +-------------------------------------------------------------------------------------------------+
  1771. * +--------------------------------------------------------------------------------------</SIGNATURE>
  1772. METHOD initialize.
  1773.  
  1774. IF gv_log_handle IS NOT INITIAL.
  1775. CALL FUNCTION 'BAL_LOG_REFRESH'
  1776. EXPORTING
  1777. i_log_handle = gv_log_handle
  1778. EXCEPTIONS
  1779. OTHERS = 0.
  1780.  
  1781. CLEAR gv_log_handle.
  1782. ENDIF.
  1783.  
  1784. ENDMETHOD.
  1785.  
  1786.  
  1787. * <SIGNATURE>---------------------------------------------------------------------------------------+
  1788. * | Static Public Method ZCL_MESSAGES=>READ_BY_EXTNUMBER
  1789.  

Report this snippet  

You need to login to post a comment.