10-10-2007 9:41 PM
Hi,
I am developing Credit Memo Details report, here user wants all the details of Credit Memo including Acct Docu Number based on Reference number.
The report is working fine if the Credit memo has account docu number, but now user wants this report to work if Cmemo does not have ACCtDocuNum also.
If ACCtDocuNum is not there, it has to display the remaining fields.
Can I use VBAK, VBAP and VBFA combination. Getting vbeln from VBAK based on s_XBLNR. Get item info from VBAP. Then get ACCTDOCUNUM from VBFA based on VBAK-VBELN and VBAP-POSNR.
Please help me if I am correct or should I use different table combination.
Thanks,
Neelu.
FORM get_data.
SELECT avbeln aposnr avgbel anetwr afkimg amatnr
bvkorg bvtweg bspart bkunag bxblnr bbstnk_vf
FROM vbrp AS a
INNER JOIN vbrk AS b
ON avbeln = bvbeln
INTO TABLE ivbrkp
WHERE b~xblnr IN s_xblnr
AND b~fkart = 'ZMKD'.
IF sy-subrc = 0.
SELECT kunnr matnr sprice eprice eohqty bstkd crmemo
FROM zppprice INTO TABLE izppprice
FOR ALL ENTRIES IN ivbrkp
WHERE kunnr = ivbrkp-kunag
AND matnr = ivbrkp-matnr
AND crmemo = ivbrkp-vgbel.
ENDIF.
ENDFORM. " get_data
&----
*& Form process_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM process_data.
DATA: lv_name1 LIKE kna1-name1,
lv_auart LIKE vbak-auart,
lv_augru LIKE vbak-augru,
lv_werks LIKE vbap-werks,
lv_fkdat LIKE vbkd-fkdat,
lv_knumv LIKE vbak-knumv,
lv_kbetr LIKE konv-kbetr.
LOOP AT ivbrkp.
g_bqty = ivbrkp-fkimg.
MOVE ivbrkp-vbeln TO iout-vbeln.
MOVE ivbrkp-posnr TO iout-posnr.
MOVE ivbrkp-vgbel TO iout-vgbel.
MOVE ivbrkp-netwr TO iout-netwr.
MOVE g_bqty TO iout-g_bqty.
MOVE ivbrkp-vkorg TO iout-vkorg.
MOVE ivbrkp-vtweg TO iout-vtweg.
MOVE ivbrkp-spart TO iout-spart.
MOVE ivbrkp-kunag TO iout-kunnr.
MOVE ivbrkp-matnr TO iout-matnr.
MOVE ivbrkp-xblnr TO iout-xblnr.
MOVE ivbrkp-bstnk_vf TO iout-bstnk_vf.
READ TABLE izppprice WITH KEY kunnr = ivbrkp-kunag
matnr = ivbrkp-matnr
crmemo = ivbrkp-vgbel.
g_qdiff = izppprice-eohqty - g_bqty.
IF sy-subrc = 0.
MOVE izppprice-sprice TO iout-sprice.
MOVE izppprice-eprice TO iout-eprice.
MOVE izppprice-eohqty TO iout-eohqty.
MOVE g_qdiff TO iout-g_qdiff.
ENDIF.
SELECT SINGLE name1
FROM kna1 INTO lv_name1 WHERE kunnr = ivbrkp-kunag.
IF sy-subrc = 0.
MOVE lv_name1 TO iout-name1.
ENDIF.
SELECT SINGLE auart augru FROM vbak INTO (lv_auart, lv_augru)
WHERE vbeln = ivbrkp-vgbel.
IF sy-subrc = 0.
MOVE lv_auart TO iout-auart.
MOVE lv_augru TO iout-augru.
ENDIF.
SELECT SINGLE werks FROM vbap INTO lv_werks
WHERE vbeln = ivbrkp-vgbel
AND posnr = ivbrkp-posnr.
IF sy-subrc = 0.
MOVE lv_werks TO iout-werks.
ENDIF.
SELECT SINGLE fkdat FROM vbkd INTO lv_fkdat
WHERE vbeln = ivbrkp-vgbel.
IF sy-subrc = 0.
MOVE lv_fkdat TO iout-fkdat.
ENDIF.
SELECT SINGLE knumv
FROM vbak INTO lv_knumv
WHERE vbeln = ivbrkp-vgbel.
SELECT SINGLE kbetr
FROM konv INTO lv_kbetr
WHERE knumv = lv_knumv
AND kschl = 'ZCPP'.
IF sy-subrc = 0.
MOVE lv_kbetr TO iout-g_pdiff.
ENDIF.
APPEND iout.
CLEAR iout.
CLEAR ivbrkp.
CLEAR lv_name1.
CLEAR lv_auart.
CLEAR lv_augru.
CLEAR lv_werks.
CLEAR lv_fkdat.
CLEAR lv_knumv.
CLEAR lv_kbetr.
ENDLOOP.
ENDFORM. " process_data
10-10-2007 9:55 PM
Hi
It appears that your code is OK
Credit Memo is one type of Billing document only like Invoice
Its details willbe in VBRK and VBRP tables
So fetch the data from them
VBTYP field will be different for Credit memo from Invoice/billing doc
Accounting doc details will be available in BSID and BSAD tables
Pass the VBRK-VBELN to these tables and fetch the accounting doc
You can use the VBFA table also for all document linkage.
Regards
Anji
Message was edited by:
Anji Reddy Vangala
10-10-2007 10:10 PM
Hi Anji,
Thank you.
The only thing I want to add to this report is, when the Cmemo does not have Acctdocunum, then I have to display remaining details. How can I modify my report to do this.
Now the report is displaying details only for Cmemo's with Acctdocunum.
Thanks,
Neelu.
REPORT zsdr_cmdetails NO STANDARD PAGE HEADING.
TABLES: vbak, vbrk, vbfa, vbkd, kna1, vbap, konv, zppprice.
INCLUDE zalvi_grid_display.
DATA: g_repid LIKE sy-repid,
g_bqty TYPE i,
g_pdiff TYPE p DECIMALS 2,
g_qdiff TYPE i.
*----------------------------------------------------------------------*
* Input Tables
*----------------------------------------------------------------------*
DATA: BEGIN OF ivbrkp OCCURS 0,
vbeln LIKE vbrp-vbeln,
posnr LIKE vbrp-posnr,
vgbel LIKE vbrp-vgbel,
netwr LIKE vbrp-netwr,
fkimg LIKE vbrp-fkimg,
matnr LIKE vbrp-matnr,
vkorg LIKE vbrk-vkorg,
vtweg LIKE vbrk-vtweg,
spart LIKE vbrk-spart,
kunag LIKE vbrk-kunag,
xblnr LIKE vbrk-xblnr,
bstnk_vf LIKE vbrk-bstnk_vf,
END OF ivbrkp.
DATA: BEGIN OF izppprice OCCURS 0,
kunnr LIKE zppprice-kunnr,
matnr LIKE zppprice-matnr,
sprice LIKE zppprice-sprice,
eprice LIKE zppprice-eprice,
eohqty LIKE zppprice-eohqty,
bstkd LIKE zppprice-bstkd,
crmemo LIKE zppprice-crmemo,
END OF izppprice.
*----------------------------------------------------------------------*
* Output Table
*----------------------------------------------------------------------*
DATA: BEGIN OF iout OCCURS 0,
vkorg LIKE vbrk-vkorg,
vtweg LIKE vbrk-vtweg,
spart LIKE vbrk-spart,
kunnr LIKE vbrk-kunag,
name1 LIKE kna1-name1,
matnr LIKE vbrp-matnr,
posnr LIKE vbrp-posnr,
fkdat LIKE vbkd-fkdat,
sprice LIKE zppprice-sprice,
eprice LIKE zppprice-eprice,
g_pdiff(10),
eohqty LIKE zppprice-eohqty,
g_bqty(13),
g_qdiff(10),
netwr LIKE vbrp-netwr,
auart LIKE vbak-auart,
bstnk_vf LIKE vbrk-bstnk_vf,
werks LIKE vbap-werks,
augru LIKE vbak-augru,
xblnr LIKE vbrk-xblnr,
vgbel LIKE vbrp-vgbel,
vbeln LIKE vbrk-vbeln,
END OF iout.
*----------------------------------------------------------------------*
* SELECTION SCREEN
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_xblnr FOR vbrk-xblnr OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM get_data.
PERFORM process_data.
PERFORM sub_alv_routines.
PERFORM comment_build USING t_list_top_of_page[].
g_repid = sy-repid.
PERFORM alv_build_fieldcat USING 'IOUT' g_repid.
PERFORM sub_modify_field_cat.
PERFORM sub_call_alv_grid TABLES iout.
*&---------------------------------------------------------------------*
*& Form getdata
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_data.
SELECT a~vbeln a~posnr a~vgbel a~netwr a~fkimg a~matnr
b~vkorg b~vtweg b~spart b~kunag b~xblnr b~bstnk_vf
FROM vbrp AS a
INNER JOIN vbrk AS b
ON a~vbeln = b~vbeln
INTO TABLE ivbrkp
WHERE b~xblnr IN s_xblnr
AND b~fkart = 'ZMKD'.
IF sy-subrc = 0.
SELECT kunnr matnr sprice eprice eohqty bstkd crmemo
FROM zppprice INTO TABLE izppprice
FOR ALL ENTRIES IN ivbrkp
WHERE kunnr = ivbrkp-kunag
AND matnr = ivbrkp-matnr
AND crmemo = ivbrkp-vgbel.
ENDIF.
ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form process_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM process_data.
DATA: lv_name1 LIKE kna1-name1,
lv_auart LIKE vbak-auart,
lv_augru LIKE vbak-augru,
lv_werks LIKE vbap-werks,
lv_fkdat LIKE vbkd-fkdat,
lv_knumv LIKE vbak-knumv,
lv_kbetr LIKE konv-kbetr.
LOOP AT ivbrkp.
g_bqty = ivbrkp-fkimg.
MOVE ivbrkp-vbeln TO iout-vbeln.
MOVE ivbrkp-posnr TO iout-posnr.
MOVE ivbrkp-vgbel TO iout-vgbel.
MOVE ivbrkp-netwr TO iout-netwr.
MOVE g_bqty TO iout-g_bqty.
MOVE ivbrkp-vkorg TO iout-vkorg.
MOVE ivbrkp-vtweg TO iout-vtweg.
MOVE ivbrkp-spart TO iout-spart.
MOVE ivbrkp-kunag TO iout-kunnr.
MOVE ivbrkp-matnr TO iout-matnr.
MOVE ivbrkp-xblnr TO iout-xblnr.
MOVE ivbrkp-bstnk_vf TO iout-bstnk_vf.
READ TABLE izppprice WITH KEY kunnr = ivbrkp-kunag
matnr = ivbrkp-matnr
crmemo = ivbrkp-vgbel.
g_qdiff = izppprice-eohqty - g_bqty.
IF sy-subrc = 0.
MOVE izppprice-sprice TO iout-sprice.
MOVE izppprice-eprice TO iout-eprice.
MOVE izppprice-eohqty TO iout-eohqty.
MOVE g_qdiff TO iout-g_qdiff.
ENDIF.
SELECT SINGLE name1
FROM kna1 INTO lv_name1 WHERE kunnr = ivbrkp-kunag.
IF sy-subrc = 0.
MOVE lv_name1 TO iout-name1.
ENDIF.
SELECT SINGLE auart augru FROM vbak INTO (lv_auart, lv_augru)
WHERE vbeln = ivbrkp-vgbel.
IF sy-subrc = 0.
MOVE lv_auart TO iout-auart.
MOVE lv_augru TO iout-augru.
ENDIF.
SELECT SINGLE werks FROM vbap INTO lv_werks
WHERE vbeln = ivbrkp-vgbel
AND posnr = ivbrkp-posnr.
IF sy-subrc = 0.
MOVE lv_werks TO iout-werks.
ENDIF.
SELECT SINGLE fkdat FROM vbkd INTO lv_fkdat
WHERE vbeln = ivbrkp-vgbel.
IF sy-subrc = 0.
MOVE lv_fkdat TO iout-fkdat.
ENDIF.
SELECT SINGLE knumv
FROM vbak INTO lv_knumv
WHERE vbeln = ivbrkp-vgbel.
SELECT SINGLE kbetr
FROM konv INTO lv_kbetr
WHERE knumv = lv_knumv
AND kschl = 'ZCPP'.
IF sy-subrc = 0.
MOVE lv_kbetr TO iout-g_pdiff.
ENDIF.
APPEND iout.
CLEAR iout.
CLEAR ivbrkp.
CLEAR lv_name1.
CLEAR lv_auart.
CLEAR lv_augru.
CLEAR lv_werks.
CLEAR lv_fkdat.
CLEAR lv_knumv.
CLEAR lv_kbetr.
ENDLOOP.
ENDFORM. " process_data
10-10-2007 10:24 PM
Hi Anji,
I have one dount:
Credit Memo exists in 2 scenario's 1. Thru MIRO(incoming Invoice)
2. VF01(Customer Invoice)
How can you say that the credit memo data exists in VBRK and VBRP, it might also stores in RBKP and RSEG. I think it depends on the Reference Document. What should be the reference document in this case ( is it a Sales Order or Delivery ) or Purchase Order ? Please clarify me !!!!!!!!
Regards
Kannaiah
10-10-2007 10:33 PM
Hi Kannaiah,
As I know, it is purchase order number(in my case).
Thanks,
Neelu.
10-10-2007 10:34 PM
Hi,
Then credit memo number would be stored in RBKP and RSEG, as this will be created from MIRO.
Regards
Kannaiah
10-10-2007 10:48 PM
Hi Kannaiah,
I gave ref num in VBKD-BSTKD and got Cmemo num in VBKD-VBELN. But I donot see any details about Cmemo num in RBKP and RSEG.
Please clarify me what tables to use to get CMDetails.
Thanks,
Neelu.
10-10-2007 10:53 PM
Hi,
I am using CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
to create Cmemo's.
Thanks,
Neelu.
10-10-2007 11:10 PM
Hi,
First of all i need to tell the business process:
Customer sends his purchase order(BSTKD) to Client(R/3). With this reference client creates Sales Order and if he has all the materials or products then he directly ships and creates a O/B delivery and sends invoice to Customer, otherwise Client creates a Purchase Order for Thirdparty and sends it to supplier and supplier delivers the goods and sends a despatch advice and client creates a I/B delivery and then Goods receipt and O/B delivery and pick,pack and Post Goods Issue and then Invoice, if customer has any product to be repaired or returned, he sends the products to Supplier and client creates a Return Order with reference to ´CUstomer Invoice and creates subsequent credit/debit invoices to customer and vendor thru MIRO with reference to Purchase Order created by Client. Let me know in which part is ur scenario or if ur scenario is different let me know that.
Please refer to the thread below for credit/debit memo:
Regards
Kannaiah
10-11-2007 12:10 AM
Hi Kannaiah,
Thank you for the bussiness process. It was very informative to me.
I am creating the credit memo for the price protection. If for a particular SKU the price is lowerd we give the customer credit back to their account as charge back, based on Sku, Warehouse Qty, Old price - Newprice. Credit amount = qty * Pricediff.
The reference number is our internal number. We are using the ref num in VBAK-XBLNR and VBKD-BSTKD in creating Cmemo for Price protection.
Thank you,
Neelu.
10-11-2007 9:30 AM
Hi,
Its not possible to <b>complete</b> a credit memo document without a accounting document.
As per my understanding :
A credit memo request would be created based on the reference of customer purchase order and this would generate a Billing Document (Credit Memo -VBRK) with reference to accounting document.
Credit memo would be created in VBRK but that wont be completed until accounting document has been assigned.
Regards
Kannaiah
10-11-2007 5:43 PM
Hi Kannaiah,
Yes, the Credit memo request is created with function 'SD_SALESDOCUMENT_CREATE' and Credit will approve it. Once it is approved then Accounting Document Number is created.
What tables should I use to get the details of creditmemo with Creditmemonum and Acctdocunum based on Ref Number?
Thanks,
Neelu.
10-11-2007 6:18 PM
10-11-2007 7:34 PM
Hi Kannaiah,
Can I use tables VBAK, VBAP and VBFA for this. I will give ref num to VBAK and get Cmemo num from it, get item getails from VBAP and Give this Cmemo num and item num to VBFA-VBELV, VBFA-POSNV and if account document is created then get VBFA-VBELN.
Please help me if this path is correct?
BKPF is giving me Acctdocunum(BELNR) based on Refnum(XBLNR), but I want Cmemo based on Refnum and then get Acctdocunum based on Cmemo.
BSEG also giving me Acctdocunum(BELNR) based on Refnum(ZUONR).
Thanks,
Neelu.
10-11-2007 8:32 PM
Hi,
VBFA gives sales document flow:
Like if you have Customer Invoice, then u can get the corresponding Sales Order numbers(if the Invoice is built thru Sales Order, this is incase of Third party orders) and then frm the sales order numbers we can get the corresponding purchase order numbers which were sent to Supplier. I dont understand why you are checking VBFA ?
Selecting the Sales Documents from VBFA for corresponding Invoice
SELECT vbelv
posnv
FROM vbfa
INTO TABLE gt_itab3
FOR ALL ENTRIES IN gt_itab5
WHERE vbeln EQ gt_itab5-vbeln
AND posnn EQ gt_itab5-posnr
AND vbtyp_n EQ 'M'.
IF sy-subrc EQ gc_zero_num.
SORT gt_itab3 BY vbelv posnv.
ENDIF.
ENDIF.
IF NOT gt_itab3 IS INITIAL.
Selecting the Purchase Orders from VBFA for corresponding Sales Documents
SELECT vbeln
posnn
FROM vbfa
INTO TABLE gt_itab4
FOR ALL ENTRIES IN gt_itab3
WHERE vbelv EQ gt_itab3-vbelv
AND posnv EQ gt_itab3-posnv
AND vbtyp_n EQ 'V'.
What i understood is, whenever u create a Credit memo request, it creates corresponding returns delivery and corresponding internal credit memo and corresponding credit for returns. Check the process is there in your system, by manually creating a credit memo request. If accounting document is not created, then there wont be any process here. Check this.
Regards
Kannaiah
10-11-2007 9:54 PM
10-11-2007 9:59 PM