Posted: Sat Oct 27, 2007 4:04 pm Post subject: Automatic generation of credit notes
I am here by sending the full code of my program. But since my program is automatic generation of credit notes, there is no file format, instead processing logic is based on data stored from the FI tables. Otherwise yours is a very similar requirement to mine. Only diffrent is I use BDC's for F-43 and F-03 together in my program.
Code:
REPORT ZCREDITNOTE_GEN.
*********************************************************
*********************************************************
***Module - FI Finance & Accounting
***program - ZCREDITNOTE_GEN
***Author - Lakshminarayanan
***Date - 30.03.2006
***Request No - D62K909833
***Specification given by- Girish
*******************************************************
*******************************************************
DATA: W_MONTH LIKE BOITEM-SPMON,
W_PERIOD(2),
G_KBETR TYPE KONV-KBETR,
DD(2) TYPE C,
MM(2) TYPE C,
YY(4) TYPE C,
L_DATE TYPE DATE,
BDC_PAR LIKE CTU_PARAMS,
W_KWERT(20),
W_TAX(20),
W_TOTAL(20),
W_DIFFRENCE(20),
FLDNAME(30),
W_NUM(2),
W_CRNO TYPE STRING,
W_FILTER(4),
W_FILTER1(4),
W_FILTER2(4).
DATA: BEGIN OF WA_INVOICES,
VBELN TYPE VBRK-VBELN, " Invoice No
VKORG TYPE VBRK-VKORG, " Sales Organisation
KUNRG TYPE VBRK-KUNRG, " Payer
KNUMV TYPE VBRK-KNUMV, " Condition Record No
FKIMG TYPE P, " Invoice Qty
VTWEG TYPE VBRK-VTWEG, " Distribution Channel
SPART TYPE VBRK-SPART, " Division
FKDAT TYPE VBRK-FKDAT, " Invoice Date
POSNR TYPE VBRP-POSNR, " Item No
MATNR TYPE VBRP-MATNR, " Material No
PRDHA(7), " Product Hierarchy
UMREN TYPE MARM-UMREN,
UMREZ TYPE MARM-UMREZ,
BOX TYPE P DECIMALS 2,
KSCHL TYPE KONV-KSCHL, " Condition Type
KWERT TYPE KONV-KWERT, " Condition Value
END OF WA_INVOICES.
DATA: BEGIN OF WA_INV,
VKORG TYPE VBRK-VKORG, " Sales Organisation
KUNRG TYPE VBRK-KUNRG, " Payer
FKIMG TYPE P, " Invoice Qty
VTWEG TYPE VBRK-VTWEG, " Distribution Channel
SPART TYPE VBRK-SPART, " Division
KSCHL TYPE KONV-KSCHL,
KWERT TYPE KONV-KWERT,
BOX TYPE P DECIMALS 2,
VKBUR TYPE KNVV-VKBUR,
KDGRP TYPE KNVV-KDGRP,
ZTGTQTY TYPE P,
ZMINQTY TYPE P,
ZTGTRATE TYPE KONP-KBETR,
SALETAX TYPE KONV-KWERT, " Sales Tax
TOTAL TYPE KONV-KWERT, " Total Amount
END OF WA_INV.
DATA: BEGIN OF WA_ACCOUNTING,
KUNNR TYPE BSID-KUNNR, " Customer Code
BELNR TYPE BSID-BELNR, " Accounting Document
VBELN TYPE BSID-VBELN, " Invoice No
END OF WA_ACCOUNTING.
DATA: BEGIN OF WA_VAT,
KBETR TYPE KONV-KBETR, " Condition Type
END OF WA_VAT.
DATA: BEGIN OF WA_CRN,
CRN_NO TYPE BSID-BELNR, " Credit Note No
KUNNR TYPE KNA1-KUNNR, " Customer Code
CRN_AMT TYPE ZCRN-CRN_AMT,
CREDIT TYPE ZCRN-CRN_AMT,
DIFFRENCE TYPE ZCRN-CRN_AMT,
END OF WA_CRN.
DATA: BEGIN OF WA_UPDATE,
HKONT TYPE BSIS-HKONT,
ZUONR TYPE BSIS-ZUONR,
BELNR TYPE BSIS-BELNR,
KUNNR TYPE VBRK-KUNRG,
VBELN TYPE VBRK-VBELN,
END OF WA_UPDATE.
DATA: BEGIN OF WA_ACCOUNT,
BELNR TYPE BSID-BELNR,
KUNNR TYPE BSID-KUNNR,
KWERT TYPE KONV-KWERT,
END OF WA_ACCOUNT.
DATA: BEGIN OF WA_MARA,
MATNR TYPE MARA-MATNR,
PRDHA TYPE MARA-PRDHA,
END OF WA_MARA.
DATA: BEGIN OF WA_MARM,
MATNR TYPE MARM-MATNR,
UMREN TYPE MARM-UMREN,
UMREZ TYPE MARM-UMREZ,
END OF WA_MARM.
DATA: BEGIN OF WA_VALUE,
VBELN TYPE VBRK-VBELN,
BUZEI TYPE BUZEI,
VKORG LIKE VBAK-VKORG,
KUNNR TYPE KNA1-KUNNR,
VTWEG TYPE VBRK-VTWEG,
SPART TYPE VBAK-SPART,
MONTH TYPE BOITEM-SPMON,
KSCHL TYPE KONP-KSCHL,
BOX TYPE P DECIMALS 2,
VKBUR TYPE KNVV-VKBUR,
RATE TYPE KONP-KBETR,
KWERT TYPE KONV-KWERT,
END OF WA_VALUE.
DATA: T_INVOICES LIKE STANDARD TABLE OF WA_INVOICES WITH HEADER LINE,
T_MATERIAL LIKE STANDARD TABLE OF WA_MARA WITH HEADER LINE,
T_MARM LIKE STANDARD TABLE OF WA_MARM WITH HEADER LINE,
T_INV LIKE STANDARD TABLE OF WA_INV WITH HEADER LINE,
T_SUMMINV LIKE STANDARD TABLE OF WA_INV WITH HEADER LINE,
T_SUMMINV1 LIKE STANDARD TABLE OF WA_INV WITH HEADER LINE,
T_SUMMINV2 LIKE STANDARD TABLE OF WA_INV WITH HEADER LINE,
T_ACCOUNTING LIKE STANDARD TABLE OF WA_ACCOUNTING WITH HEADER LINE,
T_TARGET LIKE STANDARD TABLE OF ZTARGET WITH HEADER LINE,
T_VAT LIKE STANDARD TABLE OF WA_VAT WITH HEADER LINE,
T_CRN LIKE STANDARD TABLE OF WA_CRN WITH HEADER LINE,
BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE,
T_UPDATE LIKE STANDARD TABLE OF WA_UPDATE WITH HEADER LINE,
T_NEW LIKE STANDARD TABLE OF ZCRN WITH HEADER LINE,
T_CRNO LIKE STANDARD TABLE OF WA_CRN WITH HEADER LINE,
T_HEADER LIKE STANDARD TABLE OF WA_CRN WITH HEADER LINE,
T_HEADER1 LIKE STANDARD TABLE OF WA_CRN WITH HEADER LINE,
T_HEADER2 LIKE STANDARD TABLE OF WA_ACCOUNT WITH HEADER LINE,
T_HEADER3 LIKE STANDARD TABLE OF WA_ACCOUNT WITH HEADER LINE,
T_ACCOUNT LIKE STANDARD TABLE OF WA_ACCOUNT WITH HEADER LINE,
T_ACC LIKE STANDARD TABLE OF WA_ACCOUNT WITH HEADER LINE,
T_VALUE LIKE STANDARD TABLE OF WA_VALUE WITH HEADER LINE,
MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK IPDATA WITH FRAME TITLE TEXT-001.
PARAMETERS: P_BUKRS LIKE T001-BUKRS OBLIGATORY DEFAULT '1000',
P_HKONT LIKE SKB1-SAKNR.
SELECT-OPTIONS: SO_KUNNR FOR KNA1-KUNNR,
SO_FKDAT FOR VBRK-FKDAT.
SELECTION-SCREEN END OF BLOCK IPDATA.
***To get the Month from the Invoice date entered in the selection
***screen. Once after getting the month it is passed on to the ZTARGET
***table for comparison of the target qty
*&---------------------------------------------------------------------*
*& Form F001_GETDATA
*&---------------------------------------------------------------------*
*& This Form is basically used for getting the list of invoices
*& from VBRK table based on the Date and customer given in the
*& selection screen
*----------------------------------------------------------------------*
FORM F001_GETDATA.
SELECT A~VBELN A~VKORG A~KUNRG KNUMV FKIMG VTWEG A~SPART A~FKDAT
B~POSNR B~MATNR
FROM VBRK AS A INNER JOIN VBRP AS B ON A~VBELN EQ B~VBELN
INTO TABLE T_INVOICES
WHERE KUNRG IN SO_KUNNR
AND FKDAT IN SO_FKDAT
AND FKSTO NE 'X'
AND FKART NOT IN ('S1','S2','S3')
AND RFBSK NE 'E'.
*To retrieve the Product hierarchy from the material master.
IF NOT T_INVOICES[] IS INITIAL.
SELECT MATNR PRDHA
INTO TABLE T_MATERIAL
FROM MARA
FOR ALL ENTRIES IN T_INVOICES
WHERE MATNR = T_INVOICES-MATNR.
ENDIF.
IF NOT T_MATERIAL[] IS INITIAL.
**To retrieve the conversion factors for the materials
SELECT MATNR UMREN UMREZ
INTO TABLE T_MARM
FROM MARM
FOR ALL ENTRIES IN T_MATERIAL
WHERE MATNR = T_MATERIAL-MATNR
AND MEINH = 'TR'.
ENDIF.
LOOP AT T_INVOICES.
READ TABLE T_MATERIAL WITH KEY MATNR = T_INVOICES-MATNR.
IF SY-SUBRC EQ 0.
T_INVOICES-PRDHA = T_MATERIAL-PRDHA.
ENDIF.
READ TABLE T_MARM WITH KEY MATNR = T_MATERIAL-MATNR.
IF SY-SUBRC EQ 0.
T_INVOICES-UMREN = T_MARM-UMREN.
T_INVOICES-UMREZ = T_MARM-UMREZ.
ENDIF.
CASE T_INVOICES-PRDHA.
WHEN '0010001'.
T_INVOICES-BOX = T_INVOICES-FKIMG.
WHEN '0010002'.
T_INVOICES-BOX = ( T_INVOICES-UMREN / T_INVOICES-UMREZ ) *
T_INVOICES-FKIMG.
WHEN '0010003'.
T_INVOICES-BOX = ( T_INVOICES-UMREN / T_INVOICES-UMREZ ) *
T_INVOICES-FKIMG.
ENDCASE.
*This select is to check that only RV documents are eligible for credit
*notes generation
SELECT KUNNR BELNR VBELN FROM
BSID
INTO TABLE T_ACCOUNTING
FOR ALL ENTRIES IN T_INVOICES
WHERE VBELN = T_INVOICES-VBELN
AND KUNNR = T_INVOICES-KUNRG
AND BLART = 'RV'.
LOOP AT T_INVOICES.
READ TABLE T_ACCOUNTING WITH KEY KUNNR = T_INVOICES-KUNRG
VBELN = T_INVOICES-VBELN.
*&---------------------------------------------------------------------*
*& Form F002_ADDITIONALDATA
*&---------------------------------------------------------------------*
*& Based on the invoices from the above internal table we need to
*& retrieve the Condition value for both ZMSR/ZQTR condition type
*----------------------------------------------------------------------*
FORM F002_ADDITIONALDATA.
IF NOT T_INVOICES[] IS INITIAL.
LOOP AT T_INVOICES.
IF P_HKONT = '0000220043'.
SELECT SINGLE KSCHL KWERT
FROM KONV
INTO (T_INVOICES-KSCHL,T_INVOICES-KWERT)
WHERE KNUMV = T_INVOICES-KNUMV
AND KPOSN = T_INVOICES-POSNR
AND KSCHL = 'ZMSR'
AND KAPPL = 'V'.
SELECT SINGLE KSCHL KWERT
FROM KONV
INTO (T_INVOICES-KSCHL,T_INVOICES-KWERT)
WHERE KNUMV = T_INVOICES-KNUMV
AND KPOSN = T_INVOICES-POSNR
AND KSCHL = 'ZQTR'
AND KAPPL = 'V'.
*This select is to check whether ZMSR or ZQTR condition type records are
*maintained in the ZTARGET table against the customer codes entered in
*the selection-screen. If the data is not maintained then those
*customers invoice details has to be deleted from the selection for
*further process.Done on 05.04.2006
SELECT * FROM ZTARGET
INTO TABLE T_TARGET
FOR ALL ENTRIES IN T_INVOICES
WHERE KUNNR IN SO_KUNNR
AND VTWEG EQ T_INVOICES-VTWEG
AND SPART EQ T_INVOICES-SPART
AND ZCONTYPE EQ T_INVOICES-KSCHL
AND ZFM_MTHYR EQ W_MONTH.
LOOP AT T_INV.
COLLECT T_INV INTO T_SUMMINV.
ENDLOOP.
ENDFORM. " F002_ADDITIONALDATA
*&---------------------------------------------------------------------*
*& Form F003_MOVEDATA
*&---------------------------------------------------------------------*
*& This Form is used for moving data into a new internal table
*----------------------------------------------------------------------*
FORM F003_MOVEDATA.
**To Bring in the Sales Office Field into the Base table.
LOOP AT T_SUMMINV.
SELECT SINGLE VKBUR KDGRP INTO (T_SUMMINV-VKBUR,T_SUMMINV-KDGRP)
FROM KNVV
WHERE KUNNR IN SO_KUNNR
AND VKORG EQ T_SUMMINV-VKORG
AND VTWEG EQ T_SUMMINV-VTWEG
AND SPART EQ T_SUMMINV-SPART.
*&---------------------------------------------------------------------*
*& Form F004_TARGETCOMPARE
*&---------------------------------------------------------------------*
*& This Form is for Comparing the Base internal table with the
*& ZTARGET table
*----------------------------------------------------------------------*
FORM F004_TARGETCOMPARE.
REFRESH T_TARGET.
CLEAR T_TARGET.
SELECT * FROM ZTARGET
INTO TABLE T_TARGET
FOR ALL ENTRIES IN T_SUMMINV
WHERE KUNNR IN SO_KUNNR
AND VTWEG EQ T_SUMMINV-VTWEG
AND SPART EQ T_SUMMINV-SPART
AND ZCONTYPE EQ T_SUMMINV-KSCHL
AND ZFM_MTHYR EQ W_MONTH.
*&---------------------------------------------------------------------*
*& Form F005_CHECKING
*&---------------------------------------------------------------------*
*& This form is basically decide which accruel will decide the
*& credit note generation
*----------------------------------------------------------------------*
FORM F005_CHECKING.
SELECT KBETR
INTO TABLE T_VAT
FROM KONV
FOR ALL ENTRIES IN T_INVOICES
WHERE KNUMV = T_INVOICES-KNUMV
AND KSCHL IN ('JIN6','JIN7')
AND KAPPL = 'TX'.
DELETE ADJACENT DUPLICATES FROM T_VAT COMPARING KBETR.
LOOP AT T_VAT.
G_KBETR = T_VAT-KBETR / 10.
ENDLOOP.
*&---------------------------------------------------------------------*
*& Form F006_UPLOAD
*&---------------------------------------------------------------------*
*& This form is basically for uploading the data into the F-43
*& for generating Credit Note No.
*----------------------------------------------------------------------*
FORM F006_UPLOAD.
DD = SY-DATUM+6(2).
MM = SY-DATUM+4(2).
YY = SY-DATUM+0(4).
CONCATENATE DD MM YY INTO L_DATE.
LOOP AT T_SUMMINV.
WRITE T_SUMMINV-KWERT TO W_KWERT NO-SIGN CURRENCY 'INR'.
CONDENSE W_KWERT NO-GAPS.
WRITE T_SUMMINV-SALETAX TO W_TAX NO-SIGN CURRENCY 'INR'.
CONDENSE W_TAX NO-GAPS.
WRITE T_SUMMINV-TOTAL TO W_TOTAL NO-SIGN CURRENCY 'INR'.
CONDENSE W_TOTAL NO-GAPS.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0100'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF05A-NEWKO'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'BKPF-BLDAT' L_DATE.
PERFORM BDC_FIELD USING 'BKPF-BLART' 'DC'.
PERFORM BDC_FIELD USING 'BKPF-BUKRS' P_BUKRS.
PERFORM BDC_FIELD USING 'BKPF-BUDAT' L_DATE.
PERFORM BDC_FIELD USING 'BKPF-MONAT' W_PERIOD.
PERFORM BDC_FIELD USING 'BKPF-WAERS' 'INR'.
PERFORM BDC_FIELD USING 'RF05A-NEWBS' '40'.
PERFORM BDC_FIELD USING 'RF05A-NEWKO' P_HKONT.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0300'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF05A-NEWKO'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'BSEG-WRBTR' W_KWERT.
PERFORM BDC_FIELD USING 'BSEG-ZUONR' T_SUMMINV-KUNRG.
PERFORM BDC_FIELD USING 'RF05A-NEWBS' '40'.
PERFORM BDC_FIELD USING 'RF05A-NEWKO' '214116'.
PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/EENTE'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'COBL-GSBER'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0300'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF05A-NEWKO'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'BSEG-WRBTR' W_TAX.
PERFORM BDC_FIELD USING 'BSEG-ZUONR' T_SUMMINV-KUNRG.
PERFORM BDC_FIELD USING 'RF05A-NEWBS' '31'.
PERFORM BDC_FIELD USING 'RF05A-NEWKO' T_SUMMINV-KUNRG.
PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/EENTE'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'COBL-GSBER'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0302'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'BSEG-ZUONR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'BSEG-WRBTR' W_TOTAL.
PERFORM BDC_FIELD USING 'BSEG-ZUONR' T_SUMMINV-KUNRG.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0302'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'BSEG-WRBTR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BS'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0700'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF05A-NEWBS'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BU'.
PERFORM BDC_TRANSACTION USING 'F-43'.
READ TABLE MESSTAB WITH KEY MSGID = 'F5' MSGNR = '312'.
IF SY-SUBRC EQ 0.
T_CRN-CRN_NO = MESSTAB-MSGV1.
APPEND T_CRN.
CLEAR T_CRN.
ENDIF.
ENDLOOP.
ENDFORM. " F006_UPLOAD
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDFORM. " BDC_FIELD
*&---------------------------------------------------------------------*
*& Form BDC_TRANSACTION
*&---------------------------------------------------------------------*
CALL TRANSACTION TCODE USING BDCDATA
OPTIONS FROM BDC_PAR
MESSAGES INTO MESSTAB.
REFRESH: BDCDATA.
ENDFORM. " BDC_TRANSACTION
*----------------------------------------------------------------------*
* create batchinput session *
* (not for call transaction using...) *
*----------------------------------------------------------------------*
FORM OPEN_GROUP.
* open batchinput group
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = 'DLR_COMM'
USER = SY-UNAME
KEEP = 'X'
* HOLDDATE = HOLDDATE
EXCEPTIONS
CLIENT_INVALID
DESTINATION_INVALID
GROUP_INVALID
GROUP_IS_LOCKED
HOLDDATE_INVALID
INTERNAL_ERROR
QUEUE_ERROR
RUNNING
SYSTEM_LOCK_ERROR
USER_INVALID.
ENDFORM.
*----------------------------------------------------------------------*
* end batchinput session *
* (call transaction using...: error session) *
*----------------------------------------------------------------------*
FORM CLOSE_GROUP.
* close batchinput group
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN
QUEUE_ERROR.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form F007_READCRNO
*&---------------------------------------------------------------------*
*& This Form is basically used to get the Credit Notes created
*----------------------------------------------------------------------*
FORM F007_READCRNO.
*&---------------------------------------------------------------------*
*& Form F008_CLEARING
*&---------------------------------------------------------------------*
*& This Form is used for clearing the documents through F-03
*----------------------------------------------------------------------*
FORM F008_CLEARING.
DATA: W_NO TYPE I.
CLEAR : DD,MM,YY,L_DATE.
DD = SY-DATUM+6(2).
MM = SY-DATUM+4(2).
YY = SY-DATUM+0(4).
CONCATENATE DD MM YY INTO L_DATE.
LOOP AT T_NEW.
MOVE : T_NEW-CRN_NO TO T_CRNO-CRN_NO.
MOVE : T_NEW-KUNNR TO T_CRNO-KUNNR.
MOVE : T_NEW-CRN_NO TO T_HEADER-CRN_NO.
MOVE : T_NEW-KUNNR TO T_HEADER-KUNNR.
DESCRIBE TABLE T_CRNO LINES W_NO.
SORT T_CRNO BY KUNNR.
LOOP AT T_HEADER.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0131'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF05A-XPOS1(03)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD USING 'RF05A-AGKON' P_HKONT.
PERFORM BDC_FIELD USING 'BKPF-BUDAT' L_DATE.
PERFORM BDC_FIELD USING 'BKPF-MONAT' W_PERIOD.
PERFORM BDC_FIELD USING 'BKPF-BUKRS' P_BUKRS.
PERFORM BDC_FIELD USING 'BKPF-WAERS' 'INR'.
PERFORM BDC_FIELD USING 'RF05A-XPOS1(01)' ''.
PERFORM BDC_FIELD USING 'RF05A-XPOS1(03)' 'X'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0731'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF05A-SEL01(03)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
W_NUM = 1.
LOOP AT T_CRNO WHERE KUNNR = T_HEADER-KUNNR.
CONCATENATE 'RF05A-SEL01(' W_NUM ')' INTO W_CRNO.
PERFORM BDC_FIELD USING W_CRNO T_CRNO-CRN_NO.
W_NUM = W_NUM + 1.
ENDLOOP.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0731'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF05A-SEL01(01)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=PA'.
PERFORM BDC_DYNPRO USING 'SAPDF05X' '3100'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=BU'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF05A-ABPOS'.
PERFORM BDC_TRANSACTION USING 'F-03'.
ENDLOOP.
ENDFORM. " F008_CLEARING
*&---------------------------------------------------------------------*
*& Form F008_CLEARINGB
*&---------------------------------------------------------------------*
*& This Form is used to RUN F-03 BDC if the credit note for the
*& customer if the sum of invoice qty is between Max and Min target
*&---------------------------------------------------------------------*
FORM F008_CLEARINGB.
DATA: W_NO TYPE I.
CLEAR : DD,MM,YY,L_DATE.
DD = SY-DATUM+6(2).
MM = SY-DATUM+4(2).
YY = SY-DATUM+0(4).
DESCRIBE TABLE T_CRNO LINES W_NO.
SORT T_CRNO BY KUNNR.
LOOP AT T_HEADER1.
WRITE T_HEADER1-DIFFRENCE TO W_DIFFRENCE NO-SIGN CURRENCY 'INR'.
CONDENSE W_DIFFRENCE NO-GAPS.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0131'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF05A-XPOS1(03)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD USING 'RF05A-AGKON' P_HKONT.
PERFORM BDC_FIELD USING 'BKPF-BUDAT' L_DATE.
PERFORM BDC_FIELD USING 'BKPF-MONAT' W_PERIOD.
PERFORM BDC_FIELD USING 'BKPF-BUKRS' P_BUKRS.
PERFORM BDC_FIELD USING 'BKPF-WAERS' 'INR'.
PERFORM BDC_FIELD USING 'RF05A-XPOS1(01)' ''.
PERFORM BDC_FIELD USING 'RF05A-XPOS1(03)' 'X'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0731'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF05A-SEL01(03)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
W_NUM = 1.
LOOP AT T_CRNO WHERE KUNNR = T_HEADER1-KUNNR.
CONCATENATE 'RF05A-SEL01(' W_NUM ')' INTO W_CRNO.
PERFORM BDC_FIELD USING W_CRNO T_CRNO-CRN_NO.
W_NUM = W_NUM + 1.
ENDLOOP.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0731'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF05A-SEL01(01)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=PA'.
PERFORM BDC_DYNPRO USING 'SAPDF05X' '3100'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=OSE'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF05A-ABPOS'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0700'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF05A-NEWKO'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD USING 'RF05A-NEWBS' '50'.
PERFORM BDC_FIELD USING 'RF05A-NEWKO' '220950'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0300'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'BSEG-ZUONR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD USING 'BSEG-WRBTR' W_DIFFRENCE.
PERFORM BDC_FIELD USING 'BSEG-ZUONR' T_HEADER1-KUNNR.
PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/EENTE'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'COBL-GSBER'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0300'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'BSEG-WRBTR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=BS'.
PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/EENTE'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'COBL-GSBER'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0700'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF05A-NEWBS'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=BU'.
PERFORM BDC_TRANSACTION USING 'F-03'.
CLEAR: W_DIFFRENCE.
ENDLOOP.
ENDFORM. " F008_CLEARINGB
*&---------------------------------------------------------------------*
*& Form F008_CLEARINGC
*&---------------------------------------------------------------------*
*& This form is for running BDC for F-03 if even the Minimum target
*& Qty is not met
*----------------------------------------------------------------------*
FORM F008_CLEARINGC.
LOOP AT T_ACCOUNTING.
MOVE : T_ACCOUNTING-BELNR TO T_ACCOUNT-BELNR.
MOVE : T_ACCOUNTING-KUNNR TO T_ACCOUNT-KUNNR.
MOVE : T_ACCOUNTING-KUNNR TO T_ACC-KUNNR.
LOOP AT T_ACCOUNT.
READ TABLE T_ACC WITH KEY KUNNR = T_ACCOUNT-KUNNR.
IF SY-SUBRC <> 0.
DELETE T_ACCOUNT.
CLEAR: T_ACCOUNT, T_ACC.
ENDIF.
CLEAR: T_ACCOUNT.
ENDLOOP.
SORT T_ACCOUNT BY KUNNR.
LOOP AT T_ACC.
WRITE T_ACC-KWERT TO W_DIFFRENCE NO-SIGN CURRENCY 'INR'.
CONDENSE W_DIFFRENCE NO-GAPS.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0131'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF05A-XPOS1(03)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD USING 'RF05A-AGKON' P_HKONT.
PERFORM BDC_FIELD USING 'BKPF-BUDAT' L_DATE.
PERFORM BDC_FIELD USING 'BKPF-MONAT' W_PERIOD.
PERFORM BDC_FIELD USING 'BKPF-BUKRS' P_BUKRS.
PERFORM BDC_FIELD USING 'BKPF-WAERS' 'INR'.
PERFORM BDC_FIELD USING 'RF05A-XPOS1(01)' ''.
PERFORM BDC_FIELD USING 'RF05A-XPOS1(03)' 'X'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0731'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF05A-SEL01(02)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
W_NUM = 1.
LOOP AT T_ACCOUNT WHERE KUNNR = T_ACC-KUNNR.
CONCATENATE 'RF05A-SEL01(' W_NUM ')' INTO W_CRNO.
PERFORM BDC_FIELD USING W_CRNO T_ACCOUNT-BELNR.
W_NUM = W_NUM + 1.
ENDLOOP.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0731'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF05A-SEL01(01)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=PA'.
PERFORM BDC_DYNPRO USING 'SAPDF05X' '3100'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=OSE'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF05A-ABPOS'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0700'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF05A-NEWKO'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD USING 'RF05A-NEWBS' '50'.
PERFORM BDC_FIELD USING 'RF05A-NEWKO' '220950'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0300'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'BSEG-ZUONR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD USING 'BSEG-WRBTR' W_DIFFRENCE.
PERFORM BDC_FIELD USING 'BSEG-ZUONR' T_ACC-KUNNR.
PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/EENTE'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'COBL-GSBER'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0300'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'BSEG-WRBTR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=BS'.
PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/EENTE'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'COBL-GSBER'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0700'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF05A-NEWBS'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=BU'.
PERFORM BDC_TRANSACTION USING 'F-03'.
ENDLOOP.
ENDFORM. " F008_CLEARINGC
*&---------------------------------------------------------------------*
*& Form F005_CHECKINGA
*&---------------------------------------------------------------------*
*& This Form is used for checking 220043 G/L Account
*----------------------------------------------------------------------*
FORM F005_CHECKINGA.
SELECT KBETR
INTO TABLE T_VAT
FROM KONV
FOR ALL ENTRIES IN T_INVOICES
WHERE KNUMV = T_INVOICES-KNUMV
AND KSCHL IN ('JIN6','JIN7')
AND KAPPL = 'TX'.
DELETE ADJACENT DUPLICATES FROM T_VAT COMPARING KBETR.
LOOP AT T_VAT.
G_KBETR = T_VAT-KBETR / 10.
ENDLOOP.
*&---------------------------------------------------------------------*
*& Form F004_TARGETCOMPAREA
*&---------------------------------------------------------------------*
*& This Form is used for checking 220043 G/L Account
*----------------------------------------------------------------------*
FORM F004_TARGETCOMPAREA.
SELECT * FROM ZTARGET
INTO TABLE T_TARGET
FOR ALL ENTRIES IN T_SUMMINV
WHERE KUNNR IN SO_KUNNR
AND VTWEG EQ T_SUMMINV-VTWEG
AND SPART EQ T_SUMMINV-SPART
AND ZCONTYPE EQ T_SUMMINV-KSCHL
AND ZFM_MTHYR EQ W_MONTH.
*&---------------------------------------------------------------------*
*& Form F006_UPLOADA
*&---------------------------------------------------------------------*
*& This Form is used for F-43 BDC for partial target qty
*----------------------------------------------------------------------*
FORM F006_UPLOADA.
DD = SY-DATUM+6(2).
MM = SY-DATUM+4(2).
YY = SY-DATUM+0(4).
CONCATENATE DD MM YY INTO L_DATE.
LOOP AT T_SUMMINV2.
WRITE T_SUMMINV2-KWERT TO W_KWERT NO-SIGN CURRENCY 'INR'.
CONDENSE W_KWERT NO-GAPS.
WRITE T_SUMMINV2-SALETAX TO W_TAX NO-SIGN CURRENCY 'INR'.
CONDENSE W_TAX NO-GAPS.
WRITE T_SUMMINV2-TOTAL TO W_TOTAL NO-SIGN CURRENCY 'INR'.
CONDENSE W_TOTAL NO-GAPS.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0100'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF05A-NEWKO'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'BKPF-BLDAT' L_DATE.
PERFORM BDC_FIELD USING 'BKPF-BLART' 'DC'.
PERFORM BDC_FIELD USING 'BKPF-BUKRS' P_BUKRS.
PERFORM BDC_FIELD USING 'BKPF-BUDAT' L_DATE.
PERFORM BDC_FIELD USING 'BKPF-MONAT' W_PERIOD.
PERFORM BDC_FIELD USING 'BKPF-WAERS' 'INR'.
PERFORM BDC_FIELD USING 'RF05A-NEWBS' '40'.
PERFORM BDC_FIELD USING 'RF05A-NEWKO' P_HKONT.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0300'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF05A-NEWKO'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'BSEG-WRBTR' W_KWERT.
PERFORM BDC_FIELD USING 'BSEG-ZUONR' T_SUMMINV2-KUNRG.
PERFORM BDC_FIELD USING 'RF05A-NEWBS' '40'.
PERFORM BDC_FIELD USING 'RF05A-NEWKO' '214116'.
PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/EENTE'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'COBL-GSBER'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0300'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF05A-NEWKO'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'BSEG-WRBTR' W_TAX.
PERFORM BDC_FIELD USING 'BSEG-ZUONR' T_SUMMINV2-KUNRG.
PERFORM BDC_FIELD USING 'RF05A-NEWBS' '31'.
PERFORM BDC_FIELD USING 'RF05A-NEWKO' T_SUMMINV2-KUNRG.
PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/EENTE'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'COBL-GSBER'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0302'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'BSEG-ZUONR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'BSEG-WRBTR' W_TOTAL.
PERFORM BDC_FIELD USING 'BSEG-ZUONR' T_SUMMINV2-KUNRG.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0302'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'BSEG-WRBTR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BS'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0700'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF05A-NEWBS'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BU'.
PERFORM BDC_TRANSACTION USING 'F-43'.
READ TABLE MESSTAB WITH KEY MSGID = 'F5' MSGNR = '312'.
IF SY-SUBRC EQ 0.
T_CRN-CRN_NO = MESSTAB-MSGV1.
APPEND T_CRN.
CLEAR T_CRN.
ENDIF.
ENDLOOP.
ENDFORM. " F006_UPLOADA
*&---------------------------------------------------------------------*
*& Form F007_READCRNOA
*&---------------------------------------------------------------------*
*& This Form is basically used to get the Credit Notes created
*----------------------------------------------------------------------*
FORM F007_READCRNOA.
**While a partial payout is happening the Values which are posted in
**F-43 based on the rate maintained in ZTARGET table has to flow in the
**ZCRN table
LOOP AT T_VALUE.
SELECT SINGLE VKBUR INTO T_VALUE-VKBUR
FROM KNVV
WHERE KUNNR EQ T_VALUE-KUNNR
AND VKORG EQ T_VALUE-VKORG
AND VTWEG EQ T_VALUE-VTWEG
AND SPART EQ T_VALUE-SPART.
SELECT SINGLE ZTGTRATE INTO T_VALUE-RATE FROM ZTARGET WHERE KUNNR =
T_VALUE-KUNNR AND VTWEG = T_VALUE-VTWEG
AND SPART = T_VALUE-SPART AND VKBUR = T_VALUE-VKBUR
AND ZCONTYPE = T_VALUE-KSCHL AND ZFM_MTHYR = W_MONTH.
IF SY-SUBRC EQ 0.
T_VALUE-KWERT = T_VALUE-BOX * T_VALUE-RATE.
ENDIF.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.