Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

*& Original Transport: SD0K953865..

*& Description: This program retrieve waybills based on posting date,

*& determines if the traffic is cross border, it does this by

* calling program ZFI_CREATE_DISCOUNT_WORKLISTS, which creates a *

* Worklist of all the valid waybills. The user can then enter a

* discount amount that will be apportioned to each waybill. If

* requested, this information will then be converted to a rebate

* worklist which can be submitted for approval and used to create a

* payment document to the customer.

************************************************************************

* Changed by: XXXXXXXXXXX

* SD0KXXXXXXX

* Date:

* Description:

*

************************************************************************REPORT ZFI_REBATE_CURRENCY_DISCOUNT message-id z15.******************************************************************

*&---------------------------------------------------------------------*

*& TABLES

*&---------------------------------------------------------------------*tables: zsd_wb_so_status,

zsd_rebwklst_hdr.**&---------------------------------------------------------------------

**& TYPES

**&---------------------------------------------------------------------TYPE-POOLS: abap.

types: begin of t_status,

fwset type zfwset,

versn type zversn,

kunnr_so type kunnr,

lock_flag type zarch_lock_flag,

lock_type type zarch_lock_type,

lock_user type zarch_lock_user,

lock_date type zarch_lock_date,

end of t_status.**&---------------------------------------------------------------------

**& CONSTANTS

**&---------------------------------------------------------------------CONSTANTS: c_cad type waers value 'CAD',

c_usd type waers value 'USD',

c_l value 'L',

c_p value 'P',

c_rclm type zwrklst_status value 'RCLM',

c_spnd type zwrklst_status value 'SPND',

c_cpnd type zwrklst_status value 'CPND',

c_inpg type zwrklst_status value 'INPG',

c_appr type zwrklst_status value 'APPR',

c_comp type zwrklst_status value 'COMP',

c_subm type zwrklst_status value 'SUBM',

c_rbtc type zwrklst_status value 'RBTC',

c_pink(4) type c value 'C600',

c_blue(4) type c value 'C100',

c_yellow(4) type c value 'C300'.

*&---------------------------------------------------------------------*

*& GLOBAL TABLES/STRUCTURES

*&---------------------------------------------------------------------*

data: gt_locked_waybills type table of t_status,

gt_header type TABLE OF zsd_rebwklst_hdr,

gs_header type zsd_rebwklst_hdr,

gs_header_old type zsd_rebwklst_hdr,

gt_detail type TABLE OF zsd_rebwklst_dtl,

gt_detail_alv type TABLE OF zsd_rebwklst_alv,

gt_detail_old type TABLE OF zsd_rebwklst_dtl,

gs_detail type zsd_rebwklst_dtl,

gs_detail_alv type zsd_rebwklst_alv.

*&---------------------------------------------------------------------*

*& GLOBAL DATA DECLARATIONS

*&---------------------------------------------------------------------*

data: g_lines type i,

okcode like sy-ucomm,

g_archset type zsd_arch_set,

g_cross_border type c,

g_surcharge type c,

g_create1,

g_create2,

g_proceed,

g_header_index type i,

g_create_worklist,

g_wlst_num type zarch_rebate_worklist,

g_blk_start type i,

g_blk_end type i,

gt_row_no type lvc_t_roid,

gt_cols type lvc_t_col,

gt_sel_cells type lvc_t_cell,

gt_rows type lvc_t_row.

*&---------------------------------------------------------------------*

*& GLOBAL Object DECLARATIONS

*&---------------------------------------------------------------------*

data: o_container_1 type ref TO cl_gui_docking_container,

o_container_2 type ref TO cl_gui_docking_container,

o_grid1 type ref TO cl_gui_alv_grid,

o_grid2 type ref TO cl_gui_alv_grid,

gs_layout type lvc_s_layo,

gs_layout_dtl type lvc_s_layo,

gt_exclude type ui_functions,

gt_fieldcat1 type lvc_t_fcat,

gt_fieldcat2 type lvc_t_fcat.

class lcl_events definition deferred.

data: g_events type ref to lcl_events.

* g_descr_ref TYPE ref to cl_abap_structdescr.

*---------------------------------------------------------------------*

* CLASS lcl_events DEFINITION

*---------------------------------------------------------------------*

* ........ *

*---------------------------------------------------------------------*

class lcl_events definition.

public section.

methods:

** double click

* handle_DOUBLE_CLICK for event DOUBLE_CLICK of CL_GUI_ALV_GRID

* importing E_ROW

* E_COLUMN

* ES_ROW_NO,

* data changed

handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed.

endclass. "lcl_events DEFINITION

*---------------------------------------------------------------------*

* CLASS lcl_events IMPLEMENTATION

*---------------------------------------------------------------------*

* ........ *

*---------------------------------------------------------------------*

class lcl_events implementation.

*&---------------------------------------------------------------------*

*& method handle_data_changed

*&---------------------------------------------------------------------*

method handle_data_changed.

perform data_changed using er_data_changed.

endmethod. "handle_data_changed

endclass. "lcl_events IMPLEMENTATION

*--------------------------------

* ALV Structures

*--------------------------------

*&---------------------------------------------------------------------*

*& selection screen

*&---------------------------------------------------------------------*

selection-screen begin of screen 1001 title text-002 as window.

selection-screen begin of block bl1 WITH FRAME TITLE text-001.

select-options: s_budat for zsd_wb_so_status-budat no-EXTENSION,

s_waynum for zsd_wb_so_status-waybill_num MODIF ID mod,

s_waydat for zsd_wb_so_status-waybill_date MODIF ID mod,

s_fwset for zsd_wb_so_status-fwset MODIF ID mod.

SELECTION-SCREEN skip.

selection-screen begin of block bl2 WITH FRAME TITLE text-005.

PARAMETERS: p_waers like zsd_wb_so_status-waers obligatory

default c_cad,

p_bukrs like bkpf-bukrs obligatory default '1000',

p_cont like zsd_rebwklst_dtl-contract default 'DISCOUNT'

,

p_test type char1 as CHECKBOX MODIF ID mod.

selection-screen end of block bl2.

selection-screen end of block bl1.

selection-screen end of screen 1001.

*

** Only show this parameter in SD0 and SQ1. It allows waybills

** that have charge type SURC to be included in the totals as

** currently there is no test data to retrieve.

AT SELECTION-SCREEN output.

if sy-sysid = 'SP1'.

LOOP AT screen.

CASE screen-group1 .

WHEN 'MOD'.

screen-active = 0.

WHEN OTHERS.

ENDCASE.

MODIFY SCREEN.

ENDLOOP.

endif.

*&---------------------------------------------------------------------*

*& Start of Selection

*&---------------------------------------------------------------------*

start-of-selection.

*&---------------------------------------------------------------------*

*& End of Selection

*&---------------------------------------------------------------------*

end-of-selection.

call screen 100.

*&---------------------------------------------------------------------*

*& FORMS

*&**********************************************************************

**

*&---------------------------------------------------------------------*

*& Module STATUS_0100 OUTPUT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

MODULE STATUS_0100 OUTPUT.

SET PF-STATUS '100'.

SET TITLEBAR '100'.

ENDMODULE. " STATUS_0100 OUTPUT

*&---------------------------------------------------------------------*

*& Module USER_COMMAND_0100 INPUT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

MODULE USER_COMMAND_0100 INPUT.

data: l_subrc.

case okcode.

when 'BACK' or 'CANC'.

* Free all the objects we have created

if not o_container_1 is initial.

call method o_grid1->free.

call method o_container_1->free.

clear: o_grid1, o_container_1.

endif.

leave to screen 0.

when 'CREATE'.

call selection-screen 1001 starting at 13 5.

if sy-subrc = 0.

perform create_worklist.

endif.

when 'RETRV'.

clear l_subrc.

perform retrieve_selected_worklist using l_subrc.

check l_subrc is initial.

call screen 200.

when 'DELE'.

perform delete_selected_worklist.

when others.

endcase.

ENDMODULE. " USER_COMMAND_0100 INPUT

*&---------------------------------------------------------------------*

*& Module retrieve_worklist_hdr OUTPUT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

MODULE retrieve_worklist_hdr OUTPUT.

* Retrieve all the worklists that are identified as discount

* worklists

select wlst_num contract wrklst_status totamt_adjmnt

claim_curr disc_start_date disc_end_date

into CORRESPONDING FIELDS OF table gt_header

from zsd_rebwklst_hdr.

sort gt_header by wlst_num DESCENDING.

ENDMODULE. " retrieve_worklist_hdr OUTPUT

*&---------------------------------------------------------------------*

*& Module build_alv_100 OUTPUT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

MODULE build_alv_100 OUTPUT.

* Build field catalogs and display the the ALV for the first

* time

if g_create1 is initial.

create object o_container_1

EXPORTING

extension = 2000.

create object o_grid1

EXPORTING

i_parent = o_container_1.

perform build_fieldcatalog.

* display header ALV

CALL METHOD o_grid1->set_table_for_first_display

EXPORTING

I_SAVE = 'A'

* is_variant = g_laysave

is_layout = gs_layout

it_toolbar_excluding = gt_exclude

CHANGING IT_FIELDCATALOG = gt_fieldcat1

it_outtab = gt_header.

g_create1 = abap_true.

else.

CALL METHOD o_grid1->refresh_table_display.

endif.

ENDMODULE. " build_alv_100 OUTPUT

*&---------------------------------------------------------------------*

*& Form build_fieldcatalog

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM build_fieldcatalog .

* Depending on which screen we are working from, create the

* field catalog for the header or detail ALV

data: ls_fieldcat type lvc_s_fcat,

lt_slis_fieldcat type slis_t_fieldcat_alv,

l_repid like sy-repid,

l_tabname type slis_tabname,

l_structure like dd02l-tabname.

l_repid = sy-repid.

case sy-dynnr.

when '0100'.

l_structure = 'ZSD_REBWKLST_HDR'.

* generate field catalog for header ALV

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = l_repid

I_STRUCTURE_NAME = l_structure

I_INCLNAME = l_repid

CHANGING

CT_FIELDCAT = lt_slis_fieldcat

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL FUNCTION 'LVC_TRANSFER_FROM_SLIS'

EXPORTING

IT_FIELDCAT_ALV = lt_slis_fieldcat

IMPORTING

ET_FIELDCAT_LVC = gt_fieldcat1

TABLES

IT_DATA = gt_header

EXCEPTIONS

IT_DATA_MISSING = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

loop at gt_fieldcat1 into ls_fieldcat.

case ls_fieldcat-fieldname.

when 'WLST_NUM' OR 'CLAIM_CURR'.

when 'CONTRACT' or 'WRKLST_STATUS'.

ls_fieldcat-outputlen = 20.

when 'DISC_START_DATE'.

ls_fieldcat-outputlen = 21.

ls_fieldcat-coltext = text-002.

ls_fieldcat-tooltip = text-002.

when 'DISC_END_DATE'.

ls_fieldcat-outputlen = 21.

ls_fieldcat-coltext = text-003.

ls_fieldcat-tooltip = text-003.

when 'TOTAMT_ADJMNT'.

ls_fieldcat-coltext = text-015.

ls_fieldcat-tooltip = text-015.

when others.

ls_fieldcat-no_out = abap_true.

endcase.

modify gt_fieldcat1 from ls_fieldcat.

endloop.

when '0200'.

l_structure = 'ZSD_REBWKLST_ALV'.

*

** generate field catalog for header ALV

*

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = l_repid

I_STRUCTURE_NAME = l_structure

I_INCLNAME = l_repid

CHANGING

CT_FIELDCAT = lt_slis_fieldcat

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL FUNCTION 'LVC_TRANSFER_FROM_SLIS'

EXPORTING

IT_FIELDCAT_ALV = lt_slis_fieldcat

IMPORTING

ET_FIELDCAT_LVC = gt_fieldcat2

TABLES

IT_DATA = gt_detail

EXCEPTIONS

IT_DATA_MISSING = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

loop at gt_fieldcat2 into ls_fieldcat.

case ls_fieldcat-fieldname.

when 'CONTRACT' or 'REBATE_RECIPIENT' or

'ACCRUAL_AMT' or 'NEW_ACCR_AMT' or

'CLAIM_AMT' or 'WAYBILL_NUM' or

'WAYBILL_DATE' or 'FWSET' or 'VERSN'

or 'BUKRS' or 'WAERS' or 'NAME1'

or 'DISC_PERCENTAGE' or 'ALT_PAYEE'

or 'TRANS_TYPE_CODE' or 'SPECIAL_CHRG_DSC'.

CASE ls_fieldcat-fieldname .

WHEN 'TRANS_TYPE_CODE'.

ls_fieldcat-coltext = text-043.

ls_fieldcat-tooltip = text-043.

ls_fieldcat-outputlen = 6.

WHEN 'SPECIAL_CHRG_DSC'.

ls_fieldcat-coltext = text-044.

ls_fieldcat-tooltip = text-044.

ls_fieldcat-outputlen = 28.

WHEN 'NAME1'.

ls_fieldcat-coltext = text-042.

ls_fieldcat-tooltip = text-042.

WHEN 'CLAIM_AMT'.

ls_fieldcat-coltext = text-011.

ls_fieldcat-tooltip = text-011.

WHEN 'ACCRUAL_AMT'.

ls_fieldcat-coltext = text-016.

ls_fieldcat-tooltip = text-016.

WHEN 'NEW_ACCR_AMT'.

ls_fieldcat-coltext = text-006.

ls_fieldcat-tooltip = text-006.

WHEN 'CONTRACT'.

ls_fieldcat-coltext = text-017.

ls_fieldcat-tooltip = text-017.

ls_fieldcat-outputlen = 11.

WHEN 'REBATE_RECIPIENT'.

ls_fieldcat-coltext = text-020.

ls_fieldcat-tooltip = text-020.

ls_fieldcat-outputlen = 13.

WHEN 'WAERS'.

ls_fieldcat-coltext = text-021.

ls_fieldcat-tooltip = text-021.

ls_fieldcat-outputlen = 11.

WHEN 'BUKRS'.

ls_fieldcat-coltext = text-022.

ls_fieldcat-tooltip = text-022.

ls_fieldcat-outputlen = 12.

WHEN 'DISC_PERCENTAGE'.

ls_fieldcat-coltext = text-030.

ls_fieldcat-tooltip = text-030.

ls_fieldcat-outputlen = 6.

WHEN 'ALT_PAYEE'.

ls_fieldcat-coltext = text-040.

ls_fieldcat-tooltip = text-040.

* ls_fieldcat-outputlen = 6.

WHEN OTHERS.

ENDCASE.

when others.

ls_fieldcat-no_out = abap_true.

endcase.

if ls_fieldcat-fieldname = 'SELECTED'.

ls_fieldcat-col_pos = 1.

else.

ls_fieldcat-col_pos = ls_fieldcat-col_pos + 1.

endif.

modify gt_fieldcat2 from ls_fieldcat.

endloop.

endcase.

ENDFORM. " build_fieldcatalog

*&---------------------------------------------------------------------*

*& Module STATUS_0200 OUTPUT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

MODULE STATUS_0200 OUTPUT.

data: lt_exclude type table of gui_code,

ls_exclude type gui_code.

refresh lt_exclude.

if gs_header-wrklst_status = c_comp.

ls_exclude = 'SUBMT'.

append ls_exclude to lt_exclude.

ls_exclude = 'SAVE'.

append ls_exclude to lt_exclude.

ls_exclude = 'RECALC'.

append ls_exclude to lt_exclude.

ls_exclude = 'MASCHG'.

append ls_exclude to lt_exclude.

ls_exclude = 'SELBLK'.

append ls_exclude to lt_exclude.

loop at screen.

screen-input = 0.

modify screen.

endloop.

* elseif gs_refund_header-wrklst_status = c_subm.

* ls_exclude = c_subm.

* append ls_exclude to lt_exclude.

endif.

SET PF-STATUS '200' excluding lt_exclude.

SET TITLEBAR '200'.

ENDMODULE. " STATUS_0200 OUTPUT

*&---------------------------------------------------------------------*

*& Module USER_COMMAND_0200 INPUT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

MODULE USER_COMMAND_0200 INPUT.

data: l_answer, l_valid.

clear gt_row_no.

call method o_grid2->get_selected_rows

IMPORTING

et_row_no = gt_row_no.

case okcode.

when 'BACK' or 'CANC'.

if gs_header-wrklst_status = c_inpg.

* Free all the objects we have created

* perform convert_alv_to_detail.

perform check_changed changing l_answer.

case l_answer.

when '1'.

CALL FUNCTION 'DEQUEUE_EZSD_REBWKLST_HD'

EXPORTING

WLST_NUM = gs_header-wlst_num.

if not o_container_2 is initial.

call method o_grid2->free.

call method o_container_2->free.

clear: o_grid2, o_container_2, g_create2,

gs_header, gt_detail, gt_detail_alv.

endif.

leave to screen 0.

when others.

endcase.

else.

leave to screen 0.

endif.

when 'SAVE'.

* check g_error is initial.

perform check_changed changing l_answer.

if l_answer = abap_false.

message i006 with text-023.

else.

perform calc_discount.

perform convert_alv_to_detail.

perform save_process.

endif.

when 'SUBMT'.

perform submit_worklist.

when 'RECALC'.

perform calc_discount.

when 'MASCHG'.

perform mass_change.

when 'SELBLK'.

perform select_block.

when others.

endcase.

ENDMODULE. " USER_COMMAND_0200 INPUT

*&---------------------------------------------------------------------*

*& Module convert_detail_to_alv OUTPUT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

MODULE convert_detail_to_alv OUTPUT.

data: ls_detail type zsd_rebwklst_dtl,

ls_detail_alv type zsd_rebwklst_alv,

lt_cell_tab type lvc_t_styl,

ls_cell type lvc_s_styl.

IF gt_detail_alv is initial.

loop at gt_detail into ls_detail.

clear ls_detail_alv.

MOVE-CORRESPONDING ls_detail to ls_detail_alv.

if ls_detail-wbill_closed = abap_false.

ls_detail_alv-rowcolor = c_yellow.

elseif ls_detail-wbill_closed = c_l.

ls_detail_alv-rowcolor = c_pink.

elseif ls_detail-wbill_closed = c_p.

ls_detail_alv-rowcolor = c_blue.

endif.

append ls_detail_alv to gt_detail_alv.

endloop.

elseif okcode = 'SUBMT'.

loop at gt_detail_alv into ls_detail_alv.

if ls_detail_alv-wbill_closed = c_p.

ls_detail_alv-rowcolor = c_blue.

modify gt_detail_alv from ls_detail_alv.

endif.

endloop.

call method o_grid2->refresh_table_display.

ENDIF.

ENDMODULE. " convert_detail_to_alv OUTPUT

*&---------------------------------------------------------------------*

*& Module build_alv_200 OUTPUT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

MODULE build_alv_200 OUTPUT.

if g_create2 is initial.

create object o_container_2

EXPORTING

side = cl_gui_docking_container=>dock_at_bottom

ratio = 80

extension = 2000.

create object o_grid2

EXPORTING

i_parent = o_container_2.

perform build_fieldcatalog.

perform exclude_functions.

gs_layout_dtl-info_fname = 'ROWCOLOR'.

gs_layout-stylefname = 'CELLTAB'.

gs_layout-sel_mode = 'C'.

gs_layout_dtl-smalltitle = text-008.

* display header ALV

CALL METHOD o_grid2->set_table_for_first_display

EXPORTING

I_SAVE = 'A'

* is_variant = g_laysave

is_layout = gs_layout_dtl

it_toolbar_excluding = gt_exclude

CHANGING IT_FIELDCATALOG = gt_fieldcat2

it_outtab = gt_detail_alv.

create object g_events.

g_create2 = abap_true.

set handler g_events->handle_data_changed for o_grid2.

call method o_grid2->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_modified.

if gs_header-wrklst_status = c_inpg.

call method o_grid2->set_ready_for_input

EXPORTING

i_ready_for_input = 1.

else.

call method o_grid2->set_ready_for_input

EXPORTING

i_ready_for_input = 0.

endif.

endif.

ENDMODULE. " build_alv_200 OUTPUT

*&---------------------------------------------------------------------*

*& Form exclude_functions

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM exclude_functions .

data: l_ui_function type ui_func.

case sy-dynnr.

when '0100'.

when '0200'.

* if gs_header-wrklst_status = c_appr or

* gs_header-wrklst_status = c_paid or

* gs_header-wrklst_status = c_subm.

l_ui_function = cl_gui_alv_grid=>mc_fc_info.

APPEND l_ui_function TO gt_exclude.

l_ui_function = cl_gui_alv_grid=>mc_fc_loc_cut.

APPEND l_ui_function TO gt_exclude.

l_ui_function = cl_gui_alv_grid=>mc_fc_loc_copy.

APPEND l_ui_function TO gt_exclude.

l_ui_function = cl_gui_alv_grid=>mc_fc_loc_copy_row.

APPEND l_ui_function TO gt_exclude.

l_ui_function = cl_gui_alv_grid=>mc_fc_loc_insert_row.

APPEND l_ui_function TO gt_exclude.

l_ui_function = cl_gui_alv_grid=>mc_fc_loc_undo.

APPEND l_ui_function TO gt_exclude.

l_ui_function = cl_gui_alv_grid=>mc_fc_loc_append_row.

APPEND l_ui_function TO gt_exclude.

" l_ui_function = cl_gui_alv_grid=>mc_fc_loc_delete_row.

" APPEND l_ui_function TO gt_exclude.

l_ui_function = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.

APPEND l_ui_function TO gt_exclude.

l_ui_function = cl_gui_alv_grid=>mc_fc_loc_paste.

APPEND l_ui_function TO gt_exclude.

l_ui_function = cl_gui_alv_grid=>mc_fc_graph.

APPEND l_ui_function TO gt_exclude.

l_ui_function = cl_gui_alv_grid=>mc_fc_views.

APPEND l_ui_function TO gt_exclude.

* l_ui_function = cl_gui_alv_grid=>mc_mb_export.

* APPEND l_ui_function TO gt_exclude.

l_ui_function = cl_gui_alv_grid=>mc_mb_variant.

APPEND l_ui_function TO gt_exclude.

* else.

* refresh gt_exclude.

* l_ui_function = cl_gui_alv_grid=>mc_fc_refresh.

* APPEND l_ui_function TO gt_exclude.

* l_ui_function = cl_gui_alv_grid=>mc_fc_loc_undo.

* APPEND l_ui_function TO gt_exclude.

* endif.

endcase.

ENDFORM. " exclude_functions

*&---------------------------------------------------------------------*

*& Form check_changed

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* <--P_L_ANSWER text

*----------------------------------------------------------------------*

FORM check_changed CHANGING f_ANSWER.

perform convert_alv_to_detail.

case okcode.

when 'SAVE'.

if gt_detail = gt_detail_old and

gs_header = gs_header_old.

f_answer = abap_false.

else.

f_answer = abap_true.

endif.

when 'BACK' or 'CANC'.

if gt_detail <> gt_detail_old or

gs_header <> gs_header_old.

CALL FUNCTION 'POPUP_TO_CONFIRM'

EXPORTING

TITLEBAR = text-008

TEXT_QUESTION = text-007

TEXT_BUTTON_1 = text-009

TEXT_BUTTON_2 = text-010

DISPLAY_CANCEL_BUTTON = ' '

IMPORTING

ANSWER = f_answer

EXCEPTIONS

TEXT_NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

ENDIF.

else.

f_answer = '1'.

endif.

when 'SUBM'.

endcase.

ENDFORM. " check_changed

*&---------------------------------------------------------------------*

*& Form calc_discount

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM calc_discount.

clear gs_header-totamt_adjmnt.

LOOP AT gt_detail_alv into gs_detail_alv.

check gs_detail_alv-wbill_closed <> c_l and

gs_detail_alv-wbill_closed <> c_p.

if gs_detail_alv-waers = c_cad.

gs_detail_alv-claim_amt = gs_detail_alv-accrual_amt

* gs_detail_alv-disc_percentage / 100 * '-1'.

else.

gs_detail_alv-claim_amt = gs_detail_alv-new_accr_amt

* gs_detail_alv-disc_percentage / 100 * '-1'.

endif.

gs_header-totamt_adjmnt = gs_header-totamt_adjmnt +

gs_detail_alv-claim_amt.

modify gt_detail_alv from gs_detail_alv.

ENDLOOP.

gs_header-totamt_adjmnt = gs_header-totamt_adjmnt * '-1'.

call method o_grid2->refresh_table_display.

ENDFORM. " calc_discount

*&---------------------------------------------------------------------*

*& Form save_process

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM save_process .

data: ls_detail type zsd_rebwklst_dtl.

* Old worklist - Update

gs_header-aenam = sy-uname.

gs_header-aedat = sy-datum.

gs_header-aenzt = sy-uzeit.

update zsd_rebwklst_hdr from gs_header.

if sy-subrc <> 0.

rollback work.

message w006 with text-016.

else.

modify gt_header from gs_header

transporting totamt_claimed

where wlst_num = gs_header-wlst_num.

gs_header_old = gs_header.

delete zsd_rebwklst_dtl from table gt_detail_old.

if sy-subrc = 0.

insert zsd_rebwklst_dtl from table gt_detail.

if sy-subrc = 0.

commit work.

refresh gt_detail_old.

gt_detail_old = gt_detail.

if gs_header-wrklst_status = c_inpg.

message s006 with text-012.

else.

message s006 with text-031.

endif.

else.

rollback work.

message w006 with text-017.

endif.

else.

rollback work.

message w006 with text-017.

endif.

endif.

* endif.

CALL FUNCTION 'DEQUEUE_EZSD_REBWKLST_HD'

EXPORTING

WLST_NUM = gs_header-wlst_num.

ENDFORM. " save_process

*&---------------------------------------------------------------------*

*& Form retrieve_selected_worklist

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->P_L_SUBRC text

*----------------------------------------------------------------------*

FORM retrieve_selected_worklist USING f_SUBRC.

data: lt_row_no type lvc_t_roid,

ls_row_no type lvc_s_roid,

l_lines type i.

refresh: gt_detail.

clear: g_create_worklist.

call method o_grid1->get_selected_rows

IMPORTING

et_row_no = lt_row_no.

describe table lt_row_no lines l_lines.

if lt_row_no is initial.

message i006 with text-013.

f_subrc = 4.

exit.

endif.

if l_lines > 1.

message i006 with text-014.

f_subrc = 4.

exit.

endif.

loop at lt_row_no into ls_row_no.

g_header_index = ls_row_no-row_id.

endloop.

read table gt_header into gs_header

index g_header_index.

if gs_header-wrklst_status = c_inpg or

gs_header-wrklst_status = c_appr.

CALL FUNCTION 'ENQUEUE_EZSD_REBWKLST_HD'

EXPORTING

WLST_NUM = gs_header-wlst_num

EXCEPTIONS

FOREIGN_LOCK = 1

SYSTEM_FAILURE = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

exit.

ENDIF.

endif.

gs_header_old = gs_header.

select * into table gt_detail

from zsd_rebwklst_dtl

where wlst_num = gs_header-wlst_num.

gt_detail_old = gt_detail.

ENDFORM. " retrieve_selected_worklist

*&---------------------------------------------------------------------*

*& Module check_curr INPUT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

MODULE check_curr INPUT.

if not gs_header-claim_curr is initial.

if gs_header-claim_curr = c_cad or

gs_header-claim_curr = c_usd.

exit.

else.

clear gs_header-claim_curr.

message e006 with text-017.

endif.

endif.

ENDMODULE. " check_curr INPUT

*&---------------------------------------------------------------------*

*& Form mass_change

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM mass_change .

data: l_col_cnt type i,

ls_row_no type lvc_s_roid,

* ls_header type zsd_rebwklst_hdr,

l_row_cnt type i,

ls_row type line of lvc_t_roid,

ls_col type lvc_s_col,

ls_detail type zsd_rebwklst_alv,

blk_tmp type i,

l_fields type sval occurs 0 with header line,

l_returncode,

l_value(15).

clear l_row_cnt.

describe table gt_row_no lines l_row_cnt.

if l_row_cnt <> 0.

if l_row_cnt = 1.

read table gt_row_no into ls_row_no

index 1.

if g_blk_start is initial.

g_blk_start = ls_row_no-row_id.

* else.

g_blk_end = ls_row_no-row_id.

endif.

else.

read table gt_row_no into ls_row_no

index 1.

g_blk_start = ls_row_no-row_id.

read table gt_row_no into ls_row_no

index l_row_cnt.

g_blk_end = ls_row_no-row_id.

endif.

else.

describe table gt_detail_alv lines l_row_cnt.

endif.

*

if g_blk_start > 0 and g_blk_end = 0.

call function 'POPUP_TO_DISPLAY_TEXT'

EXPORTING

titel = 'End of Block'

textline1 = 'Select End of Block'.

exit.

endif.

*

if g_blk_end > 0.

if g_blk_end < g_blk_start.

blk_tmp = g_blk_start.

g_blk_start = g_blk_end.

g_blk_end = blk_tmp.

endif.

endif.

if g_blk_start = 0.

g_blk_start = 1.

g_blk_end = l_row_cnt.

endif.

*

refresh: gt_cols, gt_sel_cells, gt_rows.

call method o_grid2->get_selected_columns

IMPORTING

et_index_columns = gt_cols.

describe table gt_cols lines l_col_cnt.

if l_col_cnt > 1.

call function 'POPUP_DISPLAY_MESSAGE'

EXPORTING

titel = 'Validate Column'

msgid = 'Z15'

msgno = '039'

msgty = 'E'.

* msgv1 = worklist_ref->cl_msgv1.

g_proceed = abap_false.

else.

g_proceed = abap_true.

endif.

check g_proceed = abap_true.

read table gt_cols into ls_col

index l_col_cnt.

perform validate_column using ls_col

changing g_proceed.

check g_proceed = abap_true.

refresh l_fields.

l_fields-fieldname = ls_col-fieldname.

l_fields-tabname = 'ZSD_REBWKLST_DTL'.

append l_fields.

l_fields-fieldname = 'FWSET'.

l_fields-tabname = 'ZSD_REBWKLST_DTL'.

l_fields-field_attr = '04'.

append l_fields.

CALL FUNCTION 'POPUP_GET_VALUES'

EXPORTING

POPUP_TITLE = 'Mass Change Value to...'

TABLES

FIELDS = l_fields.

IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

else.

read table l_fields index 1.

if sy-subrc = 0.

shift l_fields-value left deleting leading ' '.

l_value = l_fields-value.

endif.

ENDIF.

if ls_col-fieldname = 'DISC_PERCENTAGE'.

if l_value > '99.9' or l_value < '0'.

message w006 with text-032.

exit.

endif.

elseif ls_col-fieldname = 'CONTRACT'.

if l_value is initial.

exit.

endif.

endif.

check g_proceed = abap_true.

perform change_table_value using l_value

ls_col-fieldname.

clear: g_blk_start, g_blk_end, blk_tmp.

call method o_grid2->refresh_table_display.

ENDFORM. " mass_change

*&---------------------------------------------------------------------*

*& Form select_block

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM select_block .

data: ls_row_no type lvc_s_roid,

ls_header type zsd_rebwklst_hdr,

l_row_cnt type i,

row_wa type line of lvc_t_roid,

blk_tmp type i.

field-symbols: <ls_detial> type zsd_rebwklst_alv.

describe table gt_row_no lines l_row_cnt.

if l_row_cnt = 1.

read table gt_row_no into ls_row_no

index 1.

if g_blk_start is initial.

g_blk_start = ls_row_no-row_id.

else.

g_blk_end = ls_row_no-row_id.

endif.

else.

read table gt_row_no into ls_row_no

index 1.

g_blk_start = ls_row_no-row_id.

read table gt_row_no into ls_row_no

index l_row_cnt.

g_blk_end = ls_row_no-row_id.

endif.

ENDFORM. " select_block

*&---------------------------------------------------------------------*

*& Form data_changed

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->P_ER_DATA_CHANGED text

*----------------------------------------------------------------------*

FORM data_changed using fr_data_changed type ref to

cl_alv_changed_data_protocol.

data: ls_mod_cells type lvc_s_modi.

ENDFORM. " data_changed

*&---------------------------------------------------------------------*

*& Form validate_column

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* <--P_G_PROCEED text

*----------------------------------------------------------------------*

FORM validate_column using fs_col structure lvc_s_col

CHANGING f_PROCEED.

data: l_msgv1 type sychar50.

if fs_col-fieldname = 'WAERS' or

fs_col-fieldname = 'BUKRS' or

fs_col-fieldname = 'CONTRACT' or

fs_col-fieldname = 'REBATE_RECIPIENT' or

fs_col-fieldname = 'DISC_PERCENTAGE' or

fs_col-fieldname = 'ALT_PAYEE'.

f_proceed = abap_true.

else.

call function 'POPUP_DISPLAY_MESSAGE'

EXPORTING

titel = 'Validate Column'

msgid = 'Z15'

msgno = '038'

msgty = 'I'

msgv1 = l_msgv1.

f_proceed = abap_false.

endif.

ENDFORM. " validate_column

*&---------------------------------------------------------------------*

*& Form validate_entry

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->P_LS_COL_FIELDNAME text

* -->P_L_FIELDS_VALUE text

* <--P_G_PROCEED text

*----------------------------------------------------------------------*

FORM validate_entry USING f_FIELDNAME

f_VALUE

CHANGING f_PROCEED.

data: curr_amt type p decimals 2,

ls_convert type rsconvlite,

data_in(15) type c.

data_in = f_value.

clear ls_convert.

ls_convert-olength = 15.

ls_convert-decimals = 2.

ls_convert-sign = abap_true.

call function 'RS_CONV_EX_2_IN_NO_DD'

EXPORTING

input_external = data_in

convert = ls_convert

* currency = l_currency

* quantity = l_quantity " Y9CK035622

IMPORTING

output_internal = curr_amt

EXCEPTIONS

input_not_numerical = 1

too_many_decimals = 2

more_than_one_sign = 3

ill_thousand_separator_dist = 4

too_many_digits = 5

sign_for_unsigned = 6

too_large = 7

too_small = 8

invalid_date_format = 9

invalid_date = 10

invalid_time_format = 11

invalid_time = 12

invalid_hex_digit = 13

unexpected_error = 14

input_too_long = 15

no_decimals = 16

invalid_float = 17

illegal_type = 18

others = 19.

if sy-subrc <> 0.

f_proceed = abap_false.

message id sy-msgid type 'S' number sy-msgno with

sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

else.

f_proceed = abap_true.

endif.

ENDFORM. " validate_entry

*&---------------------------------------------------------------------*

*& Form change_table_value

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->P_L_VALUE text

* -->P_LS_COL_FIELDNAME text

*----------------------------------------------------------------------*

FORM change_table_value USING f_VALUE

f_FIELDNAME.

data: ls_detail_alv type zsd_rebwklst_alv.

field-symbols: <l_field> type any.

assign component f_fieldname of structure ls_detail_alv

to <l_field>.

loop at gt_detail_alv into ls_detail_alv

from g_blk_start to g_blk_end.

if ls_detail_alv-wbill_closed <> c_l and

ls_detail_alv-wbill_closed <> c_p.

<l_field> = f_value.

endif.

modify gt_detail_alv from ls_detail_alv.

endloop.

perform calc_discount.

ENDFORM. " change_table_value

*&---------------------------------------------------------------------*

*& Form convert_alv_to_detail

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM convert_alv_to_detail .

data: ls_detail_alv type zsd_rebwklst_alv,

ls_detail type zsd_rebwklst_dtl.

refresh gt_detail.

LOOP AT gt_detail_alv into ls_detail_alv.

MOVE-CORRESPONDING ls_detail_alv to ls_detail.

append ls_detail to gt_detail.

ENDLOOP.

ENDFORM. " convert_alv_to_detail

*&---------------------------------------------------------------------*

*& Form create_worklist

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM create_worklist .

data: l_jobname type btcjob,

l_jobcnt type btcjobcnt,

l_released type btcchar1,

lt_params type table of rsparams,

ls_params type rsparams.

l_jobname = sy-repid.

CALL FUNCTION 'JOB_OPEN'

EXPORTING

JOBNAME = l_jobname

IMPORTING

JOBCOUNT = l_jobcnt

EXCEPTIONS

CANT_CREATE_JOB = 1

INVALID_JOB_DATA = 2

JOBNAME_MISSING = 3

OTHERS = 4.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

loop at s_budat.

clear ls_params.

ls_params-selname = 'S_BUDAT'.

ls_params-kind = 'S'.

ls_params-sign = s_budat-sign.

ls_params-option = s_budat-option.

ls_params-low = s_budat-low.

ls_params-high = s_budat-high.

append ls_params to lt_params.

endloop.

* add in waybill date to selection params - Marty B-Dec 19, 2007

loop at S_WAYDAT.

clear ls_params.

ls_params-selname = 'S_WAYDAT'.

ls_params-kind = 'S'.

ls_params-sign = s_waydat-sign.

ls_params-option = s_waydat-option.

ls_params-low = s_waydat-low.

ls_params-high = s_waydat-high.

append ls_params to lt_params.

endloop.

* End - Marty B-Dec 19, 2007

clear ls_params.

ls_params-selname = 'P_WAERS'.

ls_params-kind = 'P'.

ls_params-sign = 'I'.

ls_params-option = 'EQ'.

ls_params-low = p_waers.

append ls_params to lt_params.

clear ls_params.

ls_params-selname = 'P_BUKRS'.

ls_params-kind = 'P'.

ls_params-sign = 'I'.

ls_params-option = 'EQ'.

ls_params-low = p_bukrs.

append ls_params to lt_params.

clear ls_params.

ls_params-selname = 'P_CONT'.

ls_params-kind = 'P'.

ls_params-sign = 'I'.

ls_params-option = 'EQ'.

ls_params-low = p_cont.

append ls_params to lt_params.

clear ls_params.

ls_params-selname = 'P_UNAME'.

ls_params-kind = 'P'.

ls_params-sign = 'I'.

ls_params-option = 'EQ'.

ls_params-low = sy-uname.

append ls_params to lt_params.

IF p_test is not initial.

clear ls_params.

ls_params-selname = 'P_TEST'.

ls_params-kind = 'P'.

ls_params-sign = 'I'.

ls_params-option = 'EQ'.

ls_params-low = p_test.

append ls_params to lt_params.

ENDIF.

* submit ZFI_CREATE_DISCOUNT_WORKLISTS

* via JOB l_jobname NUMBER l_jobcnt

* with selection-table lt_params

* and RETURN.

*

CALL FUNCTION 'JOB_CLOSE'

EXPORTING

JOBCOUNT = l_jobcnt

JOBNAME = l_jobname

STRTIMMED = abap_true

IMPORTING

JOB_WAS_RELEASED = l_released

EXCEPTIONS

CANT_START_IMMEDIATE = 1

INVALID_STARTDATE = 2

JOBNAME_MISSING = 3

JOB_CLOSE_FAILED = 4

JOB_NOSTEPS = 5

JOB_NOTEX = 6

LOCK_FAILED = 7

INVALID_TARGET = 8

OTHERS = 9.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " create_worklist

*&---------------------------------------------------------------------*

*& Form submit_worklist

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM submit_worklist.

data: t_lines type sy-tabix.

LOOP AT gt_detail_alv into gs_detail_alv

where wbill_closed = abap_false

and disc_percentage = 0.

* submit only the records with a discount % or discount amt. delete the

* ones without.

delete gt_detail_alv index sy-tabix.

ENDLOOP.

clear t_lines.

describe table gt_detail_alv lines t_lines.

if t_lines = 0.

message w006 with text-033 text-034.

exit.

endif.

perform create_and_submit.

ENDFORM. " submit_worklist

*&---------------------------------------------------------------------*

*& Form delete_selected_worklist

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM delete_selected_worklist .

data: lt_row_no type lvc_t_roid,

ls_row_no type lvc_s_roid,

l_lines type i,

lt_detail type table of zsd_rebwklst_dtl,

l_text(50),

l_subrc type sy-subrc,

l_worklist(12).

clear: l_answer, l_text.

refresh lt_detail.

call method o_grid1->get_selected_rows

IMPORTING

et_row_no = lt_row_no.

describe table lt_row_no lines l_lines.

if lt_row_no is initial.

message i006 with text-013.

exit.

endif.

if l_lines > 1.

message i006 with text-014.

exit.

endif.

loop at lt_row_no into ls_row_no.

g_header_index = ls_row_no-row_id.

endloop.

read table gt_header into gs_header

index g_header_index.

if gs_header-wrklst_status = c_comp.

l_text = text-024.

replace '&' with gs_header-wrklst_status into l_text.

message w006 with l_text.

exit.

endif.

write gs_header-wlst_num to l_worklist.

shift l_worklist left deleting leading '0'.

concatenate l_worklist '?' into l_worklist.

concatenate text-025 l_worklist into l_text

separated by space.

CALL FUNCTION 'POPUP_TO_CONFIRM'

EXPORTING

TITLEBAR = text-025

TEXT_QUESTION = l_text

TEXT_BUTTON_1 = text-009

TEXT_BUTTON_2 = text-010

DISPLAY_CANCEL_BUTTON = ' '

IMPORTING

ANSWER = l_answer

EXCEPTIONS

TEXT_NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

ENDIF.

if l_answer = 1.

CALL FUNCTION 'ENQUEUE_EZSD_REBWKLST_HD'

EXPORTING

WLST_NUM = gs_header-wlst_num

EXCEPTIONS

FOREIGN_LOCK = 1

SYSTEM_FAILURE = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

exit.

ENDIF.

select fwset versn wbill_closed into CORRESPONDING FIELDS OF TABLE

lt_detail

from zsd_rebwklst_dtl

where wlst_num = gs_header-wlst_num.

delete zsd_rebwklst_hdr from gs_header.

if sy-subrc <> 0.

rollback work.

message w006 with text-027.

exit.

endif.

delete table gt_header from gs_header.

delete from zsd_rebwklst_dtl

where wlst_num = gs_header-wlst_num.

if sy-subrc <> 0.

if sy-dbcnt > 0.

rollback work.

message w006 with text-027.

exit.

endif.

endif.

clear l_subrc.

perform unlock_waybills tables lt_detail

changing l_subrc.

IF l_subrc is INITIAL.

message s006 with text-029.

commit work.

else.

rollback work.

message w006 with text-028.

ENDIF.

CALL FUNCTION 'DEQUEUE_EZSD_REBWKLST_HD'

EXPORTING

WLST_NUM = gs_header-wlst_num.

else.

exit.

endif.

ENDFORM. " delete_selected_worklist

*&---------------------------------------------------------------------*

*& Form unlock_waybills

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM unlock_waybills tables ft_detail structure zsd_rebwklst_dtl

changing f_subrc.

data: l_change_status type zsd_arch_change_status,

l_archset type zsd_arch_set,

lt_detail type table of zsd_rebwklst_dtl,

ls_detail type zsd_rebwklst_dtl.

LOOP AT ft_detail into ls_detail

where wbill_closed = abap_false.

clear l_archset.

l_archset-fwset = ls_detail-fwset.

l_archset-versn = ls_detail-versn.

l_change_status-update_lock_data = abap_true.

l_change_status-lock_worklist = gs_header-wlst_num.

l_change_status-lock_type = c_rclm.

* CALL METHOD ZCL_ARCH_WAYBILL=>UPDATE_WAYBILL_STATUS

* EXPORTING

* X_ARCH_SET = l_archset

* X_GET_VERSION = ABAP_TRUE

* X_CHANGE_STATUS = l_change_status

* X_COMMIT = ABAP_FALSE

** X_LOCK_VERSN = ABAP_FALSE

* EXCEPTIONS

* NO_FWSET = 1

* BAD_DATA = 2

* CANNOT_UPDATE = 3

* others = 4

* .

* IF SY-SUBRC <> 0.

** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

* f_subrc = 4.

* ENDIF.

ENDLOOP.

ENDFORM. " unlock_waybills

*&---------------------------------------------------------------------*

*& Form create_and_submit

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM create_and_submit .

data: lt_detail_alv type table of zsd_rebwklst_alv,

ls_detail_alv type zsd_rebwklst_alv,

lt_detail type table of zsd_rebwklst_dtl,

ls_detail type zsd_rebwklst_dtl,

ls_header type zsd_rebwklst_hdr,

l_approver type uname,

lt_approver type table of somlreci1,

ls_approver type somlreci1,

l_subrc type subrc,

l_recip_count(2) type n.

lt_detail_alv = gt_detail_alv.

delete lt_detail_alv where wbill_closed <> abap_false.

sort lt_detail_alv by rebate_recipient.

delete ADJACENT DUPLICATES FROM lt_detail_alv

comparing rebate_recipient.

clear: l_recip_count.

LOOP AT lt_detail_alv into ls_detail_alv.

refresh: lt_detail.

clear: ls_header.

add 1 to l_recip_count.

MOVE-CORRESPONDING gs_header to ls_header.

clear: ls_header-disc_start_date, ls_header-disc_end_date.

concatenate gs_header-disc_start_date '-'

gs_header-disc_end_date+4(4) '-'

l_recip_count into

ls_header-claimno.

ls_header-contr_type = c_rbtc.

ls_header-requestor = sy-uname.

ls_header-wrklst_status = c_subm.

ls_header-ernam = sy-uname.

ls_header-erdat = sy-datum.

ls_header-uzeit = sy-uzeit.

ls_header-requestor = sy-uname.

ls_header-disc_worklist = gs_header-wlst_num.

ls_header-cpr100 = abap_true.

call function 'NUMBER_GET_NEXT'

exporting

nr_range_nr = '01'

object = 'ZREBWLSTNO'

importing

number = ls_header-wlst_num* quantity =

* returncode =EXCEPTIONS

OTHERS = 4

.

IF SY-SUBRC <> 0.

message e006(z15) with text-035.

ENDIF.

LOOP AT gt_detail_alv into gs_detail_alv

where rebate_recipient = ls_detail_alv-rebate_recipient

and wbill_closed = abap_false.

MOVE-CORRESPONDING gs_detail_alv to ls_detail.

clear: ls_detail-accrual_amt.

ls_detail-wlst_num = ls_header-wlst_num.

ls_detail-posnr = sy-tabix.

ls_detail-new_accr_amt = ls_detail-claim_amt.

ls_detail-accramt_wbcurr = ls_detail-claim_amt.

ls_detail-adj_status = c_spnd.

ls_detail-clm_status = c_cpnd.

ls_detail-contract = gs_header-contract.

append ls_detail to lt_detail.

add 1 to ls_header-totitm_claimed.

ls_header-totamt_claimed = ls_header-totamt_claimed +

ls_detail-claim_amt.

gs_detail_alv-wbill_closed = c_p.

IF gs_header-claim_curr <> gs_detail_alv-waers.

ls_detail-exchange_rate = 1 / ls_detail-exchange_rate.

gs_detail_alv-exchange_rate = ls_detail-exchange_rate.

ENDIF.

modify gt_detail_alv from gs_detail_alv.

ENDLOOP.

if sy-subrc <> 0.

rollback work.

continue.

endif.

ls_header-compcode = gs_detail_alv-bukrs.

ls_header-claim_curr = gs_detail_alv-waers.

ls_header-totamt_adjmnt = ls_header-totamt_claimed.

ls_header-rebate_recipient = gs_detail_alv-rebate_recipient.

if gs_detail_alv-alt_payee is not initial.

ls_header-rebate_recipient = gs_detail_alv-alt_payee.

endif.

perform get_approver using ls_header-totamt_claimed

ls_header-claim_curr

changing ls_approver-receiver.

append ls_approver to lt_approver.

ls_header-approver = ls_approver-receiver.

insert into zsd_rebwklst_hdr values ls_header.

if sy-subrc <> 0.

rollback work.

message w006 with text-036.

l_subrc = 4.

else.

insert zsd_rebwklst_dtl from table lt_detail.

if sy-subrc = 0.

* commit work.

* message s006 with text-012.

else.

rollback work.

message w006 with text-037.

l_subrc = 4.

endif.

endif.

ENDLOOP.

check l_subrc is initial.

sort lt_approver by receiver.

delete ADJACENT DUPLICATES FROM lt_approver comparing receiver.

perform send_emails tables lt_approver

changing l_subrc.

check l_subrc is initial.

perform complete_discount_worklist

changing l_subrc.

ENDFORM. " create_and_submit

*&---------------------------------------------------------------------*

*& Form get_approver

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->P_LS_HEADER_TOTAMT_CLAIMED text

*----------------------------------------------------------------------*

FORM get_approver USING f_TOTAMT_CLAIMED

f_waers

changing f_approver.

data: l_uname type p0105-usrid,

l_env_m type logsys,

l_apprvr type tvarv_val,

l_dmbtr type dmbtr.

l_uname = sy-uname.

* If a specific dollar level is part of the approval, pass

* the amount in here as well.

l_dmbtr = abs( f_totamt_claimed ).

select single low into l_apprvr from tvarv

where name = 'ZREBAPPRVR'.

call function 'OWN_LOGICAL_SYSTEM_GET'

IMPORTING

own_logical_system = l_env_m.

if ( l_env_m+0(2) = 'SD' and l_apprvr = 'USER' ) or

( l_env_m+0(2) = 'SQ' and l_apprvr = 'USER' ).

f_approver = sy-uname.

else.

call function 'Z_DOMA_HIERARCHY_CSP'

EXPORTING

rcptr_bname = l_uname

dmbtr = l_dmbtr

waers = f_waers

IMPORTING

ap_bname = f_approver

EXCEPTIONS

missing_input = 1

invalid_level = 2

receiptor_position_not_found = 3

receiptor_empid_not_found = 4

approver_position_not_found = 5

approver_not_found = 6

approver_userid_not_found = 7

approver_grade_too_HIGH = 8

others = 9.

endif.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " get_approver

*&---------------------------------------------------------------------*

*& Form send_emails

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM send_emails tables ft_approver structure somlreci1

changing f_subrc.

data:

lt_objpack type table of sopcklsti1,

ls_objpack type sopcklsti1,

lt_objhead type table of solisti1,

ls_objhead type solisti1,

lt_objbin type table of solisti1,

ls_objbin type solisti1,

lt_objtxt type solisti1 occurs 0,

ls_objtxt type solisti1,

lt_reclist type table of somlreci1,

ls_reclist type somlreci1,

ls_approver type somlreci1,

ls_doc_chng type sodocchgi1,

l_env type logsys,

tab_lines like sy-tabix,

lt_attach TYPE soli OCCURS 0 with header line,

ls_attach type soli.

data: email_domain type tvarv_val.

*-- Get Email domain for TVARV table

select single low into email_domain

from tvarv

where name = 'EMAIL_DOMAIN'

and type = 'P'

and numb = '000'.

* email subject:

call function 'OWN_LOGICAL_SYSTEM_GET'

IMPORTING

own_logical_system = l_env.

if l_env+0(2) <> 'SP'.

concatenate text-038

text-039

l_env+0(3)

into ls_doc_chng-obj_descr

separated by space.

else.

ls_doc_chng-obj_descr = text-038.

endif.

ls_doc_chng-OBJ_NAME = 'REB'.

perform get_email_text tables lt_objtxt using

'ZARCH_DISCOUNT_TO_APPROVER'.

loop at lt_objtxt into ls_objtxt.

endloop.

describe table lt_objtxt lines tab_lines.

ls_doc_chng-doc_size = ( tab_lines - 1 ) *

255 + strlen( ls_objtxt ).

* Creation of the entry

clear ls_objpack-transf_bin.

ls_objpack-head_start = 1.

ls_objpack-head_num = 0.

ls_objpack-body_start = 1.

ls_objpack-body_num = tab_lines.

ls_objpack-doc_type = 'HTM'.

append ls_objpack to lt_objpack.

* Creation of the document attachment

loop at ft_approver into ls_approver.

refresh: lt_attach, lt_objbin, lt_objhead,

lt_objpack, lt_reclist.

* create an attachment to be used for each approver

perform create_shortcut tables lt_attach

using ls_approver-receiver.

loop at lt_attach into ls_attach.

move ls_attach to ls_objbin.

append ls_objbin to lt_objbin.

endloop.

describe table lt_objbin lines tab_lines.

ls_objhead = 'Requestor.SAP'.

append ls_objhead to lt_objhead.

* Creation of the entry for the compressed attachment

ls_objpack-transf_bin = 'X'.

ls_objpack-head_start = 1.

ls_objpack-head_num = 1.

ls_objpack-body_start = 1.

ls_objpack-body_num = tab_lines.

ls_objpack-doc_type = 'SAP'.

ls_objpack-obj_name = 'ZD15'.

ls_objpack-obj_descr = 'SAP Logon to Transaction shortcut'.

ls_objpack-doc_size = tab_lines * 255.

append ls_objpack to lt_objpack.

* refresh ls_reclist.

* clear ls_reclist.

ls_reclist-rec_type = 'U'.

ls_reclist-express = 'X'.

ls_reclist-receiver = ls_approver-receiver.

concatenate ls_reclist-receiver

email_domain

into ls_reclist-receiver.

clear ls_reclist-copy.

append ls_reclist to lt_reclist.

ls_reclist-receiver = sy-uname.

concatenate ls_reclist-receiver

email_domain

into ls_reclist-receiver.

clear ls_reclist-copy.

append ls_reclist to lt_reclist.

* Send document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = ls_doc_chng

PUT_IN_OUTBOX = 'X'

TABLES

PACKING_LIST = lt_objpack

OBJECT_HEADER = lt_objhead

CONTENTS_BIN = lt_objbin

CONTENTS_TXT = lt_objtxt

RECEIVERS = lt_reclist

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

DOCUMENT_TYPE_NOT_EXIST = 5

PARAMETER_ERROR = 6

X_ERROR = 7

ENQUEUE_ERROR = 8

OTHERS = 99.

* if sy-subrc <> 0.

* f_subrc = sy-subrc.

* endif.

endloop.

ENDFORM. " send_emails

*&---------------------------------------------------------------------*

*& Form complete_discount_worklist

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* <--P_L_SUBRC text

*----------------------------------------------------------------------*

FORM complete_discount_worklist CHANGING f_subrc.

data: ls_detail type zsd_rebwklst_dtl.

perform convert_alv_to_detail.

loop at gt_detail into gs_detail

where wbill_closed = c_l.

endloop.

if sy-subrc <> 0.

gs_header-wrklst_status = c_comp.

endif.

perform save_process.

ENDFORM. " complete_discount_worklist

*&---------------------------------------------------------------------*

*& Form get_email_text

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->P_Llt_objtxt text

* -->P_3717 text

*----------------------------------------------------------------------*

form get_email_text tables ft_objtxt structure SOLISTI1

using f_TDNAME like THEAD-TDNAME.

data: lt_lines type table of tline,

htm_lines type table of htmlline,

ls_lines type tline,

l_left type i,

l_size type i,

l_lines type i,

l_worklist(12) type c,

l_requestor(81) type c,

ls_objtxt type solisti1,

ls_objtxt_line type solisti1,

l_pernr type persno,

l_nachn type pad_nachn,

l_vorna type pad_vorna,

l_uname type sysid,

thead_p type thead.

data: txtval_len type i,

txtvar_pos type i.

l_uname = sy-uname.

*

select single pernr into l_pernr

from pa0105

where usrid = l_uname

and endda > sy-datum

and begda < sy-datum.

select single nachn vorna into (l_nachn, l_vorna)

from pa0002

where pernr = l_pernr

and endda > sy-datum

and begda < sy-datum.

concatenate l_vorna l_nachn into l_requestor separated by space.

condense l_requestor.

* Main Text:

CALL FUNCTION 'READ_TEXT'

EXPORTING

ID = 'ST'

LANGUAGE = 'E'

NAME = f_tdname

OBJECT = 'TEXT'

IMPORTING

header = thead_p

TABLES

LINES = lt_lines

EXCEPTIONS

ID = 1

LANGUAGE = 2

NAME = 3

NOT_FOUND = 4

OBJECT = 5

REFERENCE_CHECK = 6

WRONG_ACCESS_TO_ARCHIVE = 7

OTHERS = 8.

if sy-subrc <> 0.

rollback work.

message e040.

endif.

txtval_len = strlen( l_requestor ).

loop at lt_lines into ls_lines.

search ls_lines-tdline for '&req&'.

if sy-subrc = 0.

txtvar_pos = 5 + sy-fdpos.

concatenate

* ls_lines-tdline+0(sy-fdpos)

l_requestor

ls_lines-tdline+txtvar_pos

into ls_lines-tdline

separated by space.

modify lt_lines from ls_lines.

endif.

endloop.

*-- Convert Plain text to HTML

call function 'CONVERT_ITF_TO_HTML'

EXPORTING

i_header = thead_p

TABLES

t_itf_text = lt_lines

t_html_text = htm_lines.

refresh: ft_objtxt.

loop at htm_lines into ls_lines-tdline.

ls_objtxt-line = ls_lines-tdline.

append ls_objtxt to ft_objtxt.

endloop.

ENDFORM. " get_email_text

*&---------------------------------------------------------------------*

*& Form create_shortcut

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->P_LT_ATTACH text

*----------------------------------------------------------------------*

FORM create_shortcut tables IT_attach structure soli

using f_approver.

data: l_host type syhost,

l_sysnum type char2,

l_uname like sy-uname.

DATA: lt_short TYPE soli OCCURS 0,

ls_short TYPE soli,

W_LOGON_PAR(60) TYPE C.

perform get_parameter: using 'SAPGLOBALHOST' changing l_host,

using 'SAPSYSTEM' changing l_sysnum.

* l_uname = sy-uname.

ls_short = '[System]'.

append ls_short to lt_short.

concatenate 'Name='

sy-sysid

into ls_short.

append ls_short to lt_short.

concatenate 'Client='

sy-mandt

into ls_short.

append ls_short to lt_short.

concatenate: l_host l_sysnum into ls_short separated by space,

'GuiParm=' ls_short into ls_short.

append ls_short to lt_short.

ls_short = '[User]'.

append ls_short to lt_short.

concatenate 'Name='

f_approver

into ls_short.

append ls_short to lt_short.

concatenate 'Language='

sy-langu

into ls_short.

append ls_short to lt_short.

ls_short = '[Function]'.

append ls_short to lt_short.

ls_short = 'Title=Rebate Approval'.

append ls_short to lt_short.

concatenate 'Command=' 'ZD66' INTO ls_short.

append ls_short to lt_short.

ls_short = 'Type=Transaction'.

append ls_short to lt_short.

call function 'SO_RAW_TO_RTF'

TABLES

objcont_old = lt_short

objcont_new = it_attach.

ENDFORM. " create_shortcut

*&---------------------------------------------------------------------*

*& Form get_parameter

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->P_4245 text

* <--P_L_HOST text

*----------------------------------------------------------------------*

form get_parameter using px_parameter

changing py_value.

data: l_par_name(60) type c.

data: l_par_status type syindex.

data: l_par_wert(60) type c.

data: begin of lt_par_usub occurs 0,

status like l_par_status,

pname like l_par_name,

user_wert like l_par_wert,

default_wert like l_par_wert,

end of lt_par_usub.

data: begin of lt_par_sub occurs 0,

status like l_par_status,

pname like l_par_name,

user_wert like l_par_wert,

default_wert like l_par_wert,

end of lt_par_sub.

call 'C_SAPGALLPARAM' id 'PAR_USUB' field lt_par_usub-*SYS*

id 'PAR_SUB' field lt_par_sub-SYS.

read table lt_par_sub with key pname = px_parameter.

if sy-subrc ne 0.

message e899(fi) with 'Cannot find parameter' px_parameter.

endif.

if lt_par_sub-user_wert is initial.

py_value = lt_par_sub-user_wert.

else.

py_value = lt_par_sub-default_wert.

endif.

ENDFORM. " get_parameter

  • No labels