*&---------------------------------------------------------------------*
*& Report Z_BAPICREATESALESORDER_DIS_ALV
*&
*&---------------------------------------------------------------------*
*& Author: James Zeng
*&
*&---------------------------------------------------------------------*
REPORT z_bapicreatesalesorder_dis_alv.
********************************************************************
* Global data definition
TYPE-POOLS: truxs.
DATA: order_header_in LIKE bapisdhd1,
order_items_in LIKE bapisditm OCCURS 0 WITH HEADER LINE,
order_partners LIKE bapiparnr OCCURS 0 WITH HEADER LINE,
order_schedules_in LIKE bapischdl OCCURS 0 WITH HEADER LINE,
order_keys LIKE bapisdkey OCCURS 0 WITH HEADER LINE,
return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: salesdocument LIKE bapivbeln-vbeln,
it_raw TYPE truxs_t_text_data,
line_number(4),
i_counter_update TYPE i, "Main Table Increement Counter
i_counter_success TYPE i, "Success Table increement Counter
i_counter_error TYPE i.
DATA : BEGIN OF it_success OCCURS 0,
salesdocument LIKE bapivbeln-vbeln, "
END OF it_success.
DATA : BEGIN OF it_error OCCURS 0,
line_number(4),
err_msg(73) TYPE c, "TO RETREIVE ERROR MESSAGES
END OF it_error.
DATA: BEGIN OF tab OCCURS 0,
line_number(4),
"doc_type LIKE order_header_in-doc_type,
"sales_org LIKE order_header_in-sales_org,
"distr_chan LIKE order_header_in-distr_chan,
"division LIKE order_header_in-division,
purch_no_c LIKE order_header_in-purch_no_c,
purch_date(10),
itm_number LIKE order_items_in-itm_number,
po_itm_no LIKE order_items_in-po_itm_no,
material LIKE order_items_in-material,
plant LIKE order_items_in-plant,
target_qty LIKE order_items_in-target_qty,
partn_role_sold LIKE order_partners-partn_role,
partn_numb_sold LIKE order_partners-partn_numb,
partn_role_ship LIKE order_partners-partn_role,
partn_numb_ship LIKE order_partners-partn_numb,
END OF tab.
***********************************************************
* Selection screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_vkorg TYPE vbak-vkorg OBLIGATORY,
p_vtweg TYPE vbak-vtweg OBLIGATORY,
p_spart TYPE vbak-spart OBLIGATORY,
p_auart TYPE vbak-auart OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: p_file LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b2.
************************************************************
* At selecion-screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
IF sy-subrc NE 0.
MESSAGE e010(zz) WITH text-003. "
ENDIF.
**************************************************************
* Start-of-selection
START-OF-SELECTION.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
i_line_header ='X'
i_tab_raw_data = it_raw
i_filename = p_file
TABLES
i_tab_converted_data = tab[]
EXCEPTIONS
conversion_failed = 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.
SORT tab BY line_number.
LOOP AT tab.
line_number = tab-line_number.
CONCATENATE tab-purch_date+0(4) tab-purch_date+5(2) tab-purch_date+8(2) INTO tab-purch_date.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = p_spart
IMPORTING
output = p_spart.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = tab-partn_numb_sold
IMPORTING
output = tab-partn_numb_sold.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = tab-partn_numb_ship
IMPORTING
output = tab-partn_numb_ship.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = tab-itm_number
IMPORTING
output = tab-itm_number.
IF tab-line_number = line_number.
order_header_in-doc_type = p_auart.
order_header_in-sales_org = p_vkorg.
order_header_in-distr_chan = p_vtweg .
order_header_in-division = p_spart.
order_header_in-purch_date = tab-purch_date.
order_header_in-purch_no_c = tab-purch_no_c.
order_items_in-itm_number = tab-itm_number.
order_items_in-po_itm_no = tab-po_itm_no.
order_items_in-material = tab-material.
order_items_in-plant = tab-plant.
APPEND order_items_in.
order_partners-partn_role = tab-partn_role_sold.
order_partners-partn_numb = tab-partn_numb_sold.
APPEND order_partners.
order_partners-partn_role = tab-partn_role_ship.
order_partners-partn_numb = tab-partn_numb_ship.
APPEND order_partners.
order_schedules_in-itm_number = tab-itm_number.
order_schedules_in-req_qty = tab-target_qty.
APPEND order_schedules_in.
ENDIF.
AT END OF line_number.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
* SALESDOCUMENTIN =
order_header_in = order_header_in
* ORDER_HEADER_INX =
* SENDER =
* BINARY_RELATIONSHIPTYPE =
* INT_NUMBER_ASSIGNMENT =
* BEHAVE_WHEN_ERROR =
* LOGIC_SWITCH =
* TESTRUN =
* CONVERT = ' '
IMPORTING
salesdocument = salesdocument
TABLES
return = return
order_items_in = order_items_in
* ORDER_ITEMS_INX =
order_partners = order_partners
order_schedules_in = order_schedules_in
* ORDER_SCHEDULES_INX =
* ORDER_CONDITIONS_IN =
* ORDER_CONDITIONS_INX =
* ORDER_CFGS_REF =
* ORDER_CFGS_INST =
* ORDER_CFGS_PART_OF =
* ORDER_CFGS_VALUE =
* ORDER_CFGS_BLOB =
* ORDER_CFGS_VK =
* ORDER_CFGS_REFINST =
* ORDER_CCARD =
* ORDER_TEXT =
order_keys = order_keys
* EXTENSIONIN =
* PARTNERADDRESSES =
.
IF salesdocument <> space.
COMMIT WORK.
ADD 1 TO i_counter_update.
it_success-salesdocument = salesdocument.
APPEND it_success.
CLEAR :salesdocument,order_header_in.
REFRESH : return,order_items_in,order_partners.
ELSE.
ROLLBACK WORK.
LOOP AT return.
it_error-line_number = tab-line_number.
it_error-err_msg = return-message .
APPEND it_error.
ENDLOOP.
CLEAR :salesdocument,order_header_in.
REFRESH : return,order_items_in,order_partners.
ENDIF.
ENDAT.
ENDLOOP.
DESCRIBE TABLE it_success LINES i_counter_success.
IF i_counter_success GT 0.
* Display result report column headings
PERFORM display_column_headings.
* Display result report
PERFORM display_sucess.
ENDIF.
* IF FAILS, Display Error Report
DESCRIBE TABLE it_error LINES i_counter_error.
IF i_counter_error GT 0.
PERFORM errorheadings.
PERFORM errorreport.
ENDIF.
*&---------------------------------------------------------------------*
*& Form display_column_headings
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_column_headings .
WRITE AT 2 ' Success Report ' COLOR COL_HEADING .
WRITE AT /2(50) sy-uline.
WRITE AT /2 sy-vline.
WRITE: AT 3 'The following records inserted successfully:'.
WRITE: AT 51 sy-vline.
WRITE:AT /2 sy-uline(50).
WRITE:AT /2 sy-vline,'Sales ORDER', AT 51 sy-vline.
WRITE:AT /2 sy-uline(50).
ENDFORM. " display_column_headings
*&---------------------------------------------------------------------*
*& Form display_sucess
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_sucess .
LOOP AT it_success.
WRITE: AT /2 sy-vline, it_success-salesdocument,AT 51 sy-vline.
CLEAR it_success.
ENDLOOP.
WRITE:/2 sy-uline(50).
REFRESH: it_success.
ENDFORM. " display_sucess
*&---------------------------------------------------------------------*
*& Form errorheadings
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM errorheadings .
WRITE AT /2 ' Error Report ' COLOR COL_NEGATIVE.
WRITE AT /2(65) sy-uline.
WRITE:AT /2 sy-vline, AT 3 'The following records failed during update:',AT 66 sy-vline.
WRITE:AT /2(65) sy-uline.
FORMAT COLOR COL_HEADING.
WRITE:/2 sy-vline,
(5) 'ERROR.', AT 66 sy-vline.
WRITE:AT /2(65) sy-uline.
FORMAT COLOR COL_NORMAL.
ENDFORM. " errorheadings
*&---------------------------------------------------------------------*
*& Form errorreport
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM errorreport .
* WRITE AT /2(65) sy-ULINE.
LOOP AT it_error.
WRITE:/2 sy-vline, AT (5) it_error-line_number, AT 8 sy-vline,
(60)it_error-err_msg, AT 66 sy-vline.
ENDLOOP.
WRITE:/2(65) sy-uline.
REFRESH: it_error.
ENDFORM. " errorreport
BAPI
最新推荐文章于 2022-02-23 15:02:25 发布