2007 May 22 10:42 PM
I had tried to use ME22N to run this BDC and was told it doesn't work. I am now trying ME22 running it as a BDC in the background. It runs great in the foreground but I get the following error when trying to run it in the background:
<b>Control Framework: Fatal error - GUI cannot be reached
Runtime error RAISE_EXCEPTION has occurred</b>
Thanks for your help!
Mike
Hi Michael,
As ME22N is an enjoy transaction, you cannot write BDC for that. Instead you can use BAPI.
Check this for sample code on BAPI.
http://www.sap-img.com/abap/sample-abap-code-on-bapi-po-change.htm
Reward if useful.
Thanks
Aneesh.
2007 May 22 10:48 PM
Hi Michael,
As ME22N is an enjoy transaction, you cannot write BDC for that. Instead you can use BAPI.
Check this for sample code on BAPI.
http://www.sap-img.com/abap/sample-abap-code-on-bapi-po-change.htm
Reward if useful.
Thanks
Aneesh.
2007 May 22 11:26 PM
Thanks, I am not using ME22N, but the older transaction ME22 and am getting the error. I had tried the BAPI first but it does not work for the type of PO's we use here.
Thanks
Mike
2007 May 22 11:54 PM
Use BAPI Function module :
REPORT ZT_MM_PO_CHNG_CONVERSION .
Tables Declaration
TABLES : Ekko, " Purchasing Doc Header
Ekpo, " Purchasing Doc Item
Ekkn, " A/C assignment in Purchasing Doc
Prps. " WBS Element Master Data
*Constants
CONSTANTS : tab TYPE C VALUE ',', " for use as Delimiter
logsys TYPE PATHINTERN VALUE 'DITEST'. "logical file name
Type-pools : wod1t.
Variables
Variable for Application server file
DATA : v_file(128) type c.
Structure to get data into internal table from the source file
TYPES : BEGIN OF ST_LOAD,
EBELN TYPE EKKO-EBELN,
BUKRS TYPE EKKO-BUKRS,
EBELP TYPE EKPO-EBELP,
KNTTP TYPE EKPO-KNTTP,
ZEKKN TYPE EKKN-ZEKKN,
SAKTO TYPE EKKN-SAKTO,
KOSTL TYPE EKKN-KOSTL,
POSID TYPE PRPS-POSID,
END OF ST_LOAD.
Structure for application server data
TYPES : Begin of St_text,
text(1024) Type c,
End of St_text.
Internal table for Application file
DATA i_text TYPE STANDARD TABLE of St_text.
Internal tables from structures for use in BAPI_PO_CHANGE.
DATA : i_poheader TYPE bapimepoheader,
i_poheaderx TYPE bapimepoheaderx.
DATA: Begin of i_poitem occurs 0.
include structure bapimepoitem.
DATA: End of i_poitem.
DATA: Begin of i_poitemx occurs 0.
include structure bapimepoitemx.
DATA: End of i_poitemx.
DATA: Begin of i_poaccount occurs 0.
include structure bapimepoaccount.
DATA: End of i_poaccount.
DATA: Begin of i_poaccountx occurs 0.
include structure bapimepoaccountx.
DATA: End of i_poaccountx.
*"Internal Tables like bapi return type to store error logs"
DATA: L_T_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,
L_T_MSG LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
Internal Table for File data
DATA : I_LOAD TYPE STANDARD TABLE OF ST_LOAD,
I_DOWNLOAD TYPE STANDARD TABLE OF ST_LOAD.
Work Area
DATA : W_LOAD TYPE ST_LOAD, "Work area for I_load
W_TEXT LIKE LINE OF I_TEXT, "Internal table like line of I_text
W_RETURN TYPE BAPIRET2, "WORk Area for error logs from BAPI
WL_LOAD TYPE ST_LOAD. "Temporary Itab of type I_load
Work area for App server file
DATA : v_repid TYPE sy-repid, " Report ID
v_lines TYPE sy-index. " Line count
DATA: msg_cont TYPE STRING,
v_temp_file TYPE string. " Filename.
Selection-screen
SELECTION-SCREEN : BEGIN OF BLOCK BLK WITH FRAME TITLE TEXT-001.
PARAMETERS: R_APP RADIOBUTTON GROUP RADI ,
R_PRE RADIOBUTTON GROUP RADI DEFAULT 'X' .
SELECTION-SCREEN: SKIP 1.
Parameters : p_file(256) , " Name of Input File from Presentation
Server
ap_file(256) default 'App Serv'. " Default App Serv Path
Selection-Screen : skip 1.
Selection-Screen : End of Block blk.
INITIALIZATION.
v_repid = sy-repid.
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
IF R_PRE = 'X'.
PERFORM FILENAME_GET USING P_FILE.
Main Processing for all Select query and get the data into internal
table
ENDIF.
Start-Of-Selection.
Get the data from File to Internal Table
If r_pre = 'X'.
Perform f_get_data.
Perform p_format_iload.
Endif.
Get the data from Application Server directory to Internal Table
IF r_app = 'X'.
Open the file at Application Server
PERFORM p_open_appliaction.
Read the file at Application server
PERFORM p_read_application.
Close the file at Application server file.
PERFORM p_close_application.
Format the data into I_LOAD Internal table
PERFORM p_format_iload.
ENDIF.
Top-of-page.
*SKIP 1.
Uline .
Write:/10 'DATE:' color 3,17 sy-datum color 3,
45 'Log Report for Purchase Order Updation' color 3,100
'Page:' color 3,107 sy-pagno color 3.
Uline .
Skip 1.
End-of-Selection.
CLEAR: W_LOAD,
WL_LOAD,
L_T_RETURN,
W_RETURN,
L_T_MSG.
REFRESH: L_T_RETURN,
L_T_MSG.
Sort I_LOAD BY EBELN.
TO UPLOAD EACH REC FROM THE INTERNAL TABLE INTO BAPI
I_DOWNLOAD[] = I_LOAD.
loop at i_load into w_load.
WL_LOAD = W_LOAD.
AT NEW EBELN.
Checking to see if Company code is Not Null
IF WL_LOAD-BUKRS NE ' '.
TRANSLATE WL_LOAD-BUKRS TO UPPER CASE. "
PERFORM F_BUKRS_001 USING WL_LOAD.
ENDIF.
ENDAT.
IF WL_LOAD-EBELP IS NOT INITIAL AND
WL_LOAD-EBELP NE ''.
I_POITEM-PO_ITEM = W_LOAD-EBELP.
I_POITEM-ACCTASSCAT = W_LOAD-KNTTP.
I_POITEMX-PO_ITEM = W_LOAD-EBELP.
I_POACCOUNT-PO_ITEM = W_LOAD-EBELP.
I_POACCOUNT-SERIAL_NO = W_LOAD-ZEKKN.
I_POACCOUNT-GL_ACCOUNT = W_LOAD-SAKTO.
IF I_POITEM-ACCTASSCAT = 'K'.
I_POACCOUNT-COSTCENTER = W_LOAD-KOSTL.
I_POACCOUNTX-COSTCENTER = 'X'.
ENDIF.
IF I_POITEM-ACCTASSCAT = 'P'.
I_POACCOUNT-WBS_ELEMENT = W_LOAD-POSID.
I_POACCOUNTX-WBS_ELEMENT = 'X'.
ENDIF.
I_POACCOUNTX-PO_ITEM = W_LOAD-EBELP.
I_POACCOUNTX-SERIAL_NO = '01'.
I_POACCOUNTX-GL_ACCOUNT = 'X'.
APPEND I_POACCOUNTX.
APPEND I_POACCOUNT.
APPEND I_POITEM.
APPEND I_POITEMX.
ENDIF.
L_T_MSG[] = L_T_RETURN[].
CLEAR L_T_RETURN.
REFRESH L_T_RETURN.
AT END OF EBELN.
**/ Calling BAPI for PO Change
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
PURCHASEORDER = W_LOAD-EBELN
poheader = i_poheader
poheaderx = i_poheaderx
TABLES
POITEM = I_POITEM
POITEMX = I_POITEMX
POACCOUNT = I_POACCOUNT
POACCOUNTX = I_POACCOUNTX
RETURN = L_T_RETURN. " RETURN ERROR LOG
/ Using BAPI_TRANSACTION_COMMIT TO COMMIT THE DATA TO THE PO.
READ TABLE L_T_RETURN INTO W_RETURN
WITH KEY TYPE = 'E'.
IF SY-SUBRC GE 4.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = SPACE.
ENDIF.
Move error PO to File Internal Table
READ TABLE L_T_RETURN INTO W_RETURN
WITH KEY TYPE = 'E'.
IF SY-SUBRC GE 4.
LOOP AT I_DOWNLOAD INTO W_LOAD WHERE EBELN = WL_LOAD-EBELN.
DELETE I_DOWNLOAD WHERE EBELN = WL_LOAD-EBELN.
ENDLOOP.
ENDIF.
Log Message from BAPI Function Module
CLEAR W_RETURN.
SORT L_T_RETURN BY TYPE.
LOOP AT L_T_RETURN INTO W_RETURN.
MOVE-CORRESPONDING W_RETURN TO L_T_MSG.
COLLECT L_T_MSG. " GROUPING THE MESSAGES IN ERROR LOG
ENDLOOP.
CLEAR W_RETURN.
*/Clearing & Refreshing the internal tables
CLEAR I_POITEM.
CLEAR I_POITEMX.
CLEAR I_POHEADER.
CLEAR I_POACCOUNT.
CLEAR I_POACCOUNTX.
REFRESH : I_POITEM,
I_POITEMX,
I_POACCOUNT,
I_POACCOUNTX.
ENDAT. " FROM ( AT END )
*Display Error or Success Messages to USER
SORT L_T_MSG BY TYPE. " SORTING ERROR LOG BEFORE DISPLAY
LOOP AT L_T_MSG INTO W_RETURN.
CLEAR MSG_CONT.
IF W_RETURN-TYPE = 'S'. " RETURN TYPE SUCCESS
CONCATENATE TEXT-001
W_LOAD-EBELN
INTO MSG_CONT.
WRITE:/10 MSG_CONT COLOR 5,
40 W_RETURN-MESSAGE COLOR 5.
ELSEIF W_RETURN-TYPE = 'E'. " RETURN TYPE ERROR
CONCATENATE 'Error:'
TEXT-001
W_LOAD-EBELN
INTO MSG_CONT.
WRITE:/10 MSG_CONT COLOR 6,
40 W_RETURN-MESSAGE COLOR 6.
ELSEIF W_RETURN-TYPE = 'W'. " RETURN TYPE WARNING
CONCATENATE 'Warning:'
TEXT-001
W_LOAD-EBELN
INTO MSG_CONT.
WRITE:/10 MSG_CONT COLOR 6,
40 W_RETURN-MESSAGE COLOR 6.
ENDIF.
ENDLOOP."FROM L_T_MSG
ENDLOOP. " FROM I_LOAD
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'c:\download.txt'
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = ','
TABLES
DATA_TAB = i_download
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
&----
*& Form -
>>>>>>>> f_get_data <<<<<<<<<----
&----
FORM f_get_data.
v_temp_file = p_file.
Calling function GUI_UPLOAD to get data from comma delimited
file into internal table in SAP.
CALL Function 'GUI_UPLOAD'
EXPORTING
filename = v_temp_file
filetype = 'ASC'
has_field_separator = ','
read_by_line = 'X'
dat_mode = ' '
ignore_cerr = 'Y'
replacement = ' '
TABLES
data_tab = i_text
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
others = 17.
IF sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
Endif.
Writing Total Records in File
Describe table i_text lines v_lines.
Write:/15 'Total Records in File' Color 3 ,V_lines color 3.
Skip 1.
Endform . " f_get_data.
&----
*& Form FILENAME_GET
&----
Open windows file explorer to select file
----
--> PL_FILEPATH File name path
----
FORM filename_get using pl_filepath.
CALL Function 'WS_FILENAME_GET'
EXPORTING
mask = ',.,..'
mode = 'O'
title = 'File Name'(003)
IMPORTING
filename = pl_filepath
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
others = 5.
Endform. " FILENAME_GET
&----
*& Form p_open_appliaction
&----
* Open the file at Application Server
----
Form p_open_appliaction.
v_file = ap_file.
OPEN Dataset v_file for input in text mode ENCODING DEFAULT.
If sy-subrc ne 0.
message i123(zz).
Write a error message like " File not found ".
Stop.
Endif.
Endform. " p_open_appliaction
&----
*& Form p_read_application
&----
text
----
Form p_read_application.
DO.
clear w_text.
read dataset v_file into w_text .
If syst-subrc <> 0.
exit.
Endif.
Append w_text to i_text.
EndDo.
Writing Total Records in File
Describe table i_text lines v_lines.
Write:/15 'Total Records in File' Color 3 ,V_lines color 3.
Skip 1.
Endform. " p_read_application
&----
*& Form p_close_application
&----
Close the file
----
Form p_close_application.
Close dataset v_file.
Endform. " p_close_application
&----
*& Form p_format_iload
&----
Move the data into I_LOAD Internal Table
----
Form p_format_iload.
Loop at i_text into w_text.
Using Split to split the data from line into fields.
Split w_text-text at tab into w_load-ebeln
w_load-bukrs
w_load-ebelp
w_load-knttp
w_load-zekkn
w_load-sakto
w_load-kostl
w_load-posid.
APPEND w_load TO i_load.
clear w_load.
Endloop.
Endform. " p_format_iload
&----
*& Form f_bukrs_001
&----
text
----
FORM F_BUKRS_001 USING W_LOAD TYPE ST_LOAD.
I_POHEADER-PO_NUMBER = W_LOAD-EBELN.
I_POHEADER-COMP_CODE = W_LOAD-BUKRS.
I_POHEADERX-COMP_CODE = 'X'.
ENDFORM. " f_bukrs_001
2007 May 23 12:01 AM
I have tried using the BAPI function module but is not not updating the record. All I am trying to do is uncheck the delivery complete box and it is not doing it. Not even when I run it from SE37.
Thanks
Mike
2007 May 23 12:06 AM
2007 May 23 2:48 PM
Thanks for the input, I looked at function module ME_UPDATE_SCHEDULE_EKPO does not update the field I need....I need to update field ELIKZ in table EKPO.
Thanks
Mike
2007 May 23 3:00 PM
Hi Michael,
You can use BAPI BAPI_PO_CHANGE to update EKPO-ELIKZ.
There are table parameters to set EKPO-ELIKZ.
POITEM-NO_MORE_GR = 'X'
POITEMX-NO_MORE_GR = 'X'
Regards,
Ferry Lianto
2007 May 23 3:56 PM
Thanks, I have tried that but it does not work. According to the documentation it will not update some PO's based on a firewall and certain types of invoicing. I tried to update other fields as well and they don't work either.
2007 Jun 01 3:18 PM
I second that. Unless you have specific business needs I suggest
you go with the BAPI.
2007 May 23 3:07 PM
HI Michael
First of check whether there is Gui elements in ME22. If yes then disable then and then try to use BDC for the same.
Let me know if u haven't solved ur problem.
Need ur reward points.
Regards
ravi
2007 May 23 3:17 PM
Hi, How can I disable the GUI elements in ME22 in my program? I have never done that before.
Thanks
Mike
2007 May 23 3:23 PM
i dont have access SAP now. Can send me the screen shot for ME22 screens. I will tell u how to disable.
My mail [email protected]
2007 May 24 3:39 PM
Hi Ravi, can you now tell me how to disable the gui so I can run this BDC in the background?
Thanks
Mike
2007 Jun 01 3:54 PM
Hi Michael
Sorry for delay. Actually today only i saw this transaction.
The problem in this transaction is,we need disable the object navigator. To do this, Right click on this transaction ME22. U can find option call Truncate ON/OFF(I am not sure about the term Truncate. Just check there is a option ON/OFF).U need to OFF this option. Then u can able to Run this tcode.
or else u need to disable one option in SU01 Tcode. I will check and inform u soon.
Reward me if its useful.
Let me know if ur problem not sloved.
Regards
Ravi
2007 May 31 9:34 PM
I have the same, problem but using BP (CRM's transaction).
Mike, did you fix the problem?
Thanks!
Robson
2007 Jun 01 2:36 PM
No, we did not get the problem fixed. We are going to write our own function module that should work for us. It is not the best solution but we needed a way to set the flag.
2007 Jun 01 3:55 PM
Hi Michael
Sorry for delay. Actually today only i saw this transaction.
The problem in this transaction is,we need disable the object navigator. To do this, Right click on this transaction ME22. U can find option call Truncate ON/OFF(I am not sure about the term Truncate. Just check there is a option ON/OFF).U need to OFF this option. Then u can able to Run this tcode.
or else u need to disable one option in SU01 Tcode. I will check and inform u soon.
Reward me if its useful.
Let me know if ur problem not sloved.
Regards
Ravi
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |