2007 Oct 22 5:46 PM
I am posting this question again as I haven't get any reply on my previous post
Hi Gurus,
Actually I need to update the price in some of the selected PO's as price of the materials have changed, so basically the functional folks will be sening me an input file with material no's and the changed price, and now I need to chnage the price of the materials in some of the existing PO's. I have made a selection criterion and based on that all the PO numbers those are required to be change are stored in it_tab2 with field ebeln and all the material no's and the updated price are stored in it_tab1 with field names material and price and now I have to use BAPI_PO_CHANGE to change the PO price, so can you please help me out how to use this BAPI to achieve what is required and moreover the exiting pO's may have multip;e line items with different material no's ,,,,please don't paste the sample code, please try to solve this problem using my own table and fields. I will really appreciate your efforts:
Thanks
I am posting this question again as I haven't get any reply on my previous post
Hi Gurus,
Actually I need to update the price in some of the selected PO's as price of the materials have changed, so basically the functional folks will be sening me an input file with material no's and the changed price, and now I need to chnage the price of the materials in some of the existing PO's. I have made a selection criterion and based on that all the PO numbers those are required to be change are stored in it_tab2 with field ebeln and all the material no's and the updated price are stored in it_tab1 with field names material and price and now I have to use BAPI_PO_CHANGE to change the PO price, so can you please help me out how to use this BAPI to achieve what is required and moreover the exiting pO's may have multip;e line items with different material no's ,,,,please don't paste the sample code, please try to solve this problem using my own table and fields. I will really appreciate your efforts:
Thanks
2007 Oct 22 6:12 PM
Hi Rajeev,
No one can help you write the entire code. Check the sample code below and understand how its being used, If something is not clear we can help. But dont expect anyone to try do what you are supposed to do.
Check the sample code on BAPI_PO_CHANGE
http://www.sap-img.com/abap/sample-abap-code-on-bapi-po-change.htm
Cheers
VJ
2007 Oct 22 6:52 PM
Hey Vijayendra...thnks for the reply..but this one looks like a rude reply!!! I never asked you to write the entire code...I just said please don't put the sample code. People like me are the beginers and we need support from you guys...
Rajeev
2007 Oct 22 6:28 PM
Hi Rajeev,
I hope my code will help you in solving your problem. If you find this is helpful. <b><REMOVED BY MODERATOR></b>
Sagar
REPORT zmmisnipogr.
Description : This Custom BDC program is used to upload *
Vendor Master Data from a text file to SAP *
System. *
*
Inputs : Input File containing the required data for *
this Program. *
*
Outputs : Error File with error records as well as *
the Error. *
----
TABLES DECLARATION *
----
TABLES: lfa1,
ekko,
ekpo,
mard.
*vendor details structure
TYPES: BEGIN OF ty_lfa1,
zterm TYPE lfb1-zterm,
adrnr TYPE lfa1-adrnr,
pstlz TYPE lfa1-pstlz,
otr01 TYPE lfa1-ort01,
land1 TYPE lfa1-land1,
telf1 TYPE lfa1-telf1,
telfx TYPE lfa1-telfx,
stcd1 TYPE lfa1-stcd1,
name1 TYPE lfa1-name1,
inco1 TYPE ekpo-inco1,
txjcd TYPE ekpo-txjcd,
END OF ty_lfa1.
*po details structure
TYPES:BEGIN OF ty_ekko_ekpo,
ebeln TYPE ebeln,
bukrs TYPE bukrs,
bsart TYPE bsart,
lifnr TYPE lifnr,
ekorg TYPE ekorg,
ekgrp TYPE ekgrp,
ihrez TYPE ihrez,
ebelp TYPE ebelp,
matnr TYPE matnr,
menge TYPE menge_d,
meins TYPE meins,
netpr TYPE netpr,
knttp TYPE knttp,
ean11 TYPE ean11,
END OF ty_ekko_ekpo.
*flat file details structure
TYPES: BEGIN OF ty_rec,
doc_type TYPE bsart,
vendor TYPE lifnr,
purch_org TYPE ekorg,
po_number TYPE ebeln,
po_item TYPE ebelp,
pur_group TYPE ekgrp,
co_code TYPE bukrs,
acctasscat TYPE knttp,
material TYPE matnr,
short_text TYPE txz01,
disp_quan TYPE char13,
unit TYPE meins,
deliv_date TYPE char10,
net_price TYPE char11,
plant TYPE werks_d,
g_l_acct TYPE sakto,
cost_ctr TYPE kostl,
ean11 TYPE ean11,
ref_1 TYPE ihrez,
bwart TYPE bwart,
END OF ty_rec.
TYPES: BEGIN OF ty_mard,
matnr TYPE matnr,
lgort TYPE lgort_d,
END OF ty_mard.
TYPES: BEGIN OF ty_error,
errmsg1 TYPE string,
errmsg2 TYPE string,
END OF ty_error.
******declarations for bapi_po_create*******
DATA: it_header_cr TYPE TABLE OF bapiekkoc,
w_header_cr TYPE bapiekkoc.
DATA: it_items_cr TYPE TABLE OF bapiekpoc,
w_items_cr TYPE bapiekpoc.
DATA: it_account_cr TYPE TABLE OF bapiekkn,
w_account_cr TYPE bapiekkn.
DATA: it_schedules_cr TYPE TABLE OF bapieket,
w_schedules_cr TYPE bapieket.
DATA: it_return TYPE TABLE OF bapireturn,
w_return TYPE bapireturn.
DATA: it_add_data_cr TYPE TABLE OF bapiekkoa,
w_add_data_cr TYPE bapiekkoa.
******declarations for bapi_po_create*******
******Declarations for bapi_po_change****
*Purchase Order Header
DATA: it_poheader TYPE TABLE OF bapimepoheader,
w_poheader TYPE bapimepoheader.
DATA:it_poheaderx TYPE TABLE OF bapimepoheaderx,
w_poheaderx TYPE bapimepoheaderx.
*Purchase Order Item Data
DATA: it_poitem TYPE TABLE OF bapimepoitem,
w_poitem TYPE bapimepoitem.
DATA: it_poitemx TYPE TABLE OF bapimepoitemx,
w_poitemx TYPE bapimepoitemx.
*Purchase Order Account Assignment Fields
DATA: it_poaccount TYPE TABLE OF bapimepoaccount,
w_poaccount TYPE bapimepoaccount.
DATA: it_poaccountx TYPE TABLE OF bapimepoaccountx,
w_poaccountx TYPE bapimepoaccountx.
*Purchase Order Delivery Schedule
DATA: it_poschedule TYPE TABLE OF bapimeposchedule,
w_poschedule TYPE bapimeposchedule.
DATA: it_poschedulex TYPE TABLE OF bapimeposchedulx,
w_poschedulex TYPE bapimeposchedulx.
DATA: it_bapiret2 TYPE TABLE OF bapiret2,
w_bapiret2 TYPE bapiret2,
w_purchaseorder TYPE ebeln,
w_purchaseorder1 TYPE ebeln.
***Declarations for bapi_po_change**********
***Declarations for bapi_goodsmvt_create****
DATA: w_header_gr TYPE bapi2017_gm_head_01.
DATA: it_item_gr TYPE TABLE OF bapi2017_gm_item_create,
w_item_gr TYPE bapi2017_gm_item_create.
DATA: c_mvind(1) TYPE c VALUE 'B'.
DATA: v_matdoc TYPE bapi2017_gm_head_ret-mat_doc.
***Declarations for bapi_goodsmvt_create****
DATA: it_lfa1 TYPE TABLE OF ty_lfa1.
DATA: it_ekko_ekpo TYPE TABLE OF ty_ekko_ekpo,
w_ekko_ekpo TYPE ty_ekko_ekpo.
DATA: it_rec TYPE ty_rec OCCURS 0 WITH HEADER LINE,
w_rec TYPE ty_rec.
it_error TYPE TABLE OF ty_rec,
w_error TYPE ty_rec.
DATA : BEGIN OF it_ekpo OCCURS 0,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
END OF it_ekpo.
DATA: it_mard TYPE ty_mard OCCURS 0,
w_mard TYPE ty_mard.
DATA: it_error TYPE TABLE OF ty_error ,
w_error TYPE ty_error.
DATA : w_repid_nm LIKE sy-repid VALUE sy-repid,
w_true_fg TYPE c VALUE 'X'.
DATA: p1_file TYPE string.
DATA:v_msgstr TYPE string.
DATA : msg(2) TYPE c,
msgno(3) TYPE c.
DATA: v_item(4) TYPE n. " value 10.
***********CONSTANTS***********************
CONSTANTS : c_gmcode(2) TYPE c VALUE '01',
k_flag(1) TYPE c VALUE 'X'.
*data: w_purchaseorder type ebeln.
----
SELECTION SCREEN BLOCK *
----
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-001.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETER rb_rad1 RADIOBUTTON GROUP rept DEFAULT 'X' USER-COMMAND rad1.
SELECTION-SCREEN COMMENT 3(29) text-002 FOR FIELD rb_rad1.
PARAMETERS p_local LIKE btch0000-text80 MODIF ID sg1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETER rb_rad2 RADIOBUTTON GROUP rept .
SELECTION-SCREEN COMMENT 3(29) text-003 FOR FIELD rb_rad1.
PARAMETERS p_logic LIKE btch0000-text80 MODIF ID sg2.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b3.
----
*& AT SELECTION-SCREEN OUPUT *
----
AT SELECTION-SCREEN OUTPUT.
IF rb_rad1 = 'X'.
CLEAR p_logic.
LOOP AT SCREEN.
IF screen-group1 = 'SG2'.
screen-input = '0'.
screen-intensified = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ELSEIF rb_rad2 = 'X'.
CLEAR p_local.
LOOP AT SCREEN.
IF screen-group1 = 'SG1'.
screen-input = '0'.
screen-intensified = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
&----
*& VALUE REQUEST FOR LOCAL FILE NAME *
&----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_local.
Perform To Provide List Of Possible Values
PERFORM f4_local_filename USING p_local.
AT SELECTION-SCREEN ON p_local.
IF p_local IS NOT INITIAL.
Perform To Validate Local File
PERFORM validate_local_file.
ENDIF.
AT SELECTION-SCREEN ON p_logic.
IF p_logic IS NOT INITIAL.
Perform To Validate Logical File
PERFORM validate_logical_file .
ENDIF.
START-OF-SELECTION.
To Restrict Blank File Name
IF rb_rad1 = w_true_fg AND
p_local IS INITIAL.
MESSAGE i016(0) WITH 'Please enter file'.
STOP.
ELSEIF rb_rad2 = w_true_fg AND
p_logic IS INITIAL.
MESSAGE i016(0) WITH 'Please enter file'.
STOP.
ENDIF.
IF p_local IS NOT INITIAL.
PERFORM upload_file USING p_local.
ELSEIF p_logic IS NOT INITIAL.
PERFORM read_file USING p_logic.
ENDIF.
PERFORM select_data.
LOOP AT it_rec INTO w_rec.
READ TABLE it_ekko_ekpo INTO w_ekko_ekpo WITH KEY ebeln = w_rec-po_number
ebelp = w_rec-po_item.
IF sy-subrc = 0.
PERFORM update_po.
ELSE.
CLEAR it_ekpo.
SELECT ebeln ebelp
FROM ekpo
INTO TABLE it_ekpo
WHERE ebeln = w_rec-po_number.
READ TABLE it_ekko_ekpo INTO w_ekko_ekpo WITH KEY ebeln = w_rec-po_number.
IF sy-subrc = 0.
SORT it_ekpo BY ebeln ASCENDING ebelp DESCENDING .
READ TABLE it_ekpo INDEX 1.
IF sy-subrc = 0 AND
it_ekpo-ebelp IS NOT INITIAL.
w_rec-po_item = it_ekpo-ebelp + 10.
ELSE.
w_rec-po_item = w_rec-po_item + 10.
ENDIF.
PERFORM update_po.
CLEAR w_rec-po_item.
ELSE.
w_rec-po_item = w_rec-po_item + 10.
PERFORM create_po.
CLEAR w_rec-po_item.
ENDIF.
ENDIF.
ENDLOOP.
PERFORM download_error_file.
&----
*& Form UPDATE_PO
&----
text
----
FORM update_po.
w_purchaseorder = w_rec-po_number.
Purchase order Header
w_poheader-doc_type = w_rec-doc_type.
w_poheader-vendor = w_rec-vendor.
w_poheader-purch_org = w_rec-purch_org.
w_poheader-po_number = w_rec-po_number.
w_poheader-pur_group = w_rec-pur_group.
w_poheader-comp_code = w_rec-co_code.
w_poheader-ref_1 = w_rec-ref_1.
poheaderx
w_poheaderx-doc_type = k_flag.
w_poheaderx-vendor = k_flag.
w_poheaderx-purch_org = k_flag.
w_poheaderx-po_number = k_flag.
w_poheaderx-pur_group = k_flag.
w_poheaderx-comp_code = k_flag.
w_poheaderx-ref_1 = k_flag.
*Purchase order Item data
w_poitem-po_item = w_rec-po_item.
w_poitem-acctasscat = w_rec-acctasscat.
w_poitem-material = w_rec-material.
w_poitem-po_unit = w_rec-unit.
WRITE w_rec-net_price RIGHT-JUSTIFIED.
w_poitem-net_price = w_rec-net_price.
w_poitem-short_text = w_rec-short_text.
w_poitem-plant = w_rec-plant.
READ TABLE it_mard INTO w_mard WITH KEY matnr = w_rec-material.
IF sy-subrc = 0.
w_poitem-stge_loc = w_mard-lgort.
ENDIF.
w_poitem-int_obj_no = w_rec-ean11.
APPEND w_poitem TO it_poitem.
CLEAR w_poitem.
poitemx
w_poitemx-po_item = w_rec-po_item.
w_poitemx-po_itemx = k_flag.
w_poitemx-acctasscat = k_flag.
w_poitemx-material = k_flag.
w_poitemx-po_unit = k_flag.
w_poitemx-net_price = k_flag.
w_poitemx-short_text = k_flag.
w_poitemx-plant = k_flag.
w_poitemx-stge_loc = k_flag.
w_poitemx-int_obj_no = k_flag.
APPEND w_poitemx TO it_poitemx.
CLEAR w_poitemx.
*Purchase order account
w_poaccount-po_item = w_rec-po_item.
w_poaccount-gl_account = w_rec-g_l_acct.
w_poaccount-costcenter = w_rec-cost_ctr.
APPEND w_poaccount TO it_poaccount.
CLEAR w_poaccount.
poaccountx
w_poaccountx-po_item = w_rec-po_item.
w_poaccountx-po_itemx = k_flag.
w_poaccountx-gl_account = k_flag.
w_poaccountx-costcenter = k_flag.
APPEND w_poaccountx TO it_poaccountx.
CLEAR w_poaccountx.
*Purchase order Schedule
w_poschedule-po_item = w_rec-po_item.
w_poschedule-quantity = w_rec-disp_quan.
w_poschedule-delivery_date = w_rec-deliv_date.
APPEND w_poschedule TO it_poschedule.
CLEAR w_poschedule.
*poschedulex
w_poschedulex-po_item = w_rec-po_item.
w_poschedulex-po_itemx = k_flag.
w_poschedulex-quantity = k_flag.
w_poschedulex-delivery_date = k_flag.
APPEND w_poschedulex TO it_poschedulex.
CLEAR w_poschedulex.
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
purchaseorder = w_purchaseorder
poheader = w_poheader
poheaderx = w_poheaderx
IMPORTING
EXPHEADER =
EXPPOEXPIMPHEADER =
TABLES
return = it_bapiret2
poitem = it_poitem
poitemx = it_poitemx
poschedule = it_poschedule
poschedulex = it_poschedulex
poaccount = it_poaccount
poaccountx = it_poaccountx
.
READ TABLE it_bapiret2 INTO w_bapiret2 WITH KEY type = 'E'.
IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
PERFORM create_gr.
ELSE.
APPEND w_rec TO it_error.
CLEAR w_rec.
*
PERFORM download_error_file.
READ TABLE it_bapiret2 INTO w_bapiret2 WITH KEY type = 'E'.
IF sy-subrc = 0.
APPEND w_rec TO it_error.
CLEAR w_rec.
*
PERFORM download_error_file.
*
ENDIF.
IF sy-subrc EQ 0.
msg = w_bapiret2-code+0(2).
msgno = w_bapiret2-code+2(3).
*Function Module for Formatting the Messages
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = w_bapiret2-id
lang = '-D'
no = w_bapiret2-number "w_return-LOG_MSG_NO
v1 = w_return-MESSAGE_V1
v2 = w_return-message_v2
v3 = w_return-message_v3
v4 = w_return-message_v4
IMPORTING
msg = v_msgstr
EXCEPTIONS
not_found = 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.
Moving Error Records to Error Internal Table
w_error-errmsg1 = w_rec.
w_error-errmsg2 = v_msgstr.
APPEND w_error TO it_error.
CLEAR w_error.
ENDIF.
ENDIF.
ENDFORM. "UPDATE_PO
&----
*& Form F4_FILE
&----
text
----
-->P_P_FLTFIL text
----
*FORM F4_FILE USING P_P_FLTFIL.
FORM f4_file USING file TYPE rlgrap-filename.
Function Module to Prompt the user for File-Selection
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = file.
ENDFORM. "REQUEST_FILE
*ENDFORM. " F4_FILE
&----
*& Form UPLOAD_FILE
&----
text
----
-->P_P_FILE text
----
FORM upload_file USING p_p_local.
p1_file = p_p_local.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = p1_file
filetype = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
data_tab = it_rec[]
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17
.
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 it_rec BY po_number po_item.
ENDFORM. " UPLOAD_FILE
&----
*& Form CREATE_PO
&----
text
----
--> p1 text
<-- p2 text
----
FORM create_po .
*Po_Header
w_header_cr-doc_type = w_rec-doc_type.
w_header_cr-vendor = w_rec-vendor.
w_header_cr-purch_org = w_rec-purch_org.
w_header_cr-po_number = w_rec-po_number.
w_header_cr-pur_group = w_rec-pur_group.
w_header_cr-co_code = w_rec-co_code.
*Po_Items
w_items_cr-po_item = w_rec-po_item.
w_items_cr-acctasscat = w_rec-acctasscat.
w_items_cr-material = w_rec-material.
w_items_cr-pur_mat = w_rec-material.
w_items_cr-unit = w_rec-unit.
w_items_cr-net_price = w_rec-net_price.
w_items_cr-short_text = w_rec-short_text.
w_items_cr-plant = w_rec-plant.
READ TABLE it_mard INTO w_mard WITH KEY matnr = w_rec-material.
IF sy-subrc = 0.
w_items_cr-store_loc = w_mard-lgort.
ENDIF.
APPEND w_items_cr TO it_items_cr.
CLEAR w_items_cr.
*Po_Account_assignment
w_account_cr-po_item = w_rec-po_item.
w_account_cr-g_l_acct = w_rec-g_l_acct.
w_account_cr-cost_ctr = w_rec-cost_ctr.
APPEND w_account_cr TO it_account_cr.
CLEAR w_account_cr.
*Po_item_schedules
w_schedules_cr-po_item = w_rec-po_item.
w_schedules_cr-quantity = w_rec-disp_quan.
w_schedules_cr-deliv_date = w_rec-deliv_date.
APPEND w_schedules_cr TO it_schedules_cr.
CLEAR w_schedules_cr.
*po_add_data
w_add_data_cr-ref_1 = w_rec-ref_1.
CALL FUNCTION 'BAPI_PO_CREATE'
EXPORTING
po_header = w_header_cr
po_header_add_data = w_add_data_cr
IMPORTING
purchaseorder = w_purchaseorder1
TABLES
po_items = it_items_cr
PO_ITEM_ADD_DATA =
po_item_schedules = it_schedules_cr
po_item_account_assignment = it_account_cr
PO_ITEM_TEXT =
return = it_return
.
READ TABLE it_return INTO w_return WITH KEY type = 'E'. .
IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
WAIT UP TO 4 SECONDS.
PERFORM create_gr.
ELSE.
READ TABLE it_return INTO w_return WITH KEY type = 'E'.
IF sy-subrc = 0.
APPEND w_rec TO it_error.
CLEAR w_rec.
*
PERFORM download_error_file.
*
ENDIF.
IF sy-subrc EQ 0.
msg = w_return-code+0(2).
msgno = w_return-code+2(3).
*Function Module for Formatting the Messages
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = msg
lang = '-D'
no = msgno "w_return-LOG_MSG_NO
v1 = w_return-message_v1
v2 = w_return-message_v2
v3 = w_return-message_v3
v4 = w_return-message_v4
IMPORTING
msg = v_msgstr
EXCEPTIONS
not_found = 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.
Moving Error Records to Error Internal Table
w_error-errmsg1 = w_rec.
w_error-errmsg2 = v_msgstr.
APPEND w_error TO it_error.
CLEAR w_error.
ENDIF.
ENDIF.
ENDFORM. " CREATE_PO
&----
*& Form CREATE_GR
&----
text
----
--> p1 text
<-- p2 text
----
FORM create_gr .
IF w_purchaseorder1 IS NOT INITIAL.
w_rec-po_number = w_purchaseorder1.
ENDIF.
CLEAR w_purchaseorder1.
*Goodsmvt_Header
w_header_gr-pstng_date = sy-datum.
w_header_gr-doc_date = sy-datum.
w_header_gr-ref_doc_no = w_rec-po_number.
*Goodsmvt_item
w_item_gr-material = w_rec-material.
w_item_gr-plant = w_rec-plant.
w_item_gr-move_type = w_rec-bwart.
w_item_gr-mvt_ind = c_mvind.
w_item_gr-entry_qnt = w_rec-disp_quan.
w_item_gr-entry_uom = w_rec-unit.
w_item_gr-po_number = w_rec-po_number.
w_item_gr-po_item = w_rec-po_item.
APPEND w_item_gr TO it_item_gr.
CLEAR w_item_gr.
*Goods movement create
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = w_header_gr
goodsmvt_code = c_gmcode
IMPORTING
materialdocument = v_matdoc
TABLES
goodsmvt_item = it_item_gr
return = it_bapiret2.
READ TABLE it_bapiret2 TRANSPORTING NO FIELDS WITH KEY type = 'E'.
IF sy-subrc NE 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ELSE.
PERFORM change_lineitem.
ENDIF.
REFRESH : it_bapiret2,
it_item_gr.
CLEAR : w_header_gr,
w_item_gr.
ENDFORM. " CREATE_GR
*&----
**& Form F4_LOCAL_FILENAME
*&----
text
*----
-->P_P_LOCAL text
*----
FORM f4_local_filename USING p_local_file.
DATA: w_filetable_nm TYPE filetable,
w_rc_in TYPE i,
w_useraction_in TYPE i.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'File Selection'
CHANGING
file_table = w_filetable_nm
rc = w_rc_in
user_action = w_useraction_in
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 AND
w_rc_in GT 0.
READ TABLE w_filetable_nm INDEX w_rc_in INTO p_local_file.
ENDIF.
ENDFORM. " F4_LOCAL_FILENAME
&----
*& Form VALIDATE_LOCAL_FILE
&----
text
----
--> p1 text
<-- p2 text
----
FORM validate_local_file .
DATA : w_result_tx TYPE c,
w_file_st TYPE string.
w_file_st = p_local.
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = w_file_st
RECEIVING
result = w_result_tx
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF w_result_tx NE w_true_fg.
MESSAGE e088(/gmc/ze) WITH w_file_st.
ENDIF.
ENDFORM. " VALIDATE_LOCAL_FILE
&----
*& Form VALIDATE_LOGICAL_FILE
&----
text
----
--> p1 text
<-- p2 text
----
FORM validate_logical_file .
DATA: w_file_nm TYPE file_info-filename, "file name in path
w_dirname LIKE epsf-epsdirnam,
w_filemask LIKE epsf-epsfilnam,
w_logic LIKE btch0000-text80,
w_file LIKE btch0000-text80.
DATA: t_filelist TYPE TABLE OF epsfili,
w_filelist TYPE epsfili.
DATA :w_string_ix TYPE i,
w_index_ix TYPE i,
w_count_ix TYPE i,
w_temp_nm(1) TYPE c.
w_string_ix = STRLEN( p_logic ).
DO w_string_ix TIMES.
w_index_ix = sy-index.
w_count_ix = w_string_ix - 1.
w_temp_nm = p_logic+w_count_ix(1).
IF w_temp_nm NE '/'.
CONCATENATE w_temp_nm w_file_nm INTO w_file_nm.
ELSE.
w_dirname = p_logic+0(w_count_ix).
EXIT.
ENDIF.
w_string_ix = w_string_ix - 1.
ENDDO.
w_logic = w_dirname.
w_file = w_file_nm.
CALL FUNCTION 'PFL_CHECK_DIRECTORY'
EXPORTING
directory = w_logic
write_check = 'X'
filname = w_file
EXCEPTIONS
pfl_dir_not_exist = 1
pfl_permission_denied = 2
pfl_cant_build_dataset_name = 3
pfl_file_not_exist = 4
OTHERS = 5.
CASE sy-subrc.
WHEN 1.
MESSAGE i089(/gmc/ze) WITH w_dirname.
STOP.
WHEN 4.
MESSAGE i088(/gmc/ze) WITH w_file_nm.
ENDCASE.
ENDFORM. " VALIDATE_LOGICAL_FILE
&----
*& Form SELECT_DATA
&----
text
----
--> p1 text
<-- p2 text
----
FORM select_data .
SELECT AADRNR APSTL2
AORT01 ALAND1
ATELF1 ATELFX
ASTCD1 ANAME1
BINCO1 BTXJCD
INTO TABLE IT_LFA1
FROM LFA1 AS A
INNER JOIN EKPO AS B
ON ALIFNR = BEMLIF.
IF NOT it_rec[] IS INITIAL.
SELECT aebeln abukrs absart alifnr aekorg aekgrp a~ihrez
bebelp bmatnr bmenge bmeins bnetpr bknttp b~ean11
INTO TABLE it_ekko_ekpo
FROM ekko AS a
INNER JOIN ekpo AS b
ON aebeln = bebeln
FOR ALL ENTRIES IN it_rec
WHERE a~ebeln = it_rec-po_number.
SELECT matnr lgort
INTO TABLE it_mard
FROM mard
FOR ALL ENTRIES IN it_rec
WHERE matnr = it_rec-material.
ENDIF.
ENDFORM. " SELECT_DATA
&----
*& Form download_error_file
&----
text
----
--> p1 text
<-- p2 text
----
FORM download_error_file .
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'c:\atsmmiserror.txt'
FILETYPE = 'ASC'
IMPORTING
FILELENGTH =
TABLES
data_tab = it_error
.
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. " download_error_filex
&----
*& Form change_lineitem
&----
text
----
--> p1 text
<-- p2 text
----
FORM change_lineitem .
Purchase order Header
w_poheader-doc_type = w_rec-doc_type.
w_poheader-vendor = w_rec-vendor.
w_poheader-purch_org = w_rec-purch_org.
w_poheader-po_number = w_rec-po_number.
w_poheader-pur_group = w_rec-pur_group.
w_poheader-comp_code = w_rec-co_code.
w_poheader-ref_1 = w_rec-ref_1.
poheaderx
w_poheaderx-doc_type = k_flag.
w_poheaderx-vendor = k_flag.
w_poheaderx-purch_org = k_flag.
w_poheaderx-po_number = k_flag.
w_poheaderx-pur_group = k_flag.
w_poheaderx-comp_code = k_flag.
w_poheaderx-ref_1 = k_flag.
*Purchase order Item data
w_poitem-po_item = w_rec-po_item.
w_poitem-delete_ind = k_flag.
w_poitem-acctasscat = w_rec-acctasscat.
w_poitem-material = w_rec-material.
w_poitem-po_unit = w_rec-unit.
w_poitem-net_price = w_rec-net_price.
w_poitem-short_text = w_rec-short_text.
w_poitem-plant = w_rec-plant.
w_poitem-int_obj_no = w_rec-ean11.
APPEND w_poitem TO it_poitem.
CLEAR w_poitem.
poitemx
w_poitemx-po_item = w_rec-po_item.
w_poitemx-delete_ind = k_flag.
w_poitemx-acctasscat = k_flag.
w_poitemx-material = k_flag.
w_poitemx-po_unit = k_flag.
w_poitemx-net_price = k_flag.
w_poitemx-short_text = k_flag.
w_poitemx-plant = k_flag.
w_poitemx-int_obj_no = k_flag.
APPEND w_poitemx TO it_poitemx.
CLEAR w_poitemx.
*Purchase order account
w_poaccount-po_item = w_rec-po_item.
w_poaccount-delete_ind = k_flag.
w_poaccount-gl_account = w_rec-g_l_acct.
w_poaccount-costcenter = w_rec-cost_ctr.
APPEND w_poaccount TO it_poaccount.
CLEAR w_poaccount.
poaccountx
w_poaccountx-po_item = w_rec-po_item.
w_poaccountx-po_itemx = k_flag.
w_poaccountx-delete_ind = k_flag.
w_poaccountx-gl_account = k_flag.
w_poaccountx-costcenter = k_flag.
APPEND w_poaccountx TO it_poaccountx.
CLEAR w_poaccountx.
*Purchase order Schedule
w_poschedule-po_item = w_rec-po_item.
w_poschedule-quantity = w_rec-disp_quan.
w_poschedule-delivery_date = w_rec-deliv_date.
w_poschedule-delete_ind = k_flag.
APPEND w_poschedule TO it_poschedule.
CLEAR w_poschedule.
*poschedulex
w_poschedulex-po_item = w_rec-po_item.
w_poschedulex-po_itemx = k_flag.
w_poschedulex-quantity = k_flag.
w_poschedulex-delivery_date = k_flag.
w_poschedulex-delete_ind = k_flag.
APPEND w_poschedulex TO it_poschedulex.
CLEAR w_poschedulex.
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
purchaseorder = w_rec-po_number
poheader = w_poheader
poheaderx = w_poheaderx
IMPORTING
EXPHEADER =
EXPPOEXPIMPHEADER =
TABLES
return = it_bapiret2
poitem = it_poitem
poitemx = it_poitemx
poschedule = it_poschedule
poschedulex = it_poschedulex
poaccount = it_poaccount
poaccountx = it_poaccountx
.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDFORM. " change_lineitem
&----
*& Form read_file
&----
text
----
-->P_P_LOGIC text
----
FORM read_file USING p_p_logic.
***opening dataset for reading
OPEN DATASET p_p_logic FOR INPUT IN TEXT MODE ENCODING DEFAULT.
*open dataset p1_file for input in text mode. " encoding default message l_message.
IF sy-subrc NE 0.
MESSAGE e999(za) WITH 'Error opening file p_p_logic'.
ELSE.
*******transferring data from file to app server.
DO.
READ DATASET p_p_logic INTO it_rec.
IF sy-subrc = 0.
APPEND it_rec.
CLEAR it_rec.
ELSE.
EXIT.
ENDIF.
ENDDO.
*******closing dataset
CLOSE DATASET p_p_logic.
ENDIF.
ENDFORM. " read_file
Message was edited by:
Alvaro Tejada Galindo
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |