Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Billing Copy control-invoice split by material document

Former Member
0 Kudos

Splitting the invoice based on the material Document(ekbe-belnr). Suppose i have 3 material documents for one Purchase order. Based on the 3 material documents, it shpould create 3 invoices. So for this i created a routine. Its for billing document copy control. But my routine is combining all the material document quantities and it creating only one invoice but i required multiple invoices based on no of material document. i wrote code like this. Its urgent..

FORM daten_kopieren_901.

TABLES: kna1.

DATA : v_kunnr TYPE kunag,

v_katr2 TYPE katr2,

v_belnr TYPE ekbe-belnr,

v_bewtp TYPE ekbe-bewtp.

DATA: BEGIN OF it_zuk1,

modul(3) VALUE '904',

vtweg LIKE vbak-vtweg,

spart LIKE vbak-spart,

belnr LIKE ekbe-belnr,

vgbel LIKE vbrp-vgbel,

END OF it_zuk1.

TYPES:BEGIN OF t_ekbe,

belnr TYPE ekbe-belnr,

bewtp TYPE ekbe-bewtp,

flag TYPE c, "Rajiv

END OF t_ekbe.

TYPES:BEGIN OF t_vbap,

vbeln TYPE vbap-vbeln,

posnr TYPE vbap-posnr,

END OF t_vbap.

TYPES:BEGIN OF t_vbep,

banfn TYPE vbep-banfn,

END OF t_vbep.

TYPES:BEGIN OF t_eban,

ebeln TYPE eban-ebeln,

ebelp TYPE eban-ebelp,

END OF t_eban.

STATICS:i_ekbe TYPE STANDARD TABLE OF t_ekbe.

DATA: wa_ekbe TYPE t_ekbe.

DATA: i_vbap TYPE STANDARD TABLE OF t_vbap.

DATA: i_vbep TYPE STANDARD TABLE OF t_vbep.

DATA: i_eban TYPE STANDARD TABLE OF t_eban.

SELECT vbeln posnr FROM vbap INTO TABLE i_vbap

WHERE vbeln = vbak-vbeln.

IF sy-subrc = 0.

SELECT banfn FROM vbep INTO TABLE i_vbep

FOR ALL ENTRIES IN i_vbap

WHERE vbeln = i_vbap-vbeln

AND posnr = i_vbap-posnr.

ENDIF.

IF sy-subrc = 0.

SELECT ebeln ebelp FROM eban INTO TABLE i_eban

FOR ALL ENTRIES IN i_vbep

WHERE banfn = i_vbep-banfn.

ENDIF.

IF sy-subrc = 0.

SELECT belnr bewtp FROM ekbe INTO TABLE i_ekbe

FOR ALL ENTRIES IN i_eban

WHERE ebeln = i_eban-ebeln

AND ebelp = i_eban-ebelp.

endif.

**

LOOP AT i_ekbe INTO wa_ekbe WHERE flag NE 'X'.

IF ( ( wa_ekbe-bewtp = 'E' ) OR ( wa_ekbe-bewtp = 'R' ) OR

( wa_ekbe-bewtp = 'Q' ) ).

it_zuk1-vtweg = vbak-vtweg.

it_zuk1-spart = vbak-spart.

it_zuk1-belnr = wa_ekbe-belnr.

it_zuk1-vgbel = vbrp-vgbel.

wa_ekbe-flag = 'X'.

MODIFY i_ekbe FROM wa_ekbe TRANSPORTING flag.

vbrk-zukri = it_zuk1.

EXIT.

ENDIF.

ENDLOOP.

REFRESH: i_vbap,i_vbep,i_eban,i_ekbe.

*

ENDFORM.

5 REPLIES 5

Former Member
0 Kudos

Hi,

Your routine will not work as you can only split invoices based on differences in the originating document. From your coding I guess you do order-related billing (and not delivery-related billing). This means you can either group orders to one invoice or split orders to multiple invoices.

Regards,

John.

0 Kudos

Hi John,

Thanks for the reply. But our requirement is to create one unique invoice for one GR document. It is a third party sales scenario and billing will happen basing on a sales order but the quantity should be derived from the GR document and for n number of GR's we should have n number of invoices. Kinldy help us by suggesting is there in any alternative for this.

Regards,

Ramana

0 Kudos

Hi Ramana,

I'm afraid this is not possible. Correct me if I'm wrong: You have a TPO scenario in which you create a purchase order for a sales order item. This purchase order may have multiple GR? As billing is based on the sales order position (which is only one) there is no way to split this one position into multiple lines for each GR. This would only work if there is a 1:1 relation between sales order item and GR!

Regards,

John.

abhirana_989
Discoverer
0 Kudos

Hi Ramana , I have also got the same requirement .

Did you find out the way to develop thsi requirement ??

moshenaveh
Community Manager
Community Manager
0 Kudos
Hello, While we're happy that you've come to SAP Community to get an answer to your question, you posted your question as an answer in an old thread.
I've converted your answer to a comment, but even so -- posting in older threads is not the best way to get guidance.
If you're looking for help, you should ask a new question: https://answers.sap.com/questions/ask.html.
Here are some tips to help you craft an effective question for our community: https://community.sap.com/resources/questions-and-answers, https://developers.sap.com/tutorials/community-qa.html, https://groups.community.sap.com/t5/welcome-corner-discussions/advice-from-sap-champions-questions-a....
I encourage you to follow this guidance, as I'd really like to see you get a solution to your problem.
I hope you find this advice useful!