‎2005 Dec 05 4:04 PM
Hi,
I am creating a PO using bapi BAPI_PO_CREATE1 in exit USEREXIT_SAVE_DOCUMENT_PREPARE.
I dont want to write the code in my exit. Instead I want to write the code in a Z program and call it in my exit.
My Problem.
How do I call my z program in my exit so that I can pass internal tables from my exit to the z program. Also I want to schedule the call of my external program for background processing.
I am trying with SUBMIT ZPROG AND RETURN. But not able to pass an internal table.
I tried PERFORM BAPI_PO_CREATE IN PRGRAM ZPROG, but in this case not able to schedule it in background.
Please advise.
Regards,
Shobhit
‎2005 Dec 05 4:36 PM
Why do you want to do this in a different program? You'll be adding overhead by submitting a background job. If you do it in foreground with AND RETURN, you'll have to wait for the program to finish before the dialogue can continue.
Rob
‎2005 Dec 05 4:14 PM
Hi Shobhit,
Put a break point in your exit & see whether the Exit is firing.
‎2005 Dec 05 4:18 PM
Hi Phani,
The exit is very well firing as my code is working using the PERFORM.. method. But I want to schedule the perform in the background. For that I tried using SUBMIT.. but not able to pass internal table.
Regards,
Shobhit
‎2005 Dec 05 4:22 PM
‎2005 Dec 05 4:29 PM
Hi Shobhit,
Try to Proceed according to Rich's Idea.
regards
vijay
‎2005 Dec 05 4:16 PM
You need to pass the data using shared memory buffer. Here is an example.
This example gets data from MARA into an internal table, then exports the internal table to shared memory, then it schedules a background job for ZRICH_0005. In the ZRICH_0005, it imports the internal table and writes it out. This is the functionality that you are looking for.
Program A.
report zrich_0001 .
data: l_valid,
ls_params like pri_params,
l_jobcount like tbtcjob-jobcount,
l_jobname like tbtcjob-jobname,
l_key(60) type c.
data: imara type table of mara with header line.
start-of-selection.
select * into corresponding fields of table imara
from mara
up to 100 rows.
<b> concatenate 'RICHTEST' sy-datum into l_key.
export imara = imara
to shared buffer indx(st) id l_key.</b>
* Get Print Parameters
call function 'GET_PRINT_PARAMETERS'
exporting
no_dialog = 'X'
importing
valid = l_valid
out_parameters = ls_params.
* Open Job
l_jobname = 'ZRICH_0005'.
call function 'JOB_OPEN'
exporting
jobname = l_jobname
importing
jobcount = l_jobcount.
* Submit report to job
submit zrich_0005
via job l_jobname
number l_jobcount
to sap-spool without spool dynpro
spool parameters ls_params
and return.
* Schedule and close job.
call function 'JOB_CLOSE'
exporting
jobcount = l_jobcount
jobname = l_jobname
strtimmed = 'X'.
Program B.
report zrich_0005 .
data: l_key(60) type c.
data: imara type table of mara with header line.
start-of-selection.
<b> concatenate 'RICHTEST' sy-datum into l_key.
import imara = imara
from shared buffer indx(st) id l_key.
delete from shared buffer indx(st) id l_key.</b>
loop at imara.
write:/ imara-matnr, imara-matkl.
endloop.
Regards,
Rich Heilman
‎2005 Dec 05 4:18 PM
You could try using the IMPORT/EXPORT FROM/TO MEMORY method
you could do this in your exit:
EXPORT it_table TO MEMORY ID 'MY_MEM_ID'.
In your Z scheduled program you could:
IMPORT it_table FROM MEMORY ID 'MY_MEM_ID'.
Note: Don't forget to declare the it_table in the Z program too.
‎2005 Dec 05 4:36 PM
Why do you want to do this in a different program? You'll be adding overhead by submitting a background job. If you do it in foreground with AND RETURN, you'll have to wait for the program to finish before the dialogue can continue.
Rob
‎2005 Dec 05 4:46 PM
Hi Rich and Rob!!
Thank you both!! Ill b following Rich's idea. I need to send the PO crearion to background because I want the Delivery to be created successfully after which only I want the background job to execute. (After checking the successful completion of the dialog)
Now I have another problem. I need to put a popup screen to take two input values to the user. These values would be required to create the PO in background.
How and where should I create this popup screen? in the exit or in the z program?
Thanks for any kind of help.
Regards,
Shobhit
‎2005 Dec 05 4:53 PM
If the Z program is in the background, you'll need the popup in the exit.
Rob
‎2005 Dec 05 4:54 PM
I would put it in the exit since it is in the foreground. Try something like this.
report zrich_0001 .
data: fields type table of sval with header line.
fields-tabname = 'EKKO'.
fields-fieldname = 'EBELN'.
append fields.
fields-tabname = 'EKPO'.
fields-fieldname = 'EBELP'.
append fields.
call function 'POPUP_GET_VALUES'
exporting
* NO_VALUE_CHECK = ' '
popup_title = 'Test'
* START_COLUMN = '5'
* START_ROW = '5'
* IMPORTING
* RETURNCODE =
tables
fields = fields
* EXCEPTIONS
* ERROR_IN_FIELDS = 1
* OTHERS = 2
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
Please make sure to award points for helpful answers. Thanks.
Regards,
Rich Heilman
‎2005 Dec 05 5:00 PM
‎2005 Dec 05 5:04 PM
‎2005 Dec 05 6:48 PM
Hi Rich,
Im setting runtime error:
My Code in Exit: (xvbfa is the table which i wanna pass)
concatenate 'SERVICEPO' sy-datum into l_key.
export xvbfa = xvbfa
to shared buffer indx(st) id l_key.
My Code in the called program ZMM_SERVICE_PO
Runtime Errors CONNE_IMPORT_WRONG_OBJECT_TYPE
Exceptn CX_SY_IMPORT_MISMATCH_ERROR
Date and Time 05.12.2005 21:41:54
ShrtText
Error when attempting to IMPORT object "XVBFA".
What happened?
Error in ABAP application program.
The current ABAP program "ZMM_SERVICE_PO" had to be terminated because one of
the
statements could not be executed.
This is probably due to an error in the ABAP program.
When importing the object "XVBFA", the object in the
dataset had a different type from the target object in the program
"ZMM_SERVICE_PO" (object types: field, field string/structure, table).
table).
Error analysis
An exception occurred. This exception will be dealt with in more detail
below. The exception, assigned to the class 'CX_SY_IMPORT_MISMATCH_ERROR', was
not caught, which
led to a runtime error. The reason for this exception is:
The object "XVBFA" has a different object type in the dataset from
that in the target program "ZMM_SERVICE_PO". (Object types: Field, flat
structure,
deep structure, flat table, deep table).
Missing Handling of System Exception
Program ZMM_SERVICE_PO
Trigger Location of Exception
Program ZMM_SERVICE_PO
Include ZMM_SERVICE_PO
Row 43
Module Name START-OF-SELECTION
Source Code Extract
Line SourceCde
REPORT ZMM_SERVICE_PO.
DATA: l_poheader LIKE bapimepoheader.
DATA: l_poheaderx LIKE bapimepoheaderx.
DATA: l_poitem LIKE bapimepoitem OCCURS 0 WITH HEADER LINE.
DATA: l_poitemx LIKE bapimepoitemx OCCURS 0 WITH HEADER LINE.
DATA: l_cond LIKE BAPIMEPOCOND OCCURS 0 WITH HEADER LINE.
DATA: l_condx LIKE BAPIMEPOCONDX OCCURS 0 WITH HEADER LINE.
DATA: l_poschedule LIKE bapimeposchedule OCCURS 0 WITH HEADER LINE.
DATA: l_poschedulex LIKE bapimeposchedulx OCCURS 0 WITH HEADER LINE.
DATA: l_purchaseorder LIKE bapimepoheader-po_number.
DATA: l_return TYPE BAPIRET2 OCCURS 0.
DATA: l_error_found TYPE c.
DATA: l_show_messages TYPE c.
DATA: l_eindt(10) TYPE c.
DATA: l_answer TYPE c.
DATA: l_VBAK TYPE STANDARD TABLE OF VBAK WITH HEADER LINE.
DATA: l_VBFA TYPE STANDARD TABLE OF VBFA WITH HEADER LINE.
DATA: xlips TYPE STANDARD TABLE OF LIPS WITH HEADER LINE.
*DATA: xvbfa TYPE STANDARD TABLE OF vbfa WITH HEADER LINE.
DATA xvbfa like vbfa.
DATA: l_key(60) type c.
concatenate 'SERVICEPO' sy-datum into l_key.
>>>>> import xvbfa = xvbfa
from shared buffer indx(st) id l_key.
delete from shared buffer indx(st) id l_key.
Could you help.
Regads,
Shobhit
‎2005 Dec 05 6:50 PM
‎2005 Dec 05 6:51 PM
Your xvbfa in the user exit might be having a different structure compared to what you declared in your ZMM_SERVICE_PO. They have to have the same structure.
Srinivas
‎2005 Dec 05 6:54 PM
Here is the definition of XVBFA in SAPMV45A, include VBFADATA.
data: begin of xvbfa occurs 0.
include structure vbfavb.
data: end of xvbfa.
‎2005 Dec 05 6:58 PM
WHy can't you open another thread as every can see this..
Becaue this is already closed..
regards
vijay
‎2005 Dec 05 7:01 PM
Hi Rich,
It is an internal table only. Im just tryin diff ways to define n internal table. Thats why u see the commented line. Still I get the same error.
If you don't mind, may I have your email id?
Thanks & Regards,
Shobhit
‎2005 Dec 05 7:03 PM
Shobhit, please look at my response. Change your xvbfa definition to that of the include, then it will be ok.
Srinivas
‎2005 Dec 05 7:03 PM
‎2005 Dec 05 7:13 PM
Sorry guys!! my mistake.. the structure is vbfadata!!
It worked!!! :-). The values got passed successfully!!!
Now, could someoneexplain me the meaning of the statement:
"from shared buffer indx(st) id l_key."
Since numerous Deliveries would be created in a day (might happen at the same instance of time also), the l_key value should be unique. Can someone explain.
Regards,
Shobhit
‎2005 Dec 05 7:17 PM
Then you should add a unique identifier to the key, maybe delivery number. This way you are assuring that you will be getting the right data. You will have to pass the delivery note number thru to the submitted program. It might be easier to pass the entire key.
concatenate 'RICHTEST' sy-datum vbfa-vbeln into l_key.
Submit program
with p_key = l_key.Regards,
Rich Heilman]
‎2005 Dec 05 7:21 PM
Your l_key should be unique, otherwise you will be overwriting the values. Include the document number in your key so that it will be unique.
‎2005 Dec 05 7:24 PM
Hi Rich,
You are right. But thats what the problem is. In the exit I can very well add any identifier like a delivery no.
But when I enter my submitted program, I do not have any value from the delivery. In order to establish a link (key field) between my exit and the submitted program, I am writing all this logic.
So I dont have any identification to concatenate when im in the submitted program.
Reg,
Shobhit
‎2005 Dec 05 7:31 PM
That's why I am saying that you should pass the key thru the parameters. In your submitted program....
data: l_key(60) type c.
Parameters: p_key(60) type c.
import ivbfa = ivbfa from .......
id l_key.So you are passing the key thru the parameters, and the interal table thru global memory. Now in the submitted program you know exactly what the key is.
Regards,
Rich Heilman