************************************************************************
* 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.
CONSTANTS:gc_success TYPE char01 VALUE 'S'.
CONSTANTS:gc_error TYPE char01 VALUE 'E'.
DATA:gt_fieldcat TYPE lvc_t_fcat.
DATA:gs_fieldcat TYPE lvc_s_fcat.
DATA:gs_layout TYPE lvc_s_layo.
CONSTANTS: gc_callback_user_command TYPE slis_formname VALUE 'FRM_USER_COMMAND'.
CONSTANTS: gc_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 AS CHECKBOX .
SELECTION-SCREEN END OF BLOCK b1.
INITIALIZATION.
PERFORM set_functxt.
* 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 gc_error.
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 : TYPE any.
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.
IF sy-subrc IS NOT INITIAL.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
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.
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_ekkodb TYPE /bmw/gis_cr_bapi_char.
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 = abap_true.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = is_data-vendor
IMPORTING
output = ls_header-vendor.
ls_headerx-vendor = abap_true.
ls_header-langu = sy-langu.
ls_headerx-langu = abap_true.
ls_header-creat_date = sy-datum.
ls_headerx-creat_date = abap_true.
ls_header-created_by = sy-uname.
ls_headerx-created_by = abap_true.
ls_header-currency = 'RMB'.
ls_headerx-currency = abap_true.
ls_header-purch_org = is_data-ekorg.
ls_headerx-purch_org = abap_true.
ls_header-pur_group = is_data-ekgrp.
ls_headerx-pur_group = abap_true.
ls_header-vper_start = is_data-vper_start.
ls_headerx-vper_start = abap_true.
ls_header-vper_end = is_data-vper_end.
ls_headerx-vper_end = abap_true.
*Target Value for Header Area per Distribution
ls_header-acum_value = is_data-acum_value.
ls_headerx-acum_value = abap_true.
ls_header-ref_1 = is_data-ref_1.
ls_headerx-ref_1 = abap_true.
ls_header-our_ref = is_data-our_ref.
ls_headerx-our_ref = abap_true.
*quotation
ls_header-quotation = is_data-quotation.
ls_headerx-quotation = abap_true.
*quot_date
ls_header-quot_date = is_data-quot_date.
ls_headerx-quot_date = abap_true.
* 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+30.
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 WHERE ebeln IS INITIAL.
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.
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.
IF sy-subrc IS NOT INITIAL.
MESSAGE s001(/sapmp/mm) WITH 'No data to create contract' DISPLAY LIKE gc_error.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " CREATE_CONTRACT
" 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 = gc_callback_status
i_callback_user_command = gc_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 = gc_error.
ELSE.
-zicon = icon_green_light.
-ztype = gc_success.
ENDIF.
ENDLOOP.
ENDFORM. " CHECK_DATA
*&---------------------------------------------------------------------*
*& Form FRM_SET_PF_STATUS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_user_status USING 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: lv_cl_grid TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = lv_cl_grid.
CALL METHOD lv_cl_grid->check_changed_data.
CASE iv_ucomm.
WHEN '&MASS'.
CLEAR gs_data.
READ TABLE gt_data TRANSPORTING NO FIELDS WITH KEY ztype = gc_error.
IF sy-subrc IS INITIAL.
MESSAGE 'Please check error data and try again!' TYPE gc_success DISPLAY LIKE gc_error.
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 = lv_cl_grid.
CALL METHOD lv_cl_grid->check_changed_data.
CALL METHOD lv_cl_grid->refresh_table_display.
is_selfield-refresh = abap_true .
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 = p_test
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 = gc_error.
ls_data-msg = ls_data-msg && ls_return-message.
ENDLOOP.
IF sy-subrc IS INITIAL.
ls_data-ztype = gc_error.
ls_data-zicon = icon_red_light.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
ls_data-ztype = gc_success.
ls_data-zicon = icon_green_light.
ls_data-msg = 'Contract created successfully'.
ls_data-ebeln = lv_purchasingdocument.
IF p_test IS INITIAL .
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
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:
lv_dstntn TYPE localfile,
lv_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.
lv_dstntn = lv_fullpath.
CALL FUNCTION 'TRINT_FILE_GET_EXTENSION'
EXPORTING
filename = lv_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 = '/BMW/GIS_MASS_CONTRACT_CREATE'.
IF sy-subrc <> 0 OR
ls_obdata-objid = space.
MESSAGE s001(/sapmp/mm) WITH 'Template not exist ' DISPLAY LIKE gc_error.
LEAVE LIST-PROCESSING.
ENDIF.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
key = ls_obdata
destination = lv_dstntn
IMPORTING
rc = lv_rc.
* CHANGING
* TEMP =
IF lv_rc <> 0.
MESSAGE s001(/sapmp/mm) WITH 'Failed to download template' DISPLAY LIKE gc_error.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
ENDFORM. " DOWNLOAD_TEMPLATE
*&---------------------------------------------------------------------*
*& Form SET_FUNCTXT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM set_functxt .
DATA:ls_textfield TYPE smp_dyntxt.
ls_textfield-icon_id = '@48@'.
ls_textfield-icon_text = text-004.
sscrfields-functxt_01 = ls_textfield.
ENDFORM. " SET_FUNCTXT
如果报错VK251 OR dump raise not found 参考别的文章