03-20-2013 6:20 AM
Dear Experts,
Please help me regarding this.....
In my requirement my user wants to create an invoice automatically and sends it to local printer for printing when PGI button is clicked on Vl01n/Vl02n
screen with respect to delivery.
I tried using Badi LE_SHP_DELIVERY_PROC. In this badi i tried methods save_document_prepare,SAVE_AND_PUBLISH_DOCUMENT,SAVE_AND_PUBLISH_BEFORE_OUTPUT,SAVE_AND_PUBLISH_DOCUMENT.
I tried userexits in SAPMV50A~MV50AFZ1----USEREXIT_SAVE_DOCUMENT,USEREXIT_SAVE_DOCUMENT_PREPARE.
my sample code as follows...
BREAK-POINT.
data : t_vbrk type TABLE OF bapivbrk," WITH HEADER LINE,
w_vbrk type bapivbrk ,"WITH HEADER LINE,
return type TABLE OF bapiret1," WITH HEADER LINE,
w_return type bapiret1," WITH HEADER LINE,
success type TABLE OF BAPIVBRKSUCCESS," WITH HEADER LINE.
w_success type BAPIVBRKSUCCESS ,"WITH HEADER LINE.
xlikp type likp.
loop at ct_xlikp into xlikp.
if xlikp-vkorg eq 'RME1' and sy-ucomm eq 'WABU_T'.
w_vbrk-ordbilltyp = xlikp-fkarv. " likp MANDATORY
w_vbrk-ref_doc = xlikp-vbeln. " likp MANDATORY
w_vbrk-ref_doc_ca = 'J'. " hard code MAINTAINED IN LIKP TABLE MADATORY
append w_vbrk to t_vbrk.
CLEAR w_vbrk.
CALL FUNCTION 'BAPI_BILLINGDOC_CREATEMULTIPLE'
EXPORTING
* CREATORDATAIN =
TESTRUN = 'X'
* POSTING =
TABLES
BILLINGDATAIN = t_vbrk
* CONDITIONDATAIN =
* CCARDDATAIN =
* TEXTDATAIN =
* ERRORS =
RETURN = return
SUCCESS = success.
endif.
endloop.
But I am getting error in Return table as "VF 066 Goods issue has not been posted for the delivery"...
Kindly please help me on this to find a right userexit/badi after the PGI Posted .....
I need to close this immediately.....
anybody please help me on this....
Thanks and Regards
Mahesh.P
03-21-2013 11:25 AM
Dear Mahesh,
Have you solved your issue if not please find the below code as i checked it is working ok here.
First create enhacement in FV50XF0B_BELEG_SICHERN as you said earlier i checked it you can create enhancement in that.
IF v50agl-no_commit = ' ' AND
v50agl-sofauftrag NE charx.
* Bei Aufruf aus Verpacken wird der Commit extern gesetzt
PERFORM sd_monitor_protocol_save.
IF v50agl-synchron NE charx.
COMMIT WORK.
ELSE.
COMMIT WORK AND WAIT.
ENDIF.
ENDIF.
data : t_vbrk type TABLE OF bapivbrk," WITH HEADER LINE,
w_vbrk type bapivbrk ,"WITH HEADER LINE,
return type TABLE OF bapiret1," WITH HEADER LINE,
w_return type bapiret1," WITH HEADER LINE,
success type TABLE OF BAPIVBRKSUCCESS," WITH HEADER LINE.
w_success type BAPIVBRKSUCCESS ,"WITH HEADER LINE.
* xlikp type likp,
lw_likp TYPE likp.
DATA : lv_wait TYPE bapita-wait VALUE 'X'.
if sy-ucomm eq 'WABU_T' AND ( SY-TCODE = 'VL01N' OR SY-TCODE = 'VL02N' ).
WAIT UP TO 3 SECONDS.
loop at xlikp into lw_likp.
if lw_likp-vkorg eq '1000' and sy-ucomm eq 'WABU_T'.
w_vbrk-ordbilltyp = lw_likp-fkarv. " likp MANDATORY
w_vbrk-ref_doc = lw_likp-vbeln. " likp MANDATORY
w_vbrk-ref_doc_ca = 'J'. " hard code MAINTAINED IN LIKP TABLE MADATORY
append w_vbrk to t_vbrk.
CLEAR w_vbrk.
CALL FUNCTION 'BAPI_BILLINGDOC_CREATEMULTIPLE'
EXPORTING
* CREATORDATAIN =
TESTRUN = ' ' "'X'
POSTING = ' '
TABLES
BILLINGDATAIN = t_vbrk
* CONDITIONDATAIN =
* CCARDDATAIN =
* TEXTDATAIN =
* ERRORS =
RETURN = return
SUCCESS = success.
ENDIF.
endloop.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = lv_wait
* IMPORTING
* RETURN =
.
endif.
with regards
vikas pandey
03-20-2013 9:45 AM
Dear Mahaesh,
You can use your code in method DELIVERY_FINAL_CHECK of BADI LE_SHP_DELIVERY_PROC
It will work perfectly as i already impleted to check packing at PGI
with regards
vikas pandey
03-20-2013 9:49 AM
Dear,
use this method
SAVE_AND_PUBLISH_BEFORE_OUTPUT of badi LE_SHP_DELIVERY_PROC
with regards
vikas pandey
03-20-2013 10:03 AM
Thanks Vikas,
But in the two methods u mentioned DELIVERY_FINAL_CHECK,SAVE_AND_PUBLISH_BEFORE_OUTPUT
Bapi is still throwing error message
in Return table as "VF 066 Goods issue has not been posted for the delivery"...
Is there any thing in my code i am missing to pass to the bapi...
i found one Perform BELEG_SICHERN_POST in FV50XF0B_BELEG_SICHERN , where i found
MB_POST_GOODS_MOVEMENT ,,I tried to create implicit Enhancement after this,But the
subroutine FV50XF0B_BELEG_SICHERN is not allowing to create enhancements..
any alternative ideas......
Please help....
Thanks & Regards
Mahesh.P
03-20-2013 12:49 PM
Hello,
I think you are facing the issue because the commit is yet to be done on the PGI.
One option that you can go about is -
1 - Create a Z function module with importing parameters like table CT_LIKP.
2 - Inside the FM, Put a wait for 1 or 2 seconds, using WAIT FOR 2 SECONDS.
3 - After the waiting time is over, call the BAPI to create the invoice.
4 - Call the new function module created with "STARTING IN A NEW TASK".
CALL FUNCTION ZINVOICE
STARTING IN A NEW TASK
EXPORTING
IT_LIKP = CT_LIKP
Let me know in case of issues.
Cheers!
Abhinab.
03-20-2013 1:04 PM
When writing
4 - Call the new function module created with "STARTING IN A NEW TASK".
were you thinking
4 - Call the new function module created with "IN BACKGROUND TASK".
then you could remove the wait ?
Regards,
Raymond
03-20-2013 1:08 PM
Thanks Abhinab,
As you suggested instead of going for a new ZFM,,,, we can write the WAIT statement in the above code itself.....naa
My code as follows........
BREAK-POINT.
data : t_vbrk type TABLE OF bapivbrk WITH HEADER LINE,
return type table of bapiret1 WITH HEADER LINE,
success type table of BAPIVBRKSUCCESS WITH HEADER LINE.
if xlikp-vkorg eq 'RME1' and sy-ucomm eq 'WABU_T'.
t_vbrk-ordbilltyp = likp-fkarv. " likp MANDATORY
t_vbrk-ref_doc = likp-vbeln. " likp MANDATORY
t_vbrk-ref_doc_ca = 'J'. " hard code MAINTAINED IN LIKP TABLE MADATORY
append t_vbrk.
CALL FUNCTION 'BAPI_BILLINGDOC_CREATEMULTIPLE'
EXPORTING
* CREATORDATAIN =
TESTRUN = 'X'
* POSTING =
TABLES
BILLINGDATAIN = t_vbrk
* CONDITIONDATAIN =
* CCARDDATAIN =
* TEXTDATAIN =
* ERRORS =
RETURN = return
SUCCESS = success.
wait UP TO 5 SECONDS.
if return-type = 'E'.
call function 'BAPI_BILLINGDOC_CREATEMULTIPLE'
* EXPORTING
* CREATORDATAIN =
* TESTRUN =
* POSTING =
tables
billingdatain = t_vbrk
* CONDITIONDATAIN =
* CCARDDATAIN =
* TEXTDATAIN =
* ERRORS =
return = return
success = success .
endif.
endif.
now i am getting dump .....
please help me on this.......
Regards
Mahesh.P
03-20-2013 1:27 PM
Mahesh :Y ou can't put WAIT in the BADI. It will hold the current processing.
You have to create a new FM, either call it in a background task as Raymond suggested without the wait, or call it in a new task with a second wait.
Raymond : Thanks , In fact I didn't thought about the background task addition in a hustle.
But yes the addition of background task is the apt idea for this situation as the FM will be registered to the running LUW and will be triggered according to the sequence in a COMMIT WORK. Please let me know if I am wrong.
Thanks
Abhinab
03-20-2013 1:27 PM
If you go to this solution (performance due to 5 seconds wait...) write at least as
if return-type = 'E'.
wait UP TO 5 SECONDS. " Only wait if required
call function 'BAPI_TRANSACTION_ROLLBACK'. " And some cleaning
call function 'BAPI_BILLINGDOC_CREATEMULTIPLE' " retry
etc.
Regards,
Raymond
03-20-2013 1:37 PM
Thanks Abhinab....
I am little bit confused here.....
What you want me to do is
1.create a zfm with importing param as ct_likp
2.call bapi in that zfm
3.call that zfm In the Badi~SAVE_AND_PUBLISH_BEFORE_OUTPUT in background task...
Right,,
Regards
Mahesh.P
03-20-2013 1:46 PM
03-20-2013 4:30 PM
It's not possible to do this in any user exit/enhancement, etc. When PGI button is clicked, a goods movement document is created. This document must be posted successfully and delivery status updates must be completed before an invoice may be created. Invoice (billing document) creation is actually a completely different transaction (it also creates an FI document), it's not efasible to initiate it in the same update task as PGI.
You can try delivery output with 'special function' (output is processed after the main document update) but I'd suggest just to schedule Billing Due list (SDBILLDL) to run every 5 minutes. It'll create the invoices properly with no additional effort and I bet no one will notice the difference. Actually you can also do PGI automatically in the same job, so as soon as picking is completed, delivery would be PGIed and billed automatically.
03-21-2013 7:00 AM
Hello Jelena,
I am not sure why you said this is not possible
As technically I can see this requirement is feasible and achievable.
Cheers!
Abhinab
03-21-2013 8:13 AM
Thanks Abhinab,
I tried creating ZFM and called it in the badi in background task,,,
I was not able to create Invoice Doc..
my code as
BREAK-POINT.
data return type bapiret2.
CALL FUNCTION 'ZAUTO_INVOICE_CREATE' in BACKGROUND TASK
EXPORTING
CT_LIKP = it_xlikp
CHANGING
IT_RETURN = return.
But invoice document is not getting created .
03-21-2013 9:36 AM
Mahesh,
In these cases, I will prefer to use the addition of "STARTING IN A NEW TASK" and keep a wait of few seconds at the starting of the FM.
The idea behind this is as follows
- The custom FM will be called in a new task, which will ensure the task of PGI is not interrupted.
- As in the start of the FM, an WAIT of some seconds is there, that means the BAPI will be called after the PGI has been posted to the DB.
- Make to call the FM in a Method , where the save process is triggered in the BADI.
I think this should solve your problem.
Let me know for conerns.
Cheers!
Abhinab.
03-21-2013 11:25 AM
Dear Mahesh,
Have you solved your issue if not please find the below code as i checked it is working ok here.
First create enhacement in FV50XF0B_BELEG_SICHERN as you said earlier i checked it you can create enhancement in that.
IF v50agl-no_commit = ' ' AND
v50agl-sofauftrag NE charx.
* Bei Aufruf aus Verpacken wird der Commit extern gesetzt
PERFORM sd_monitor_protocol_save.
IF v50agl-synchron NE charx.
COMMIT WORK.
ELSE.
COMMIT WORK AND WAIT.
ENDIF.
ENDIF.
data : t_vbrk type TABLE OF bapivbrk," WITH HEADER LINE,
w_vbrk type bapivbrk ,"WITH HEADER LINE,
return type TABLE OF bapiret1," WITH HEADER LINE,
w_return type bapiret1," WITH HEADER LINE,
success type TABLE OF BAPIVBRKSUCCESS," WITH HEADER LINE.
w_success type BAPIVBRKSUCCESS ,"WITH HEADER LINE.
* xlikp type likp,
lw_likp TYPE likp.
DATA : lv_wait TYPE bapita-wait VALUE 'X'.
if sy-ucomm eq 'WABU_T' AND ( SY-TCODE = 'VL01N' OR SY-TCODE = 'VL02N' ).
WAIT UP TO 3 SECONDS.
loop at xlikp into lw_likp.
if lw_likp-vkorg eq '1000' and sy-ucomm eq 'WABU_T'.
w_vbrk-ordbilltyp = lw_likp-fkarv. " likp MANDATORY
w_vbrk-ref_doc = lw_likp-vbeln. " likp MANDATORY
w_vbrk-ref_doc_ca = 'J'. " hard code MAINTAINED IN LIKP TABLE MADATORY
append w_vbrk to t_vbrk.
CLEAR w_vbrk.
CALL FUNCTION 'BAPI_BILLINGDOC_CREATEMULTIPLE'
EXPORTING
* CREATORDATAIN =
TESTRUN = ' ' "'X'
POSTING = ' '
TABLES
BILLINGDATAIN = t_vbrk
* CONDITIONDATAIN =
* CCARDDATAIN =
* TEXTDATAIN =
* ERRORS =
RETURN = return
SUCCESS = success.
ENDIF.
endloop.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = lv_wait
* IMPORTING
* RETURN =
.
endif.
with regards
vikas pandey
03-24-2013 8:49 AM
Dear Vikas...
Thanks for the help..........
Its working Perfectly...........
Regards
Mahesh.P
04-03-2013 9:25 PM
04-03-2013 9:26 PM
as i implemented the same and working fine as per my requirement
thank you vikas