Advertisement
arnau-mas

ZJAU_242_PACT

Nov 12th, 2021
1,516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 17.78 KB | None | 0 0
  1. *&---------------------------------------------------------------------*
  2. *& Report  ZJAU_242_PACT
  3. *&
  4. *&---------------------------------------------------------------------*
  5. *&
  6. *& Pactes de preus per kg
  7. *&---------------------------------------------------------------------*
  8.  
  9. REPORT  zjau_242_pact.
  10.  
  11. INCLUDE zjau_242_pact_top.
  12.  
  13. INITIALIZATION.
  14.  
  15.   GET PARAMETER ID 'PLIFNR' FIELD plifnr.
  16.   zperf_pactes-lifnr = plifnr.
  17.  
  18. START-OF-SELECTION.
  19.  
  20.   SELECT SINGLE lifnr INTO plifnr FROM zperf_proveidor WHERE lifnr = plifnr.
  21.   IF sy-subrc = 0.
  22.     SELECT SINGLE name1 INTO lfa1-name1 FROM lfa1 WHERE lifnr = plifnr.
  23.     CALL SCREEN 100.
  24.   ELSE.
  25.     MESSAGE 'Proveïdor no existeix' TYPE 'S' DISPLAY LIKE 'E'.
  26.   ENDIF.
  27. *&---------------------------------------------------------------------*
  28. *&      Module  STATUS_0100  OUTPUT
  29. *&---------------------------------------------------------------------*
  30. *       text
  31. *----------------------------------------------------------------------*
  32. MODULE status_0100 OUTPUT.
  33.   SET PF-STATUS 'STAT0100'.
  34.   SET TITLEBAR 'TIT_0100'.
  35.  
  36. ENDMODULE.                 " STATUS_0100  OUTPUT
  37. *&---------------------------------------------------------------------*
  38. *&      Module  display_0100  OUTPUT
  39. *&---------------------------------------------------------------------*
  40. *       text
  41. *----------------------------------------------------------------------*
  42. MODULE display_0100 OUTPUT.
  43.   PERFORM display_0100.
  44. ENDMODULE.                 " display_0100  OUTPUT
  45. *&---------------------------------------------------------------------*
  46. *&      Form  display_0100
  47. *&---------------------------------------------------------------------*
  48. *       text
  49. *----------------------------------------------------------------------*
  50. *  -->  p1        text
  51. *  <--  p2        text
  52. *----------------------------------------------------------------------*
  53. FORM display_0100 .
  54.   DATA: lt_exclude TYPE ui_functions.
  55.   IF gr_alvgrid IS INITIAL.
  56. *----Creating custom container instance
  57.     CREATE OBJECT gr_ccontainer
  58.       EXPORTING
  59.         container_name              = gc_custom_control_name
  60.       EXCEPTIONS
  61.         cntl_error                  = 1
  62.         cntl_system_error           = 2
  63.         create_error                = 3
  64.         lifetime_error              = 4
  65.         lifetime_dynpro_dynpro_link = 5
  66.         OTHERS                      = 6.
  67.  
  68. *----Creating ALV Grid instance
  69.     CREATE OBJECT gr_alvgrid
  70.       EXPORTING
  71.         i_parent          = gr_ccontainer
  72.       EXCEPTIONS
  73.         error_cntl_create = 1
  74.         error_cntl_init   = 2
  75.         error_cntl_link   = 3
  76.         error_dp_create   = 4
  77.         OTHERS            = 5.
  78.  
  79. *----Preparing field catalog.
  80.     PERFORM llenar_fieldcat CHANGING gt_fieldcat.
  81. *----Preparing layout structure
  82.     gs_layout-sel_mode = 'A'.
  83.     gs_layout-box_fname = 'SEL'.
  84.     PERFORM exclude_tb_functions CHANGING lt_exclude .
  85.  
  86.     CALL METHOD gr_alvgrid->set_table_for_first_display
  87.       EXPORTING
  88.         i_save                        = 'X'
  89.         is_layout                     = gs_layout
  90.         it_toolbar_excluding          = lt_exclude
  91.       CHANGING
  92.         it_outtab                     = gt_lista
  93.         it_fieldcatalog               = gt_fieldcat
  94.       EXCEPTIONS
  95.         invalid_parameter_combination = 1
  96.         program_error                 = 2
  97.         too_many_lines                = 3
  98.         OTHERS                        = 4.
  99.  
  100. *--Creating an instance for the event handler
  101.     CREATE OBJECT gr_event_handler.
  102. *--Registering handler methods to handle ALV Grid events
  103.     SET HANDLER gr_event_handler->handle_toolbar FOR gr_alvgrid.
  104.     SET HANDLER gr_event_handler->handle_user_command FOR gr_alvgrid.
  105.     SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid.
  106.     CALL METHOD gr_alvgrid->set_toolbar_interactive.
  107.   ELSE.
  108.     CALL METHOD gr_alvgrid->refresh_table_display
  109.       EXCEPTIONS
  110.         finished = 1
  111.         OTHERS   = 2.
  112.  
  113.   ENDIF.
  114. ENDFORM.                    " display_0100
  115. *&---------------------------------------------------------------------*
  116. *&      Form  llenar_fieldcat
  117. *&---------------------------------------------------------------------*
  118. *       text
  119. *----------------------------------------------------------------------*
  120. *      <--P_GT_FIELDCAT  text
  121. *----------------------------------------------------------------------*
  122. FORM llenar_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
  123.   DATA: ls_fieldcat TYPE lvc_s_fcat.
  124.  
  125.   CLEAR ls_fieldcat.
  126.   ls_fieldcat-fieldname   = 'DATAB'.
  127.   ls_fieldcat-tabname     = 'GT_LISTA'.
  128.   ls_fieldcat-scrtext_m   = 'Data inici'.
  129.   ls_fieldcat-ref_table   = ''.
  130.   ls_fieldcat-ref_field   = ''.
  131.   ls_fieldcat-edit        = ' '.
  132.   ls_fieldcat-outputlen   = 12.
  133.   ls_fieldcat-emphasize   = 'C411'. " color
  134.   APPEND ls_fieldcat TO pt_fieldcat.
  135.  
  136.   CLEAR ls_fieldcat.
  137.   ls_fieldcat-fieldname   = 'TIPUS'.
  138.   ls_fieldcat-tabname     = 'GT_LISTA'.
  139.   ls_fieldcat-scrtext_m   = 'Tipus'.
  140.   ls_fieldcat-ref_table   = ''.
  141.   ls_fieldcat-ref_field   = ''.
  142.   ls_fieldcat-edit        = ' '.
  143.   ls_fieldcat-outputlen   = 6.
  144.   ls_fieldcat-emphasize   = 'C411'. " color
  145.   APPEND ls_fieldcat TO pt_fieldcat.
  146.  
  147.   CLEAR ls_fieldcat.
  148.   ls_fieldcat-fieldname   = 'DATBI'.
  149.   ls_fieldcat-tabname     = 'GT_LISTA'.
  150.   ls_fieldcat-scrtext_m   = 'Data fi'.
  151.   ls_fieldcat-ref_table   = ''.
  152.   ls_fieldcat-ref_field   = ''.
  153.   ls_fieldcat-edit        = ' '.
  154.   ls_fieldcat-outputlen   = 12.
  155.   "  ls_fieldcat-f4availabl  = ' '.
  156.   APPEND ls_fieldcat TO pt_fieldcat.
  157.  
  158.   CLEAR ls_fieldcat.
  159.   ls_fieldcat-fieldname   = 'MAXKG'.
  160.   ls_fieldcat-tabname     = 'GT_LISTA'.
  161.   ls_fieldcat-scrtext_m   = 'Pes màxim'.
  162.   ls_fieldcat-ref_table   = 'ZPERF_PACTES'.
  163.   ls_fieldcat-ref_field   = 'MAXKG'.
  164.   ls_fieldcat-edit        = ' '.
  165.   ls_fieldcat-outputlen   = 12.
  166.   APPEND ls_fieldcat TO pt_fieldcat.
  167.  
  168.   CLEAR ls_fieldcat.
  169.   ls_fieldcat-fieldname   = 'MEINS'.
  170.   ls_fieldcat-tabname     = 'GT_LISTA'.
  171.   ls_fieldcat-scrtext_m   = 'UM'.
  172.   ls_fieldcat-ref_table   = 'ZPERF_PACTES'.
  173.   ls_fieldcat-ref_field   = 'MEINS'.
  174.   ls_fieldcat-edit        = ' '.
  175.   ls_fieldcat-outputlen   = 6.
  176.   APPEND ls_fieldcat TO pt_fieldcat.
  177.  
  178.  
  179. ENDFORM.                    " llenar_fieldcat
  180. *&---------------------------------------------------------------------*
  181. *&      Form  exclude_tb_functions
  182. *&---------------------------------------------------------------------*
  183. *       text
  184. *----------------------------------------------------------------------*
  185. *      -->PT_EXCLUDE text
  186. *----------------------------------------------------------------------*
  187. FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions .
  188.   DATA ls_exclude TYPE ui_func.
  189.   ls_exclude = cl_gui_alv_grid=>mc_fc_maximum .
  190.   APPEND ls_exclude TO pt_exclude.
  191.   ls_exclude = cl_gui_alv_grid=>mc_fc_minimum .
  192.   APPEND ls_exclude TO pt_exclude.
  193.   ls_exclude = cl_gui_alv_grid=>mc_fc_subtot .
  194.   APPEND ls_exclude TO pt_exclude.
  195.   ls_exclude = cl_gui_alv_grid=>mc_fc_sum .
  196.   APPEND ls_exclude TO pt_exclude.
  197.   ls_exclude = cl_gui_alv_grid=>mc_fc_average .
  198.   APPEND ls_exclude TO pt_exclude.
  199.   ls_exclude = cl_gui_alv_grid=>mc_mb_sum .
  200.   APPEND ls_exclude TO pt_exclude.
  201.   ls_exclude = cl_gui_alv_grid=>mc_mb_subtot .
  202.   APPEND ls_exclude TO pt_exclude.
  203.   ls_exclude = cl_gui_alv_grid=>mc_fc_views.
  204.   APPEND ls_exclude TO pt_exclude.
  205.   ls_exclude = cl_gui_alv_grid=>mc_fc_graph.
  206.   APPEND ls_exclude TO pt_exclude.
  207.   ls_exclude = cl_gui_alv_grid=>mc_fc_info.
  208.   APPEND ls_exclude TO pt_exclude.
  209.   ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row .
  210.   APPEND ls_exclude TO pt_exclude.
  211.   ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy .
  212.   APPEND ls_exclude TO pt_exclude.
  213.   ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row .
  214.   APPEND ls_exclude TO pt_exclude.
  215.   ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut .
  216.   APPEND ls_exclude TO pt_exclude.
  217.   ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row .
  218.   APPEND ls_exclude TO pt_exclude.
  219.   ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
  220.   APPEND ls_exclude TO pt_exclude.
  221.   ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
  222.   APPEND ls_exclude TO pt_exclude.
  223.   ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste .
  224.   APPEND ls_exclude TO pt_exclude.
  225.   ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row .
  226.   APPEND ls_exclude TO pt_exclude.
  227.   ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
  228.   APPEND ls_exclude TO pt_exclude.
  229.   ls_exclude = cl_gui_alv_grid=>mc_fc_refresh.
  230.   APPEND ls_exclude TO pt_exclude.
  231. ENDFORM .                    "exclude_tb_functions
  232. *&---------------------------------------------------------------------*
  233. *&      Module  llenar_datos  OUTPUT
  234. *&---------------------------------------------------------------------*
  235. *       text
  236. *----------------------------------------------------------------------*
  237. MODULE llenar_datos OUTPUT.
  238.   PERFORM llenar_datos.
  239. ENDMODULE.                 " llenar_datos  OUTPUT
  240. *&---------------------------------------------------------------------*
  241. *&      Form  llenar_datos
  242. *&---------------------------------------------------------------------*
  243. *       text
  244. *----------------------------------------------------------------------*
  245. *  -->  p1        text
  246. *  <--  p2        text
  247. *----------------------------------------------------------------------*
  248. FORM llenar_datos.
  249.   SELECT * FROM zperf_pactes INTO TABLE gt_lista WHERE lifnr = plifnr.
  250.   SORT gt_lista BY datab.
  251. ENDFORM.                    " llenar_datos
  252. *&---------------------------------------------------------------------*
  253. *&      Module  USER_COMMAND_0100  INPUT
  254. *&---------------------------------------------------------------------*
  255. *       text
  256. *----------------------------------------------------------------------*
  257. MODULE user_command_0100 INPUT.
  258.   CASE ok_code.
  259.     WHEN 'BACK'.
  260.       CLEAR: zperf_pactes-datab, zperf_pactes-tipus, zperf_pactes-datbi,
  261.       zperf_pactes-maxkg, zperf_pactes-meins.
  262.       LEAVE TO SCREEN 0.
  263.     WHEN 'SAVE'.
  264.       PERFORM save.
  265.   ENDCASE.
  266. ENDMODULE.                 " USER_COMMAND_0100  INPUT
  267. *&---------------------------------------------------------------------*
  268. *&      Form  SAVE
  269. *&---------------------------------------------------------------------*
  270. *       text
  271. *----------------------------------------------------------------------*
  272. *  -->  p1        text
  273. *  <--  p2        text
  274. *----------------------------------------------------------------------*
  275. FORM save.
  276.  
  277.   DATA: lt_usu_dep     TYPE TABLE OF zperf_pactes,
  278.         wa_usu_dep     TYPE zperf_pactes,
  279.         wa_usu_dep_nou TYPE zperf_pactes.
  280.   DATA: wa_llista TYPE zperf_pactes.
  281.   DATA: error TYPE i VALUE 0.
  282.   CHECK zperf_pactes-datab IS NOT INITIAL.
  283.   CHECK zperf_pactes-tipus IS NOT INITIAL.
  284.   CHECK zperf_pactes-datbi IS NOT INITIAL.
  285.  
  286.   "Comprovar que no n'existeixi cap igual
  287.   SELECT SINGLE datab FROM zperf_pactes INTO zperf_pactes-datab
  288.     WHERE lifnr = plifnr AND datab = zperf_pactes-datab AND tipus = zperf_pactes-tipus.
  289.  
  290.   IF sy-subrc > 0.
  291.     "Detectar si la data se superposa a una altra.
  292.     LOOP AT gt_lista INTO wa_llista.
  293.       IF
  294.         NOT ( zperf_pactes-datbi < wa_llista-datab
  295.         OR zperf_pactes-datab > wa_llista-datbi )
  296.         AND wa_llista-tipus = zperf_pactes-tipus.
  297.         error = 1.
  298.         EXIT.
  299.       ENDIF.
  300.     ENDLOOP.
  301.  
  302.     IF error = 0.
  303.       wa_usu_dep_nou-datab = zperf_pactes-datab.
  304.       wa_usu_dep_nou-tipus = zperf_pactes-tipus.
  305.       wa_usu_dep_nou-datbi = zperf_pactes-datbi.
  306.       wa_usu_dep_nou-maxkg = zperf_pactes-maxkg.
  307.       wa_usu_dep_nou-meins = zperf_pactes-meins.
  308.       wa_usu_dep_nou-lifnr = plifnr.
  309.  
  310.       READ TABLE gt_lista INTO wa_usu_dep_nou WITH KEY datab = wa_usu_dep_nou-datab lifnr = wa_usu_dep_nou-lifnr tipus = wa_usu_dep_nou-tipus.
  311.       " Com és que ho torno a comprovar aquí? Representa que això ja es comprova al principi.
  312.       IF sy-subrc IS NOT INITIAL.
  313.         INSERT zperf_pactes FROM wa_usu_dep_nou.
  314.       ENDIF.
  315.     ELSE.
  316.       MESSAGE 'Les dates no poden superposar-se.' TYPE 'S' DISPLAY LIKE 'E'.
  317.     ENDIF.
  318.   ELSE.
  319.     MESSAGE 'Ja existeix un preu per aquest tipus i data.' TYPE 'S' DISPLAY LIKE 'E'.
  320.   ENDIF.
  321. ENDFORM.                    " SAVE
  322. *&---------------------------------------------------------------------*
  323. *&      Form  handle_toolbar
  324. *&---------------------------------------------------------------------*
  325. *       text
  326. *----------------------------------------------------------------------*
  327. *      -->P_E_OBJECT  text
  328. *      -->P_E_INTERACTIVE  text
  329. *----------------------------------------------------------------------*
  330. FORM handle_toolbar USING i_object TYPE REF TO cl_alv_event_toolbar_set
  331.                           i_interactive TYPE char01.
  332.  
  333.   DATA: ls_toolbar TYPE stb_button.
  334.   CLEAR ls_toolbar.
  335.   MOVE 3 TO ls_toolbar-butn_type.
  336.   APPEND ls_toolbar TO i_object->mt_toolbar.
  337.   CLEAR ls_toolbar.
  338.   MOVE 'SAVE' TO ls_toolbar-function.                       "#EC NOTEXT
  339.   MOVE icon_system_save TO ls_toolbar-icon.
  340.   MOVE 'Guardar' TO ls_toolbar-quickinfo.
  341.   MOVE ' ' TO ls_toolbar-disabled.                          "#EC NOTEXT
  342.   APPEND ls_toolbar TO i_object->mt_toolbar.
  343.   MOVE 'DELE' TO ls_toolbar-function.                       "#EC NOTEXT
  344.   MOVE icon_delete TO ls_toolbar-icon.
  345.   MOVE 'Borrar' TO ls_toolbar-quickinfo.
  346.   MOVE ' ' TO ls_toolbar-disabled.                          "#EC NOTEXT
  347.   APPEND ls_toolbar TO i_object->mt_toolbar.
  348.  
  349. ENDFORM.                    " handle_toolbar
  350. *&---------------------------------------------------------------------*
  351. *&      Form  handle_user_command
  352. *&---------------------------------------------------------------------*
  353. *       text
  354. *----------------------------------------------------------------------*
  355. *      -->P_E_UCOMM  text
  356. *----------------------------------------------------------------------*
  357. FORM handle_user_command USING i_ucomm TYPE syucomm .
  358.   DATA lt_selected_rows TYPE lvc_t_roid .
  359.   DATA ls_selected_row TYPE lvc_s_roid .
  360.   DATA: wa_lista TYPE zperf_pactes.
  361.  
  362.   CASE i_ucomm .
  363.  
  364.     WHEN 'SAVE' .
  365.       LOOP AT gt_lista INTO wa_lista.
  366.         MODIFY zperf_pactes FROM wa_lista.
  367.       ENDLOOP.
  368.       PERFORM display_0100.
  369.     WHEN 'DELE' .
  370.       CALL METHOD gr_alvgrid->get_selected_rows
  371.         IMPORTING
  372.           et_row_no = lt_selected_rows.
  373.       SORT lt_selected_rows BY row_id DESCENDING.
  374.       LOOP AT lt_selected_rows INTO ls_selected_row.
  375.         READ TABLE gt_lista INTO wa_lista INDEX ls_selected_row-row_id .
  376.         DELETE FROM zperf_pactes WHERE lifnr = wa_lista-lifnr AND datab = wa_lista-datab AND tipus = wa_lista-tipus.
  377.         DELETE gt_lista INDEX ls_selected_row-row_id.
  378.       ENDLOOP.
  379.       PERFORM display_0100.
  380.   ENDCASE .
  381. ENDFORM.                    " handle_user_command
  382. FORM handle_double_click USING i_row TYPE lvc_s_row
  383.          i_column TYPE lvc_s_col
  384.          is_row_no TYPE lvc_s_roid.
  385.   DATA: wa_llista TYPE zperf_pactes OCCURS 0 WITH HEADER LINE.
  386.   DATA: t_fields LIKE sval OCCURS 0 WITH HEADER LINE.
  387.   DATA: wa_lista TYPE zperf_pactes.
  388.   DATA: error TYPE i VALUE 0.
  389.   DATA: data_vella LIKE zperf_pactes-datbi.
  390.  
  391.   READ TABLE gt_lista INTO wa_llista INDEX is_row_no-row_id.
  392.  
  393.   IF sy-subrc = 0.
  394.     CASE i_column.
  395.       WHEN 'DATBI'.   " DATBI
  396.         t_fields-tabname = 'ZPERF_PACTES'.
  397.         t_fields-fieldname = 'DATBI'.
  398.         APPEND t_fields.
  399.  
  400.         CALL FUNCTION 'POPUP_GET_VALUES'
  401.           EXPORTING
  402.             popup_title     = 'test popup'
  403.           TABLES
  404.             fields          = t_fields
  405.           EXCEPTIONS
  406.             error_in_fields = 1
  407.             OTHERS          = 2.
  408.         IF t_fields-value IS NOT INITIAL. " Comprovar que no estigui en blanc
  409.           IF t_fields-value > wa_llista-datbi. " Comprovar que la data final és més gran que la d'inici
  410.             data_vella = wa_llista-datbi.
  411.             wa_llista-datbi = t_fields-value.
  412.             LOOP AT t_fields.
  413.               "Detectar si la data se superposa a una altra.
  414.               LOOP AT gt_lista INTO wa_lista.
  415.                 IF sy-tabix <> is_row_no-row_id.
  416.                   IF
  417.                     " wa_lista -> tota la taula
  418.                     " wa_llista -> línia modificada
  419.                     NOT ( t_fields-value < wa_lista-datab
  420.                     OR  wa_llista-datab > wa_lista-datbi )
  421.                     AND wa_lista-tipus = wa_llista-tipus.
  422.                     error = 1.
  423.                     EXIT.
  424.                   ENDIF.
  425.                 ENDIF.
  426.               ENDLOOP.
  427.               IF error > 0.
  428.                 wa_llista-datbi = data_vella.
  429.               ENDIF.
  430.             ENDLOOP.
  431.           ELSE.
  432.             error = 3.
  433.           ENDIF.
  434.         ELSE.
  435.           error = 2.
  436.         ENDIF.
  437.  
  438.       WHEN 'MAXKG' OR 'MEINS'.   " MAXKG || MEINS
  439.         t_fields-tabname = 'ZPERF_PACTES'.
  440.         t_fields-fieldname = 'MAXKG'.
  441.         APPEND t_fields.
  442.         t_fields-tabname = 'ZPERF_PACTES'.
  443.         t_fields-fieldname = 'MEINS'.
  444.         APPEND t_fields.
  445.  
  446.         CALL FUNCTION 'POPUP_GET_VALUES'
  447.           EXPORTING
  448.             popup_title     = 'test popup'
  449.           TABLES
  450.             fields          = t_fields
  451.           EXCEPTIONS
  452.             error_in_fields = 1
  453.             OTHERS          = 2.
  454.  
  455.         LOOP AT t_fields.
  456.           IF t_fields-fieldname = 'MAXKG'.
  457.             wa_llista-maxkg = t_fields-value.
  458.           ELSEIF t_fields-fieldname = 'MEINS'.
  459.             wa_llista-meins = t_fields-value.
  460.           ENDIF.
  461.         ENDLOOP.
  462.     ENDCASE.
  463.  
  464.     IF error = 0.
  465.       MODIFY zperf_pactes FROM wa_llista.
  466.       PERFORM llenar_datos.
  467.     ELSEIF error = 2.
  468.       MESSAGE 'La data no pot estar en blanc.' TYPE 'S' DISPLAY LIKE 'E'.
  469.     ELSEIF error = 3.
  470.       MESSAGE 'La data final ha de ser més gran que la d´inici.' TYPE 'S' DISPLAY LIKE 'E'.
  471.     ELSE.
  472.       MESSAGE 'Les dates no poden superposar-se.' TYPE 'S' DISPLAY LIKE 'E'.
  473.     ENDIF.
  474.     PERFORM display_0100.
  475.  
  476.   ENDIF.
  477.  
  478. ENDFORM . "handle_double_click
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement