|
How to used BAPI_AGREEMENT_CONTRACT to create vendor
contract for tcode ME31K?
REPORT zbapi_contract_create NO STANDARD PAGE HEADING LINE-SIZE 120.
*&---------------------------------------------------------------------*
*& TOP INCLUDE INCLUDE zcontract_create_top. *& FORMS INCLUDE INCLUDE zcontract_create_forms. *&---------------------------------------------------------------------*
*& Providing f4 help path to filmanager on presentation server AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. PERFORM get_file_name USING p_file. *&---------------------------------------------------------------------*
START-OF-SELECTION. *& Getting xls file from presentation server and converting it into int tab PERFORM convert_xls_to_itab USING it_type CHANGING it_contract. *&---------------------------------------------------------------------*
END-OF-SELECTION. *& Filling up data for bapi fm and processing it for contract creation PERFORM build_and_processing_bapi USING it_contract. *& return messages from bapi PERFORM get_return_messages. *&---------------------------------------------------------------------*
TOP-OF-PAGE. PERFORM write_heading. *&---------------------------------------------------------------------*
TYPE-POOLS: truxs. *& structure same as xls file on presentation server TYPES: BEGIN OF ty_contract, vendor(10),
END OF ty_contract, *& structure for reporting status for created contracted BEGIN OF ty_message, vendor(10),
END OF ty_message. TYPES: ty_t_contract TYPE STANDARD TABLE OF ty_contract. *& work area declarations DATA: wa_contract TYPE ty_contract, wa_contract_header TYPE bapioahead,
*& Internal table declarations it_contract_detail TYPE STANDARD TABLE OF bapioaitem,
*& misc data declarations for programming logic l_count TYPE evrtp VALUE '00000'. *& constants used in prog CONSTANTS: cns_x TYPE char1 VALUE 'X'. *&----------------- S E L E C T I O N - S C R E E N -----------------* SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-001. PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY. SELECTION-SCREEN END OF BLOCK bl1. *&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
* Conversion of xls file
* -->P_IT_TYPE used as import parameter for conversion
FORM convert_xls_to_itab USING p_it_type TYPE truxs_t_text_data CHANGING p_it_contract TYPE ty_t_contract. CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP' EXPORTING i_field_seperator = cns_x
TABLES i_tab_converted_data = p_it_contract EXCEPTIONS conversion_failed = 1.
IF sy-subrc = 1. MESSAGE e021(z12_psv1). ENDIF.
ENDFORM. " convert_xls_to_itab *&---------------------------------------------------------------------*
FORM build_and_processing_bapi USING p_it_contract TYPE ty_t_contract. ** local variable for splitting entered dates DATA: l_mm TYPE char2, l_dd TYPE char2,
LOOP AT p_it_contract INTO wa_contract. ** for agreement item no's l_count = l_count + 10. ** setting document date for internal usage CLEAR: l_mm, l_dd, l_yyyy, l_date. SPLIT wa_contract-agree_date AT sep INTO l_mm l_dd l_yyyy IN CHARACTER MODE. CONCATENATE l_yyyy l_mm l_dd INTO l_date. ** setting validity start date for internal usage CLEAR: l_mm, l_dd, l_yyyy, l_date1. SPLIT wa_contract-agree_date AT sep INTO l_mm l_dd l_yyyy IN CHARACTER MODE. CONCATENATE l_yyyy l_mm l_dd INTO l_date1. ** setting validity end date for internal usage CLEAR: l_mm, l_dd, l_yyyy, l_date2. SPLIT wa_contract-agree_date AT sep INTO l_mm l_dd l_yyyy IN CHARACTER MODE. CONCATENATE l_yyyy l_mm l_dd INTO l_date2. ** assignment of header and details from it_contract for passing it to bapi fm CLEAR: wa_contract_header, wa_contract_header_x, wa_contract_detail, wa_contract_detail_x.
APPEND wa_contract_detail TO it_contract_detail. wa_contract_detail_x-agrmt_item = cns_x.
APPEND wa_contract_detail_x TO it_contract_detail_x. AT END OF vendor. PERFORM call_bapi. ENDAT. ENDLOOP. ENDFORM. " build_and_processing_bapi *&---------------------------------------------------------------------*
FORM call_bapi . REFRESH it_return. CALL FUNCTION 'BAPI_AGREEMENT_MAINTAIN' EXPORTING im_agreement_header = wa_contract_header
TABLES ext_return = it_return imt_agreement_items = it_contract_detail
REFRESH: it_contract_detail, it_contract_detail_x. CLEAR l_count. ** generating status report for created contract CLEAR wa_message. wa_message-vendor = wa_contract_header-vendor. LOOP AT it_return INTO wa_return. IF wa_return-type = 'S' or wa_return-type = 'I'.
ELSE. wa_message-status = 'Not Created'.
ENDIF. APPEND wa_message TO it_message. ENDLOOP. ENDFORM. " call_bapi *&---------------------------------------------------------------------*
FORM get_file_name USING p_p_file TYPE rlgrap-filename. CALL FUNCTION 'KD_GET_FILENAME_ON_F4' EXPORTING program_name = syst-repid
* STATIC = ' '
CHANGING file_name = p_p_file. ENDFORM. " get_file_name *&---------------------------------------------------------------------*
FORM get_return_messages . FORMAT INVERSE ON. FORMAT COLOR 3 ON. WRITE:/3(118) sy-uline. WRITE:/3 sy-vline, 5 'VENDOR', 18 sy-vline, 20 'STATUS', 43 sy-vline, 45 'MESSAGE', 120 sy-vline, /3(118) sy-uline. FORMAT COLOR OFF. FORMAT COLOR 5 ON. LOOP AT it_message INTO wa_message. WRITE:/3 sy-vline, 5 wa_message-vendor, 18 sy-vline, 20 wa_message-status, 43 sy-vline, 45 wa_message-message, 120 sy-vline, /3(118) sy-uline. ENDLOOP. FORMAT COLOR OFF. FORMAT INVERSE OFF. ENDFORM. " get_return_messages *&---------------------------------------------------------------------*
FORM write_heading . WRITE:/40 'Status Report for Vendor Contract Creation'. WRITE:/3(118) sy-uline. SKIP 2. ENDFORM. " write_heading |
|
See Also
Get help for your ABAP problems
ABAP Books
More ABAP Tips
SAP Basis, ABAP Programming and Other IMG Stuff All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|