Advertisement
yaramohamed78

REQ - V2

Mar 22nd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 17.63 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.  
  285.  
  286. AT SELECTION-SCREEN.
  287.  
  288.  
  289. *Handle on Button Click
  290. CASE sy-ucomm.
  291.  
  292.  when 'SEARCH'.
  293. *     CLEAR lo_alv.
  294.      PERFORM SEARCH.
  295.  
  296. *Create object of class lc_report.
  297.      CREATE OBJECT lo_report.
  298.  
  299. *Generate output & get data
  300.      lo_report->generate_output( ).
  301.      lo_report->get_data( ).
  302.  
  303.   WHEN 'RESET'.
  304.     PERFORM RESET.
  305.  
  306. ENDCASE.
  307.  
  308.  
  309. *
  310. *----------------------------------------------------------------------*
  311. * Local Class Implementation
  312. *----------------------------------------------------------------------*
  313. CLASS lcl_report IMPLEMENTATION.
  314. *
  315.   METHOD get_data.
  316. *
  317. *   data selection
  318.       me->t_data = it_reqs.
  319.  
  320.     IF sy-dbcnt IS INITIAL.
  321.       MESSAGE s398(00) WITH 'No data selected'.
  322.     ENDIF.
  323. *
  324. *   export to memory
  325.     EXPORT data = me->t_data TO MEMORY ID sy-cprog.
  326. *
  327.   ENDMETHOD.                    "get_data
  328. *
  329.   METHOD generate_output.
  330. *
  331. *   local data for the docking , gui_container , and the cl_salv
  332.     DATA: lo_dock TYPE REF TO cl_gui_docking_container,
  333.           lo_cont TYPE REF TO cl_gui_container,
  334.           lo_alv  TYPE REF TO cl_salv_table.
  335.  
  336.  
  337. *   lo_dock->free( ).
  338. *   lo_cont->free( ).
  339. *   import output table from the memory and free afterwards
  340.     IMPORT data = me->t_data FROM MEMORY ID sy-cprog.
  341.     FREE MEMORY ID sy-cprog.
  342. *
  343. *   Only if there is some data
  344.     CHECK me->t_data IS NOT INITIAL.
  345. *
  346. *   Create a docking control at bottom
  347.  
  348.     CHECK lo_dock IS INITIAL.
  349.     CREATE OBJECT lo_dock
  350.       EXPORTING
  351.         repid = sy-cprog
  352.         dynnr = sy-dynnr
  353.         ratio = 80
  354.         side  = cl_gui_docking_container=>dock_at_bottom
  355.         name  = 'DOCK_CONT'.
  356.     IF sy-subrc <> 0.
  357.       MESSAGE 'Error in the Docking control' TYPE 'S'.
  358.     ENDIF.
  359. *
  360. *   Create a SALV for output
  361.      CHECK lo_alv IS INITIAL.
  362.     TRY.
  363. *       Narrow Casting: To initialize custom container from
  364. *       docking container
  365.         lo_cont ?= lo_dock.
  366. *
  367. *       SALV Table Display on the Docking container
  368.         CALL METHOD cl_salv_table=>factory(
  369.           EXPORTING
  370.             list_display   = if_salv_c_bool_sap=>false
  371.             r_container    = lo_cont
  372. *            container_name = 'DOCK_CONT'
  373.           IMPORTING
  374.             r_salv_table   = lo_alv
  375.           CHANGING
  376.             t_table        = it_reqs[] ).
  377.  
  378.  
  379. *Get columns of the ALV to be able to edit them
  380.         columns = lo_alv->get_columns( ).
  381.  
  382. *Call the forms that will edit each column.
  383.         PERFORM set_service_type_column.
  384.         PERFORM set_request_status_column.
  385.         PERFORM set_create_user_column.
  386.         PERFORM set_create_time_column.
  387.         PERFORM set_change_user_column.
  388.         PERFORM set_change_time_column.
  389.  
  390. *Catch errors if there are
  391.       CATCH cx_salv_msg .
  392.     ENDTRY.
  393. *
  394. *   Pf status
  395.     DATA: lo_functions TYPE REF TO cl_salv_functions_list.
  396.     lo_functions = lo_alv->get_functions( ).
  397.     lo_functions->set_default( abap_true ).
  398. *
  399. *   output display
  400.     lo_alv->display( ).
  401. *
  402.   ENDMETHOD.                    "generate_output
  403. *
  404.  
  405.  
  406.  
  407.  
  408.  
  409. ENDCLASS.
  410.  
  411. *********************************************************************************************************************************************************
  412.  
  413. *Search Function to get data required from the database.
  414.  
  415.  FORM SEARCH.
  416.  
  417. *Internal Table Fields that will be passed to FM
  418.    wa_req-ZZCOMPANY_CODE = COM_CODE.
  419.    wa_req-ZZCOST_CENTER  = COST_CNT.
  420.    wa_req-ZZSR_NUMBER  = SER_NO.
  421.    wa_req-ZZDATE = DATE.
  422.    wa_req_status-ZZCODE = REQ_STS.
  423.    wa_service-ZZCODE = SRV_TYPE.
  424. *    MESSAGE ID 'ZALV_ERRORS' TYPE 'I' NUMBER '000' WITH wa_req_status-ZZCODE.
  425. *    MESSAGE ID 'ZALV_ERRORS' TYPE 'I' NUMBER '000' WITH wa_service-ZZCODE.
  426.  
  427. CALL FUNCTION 'Z_REQ_FN_INQUIRY'
  428.   EXPORTING
  429.     WA_REQ              = WA_REQ
  430.     WA_REQ_STATUS       = WA_REQ_STATUS
  431.     WA_SERVICE          = WA_SERVICE
  432.   TABLES
  433.     QT_REQ              = it_reqs
  434.           .
  435.  
  436.  ENDFORM.
  437.  
  438. *********************************************************************************************************************************************************
  439.  
  440. *Reset Function - Clear all input fields.
  441.  
  442. FORM RESET.
  443.  
  444. *Clear all input fields.
  445.  
  446. *  lo_alv->free( ).
  447.   CLEAR COST_CNT.
  448.   CLEAR SER_NO.
  449.   CLEAR DATE.
  450.   CLEAR REQ_STS.
  451.   CLEAR SRV_TYPE.
  452.  
  453. ENDFORM.
  454.  
  455. *********************************************************************************************************************************************************
  456.  
  457. *Change service type column name
  458.  
  459. FORM set_service_type_column.
  460.     DATA not_found TYPE REF TO cx_salv_not_found.
  461.  
  462.   TRY.
  463.       column = columns->get_column( columnname =  'S_ZZDESC' ).
  464. *      column->set_short_text( 'S. Type' ).
  465. *      column->set_medium_text( 'Ser. Type' ).
  466.       column->set_long_text( 'Service Type' ).
  467.       column->set_optimized( ).
  468.     CATCH cx_salv_not_found INTO not_found.
  469.       " error handling
  470.   ENDTRY.
  471. ENDFORM.
  472.  
  473. *********************************************************************************************************************************************************
  474.  
  475. *Change request status column name
  476.  
  477. FORM set_request_status_column.
  478.     DATA not_found TYPE REF TO cx_salv_not_found.
  479.  
  480.   TRY.
  481.       column = columns->get_column( columnname =  'RS_ZZDESC' ).
  482.       column->set_short_text( 'R. Status' ).
  483.       column->set_medium_text( 'Req. Status' ).
  484.       column->set_long_text( 'Request Status' ).
  485.       column->set_optimized( ).
  486.     CATCH cx_salv_not_found INTO not_found.
  487.       " error handling
  488.   ENDTRY.
  489. ENDFORM.
  490.  
  491. *********************************************************************************************************************************************************
  492.  
  493. *Change create user column name.
  494.  
  495. FORM set_create_user_column.
  496.     DATA not_found TYPE REF TO cx_salv_not_found.
  497.  
  498.   TRY.
  499.       column = columns->get_column( columnname =  'CREA_USER' ).
  500.       column->set_short_text( 'C. User' ).
  501.       column->set_medium_text( 'CREA. User' ).
  502.       column->set_long_text( 'Create User' ).
  503.     CATCH cx_salv_not_found INTO not_found.
  504.       " error handling
  505.   ENDTRY.
  506. ENDFORM.
  507.  
  508. *********************************************************************************************************************************************************
  509.  
  510. *Change create time column name.
  511. FORM set_create_time_column.
  512.     DATA not_found TYPE REF TO cx_salv_not_found.
  513.  
  514.   TRY.
  515.       column = columns->get_column( columnname =  'CREA_TIME' ).
  516.       column->set_short_text( 'C. Time' ).
  517.       column->set_medium_text( 'CREA. Time' ).
  518.       column->set_long_text( 'Create Time' ).
  519.     CATCH cx_salv_not_found INTO not_found.
  520.       " error handling
  521.   ENDTRY.
  522. ENDFORM.
  523.  
  524. *********************************************************************************************************************************************************
  525.  
  526. *Change Change User column name.
  527. FORM set_change_user_column.
  528.     DATA not_found TYPE REF TO cx_salv_not_found.
  529.  
  530.   TRY.
  531.       column = columns->get_column( columnname =  'CHNG_USER' ).
  532.       column->set_short_text( 'C. User' ).
  533.       column->set_medium_text( 'Chan. User' ).
  534.       column->set_long_text( 'Change User' ).
  535.     CATCH cx_salv_not_found INTO not_found.
  536.       " error handling
  537.   ENDTRY.
  538. ENDFORM.
  539.  
  540. *********************************************************************************************************************************************************
  541.  
  542. *Change Change time column name.
  543. FORM set_change_time_column.
  544.     DATA not_found TYPE REF TO cx_salv_not_found.
  545.  
  546.   TRY.
  547.       column = columns->get_column( columnname =  'CHNG_TIME' ).
  548.       column->set_short_text( 'C. Time' ).
  549.       column->set_medium_text( 'Chan. Time' ).
  550.       column->set_long_text( 'Change Time' ).
  551.     CATCH cx_salv_not_found INTO not_found.
  552.       " error handling
  553.   ENDTRY.
  554. ENDFORM.
  555.  
  556. *********************************************************************************************************************************************************
  557.  
  558. FORM optimize_column_width.
  559.   columns->set_optimize( ).
  560. ENDFORM.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement