Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *&---------------------------------------------------------------------*
- *& Report ZJAU_242_PACT
- *&
- *&---------------------------------------------------------------------*
- *&
- *& Pactes de preus per kg
- *&---------------------------------------------------------------------*
- REPORT zjau_242_pact.
- INCLUDE zjau_242_pact_top.
- INITIALIZATION.
- GET PARAMETER ID 'PLIFNR' FIELD plifnr.
- zperf_pactes-lifnr = plifnr.
- START-OF-SELECTION.
- SELECT SINGLE lifnr INTO plifnr FROM zperf_proveidor WHERE lifnr = plifnr.
- IF sy-subrc = 0.
- SELECT SINGLE name1 INTO lfa1-name1 FROM lfa1 WHERE lifnr = plifnr.
- CALL SCREEN 100.
- ELSE.
- MESSAGE 'Proveïdor no existeix' TYPE 'S' DISPLAY LIKE 'E'.
- ENDIF.
- *&---------------------------------------------------------------------*
- *& Module STATUS_0100 OUTPUT
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- MODULE status_0100 OUTPUT.
- SET PF-STATUS 'STAT0100'.
- SET TITLEBAR 'TIT_0100'.
- ENDMODULE. " STATUS_0100 OUTPUT
- *&---------------------------------------------------------------------*
- *& Module display_0100 OUTPUT
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- MODULE display_0100 OUTPUT.
- PERFORM display_0100.
- ENDMODULE. " display_0100 OUTPUT
- *&---------------------------------------------------------------------*
- *& Form display_0100
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- * --> p1 text
- * <-- p2 text
- *----------------------------------------------------------------------*
- FORM display_0100 .
- DATA: lt_exclude TYPE ui_functions.
- IF gr_alvgrid IS INITIAL.
- *----Creating custom container instance
- CREATE OBJECT gr_ccontainer
- EXPORTING
- container_name = gc_custom_control_name
- EXCEPTIONS
- cntl_error = 1
- cntl_system_error = 2
- create_error = 3
- lifetime_error = 4
- lifetime_dynpro_dynpro_link = 5
- OTHERS = 6.
- *----Creating ALV Grid instance
- CREATE OBJECT gr_alvgrid
- EXPORTING
- i_parent = gr_ccontainer
- EXCEPTIONS
- error_cntl_create = 1
- error_cntl_init = 2
- error_cntl_link = 3
- error_dp_create = 4
- OTHERS = 5.
- *----Preparing field catalog.
- PERFORM llenar_fieldcat CHANGING gt_fieldcat.
- *----Preparing layout structure
- gs_layout-sel_mode = 'A'.
- gs_layout-box_fname = 'SEL'.
- PERFORM exclude_tb_functions CHANGING lt_exclude .
- CALL METHOD gr_alvgrid->set_table_for_first_display
- EXPORTING
- i_save = 'X'
- is_layout = gs_layout
- it_toolbar_excluding = lt_exclude
- CHANGING
- it_outtab = gt_lista
- it_fieldcatalog = gt_fieldcat
- EXCEPTIONS
- invalid_parameter_combination = 1
- program_error = 2
- too_many_lines = 3
- OTHERS = 4.
- *--Creating an instance for the event handler
- CREATE OBJECT gr_event_handler.
- *--Registering handler methods to handle ALV Grid events
- SET HANDLER gr_event_handler->handle_toolbar FOR gr_alvgrid.
- SET HANDLER gr_event_handler->handle_user_command FOR gr_alvgrid.
- SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid.
- CALL METHOD gr_alvgrid->set_toolbar_interactive.
- ELSE.
- CALL METHOD gr_alvgrid->refresh_table_display
- EXCEPTIONS
- finished = 1
- OTHERS = 2.
- ENDIF.
- ENDFORM. " display_0100
- *&---------------------------------------------------------------------*
- *& Form llenar_fieldcat
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- * <--P_GT_FIELDCAT text
- *----------------------------------------------------------------------*
- FORM llenar_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
- DATA: ls_fieldcat TYPE lvc_s_fcat.
- CLEAR ls_fieldcat.
- ls_fieldcat-fieldname = 'DATAB'.
- ls_fieldcat-tabname = 'GT_LISTA'.
- ls_fieldcat-scrtext_m = 'Data inici'.
- ls_fieldcat-ref_table = ''.
- ls_fieldcat-ref_field = ''.
- ls_fieldcat-edit = ' '.
- ls_fieldcat-outputlen = 12.
- ls_fieldcat-emphasize = 'C411'. " color
- APPEND ls_fieldcat TO pt_fieldcat.
- CLEAR ls_fieldcat.
- ls_fieldcat-fieldname = 'TIPUS'.
- ls_fieldcat-tabname = 'GT_LISTA'.
- ls_fieldcat-scrtext_m = 'Tipus'.
- ls_fieldcat-ref_table = ''.
- ls_fieldcat-ref_field = ''.
- ls_fieldcat-edit = ' '.
- ls_fieldcat-outputlen = 6.
- ls_fieldcat-emphasize = 'C411'. " color
- APPEND ls_fieldcat TO pt_fieldcat.
- CLEAR ls_fieldcat.
- ls_fieldcat-fieldname = 'DATBI'.
- ls_fieldcat-tabname = 'GT_LISTA'.
- ls_fieldcat-scrtext_m = 'Data fi'.
- ls_fieldcat-ref_table = ''.
- ls_fieldcat-ref_field = ''.
- ls_fieldcat-edit = ' '.
- ls_fieldcat-outputlen = 12.
- " ls_fieldcat-f4availabl = ' '.
- APPEND ls_fieldcat TO pt_fieldcat.
- CLEAR ls_fieldcat.
- ls_fieldcat-fieldname = 'MAXKG'.
- ls_fieldcat-tabname = 'GT_LISTA'.
- ls_fieldcat-scrtext_m = 'Pes màxim'.
- ls_fieldcat-ref_table = 'ZPERF_PACTES'.
- ls_fieldcat-ref_field = 'MAXKG'.
- ls_fieldcat-edit = ' '.
- ls_fieldcat-outputlen = 12.
- APPEND ls_fieldcat TO pt_fieldcat.
- CLEAR ls_fieldcat.
- ls_fieldcat-fieldname = 'MEINS'.
- ls_fieldcat-tabname = 'GT_LISTA'.
- ls_fieldcat-scrtext_m = 'UM'.
- ls_fieldcat-ref_table = 'ZPERF_PACTES'.
- ls_fieldcat-ref_field = 'MEINS'.
- ls_fieldcat-edit = ' '.
- ls_fieldcat-outputlen = 6.
- APPEND ls_fieldcat TO pt_fieldcat.
- ENDFORM. " llenar_fieldcat
- *&---------------------------------------------------------------------*
- *& Form exclude_tb_functions
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- * -->PT_EXCLUDE text
- *----------------------------------------------------------------------*
- FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions .
- DATA ls_exclude TYPE ui_func.
- ls_exclude = cl_gui_alv_grid=>mc_fc_maximum .
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_minimum .
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_subtot .
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_sum .
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_average .
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_mb_sum .
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_mb_subtot .
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_views.
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_graph.
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_info.
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row .
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy .
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row .
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut .
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row .
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste .
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row .
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
- APPEND ls_exclude TO pt_exclude.
- ls_exclude = cl_gui_alv_grid=>mc_fc_refresh.
- APPEND ls_exclude TO pt_exclude.
- ENDFORM . "exclude_tb_functions
- *&---------------------------------------------------------------------*
- *& Module llenar_datos OUTPUT
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- MODULE llenar_datos OUTPUT.
- PERFORM llenar_datos.
- ENDMODULE. " llenar_datos OUTPUT
- *&---------------------------------------------------------------------*
- *& Form llenar_datos
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- * --> p1 text
- * <-- p2 text
- *----------------------------------------------------------------------*
- FORM llenar_datos.
- SELECT * FROM zperf_pactes INTO TABLE gt_lista WHERE lifnr = plifnr.
- SORT gt_lista BY datab.
- ENDFORM. " llenar_datos
- *&---------------------------------------------------------------------*
- *& Module USER_COMMAND_0100 INPUT
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- MODULE user_command_0100 INPUT.
- CASE ok_code.
- WHEN 'BACK'.
- CLEAR: zperf_pactes-datab, zperf_pactes-tipus, zperf_pactes-datbi,
- zperf_pactes-maxkg, zperf_pactes-meins.
- LEAVE TO SCREEN 0.
- WHEN 'SAVE'.
- PERFORM save.
- ENDCASE.
- ENDMODULE. " USER_COMMAND_0100 INPUT
- *&---------------------------------------------------------------------*
- *& Form SAVE
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- * --> p1 text
- * <-- p2 text
- *----------------------------------------------------------------------*
- FORM save.
- DATA: lt_usu_dep TYPE TABLE OF zperf_pactes,
- wa_usu_dep TYPE zperf_pactes,
- wa_usu_dep_nou TYPE zperf_pactes.
- DATA: wa_llista TYPE zperf_pactes.
- DATA: error TYPE i VALUE 0.
- CHECK zperf_pactes-datab IS NOT INITIAL.
- CHECK zperf_pactes-tipus IS NOT INITIAL.
- CHECK zperf_pactes-datbi IS NOT INITIAL.
- "Comprovar que no n'existeixi cap igual
- SELECT SINGLE datab FROM zperf_pactes INTO zperf_pactes-datab
- WHERE lifnr = plifnr AND datab = zperf_pactes-datab AND tipus = zperf_pactes-tipus.
- IF sy-subrc > 0.
- "Detectar si la data se superposa a una altra.
- LOOP AT gt_lista INTO wa_llista.
- IF
- NOT ( zperf_pactes-datbi < wa_llista-datab
- OR zperf_pactes-datab > wa_llista-datbi )
- AND wa_llista-tipus = zperf_pactes-tipus.
- error = 1.
- EXIT.
- ENDIF.
- ENDLOOP.
- IF error = 0.
- wa_usu_dep_nou-datab = zperf_pactes-datab.
- wa_usu_dep_nou-tipus = zperf_pactes-tipus.
- wa_usu_dep_nou-datbi = zperf_pactes-datbi.
- wa_usu_dep_nou-maxkg = zperf_pactes-maxkg.
- wa_usu_dep_nou-meins = zperf_pactes-meins.
- wa_usu_dep_nou-lifnr = plifnr.
- 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.
- " Com és que ho torno a comprovar aquí? Representa que això ja es comprova al principi.
- IF sy-subrc IS NOT INITIAL.
- INSERT zperf_pactes FROM wa_usu_dep_nou.
- ENDIF.
- ELSE.
- MESSAGE 'Les dates no poden superposar-se.' TYPE 'S' DISPLAY LIKE 'E'.
- ENDIF.
- ELSE.
- MESSAGE 'Ja existeix un preu per aquest tipus i data.' TYPE 'S' DISPLAY LIKE 'E'.
- ENDIF.
- ENDFORM. " SAVE
- *&---------------------------------------------------------------------*
- *& Form handle_toolbar
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- * -->P_E_OBJECT text
- * -->P_E_INTERACTIVE text
- *----------------------------------------------------------------------*
- FORM handle_toolbar USING i_object TYPE REF TO cl_alv_event_toolbar_set
- i_interactive TYPE char01.
- DATA: ls_toolbar TYPE stb_button.
- CLEAR ls_toolbar.
- MOVE 3 TO ls_toolbar-butn_type.
- APPEND ls_toolbar TO i_object->mt_toolbar.
- CLEAR ls_toolbar.
- MOVE 'SAVE' TO ls_toolbar-function. "#EC NOTEXT
- MOVE icon_system_save TO ls_toolbar-icon.
- MOVE 'Guardar' TO ls_toolbar-quickinfo.
- MOVE ' ' TO ls_toolbar-disabled. "#EC NOTEXT
- APPEND ls_toolbar TO i_object->mt_toolbar.
- MOVE 'DELE' TO ls_toolbar-function. "#EC NOTEXT
- MOVE icon_delete TO ls_toolbar-icon.
- MOVE 'Borrar' TO ls_toolbar-quickinfo.
- MOVE ' ' TO ls_toolbar-disabled. "#EC NOTEXT
- APPEND ls_toolbar TO i_object->mt_toolbar.
- ENDFORM. " handle_toolbar
- *&---------------------------------------------------------------------*
- *& Form handle_user_command
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- * -->P_E_UCOMM text
- *----------------------------------------------------------------------*
- FORM handle_user_command USING i_ucomm TYPE syucomm .
- DATA lt_selected_rows TYPE lvc_t_roid .
- DATA ls_selected_row TYPE lvc_s_roid .
- DATA: wa_lista TYPE zperf_pactes.
- CASE i_ucomm .
- WHEN 'SAVE' .
- LOOP AT gt_lista INTO wa_lista.
- MODIFY zperf_pactes FROM wa_lista.
- ENDLOOP.
- PERFORM display_0100.
- WHEN 'DELE' .
- CALL METHOD gr_alvgrid->get_selected_rows
- IMPORTING
- et_row_no = lt_selected_rows.
- SORT lt_selected_rows BY row_id DESCENDING.
- LOOP AT lt_selected_rows INTO ls_selected_row.
- READ TABLE gt_lista INTO wa_lista INDEX ls_selected_row-row_id .
- DELETE FROM zperf_pactes WHERE lifnr = wa_lista-lifnr AND datab = wa_lista-datab AND tipus = wa_lista-tipus.
- DELETE gt_lista INDEX ls_selected_row-row_id.
- ENDLOOP.
- PERFORM display_0100.
- ENDCASE .
- ENDFORM. " handle_user_command
- FORM handle_double_click USING i_row TYPE lvc_s_row
- i_column TYPE lvc_s_col
- is_row_no TYPE lvc_s_roid.
- DATA: wa_llista TYPE zperf_pactes OCCURS 0 WITH HEADER LINE.
- DATA: t_fields LIKE sval OCCURS 0 WITH HEADER LINE.
- DATA: wa_lista TYPE zperf_pactes.
- DATA: error TYPE i VALUE 0.
- DATA: data_vella LIKE zperf_pactes-datbi.
- READ TABLE gt_lista INTO wa_llista INDEX is_row_no-row_id.
- IF sy-subrc = 0.
- CASE i_column.
- WHEN 'DATBI'. " DATBI
- t_fields-tabname = 'ZPERF_PACTES'.
- t_fields-fieldname = 'DATBI'.
- APPEND t_fields.
- CALL FUNCTION 'POPUP_GET_VALUES'
- EXPORTING
- popup_title = 'test popup'
- TABLES
- fields = t_fields
- EXCEPTIONS
- error_in_fields = 1
- OTHERS = 2.
- IF t_fields-value IS NOT INITIAL. " Comprovar que no estigui en blanc
- IF t_fields-value > wa_llista-datbi. " Comprovar que la data final és més gran que la d'inici
- data_vella = wa_llista-datbi.
- wa_llista-datbi = t_fields-value.
- LOOP AT t_fields.
- "Detectar si la data se superposa a una altra.
- LOOP AT gt_lista INTO wa_lista.
- IF sy-tabix <> is_row_no-row_id.
- IF
- " wa_lista -> tota la taula
- " wa_llista -> línia modificada
- NOT ( t_fields-value < wa_lista-datab
- OR wa_llista-datab > wa_lista-datbi )
- AND wa_lista-tipus = wa_llista-tipus.
- error = 1.
- EXIT.
- ENDIF.
- ENDIF.
- ENDLOOP.
- IF error > 0.
- wa_llista-datbi = data_vella.
- ENDIF.
- ENDLOOP.
- ELSE.
- error = 3.
- ENDIF.
- ELSE.
- error = 2.
- ENDIF.
- WHEN 'MAXKG' OR 'MEINS'. " MAXKG || MEINS
- t_fields-tabname = 'ZPERF_PACTES'.
- t_fields-fieldname = 'MAXKG'.
- APPEND t_fields.
- t_fields-tabname = 'ZPERF_PACTES'.
- t_fields-fieldname = 'MEINS'.
- APPEND t_fields.
- CALL FUNCTION 'POPUP_GET_VALUES'
- EXPORTING
- popup_title = 'test popup'
- TABLES
- fields = t_fields
- EXCEPTIONS
- error_in_fields = 1
- OTHERS = 2.
- LOOP AT t_fields.
- IF t_fields-fieldname = 'MAXKG'.
- wa_llista-maxkg = t_fields-value.
- ELSEIF t_fields-fieldname = 'MEINS'.
- wa_llista-meins = t_fields-value.
- ENDIF.
- ENDLOOP.
- ENDCASE.
- IF error = 0.
- MODIFY zperf_pactes FROM wa_llista.
- PERFORM llenar_datos.
- ELSEIF error = 2.
- MESSAGE 'La data no pot estar en blanc.' TYPE 'S' DISPLAY LIKE 'E'.
- ELSEIF error = 3.
- MESSAGE 'La data final ha de ser més gran que la d´inici.' TYPE 'S' DISPLAY LIKE 'E'.
- ELSE.
- MESSAGE 'Les dates no poden superposar-se.' TYPE 'S' DISPLAY LIKE 'E'.
- ENDIF.
- PERFORM display_0100.
- ENDIF.
- ENDFORM . "handle_double_click
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement