2007 Jul 10 4:44 PM
Hi all,
I need your help.
I want to implement the BAPI_PO_CHANGE to modify orderpurchase in the header text , and header conditions and items conditions.
Some body has an example for this, Please?
Thanks in advance
regards.
2007 Jul 10 6:11 PM
Check out this code:
REPORT ztc_mm_po_sto_input .
----
*Data Variables
----
DATA : v_input_file TYPE string ,
v_error_file TYPE string ,
v_success_file TYPE string ,
v_run_time(1) TYPE c,
v_suc_file_text TYPE ibipparms-path,
v_err_file_text TYPE ibipparms-path,
v_suc_file_text1 TYPE ibipparms-path,
v_err_file_text1 TYPE ibipparms-path,
vl_succ type i,
vl_err type i,
v_repid like sy-repid.
----
Data Declarations
----
DATA:
wl_po_header_remote TYPE bapiekkol,
wl_po_address_remote TYPE bapiaddress,
wl_poheader TYPE bapimepoheader,
wl_c_poheader TYPE bapimepoheader,
wl_poaddrvendor TYPE bapimepoaddrvendor,
wl_c_poaddrvendor TYPE bapimepoaddrvendor,
BAPI for Remote Declarations
wl_po_header_remote TYPE bapiekkol,
wl_po_address_remote TYPE bapiaddress,
il_po_header_texts_remote TYPE bapiekkotx OCCURS 0 WITH HEADER LINE,
il_po_items_remote TYPE bapiekpo OCCURS 0 WITH HEADER LINE,
il_po_item_account_remote TYPE bapiekkn OCCURS 0 WITH HEADER LINE,
il_po_item_schedules_remote TYPE bapieket OCCURS 0 WITH HEADER LINE,
il_po_item_confirma_remote TYPE bapiekes OCCURS 0
WITH HEADER LINE,
il_po_item_texts_remote TYPE bapiekpotx OCCURS 0 WITH HEADER LINE,
il_po_item_history_remote TYPE bapiekbe OCCURS 0 WITH HEADER LINE,
il_po_item_totals_remote TYPE bapiekbes OCCURS 0 WITH HEADER LINE,
il_po_item_limits_remote TYPE bapiesuh OCCURS 0 WITH HEADER LINE,
il_po_item_contracts_remote TYPE bapiesuc OCCURS 0 WITH HEADER LINE,
il_po_item_services_remote TYPE bapiesll OCCURS 0 WITH HEADER LINE,
il_po_item_srv_accass_remote TYPE bapieskl OCCURS 0 WITH HEADER LINE,
il_return_remote TYPE bapireturn OCCURS 0 WITH HEADER LINE,
il_po_services_texts_remote TYPE bapieslltx OCCURS 0 WITH HEADER LINE,
il_extensionout_remote TYPE bapiparex OCCURS 0 WITH HEADER LINE,
BAPI for Local System Declarations
wl_po_header_local TYPE bapiekkol,
wl_po_address_local TYPE bapiaddress,
il_po_header_texts_local TYPE bapiekkotx OCCURS 0 WITH HEADER LINE,
il_po_items_local TYPE bapiekpo OCCURS 0 WITH HEADER LINE,
il_po_item_account_local TYPE bapiekkn OCCURS 0 WITH HEADER LINE,
il_po_item_schedules_local TYPE bapieket OCCURS 0 WITH HEADER LINE,
il_po_item_confirma_local TYPE bapiekes OCCURS 0
WITH HEADER LINE,
il_po_item_texts_local TYPE bapiekpotx OCCURS 0 WITH HEADER LINE,
il_po_item_history_local TYPE bapiekbe OCCURS 0 WITH HEADER LINE,
il_po_item_totals_local TYPE bapiekbes OCCURS 0 WITH HEADER LINE,
il_po_item_limits_local TYPE bapiesuh OCCURS 0 WITH HEADER LINE,
il_po_item_contracts_local TYPE bapiesuc OCCURS 0 WITH HEADER LINE,
il_po_item_services_local TYPE bapiesll OCCURS 0 WITH HEADER LINE,
il_po_item_srv_accass_local TYPE bapieskl OCCURS 0 WITH HEADER LINE,
il_return_local TYPE bapireturn OCCURS 0 WITH HEADER LINE,
il_po_services_texts_local TYPE bapieslltx OCCURS 0 WITH HEADER LINE,
il_extensionout_local TYPE bapiparex OCCURS 0 WITH HEADER LINE,
BAPI Create
il_poitem TYPE bapimepoitem OCCURS 0 WITH HEADER LINE,
il_bapireturn type bapiret2 occurs 0 with header line,
il_c_poitem TYPE bapimepoitem OCCURS 0 WITH HEADER LINE,
il_poschedule TYPE bapimeposchedule OCCURS 0 WITH HEADER LINE,
il_c_poschedule TYPE bapimeposchedule OCCURS 0 WITH HEADER LINE,
il_poaccount TYPE bapimepoaccount OCCURS 0 WITH HEADER LINE,
il_c_poaccount TYPE bapimepoaccount OCCURS 0 WITH HEADER LINE,
il_potextheader TYPE bapimepotextheader OCCURS 0 WITH HEADER LINE,
il_potextitem TYPE bapimepotext OCCURS 0 WITH HEADER LINE,
il_c_potextheader TYPE bapimepotextheader OCCURS 0 WITH HEADER LINE,
il_c_potextitem TYPE bapimepotext OCCURS 0 WITH HEADER LINE,
BAPI - GET RELINFO Local system
IL_BAPIRLCOPO_LOCAL TYPE BAPIRLCOPO OCCURS 0 WITH HEADER LINE,
BAPI - GET RELINFO Remote system
IL_BAPIRLCOPO_REMOTE TYPE BAPIRLCOPO OCCURS 0 WITH HEADER LINE,
BAPI Return Messages
il_ret2_commit type BAPIRET2 OCCURS 0 WITH HEADER LINE,
il_returnreset type bapireturn occurs 0 with header line,
il_returnrel type bapireturn occurs 0 with header line,
wl_BAPIRLCOPO_LOCAL like line of IL_BAPIRLCOPO_LOCAL,
wl_BAPIRLCOPO_remote like line of IL_BAPIRLCOPO_REMOTE.
----
*Type defination
----
types: begin of t_record,
purchaseorder type EKKO-EBELN,
end of t_record,
begin of t_success,
purchaseorder type EKKO-EBELN,
messagetype(1),
message(256),
end of t_success,
begin of t_error,
purchaseorder type EKKO-EBELN,
messagetype(1),
message(256),
end of t_error,
begin of t_SUMMARY,
TEXT(30),
COUNT(5),
end of t_summary,
begin of t_change,
ebeln type ekko-ebeln,
EBELP type ekpo-ebelp,
LOEKZ type ekko-LOEKZ,
end of t_change,
begin of t_relsucc,
purchaseorder type EKKO-EBELN,
messagetype(1),
message(256),
end of t_relsucc,
begin of t_relerror,
purchaseorder type EKKO-EBELN,
messagetype(1),
message(256),
end of t_relerror.
----
*Internal Tables
----
DATA : i_record TYPE STANDARD TABLE OF t_record WITH HEADER LINE,
i_success type standard table of t_success with header line,
i_error type standard table of t_error with header line,
i_summary type standard table of t_summary with header line,
il_change type standard table of t_change with header line,
i_relsucc type standard table of t_relsucc with header line,
i_relerror type standard table of t_relsucc with header line.
----
Selection Screen
----
SELECTION-SCREEN BEGIN OF BLOCK run_time WITH FRAME TITLE text-001.
PARAMETERS : rb_fgrnd RADIOBUTTON GROUP gr1 USER-COMMAND fgrn
DEFAULT 'X' .
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 5(30) text-011.
PARAMETERS : p_infl LIKE ibipparms-path
DEFAULT 'C:\temp\PO_Conversion.txt'
LOWER CASE MODIF ID sc1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 5(30) text-013.
PARAMETERS : p_sucfl LIKE ibipparms-path
DEFAULT v_suc_file_text
DEFAULT 'C:\temp\PO_Success.txt'
LOWER CASE MODIF ID sc1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 5(30) text-012.
PARAMETERS : p_erfl LIKE ibipparms-path
DEFAULT v_err_file_text
DEFAULT 'C:\temp\PO_Error.txt'
LOWER CASE MODIF ID sc1.
SELECTION-SCREEN END OF LINE.
PARAMETERS : rb_bgrnd RADIOBUTTON GROUP gr1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 5(30) text-014.
PARAMETERS : p_binfl LIKE ibipparms-path
DEFAULT '/usr/sap/interfaces/celerra/Entity_Reorg/PO_Conversion.txt'
LOWER CASE MODIF ID sc2.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 5(30) text-016.
PARAMETERS : p_bsucfl LIKE ibipparms-path
DEFAULT v_suc_file_text1
DEFAULT '/usr/sap/interfaces/celerra/Entity_Reorg/PO_success.txt'
LOWER CASE MODIF ID sc2.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 5(30) text-015.
PARAMETERS : p_berfl LIKE ibipparms-path
DEFAULT '/usr/sap/interfaces/celerra/Entity_Reorg/PO_error.txt'
DEFAULT v_err_file_text1
LOWER CASE MODIF ID sc2.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK run_time.
SELECTION-SCREEN BEGIN OF BLOCK rfc_dest WITH FRAME TITLE text-002.
PARAMETERS: p_dest LIKE rfcdisplay-rfcdest.
SELECTION-SCREEN END OF BLOCK rfc_dest.
----
AT SELECTION-SCREEN OUTPUT *
----
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-group1 = 'SC1'.
IF rb_fgrnd = 'X'.
screen-input = '1'.
ELSE.
screen-input = '0'.
ENDIF.
ELSEIF screen-group1 = 'SC2'.
IF rb_bgrnd = 'X'.
screen-input = '1'.
ELSE.
screen-input = '0'.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
----
AT SELECTION-SCREEN ON VALUE REQUEST FOR INPUT *
----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_infl.
CALL METHOD zcler_conversion=>filename_get
CHANGING
vp_filename = p_infl.
CALL FUNCTION 'F4_FILENAME' "allows user to select path/file
EXPORTING
program_name = syst-repid
dynpro_number = syst-dynnr
field_name = 'p_infl'
IMPORTING
file_name = p_infl.
IF sy-subrc NE 0.
WRITE: / 'Error'.
ENDIF.
----
AT SELECTION-SCREEN ON VALUE REQUEST FOR ERROR *
----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_erfl.
CALL FUNCTION 'F4_FILENAME' "allows user to select path/file
EXPORTING
program_name = syst-repid
dynpro_number = syst-dynnr
field_name = 'p_erfl'
IMPORTING
file_name = p_erfl.
IF sy-subrc NE 0.
WRITE: / 'Error'.
ENDIF.
----
AT SELECTION-SCREEN ON VALUE REQUEST FOR SUCCESS *
----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_sucfl.
CALL FUNCTION 'F4_FILENAME' "allows user to select path/file
EXPORTING
program_name = syst-repid
dynpro_number = syst-dynnr
field_name = 'p_sucfl'
IMPORTING
file_name = p_sucfl.
IF sy-subrc NE 0.
WRITE: / 'Error'.
ENDIF.
----
AT SELECTION-SCREEN ON BLOCK RUNTIME *
----
AT SELECTION-SCREEN ON BLOCK run_time.
IF rb_bgrnd = 'X' OR sy-batch = 'X'.
v_run_time = 'B'.
MOVE p_binfl TO v_input_file.
MOVE p_berfl TO v_error_file.
MOVE p_bsucfl TO v_success_file.
ELSE.
v_run_time = 'F'.
MOVE p_infl TO v_input_file.
MOVE p_erfl TO v_error_file.
MOVE p_sucfl TO v_success_file.
ENDIF.
----
START-OF-SELECTION - Point after processing the selection screen. *
----
START-OF-SELECTION.
Upload File from AS or PS
PERFORM get_data.
Process Data
PERFORM process_data.
Identify Release during Delta Period
PERFORM RELEASE_DELTAPERIOD.
Download Data - Success file
*IF I_SUCCESS[] IS NOT INITIAL.
PERFORM DOWNLOAD_DATA TABLES I_SUCCESS
USING v_success_file.
ENDIF.
Download Data - error file
*IF I_ERROR[] IS NOT INITIAL.
PERFORM DOWNLOAD_DATA TABLES I_ERROR
USING v_error_file.
*
ENDIF.
Populate Sumamry Report
*PERFORM SUB_POPULATE_SUMMARY.
----
END OF SELECTION *
----
END-OF-SELECTION.
Download Data - Success file
IF I_SUCCESS[] IS NOT INITIAL.
PERFORM DOWNLOAD_DATA TABLES I_SUCCESS
USING v_success_file.
ENDIF.
Download Data - error file
IF I_ERROR[] IS NOT INITIAL.
PERFORM DOWNLOAD_DATA TABLES I_ERROR
USING v_error_file.
ENDIF.
Populate Sumamry Report
PERFORM SUB_POPULATE_SUMMARY.
Write Data
PERFORM WRITE_DATA.
----
TOP OF PAGE *
----
TOP-OF-PAGE.
PERFORM TOP-OF-PAGE.
&----
*& Form get_data
&----
Upload File from AS or PS
----
FORM get_data .
*-- UPLOAD INPUT FILE
IF sy-batch = 'X' OR v_run_time = 'B'.
*-- Background Processing
CALL FUNCTION 'Z_TXX_UNIX_UPLOAD'
EXPORTING
filename = v_input_file
TABLES
data_tab = i_record.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ELSE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_input_file
filetype = 'ASC'
TABLES
data_tab = i_record
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 e002(sy) WITH 'File Not Found or Unabe to Read File'.
ENDIF.
ENDIF.
ENDFORM. " get_data
&----
*& Form process_data
&----
Process Data
----
FORM process_data .
*loop throgh each record.
LOOP AT i_record.
Perform Conversion for PR number
perform conversion_exit using i_record-purchaseorder.
Getdetail PR from Remote System - VPR System
PERFORM POGETDETAIL_REMOTESYSTEM.
Check Remote Connection
if sy-subrc eq 0.
Check PR number exist in Remote system
if sy-subrc eq 0 and il_return_remote-type <> 'E'.
Getdetails PR from Local System - -VPP System
PERFORM POGETDETAIL_LOCALSYSTEM.
*check wether it exists locally in VPP.
if sy-subrc eq 0 and il_return_local-type <> 'E'.
*PO exits in local system, Changes Occured in the Local System
CLEAR:wl_poheader.
**Mapping Feilds PO_HEADER -> POHEADER
MOVE-CORRESPONDING wl_po_header_remote TO wl_c_poheader.
MOVE: "i_record-purchaseorder TO wl_poheader-po_number,
"sy-langu TO wl_poheader-po_number.
SELECT SINGLE bukrs
FROM ztps_newcc_plant
INTO wl_c_poheader-comp_code
WHERE werks = il_po_items_remote-plant.
**Mapping Feilds PO_ADDRESS -> POADDRVENDOR.
*wl_po_address wl_poaddrvendor
**************************************************
clear : wl_c_poaddrvendor.
***************************************************
MOVE-CORRESPONDING wl_po_address_remote TO wl_c_poaddrvendor.
MOVE :
i_record-purchaseorder TO wl_c_poaddrvendor-po_number,
wl_po_address_remote-addrnumber TO wl_c_poaddrvendor-addr_no,
wl_po_address_remote-name1 TO wl_c_poaddrvendor-name,
wl_po_address_remote-city1 TO wl_c_poaddrvendor-city,
wl_po_address_remote-post_code1 TO wl_c_poaddrvendor-postl_cod1,
wl_po_address_remote-roomnumber TO wl_c_poaddrvendor-room_no,
wl_po_address_remote-tel_number TO wl_c_poaddrvendor-tel1_numbr,
wl_po_address_remote-tel_extens TO wl_c_poaddrvendor-tel1_ext.
**Mapping Feilds PO_HEADER_TEXTS -> POTEXTHEADER
MOVE-CORRESPONDING il_po_header_texts_remote TO il_c_potextheader.
**Mapping Feilds PO_ITEMS -> POITEM
CLEAR: il_po_items_remote.
LOOP AT il_po_items_remote.
**Mapping Feilds PO_ITEMS -> PO_ITEMS
MOVE-CORRESPONDING il_po_items_remote TO il_c_poitem.
MOVE: il_po_items_remote-store_loc TO il_c_poitem-stge_loc,
il_po_items_remote-mat_grp TO il_c_poitem-matl_group,
il_po_items_remote-unit TO il_c_poitem-po_unit,
il_po_items_remote-overdeltol TO il_c_poitem-over_dlv_tol,
il_po_items_remote-unlimited TO il_c_poitem-unlimited_dlv,
il_po_items_remote-under_tol TO il_c_poitem-under_dlv_tol,
il_po_items_remote-tax_jur_cd TO il_c_poitem-taxjurcode.
APPEND il_c_poitem.
CLEAR:il_po_items_remote,il_c_poitem.
ENDLOOP.
**Mapping Feilds PO_ITEM_ACCOUNT_ASSIGNMENT -> POACCOUNT
CLEAR:il_po_item_account_remote.
LOOP AT il_po_item_account_remote.
MOVE-CORRESPONDING il_po_item_account_remote TO il_c_poaccount.
MOVE:
il_po_item_account_remote-g_l_acct TO
il_c_poaccount-gl_account,
il_po_item_account_remote-wbs_elem_e TO
il_c_poaccount-wbs_element,
il_po_item_account_remote-cost_ctr TO
il_c_poaccount-costcenter.
APPEND il_c_poaccount.
CLEAR:il_po_item_account_remote,il_c_poaccount.
ENDLOOP.
**Mapping Feilds PO_ITEM_SCHEDULES -> POSCHEDULE
CLEAR: il_po_item_schedules_remote.
LOOP AT il_po_item_schedules_remote.
MOVE-CORRESPONDING il_po_item_schedules_remote TO il_c_poschedule.
MOVE: il_po_item_schedules_remote-serial_no TO
il_c_poschedule-sched_line,
il_po_item_schedules_remote-deliv_date TO
il_c_poschedule-delivery_date.
APPEND il_c_poschedule.
CLEAR:il_po_item_schedules_remote,il_c_poschedule.
ENDLOOP.
**Mapping Feilds PO_ITEM_TEXTS -> POTEXTITEM
il_po_item_texts_remote[] = il_c_potextitem[].
Call BAPI Purchase Order Change
perform purchaseorder_change.
*Read BAPI Return & Commit Bapi
perform transaction_commit.
Perform clear & refresh
PERFORM CLEAR_DATA.
Create PO
*PO does not exits in local system,so get details and create new one.
ELSE.
CLEAR:wl_poheader.
**Mapping Feilds PO_HEADER -> POHEADER
MOVE-CORRESPONDING wl_po_header_remote TO wl_poheader.
MOVE: "i_record-purchaseorder TO wl_poheader-po_number,
sy-langu TO wl_poheader-po_number.
SELECT SINGLE bukrs
FROM ztps_newcc_plant
INTO wl_poheader-comp_code
WHERE werks = il_po_items_remote-plant.
*********************************************************
clear : wl_poaddrvendor.
************************************************************
**Mapping Feilds PO_ADDRESS -> POADDRVENDOR.
*wl_po_address wl_poaddrvendor
MOVE-CORRESPONDING wl_po_address_remote TO wl_poaddrvendor.
MOVE :i_record-purchaseorder TO wl_poaddrvendor-po_number,
wl_po_address_remote-addrnumber TO wl_poaddrvendor-addr_no,
wl_po_address_remote-name1 TO wl_poaddrvendor-name,
wl_po_address_remote-city1 TO wl_poaddrvendor-city,
wl_po_address_remote-post_code1 TO
wl_poaddrvendor-postl_cod1,
wl_po_address_remote-roomnumber TO wl_poaddrvendor-room_no,
wl_po_address_remote-tel_number TO
wl_poaddrvendor-tel1_numbr,
wl_po_address_remote-tel_extens TO wl_poaddrvendor-tel1_ext.
**Mapping Feilds PO_HEADER_TEXTS -> POTEXTHEADER
MOVE-CORRESPONDING il_po_header_texts_remote TO il_potextheader.
**Mapping Feilds PO_ITEMS -> POITEM
CLEAR: il_po_items_remote.
LOOP AT il_po_items_remote.
**Mapping Feilds PO_ITEMS -> PO_ITEMS
MOVE-CORRESPONDING il_po_items_remote TO il_poitem.
MOVE: il_po_items_remote-store_loc TO il_poitem-stge_loc,
il_po_items_remote-mat_grp TO il_poitem-matl_group,
il_po_items_remote-unit TO il_poitem-po_unit,
il_po_items_remote-overdeltol TO il_poitem-over_dlv_tol,
il_po_items_remote-unlimited TO il_poitem-unlimited_dlv,
il_po_items_remote-under_tol TO il_poitem-under_dlv_tol,
il_po_items_remote-tax_jur_cd TO il_poitem-taxjurcode.
APPEND il_poitem.
CLEAR:il_po_items_remote,il_poitem.
ENDLOOP.
**Mapping Feilds PO_ITEM_ACCOUNT_ASSIGNMENT -> POACCOUNT
CLEAR:il_po_item_account_remote.
LOOP AT il_po_item_account_remote.
MOVE-CORRESPONDING il_po_item_account_remote TO il_poaccount.
MOVE:
il_po_item_account_remote-g_l_acct TO il_poaccount-gl_account,
il_po_item_account_remote-wbs_elem_e TO il_poaccount-wbs_element,
il_po_item_account_remote-cost_ctr TO il_poaccount-costcenter.
APPEND il_poaccount.
CLEAR:il_po_item_account_remote,il_poaccount.
ENDLOOP.
**Mapping Feilds PO_ITEM_SCHEDULES -> POSCHEDULE
CLEAR: il_po_item_schedules_remote.
LOOP AT il_po_item_schedules_remote.
MOVE-CORRESPONDING il_po_item_schedules_remote TO il_poschedule.
MOVE:
il_po_item_schedules_remote-serial_no TO
il_poschedule-sched_line,
il_po_item_schedules_remote-deliv_date TO
il_poschedule-delivery_date.
APPEND il_poschedule.
CLEAR:il_po_item_schedules_remote,il_poschedule.
ENDLOOP.
**Mapping Feilds PO_ITEM_TEXTS -> POTEXTITEM
il_po_item_texts_remote[] = il_potextitem[].
BAPI - Create Purchase Order
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = wl_poheader
POHEADERX =
poaddrvendor = wl_poaddrvendor
TABLES
RETURN = il_bapireturn
poitem = il_poitem
poschedule = il_poschedule
POSCHEDULEX =
poaccount = il_poaccount
potextheader = il_potextheader
potextitem = il_potextitem.
*Read BAPI Return & Commit Bapi
perform transaction_commit.
*************************
Check for Deletion Indicator
Getdetails PO from Local System - -VPP System
perform pogetdetail_localsystem.
To check whether PO number Exist in Local System
if sy-subrc eq 0 and il_return_local-type <> 'E'.
PR Changes occured in Local System
Remote System - for Deletion Indicator
loop at il_po_items_remote.
if il_po_items_remote-DELETE_IND = 'L'.
move :
il_po_items_remote-PO_ITEM to il_c_poitem-PO_ITEM.
il_c_poitem-DELETE_IND = 'L'.
append il_c_poitem.
clear il_c_poitem.
move : il_po_items_remote-PO_NUMBER to il_change-ebeln,
il_po_items_remote-PO_ITEM to il_change-EBELP,
il_po_items_remote-DELETE_IND to il_change-LOEKZ.
append il_change.
clear il_change.
ENDIF.
endloop.
Check to call PO Change
if not il_change[] is initial.
Call BAPI Purchase Order Change
perform purchaseorder_change.
*Read BAPI Return & Commit Bapi
perform transaction_commit.
endif.
endif.
Perform clear & refresh
PERFORM CLEAR_DATA.
endif.
******************************
ELSE.
If not exist in Remote system, Populate error
vl_err = vl_err + 1.
I_ERROR-purchaseorder = I_RECORD-purchaseorder.
i_error-messagetype = il_return_remote-TYPE.
I_ERROR-MESSAGE = il_return_remote-message.
append i_error.
clear i_error.
ENDIF.
*****************************
else.
Populate RFC Connection Disconnected
write : / 'RFC Connection Disconnected or Wrong Path'.
skip.
stop.
endif.
clear : i_record.
endloop.
ENDFORM. " process_data
&----
*& Form RELEASE_DELTAPERIOD
&----
Release made during Delta Period
----
form RELEASE_DELTAPERIOD .
Check release status for Each PO in Local System
LOOP AT I_RECORD.
Perform Conversion Routine
perform conversion_exit using i_record-purchaseorder.
Getdetail PO from Remote System - VPR System
PERFORM POGETDETAIL_REMOTESYSTEM.
Check Remote Connection
if sy-subrc eq 0.
Check PR number exist in Remote system
if sy-subrc eq 0 and il_return_remote-type <> 'E'.
Getdetails PR from Local System - -VPP System
PERFORM POGETDETAIL_LOCALSYSTEM.
To check whether PR number Exist in Local System
IF SY-SUBRC EQ 0 AND IL_RETURN_LOCAL IS INITIAL.
if sy-subrc eq 0 and il_return_local-type <> 'E'.
*************************
Call BAPI PO GETREL Information Locally - VPP
CALL FUNCTION 'BAPI_PO_GETRELINFO'
EXPORTING
PURCHASEORDER = I_RECORD-purchaseorder
IMPORTING
RELEASE_ALREADY_POSTED = IL_BAPIRLCOPO_LOCAL[].
Calling BAPI PO GETREL Information Remotly - VPR
CALL FUNCTION 'BAPI_PO_GETRELINFO' destination p_dest
EXPORTING
PURCHASEORDER = I_RECORD-purchaseorder
IMPORTING
RELEASE_ALREADY_POSTED = IL_BAPIRLCOPO_REMOTE[]
exceptions
system_failure = 1
communication_failure = 2.
CLEAR : IL_BAPIRLCOPO_LOCAL,IL_BAPIRLCOPO_REMOTE.
******************************
Check Release codes 1 to 8 in Local & Remote System
if not IL_BAPIRLCOPO_LOCAL is initial
or il_BAPIRLCOPO_REMOTE is initial.
Comparing & Updating Release codes
perform validate_rel_code.
endif.
endif.
endif.
clear : wl_BAPIRLCOPO_LOCAL ,wl_BAPIRLCOPO_remote.
refresh : IL_BAPIRLCOPO_REMOTE, IL_BAPIRLCOPO_local.
Perform Clear & Refresh Data
PERFORM CLEAR_DATA.
CLEAR : I_RECORD.
******
ELSE.
If not exist in Remote system, Populate error
vl_err = vl_err + 1.
I_ERROR-purchaseorder = I_RECORD-purchaseorder.
i_error-messagetype = il_return_remote-TYPE.
I_ERROR-MESSAGE = il_return_remote-message.
append i_error.
clear i_error.
*
*************
ENDIF.
else.
Populate RFC Connection Disconnected
write : / 'RFC Connection Disconnected or Wrong Path'.
skip.
stop.
endif.
ENDLOOP.
endform. " RELEASE_DELTAPERIOD
&----
*& Form CONVERSION_EXIT
&----
PR Number
----
form conversion_exit using p_data.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = p_data
IMPORTING
output = p_data.
endform. " CONVERSION_EXIT
&----
*& Form PRGETDETAIL_REMOTESYSTEM
&----
Call BAPI Get detail from Remote System - VPR
----
form POGETDETAIL_REMOTESYSTEM .
Call BAPI Get detail from Remote System - VPR
CALL FUNCTION 'BAPI_PO_GETDETAIL' DESTINATION p_dest
EXPORTING
purchaseorder = i_record-purchaseorder
items = 'X'
account_assignment = 'X'
schedules = 'X'
history = 'X'
item_texts = 'X'
header_texts = 'X'
services = 'X'
confirmations = 'X'
service_texts = 'X'
extensions = 'X'
IMPORTING
po_header = wl_po_header_remote
po_address = wl_po_address_remote
TABLES
po_header_texts = il_po_header_texts_remote
po_items = il_po_items_remote
po_item_account_assignment = il_po_item_account_remote
po_item_schedules = il_po_item_schedules_remote
po_item_confirmations = il_po_item_confirma_remote
po_item_texts = il_po_item_texts_remote
po_item_history = il_po_item_history_remote
po_item_history_totals = il_po_item_totals_remote
po_item_limits = il_po_item_limits_remote
po_item_contract_limits = il_po_item_contracts_remote
po_item_services = il_po_item_services_remote
po_item_srv_accass_values = il_po_item_srv_accass_remote
return = il_return_remote
po_services_texts = il_po_services_texts_remote
extensionout = il_extensionout_remote
exceptions
system_failure = 1
communication_failure = 2.
*
IF SY-SUBRC <> 0.
WRITE : / 'Populate Error'.
STOP.
ENDIF.
endform. " POGETDETAIL_REMOTESYSTEM
&----
*& Form POGETDETAIL_LOCALSYSTEM
&----
*
----
FORM POGETDETAIL_LOCALSYSTEM .
CALL FUNCTION 'BAPI_PO_GETDETAIL'
EXPORTING
purchaseorder = i_record-purchaseorder
items = 'X'
account_assignment = 'X'
schedules = 'X'
history = 'X'
item_texts = 'X'
header_texts = 'X'
services = 'X'
confirmations = 'X'
service_texts = 'X'
extensions = 'X'
IMPORTING
po_header = wl_po_header_local
po_address = wl_po_address_local
TABLES
po_header_texts = il_po_header_texts_local
po_items = il_po_items_local
po_item_account_assignment = il_po_item_account_local
po_item_schedules = il_po_item_schedules_local
po_item_confirmations = il_po_item_confirma_local
po_item_texts = il_po_item_texts_local
po_item_history = il_po_item_history_local
po_item_history_totals = il_po_item_totals_local
po_item_limits = il_po_item_limits_local
po_item_contract_limits = il_po_item_contracts_local
po_item_services = il_po_item_services_local
po_item_srv_accass_values = il_po_item_srv_accass_local
return = il_return_local
po_services_texts = il_po_services_texts_local
extensionout = il_extensionout_local.
ENDFORM. " POGETDETAIL_LOCALSYSTEM
&----
*& Form validate_rel_code
&----
Validate Release Codes
----
FORM validate_rel_code .
loop at IL_BAPIRLCOPO_LOCAL into wl_BAPIRLCOPO_LOCAL.
read table IL_BAPIRLCOPO_REMOTE into wl_BAPIRLCOPO_REMOTE
with key PO_NUMBER = wl_BAPIRLCOPO_LOCAL-PO_NUMBER.
endloop.
loop at IL_BAPIRLCOPO_REMOTE into wl_BAPIRLCOPO_REMOTE.
read table IL_BAPIRLCOPO_LOCAL into wl_BAPIRLCOPO_LOCAL
with key PO_NUMBER = wl_BAPIRLCOPO_REMOTE-PO_NUMBER.
endloop.
Check Release codes 1 to 8 in Local & Remote System
IF wL_BAPIRLCOPO_LOCAL-REL_CODE1 <> ' '
or wL_BAPIRLCOPO_REMOTE-REL_CODE1 <> ' '.
Release Code 1
IF wL_BAPIRLCOPO_REMOTE-REL_CODE1 <> wL_BAPIRLCOPO_LOCAL-REL_CODE1.
*****************************************
IF wL_BAPIRLCOPO_LOCAL-REL_CODE1 <> ' '
AND wL_BAPIRLCOPO_REMOTE-REL_CODE1 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
wL_BAPIRLCOPO_LOCAL-REL_CODE1.
ELSE.
ELSE.
wL_BAPIRLCOPO_LOCAL-REL_CODE1 = wL_BAPIRLCOPO_REMOTE-REL_CODE1.
Update Release Indicator in Local System - VPP
PERFORM RELEASE_UPDATE_LOCALSYSTEM USING
wL_BAPIRLCOPO_REMOTE-REL_CODE1.
ELSE.
IF IL_BAPIRLCORQ_LOCAL-REL_CODE1 <> ' '.
IF IL_BAPIRLCORQ_REMOTE-REL_CODE1 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
IL_BAPIRLCORQ_REMOTE-REL_CODE1.
ENDIF.
ENDIF.
Check release code 2 in local & remote system
IF wL_BAPIRLCOPO_LOCAL-REL_CODE2 <> ' '
or wL_BAPIRLCOPO_REMOTE-REL_CODE2 <> ' '.
Release Code 2
IF wL_BAPIRLCOPO_REMOTE-REL_CODE2 <> wL_BAPIRLCOPO_LOCAL-REL_CODE2.
IF wL_BAPIRLCOPO_LOCAL-REL_CODE2 <> ' '
AND wL_BAPIRLCOPO_REMOTE-REL_CODE2 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
wL_BAPIRLCOPO_LOCAL-REL_CODE2.
ELSE.
wL_BAPIRLCOPO_LOCAL-REL_CODE2 = wL_BAPIRLCOPO_REMOTE-REL_CODE2.
Update Release Indicator in Local System - VPP
PERFORM RELEASE_UPDATE_LOCALSYSTEM USING
wL_BAPIRLCOPO_REMOTE-REL_CODE2.
ENDIF.
ENDIF.
Check release code 3 in local & remote system
IF wL_BAPIRLCOPO_LOCAL-REL_CODE3 <> ' '
or wL_BAPIRLCOPO_REMOTE-REL_CODE3 <> ' '.
Release Code 3
IF wL_BAPIRLCOPO_REMOTE-REL_CODE3 <> wL_BAPIRLCOPO_LOCAL-REL_CODE3.
IF wL_BAPIRLCOPO_LOCAL-REL_CODE3 <> ' '
AND wL_BAPIRLCOPO_REMOTE-REL_CODE3 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
wL_BAPIRLCOPO_LOCAL-REL_CODE3.
ELSE.
wL_BAPIRLCOPO_LOCAL-REL_CODE3 = wL_BAPIRLCOPO_REMOTE-REL_CODE3.
Update Release Indicator in Local System - VPP
PERFORM RELEASE_UPDATE_LOCALSYSTEM USING
wL_BAPIRLCOPO_REMOTE-REL_CODE3.
ENDIF.
ENDIF.
Check release code 4 in local & remote system
IF wL_BAPIRLCOPO_LOCAL-REL_CODE4 <> ' '
or wL_BAPIRLCOPO_REMOTE-REL_CODE4 <> ' '.
Release Code 4
IF wL_BAPIRLCOPO_REMOTE-REL_CODE4 <> wL_BAPIRLCOPO_LOCAL-REL_CODE4.
IF wL_BAPIRLCOPO_LOCAL-REL_CODE4 <> ' '
AND wL_BAPIRLCOPO_REMOTE-REL_CODE4 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
wL_BAPIRLCOPO_LOCAL-REL_CODE4.
ELSE.
wL_BAPIRLCOPO_LOCAL-REL_CODE4 = wL_BAPIRLCOPO_REMOTE-REL_CODE4.
Update Release Indicator in Local System - VPP
PERFORM RELEASE_UPDATE_LOCALSYSTEM USING
wL_BAPIRLCOPO_REMOTE-REL_CODE4.
ENDIF.
ENDIF.
Check release code 5 in local & remote system
IF wL_BAPIRLCOPO_LOCAL-REL_CODE5 <> ' '
or wL_BAPIRLCOPO_REMOTE-REL_CODE5 <> ' '.
Release Code 5
IF wL_BAPIRLCOPO_REMOTE-REL_CODE5 <> wL_BAPIRLCOPO_LOCAL-REL_CODE5.
IF wL_BAPIRLCOPO_LOCAL-REL_CODE5 <> ' '
AND wL_BAPIRLCOPO_REMOTE-REL_CODE5 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
wL_BAPIRLCOPO_LOCAL-REL_CODE5.
ELSE.
wL_BAPIRLCOPO_LOCAL-REL_CODE5 = wL_BAPIRLCOPO_REMOTE-REL_CODE5.
Update Release Indicator in Local System - VPP
PERFORM RELEASE_UPDATE_LOCALSYSTEM USING
wL_BAPIRLCOPO_REMOTE-REL_CODE5.
ENDIF.
ENDIF.
Check release code 6 in local & remote system
IF wL_BAPIRLCOPO_LOCAL-REL_CODE6 <> ' '
or wL_BAPIRLCOPO_REMOTE-REL_CODE6 <> ' '.
Release Code 6
IF wL_BAPIRLCOPO_REMOTE-REL_CODE6 <> wL_BAPIRLCOPO_LOCAL-REL_CODE6.
IF wL_BAPIRLCOPO_LOCAL-REL_CODE6 <> ' '
AND wL_BAPIRLCOPO_REMOTE-REL_CODE6 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
wL_BAPIRLCOPO_LOCAL-REL_CODE6.
ELSE.
wL_BAPIRLCOPO_LOCAL-REL_CODE6 = wL_BAPIRLCOPO_REMOTE-REL_CODE6.
Update Release Indicator in Local System - VPP
PERFORM RELEASE_UPDATE_LOCALSYSTEM USING
wL_BAPIRLCOPO_REMOTE-REL_CODE6.
ENDIF.
ENDIF.
Check release code 7 in local & remote system
IF wL_BAPIRLCOPO_LOCAL-REL_CODE7 <> ' '
or wL_BAPIRLCOPO_REMOTE-REL_CODE7 <> ' '.
Release Code 7
IF wL_BAPIRLCOPO_REMOTE-REL_CODE7 <> wL_BAPIRLCOPO_LOCAL-REL_CODE7.
IF wL_BAPIRLCOPO_LOCAL-REL_CODE7 <> ' '
AND wL_BAPIRLCOPO_REMOTE-REL_CODE7 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
wL_BAPIRLCOPO_LOCAL-REL_CODE7.
ELSE.
wL_BAPIRLCOPO_LOCAL-REL_CODE7 = wL_BAPIRLCOPO_REMOTE-REL_CODE7.
Update Release Indicator in Local System - VPP
PERFORM RELEASE_UPDATE_LOCALSYSTEM USING
wL_BAPIRLCOPO_REMOTE-REL_CODE7.
ENDIF.
ENDIF.
Check release code 8 in local & remote system
IF wL_BAPIRLCOPO_LOCAL-REL_CODE8 <> ' '
or wL_BAPIRLCOPO_REMOTE-REL_CODE8 <> ' '.
Release Code 8
IF wL_BAPIRLCOPO_REMOTE-REL_CODE8 <> wL_BAPIRLCOPO_LOCAL-REL_CODE8.
IF wL_BAPIRLCOPO_LOCAL-REL_CODE8 <> ' '
AND wL_BAPIRLCOPO_REMOTE-REL_CODE8 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
wL_BAPIRLCOPO_LOCAL-REL_CODE8.
ELSE.
wL_BAPIRLCOPO_LOCAL-REL_CODE8 = wL_BAPIRLCOPO_REMOTE-REL_CODE8.
Update Release Indicator in Local System - VPP
PERFORM RELEASE_UPDATE_LOCALSYSTEM USING
wL_BAPIRLCOPO_REMOTE-REL_CODE8.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " validate_rel_code
&----
*& Form RELEASE_UPDATE_LOCALSYSTEM
&----
Update Release Indicator
----
FORM RELEASE_UPDATE_LOCALSYSTEM USING P_DATA.
Update Release Indicator in Local System - VPP
CALL FUNCTION 'BAPI_PO_RELEASE'
EXPORTING
PURCHASEORDER = i_record-purchaseorder
PO_REL_CODE = P_DATA
TABLES
RETURN = IL_RETURNREL
EXCEPTIONS
AUTHORITY_CHECK_FAIL = 1
DOCUMENT_NOT_FOUND = 2
ENQUEUE_FAIL = 3
PREREQUISITE_FAIL = 4
RELEASE_ALREADY_POSTED = 5
RESPONSIBILITY_FAIL = 6
OTHERS = 7 .
Check Release Status
IF SY-SUBRC = 0 AND il_returnrel-TYPE NE 'E'.
vl_succ = vl_succ + 1.
i_relsucc-purchaseorder = I_RECORD-purchaseorder.
IF NOT il_returnrel[] IS INITIAL.
i_relsucc-messagetype = il_returnrel-type.
i_relsucc-MESSAGE = IL_RETURNREL-message.
ELSE.
i_relsucc-messagetype = 'S'.
i_relsucc-message = 'PR RELEASED SUCCESFULLY'.
ENDIF.
append i_relsucc.
clear i_relsucc.
ELSE.
vl_err = vl_err + 1.
i_relerror-purchaseorder = I_RECORD-purchaseorder.
i_relerror-messagetype = il_returnrel-type.
i_relerror-MESSAGE = IL_RETURNREL-message.
append i_relerror.
clear i_relerror.
endif.
clear : il_returnrel.
refresh : il_returnrel.
ENDFORM. " RELEASE_UPDATE_LOCALSYSTEM
&----
*& Form RELEASE_RESET_LOCALSYSTEM
&----
Reset Release Indicator
*----
FORM RELEASE_RESET_LOCALSYSTEM USING P_DATA.
Reset Release Indicator in local System - VPP comparing with VPR
CALL FUNCTION 'BAPI_PO_RESET_RELEASE'
EXPORTING
PURCHASEORDER = i_record-purchaseorder
PO_REL_CODE = P_DATA
TABLES
RETURN = IL_RETURNRESET
EXCEPTIONS
AUTHORITY_CHECK_FAIL = 1
DOCUMENT_NOT_FOUND = 2
ENQUEUE_FAIL = 3
PREREQUISITE_FAIL = 4
RELEASE_ALREADY_POSTED = 5
RESPONSIBILITY_FAIL = 6
NO_RELEASE_ALREADY = 7
NO_NEW_RELEASE_INDICATOR = 8
OTHERS = 9 .
Check Reset Status
IF NOT IL_RETURNRESET[] IS INITIAL.
IF SY-SUBRC = 0 AND il_returnreset-TYPE NE 'E'.
vl_succ = vl_succ + 1.
i_relsucc-purchaseorder = I_RECORD-purchaseorder.
IF NOT IL_BAPIRETURN[] IS INITIAL.
i_relsucc-messagetype = IL_RETURNRESET-type.
i_relsucc-MESSAGE = IL_RETURNRESET-message.
ELSE.
i_relsucc-messagetype = 'S'.
i_relsucc-message = 'PO RESET SUCCESFULLY'.
ENDIF.
append i_relsucc.
clear i_relsucc.
ELSE.
vl_err = vl_err + 1.
i_relerror-purchaseorder = I_RECORD-purchaseorder.
i_relerror-messagetype = IL_RETURNRESET-type.
i_relerror-MESSAGE = IL_RETURNRESET-message.
append i_relerror.
clear i_relerror.
endif.
ELSE.
vl_err = vl_err + 1.
I_ERROR-purchaseorder = I_RECORD-purchaseorder.
i_error-messagetype = IL_RETURNRESET-type.
I_ERROR-MESSAGE = IL_RETURNRESET-message.
append i_error.
clear i_error.
ENDIF.
clear : il_returnreset.
refresh : il_returnreset.
ENDFORM. " RELEASE_RESET_LOCALSYSTEM
&----
*& Form DOWNLOAD_DATA
&----
Download file
----
FORM DOWNLOAD_DATA TABLES IL_SUCCESS STRUCTURE I_SUCCESS
USING P_FILE.
*-- Download file
if sy-batch = 'X' or v_run_time = 'B'.
*-- Background Processing
call function 'Z_TXX_UNIX_DOWNLOAD'
EXPORTING
filename = P_FILE
TABLES
data_tab = IL_SUCCESS.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
else.
call function 'GUI_DOWNLOAD'
EXPORTING
filename = P_FILE
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = IL_SUCCESS
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 e002(sy) with 'File Not Found or Unabe to Read File'.
endif.
endif.
ENDFORM. " DOWNLOAD_DATA
&----
*& Form SUB_POPULATE_SUMMARY
&----
Sumamry Report
----
FORM SUB_POPULATE_SUMMARY .
I_SUMMARY-TEXT = 'Total NO of Records from file'.
DESCRIBE TABLE I_RECORD LINES I_SUMMARY-COUNT.
APPEND I_SUMMARY.
CLEAR I_SUMMARY.
I_SUMMARY-TEXT = 'Total NO of Success Records'.
DESCRIBE TABLE I_SUCCESS LINES I_SUMMARY-COUNT.
APPEND I_SUMMARY.
CLEAR I_SUMMARY.
I_SUMMARY-TEXT = 'Total No of Error Records'.
DESCRIBE TABLE I_ERROR LINES I_SUMMARY-COUNT.
APPEND I_SUMMARY.
CLEAR I_SUMMARY.
ENDFORM. " SUB_POPULATE_SUMMARY
&----
*& Form WRITE_DATA
&----
Write Output
----
FORM WRITE_DATA .
Populate Summary Report
PERFORM SUMMARY.
WRITE : /5 'SUMMARY REPORT' , 45 'TOTAL RECORDS'.
SKIP.
IF NOT I_SUMMARY[] IS INITIAL.
LOOP AT I_SUMMARY.
WRITE : /5 I_SUMMARY-TEXT , ' : ', 45 I_SUMMARY-COUNT.
CLEAR I_SUMMARY.
ENDLOOP.
REFRESH I_SUMMARY.
ELSE.
WRITE : / 'No Purchase Orders Found'.
ENDIF.
*Populate Success Report
PERFORM SUCCESS.
WRITE : /5 'PO NUMBER' , 30 'MESSAGE TYPE' , 50 'SUCCESS MESSAGE'.
SKIP.
IF NOT I_SUCCESS[] IS INITIAL.
LOOP AT I_SUCCESS.
WRITE : /5 I_SUCCESS-purchaseorder , 30 I_SUCCESS-messagetype ,
50 I_SUCCESS-MESSAGE.
CLEAR I_SUCCESS.
ENDLOOP.
REFRESH I_SUCCESS.
ELSE.
WRITE : /15 'No Success Records Found'.
ENDIF.
*Populate Error Report
PERFORM ERROR.
WRITE : /5 'PO NUMBER' , 30 'MESSAGE TYPE' , 50 'ERROR MESSAGE'.
SKIP.
IF NOT I_ERROR[] IS INITIAL.
LOOP AT I_ERROR.
WRITE : /5 I_ERROR-purchaseorder , 30 I_ERROR-messagetype ,
50 I_ERROR-MESSAGE.
CLEAR I_ERROR.
ENDLOOP.
REFRESH I_ERROR.
ELSE.
WRITE : /15 'No Error Records Found'.
*Populate RELEASE/RESET Success Report
perform relsucc.
write : /5 'PO NUMBER' , 30 'MESSAGE TYPE' , 50 'SUCCESS MESSAGE'.
skip.
if not i_relsucc[] is initial.
*delete adjacent duplicates from i_error.
loop at i_relsucc.
write : /5 i_relsucc-purchaseorder , 30 i_relsucc-messagetype ,
50 i_relsucc-message.
clear i_relsucc.
endloop.
refresh i_relsucc.
else.
write : /15 'No RELSUCC Records Found'.
endif.
*Populate RELEASE/RESET Error Report
perform relerror.
write : /5 'PO NUMBER' , 30 'MESSAGE TYPE' , 50 'ERROR MESSAGE'.
skip.
if not i_relerror[] is initial.
*delete adjacent duplicates from i_error.
loop at i_error.
write : /5 i_relerror-purchaseorder , 30 i_relerror-messagetype ,
50 i_relerror-message.
clear i_relerror.
endloop.
refresh i_relerror.
else.
write : /15 'No RELERROR Records Found'.
endif.
ENDIF.
ENDFORM. " WRITE_DATA
*----
FORM SUCCESS
*----
Title for Success report
*----
FORM SUCCESS.
FORMAT COLOR COL_HEADING.
WRITE: AT /(170) 'Success Report' CENTERED.
FORMAT RESET.
ENDFORM.
*----
FORM ERROR
*----
Title for Error report
*----
FORM ERROR.
FORMAT COLOR COL_HEADING.
WRITE: AT /(170) 'Error Report' CENTERED.
FORMAT RESET.
ENDFORM.
*----
FORM SUMMARY
*----
Title for Summary report
*----
FORM SUMMARY.
FORMAT COLOR COL_HEADING.
WRITE: AT /(170) 'Summary Report' CENTERED.
FORMAT RESET.
ENDFORM.
*----
FORM RELSUCCESS
*----
Title for RELSUCC report
*----
form relsucc.
format color col_heading.
write: at /(170) 'RELSUCC Report' centered.
format reset.
endform.
*----
FORM ERROR
*----
Title for RELERROR report
*----
form relerror.
format color col_heading.
write: at /(170) 'RELERROR Report' centered.
format reset.
endform.
&----
*& Form TOP-OF-PAGE
&----
TOP OF PAGE
----
FORM TOP-OF-PAGE .
DATA: LEN TYPE I, POS TYPE I.
DATA : VL_TITLE(100).
LEN = 23.
FORMAT COLOR COL_HEADING ON.
COMPUTE LEN = STRLEN( SY-UNAME ).
ULINE.
WRITE: AT /(010)
'User:' LEFT-JUSTIFIED,SPACE.
WRITE: AT 011(LEN) SY-UNAME RIGHT-JUSTIFIED NO-GAP.
LEN = 43.
WRITE: AT 40(LEN) 'T-MOBILE' CENTERED.
LEN = SY-LINSZ - 30.
WRITE: AT LEN(010) 'Run Date:'.
LEN = SY-LINSZ - 19.
WRITE: AT LEN(010) SY-DATUM MM/DD/YYYY LEFT-JUSTIFIED,SPACE.
LEN = SY-LINSZ - 07.
WRITE AT LEN(008) SY-UZEIT USING EDIT MASK '__:__:__' LEFT-JUSTIFIED.
COMPUTE LEN = STRLEN( SY-REPID ).
WRITE:
/(010) 'Program:' LEFT-JUSTIFIED,SPACE.
WRITE AT 011(LEN) SY-REPID RIGHT-JUSTIFIED NO-GAP.
VL_TITLE = SY-TITLE.
COMPUTE LEN = STRLEN( VL_TITLE ).
POS = ( SY-LINSZ - LEN ) / 2.
WRITE AT POS(LEN) VL_TITLE CENTERED.
LEN = SY-LINSZ - 27.
WRITE: AT LEN(010) 'Page No:'(097) LEFT-JUSTIFIED,SPACE.
LEN = SY-LINSZ - 8.
WRITE: AT LEN(010) SY-PAGNO RIGHT-JUSTIFIED NO-GAP.
ULINE.
FORMAT COLOR COL_HEADING OFF.
ENDFORM. " TOP-OF-PAGE
&----
*& Form CLEAR_DATA
&----
Clear & Refresh Data
----
FORM CLEAR_DATA .
clear : il_po_header_texts_remote,il_po_items_remote ,
il_po_item_account_remote,il_po_item_schedules_remote,
il_po_item_confirma_remote,il_po_item_texts_remote,
il_po_item_history_remote,il_po_item_totals_remote,
il_po_item_limits_remote,il_po_item_contracts_remote,
il_po_item_services_remote,il_po_item_srv_accass_remote,
il_return_remote,il_po_services_texts_remote,il_returnrel,
il_extensionout_remote,il_po_header_texts_local,il_po_items_local,
il_po_item_account_local,il_po_item_schedules_local,
il_po_item_confirma_local,il_po_item_texts_local,
il_po_item_history_local,il_po_item_totals_local,
il_po_item_limits_local,il_po_item_contracts_local,
il_po_item_services_local,il_po_item_srv_accass_local,
il_return_local,il_po_services_texts_local,il_returnreset,
il_extensionout_local,il_poitem,il_bapireturn,il_c_poitem,
il_poschedule,il_c_poschedule,il_poaccount,il_c_poaccount,
il_potextheader,il_potextitem,il_c_potextheader,il_c_potextitem,
IL_BAPIRLCOPO_LOCAL,IL_BAPIRLCOPO_remote,il_ret2_commit.
REFRESH : il_po_header_texts_remote,il_po_items_remote ,
il_po_item_account_remote,il_po_item_schedules_remote,
il_po_item_confirma_remote,il_po_item_texts_remote,
il_po_item_history_remote,il_po_item_totals_remote,
il_po_item_limits_remote,il_po_item_contracts_remote,
il_po_item_services_remote,il_po_item_srv_accass_remote,
il_return_remote,il_po_services_texts_remote,il_returnrel,
il_extensionout_remote,il_po_header_texts_local,il_po_items_local,
il_po_item_account_local,il_po_item_schedules_local,
il_po_item_confirma_local,il_po_item_texts_local,
il_po_item_history_local,il_po_item_totals_local,
il_po_item_limits_local,il_po_item_contracts_local,
il_po_item_services_local,il_po_item_srv_accass_local,
il_return_local,il_po_services_texts_local,il_returnreset,
il_extensionout_local,il_poitem,il_bapireturn,il_c_poitem,
il_poschedule,il_c_poschedule,il_poaccount,il_c_poaccount,
il_potextheader,il_potextitem,il_c_potextheader,il_c_potextitem,
IL_BAPIRLCOPO_LOCAL,IL_BAPIRLCOPO_remote,il_ret2_commit.
ENDFORM. " CLEAR_DATA
&----
*& Form purchaseorder_change
&----
Pruchase Order Change
----
form purchaseorder_change .
BAPI to call PO Change
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
purchaseorder = i_record-purchaseorder
poheader = wl_c_poheader
poheaderx =
poaddrvendor = wl_c_poaddrvendor
TABLES
return = il_bapireturn
poitem = il_c_poitem
poitemx =
poaddrdelivery =
poschedule = il_c_poschedule
poschedulex =
poaccount = il_c_poaccount
potextheader = il_c_potextheader
potextitem = il_c_potextitem.
endform. " purchaseorder_change
&----
*& Form transaction_commit
&----
BAPI Transaction Commit
----
form transaction_commit .
*Read BAPI Return & Commit Bapi
IF NOT IL_BAPIRETURN[] IS INITIAL.
READ TABLE IL_BAPIRETURN WITH KEY TYPE = 'E' BINARY SEARCH.
IF SY-SUBRC NE 0.
call function 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
RETURN = il_ret2_commit.
Check Commit
if not IL_RET2_COMMIT[] is initial.
READ TABLE IL_RET2_COMMIT WITH KEY TYPE = 'E' BINARY SEARCH.
IF SY-SUBRC NE 0.
IF SY-SUBRC = 0 AND il_ret2_commit-TYPE NE 'E'.
vl_succ = vl_succ + 1.
I_success-purchaseorder = I_RECORD-purchaseorder.
IF NOT IL_BAPIRETURN[] IS INITIAL.
i_success-messagetype = il_bapireturn-TYPE.
I_success-MESSAGE = 'PR changed sucessfully'.
I_success-MESSAGE = il_bapireturn-MESSAGE.
ELSE.
i_success-messagetype = 'S'.
i_success-message = 'PO CREATED/CHANGED SUCCESFULLY'.
ENDIF.
append i_success.
clear i_success.
endif.
ELSE.
vl_err = vl_err + 1.
I_ERROR-purchaseorder = I_RECORD-purchaseorder.
i_ERROR-messagetype = il_ret2_commit-TYPE.
I_ERROR-MESSAGE = 'PR not changed'.
i_error-message = il_ret2_commit-MESSAGE.
append i_error.
clear i_error.
endif.
ELSE.
vl_err = vl_err + 1.
I_ERROR-purchaseorder = I_RECORD-purchaseorder.
i_error-messagetype = il_bapireturn-TYPE.
I_ERROR-MESSAGE = il_bapireturn-message.
append i_error.
clear i_error.
ENDIF.
endform. " transaction_commit
Hi all,
I need your help.
I want to implement the BAPI_PO_CHANGE to modify orderpurchase in the header text , and header conditions and items conditions.
Some body has an example for this, Please?
Thanks in advance
regards.
2007 Jul 10 4:59 PM
Check with below program :
REPORT ZMMR_DELETEPO NO STANDARD PAGE HEADING MESSAGE-ID zisb.
tables : zvtls_sap.
*C-- Types Declarations
TYPES : BEGIN OF tp_flatfile_vtls,
ebeln(10),
ebelp type ekpo-ebelp,
END OF tp_flatfile_vtls.
*=====================================================================
INTERNAL TABLES DECLARATION
*=====================================================================
DATA: t_flatfile_vtls TYPE tp_flatfile_vtls OCCURS 0 WITH HEADER LINE.
data : begin of t_sapdata occurs 0,
po like zvtls_sap-posap,
item like zvtls_sap-itemsap,
end of t_sapdata.
data : begin of t_flatfile_vtls1 occurs 0,
po(10),
item like zvtls_sap-itemsap,
end of t_flatfile_vtls1.
data : begin of t_update occurs 0,
mandt like zvtls_sap-mandt,
povtls like zvtls_sap-povtls,
itemvtls like zvtls_sap-itemvtls,
posap like zvtls_sap-posap,
itemsap like zvtls_sap-itemsap,
aedat like zvtls_sap-aedat,
paedt like zvtls_sap-paedt,
loekz like zvtls_sap-loekz,
end of t_update.
data : begin of t_poheader occurs 0,
po like zvtls_sap-posap,
end of t_poheader.
data : begin of t_poitem occurs 0,
po like zvtls_sap-posap,
item like zvtls_sap-itemsap,
end of t_poitem.
DATA : BEGIN OF T_MESSAGE OCCURS 0,
MSGTY,
MSGID(2),
MSGNO(3),
MSGTX(100),
PO like zvtls_sap-povtls,
item like zvtls_sap-itemvtls,
END OF T_MESSAGE.
DATA : BEGIN OF t_bapi_poheader OCCURS 0.
INCLUDE STRUCTURE bapimepoheader.
DATA : END OF t_bapi_poheader.
DATA : BEGIN OF t_bapi_poheaderx OCCURS 0.
INCLUDE STRUCTURE bapimepoheaderx.
DATA : END OF t_bapi_poheaderx.
DATA : BEGIN OF t_bapi_poitem OCCURS 0.
INCLUDE STRUCTURE bapimepoitem.
DATA : END OF t_bapi_poitem.
DATA : BEGIN OF t_bapi_poitemx OCCURS 0.
INCLUDE STRUCTURE bapimepoitemx.
DATA : END OF t_bapi_poitemx.
DATA : BEGIN OF t_bapireturn OCCURS 0.
INCLUDE STRUCTURE bapiret2.
DATA : END OF t_bapireturn.
*=====================================================================
V A R I A B L E S
*=====================================================================
DATA: w_success(6) TYPE n,
w_bklas like t023-bklas,
w_curryear(4),
w_begda like sy-datum,
w_endda like sy-datum,
w_begyr(4),
w_endyr(4),
w_currmon(2),
w_assetclass like ankt-anlkl,
w_price type p,
w_recordsap type i,
w_povtls(10),
w_count type i.
DATA: w_filepath TYPE rlgrap-filename,
w_rc TYPE sy-subrc,
w_sscrfields_ucomm1 TYPE sscrfields-ucomm,
w_file1 TYPE string,
w_file2 TYPE FILENAME-FILEINTERN.
*=====================================================================
C O N S T A N T S
*=====================================================================
CONSTANTS: c_x TYPE c VALUE 'X',
c_hyp TYPE c VALUE '-',
c_err TYPE bdc_mart VALUE 'E'.
CONSTANTS: c_slash(1) TYPE c VALUE '/',
c_hash(1) TYPE c VALUE '#',
c_pipe TYPE c VALUE '|',
c_1 TYPE i VALUE 1,
c_zero TYPE n VALUE '0',
c_rg1(3) TYPE c VALUE 'rg1',
c_gr3(3) TYPE c VALUE 'GR3',
c_gr2(3) TYPE c VALUE 'GR2',
c_e(1) TYPE c VALUE 'E',
c_filepath(8) TYPE c VALUE '/interf/',
c_filetype(10) TYPE c VALUE 'ASC'.
CONSTANTS : c_bapimepoheaderx TYPE x030l-tabname
VALUE 'bapimepoheaderx',
c_bapimepoitem TYPE x030l-tabname
VALUE 'bapimepoitem',
c_bapimepoaccount TYPE x030l-tabname
VALUE 'bapimepoaccount',
c_t_bapi_poheader(15) TYPE c
VALUE 't_bapi_poheader',
c_t_bapi_poitem(13) TYPE c
VALUE 't_bapi_poitem',
c_t_bapi_poitemx(14) TYPE c
VALUE 't_bapi_poitemx',
c_t_bapi_poheaderx(16) TYPE c
VALUE 't_bapi_poheaderx'.
CLASS cl_abap_char_utilities DEFINITION LOAD.
CONSTANTS:con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
*======================================================================
SELECTION SCREEN
*======================================================================
SELECTION-SCREEN BEGIN OF BLOCK inputpath WITH FRAME TITLE text-001.
SELECTION-SCREEN : BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.
PARAMETERS : p_fore RADIOBUTTON GROUP rg1
USER-COMMAND pc,
p_back RADIOBUTTON GROUP rg1 DEFAULT 'X'.
SELECTION-SCREEN : END OF BLOCK blk2.
SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-003.
PARAMETERS : p_file1 LIKE rlgrap-filename OBLIGATORY MODIF ID gr2.
PARAMETERS : p_afile1 LIKE rlgrap-filename OBLIGATORY MODIF ID gr3.
SELECTION-SCREEN : END OF BLOCK blk1.
SELECTION-SCREEN END OF BLOCK inputpath.
*C-- Initialization Event
INITIALIZATION.
CLEAR w_filepath.
CONCATENATE c_filepath sy-sysid c_slash sy-mandt c_slash INTO
w_filepath.
CONDENSE w_filepath NO-GAPS.
p_file1 = text-008.
p_afile1 = text-009.
*======================================================================
SELECTION SCREEN EVENTS
*======================================================================
*C-- Selection Screen Output
AT SELECTION-SCREEN OUTPUT.
IF p_fore = c_x.
w_sscrfields_ucomm1 = space.
ELSE.
w_sscrfields_ucomm1 = c_rg1.
ENDIF.
LOOP AT SCREEN.
*C--Modify selection screen if presentation
*C--or application server radio button is chosen
IF w_sscrfields_ucomm1 = space.
IF screen-group1 = c_gr3.
screen-active = c_zero.
ENDIF.
ELSE.
IF screen-group1 = c_gr2.
screen-active = c_zero.
ENDIF.
ENDIF.
if screen-name = 'P_AFILE1'.
screen-input = 0.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
*C-- Selection Screen VALUE-REQUEST FOR File path
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1.
IF p_fore EQ c_x.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = p_file1.
ENDIF.
*C-- At Start of the Selection Process
START-OF-SELECTION.
IF p_fore EQ c_x.
w_file1 = p_file1.
ELSE.
w_file2 = p_afile1.
ENDIF.
IF p_fore EQ c_x. " Presentaion Server
*C--Validations for the input files
PERFORM validate_pre_file USING p_file1.
*C-- Load the contents of the input file into the internal table
PERFORM upload_file TABLES t_flatfile_vtls
USING w_file1
CHANGING w_rc.
IF w_rc <> 0.
MESSAGE s006 DISPLAY LIKE c_e.
ENDIF.
ELSE. " Application Server
*C--Validations for the input files
PERFORM validate_app_file USING w_file2.
*C-- Load the contents of the input file into the internal table
PERFORM upload_file_app TABLES t_flatfile_vtls
USING w_file2
CHANGING w_rc.
ENDIF.
loop at t_flatfile_vtls.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = t_flatfile_vtls-ebeln
IMPORTING
output = t_flatfile_vtls1-po.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = t_flatfile_vtls-ebelp
IMPORTING
output = t_flatfile_vtls1-item.
append t_flatfile_vtls1.
clear t_flatfile_vtls1.
endloop.
perform get_podata.
loop at t_poheader.
perform move_to_bapi.
perform call_bapi.
endloop.
PERFORM STORE_MESSAGES TABLES T_MESSAGE.
*&----
*
*& Form validate_pre_file
*&----
*
Routine to validate presentation server file path.
*----
*
-->fp_name text
*----
*
FORM validate_pre_file USING fp_name TYPE rlgrap-filename.
DATA : l_result,
l_filename TYPE string.
l_filename = fp_name.
CLEAR l_result.
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = l_filename
RECEIVING
result = l_result
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE s007 DISPLAY LIKE c_e.
LEAVE LIST-PROCESSING.
ELSEIF l_result IS INITIAL.
MESSAGE s008 DISPLAY LIKE c_e.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " validate_pre_file_hdr
*&----
*
*& Form validate_app_file
*&----
*
text - Checks if the path entered and filename is correct
*----
*
FORM validate_app_file USING fp_file TYPE FILENAME-FILEINTERN.
data : l_fname(60).
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
LOGICAL_FILENAME = FP_FILE
OPERATING_SYSTEM = SY-OPSYS
IMPORTING
FILE_NAME = L_FNAME
EXCEPTIONS
FILE_NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC = '0'.
OPEN DATASET L_FNAME FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
MESSAGE s007 DISPLAY LIKE c_e.
ELSE.
CLOSE DATASET l_fname.
ENDIF.
ENDIF.
ENDFORM. " validate_app_file
*&----
*
*& Form upload_file
*&----
*
Routine to upload data from file to tables.
*----
*
-->P_fp_flatfile
-->P_fp_file
<--P_fp_rc
*----
*
FORM upload_file TABLES fp_flatfile
USING fp_file TYPE string
CHANGING fp_rc TYPE sy-subrc.
IF fp_flatfile[] IS INITIAL.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = fp_file
filetype = c_filetype
has_field_separator = c_x
TABLES
data_tab = fp_flatfile
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.
MOVE sy-subrc TO fp_rc.
ENDIF.
ENDFORM. " upload_file
&----
*& Form upload_file_app
&----
text
----
-->FP_FLATFILEtext
-->FP_FILE text
-->FP_RC text
----
FORM upload_file_app TABLES fp_flatfile
USING fp_file TYPE FILENAME-FILEINTERN
CHANGING fp_rc TYPE sy-subrc.
DATA: l_string TYPE tedata-data.
DATA: wa_data_file TYPE tp_flatfile_vtls,
l_wllength TYPE i,
FNAME(60).
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
LOGICAL_FILENAME = FP_FILE
OPERATING_SYSTEM = SY-OPSYS
IMPORTING
FILE_NAME = FNAME
EXCEPTIONS
FILE_NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC = 0.
OPEN DATASET FNAME FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
*C-- commented by Bikash
MESSAGE s107(yaero_ps) DISPLAY LIKE c_e.
message e008.
ELSE.
DO.
CLEAR: l_string.
READ DATASET FNAME INTO l_string LENGTH l_wllength.
IF sy-subrc NE 0.
EXIT.
ELSE.
SPLIT l_string AT con_tab INTO wa_data_file-ebeln
wa_data_file-ebelp.
APPEND wa_data_file TO fp_flatfile.
ENDIF.
ENDDO.
CLOSE DATASET FNAME.
ENDIF.
ENDIF.
ENDFORM. " upload_file_app
&----
*& Form get_podata
&----
text
----
form get_podata.
select *
into table t_update
from zvtls_sap
for all entries in t_flatfile_vtls1
where itemvtls = t_flatfile_vtls1-item
and povtls = t_flatfile_vtls1-po.
sort t_update by posap itemsap.
loop at t_update.
at new posap.
t_poheader-po = t_update-posap.
append t_poheader.
clear t_poheader.
endat.
t_poitem-po = t_update-posap.
t_poitem-item = t_update-itemsap.
append t_poitem.
clear t_poitem.
t_update-paedt = sy-datum.
t_update-loekz = 'X'.
modify t_update.
endloop.
modify zvtls_sap from table t_update.
endform. "get_podata
&----
*& Form move_to_bapi
&----
text
----
form move_to_bapi.
t_bapi_poheader-po_number = t_poheader-po.
CLEAR t_bapi_poheaderx.
PERFORM fill_check_structure USING c_bapimepoheaderx
c_t_bapi_poheader
c_t_bapi_poheaderx
c_x.
refresh : t_bapi_poitem,t_bapi_poitemx.
loop at t_poitem where po = t_poheader-po.
clear t_bapi_poitem.
t_bapi_poitem-po_item = t_poitem-item.
t_bapi_poitem-delete_ind = 'X'.
CLEAR t_bapi_poitemx.
PERFORM fill_check_structure USING c_bapimepoitem
c_t_bapi_poitem
c_t_bapi_poitemx
c_x.
t_bapi_poitemx-po_item = t_poitem-item.
t_bapi_poitemx-po_itemx = c_x.
APPEND t_bapi_poitem.
APPEND t_bapi_poitemx.
clear t_bapi_poitem.
clear t_bapi_poitemx.
endloop.
endform. "move_to_bapi
*&----
*
*& Form call_bapi
*&----
*
This form Routine is used to commit the data records
----
FORM call_bapi .
DATA : l_msgty TYPE c,
l_msgid(2) TYPE c,
l_msgno(3) TYPE c,
l_msgtx(100) TYPE c,
l_errflag TYPE c.
CLEAR: t_bapireturn.
REFRESH: t_bapireturn.
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
PURCHASEORDER = T_POHEADER-PO
POHEADER = T_BAPI_POHEADER
POHEADERX = T_BAPI_POHEADERX
TABLES
RETURN = T_BAPIRETURN
POITEM = T_BAPI_POITEM
POITEMX = T_BAPI_POITEMX.
READ TABLE t_bapireturn WITH KEY type = c_err TRANSPORTING NO FIELDS.
IF sy-subrc NE 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = c_x.
ENDIF.
*C-- Write messages
WRITE: / 'PO Number', t_poheader-po.
clear : t_update,w_povtls.
read table t_update with key posap = t_poheader-po.
w_povtls = t_update-povtls.
CLEAR l_errflag.
LOOP AT t_bapireturn.
CLEAR: l_msgty, l_msgid, l_msgno, l_msgtx.
l_msgty = t_bapireturn-type.
l_msgid = t_bapireturn-id.
l_msgno = t_bapireturn-number.
l_msgtx = t_bapireturn-message.
WRITE: / l_msgty, l_msgid, l_msgno, l_msgtx.
if l_msgtx cs t_poheader-po.
w_count = w_count + 1.
loop at t_update.
if sy-tabix = w_count.
t_message-item = t_update-itemvtls.
endif.
endloop.
endif.
t_message-msgty = l_msgty.
t_message-msgid = l_msgid.
t_message-msgno = l_msgno.
t_message-msgtx = l_msgtx.
t_message-po = w_povtls.
append t_message.
clear t_message.
IF l_msgty EQ c_err.
l_errflag = c_x.
ENDIF. " l_msgty EQ 'E'
ENDLOOP.
ULINE.
IF l_errflag NE c_x.
w_success = w_success + 1.
ENDIF. " l_errflag NE C_X
endform. "call_bapi
*&----
*
*& Form fill_check_structure
*&----
*
This form Routine will check whether the specified structure
exist/active
*----
*
FORM fill_check_structure USING fp_tabname TYPE any
fp_orgtabname TYPE any
fp_chktabname TYPE any
fp_check TYPE c.
FIELD-SYMBOLS : <fs_chk>, <fs_org>.
DATA: l_char1(61) TYPE c,
l_char2(61) TYPE c.
DATA: BEGIN OF tl_nametab OCCURS 60.
INCLUDE STRUCTURE x031l.
DATA: END OF tl_nametab.
REFRESH tl_nametab.
CALL FUNCTION 'RFC_GET_NAMETAB'
EXPORTING
tabname = fp_tabname
TABLES
nametab = tl_nametab
EXCEPTIONS
table_not_active = 1
OTHERS = 2.
IF sy-subrc <> 0.
CLEAR tl_nametab.
ENDIF.
LOOP AT tl_nametab.
CLEAR: l_char1, l_char2.
CONCATENATE fp_chktabname c_hyp tl_nametab-fieldname INTO l_char1.
ASSIGN (l_char1) TO <fs_chk>.
CONCATENATE fp_orgtabname c_hyp tl_nametab-fieldname INTO l_char2.
ASSIGN (l_char2) TO <fs_org>.
IF <fs_org> IS NOT INITIAL.
<fs_chk> = fp_check.
ENDIF.
ENDLOOP.
ENDFORM. " fill_check_structure
&----
*& Form STORE_MESSAGES
&----
text
----
-->FP_MESSAGEStext
----
FORM STORE_MESSAGES TABLES FP_MESSAGES STRUCTURE T_MESSAGE.
DATA: wl_output_data LIKE t_MESSAGE.
DATA: l_catstr TYPE string.
DATA: l_fieldvalue TYPE string.
DATA: l_index TYPE i VALUE 1.
DATA: L_FNAME(60).
FIELD-SYMBOLS <fs>.
CLEAR l_catstr.
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
LOGICAL_FILENAME = '/USR/SAP/VTLS/POCHANGE/LOG'
OPERATING_SYSTEM = SY-OPSYS
IMPORTING
FILE_NAME = L_FNAME
EXCEPTIONS
FILE_NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC = '0'.
IF fp_messages[] IS NOT INITIAL.
OPEN DATASET L_FNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
LEAVE LIST-PROCESSING.
ELSE.
LOOP AT fp_messages INTO wl_output_data.
DO.
ASSIGN COMPONENT l_index OF STRUCTURE wl_output_data TO <fs>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
MOVE <fs> TO l_fieldvalue.
IF l_catstr IS NOT INITIAL.
CONCATENATE l_catstr l_fieldvalue INTO l_catstr SEPARATED
BY con_tab.
ELSE.
MOVE l_fieldvalue TO l_catstr.
ENDIF.
l_index = l_index + c_1.
CLEAR l_fieldvalue.
CLEAR <fs>.
ENDDO.
l_index = c_1.
TRANSFER l_catstr TO L_FNAME .
CLEAR wl_output_data.
CLEAR l_catstr.
ENDLOOP.
CLOSE DATASET L_FNAME.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. "STORE_MESSAGES
For header text -> pass the values to BAPIMEPOTEXTHEADER
Thanks
Seshu
2007 Jul 10 6:11 PM
Check out this code:
REPORT ztc_mm_po_sto_input .
----
*Data Variables
----
DATA : v_input_file TYPE string ,
v_error_file TYPE string ,
v_success_file TYPE string ,
v_run_time(1) TYPE c,
v_suc_file_text TYPE ibipparms-path,
v_err_file_text TYPE ibipparms-path,
v_suc_file_text1 TYPE ibipparms-path,
v_err_file_text1 TYPE ibipparms-path,
vl_succ type i,
vl_err type i,
v_repid like sy-repid.
----
Data Declarations
----
DATA:
wl_po_header_remote TYPE bapiekkol,
wl_po_address_remote TYPE bapiaddress,
wl_poheader TYPE bapimepoheader,
wl_c_poheader TYPE bapimepoheader,
wl_poaddrvendor TYPE bapimepoaddrvendor,
wl_c_poaddrvendor TYPE bapimepoaddrvendor,
BAPI for Remote Declarations
wl_po_header_remote TYPE bapiekkol,
wl_po_address_remote TYPE bapiaddress,
il_po_header_texts_remote TYPE bapiekkotx OCCURS 0 WITH HEADER LINE,
il_po_items_remote TYPE bapiekpo OCCURS 0 WITH HEADER LINE,
il_po_item_account_remote TYPE bapiekkn OCCURS 0 WITH HEADER LINE,
il_po_item_schedules_remote TYPE bapieket OCCURS 0 WITH HEADER LINE,
il_po_item_confirma_remote TYPE bapiekes OCCURS 0
WITH HEADER LINE,
il_po_item_texts_remote TYPE bapiekpotx OCCURS 0 WITH HEADER LINE,
il_po_item_history_remote TYPE bapiekbe OCCURS 0 WITH HEADER LINE,
il_po_item_totals_remote TYPE bapiekbes OCCURS 0 WITH HEADER LINE,
il_po_item_limits_remote TYPE bapiesuh OCCURS 0 WITH HEADER LINE,
il_po_item_contracts_remote TYPE bapiesuc OCCURS 0 WITH HEADER LINE,
il_po_item_services_remote TYPE bapiesll OCCURS 0 WITH HEADER LINE,
il_po_item_srv_accass_remote TYPE bapieskl OCCURS 0 WITH HEADER LINE,
il_return_remote TYPE bapireturn OCCURS 0 WITH HEADER LINE,
il_po_services_texts_remote TYPE bapieslltx OCCURS 0 WITH HEADER LINE,
il_extensionout_remote TYPE bapiparex OCCURS 0 WITH HEADER LINE,
BAPI for Local System Declarations
wl_po_header_local TYPE bapiekkol,
wl_po_address_local TYPE bapiaddress,
il_po_header_texts_local TYPE bapiekkotx OCCURS 0 WITH HEADER LINE,
il_po_items_local TYPE bapiekpo OCCURS 0 WITH HEADER LINE,
il_po_item_account_local TYPE bapiekkn OCCURS 0 WITH HEADER LINE,
il_po_item_schedules_local TYPE bapieket OCCURS 0 WITH HEADER LINE,
il_po_item_confirma_local TYPE bapiekes OCCURS 0
WITH HEADER LINE,
il_po_item_texts_local TYPE bapiekpotx OCCURS 0 WITH HEADER LINE,
il_po_item_history_local TYPE bapiekbe OCCURS 0 WITH HEADER LINE,
il_po_item_totals_local TYPE bapiekbes OCCURS 0 WITH HEADER LINE,
il_po_item_limits_local TYPE bapiesuh OCCURS 0 WITH HEADER LINE,
il_po_item_contracts_local TYPE bapiesuc OCCURS 0 WITH HEADER LINE,
il_po_item_services_local TYPE bapiesll OCCURS 0 WITH HEADER LINE,
il_po_item_srv_accass_local TYPE bapieskl OCCURS 0 WITH HEADER LINE,
il_return_local TYPE bapireturn OCCURS 0 WITH HEADER LINE,
il_po_services_texts_local TYPE bapieslltx OCCURS 0 WITH HEADER LINE,
il_extensionout_local TYPE bapiparex OCCURS 0 WITH HEADER LINE,
BAPI Create
il_poitem TYPE bapimepoitem OCCURS 0 WITH HEADER LINE,
il_bapireturn type bapiret2 occurs 0 with header line,
il_c_poitem TYPE bapimepoitem OCCURS 0 WITH HEADER LINE,
il_poschedule TYPE bapimeposchedule OCCURS 0 WITH HEADER LINE,
il_c_poschedule TYPE bapimeposchedule OCCURS 0 WITH HEADER LINE,
il_poaccount TYPE bapimepoaccount OCCURS 0 WITH HEADER LINE,
il_c_poaccount TYPE bapimepoaccount OCCURS 0 WITH HEADER LINE,
il_potextheader TYPE bapimepotextheader OCCURS 0 WITH HEADER LINE,
il_potextitem TYPE bapimepotext OCCURS 0 WITH HEADER LINE,
il_c_potextheader TYPE bapimepotextheader OCCURS 0 WITH HEADER LINE,
il_c_potextitem TYPE bapimepotext OCCURS 0 WITH HEADER LINE,
BAPI - GET RELINFO Local system
IL_BAPIRLCOPO_LOCAL TYPE BAPIRLCOPO OCCURS 0 WITH HEADER LINE,
BAPI - GET RELINFO Remote system
IL_BAPIRLCOPO_REMOTE TYPE BAPIRLCOPO OCCURS 0 WITH HEADER LINE,
BAPI Return Messages
il_ret2_commit type BAPIRET2 OCCURS 0 WITH HEADER LINE,
il_returnreset type bapireturn occurs 0 with header line,
il_returnrel type bapireturn occurs 0 with header line,
wl_BAPIRLCOPO_LOCAL like line of IL_BAPIRLCOPO_LOCAL,
wl_BAPIRLCOPO_remote like line of IL_BAPIRLCOPO_REMOTE.
----
*Type defination
----
types: begin of t_record,
purchaseorder type EKKO-EBELN,
end of t_record,
begin of t_success,
purchaseorder type EKKO-EBELN,
messagetype(1),
message(256),
end of t_success,
begin of t_error,
purchaseorder type EKKO-EBELN,
messagetype(1),
message(256),
end of t_error,
begin of t_SUMMARY,
TEXT(30),
COUNT(5),
end of t_summary,
begin of t_change,
ebeln type ekko-ebeln,
EBELP type ekpo-ebelp,
LOEKZ type ekko-LOEKZ,
end of t_change,
begin of t_relsucc,
purchaseorder type EKKO-EBELN,
messagetype(1),
message(256),
end of t_relsucc,
begin of t_relerror,
purchaseorder type EKKO-EBELN,
messagetype(1),
message(256),
end of t_relerror.
----
*Internal Tables
----
DATA : i_record TYPE STANDARD TABLE OF t_record WITH HEADER LINE,
i_success type standard table of t_success with header line,
i_error type standard table of t_error with header line,
i_summary type standard table of t_summary with header line,
il_change type standard table of t_change with header line,
i_relsucc type standard table of t_relsucc with header line,
i_relerror type standard table of t_relsucc with header line.
----
Selection Screen
----
SELECTION-SCREEN BEGIN OF BLOCK run_time WITH FRAME TITLE text-001.
PARAMETERS : rb_fgrnd RADIOBUTTON GROUP gr1 USER-COMMAND fgrn
DEFAULT 'X' .
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 5(30) text-011.
PARAMETERS : p_infl LIKE ibipparms-path
DEFAULT 'C:\temp\PO_Conversion.txt'
LOWER CASE MODIF ID sc1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 5(30) text-013.
PARAMETERS : p_sucfl LIKE ibipparms-path
DEFAULT v_suc_file_text
DEFAULT 'C:\temp\PO_Success.txt'
LOWER CASE MODIF ID sc1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 5(30) text-012.
PARAMETERS : p_erfl LIKE ibipparms-path
DEFAULT v_err_file_text
DEFAULT 'C:\temp\PO_Error.txt'
LOWER CASE MODIF ID sc1.
SELECTION-SCREEN END OF LINE.
PARAMETERS : rb_bgrnd RADIOBUTTON GROUP gr1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 5(30) text-014.
PARAMETERS : p_binfl LIKE ibipparms-path
DEFAULT '/usr/sap/interfaces/celerra/Entity_Reorg/PO_Conversion.txt'
LOWER CASE MODIF ID sc2.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 5(30) text-016.
PARAMETERS : p_bsucfl LIKE ibipparms-path
DEFAULT v_suc_file_text1
DEFAULT '/usr/sap/interfaces/celerra/Entity_Reorg/PO_success.txt'
LOWER CASE MODIF ID sc2.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 5(30) text-015.
PARAMETERS : p_berfl LIKE ibipparms-path
DEFAULT '/usr/sap/interfaces/celerra/Entity_Reorg/PO_error.txt'
DEFAULT v_err_file_text1
LOWER CASE MODIF ID sc2.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK run_time.
SELECTION-SCREEN BEGIN OF BLOCK rfc_dest WITH FRAME TITLE text-002.
PARAMETERS: p_dest LIKE rfcdisplay-rfcdest.
SELECTION-SCREEN END OF BLOCK rfc_dest.
----
AT SELECTION-SCREEN OUTPUT *
----
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-group1 = 'SC1'.
IF rb_fgrnd = 'X'.
screen-input = '1'.
ELSE.
screen-input = '0'.
ENDIF.
ELSEIF screen-group1 = 'SC2'.
IF rb_bgrnd = 'X'.
screen-input = '1'.
ELSE.
screen-input = '0'.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
----
AT SELECTION-SCREEN ON VALUE REQUEST FOR INPUT *
----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_infl.
CALL METHOD zcler_conversion=>filename_get
CHANGING
vp_filename = p_infl.
CALL FUNCTION 'F4_FILENAME' "allows user to select path/file
EXPORTING
program_name = syst-repid
dynpro_number = syst-dynnr
field_name = 'p_infl'
IMPORTING
file_name = p_infl.
IF sy-subrc NE 0.
WRITE: / 'Error'.
ENDIF.
----
AT SELECTION-SCREEN ON VALUE REQUEST FOR ERROR *
----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_erfl.
CALL FUNCTION 'F4_FILENAME' "allows user to select path/file
EXPORTING
program_name = syst-repid
dynpro_number = syst-dynnr
field_name = 'p_erfl'
IMPORTING
file_name = p_erfl.
IF sy-subrc NE 0.
WRITE: / 'Error'.
ENDIF.
----
AT SELECTION-SCREEN ON VALUE REQUEST FOR SUCCESS *
----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_sucfl.
CALL FUNCTION 'F4_FILENAME' "allows user to select path/file
EXPORTING
program_name = syst-repid
dynpro_number = syst-dynnr
field_name = 'p_sucfl'
IMPORTING
file_name = p_sucfl.
IF sy-subrc NE 0.
WRITE: / 'Error'.
ENDIF.
----
AT SELECTION-SCREEN ON BLOCK RUNTIME *
----
AT SELECTION-SCREEN ON BLOCK run_time.
IF rb_bgrnd = 'X' OR sy-batch = 'X'.
v_run_time = 'B'.
MOVE p_binfl TO v_input_file.
MOVE p_berfl TO v_error_file.
MOVE p_bsucfl TO v_success_file.
ELSE.
v_run_time = 'F'.
MOVE p_infl TO v_input_file.
MOVE p_erfl TO v_error_file.
MOVE p_sucfl TO v_success_file.
ENDIF.
----
START-OF-SELECTION - Point after processing the selection screen. *
----
START-OF-SELECTION.
Upload File from AS or PS
PERFORM get_data.
Process Data
PERFORM process_data.
Identify Release during Delta Period
PERFORM RELEASE_DELTAPERIOD.
Download Data - Success file
*IF I_SUCCESS[] IS NOT INITIAL.
PERFORM DOWNLOAD_DATA TABLES I_SUCCESS
USING v_success_file.
ENDIF.
Download Data - error file
*IF I_ERROR[] IS NOT INITIAL.
PERFORM DOWNLOAD_DATA TABLES I_ERROR
USING v_error_file.
*
ENDIF.
Populate Sumamry Report
*PERFORM SUB_POPULATE_SUMMARY.
----
END OF SELECTION *
----
END-OF-SELECTION.
Download Data - Success file
IF I_SUCCESS[] IS NOT INITIAL.
PERFORM DOWNLOAD_DATA TABLES I_SUCCESS
USING v_success_file.
ENDIF.
Download Data - error file
IF I_ERROR[] IS NOT INITIAL.
PERFORM DOWNLOAD_DATA TABLES I_ERROR
USING v_error_file.
ENDIF.
Populate Sumamry Report
PERFORM SUB_POPULATE_SUMMARY.
Write Data
PERFORM WRITE_DATA.
----
TOP OF PAGE *
----
TOP-OF-PAGE.
PERFORM TOP-OF-PAGE.
&----
*& Form get_data
&----
Upload File from AS or PS
----
FORM get_data .
*-- UPLOAD INPUT FILE
IF sy-batch = 'X' OR v_run_time = 'B'.
*-- Background Processing
CALL FUNCTION 'Z_TXX_UNIX_UPLOAD'
EXPORTING
filename = v_input_file
TABLES
data_tab = i_record.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ELSE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_input_file
filetype = 'ASC'
TABLES
data_tab = i_record
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 e002(sy) WITH 'File Not Found or Unabe to Read File'.
ENDIF.
ENDIF.
ENDFORM. " get_data
&----
*& Form process_data
&----
Process Data
----
FORM process_data .
*loop throgh each record.
LOOP AT i_record.
Perform Conversion for PR number
perform conversion_exit using i_record-purchaseorder.
Getdetail PR from Remote System - VPR System
PERFORM POGETDETAIL_REMOTESYSTEM.
Check Remote Connection
if sy-subrc eq 0.
Check PR number exist in Remote system
if sy-subrc eq 0 and il_return_remote-type <> 'E'.
Getdetails PR from Local System - -VPP System
PERFORM POGETDETAIL_LOCALSYSTEM.
*check wether it exists locally in VPP.
if sy-subrc eq 0 and il_return_local-type <> 'E'.
*PO exits in local system, Changes Occured in the Local System
CLEAR:wl_poheader.
**Mapping Feilds PO_HEADER -> POHEADER
MOVE-CORRESPONDING wl_po_header_remote TO wl_c_poheader.
MOVE: "i_record-purchaseorder TO wl_poheader-po_number,
"sy-langu TO wl_poheader-po_number.
SELECT SINGLE bukrs
FROM ztps_newcc_plant
INTO wl_c_poheader-comp_code
WHERE werks = il_po_items_remote-plant.
**Mapping Feilds PO_ADDRESS -> POADDRVENDOR.
*wl_po_address wl_poaddrvendor
**************************************************
clear : wl_c_poaddrvendor.
***************************************************
MOVE-CORRESPONDING wl_po_address_remote TO wl_c_poaddrvendor.
MOVE :
i_record-purchaseorder TO wl_c_poaddrvendor-po_number,
wl_po_address_remote-addrnumber TO wl_c_poaddrvendor-addr_no,
wl_po_address_remote-name1 TO wl_c_poaddrvendor-name,
wl_po_address_remote-city1 TO wl_c_poaddrvendor-city,
wl_po_address_remote-post_code1 TO wl_c_poaddrvendor-postl_cod1,
wl_po_address_remote-roomnumber TO wl_c_poaddrvendor-room_no,
wl_po_address_remote-tel_number TO wl_c_poaddrvendor-tel1_numbr,
wl_po_address_remote-tel_extens TO wl_c_poaddrvendor-tel1_ext.
**Mapping Feilds PO_HEADER_TEXTS -> POTEXTHEADER
MOVE-CORRESPONDING il_po_header_texts_remote TO il_c_potextheader.
**Mapping Feilds PO_ITEMS -> POITEM
CLEAR: il_po_items_remote.
LOOP AT il_po_items_remote.
**Mapping Feilds PO_ITEMS -> PO_ITEMS
MOVE-CORRESPONDING il_po_items_remote TO il_c_poitem.
MOVE: il_po_items_remote-store_loc TO il_c_poitem-stge_loc,
il_po_items_remote-mat_grp TO il_c_poitem-matl_group,
il_po_items_remote-unit TO il_c_poitem-po_unit,
il_po_items_remote-overdeltol TO il_c_poitem-over_dlv_tol,
il_po_items_remote-unlimited TO il_c_poitem-unlimited_dlv,
il_po_items_remote-under_tol TO il_c_poitem-under_dlv_tol,
il_po_items_remote-tax_jur_cd TO il_c_poitem-taxjurcode.
APPEND il_c_poitem.
CLEAR:il_po_items_remote,il_c_poitem.
ENDLOOP.
**Mapping Feilds PO_ITEM_ACCOUNT_ASSIGNMENT -> POACCOUNT
CLEAR:il_po_item_account_remote.
LOOP AT il_po_item_account_remote.
MOVE-CORRESPONDING il_po_item_account_remote TO il_c_poaccount.
MOVE:
il_po_item_account_remote-g_l_acct TO
il_c_poaccount-gl_account,
il_po_item_account_remote-wbs_elem_e TO
il_c_poaccount-wbs_element,
il_po_item_account_remote-cost_ctr TO
il_c_poaccount-costcenter.
APPEND il_c_poaccount.
CLEAR:il_po_item_account_remote,il_c_poaccount.
ENDLOOP.
**Mapping Feilds PO_ITEM_SCHEDULES -> POSCHEDULE
CLEAR: il_po_item_schedules_remote.
LOOP AT il_po_item_schedules_remote.
MOVE-CORRESPONDING il_po_item_schedules_remote TO il_c_poschedule.
MOVE: il_po_item_schedules_remote-serial_no TO
il_c_poschedule-sched_line,
il_po_item_schedules_remote-deliv_date TO
il_c_poschedule-delivery_date.
APPEND il_c_poschedule.
CLEAR:il_po_item_schedules_remote,il_c_poschedule.
ENDLOOP.
**Mapping Feilds PO_ITEM_TEXTS -> POTEXTITEM
il_po_item_texts_remote[] = il_c_potextitem[].
Call BAPI Purchase Order Change
perform purchaseorder_change.
*Read BAPI Return & Commit Bapi
perform transaction_commit.
Perform clear & refresh
PERFORM CLEAR_DATA.
Create PO
*PO does not exits in local system,so get details and create new one.
ELSE.
CLEAR:wl_poheader.
**Mapping Feilds PO_HEADER -> POHEADER
MOVE-CORRESPONDING wl_po_header_remote TO wl_poheader.
MOVE: "i_record-purchaseorder TO wl_poheader-po_number,
sy-langu TO wl_poheader-po_number.
SELECT SINGLE bukrs
FROM ztps_newcc_plant
INTO wl_poheader-comp_code
WHERE werks = il_po_items_remote-plant.
*********************************************************
clear : wl_poaddrvendor.
************************************************************
**Mapping Feilds PO_ADDRESS -> POADDRVENDOR.
*wl_po_address wl_poaddrvendor
MOVE-CORRESPONDING wl_po_address_remote TO wl_poaddrvendor.
MOVE :i_record-purchaseorder TO wl_poaddrvendor-po_number,
wl_po_address_remote-addrnumber TO wl_poaddrvendor-addr_no,
wl_po_address_remote-name1 TO wl_poaddrvendor-name,
wl_po_address_remote-city1 TO wl_poaddrvendor-city,
wl_po_address_remote-post_code1 TO
wl_poaddrvendor-postl_cod1,
wl_po_address_remote-roomnumber TO wl_poaddrvendor-room_no,
wl_po_address_remote-tel_number TO
wl_poaddrvendor-tel1_numbr,
wl_po_address_remote-tel_extens TO wl_poaddrvendor-tel1_ext.
**Mapping Feilds PO_HEADER_TEXTS -> POTEXTHEADER
MOVE-CORRESPONDING il_po_header_texts_remote TO il_potextheader.
**Mapping Feilds PO_ITEMS -> POITEM
CLEAR: il_po_items_remote.
LOOP AT il_po_items_remote.
**Mapping Feilds PO_ITEMS -> PO_ITEMS
MOVE-CORRESPONDING il_po_items_remote TO il_poitem.
MOVE: il_po_items_remote-store_loc TO il_poitem-stge_loc,
il_po_items_remote-mat_grp TO il_poitem-matl_group,
il_po_items_remote-unit TO il_poitem-po_unit,
il_po_items_remote-overdeltol TO il_poitem-over_dlv_tol,
il_po_items_remote-unlimited TO il_poitem-unlimited_dlv,
il_po_items_remote-under_tol TO il_poitem-under_dlv_tol,
il_po_items_remote-tax_jur_cd TO il_poitem-taxjurcode.
APPEND il_poitem.
CLEAR:il_po_items_remote,il_poitem.
ENDLOOP.
**Mapping Feilds PO_ITEM_ACCOUNT_ASSIGNMENT -> POACCOUNT
CLEAR:il_po_item_account_remote.
LOOP AT il_po_item_account_remote.
MOVE-CORRESPONDING il_po_item_account_remote TO il_poaccount.
MOVE:
il_po_item_account_remote-g_l_acct TO il_poaccount-gl_account,
il_po_item_account_remote-wbs_elem_e TO il_poaccount-wbs_element,
il_po_item_account_remote-cost_ctr TO il_poaccount-costcenter.
APPEND il_poaccount.
CLEAR:il_po_item_account_remote,il_poaccount.
ENDLOOP.
**Mapping Feilds PO_ITEM_SCHEDULES -> POSCHEDULE
CLEAR: il_po_item_schedules_remote.
LOOP AT il_po_item_schedules_remote.
MOVE-CORRESPONDING il_po_item_schedules_remote TO il_poschedule.
MOVE:
il_po_item_schedules_remote-serial_no TO
il_poschedule-sched_line,
il_po_item_schedules_remote-deliv_date TO
il_poschedule-delivery_date.
APPEND il_poschedule.
CLEAR:il_po_item_schedules_remote,il_poschedule.
ENDLOOP.
**Mapping Feilds PO_ITEM_TEXTS -> POTEXTITEM
il_po_item_texts_remote[] = il_potextitem[].
BAPI - Create Purchase Order
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = wl_poheader
POHEADERX =
poaddrvendor = wl_poaddrvendor
TABLES
RETURN = il_bapireturn
poitem = il_poitem
poschedule = il_poschedule
POSCHEDULEX =
poaccount = il_poaccount
potextheader = il_potextheader
potextitem = il_potextitem.
*Read BAPI Return & Commit Bapi
perform transaction_commit.
*************************
Check for Deletion Indicator
Getdetails PO from Local System - -VPP System
perform pogetdetail_localsystem.
To check whether PO number Exist in Local System
if sy-subrc eq 0 and il_return_local-type <> 'E'.
PR Changes occured in Local System
Remote System - for Deletion Indicator
loop at il_po_items_remote.
if il_po_items_remote-DELETE_IND = 'L'.
move :
il_po_items_remote-PO_ITEM to il_c_poitem-PO_ITEM.
il_c_poitem-DELETE_IND = 'L'.
append il_c_poitem.
clear il_c_poitem.
move : il_po_items_remote-PO_NUMBER to il_change-ebeln,
il_po_items_remote-PO_ITEM to il_change-EBELP,
il_po_items_remote-DELETE_IND to il_change-LOEKZ.
append il_change.
clear il_change.
ENDIF.
endloop.
Check to call PO Change
if not il_change[] is initial.
Call BAPI Purchase Order Change
perform purchaseorder_change.
*Read BAPI Return & Commit Bapi
perform transaction_commit.
endif.
endif.
Perform clear & refresh
PERFORM CLEAR_DATA.
endif.
******************************
ELSE.
If not exist in Remote system, Populate error
vl_err = vl_err + 1.
I_ERROR-purchaseorder = I_RECORD-purchaseorder.
i_error-messagetype = il_return_remote-TYPE.
I_ERROR-MESSAGE = il_return_remote-message.
append i_error.
clear i_error.
ENDIF.
*****************************
else.
Populate RFC Connection Disconnected
write : / 'RFC Connection Disconnected or Wrong Path'.
skip.
stop.
endif.
clear : i_record.
endloop.
ENDFORM. " process_data
&----
*& Form RELEASE_DELTAPERIOD
&----
Release made during Delta Period
----
form RELEASE_DELTAPERIOD .
Check release status for Each PO in Local System
LOOP AT I_RECORD.
Perform Conversion Routine
perform conversion_exit using i_record-purchaseorder.
Getdetail PO from Remote System - VPR System
PERFORM POGETDETAIL_REMOTESYSTEM.
Check Remote Connection
if sy-subrc eq 0.
Check PR number exist in Remote system
if sy-subrc eq 0 and il_return_remote-type <> 'E'.
Getdetails PR from Local System - -VPP System
PERFORM POGETDETAIL_LOCALSYSTEM.
To check whether PR number Exist in Local System
IF SY-SUBRC EQ 0 AND IL_RETURN_LOCAL IS INITIAL.
if sy-subrc eq 0 and il_return_local-type <> 'E'.
*************************
Call BAPI PO GETREL Information Locally - VPP
CALL FUNCTION 'BAPI_PO_GETRELINFO'
EXPORTING
PURCHASEORDER = I_RECORD-purchaseorder
IMPORTING
RELEASE_ALREADY_POSTED = IL_BAPIRLCOPO_LOCAL[].
Calling BAPI PO GETREL Information Remotly - VPR
CALL FUNCTION 'BAPI_PO_GETRELINFO' destination p_dest
EXPORTING
PURCHASEORDER = I_RECORD-purchaseorder
IMPORTING
RELEASE_ALREADY_POSTED = IL_BAPIRLCOPO_REMOTE[]
exceptions
system_failure = 1
communication_failure = 2.
CLEAR : IL_BAPIRLCOPO_LOCAL,IL_BAPIRLCOPO_REMOTE.
******************************
Check Release codes 1 to 8 in Local & Remote System
if not IL_BAPIRLCOPO_LOCAL is initial
or il_BAPIRLCOPO_REMOTE is initial.
Comparing & Updating Release codes
perform validate_rel_code.
endif.
endif.
endif.
clear : wl_BAPIRLCOPO_LOCAL ,wl_BAPIRLCOPO_remote.
refresh : IL_BAPIRLCOPO_REMOTE, IL_BAPIRLCOPO_local.
Perform Clear & Refresh Data
PERFORM CLEAR_DATA.
CLEAR : I_RECORD.
******
ELSE.
If not exist in Remote system, Populate error
vl_err = vl_err + 1.
I_ERROR-purchaseorder = I_RECORD-purchaseorder.
i_error-messagetype = il_return_remote-TYPE.
I_ERROR-MESSAGE = il_return_remote-message.
append i_error.
clear i_error.
*
*************
ENDIF.
else.
Populate RFC Connection Disconnected
write : / 'RFC Connection Disconnected or Wrong Path'.
skip.
stop.
endif.
ENDLOOP.
endform. " RELEASE_DELTAPERIOD
&----
*& Form CONVERSION_EXIT
&----
PR Number
----
form conversion_exit using p_data.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = p_data
IMPORTING
output = p_data.
endform. " CONVERSION_EXIT
&----
*& Form PRGETDETAIL_REMOTESYSTEM
&----
Call BAPI Get detail from Remote System - VPR
----
form POGETDETAIL_REMOTESYSTEM .
Call BAPI Get detail from Remote System - VPR
CALL FUNCTION 'BAPI_PO_GETDETAIL' DESTINATION p_dest
EXPORTING
purchaseorder = i_record-purchaseorder
items = 'X'
account_assignment = 'X'
schedules = 'X'
history = 'X'
item_texts = 'X'
header_texts = 'X'
services = 'X'
confirmations = 'X'
service_texts = 'X'
extensions = 'X'
IMPORTING
po_header = wl_po_header_remote
po_address = wl_po_address_remote
TABLES
po_header_texts = il_po_header_texts_remote
po_items = il_po_items_remote
po_item_account_assignment = il_po_item_account_remote
po_item_schedules = il_po_item_schedules_remote
po_item_confirmations = il_po_item_confirma_remote
po_item_texts = il_po_item_texts_remote
po_item_history = il_po_item_history_remote
po_item_history_totals = il_po_item_totals_remote
po_item_limits = il_po_item_limits_remote
po_item_contract_limits = il_po_item_contracts_remote
po_item_services = il_po_item_services_remote
po_item_srv_accass_values = il_po_item_srv_accass_remote
return = il_return_remote
po_services_texts = il_po_services_texts_remote
extensionout = il_extensionout_remote
exceptions
system_failure = 1
communication_failure = 2.
*
IF SY-SUBRC <> 0.
WRITE : / 'Populate Error'.
STOP.
ENDIF.
endform. " POGETDETAIL_REMOTESYSTEM
&----
*& Form POGETDETAIL_LOCALSYSTEM
&----
*
----
FORM POGETDETAIL_LOCALSYSTEM .
CALL FUNCTION 'BAPI_PO_GETDETAIL'
EXPORTING
purchaseorder = i_record-purchaseorder
items = 'X'
account_assignment = 'X'
schedules = 'X'
history = 'X'
item_texts = 'X'
header_texts = 'X'
services = 'X'
confirmations = 'X'
service_texts = 'X'
extensions = 'X'
IMPORTING
po_header = wl_po_header_local
po_address = wl_po_address_local
TABLES
po_header_texts = il_po_header_texts_local
po_items = il_po_items_local
po_item_account_assignment = il_po_item_account_local
po_item_schedules = il_po_item_schedules_local
po_item_confirmations = il_po_item_confirma_local
po_item_texts = il_po_item_texts_local
po_item_history = il_po_item_history_local
po_item_history_totals = il_po_item_totals_local
po_item_limits = il_po_item_limits_local
po_item_contract_limits = il_po_item_contracts_local
po_item_services = il_po_item_services_local
po_item_srv_accass_values = il_po_item_srv_accass_local
return = il_return_local
po_services_texts = il_po_services_texts_local
extensionout = il_extensionout_local.
ENDFORM. " POGETDETAIL_LOCALSYSTEM
&----
*& Form validate_rel_code
&----
Validate Release Codes
----
FORM validate_rel_code .
loop at IL_BAPIRLCOPO_LOCAL into wl_BAPIRLCOPO_LOCAL.
read table IL_BAPIRLCOPO_REMOTE into wl_BAPIRLCOPO_REMOTE
with key PO_NUMBER = wl_BAPIRLCOPO_LOCAL-PO_NUMBER.
endloop.
loop at IL_BAPIRLCOPO_REMOTE into wl_BAPIRLCOPO_REMOTE.
read table IL_BAPIRLCOPO_LOCAL into wl_BAPIRLCOPO_LOCAL
with key PO_NUMBER = wl_BAPIRLCOPO_REMOTE-PO_NUMBER.
endloop.
Check Release codes 1 to 8 in Local & Remote System
IF wL_BAPIRLCOPO_LOCAL-REL_CODE1 <> ' '
or wL_BAPIRLCOPO_REMOTE-REL_CODE1 <> ' '.
Release Code 1
IF wL_BAPIRLCOPO_REMOTE-REL_CODE1 <> wL_BAPIRLCOPO_LOCAL-REL_CODE1.
*****************************************
IF wL_BAPIRLCOPO_LOCAL-REL_CODE1 <> ' '
AND wL_BAPIRLCOPO_REMOTE-REL_CODE1 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
wL_BAPIRLCOPO_LOCAL-REL_CODE1.
ELSE.
ELSE.
wL_BAPIRLCOPO_LOCAL-REL_CODE1 = wL_BAPIRLCOPO_REMOTE-REL_CODE1.
Update Release Indicator in Local System - VPP
PERFORM RELEASE_UPDATE_LOCALSYSTEM USING
wL_BAPIRLCOPO_REMOTE-REL_CODE1.
ELSE.
IF IL_BAPIRLCORQ_LOCAL-REL_CODE1 <> ' '.
IF IL_BAPIRLCORQ_REMOTE-REL_CODE1 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
IL_BAPIRLCORQ_REMOTE-REL_CODE1.
ENDIF.
ENDIF.
Check release code 2 in local & remote system
IF wL_BAPIRLCOPO_LOCAL-REL_CODE2 <> ' '
or wL_BAPIRLCOPO_REMOTE-REL_CODE2 <> ' '.
Release Code 2
IF wL_BAPIRLCOPO_REMOTE-REL_CODE2 <> wL_BAPIRLCOPO_LOCAL-REL_CODE2.
IF wL_BAPIRLCOPO_LOCAL-REL_CODE2 <> ' '
AND wL_BAPIRLCOPO_REMOTE-REL_CODE2 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
wL_BAPIRLCOPO_LOCAL-REL_CODE2.
ELSE.
wL_BAPIRLCOPO_LOCAL-REL_CODE2 = wL_BAPIRLCOPO_REMOTE-REL_CODE2.
Update Release Indicator in Local System - VPP
PERFORM RELEASE_UPDATE_LOCALSYSTEM USING
wL_BAPIRLCOPO_REMOTE-REL_CODE2.
ENDIF.
ENDIF.
Check release code 3 in local & remote system
IF wL_BAPIRLCOPO_LOCAL-REL_CODE3 <> ' '
or wL_BAPIRLCOPO_REMOTE-REL_CODE3 <> ' '.
Release Code 3
IF wL_BAPIRLCOPO_REMOTE-REL_CODE3 <> wL_BAPIRLCOPO_LOCAL-REL_CODE3.
IF wL_BAPIRLCOPO_LOCAL-REL_CODE3 <> ' '
AND wL_BAPIRLCOPO_REMOTE-REL_CODE3 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
wL_BAPIRLCOPO_LOCAL-REL_CODE3.
ELSE.
wL_BAPIRLCOPO_LOCAL-REL_CODE3 = wL_BAPIRLCOPO_REMOTE-REL_CODE3.
Update Release Indicator in Local System - VPP
PERFORM RELEASE_UPDATE_LOCALSYSTEM USING
wL_BAPIRLCOPO_REMOTE-REL_CODE3.
ENDIF.
ENDIF.
Check release code 4 in local & remote system
IF wL_BAPIRLCOPO_LOCAL-REL_CODE4 <> ' '
or wL_BAPIRLCOPO_REMOTE-REL_CODE4 <> ' '.
Release Code 4
IF wL_BAPIRLCOPO_REMOTE-REL_CODE4 <> wL_BAPIRLCOPO_LOCAL-REL_CODE4.
IF wL_BAPIRLCOPO_LOCAL-REL_CODE4 <> ' '
AND wL_BAPIRLCOPO_REMOTE-REL_CODE4 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
wL_BAPIRLCOPO_LOCAL-REL_CODE4.
ELSE.
wL_BAPIRLCOPO_LOCAL-REL_CODE4 = wL_BAPIRLCOPO_REMOTE-REL_CODE4.
Update Release Indicator in Local System - VPP
PERFORM RELEASE_UPDATE_LOCALSYSTEM USING
wL_BAPIRLCOPO_REMOTE-REL_CODE4.
ENDIF.
ENDIF.
Check release code 5 in local & remote system
IF wL_BAPIRLCOPO_LOCAL-REL_CODE5 <> ' '
or wL_BAPIRLCOPO_REMOTE-REL_CODE5 <> ' '.
Release Code 5
IF wL_BAPIRLCOPO_REMOTE-REL_CODE5 <> wL_BAPIRLCOPO_LOCAL-REL_CODE5.
IF wL_BAPIRLCOPO_LOCAL-REL_CODE5 <> ' '
AND wL_BAPIRLCOPO_REMOTE-REL_CODE5 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
wL_BAPIRLCOPO_LOCAL-REL_CODE5.
ELSE.
wL_BAPIRLCOPO_LOCAL-REL_CODE5 = wL_BAPIRLCOPO_REMOTE-REL_CODE5.
Update Release Indicator in Local System - VPP
PERFORM RELEASE_UPDATE_LOCALSYSTEM USING
wL_BAPIRLCOPO_REMOTE-REL_CODE5.
ENDIF.
ENDIF.
Check release code 6 in local & remote system
IF wL_BAPIRLCOPO_LOCAL-REL_CODE6 <> ' '
or wL_BAPIRLCOPO_REMOTE-REL_CODE6 <> ' '.
Release Code 6
IF wL_BAPIRLCOPO_REMOTE-REL_CODE6 <> wL_BAPIRLCOPO_LOCAL-REL_CODE6.
IF wL_BAPIRLCOPO_LOCAL-REL_CODE6 <> ' '
AND wL_BAPIRLCOPO_REMOTE-REL_CODE6 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
wL_BAPIRLCOPO_LOCAL-REL_CODE6.
ELSE.
wL_BAPIRLCOPO_LOCAL-REL_CODE6 = wL_BAPIRLCOPO_REMOTE-REL_CODE6.
Update Release Indicator in Local System - VPP
PERFORM RELEASE_UPDATE_LOCALSYSTEM USING
wL_BAPIRLCOPO_REMOTE-REL_CODE6.
ENDIF.
ENDIF.
Check release code 7 in local & remote system
IF wL_BAPIRLCOPO_LOCAL-REL_CODE7 <> ' '
or wL_BAPIRLCOPO_REMOTE-REL_CODE7 <> ' '.
Release Code 7
IF wL_BAPIRLCOPO_REMOTE-REL_CODE7 <> wL_BAPIRLCOPO_LOCAL-REL_CODE7.
IF wL_BAPIRLCOPO_LOCAL-REL_CODE7 <> ' '
AND wL_BAPIRLCOPO_REMOTE-REL_CODE7 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
wL_BAPIRLCOPO_LOCAL-REL_CODE7.
ELSE.
wL_BAPIRLCOPO_LOCAL-REL_CODE7 = wL_BAPIRLCOPO_REMOTE-REL_CODE7.
Update Release Indicator in Local System - VPP
PERFORM RELEASE_UPDATE_LOCALSYSTEM USING
wL_BAPIRLCOPO_REMOTE-REL_CODE7.
ENDIF.
ENDIF.
Check release code 8 in local & remote system
IF wL_BAPIRLCOPO_LOCAL-REL_CODE8 <> ' '
or wL_BAPIRLCOPO_REMOTE-REL_CODE8 <> ' '.
Release Code 8
IF wL_BAPIRLCOPO_REMOTE-REL_CODE8 <> wL_BAPIRLCOPO_LOCAL-REL_CODE8.
IF wL_BAPIRLCOPO_LOCAL-REL_CODE8 <> ' '
AND wL_BAPIRLCOPO_REMOTE-REL_CODE8 = ' '.
Reset Release Indicator in local System - VPP comparing with VPR
PERFORM RELEASE_RESET_LOCALSYSTEM USING
wL_BAPIRLCOPO_LOCAL-REL_CODE8.
ELSE.
wL_BAPIRLCOPO_LOCAL-REL_CODE8 = wL_BAPIRLCOPO_REMOTE-REL_CODE8.
Update Release Indicator in Local System - VPP
PERFORM RELEASE_UPDATE_LOCALSYSTEM USING
wL_BAPIRLCOPO_REMOTE-REL_CODE8.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " validate_rel_code
&----
*& Form RELEASE_UPDATE_LOCALSYSTEM
&----
Update Release Indicator
----
FORM RELEASE_UPDATE_LOCALSYSTEM USING P_DATA.
Update Release Indicator in Local System - VPP
CALL FUNCTION 'BAPI_PO_RELEASE'
EXPORTING
PURCHASEORDER = i_record-purchaseorder
PO_REL_CODE = P_DATA
TABLES
RETURN = IL_RETURNREL
EXCEPTIONS
AUTHORITY_CHECK_FAIL = 1
DOCUMENT_NOT_FOUND = 2
ENQUEUE_FAIL = 3
PREREQUISITE_FAIL = 4
RELEASE_ALREADY_POSTED = 5
RESPONSIBILITY_FAIL = 6
OTHERS = 7 .
Check Release Status
IF SY-SUBRC = 0 AND il_returnrel-TYPE NE 'E'.
vl_succ = vl_succ + 1.
i_relsucc-purchaseorder = I_RECORD-purchaseorder.
IF NOT il_returnrel[] IS INITIAL.
i_relsucc-messagetype = il_returnrel-type.
i_relsucc-MESSAGE = IL_RETURNREL-message.
ELSE.
i_relsucc-messagetype = 'S'.
i_relsucc-message = 'PR RELEASED SUCCESFULLY'.
ENDIF.
append i_relsucc.
clear i_relsucc.
ELSE.
vl_err = vl_err + 1.
i_relerror-purchaseorder = I_RECORD-purchaseorder.
i_relerror-messagetype = il_returnrel-type.
i_relerror-MESSAGE = IL_RETURNREL-message.
append i_relerror.
clear i_relerror.
endif.
clear : il_returnrel.
refresh : il_returnrel.
ENDFORM. " RELEASE_UPDATE_LOCALSYSTEM
&----
*& Form RELEASE_RESET_LOCALSYSTEM
&----
Reset Release Indicator
*----
FORM RELEASE_RESET_LOCALSYSTEM USING P_DATA.
Reset Release Indicator in local System - VPP comparing with VPR
CALL FUNCTION 'BAPI_PO_RESET_RELEASE'
EXPORTING
PURCHASEORDER = i_record-purchaseorder
PO_REL_CODE = P_DATA
TABLES
RETURN = IL_RETURNRESET
EXCEPTIONS
AUTHORITY_CHECK_FAIL = 1
DOCUMENT_NOT_FOUND = 2
ENQUEUE_FAIL = 3
PREREQUISITE_FAIL = 4
RELEASE_ALREADY_POSTED = 5
RESPONSIBILITY_FAIL = 6
NO_RELEASE_ALREADY = 7
NO_NEW_RELEASE_INDICATOR = 8
OTHERS = 9 .
Check Reset Status
IF NOT IL_RETURNRESET[] IS INITIAL.
IF SY-SUBRC = 0 AND il_returnreset-TYPE NE 'E'.
vl_succ = vl_succ + 1.
i_relsucc-purchaseorder = I_RECORD-purchaseorder.
IF NOT IL_BAPIRETURN[] IS INITIAL.
i_relsucc-messagetype = IL_RETURNRESET-type.
i_relsucc-MESSAGE = IL_RETURNRESET-message.
ELSE.
i_relsucc-messagetype = 'S'.
i_relsucc-message = 'PO RESET SUCCESFULLY'.
ENDIF.
append i_relsucc.
clear i_relsucc.
ELSE.
vl_err = vl_err + 1.
i_relerror-purchaseorder = I_RECORD-purchaseorder.
i_relerror-messagetype = IL_RETURNRESET-type.
i_relerror-MESSAGE = IL_RETURNRESET-message.
append i_relerror.
clear i_relerror.
endif.
ELSE.
vl_err = vl_err + 1.
I_ERROR-purchaseorder = I_RECORD-purchaseorder.
i_error-messagetype = IL_RETURNRESET-type.
I_ERROR-MESSAGE = IL_RETURNRESET-message.
append i_error.
clear i_error.
ENDIF.
clear : il_returnreset.
refresh : il_returnreset.
ENDFORM. " RELEASE_RESET_LOCALSYSTEM
&----
*& Form DOWNLOAD_DATA
&----
Download file
----
FORM DOWNLOAD_DATA TABLES IL_SUCCESS STRUCTURE I_SUCCESS
USING P_FILE.
*-- Download file
if sy-batch = 'X' or v_run_time = 'B'.
*-- Background Processing
call function 'Z_TXX_UNIX_DOWNLOAD'
EXPORTING
filename = P_FILE
TABLES
data_tab = IL_SUCCESS.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
else.
call function 'GUI_DOWNLOAD'
EXPORTING
filename = P_FILE
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = IL_SUCCESS
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 e002(sy) with 'File Not Found or Unabe to Read File'.
endif.
endif.
ENDFORM. " DOWNLOAD_DATA
&----
*& Form SUB_POPULATE_SUMMARY
&----
Sumamry Report
----
FORM SUB_POPULATE_SUMMARY .
I_SUMMARY-TEXT = 'Total NO of Records from file'.
DESCRIBE TABLE I_RECORD LINES I_SUMMARY-COUNT.
APPEND I_SUMMARY.
CLEAR I_SUMMARY.
I_SUMMARY-TEXT = 'Total NO of Success Records'.
DESCRIBE TABLE I_SUCCESS LINES I_SUMMARY-COUNT.
APPEND I_SUMMARY.
CLEAR I_SUMMARY.
I_SUMMARY-TEXT = 'Total No of Error Records'.
DESCRIBE TABLE I_ERROR LINES I_SUMMARY-COUNT.
APPEND I_SUMMARY.
CLEAR I_SUMMARY.
ENDFORM. " SUB_POPULATE_SUMMARY
&----
*& Form WRITE_DATA
&----
Write Output
----
FORM WRITE_DATA .
Populate Summary Report
PERFORM SUMMARY.
WRITE : /5 'SUMMARY REPORT' , 45 'TOTAL RECORDS'.
SKIP.
IF NOT I_SUMMARY[] IS INITIAL.
LOOP AT I_SUMMARY.
WRITE : /5 I_SUMMARY-TEXT , ' : ', 45 I_SUMMARY-COUNT.
CLEAR I_SUMMARY.
ENDLOOP.
REFRESH I_SUMMARY.
ELSE.
WRITE : / 'No Purchase Orders Found'.
ENDIF.
*Populate Success Report
PERFORM SUCCESS.
WRITE : /5 'PO NUMBER' , 30 'MESSAGE TYPE' , 50 'SUCCESS MESSAGE'.
SKIP.
IF NOT I_SUCCESS[] IS INITIAL.
LOOP AT I_SUCCESS.
WRITE : /5 I_SUCCESS-purchaseorder , 30 I_SUCCESS-messagetype ,
50 I_SUCCESS-MESSAGE.
CLEAR I_SUCCESS.
ENDLOOP.
REFRESH I_SUCCESS.
ELSE.
WRITE : /15 'No Success Records Found'.
ENDIF.
*Populate Error Report
PERFORM ERROR.
WRITE : /5 'PO NUMBER' , 30 'MESSAGE TYPE' , 50 'ERROR MESSAGE'.
SKIP.
IF NOT I_ERROR[] IS INITIAL.
LOOP AT I_ERROR.
WRITE : /5 I_ERROR-purchaseorder , 30 I_ERROR-messagetype ,
50 I_ERROR-MESSAGE.
CLEAR I_ERROR.
ENDLOOP.
REFRESH I_ERROR.
ELSE.
WRITE : /15 'No Error Records Found'.
*Populate RELEASE/RESET Success Report
perform relsucc.
write : /5 'PO NUMBER' , 30 'MESSAGE TYPE' , 50 'SUCCESS MESSAGE'.
skip.
if not i_relsucc[] is initial.
*delete adjacent duplicates from i_error.
loop at i_relsucc.
write : /5 i_relsucc-purchaseorder , 30 i_relsucc-messagetype ,
50 i_relsucc-message.
clear i_relsucc.
endloop.
refresh i_relsucc.
else.
write : /15 'No RELSUCC Records Found'.
endif.
*Populate RELEASE/RESET Error Report
perform relerror.
write : /5 'PO NUMBER' , 30 'MESSAGE TYPE' , 50 'ERROR MESSAGE'.
skip.
if not i_relerror[] is initial.
*delete adjacent duplicates from i_error.
loop at i_error.
write : /5 i_relerror-purchaseorder , 30 i_relerror-messagetype ,
50 i_relerror-message.
clear i_relerror.
endloop.
refresh i_relerror.
else.
write : /15 'No RELERROR Records Found'.
endif.
ENDIF.
ENDFORM. " WRITE_DATA
*----
FORM SUCCESS
*----
Title for Success report
*----
FORM SUCCESS.
FORMAT COLOR COL_HEADING.
WRITE: AT /(170) 'Success Report' CENTERED.
FORMAT RESET.
ENDFORM.
*----
FORM ERROR
*----
Title for Error report
*----
FORM ERROR.
FORMAT COLOR COL_HEADING.
WRITE: AT /(170) 'Error Report' CENTERED.
FORMAT RESET.
ENDFORM.
*----
FORM SUMMARY
*----
Title for Summary report
*----
FORM SUMMARY.
FORMAT COLOR COL_HEADING.
WRITE: AT /(170) 'Summary Report' CENTERED.
FORMAT RESET.
ENDFORM.
*----
FORM RELSUCCESS
*----
Title for RELSUCC report
*----
form relsucc.
format color col_heading.
write: at /(170) 'RELSUCC Report' centered.
format reset.
endform.
*----
FORM ERROR
*----
Title for RELERROR report
*----
form relerror.
format color col_heading.
write: at /(170) 'RELERROR Report' centered.
format reset.
endform.
&----
*& Form TOP-OF-PAGE
&----
TOP OF PAGE
----
FORM TOP-OF-PAGE .
DATA: LEN TYPE I, POS TYPE I.
DATA : VL_TITLE(100).
LEN = 23.
FORMAT COLOR COL_HEADING ON.
COMPUTE LEN = STRLEN( SY-UNAME ).
ULINE.
WRITE: AT /(010)
'User:' LEFT-JUSTIFIED,SPACE.
WRITE: AT 011(LEN) SY-UNAME RIGHT-JUSTIFIED NO-GAP.
LEN = 43.
WRITE: AT 40(LEN) 'T-MOBILE' CENTERED.
LEN = SY-LINSZ - 30.
WRITE: AT LEN(010) 'Run Date:'.
LEN = SY-LINSZ - 19.
WRITE: AT LEN(010) SY-DATUM MM/DD/YYYY LEFT-JUSTIFIED,SPACE.
LEN = SY-LINSZ - 07.
WRITE AT LEN(008) SY-UZEIT USING EDIT MASK '__:__:__' LEFT-JUSTIFIED.
COMPUTE LEN = STRLEN( SY-REPID ).
WRITE:
/(010) 'Program:' LEFT-JUSTIFIED,SPACE.
WRITE AT 011(LEN) SY-REPID RIGHT-JUSTIFIED NO-GAP.
VL_TITLE = SY-TITLE.
COMPUTE LEN = STRLEN( VL_TITLE ).
POS = ( SY-LINSZ - LEN ) / 2.
WRITE AT POS(LEN) VL_TITLE CENTERED.
LEN = SY-LINSZ - 27.
WRITE: AT LEN(010) 'Page No:'(097) LEFT-JUSTIFIED,SPACE.
LEN = SY-LINSZ - 8.
WRITE: AT LEN(010) SY-PAGNO RIGHT-JUSTIFIED NO-GAP.
ULINE.
FORMAT COLOR COL_HEADING OFF.
ENDFORM. " TOP-OF-PAGE
&----
*& Form CLEAR_DATA
&----
Clear & Refresh Data
----
FORM CLEAR_DATA .
clear : il_po_header_texts_remote,il_po_items_remote ,
il_po_item_account_remote,il_po_item_schedules_remote,
il_po_item_confirma_remote,il_po_item_texts_remote,
il_po_item_history_remote,il_po_item_totals_remote,
il_po_item_limits_remote,il_po_item_contracts_remote,
il_po_item_services_remote,il_po_item_srv_accass_remote,
il_return_remote,il_po_services_texts_remote,il_returnrel,
il_extensionout_remote,il_po_header_texts_local,il_po_items_local,
il_po_item_account_local,il_po_item_schedules_local,
il_po_item_confirma_local,il_po_item_texts_local,
il_po_item_history_local,il_po_item_totals_local,
il_po_item_limits_local,il_po_item_contracts_local,
il_po_item_services_local,il_po_item_srv_accass_local,
il_return_local,il_po_services_texts_local,il_returnreset,
il_extensionout_local,il_poitem,il_bapireturn,il_c_poitem,
il_poschedule,il_c_poschedule,il_poaccount,il_c_poaccount,
il_potextheader,il_potextitem,il_c_potextheader,il_c_potextitem,
IL_BAPIRLCOPO_LOCAL,IL_BAPIRLCOPO_remote,il_ret2_commit.
REFRESH : il_po_header_texts_remote,il_po_items_remote ,
il_po_item_account_remote,il_po_item_schedules_remote,
il_po_item_confirma_remote,il_po_item_texts_remote,
il_po_item_history_remote,il_po_item_totals_remote,
il_po_item_limits_remote,il_po_item_contracts_remote,
il_po_item_services_remote,il_po_item_srv_accass_remote,
il_return_remote,il_po_services_texts_remote,il_returnrel,
il_extensionout_remote,il_po_header_texts_local,il_po_items_local,
il_po_item_account_local,il_po_item_schedules_local,
il_po_item_confirma_local,il_po_item_texts_local,
il_po_item_history_local,il_po_item_totals_local,
il_po_item_limits_local,il_po_item_contracts_local,
il_po_item_services_local,il_po_item_srv_accass_local,
il_return_local,il_po_services_texts_local,il_returnreset,
il_extensionout_local,il_poitem,il_bapireturn,il_c_poitem,
il_poschedule,il_c_poschedule,il_poaccount,il_c_poaccount,
il_potextheader,il_potextitem,il_c_potextheader,il_c_potextitem,
IL_BAPIRLCOPO_LOCAL,IL_BAPIRLCOPO_remote,il_ret2_commit.
ENDFORM. " CLEAR_DATA
&----
*& Form purchaseorder_change
&----
Pruchase Order Change
----
form purchaseorder_change .
BAPI to call PO Change
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
purchaseorder = i_record-purchaseorder
poheader = wl_c_poheader
poheaderx =
poaddrvendor = wl_c_poaddrvendor
TABLES
return = il_bapireturn
poitem = il_c_poitem
poitemx =
poaddrdelivery =
poschedule = il_c_poschedule
poschedulex =
poaccount = il_c_poaccount
potextheader = il_c_potextheader
potextitem = il_c_potextitem.
endform. " purchaseorder_change
&----
*& Form transaction_commit
&----
BAPI Transaction Commit
----
form transaction_commit .
*Read BAPI Return & Commit Bapi
IF NOT IL_BAPIRETURN[] IS INITIAL.
READ TABLE IL_BAPIRETURN WITH KEY TYPE = 'E' BINARY SEARCH.
IF SY-SUBRC NE 0.
call function 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
RETURN = il_ret2_commit.
Check Commit
if not IL_RET2_COMMIT[] is initial.
READ TABLE IL_RET2_COMMIT WITH KEY TYPE = 'E' BINARY SEARCH.
IF SY-SUBRC NE 0.
IF SY-SUBRC = 0 AND il_ret2_commit-TYPE NE 'E'.
vl_succ = vl_succ + 1.
I_success-purchaseorder = I_RECORD-purchaseorder.
IF NOT IL_BAPIRETURN[] IS INITIAL.
i_success-messagetype = il_bapireturn-TYPE.
I_success-MESSAGE = 'PR changed sucessfully'.
I_success-MESSAGE = il_bapireturn-MESSAGE.
ELSE.
i_success-messagetype = 'S'.
i_success-message = 'PO CREATED/CHANGED SUCCESFULLY'.
ENDIF.
append i_success.
clear i_success.
endif.
ELSE.
vl_err = vl_err + 1.
I_ERROR-purchaseorder = I_RECORD-purchaseorder.
i_ERROR-messagetype = il_ret2_commit-TYPE.
I_ERROR-MESSAGE = 'PR not changed'.
i_error-message = il_ret2_commit-MESSAGE.
append i_error.
clear i_error.
endif.
ELSE.
vl_err = vl_err + 1.
I_ERROR-purchaseorder = I_RECORD-purchaseorder.
i_error-messagetype = il_bapireturn-TYPE.
I_ERROR-MESSAGE = il_bapireturn-message.
append i_error.
clear i_error.
ENDIF.
endform. " transaction_commit
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |