Advertisement
yaramohamed78

Untitled

Apr 11th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 13.87 KB | None | 0 0
  1. *&---------------------------------------------------------------------*
  2. *& Report  Z_YYY_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.  
  17.  
  18.  
  19. REPORT Z_YYY_DISPOSAL_REQ_INQ.
  20.  
  21. TABLES : ZFI_DISPOSAL_REQ , ZFI_LOOKUP.
  22.  
  23. *---------------------------------------------------------------------*
  24. *                        W O R K  A R E A S                           *
  25. *---------------------------------------------------------------------*
  26. *Internal table which will be used in filling the alv by returning the data from the fm inquiry.
  27. TYPES : BEGIN OF IT_req,
  28.           zzsr_number    TYPE ZFI_DISPOSAL_REQ-ZZSR_NUMBER,
  29.           zzcompany_code TYPE ZFI_DISPOSAL_REQ-ZZCOMPANY_CODE,
  30.           zzcost_center  TYPE ZFI_DISPOSAL_REQ-ZZCOST_CENTER,
  31.           zzdate         TYPE ZFI_DISPOSAL_REQ-ZZDATE,
  32.           s_zzdesc       TYPE ZFI_LOOKUP-ZZDESC,
  33.           rs_zzdesc      TYPE ZFI_LOOKUP-ZZDESC,
  34.           crea_user      TYPE ZFI_DISPOSAL_REQ-CREA_USER,
  35.           crea_time      TYPE ZFI_DISPOSAL_REQ-CREA_TIME,
  36.           chng_user      TYPE ZFI_DISPOSAL_REQ-CHNG_USER,
  37.           chng_time      TYPE ZFI_DISPOSAL_REQ-CHNG_TIME,
  38.  
  39.   END OF IT_req.
  40.  
  41. *Internal Table & work area for it.
  42. DATA : it_reqs  TYPE STANDARD TABLE OF it_req,
  43.         wa_reqs TYPE it_req,
  44.         WA_FIELDCAT TYPE LVC_S_FCAT,
  45.         T_FIELDCAT TYPE LVC_T_FCAT.
  46.  
  47. ********************************************************************************************************************************************************
  48.  
  49. *Internal tables we will need for the search help filtering
  50.  
  51. *Cost Center
  52. TYPES: BEGIN OF ty_req,
  53.        cost_center  TYPE ZFI_DISPOSAL_REQ-ZZCOST_CENTER,
  54.        END OF ty_req.
  55.  
  56. * Request Status & Service
  57. TYPES: BEGIN OF ty_lookup,
  58.         code      TYPE ZFI_LOOKUP-ZZCODE,
  59.        END OF ty_lookup.
  60.  
  61.  
  62. DATA:   gwa_req         TYPE ty_req,
  63.         gt_req          TYPE TABLE OF ty_req,
  64.         gwa_lookup      TYPE ty_lookup,
  65.         gt_lookup       TYPE TABLE OF ty_lookup,
  66.         gt_return       TYPE TABLE OF ddshretval,
  67.         gwa_return      TYPE ddshretval,
  68.         gwa_dynpfields  TYPE dynpread,
  69.         gt_dynpfields   TYPE TABLE OF dynpread,
  70.         gv_company_code TYPE ZFI_DISPOSAL_REQ-ZZCOMPANY_CODE,
  71.         gv_type         TYPE ZFI_LOOKUP-ZZTYPE.
  72.  
  73. *Working area for the three tables we will need to work on .
  74. DATA:   wa_req TYPE ZFI_DISPOSAL_REQ,
  75.         wa_service TYPE ZFI_LOOKUP,
  76.         wa_req_status TYPE ZFI_LOOKUP.
  77.  
  78. ********************************************************************************************************************************************************
  79. *   local data for the docking , gui_container , and the cl_salv
  80.     DATA: lo_dock TYPE REF TO cl_gui_docking_container,
  81.           lo_alv  TYPE REF TO cl_gui_alv_grid.
  82.  
  83. ********************************************************
  84.  
  85.  
  86.  
  87. SELECTION-SCREEN BEGIN OF BLOCK SELECTION WITH FRAME TITLE text-001.
  88.  
  89. *Company Code Default(1200)
  90. SELECTION-SCREEN BEGIN OF LINE.
  91.   SELECTION-SCREEN COMMENT (20) text-002 FOR FIELD COM_CODE .
  92. PARAMETERS :     COM_CODE LIKE ZFI_DISPOSAL_REQ-ZZCOMPANY_CODE DEFAULT '1200'.
  93. SELECTION-SCREEN POSITION 35.
  94.  
  95. *Cost Center - Search Help depending on the value for the company code
  96. SELECTION-SCREEN COMMENT (20) text-003 FOR FIELD COST_CNT .
  97. PARAMETERS :     COST_CNT LIKE ZFI_DISPOSAL_REQ-ZZCOST_CENTER.
  98. SELECTION-SCREEN POSITION 70.
  99. SELECTION-SCREEN END OF LINE.
  100.  
  101. *Serial Number
  102. SELECTION-SCREEN BEGIN OF LINE.
  103.   SELECTION-SCREEN COMMENT (20) text-004 FOR FIELD SER_NO .
  104. PARAMETERS :     SER_NO   LIKE ZFI_DISPOSAL_REQ-ZZSR_NUMBER.
  105.  
  106.  
  107. *SELECTION-SCREEN POSITION 10.
  108. *Service Type - Search Help
  109. SELECTION-SCREEN COMMENT (20) text-005 FOR FIELD SRV_TYPE .
  110. PARAMETERS :     SRV_TYPE LIKE ZFI_LOOKUP-ZZCODE .
  111. SELECTION-SCREEN POSITION 70.
  112. PARAMETERS :     SRV_DESC  LIKE ZFI_LOOKUP-ZZDESC.
  113. SELECTION-SCREEN END OF LINE.
  114. *Date
  115. SELECTION-SCREEN BEGIN OF LINE.
  116.   SELECTION-SCREEN COMMENT (20) text-006 FOR FIELD DATE .
  117. PARAMETERS :     DATE LIKE ZFI_DISPOSAL_REQ-ZZDATE.
  118. *SELECTION-SCREEN POSITION 35.
  119.  
  120. *Request Status - Search Help
  121. SELECTION-SCREEN COMMENT (20) text-007 FOR FIELD REQ_STS .
  122. PARAMETERS :     REQ_STS  LIKE ZFI_LOOKUP-ZZCODE.
  123. SELECTION-SCREEN END OF LINE.
  124. SELECTION-SCREEN BEGIN OF LINE.
  125. PARAMETERS :     REQ_DESC  LIKE ZFI_LOOKUP-ZZDESC.
  126.  
  127. *Search Button
  128. SELECTION-SCREEN PUSHBUTTON (10) BUT1 USER-COMMAND SEARCH.
  129.  
  130. *Reset Button
  131. SELECTION-SCREEN PUSHBUTTON (10) BUT2 USER-COMMAND RESET.
  132. SELECTION-SCREEN END OF LINE.
  133. SELECTION-SCREEN END OF BLOCK SELECTION.
  134.  
  135. *On Value Request for cost center - filter it depending on company code
  136. AT SELECTION-SCREEN ON VALUE-REQUEST FOR COST_CNT.
  137.  
  138.   REFRESH gt_dynpfields.
  139.  
  140. *Field i will filter upon
  141.   gwa_dynpfields-fieldname = 'COM_CODE'.
  142.   APPEND gwa_dynpfields TO gt_dynpfields.
  143.  
  144.   CALL FUNCTION 'DYNP_VALUES_READ'
  145.     EXPORTING
  146.       DYNAME                               = sy-repid
  147.       DYNUMB                               = sy-dynnr
  148.     TABLES
  149.       DYNPFIELDS                           = gt_dynpfields
  150.    EXCEPTIONS
  151.      INVALID_ABAPWORKAREA                 = 1
  152.      INVALID_DYNPROFIELD                  = 2
  153.      INVALID_DYNPRONAME                   = 3
  154.      INVALID_DYNPRONUMMER                 = 4
  155.      INVALID_REQUEST                      = 5
  156.      NO_FIELDDESCRIPTION                  = 6
  157.      INVALID_PARAMETER                    = 7
  158.      UNDEFIND_ERROR                       = 8
  159.      DOUBLE_CONVERSION                    = 9
  160.      STEPL_NOT_FOUND                      = 10
  161.      OTHERS                               = 11
  162.             .
  163.   READ TABLE gt_dynpfields INTO gwa_dynpfields
  164.              WITH KEY fieldname = 'COM_CODE'.
  165. *If there are no errors , assign the company code the value returned.
  166.   IF SY-SUBRC = 0.
  167.       gv_company_code = gwa_dynpfields-fieldvalue.
  168.   ENDIF.
  169.  
  170. *Select statement to get the cost center depending on the dynamic value for the company code & assign it to the table we created.
  171.   SELECT DISTINCT ZZCOST_CENTER
  172.          INTO TABLE gt_req
  173.          FROM ZFI_DISPOSAL_REQ
  174.          WHERE ZZCOMPANY_CODE = gv_company_code.
  175.  
  176. *Get cost center search help values depending on the company code.
  177.     CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
  178.       EXPORTING
  179.         RETFIELD               = 'COST_CENTER'
  180.         VALUE_ORG              = 'S'
  181.       TABLES
  182.         VALUE_TAB              = gt_req
  183.         RETURN_TAB             = gt_return
  184.      EXCEPTIONS
  185.        PARAMETER_ERROR        = 1
  186.        NO_VALUES_FOUND        = 2
  187.        OTHERS                 = 3
  188.               .
  189.  
  190.      READ TABLE gt_return INTO gwa_return INDEX 1.
  191.  
  192. *If there are no errors , assign the returned table to the cost_cnt selection paramter.
  193.     IF SY-SUBRC = 0.
  194.       COST_CNT = gwa_return-fieldval.
  195.     ENDIF.
  196.  
  197.  
  198. *********************************************************************************************************************************************************
  199.  
  200. *On Value Request for Request Status
  201. AT SELECTION-SCREEN ON VALUE-REQUEST FOR  REQ_STS.
  202.   REFRESH gt_dynpfields.
  203.  
  204.   SELECT  ZZCODE
  205.          INTO TABLE gt_lookup
  206.          FROM ZFI_LOOKUP
  207.          WHERE ZZTYPE = '1'.
  208.  
  209.     CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
  210.       EXPORTING
  211.         RETFIELD               = 'TYPE'
  212.         VALUE_ORG              = 'S'
  213.       TABLES
  214.         VALUE_TAB              = gt_lookup
  215.         RETURN_TAB             = gt_return
  216.      EXCEPTIONS
  217.        PARAMETER_ERROR        = 1
  218.        NO_VALUES_FOUND        = 2
  219.        OTHERS                 = 3
  220.               .
  221.  
  222.      READ TABLE gt_return INTO gwa_return INDEX 1.
  223.  
  224.     IF SY-SUBRC = 0.
  225.       REQ_STS = gwa_return-fieldval.
  226.     ENDIF.
  227.  
  228.       SELECT ZZDESC
  229.       INTO REQ_DESC
  230.       FROM ZFI_LOOKUP
  231.       WHERE ZZCODE = REQ_STS.
  232.      ENDSELECT.
  233.  
  234. *********************************************************************************************************************************************************
  235.  
  236. *On Value Request for Service Type
  237.  
  238.     AT SELECTION-SCREEN ON VALUE-REQUEST FOR  SRV_TYPE.
  239.   REFRESH gt_dynpfields.
  240.  
  241.   SELECT  ZZCODE
  242.          INTO TABLE gt_lookup
  243.          FROM ZFI_LOOKUP
  244.          WHERE ZZTYPE = '2'.
  245.  
  246.     CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
  247.       EXPORTING
  248.         RETFIELD               = 'TYPE'
  249.         VALUE_ORG              = 'S'
  250.       TABLES
  251.         VALUE_TAB              = gt_lookup
  252.         RETURN_TAB             = gt_return
  253.      EXCEPTIONS
  254.        PARAMETER_ERROR        = 1
  255.        NO_VALUES_FOUND        = 2
  256.        OTHERS                 = 3
  257.               .
  258.  
  259.      READ TABLE gt_return INTO gwa_return INDEX 1.
  260.  
  261.     IF SY-SUBRC = 0.
  262.       SRV_TYPE = gwa_return-fieldval.
  263.     ENDIF.
  264.  
  265.     SELECT ZZDESC
  266.       INTO SRV_DESC
  267.       FROM ZFI_LOOKUP
  268.       WHERE ZZCODE = SRV_TYPE.
  269.      ENDSELECT.
  270.  
  271.  
  272.  
  273. *********************************************************************************************************************************************************
  274.  
  275.  
  276. ** Initialization
  277.  
  278. INITIALIZATION.
  279.  
  280. *Buttons Text
  281. BUT1 = 'Search'.
  282. BUT2 = 'Reset'.
  283.  
  284. AT SELECTION-SCREEN OUTPUT.
  285.  
  286.    LOOP AT SCREEN.
  287.    IF screen-NAME = 'COM_CODE'.
  288.      SCREEN-REQUIRED = 1.
  289.      SCREEN-INPUT = 0.
  290.      MODIFY SCREEN.
  291.      ENDIF.
  292.      IF SCREEN-NAME = 'SRV_DESC'.
  293.        SCREEN-REQUIRED = 1.
  294.        SCREEN-INPUT = 0.
  295.        MODIFY SCREEN.
  296.      ENDIF.
  297.        IF SCREEN-NAME = 'REQ_DESC'.
  298.        SCREEN-REQUIRED = 1.
  299.        SCREEN-INPUT = 0.
  300.        MODIFY SCREEN.
  301.      ENDIF.
  302.    ENDLOOP.
  303. PERFORM DISPLAY_OUTPUT.
  304. PERFORM CREATE_OBJECTS.
  305.  
  306.  
  307. AT SELECTION-SCREEN.
  308.  
  309. *Handle on Button Click
  310. CASE sy-ucomm.
  311.  
  312.  when 'SEARCH'.
  313.      PERFORM SEARCH.
  314.  
  315.   WHEN 'RESET'.
  316.     PERFORM RESET.
  317.  
  318. ENDCASE.
  319.  
  320. *******************************************************************************
  321. *Create Fieldcat
  322.  FORM DISPLAY_OUTPUT.
  323.    PERFORM FILL_FIELDCAT USING :
  324.           'ZZSR_NUMBER'     'IT_REQS' 'Serial Number' '',
  325.           'ZZCOMPANY_CODE'  'IT_REQS' 'Company Code' '',
  326.           'ZZCOST_CENTER'   'IT_REQS' 'Cost Center' '',
  327.           'ZZDATE'          'IT_REQS' 'Date' '',
  328.           'S_ZZDESC'        'IT_REQS' 'Service Type' '',
  329.           'RS_ZZDESC'       'IT_REQS' 'Request Status' '',
  330.           'CREA_USER'       'IT_REQS' 'Create User' '',
  331.           'CREA_TIME'       'IT_REQS' 'Create Time' '',
  332.           'CHNG_USER'       'IT_REQS' 'Change User' '',
  333.           'CHNG_TIME'       'IT_REQS' 'Change Time' ''.
  334.  ENDFORM.
  335.  
  336. *Fill them using parameters send to the function
  337. FORM FILL_FIELDCAT USING pv_field    TYPE any
  338.                          pv_tabname  TYPE any
  339.                          pv_coltext  TYPE any
  340.                          pv_outputlen TYPE any.
  341.  
  342.  
  343.   wa_fieldcat-fieldname = pv_field.
  344.   wa_fieldcat-tabname = pv_tabname.
  345.   wa_fieldcat-coltext = pv_coltext.
  346.   APPEND wa_fieldcat TO t_fieldcat.
  347.   CLEAR wa_fieldcat.
  348.  
  349. ENDFORM.
  350. *Create all objects required (Docker,ALV,Grid)
  351. FORM create_objects.
  352.   CHECK lo_dock is INITIAL.
  353.   CREATE OBJECT lo_dock
  354.     EXPORTING
  355.    side                        = cl_gui_docking_container=>dock_at_bottom
  356.       extension                   = 230
  357.       caption                     = 'Assets Request Inquiry'
  358.     EXCEPTIONS
  359.       cntl_error                  = 1
  360.       cntl_system_error           = 2
  361.       create_error                = 3
  362.       lifetime_error              = 4
  363.       lifetime_dynpro_dynpro_link = 5
  364.       OTHERS                      = 6.
  365.   IF sy-subrc <> 0.
  366. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  367.           WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  368.   ENDIF.                               "  IF sy-subrc <> 0.
  369.  
  370.  
  371. * To Create the Grid Instance
  372.   CREATE OBJECT lo_alv
  373.     EXPORTING
  374.       i_parent          = lo_dock
  375.     EXCEPTIONS
  376.       error_cntl_create = 1
  377.       error_cntl_init   = 2
  378.       error_cntl_link   = 3
  379.       error_dp_create   = 4
  380.       OTHERS            = 5.
  381.   IF sy-subrc <> 0.
  382.  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  383.              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  384.   ENDIF.                               " IF sy-subrc <> 0.
  385.  
  386. * Formatted Output Table is Sent to Control
  387. MESSAGE ID 'ZALV_ERRORS' TYPE 'I' NUMBER '000' WITH wa_req_status-ZZCODE.
  388.   CALL METHOD lo_alv->set_table_for_first_display
  389.     CHANGING
  390.       it_outtab                      =  it_reqs
  391.       it_fieldcatalog                =  t_fieldcat
  392. *      it_sort                       =
  393. *      it_filter                     =
  394.     EXCEPTIONS
  395.       invalid_parameter_combination = 1
  396.       program_error                 = 2
  397.       too_many_lines                = 3
  398.       OTHERS                        = 4
  399.           .
  400.   IF sy-subrc <> 0.
  401.    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  402.               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  403.   ENDIF.                               " IF sy-subrc <> 0.
  404.  
  405. ENDFORM.
  406.  
  407. FORM SEARCH.
  408.  
  409. *Internal Table Fields that will be passed to FM
  410.    wa_req-ZZCOMPANY_CODE = COM_CODE.
  411.    wa_req-ZZCOST_CENTER  = COST_CNT.
  412.    wa_req-ZZSR_NUMBER  = SER_NO.
  413.    wa_req-ZZDATE = DATE.
  414.    wa_req_status-ZZCODE = REQ_STS.
  415.    wa_service-ZZCODE = SRV_TYPE.
  416.  
  417. CALL FUNCTION 'Z_REQ_FN_INQUIRY'
  418.   EXPORTING
  419.     WA_REQ              = WA_REQ
  420.     WA_REQ_STATUS       = WA_REQ_STATUS
  421.     WA_SERVICE          = WA_SERVICE
  422.   TABLES
  423.     QT_REQ              = it_reqs
  424.           .
  425. CALL METHOD lo_alv->refresh_table_display.
  426.  ENDFORM.
  427.  
  428. *Clear All fields.
  429.  FORM RESET.
  430.   CLEAR : COST_CNT,
  431.           SER_NO,
  432.            DATE,
  433.            REQ_STS,
  434.            SRV_TYPE,
  435.            it_reqs.
  436. CALL METHOD lo_alv->refresh_table_display.
  437.   ENDFORM.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement