************************************************************************
* TITLE :
* AUTHOR :
* DATE : 2023.05.10
* CHANGE REQUEST :
* DESCRIPTION :Contract create
************************************************************************
* CHANGE HISTORY LOG
*-----------------------------------------------------------------------
* MOD. NO. DATE | NAME | TR NUMBER | CHANGE REFERENCE
*-----------------------------------------------------------------------
* MOD-0001 | DD.MM.YYYY | Q?????? | G??K9????? | CRnnnnnn / PKEnnnnnnn
*
*-----------------------------------------------------------------------
REPORT ZTEST.
TYPE-POOLS:slis,icon,ole2.
************************************************************************
* TYPES
************************************************************************
TYPES :BEGIN OF ts_upd,
*head data*
sequence TYPE char20,
vendor TYPE lifnr,
doc_type TYPE char04,"Purchasing Document Type
ekorg TYPE ekorg,
ekgrp TYPE bkgrp,
text TYPE char200,
vper_start TYPE char08,"Start of Validity Period
vper_end TYPE char08,"End of Validity Period
acum_value TYPE ktwrt,"Target Value for Header Area per Distribution
ref_1 TYPE ihrez,"Your Reference
our_ref TYPE unsez,"Our Reference
quotation TYPE angnr ," quotation NUMBER
quot_date TYPE char08 ," quotation submission DATE
gislp_doh TYPE string ," Degree of Hardness
*-------------
*ITEM data
item_no TYPE ebelp,"Item Number of Purchasing Document
knttp TYPE knttp ,"Account Assignment Category
ematn TYPE ematnr," Material Number
txz01 TYPE txz01 ," Short Text
ktmng TYPE ktmng," Target Quantity
meins TYPE bstme,"Purchase Order Unit of Measure
netpr TYPE bprei, "Net Price in Purchasing Document (in Document Currency)
peinh TYPE epein," Price Unit
bprme TYPE bbprm ," Order Price Unit (Purchasing)
matkl TYPE matkl ," Material Group
werks TYPE ewerk,"Plant
mwskz TYPE mwskz, "Tax on sales/purchases code
*-------------
ebeln TYPE ebeln,
zicon TYPE char10,"light
msg TYPE bapi_msg,
ztype TYPE char01,"msg type
END OF ts_upd.
DATA:gt_data TYPE STANDARD TABLE OF ts_upd.
DATA:gs_data TYPE ts_upd.
DATA:gt_fieldcat TYPE lvc_t_fcat.
DATA:gs_fieldcat TYPE lvc_s_fcat.
DATA:gs_layout TYPE lvc_s_layo.
CONSTANTS: gv_callback_user_command TYPE slis_formname VALUE 'FRM_USER_COMMAND'.
CONSTANTS: gv_callback_status TYPE slis_formname VALUE 'FRM_USER_STATUS'.
************************************************************************
* SELECTION SCREEN *
************************************************************************
TABLES:sscrfields.
SELECTION-SCREEN: FUNCTION KEY 1.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
PARAMETER : p_filein TYPE localfile.
*PARAMETER : p_test TYPE char01 .
SELECTION-SCREEN END OF BLOCK b1.
INITIALIZATION.
DATA:ls_textfield TYPE smp_dyntxt.
ls_textfield-icon_id = '@48@'.
ls_textfield-icon_text = text-004.
sscrfields-functxt_01 = ls_textfield.
* p_test = 'N'.
*-----------------------------------------------------------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_filein.
*-----------------------------------------------------------------------
PERFORM query_filename.
*-----------------------------------------------------------------------
AT SELECTION-SCREEN.
*-----------------------------------------------------------------------
IF sscrfields-ucomm = 'FC01'.
PERFORM download_template.
ENDIF.
*-----------------------------------------------------------------------
START-OF-SELECTION.
*-----------------------------------------------------------------------
IF p_filein IS INITIAL.
MESSAGE s001(/sapmp/mm) WITH 'File name cannot be empty' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
*Get upload data
PERFORM get_upd_data.
*check data
PERFORM check_data.
PERFORM output_report.
*-----------------------------------------------------------------------
*END-OF-SELECTION.
*-----------------------------------------------------------------------
************************************************************************
********************* START OF MAIN PROGRAM ****************************
************************************************************************
*&---------------------------------------------------------------------*
*& Form QUERY_FILENAME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM query_filename .
DATA : lt_file_table TYPE filetable,
lv_file_count TYPE i.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Select file for Upload'
CHANGING
file_table = lt_file_table
rc = lv_file_count
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc EQ 0.
READ TABLE lt_file_table INDEX lv_file_count INTO p_filein.
ENDIF.
ENDFORM. " QUERY_FILENAME
*&---------------------------------------------------------------------*
*& Form READ_INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_upd_data .
DATA : lv_start_col TYPE i VALUE '1',
lv_start_row TYPE i VALUE '3',
lv_end_col TYPE i VALUE '360',
lv_end_row TYPE i VALUE '65536'.
DATA : lt_intern TYPE STANDARD TABLE OF alsmex_tabline.
DATA : ls_intern TYPE alsmex_tabline.
DATA : lv_index TYPE i.
FIELD-SYMBOLS : .
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_filein
i_begin_col = lv_start_col
i_begin_row = lv_start_row
i_end_col = lv_end_col
i_end_row = lv_end_row
TABLES
intern = lt_intern
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
CHECK NOT lt_intern[] IS INITIAL.
SORT lt_intern BY row col.
LOOP AT lt_intern INTO ls_intern.
MOVE : ls_intern-col TO lv_index.
ASSIGN COMPONENT lv_index OF STRUCTURE gs_data TO .
IF ls_intern-value IS INITIAL.
CLEAR ls_intern-value.
ENDIF.
MOVE : ls_intern-value TO .
AT END OF row.
* PERFORM format_dates.
APPEND gs_data TO gt_data.
CLEAR gs_data.
ENDAT.
ENDLOOP.
ENDFORM. " READ_INPUT
*&---------------------------------------------------------------------*
*& Form FORMAT_DATES
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM format_dates .
* REPLACE ALL OCCURENCES OF '.' IN is_data-aedat WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-bedat WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-kdatb WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-kdate WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-bwbdt WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-angdt WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-bnddt WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-gwldt WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-ihran WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-ekpo_aedat WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-agdat WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-abdat WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-prdat WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-lewed WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-eildt WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-drdat WITH ''.
* REPLACE ALL OCCURENCES OF ':' IN is_data-druhr WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-nlabd WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-nfabd WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-j_1aidatep WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-ekkn_aedat WITH ''.
* REPLACE ALL OCCURENCES OF '.' IN is_data-dabrz WITH ''.
ENDFORM. " FORMAT_DATES
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM process_data .
* DATA : l_input TYPE t_input.
*
* LOOP AT it_input
* INTO l_input.
*
* is_data = l_input.
*
* w_ebeln = is_data-ebeln.
*
* AT NEW ebeln.
* CLEAR : ls_header,
* ls_headerx,
* w_error.
*
* REFRESH : it_item,
* it_itemx.
*
* PERFORM setup_header.
*
* ENDAT.
*
* PERFORM setup_item.
*
* AT END OF ebeln.
*
* PERFORM create_contract.
*
* ENDAT.
*
* ENDLOOP.
ENDFORM. " PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form SETUP_HEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fill_header USING is_data TYPE ts_upd
CHANGING cs_header TYPE bapimeoutheader
cs_headerx TYPE bapimeoutheaderx
ct_header_text TYPE bapimeout_t_text
ct_extensionin TYPE bapiparextab.
DATA:ls_header_text TYPE bapimeouttext.
DATA:ls_ekkodb TYPE bapi_te_meoutheader.
DATA:ls_ekkodbx TYPE bapi_te_meoutheaderx.
DATA:ls_extensionin TYPE bapiparex.
DATA:ls_header TYPE bapimeoutheader.
DATA:ls_headerx TYPE bapimeoutheaderx.
ls_header-doc_type = is_data-doc_type.
ls_headerx-doc_type = 'X'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = is_data-vendor
IMPORTING
output = ls_header-vendor.
ls_headerx-vendor = 'X'.
ls_header-langu = sy-langu.
ls_headerx-langu = 'X'.
ls_header-creat_date = sy-datum.
ls_headerx-creat_date = 'X'.
ls_header-created_by = sy-uname.
ls_headerx-created_by = 'X'.
ls_header-currency = 'RMB'.
ls_headerx-currency = 'X'.
ls_header-purch_org = is_data-ekorg.
ls_headerx-purch_org = 'X'.
ls_header-pur_group = is_data-ekgrp.
ls_headerx-pur_group = 'X'.
ls_header-vper_start = is_data-vper_start.
ls_headerx-vper_start = 'X'.
ls_header-vper_end = is_data-vper_end.
ls_headerx-vper_end = 'X'.
*Target Value for Header Area per Distribution
ls_header-acum_value = is_data-acum_value.
ls_headerx-acum_value = 'X'.
ls_header-ref_1 = is_data-ref_1.
ls_headerx-ref_1 = 'X'.
ls_header-our_ref = is_data-our_ref.
ls_headerx-our_ref = 'X'.
*quotation
ls_header-quotation = is_data-quotation.
ls_headerx-quotation = 'X'.
*quot_date
ls_header-quot_date = is_data-quot_date.
ls_headerx-quot_date = 'X'.
* Fill head text
ls_header_text-text_id = 'K01'.
ls_header_text-text_form = '*'.
ls_header_text-text_line = is_data-text.
APPEND ls_header_text TO ct_header_text.
*Fill custom fields
ls_ekkodb-/bmw/gislp_doh = is_data-gislp_doh.
ls_ekkodbx-/bmw/gislp_doh = abap_true.
ls_extensionin-structure = 'BAPI_TE_MEOUTHEADER'.
CALL METHOD cl_abap_container_utilities=>fill_container_c
EXPORTING
im_value = ls_ekkodb
IMPORTING
ex_container = ls_extensionin-valuepart1.
APPEND ls_extensionin TO ct_extensionin.
CLEAR ls_extensionin.
ls_extensionin-structure = 'BAPI_TE_MEOUTHEADERX'.
CALL METHOD cl_abap_container_utilities=>fill_container_c
EXPORTING
im_value = ls_ekkodbx
IMPORTING
ex_container = ls_extensionin-valuepart1.
APPEND ls_extensionin TO ct_extensionin.
cs_header = ls_header.
cs_headerx = ls_headerx.
ENDFORM. " SETUP_HEADER
*&---------------------------------------------------------------------*
*& Form CREATE_CONTRACT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_contract .
DATA:ls_data TYPE ts_upd.
*head
DATA:ls_header TYPE bapimeoutheader.
DATA:ls_headerx TYPE bapimeoutheaderx.
*header_text
DATA:lt_header_text TYPE bapimeout_t_text.
*Custom head fields
DATA:lt_extensionin TYPE bapiparextab.
*item data
DATA:lt_item TYPE bapimeout_t_item.
DATA:lt_itemx TYPE bapimeout_t_itemx.
DATA:lt_item_condition TYPE bapimeout_t_cond.
DATA:lt_item_conditionx TYPE bapimeout_t_condx.
LOOP AT gt_data INTO gs_data.
CLEAR ls_data.
ls_data = gs_data.
AT NEW sequence.
PERFORM fill_header USING ls_data
CHANGING ls_header
ls_headerx
lt_header_text
lt_extensionin
.
ENDAT.
PERFORM fill_item USING ls_data
CHANGING lt_item
lt_itemx
lt_item_condition
lt_item_conditionx.
AT END OF sequence.
* PERFORM call_bapi_create USING ls_data
* ls_header
* ls_headerx
* lt_header_text
* lt_extensionin
* lt_item
* lt_itemx
* lt_item_condition
* lt_item_conditionx.
PERFORM call_bdc_create USING ls_data
ls_header
ls_headerx
lt_header_text
lt_extensionin
lt_item
lt_itemx
lt_item_condition
lt_item_conditionx.
CLEAR ls_header.
CLEAR ls_headerx.
CLEAR lt_header_text.
CLEAR lt_extensionin.
CLEAR lt_item.
CLEAR lt_itemx.
CLEAR lt_item_condition.
CLEAR lt_item_conditionx.
ENDAT.
ENDLOOP.
ENDFORM. " CREATE_CONTRACT
*&---------------------------------------------------------------------*
*& Form CONVERT_ALPHA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_is_data_LIFNR text
* <--P_is_data_LIFNR text
*----------------------------------------------------------------------*
FORM convert_alpha USING pi_input
CHANGING po_output.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = pi_input
IMPORTING
output = po_output.
ENDFORM. " CONVERT_ALPHA
*&---------------------------------------------------------------------*
*& Form OUTPUT_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM output_report.
PERFORM build_fieldcat.
PERFORM alv_output.
ENDFORM. " OUTPUT_REPORT
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_fieldcat .
PERFORM fill_fieldcat USING 'EBELN' 'Contract No' .
PERFORM fill_fieldcat USING 'SEQUENCE' 'Sequence' .
PERFORM fill_fieldcat USING 'VENDOR' 'Vendor' .
PERFORM fill_fieldcat USING 'DOC_TYPE' 'Type' .
PERFORM fill_fieldcat USING 'EKORG' 'Purch Org' .
PERFORM fill_fieldcat USING 'EKGRP' 'Purch Group' .
PERFORM fill_fieldcat USING 'TEXT ' 'Header Text' .
PERFORM fill_fieldcat USING 'VPER_START ' 'VP Start' .
PERFORM fill_fieldcat USING 'VPER_END ' 'VPer.End' .
PERFORM fill_fieldcat USING 'ACUM_VALUE ' 'Targ. Val.' .
PERFORM fill_fieldcat USING 'REF_1 ' 'Your Reference' .
PERFORM fill_fieldcat USING 'OUR_REF ' 'Our Reference' .
PERFORM fill_fieldcat USING 'QUOTATION ' 'Quotation' .
PERFORM fill_fieldcat USING 'QUOT_DATE ' 'Quotation Date' .
PERFORM fill_fieldcat USING 'GISLP_DOH ' 'Deg.of Hardness' .
*item ----
PERFORM fill_fieldcat USING 'ITEM_NO ' 'Item No.' .
PERFORM fill_fieldcat USING 'KNTTP ' 'Item Acct Assignment Cat.' .
PERFORM fill_fieldcat USING 'EMATN ' 'Material' .
PERFORM fill_fieldcat USING 'TXZ01 ' 'Short Text' .
PERFORM fill_fieldcat USING 'KTMNG ' 'Targ. QTY' .
PERFORM fill_fieldcat USING 'MEINS ' 'Order Unit' .
PERFORM fill_fieldcat USING 'NETPR ' 'Net price' .
PERFORM fill_fieldcat USING 'PEINH ' 'Per' .
PERFORM fill_fieldcat USING 'BPRME ' 'Order Price Unit' .
PERFORM fill_fieldcat USING 'MATKL ' 'Matl Group' .
PERFORM fill_fieldcat USING 'WERKS ' 'Plnt' .
PERFORM fill_fieldcat USING 'MWSKZ ' 'Tax code' .
PERFORM fill_fieldcat USING 'ZICON ' 'Light' .
PERFORM fill_fieldcat USING 'MSG ' 'Message Text' .
ENDFORM. " BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*& Form ALV_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alv_output .
gs_layout-zebra = abap_true.
gs_layout-cwidth_opt = abap_true.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
* i_structure_name = 'dfies'
i_callback_pf_status_set = gv_callback_status
i_callback_user_command = gv_callback_user_command
is_layout_lvc = gs_layout
it_fieldcat_lvc = gt_fieldcat
* i_save = 'A'
TABLES
t_outtab = gt_data[]
EXCEPTIONS
program_error = 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.
ENDFORM. " ALV_OUTPUT
*&---------------------------------------------------------------------*
*& Form FILL_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_1187 text
* -->P_1188 text
*----------------------------------------------------------------------*
FORM fill_fieldcat USING iv_fieldname TYPE any
iv_scrtext TYPE any .
CLEAR: gs_fieldcat.
gs_fieldcat-fieldname = iv_fieldname.
gs_fieldcat-scrtext_l = iv_scrtext.
gs_fieldcat-scrtext_m = iv_scrtext.
gs_fieldcat-scrtext_s = iv_scrtext.
APPEND gs_fieldcat TO gt_fieldcat.
ENDFORM. " FILL_FIELDCAT
*&---------------------------------------------------------------------*
*& Form CHECK_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM check_data .
FIELD-SYMBOLS: TYPE ts_upd.
LOOP AT gt_data ASSIGNING .
IF -sequence IS INITIAL.
-msg = 'Please input sequence'.
ENDIF.
IF -vendor IS INITIAL.
-msg = -msg && 'Please input vendor'.
ENDIF.
IF -doc_type IS INITIAL.
-msg = -msg && 'Please input type'.
ENDIF.
IF -ekorg IS INITIAL.
-msg = -msg && 'Please input Purch Org'.
ENDIF.
IF -ekgrp IS INITIAL.
-msg = -msg && 'Please input Purch Group'.
ENDIF.
IF -vper_start IS INITIAL.
-msg = -msg && 'Please input VP Start'.
ENDIF.
IF -vper_end IS INITIAL.
-msg = -msg && 'Please input VPer.End'.
ENDIF.
IF -acum_value IS INITIAL.
-msg = -msg && 'Please input Targ. Val.'.
ENDIF.
IF -gislp_doh IS INITIAL.
-msg = -msg && 'Please input Deg.of Hardness'.
ENDIF.
IF -item_no IS INITIAL.
-msg = -msg && 'Please input Item No.'.
ENDIF.
IF -knttp IS INITIAL.
-msg = -msg && 'Please input Item Acct Assignment Cat.'.
ENDIF.
IF -txz01 IS INITIAL.
-msg = -msg && 'Please input Short Text'.
ENDIF.
IF -ktmng IS INITIAL.
-msg = -msg && 'Please input Targ. QTY'.
ENDIF.
IF -meins IS INITIAL.
-msg = -msg && 'Please input Order Unit'.
ENDIF.
IF -netpr IS INITIAL.
-msg = -msg && 'Please input Net price'.
ENDIF.
IF -peinh IS INITIAL.
-msg = -msg && 'Please input Per'.
ENDIF.
IF -bprme IS INITIAL.
-msg = -msg && 'Please input Order Price Unit'.
ENDIF.
IF -matkl IS INITIAL.
-msg = -msg && 'Please input Matl Group'.
ENDIF.
IF -werks IS INITIAL.
-msg = -msg && 'Please input Plant'.
ENDIF.
"
IF -msg IS NOT INITIAL.
-zicon = icon_red_light.
-ztype = 'E'.
ELSE.
-zicon = icon_green_light.
-ztype = 'S'.
ENDIF.
ENDLOOP.
ENDFORM. " CHECK_DATA
*&---------------------------------------------------------------------*
*& Form FRM_SET_PF_STATUS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_user_status USING i_it_extab TYPE slis_t_extab.
SET PF-STATUS 'CONTRACT_CREATE' .
ENDFORM. " FRM_SET_PF_STATUS
*&---------------------------------------------------------------------*
*& Form frm_user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->IV_UCOMM text
* -->IS_SELFIELD text
*----------------------------------------------------------------------*
FORM frm_user_command USING iv_ucomm TYPE sy-ucomm
is_selfield TYPE slis_selfield.
DATA: l_grid TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = l_grid.
CALL METHOD l_grid->check_changed_data.
CASE iv_ucomm.
WHEN '&MASS'.
CLEAR gs_data.
READ TABLE gt_data TRANSPORTING NO FIELDS WITH KEY ztype = 'E'.
IF sy-subrc IS INITIAL.
MESSAGE 'Please check error data and try again!' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
PERFORM create_contract.
* WHEN '&IC1'. "单击复选框 勾选(取消)后同一预留号都自动勾选(取消)
* READ TABLE gt_alv INDEX is_selfield-tabindex INTO DATA(ls_alb). "获取单击行
* IF is_selfield--fieldname = 'SEL' AND is_selfield-sel = ''.
*
* SET PARAMETER ID 'ANR' FIELD -aufnr.
* CALL TRANSACTION 'IW33' AND SKIP FIRST SCREEN.
*
* CALL FUNCTION 'MIGO_DIALOG'
* EXPORTING
* i_action = 'A04'
* i_refdoc = 'R02'
* i_mblnr = lv_mblnr
* i_mjahr = lv_mjahr
* EXCEPTIONS
* illegal_combination = 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.
*
* ENDIF.
ENDCASE.
**刷新
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = l_grid.
CALL METHOD l_grid->check_changed_data.
CALL METHOD l_grid->refresh_table_display.
is_selfield-refresh = 'X' .
ENDFORM. "frm_user_command
*&---------------------------------------------------------------------*
*& Form CALL_BAPI_CREATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_DATA text
* -->P_LS_HEADER text
* -->P_LS_HEADERX text
* -->P_LT_HEADER_TEXT text
* -->P_LT_EXTENSIONIN text
* -->P_LT_ITEM text
* -->P_LT_ITEMX text
*----------------------------------------------------------------------*
FORM call_bapi_create USING is_data TYPE ts_upd
is_header TYPE bapimeoutheader
is_headerx TYPE bapimeoutheaderx
it_header_text TYPE bapimeout_t_text
it_extensionin TYPE bapiparextab
it_item TYPE bapimeout_t_item
it_itemx TYPE bapimeout_t_itemx
it_item_condition TYPE bapimeout_t_cond
it_item_conditionx TYPE bapimeout_t_condx.
DATA:lv_purchasingdocument TYPE bapimeoutheader-number.
DATA:lt_return TYPE bapiret2tab.
DATA:ls_return TYPE bapiret2.
DATA:ls_data TYPE ts_upd.
ls_data = is_data.
BREAK-POINT.
CALL FUNCTION 'BAPI_CONTRACT_CREATE'
EXPORTING
header = is_header
headerx = is_headerx
testrun = ''
IMPORTING
purchasingdocument = lv_purchasingdocument
TABLES
return = lt_return
item = it_item
itemx = it_itemx
* ACCOUNT = ACCOUNT
* ACCOUNTPROFITSEGMENT = ACCOUNTPROFITSEGMENT
* ACCOUNTX = ACCOUNTX
* DELIVERY_ADDRESS = DELIVERY_ADDRESS
* ITEM_COND_VALIDITY = ITEM_COND_VALIDITY
* ITEM_COND_VALIDITYX = ITEM_COND_VALIDITYX
item_condition = it_item_condition
item_conditionx = it_item_conditionx
* ITEM_COND_SCALE_VALUE = ITEM_COND_SCALE_VALUE
* ITEM_COND_SCALE_QUAN = ITEM_COND_SCALE_QUAN
* ITEM_TEXT = ITEM_TEXT
header_text = it_header_text
* HEAD_COND_VALIDITY = HEAD_COND_VALIDITY
* HEAD_COND_VALIDITYX = HEAD_COND_VALIDITYX
* HEAD_CONDITION = HEAD_CONDITION
* HEAD_CONDITIONX = HEAD_CONDITIONX
* HEAD_COND_SCALE_VAL = HEAD_COND_SCALE_VAL
* HEAD_COND_SCALE_QUAN = HEAD_COND_SCALE_QUAN
* PARTNER = PARTNER
* PARTNERX = PARTNERX
extensionin = it_extensionin
* extensionout =.
* EXTENSIONOUT
.
LOOP AT lt_return INTO ls_return WHERE type = 'E'.
ls_data-msg = ls_data-msg && ls_return-message.
ENDLOOP.
IF sy-subrc IS INITIAL.
ls_data-ztype = 'E'.
ls_data-zicon = icon_red_light.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
ls_data-ztype = 'S'.
ls_data-zicon = icon_green_light.
ls_data-msg = 'Contract created successfully'.
ls_data-ebeln = lv_purchasingdocument.
ENDIF.
MODIFY gt_data FROM ls_data TRANSPORTING ztype zicon msg ebeln WHERE sequence = ls_data-sequence .
ENDFORM. " CALL_BAPI_CREATE
*&---------------------------------------------------------------------*
*& Form SETUP_ITEM
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fill_item USING is_data TYPE ts_upd
CHANGING ct_item TYPE bapimeout_t_item
ct_itemx TYPE bapimeout_t_itemx
ct_item_condition TYPE bapimeout_t_cond
ct_item_conditionx TYPE bapimeout_t_condx.
*item data
DATA:ls_item TYPE bapimeoutitem.
DATA:ls_itemx TYPE bapimeoutitemx.
DATA:ls_item_condition TYPE bapimeoutcondition.
DATA:ls_item_conditionx TYPE bapimeoutconditionx.
ls_item-item_no = is_data-item_no.
ls_itemx-item_no = is_data-item_no.
ls_item-acctasscat = is_data-knttp.
ls_itemx-acctasscat = abap_true.
ls_item-material = is_data-ematn.
ls_itemx-material = abap_true.
ls_item-short_text = is_data-txz01.
ls_itemx-short_text = abap_true.
ls_item-target_qty = is_data-ktmng.
ls_itemx-target_qty = abap_true.
ls_item-po_unit = is_data-meins.
ls_itemx-po_unit = abap_true.
ls_item-net_price = is_data-netpr.
ls_itemx-net_price = abap_true.
ls_item-orderpr_un = is_data-bprme.
ls_itemx-orderpr_un = abap_true.
ls_item-price_unit = is_data-peinh.
ls_itemx-price_unit = abap_true.
ls_item-matl_group = is_data-matkl.
ls_itemx-matl_group = abap_true.
ls_item-plant = is_data-werks.
ls_itemx-plant = abap_true.
ls_item-tax_code = is_data-mwskz.
ls_itemx-tax_code = abap_true.
APPEND ls_item TO ct_item.
APPEND ls_itemx TO ct_itemx.
*fill condition
ls_item_condition-item_no = is_data-item_no.
ls_item_conditionx-item_no = is_data-item_no.
ls_item_condition-cond_type = 'PB00'.
ls_item_conditionx-cond_type = abap_true.
ls_item_condition-currency = 'RMB'.
ls_item_conditionx-currency = abap_true.
ls_item_condition-cond_value = is_data-netpr.
ls_item_conditionx-cond_value = abap_true.
ls_item_condition-cond_p_unt = is_data-peinh.
ls_item_conditionx-cond_p_unt = abap_true.
APPEND ls_item_condition TO ct_item_condition.
APPEND ls_item_conditionx TO ct_item_conditionx.
ENDFORM. " SETUP_ITEM
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_TEMPLATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM download_template .
DATA:
ls_obdata TYPE wwwdatatab,
lv_filename TYPE string,
lv_file_name TYPE string,
lv_path TYPE string,
lv_fullpath TYPE string,
lv_extension TYPE c LENGTH 6.
DATA:
l_dstntn TYPE localfile,
l_rc TYPE sysubrc.
lv_file_name = 'Contract Template Upload.xlsx' .
*--------------"调用保存对话框"-------------------------*
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
default_extension = 'XLSX'
default_file_name = lv_file_name
CHANGING
filename = lv_filename
path = lv_path
fullpath = lv_fullpath
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF lv_fullpath = ''.
MESSAGE e001(/sapmp/mm) WITH 'Path cannot be empty'.
ENDIF.
IF sy-subrc = 0.
l_dstntn = lv_fullpath.
CALL FUNCTION 'TRINT_FILE_GET_EXTENSION'
EXPORTING
filename = l_dstntn
IMPORTING
extension = lv_extension.
IF lv_extension <> 'XLSX' .
MESSAGE e001(/sapmp/mm) WITH 'Format error'.
ENDIF.
SELECT SINGLE *
INTO CORRESPONDING FIELDS OF ls_obdata
FROM wwwdata
WHERE srtf2 = 0 AND
relid = 'MI' AND
objid = 'ZCONTRACT_CREATE'.
IF sy-subrc <> 0 OR
ls_obdata-objid = space.
MESSAGE s001(/sapmp/mm) WITH 'Template not exist ' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
key = ls_obdata
destination = l_dstntn
IMPORTING
rc = l_rc.
* CHANGING
* TEMP =
IF l_rc <> 0.
MESSAGE s001(/sapmp/mm) WITH 'Failed to download template' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
ENDFORM. " DOWNLOAD_TEMPLATE
*&---------------------------------------------------------------------*
*& Form CALL_BDC_CREATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_DATA text
* -->P_LS_HEADER text
* -->P_LS_HEADERX text
* -->P_LT_HEADER_TEXT text
* -->P_LT_EXTENSIONIN text
* -->P_LT_ITEM text
* -->P_LT_ITEMX text
* -->P_LT_ITEM_CONDITION text
* -->P_LT_ITEM_CONDITIONX text
*----------------------------------------------------------------------*
FORM call_bdc_create USING is_data TYPE ts_upd
is_header TYPE bapimeoutheader
is_headerx TYPE bapimeoutheaderx
it_header_text TYPE bapimeout_t_text
it_extensionin TYPE bapiparextab
it_item TYPE bapimeout_t_item
it_itemx TYPE bapimeout_t_itemx
it_item_condition TYPE bapimeout_t_cond
it_item_conditionx TYPE bapimeout_t_condx.
*bdc值转化数据定义
DATA:l_date_str1 TYPE char10,
l_date_str2 TYPE char10,
l_ktwrt_str TYPE char15,
l_wkurs_str TYPE char10,
l_bukrs TYPE bukrs,
l_ktmng_str TYPE char20,
lv_netpr_str TYPE char14,
l_menge_str TYPE char17,
l_tbtwr_str TYPE char20,
lv_string TYPE string,
l_poski_str TYPE char8,
l_vbelp_str TYPE char5.
DATA:lt_bdcdata TYPE bdcdata_tab.
DATA:ls_data TYPE ts_upd.
DATA:ls_item TYPE bapimeoutitem.
DATA:lv_lines TYPE i,
lv_index TYPE i,
lv_price_unit TYPE string,
lv_lines2 TYPE i.
DATA: w_lastitem(5) TYPE n.
DATA: w_curritem(5) TYPE n.
DATA:lt_tab_msg TYPE TABLE OF bdcmsgcoll,
ls_tab_msg TYPE bdcmsgcoll.
DATA: ls_header TYPE thead .
DATA: lt_ltxts TYPE STANDARD TABLE OF tline .
DATA: ls_ltxt TYPE tline .
ls_data = is_data.
*Fill head
* Begin dynpro 200 (Einstiegsbild)
PERFORM bdc_dynpro TABLES lt_bdcdata
USING 'SAPMM06E' '0200'.
* Set fields (dynpro 200)
PERFORM set_fields_blaord_dynpro_200
TABLES lt_bdcdata
USING is_data.
* fill item
lv_lines = lines( it_item ).
lv_lines2 = lv_lines - 1 .
LOOP AT it_item INTO ls_item .
CLEAR lv_netpr_str .
CLEAR l_menge_str.
CLEAR lv_price_unit.
WRITE ls_item-net_price TO lv_netpr_str NO-GROUPING DECIMALS 2.
WRITE ls_item-target_qty TO l_menge_str NO-GROUPING DECIMALS 3.
lv_index = lv_index + 1 .
IF lv_index = 1.
w_lastitem = 10.
w_curritem = 10.
ELSEIF lv_index = 2.
w_lastitem = 10.
w_curritem = w_curritem + 10.
ELSE.
w_lastitem = w_lastitem + 10.
w_curritem = w_curritem + 10.
ENDIF.
PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMM06E' '0220'.
PERFORM bdc_field TABLES lt_bdcdata USING 'RM06E-EBELP' w_lastitem.
PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '/00'.
PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMM06E' '0220'.
IF lv_index = 1.
* PERFORM bdc_dynpro TABLES lt_bdcdata
* USING 'SAPMM06E'
* '0220'.
* PERFORM bdc_field TABLES lt_bdcdata
* USING 'BDC_CURSOR'
* 'EKPO-KTMNG'.
* IF lv_index = lv_lines .
* lv_string = '=BU'.
* ELSE.
* lv_string = '=BS'.
* ENDIF.
* PERFORM bdc_field TABLES lt_bdcdata
* USING 'BDC_OKCODE'
* lv_string.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-KNTTP(01)'
ls_item-acctasscat.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-EMATN(01)'
ls_item-material.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-TXZ01(01)'
ls_item-short_text.
CONDENSE l_menge_str NO-GAPS.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-KTMNG(01)'
l_menge_str.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-MEINS(01)'
ls_item-po_unit.
CONDENSE lv_netpr_str NO-GAPS.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-NETPR(01)'
lv_netpr_str.
lv_price_unit = ls_item-price_unit.
CONDENSE lv_price_unit NO-GAPS.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-PEINH(01)'
lv_price_unit.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-BPRME(01)'
ls_item-po_unit.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-MATKL(01)'
ls_item-matl_group.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-WERKS(01)'
ls_item-plant.
ELSE.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-KNTTP(02)'
ls_item-acctasscat.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-EMATN(02)'
ls_item-material.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-TXZ01(02)'
ls_item-short_text.
CONDENSE l_menge_str NO-GAPS.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-KTMNG(02)'
l_menge_str.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-MEINS(02)'
ls_item-po_unit.
CONDENSE lv_netpr_str NO-GAPS.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-NETPR(02)'
lv_netpr_str.
lv_price_unit = ls_item-price_unit.
CONDENSE lv_price_unit NO-GAPS.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-PEINH(02)'
lv_price_unit.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-BPRME(02)'
ls_item-po_unit.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-MATKL(02)'
ls_item-matl_group.
PERFORM bdc_field TABLES lt_bdcdata
USING 'EKPO-WERKS(02)'
ls_item-plant.
ENDIF.
IF lv_index = 1.
PERFORM bdc_field TABLES lt_bdcdata USING 'RM06E-TCSELFLAG(01)' 'X'.
ELSE.
PERFORM bdc_field TABLES lt_bdcdata USING 'RM06E-TCSELFLAG(02)' 'X'.
ENDIF.
PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '=DETA'.
PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMM06E' '0211'.
IF ls_item-tax_code IS NOT INITIAL.
PERFORM bdc_field TABLES lt_bdcdata USING 'EKPO-MWSKZ' ls_item-tax_code.
ENDIF.
PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '/00'.
ENDLOOP.
PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMM06E' '0220'.
PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '=BU'.
PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPLSPO1' '0300'.
PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE'
'=YES'.
BREAK-POINT.
CALL TRANSACTION 'ME31K' USING lt_bdcdata
MODE 'N'
UPDATE 'S'
MESSAGES INTO lt_tab_msg.
COMMIT WORK .
LOOP AT lt_tab_msg INTO ls_tab_msg.
IF ls_tab_msg-msgtyp = 'S' AND
ls_tab_msg-msgid = '06' AND
ls_tab_msg-msgnr = '017'. "
ls_data-ztype = 'S'.
ls_data-zicon = icon_green_light.
ls_data-msg = 'Contract created successfully'.
ls_data-ebeln = ls_tab_msg-msgv2.
ELSEIF ls_tab_msg-msgtyp = 'E'.
MESSAGE ID ls_tab_msg-msgid TYPE ls_tab_msg-msgtyp NUMBER ls_tab_msg-msgnr
WITH ls_tab_msg-msgv1 ls_tab_msg-msgv2
ls_tab_msg-msgv3 ls_tab_msg-msgv4
INTO ls_data-msg.
ls_data-ztype = 'E'.
ls_data-zicon = icon_red_light.
ENDIF.
ENDLOOP.
*update head text
IF ls_data-ebeln IS NOT INITIAL.
ls_ltxt-tdline = is_data-text.
ls_ltxt-tdformat = '*'.
APPEND ls_ltxt TO lt_ltxts .
ls_header-tdobject = 'EKKO' . "文本对象
ls_header-tdid = 'K01'. "文本ID
ls_header-tdspras = '1'. "语言
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = ls_data-ebeln
IMPORTING
output = ls_data-ebeln.
ls_header-tdname = ls_data-ebeln. "输入参数
ls_header-tdform = 'SYSTEM'. "输入参数
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
client = sy-mandt
header = ls_header
savemode_direct = 'X'
TABLES
lines = lt_ltxts.
IF sy-subrc <> 0.
ROLLBACK WORK .
ELSE.
COMMIT WORK AND WAIT .
ENDIF.
ENDIF.
MODIFY gt_data FROM ls_data TRANSPORTING ztype zicon msg ebeln WHERE sequence = ls_data-sequence .
ENDFORM. " CALL_BDC_CREATE
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
FORM bdc_dynpro
TABLES
t_bdcdata STRUCTURE bdcdata
USING
program LIKE bdcdata-program
dynpro LIKE bdcdata-dynpro.
CLEAR t_bdcdata.
t_bdcdata-program = program.
t_bdcdata-dynpro = dynpro.
t_bdcdata-dynbegin = abap_true.
APPEND t_bdcdata.
ENDFORM. "bdc_dynpro
*&---------------------------------------------------------------------*
*& Form SET_FIELDS_BLAORD_DYNPRO_200
*&---------------------------------------------------------------------*
FORM set_fields_blaord_dynpro_200
TABLES t_bdcdata STRUCTURE bdcdata
USING f_ekko TYPE ts_upd.
DATA: lv_bedat(35).
DATA: lv_acum_value(20).
WRITE f_ekko-acum_value TO lv_acum_value NO-GROUPING DECIMALS 2.
PERFORM bdc_field
TABLES t_bdcdata
USING 'EKKO-LIFNR'
f_ekko-vendor.
PERFORM bdc_field
TABLES t_bdcdata
USING 'RM06E-EVART'
f_ekko-doc_type.
lv_bedat = sy-datum.
PERFORM bdc_field
TABLES t_bdcdata
USING 'RM06E-VEDAT'
lv_bedat.
PERFORM bdc_field
TABLES t_bdcdata
USING 'EKKO-EKORG'
f_ekko-ekorg.
PERFORM bdc_field
TABLES t_bdcdata
USING 'EKKO-EKGRP'
f_ekko-ekgrp.
PERFORM bdc_dynpro TABLES t_bdcdata USING 'SAPMM06E' '0201'.
PERFORM bdc_field TABLES t_bdcdata USING 'BDC_CURSOR'
'EKKO-KDATE'.
* PERFORM bdc_field TABLES t_bdcdata
* USING 'BDC_OKCODE'
* '=BS'.
CLEAR lv_bedat.
lv_bedat = f_ekko-vper_start.
PERFORM bdc_field TABLES t_bdcdata
USING 'EKKO-KDATB'
lv_bedat.
CLEAR lv_bedat.
lv_bedat = f_ekko-vper_end.
PERFORM bdc_field TABLES t_bdcdata
USING 'EKKO-KDATE'
lv_bedat.
CONDENSE lv_acum_value NO-GAPS.
PERFORM bdc_field TABLES t_bdcdata
USING 'EKKO-KTWRT'
* f_ekko-acum_value.
lv_acum_value.
PERFORM bdc_field TABLES t_bdcdata
USING 'EKKO-IHREZ'
f_ekko-ref_1.
PERFORM bdc_field TABLES t_bdcdata
USING 'EKKO-UNSEZ'
f_ekko-our_ref.
PERFORM bdc_field TABLES t_bdcdata
USING 'EKKO-ANGNR'
f_ekko-quotation.
CLEAR lv_bedat.
lv_bedat = f_ekko-quot_date.
PERFORM bdc_field TABLES t_bdcdata
USING 'EKKO-IHRAN'
lv_bedat.
PERFORM bdc_field TABLES t_bdcdata
USING 'EKKO_CI-/BMW/GISLP_DOH'
f_ekko-gislp_doh.
ENDFORM. " SET_FIELDS_BLAORD_DYNPRO_200
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FNAM text
* -->FVAL text
*----------------------------------------------------------------------*
FORM bdc_field TABLES t_bdcdata STRUCTURE bdcdata
USING fnam fval.
IF fval <> ''.
CLEAR t_bdcdata.
t_bdcdata-fnam = fnam.
t_bdcdata-fval = fval.
APPEND t_bdcdata.
ENDIF.
ENDFORM. "BDC_FIELD