Advertisement
yaramohamed78

Untitled

Mar 22nd, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.14 KB | None | 0 0
  1. *&---------------------------------------------------------------------*
  2. *& Report Z_YY_DISPOSAL_REQ_INQ
  3. *&
  4. *&---------------------------------------------------------------------*
  5. *&
  6. *&
  7. *&---------------------------------------------------------------------*
  8. *----------------------------------------------------------------------*
  9. * Author : <Yara Mohamed/Developer user ID>
  10. * Creation Date : <09-03-2017>
  11. * Transaction : <Transaction code if attached>
  12. * Technical design: <Assets Disposal Request Inquiry Screen>
  13. * Description : < Show Disposal Request Information>
  14. *----------------------------------------------------------------------*
  15.  
  16. REPORT Z_YY_DISPOSAL_REQ_INQ.
  17.  
  18. ******************************************************************************************************
  19.  
  20. *Internal table which will be used in filling the alv by returning the data from the fm inquiry.
  21. TYPES : BEGIN OF IT_req,
  22. zzsr_number TYPE ZFI_DISPOSAL_REQ-ZZSR_NUMBER,
  23. zzcompany_code TYPE ZFI_DISPOSAL_REQ-ZZCOMPANY_CODE,
  24. zzcost_center TYPE ZFI_DISPOSAL_REQ-ZZCOST_CENTER,
  25. zzdate TYPE ZFI_DISPOSAL_REQ-ZZDATE,
  26. s_zzdesc TYPE ZFI_LOOKUP-ZZDESC,
  27. rs_zzdesc TYPE ZFI_LOOKUP-ZZDESC,
  28. crea_user TYPE ZFI_DISPOSAL_REQ-CREA_USER,
  29. crea_time TYPE ZFI_DISPOSAL_REQ-CREA_TIME,
  30. chng_user TYPE ZFI_DISPOSAL_REQ-CHNG_USER,
  31. chng_time TYPE ZFI_DISPOSAL_REQ-CHNG_TIME,
  32.  
  33. END OF IT_req.
  34.  
  35. *Internal Table & work area for it.
  36. DATA : it_reqs TYPE TABLE OF it_req,
  37. wa_reqs TYPE it_req.
  38.  
  39. DATA columns TYPE REF TO cl_salv_columns_table.
  40. DATA column TYPE REF TO cl_salv_column.
  41.  
  42. ********************************************************************************************************************************************************
  43.  
  44. *Internal tables we will need for the search help filtering
  45.  
  46. *Cost Center
  47. TYPES: BEGIN OF ty_req,
  48. company_code TYPE ZFI_DISPOSAL_REQ-ZZCOMPANY_CODE,
  49. cost_center TYPE ZFI_DISPOSAL_REQ-ZZCOST_CENTER,
  50. END OF ty_req.
  51.  
  52. * Request Status & Service
  53. TYPES: BEGIN OF ty_lookup,
  54. code TYPE ZFI_LOOKUP-ZZCODE,
  55. END OF ty_lookup.
  56.  
  57.  
  58. DATA: gwa_req TYPE ty_req,
  59. gt_req TYPE TABLE OF ty_req,
  60. gwa_lookup TYPE ty_lookup,
  61. gt_lookup TYPE TABLE OF ty_lookup,
  62. gt_return TYPE TABLE OF ddshretval,
  63. gwa_return TYPE ddshretval,
  64. gwa_dynpfields TYPE dynpread,
  65. gt_dynpfields TYPE TABLE OF dynpread,
  66. gv_company_code TYPE ZFI_DISPOSAL_REQ-ZZCOMPANY_CODE,
  67. gv_type TYPE ZFI_LOOKUP-ZZTYPE.
  68.  
  69. *Working area for the three tables we will need to work on .
  70. DATA: wa_req TYPE ZFI_DISPOSAL_REQ,
  71. wa_service TYPE ZFI_LOOKUP,
  72. wa_req_status TYPE ZFI_LOOKUP.
  73.  
  74. ********************************************************************************************************************************************************
  75. * local data for the docking , gui_container , and the cl_salv
  76. DATA: lo_dock TYPE REF TO cl_gui_docking_container,
  77. lo_cont TYPE REF TO cl_gui_container,
  78. lo_alv TYPE REF TO cl_salv_table.
  79.  
  80. *
  81. *----------------------------------------------------------------------*
  82. * Local class for report
  83. *----------------------------------------------------------------------*
  84. CLASS lcl_report DEFINITION.
  85. *
  86. PUBLIC SECTION.
  87.  
  88.  
  89. DATA: t_data TYPE STANDARD TABLE OF it_req. " Output data
  90. *
  91. METHODS:
  92. get_data,
  93. *
  94. generate_output.
  95. *
  96. ENDCLASS. "lcl_report DEFINITION
  97. *
  98. DATA: lo_report TYPE REF TO lcl_report.
  99. *
  100.  
  101. *********************************************************************************************************************************************************
  102. ** Selection Screen
  103. SELECTION-SCREEN BEGIN OF BLOCK SELECTION WITH FRAME TITLE text-001.
  104.  
  105. *Company Code Default(1200)
  106. SELECTION-SCREEN BEGIN OF LINE.
  107. SELECTION-SCREEN COMMENT (20) text-002 FOR FIELD COM_CODE .
  108. PARAMETERS : COM_CODE LIKE ZFI_DISPOSAL_REQ-ZZCOMPANY_CODE DEFAULT '1200'.
  109. SELECTION-SCREEN POSITION 35.
  110.  
  111. *Cost Center - Search Help depending on the value for the company code
  112. SELECTION-SCREEN COMMENT (20) text-003 FOR FIELD COST_CNT .
  113. PARAMETERS : COST_CNT LIKE ZFI_DISPOSAL_REQ-ZZCOST_CENTER.
  114. SELECTION-SCREEN POSITION 70.
  115. SELECTION-SCREEN END OF LINE.
  116.  
  117. *Serial Number
  118. SELECTION-SCREEN BEGIN OF LINE.
  119. SELECTION-SCREEN COMMENT (20) text-004 FOR FIELD SER_NO .
  120. PARAMETERS : SER_NO LIKE ZFI_DISPOSAL_REQ-ZZSR_NUMBER.
  121.  
  122.  
  123. *SELECTION-SCREEN POSITION 10.
  124. *Service Type - Search Help
  125. SELECTION-SCREEN COMMENT (20) text-005 FOR FIELD SRV_TYPE .
  126. PARAMETERS : SRV_TYPE LIKE ZFI_LOOKUP-ZZCODE .
  127. SELECTION-SCREEN POSITION 70.
  128. SELECTION-SCREEN END OF LINE.
  129.  
  130. *Date
  131. SELECTION-SCREEN BEGIN OF LINE.
  132. SELECTION-SCREEN COMMENT (20) text-006 FOR FIELD DATE .
  133. PARAMETERS : DATE LIKE ZFI_DISPOSAL_REQ-ZZDATE.
  134. *SELECTION-SCREEN POSITION 35.
  135.  
  136. *Request Status - Search Help
  137. SELECTION-SCREEN COMMENT (20) text-007 FOR FIELD REQ_STS .
  138. PARAMETERS : REQ_STS LIKE ZFI_LOOKUP-ZZCODE.
  139.  
  140. *Search Button
  141. SELECTION-SCREEN PUSHBUTTON (10) BUT1 USER-COMMAND SEARCH.
  142.  
  143. *Reset Button
  144. SELECTION-SCREEN PUSHBUTTON (10) BUT2 USER-COMMAND RESET.
  145. SELECTION-SCREEN END OF LINE.
  146. SELECTION-SCREEN END OF BLOCK SELECTION.
  147. *
  148. *********************************************************************************************************************************************************
  149.  
  150. *On Value Request for cost center - filter it depending on company code
  151. AT SELECTION-SCREEN ON VALUE-REQUEST FOR COST_CNT.
  152.  
  153. REFRESH gt_dynpfields.
  154.  
  155. *Field i will filter upon
  156. gwa_dynpfields-fieldname = 'COM_CODE'.
  157. APPEND gwa_dynpfields TO gt_dynpfields.
  158.  
  159. CALL FUNCTION 'DYNP_VALUES_READ'
  160. EXPORTING
  161. DYNAME = sy-repid
  162. DYNUMB = sy-dynnr
  163. TABLES
  164. DYNPFIELDS = gt_dynpfields
  165. EXCEPTIONS
  166. INVALID_ABAPWORKAREA = 1
  167. INVALID_DYNPROFIELD = 2
  168. INVALID_DYNPRONAME = 3
  169. INVALID_DYNPRONUMMER = 4
  170. INVALID_REQUEST = 5
  171. NO_FIELDDESCRIPTION = 6
  172. INVALID_PARAMETER = 7
  173. UNDEFIND_ERROR = 8
  174. DOUBLE_CONVERSION = 9
  175. STEPL_NOT_FOUND = 10
  176. OTHERS = 11
  177. .
  178. READ TABLE gt_dynpfields INTO gwa_dynpfields
  179. WITH KEY fieldname = 'COM_CODE'.
  180. *If there are no errors , assign the company code the value returned.
  181. IF SY-SUBRC = 0.
  182. gv_company_code = gwa_dynpfields-fieldvalue.
  183. ENDIF.
  184.  
  185. *Select statement to get the cost center depending on the dynamic value for the company code & assign it to the table we created.
  186. SELECT ZZCOMPANY_CODE ZZCOST_CENTER
  187. INTO TABLE gt_req
  188. FROM ZFI_DISPOSAL_REQ
  189. WHERE ZZCOMPANY_CODE = gv_company_code.
  190.  
  191. *Get cost center search help values depending on the company code.
  192. CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
  193. EXPORTING
  194. RETFIELD = 'COST_CENTER'
  195. VALUE_ORG = 'S'
  196. TABLES
  197. VALUE_TAB = gt_req
  198. RETURN_TAB = gt_return
  199. EXCEPTIONS
  200. PARAMETER_ERROR = 1
  201. NO_VALUES_FOUND = 2
  202. OTHERS = 3
  203. .
  204.  
  205. READ TABLE gt_return INTO gwa_return INDEX 1.
  206.  
  207. *If there are no errors , assign the returned table to the cost_cnt selection paramter.
  208. IF SY-SUBRC = 0.
  209. COST_CNT = gwa_return-fieldval.
  210. ENDIF.
  211.  
  212.  
  213. *********************************************************************************************************************************************************
  214.  
  215. *On Value Request for Request Status
  216. AT SELECTION-SCREEN ON VALUE-REQUEST FOR REQ_STS.
  217. REFRESH gt_dynpfields.
  218.  
  219. SELECT ZZCODE
  220. INTO TABLE gt_lookup
  221. FROM ZFI_LOOKUP
  222. WHERE ZZTYPE = '1'.
  223.  
  224. CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
  225. EXPORTING
  226. RETFIELD = 'TYPE'
  227. VALUE_ORG = 'S'
  228. TABLES
  229. VALUE_TAB = gt_lookup
  230. RETURN_TAB = gt_return
  231. EXCEPTIONS
  232. PARAMETER_ERROR = 1
  233. NO_VALUES_FOUND = 2
  234. OTHERS = 3
  235. .
  236.  
  237. READ TABLE gt_return INTO gwa_return INDEX 1.
  238.  
  239. IF SY-SUBRC = 0.
  240. REQ_STS = gwa_return-fieldval.
  241. ENDIF.
  242.  
  243. *********************************************************************************************************************************************************
  244.  
  245. *On Value Request for Service Type
  246.  
  247. AT SELECTION-SCREEN ON VALUE-REQUEST FOR SRV_TYPE.
  248. REFRESH gt_dynpfields.
  249.  
  250. SELECT ZZCODE
  251. INTO TABLE gt_lookup
  252. FROM ZFI_LOOKUP
  253. WHERE ZZTYPE = '2'.
  254.  
  255. CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
  256. EXPORTING
  257. RETFIELD = 'TYPE'
  258. VALUE_ORG = 'S'
  259. TABLES
  260. VALUE_TAB = gt_lookup
  261. RETURN_TAB = gt_return
  262. EXCEPTIONS
  263. PARAMETER_ERROR = 1
  264. NO_VALUES_FOUND = 2
  265. OTHERS = 3
  266. .
  267.  
  268. READ TABLE gt_return INTO gwa_return INDEX 1.
  269.  
  270. IF SY-SUBRC = 0.
  271. SRV_TYPE = gwa_return-fieldval.
  272. ENDIF.
  273.  
  274. *********************************************************************************************************************************************************
  275.  
  276.  
  277. ** Initialization
  278.  
  279. INITIALIZATION.
  280.  
  281. *Buttons Text
  282. BUT1 = 'Search'.
  283. BUT2 = 'Reset'.
  284. PERFORM create_grid.
  285.  
  286.  
  287. AT SELECTION-SCREEN.
  288.  
  289.  
  290. *Handle on Button Click
  291. CASE sy-ucomm.
  292.  
  293. when 'SEARCH'.
  294. * CLEAR lo_alv.
  295. * CALL METHOD lo_dock->refresh_table_display.
  296. PERFORM CLEAR_GRID.
  297. PERFORM SEARCH.
  298.  
  299. *Create object of class lc_report.
  300. CREATE OBJECT lo_report.
  301.  
  302. *Generate output & get data
  303. lo_report->generate_output( ).
  304. lo_report->get_data( ).
  305.  
  306. WHEN 'RESET'.
  307. PERFORM RESET.
  308.  
  309. ENDCASE.
  310.  
  311.  
  312. *
  313. *----------------------------------------------------------------------*
  314. * Local Class Implementation
  315. *----------------------------------------------------------------------*
  316. CLASS lcl_report IMPLEMENTATION.
  317. *
  318. METHOD get_data.
  319. *
  320. * data selection
  321. me->t_data = it_reqs.
  322.  
  323. IF sy-dbcnt IS INITIAL.
  324. MESSAGE s398(00) WITH 'No data selected'.
  325. ENDIF.
  326. *
  327. * export to memory
  328. EXPORT data = me->t_data TO MEMORY ID sy-cprog.
  329. *
  330. ENDMETHOD. "get_data
  331. *
  332. METHOD generate_output.
  333. *
  334. * local data for the docking , gui_container , and the cl_salv
  335. * DATA: lo_dock TYPE REF TO cl_gui_docking_container,
  336. * lo_cont TYPE REF TO cl_gui_container,
  337. * lo_alv TYPE REF TO cl_salv_table.
  338.  
  339.  
  340. * lo_dock->free( ).
  341. * lo_cont->free( ).
  342. * import output table from the memory and free afterwards
  343. IMPORT data = me->t_data FROM MEMORY ID sy-cprog.
  344. FREE MEMORY ID sy-cprog.
  345. *
  346. * Only if there is some data
  347. CHECK me->t_data IS NOT INITIAL.
  348. *
  349. * Create a docking control at bottom
  350.  
  351. * CHECK lo_dock IS INITIAL.
  352. * CREATE OBJECT lo_dock
  353. * EXPORTING
  354. * repid = sy-cprog
  355. * dynnr = sy-dynnr
  356. * ratio = 80
  357. * side = cl_gui_docking_container=>dock_at_bottom
  358. * name = 'DOCK_CONT'.
  359. * IF sy-subrc <> 0.
  360. * MESSAGE 'Error in the Docking control' TYPE 'S'.
  361. * ENDIF.
  362. *
  363. * Create a SALV for output
  364. CHECK lo_alv IS INITIAL.
  365. TRY.
  366. * Narrow Casting: To initialize custom container from
  367. * docking container
  368. lo_cont ?= lo_dock.
  369. *
  370. * SALV Table Display on the Docking container
  371. CALL METHOD cl_salv_table=>factory(
  372. EXPORTING
  373. list_display = if_salv_c_bool_sap=>false
  374. r_container = lo_cont
  375. * container_name = 'DOCK_CONT'
  376. IMPORTING
  377. r_salv_table = lo_alv
  378. CHANGING
  379. t_table = it_reqs[] ).
  380.  
  381.  
  382. *Get columns of the ALV to be able to edit them
  383. columns = lo_alv->get_columns( ).
  384.  
  385. *Call the forms that will edit each column.
  386. PERFORM set_service_type_column.
  387. PERFORM set_request_status_column.
  388. PERFORM set_create_user_column.
  389. PERFORM set_create_time_column.
  390. PERFORM set_change_user_column.
  391. PERFORM set_change_time_column.
  392.  
  393. *Catch errors if there are
  394. CATCH cx_salv_msg .
  395. ENDTRY.
  396. *
  397. * Pf status
  398. DATA: lo_functions TYPE REF TO cl_salv_functions_list.
  399. lo_functions = lo_alv->get_functions( ).
  400. lo_functions->set_default( abap_true ).
  401. *
  402. * output display
  403. lo_alv->display( ).
  404. *
  405. ENDMETHOD. "generate_output
  406. *
  407.  
  408.  
  409.  
  410.  
  411.  
  412. ENDCLASS.
  413.  
  414. *********************************************************************************************************************************************************
  415.  
  416. *Search Function to get data required from the database.
  417.  
  418. FORM SEARCH.
  419.  
  420. *Internal Table Fields that will be passed to FM
  421. wa_req-ZZCOMPANY_CODE = COM_CODE.
  422. wa_req-ZZCOST_CENTER = COST_CNT.
  423. wa_req-ZZSR_NUMBER = SER_NO.
  424. wa_req-ZZDATE = DATE.
  425. wa_req_status-ZZCODE = REQ_STS.
  426. wa_service-ZZCODE = SRV_TYPE.
  427. * MESSAGE ID 'ZALV_ERRORS' TYPE 'I' NUMBER '000' WITH wa_req_status-ZZCODE.
  428. * MESSAGE ID 'ZALV_ERRORS' TYPE 'I' NUMBER '000' WITH wa_service-ZZCODE.
  429.  
  430. CALL FUNCTION 'Z_REQ_FN_INQUIRY'
  431. EXPORTING
  432. WA_REQ = WA_REQ
  433. WA_REQ_STATUS = WA_REQ_STATUS
  434. WA_SERVICE = WA_SERVICE
  435. TABLES
  436. QT_REQ = it_reqs
  437. .
  438.  
  439. ENDFORM.
  440.  
  441. *********************************************************************************************************************************************************
  442.  
  443. *Reset Function - Clear all input fields.
  444.  
  445. FORM RESET.
  446.  
  447. *Clear all input fields.
  448.  
  449. * lo_alv->free( ).
  450. CLEAR COST_CNT.
  451. CLEAR SER_NO.
  452. CLEAR DATE.
  453. CLEAR REQ_STS.
  454. CLEAR SRV_TYPE.
  455.  
  456. ENDFORM.
  457.  
  458. *********************************************************************************************************************************************************
  459.  
  460. *Change service type column name
  461.  
  462. FORM set_service_type_column.
  463. DATA not_found TYPE REF TO cx_salv_not_found.
  464.  
  465. TRY.
  466. column = columns->get_column( columnname = 'S_ZZDESC' ).
  467. * column->set_short_text( 'S. Type' ).
  468. * column->set_medium_text( 'Ser. Type' ).
  469. column->set_long_text( 'Service Type' ).
  470. column->set_optimized( ).
  471. CATCH cx_salv_not_found INTO not_found.
  472. " error handling
  473. ENDTRY.
  474. ENDFORM.
  475.  
  476. *********************************************************************************************************************************************************
  477.  
  478. *Change request status column name
  479.  
  480. FORM set_request_status_column.
  481. DATA not_found TYPE REF TO cx_salv_not_found.
  482.  
  483. TRY.
  484. column = columns->get_column( columnname = 'RS_ZZDESC' ).
  485. column->set_short_text( 'R. Status' ).
  486. column->set_medium_text( 'Req. Status' ).
  487. column->set_long_text( 'Request Status' ).
  488. column->set_optimized( ).
  489. CATCH cx_salv_not_found INTO not_found.
  490. " error handling
  491. ENDTRY.
  492. ENDFORM.
  493.  
  494. *********************************************************************************************************************************************************
  495.  
  496. *Change create user column name.
  497.  
  498. FORM set_create_user_column.
  499. DATA not_found TYPE REF TO cx_salv_not_found.
  500.  
  501. TRY.
  502. column = columns->get_column( columnname = 'CREA_USER' ).
  503. column->set_short_text( 'C. User' ).
  504. column->set_medium_text( 'CREA. User' ).
  505. column->set_long_text( 'Create User' ).
  506. CATCH cx_salv_not_found INTO not_found.
  507. " error handling
  508. ENDTRY.
  509. ENDFORM.
  510.  
  511. *********************************************************************************************************************************************************
  512.  
  513. *Change create time column name.
  514. FORM set_create_time_column.
  515. DATA not_found TYPE REF TO cx_salv_not_found.
  516.  
  517. TRY.
  518. column = columns->get_column( columnname = 'CREA_TIME' ).
  519. column->set_short_text( 'C. Time' ).
  520. column->set_medium_text( 'CREA. Time' ).
  521. column->set_long_text( 'Create Time' ).
  522. CATCH cx_salv_not_found INTO not_found.
  523. " error handling
  524. ENDTRY.
  525. ENDFORM.
  526.  
  527. *********************************************************************************************************************************************************
  528.  
  529. *Change Change User column name.
  530. FORM set_change_user_column.
  531. DATA not_found TYPE REF TO cx_salv_not_found.
  532.  
  533. TRY.
  534. column = columns->get_column( columnname = 'CHNG_USER' ).
  535. column->set_short_text( 'C. User' ).
  536. column->set_medium_text( 'Chan. User' ).
  537. column->set_long_text( 'Change User' ).
  538. CATCH cx_salv_not_found INTO not_found.
  539. " error handling
  540. ENDTRY.
  541. ENDFORM.
  542.  
  543. *********************************************************************************************************************************************************
  544.  
  545. *Change Change time column name.
  546. FORM set_change_time_column.
  547. DATA not_found TYPE REF TO cx_salv_not_found.
  548.  
  549. TRY.
  550. column = columns->get_column( columnname = 'CHNG_TIME' ).
  551. column->set_short_text( 'C. Time' ).
  552. column->set_medium_text( 'Chan. Time' ).
  553. column->set_long_text( 'Change Time' ).
  554. CATCH cx_salv_not_found INTO not_found.
  555. " error handling
  556. ENDTRY.
  557. ENDFORM.
  558.  
  559. *********************************************************************************************************************************************************
  560.  
  561. FORM optimize_column_width.
  562. columns->set_optimize( ).
  563. ENDFORM.
  564.  
  565. FORM create_grid.
  566. CHECK lo_dock IS INITIAL.
  567. CREATE OBJECT lo_dock
  568. EXPORTING
  569. repid = sy-cprog
  570. dynnr = sy-dynnr
  571. ratio = 80
  572. side = cl_gui_docking_container=>dock_at_bottom
  573. name = 'DOCK_CONT'.
  574. IF sy-subrc <> 0.
  575. MESSAGE 'Error in the Docking control' TYPE 'S'.
  576. ENDIF.
  577. ENDFORM.
  578.  
  579. FORM CLEAR_GRID.
  580. REFRESH lo_dock.
  581.  
  582. ENDFORM.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement