0% found this document useful (0 votes)
108 views2 pages

GRN Date Into BaseLine Date

The document outlines a requirement to add the old active GRN date as a baseline date in the MIRO transaction, with specific validation rules for considering GRNs. It details the implementation using a BADI (MRM_PAYMENT_TERMS) and provides code snippets to handle the logic for filtering out canceled and invoiced GRNs. Additionally, it addresses an error related to the baseline date being blank and includes a code enhancement to resolve this issue.

Uploaded by

Ajit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views2 pages

GRN Date Into BaseLine Date

The document outlines a requirement to add the old active GRN date as a baseline date in the MIRO transaction, with specific validation rules for considering GRNs. It details the implementation using a BADI (MRM_PAYMENT_TERMS) and provides code snippets to handle the logic for filtering out canceled and invoiced GRNs. Additionally, it addresses an error related to the baseline date being blank and includes a code enhancement to resolve this issue.

Uploaded by

Ajit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Requirement: Adding OLD active GRN date as a baseline date in MIRO.

Validation: Consider old GRN, if invoice generated then do not consider GRN, if canceled then do not consider.

BADI Used: MRM_PAYMENT_TERMS


Pass all data of RBKPV to respective variables. Consider highlighted code.

Code Start:
METHOD if_ex_mrm_payment_terms~payment_terms_set.

CHECK sy-tcode = 'MIRO' AND sy-ucomm = 'HEADER_PAY'.

DATA: lt_mkpf TYPE TABLE OF mkpf,


lwa_mkpf TYPE mkpf,
lt_mseg101 TYPE TABLE OF mseg,
lt_mseg102 TYPE TABLE OF mseg,
lt_rseg TYPE TABLE OF rseg,
lwa_rseg TYPE rseg,
lwa_drseg TYPE mmcr_drseg,
lv_basedate TYPE rbkp-zfbdt.

TYPES: BEGIN OF ty_date,


zfbdt TYPE rbkp-zfbdt,
ebeln TYPE ekko-ebeln,
mblnr TYPE mkpf-mblnr,
END OF ty_date.

DATA: lt_date TYPE TABLE OF ty_date,


lwa_date TYPE ty_date.

*************************
READ TABLE ti_drseg INTO lwa_drseg INDEX 1.

SELECT * FROM mseg INTO TABLE lt_mseg101


WHERE bwart = '101'
AND ebeln = lwa_drseg-ebeln.

SELECT * FROM mseg INTO TABLE lt_mseg102


WHERE bwart = '102'
AND ebeln = lwa_drseg-ebeln.

IF lt_mseg101 IS NOT INITIAL.


SORT: lt_mseg101 ASCENDING BY mjahr mblnr zeile.
ENDIF.

IF lt_mseg102 IS NOT INITIAL.


SORT: lt_mseg102 ASCENDING BY mjahr mblnr zeile.
ENDIF.

************* removing cancelled grn


IF lt_mseg101 IS NOT INITIAL.
LOOP AT lt_mseg101 INTO DATA(lwa_101).

READ TABLE lt_mseg102 INTO DATA(lwa_102)


WITH KEY smbln = lwa_101-mblnr
smblp = lwa_101-zeile
sjahr = lwa_101-mjahr.
IF sy-subrc = 0.
DELETE lt_mseg101 WHERE mblnr = lwa_101-mblnr
AND zeile = lwa_101-zeile
AND mjahr = lwa_101-mjahr.
ENDIF.

ENDLOOP.
ENDIF.

**************** removing invoiced/miro, grn


SELECT * FROM rseg INTO TABLE lt_rseg
FOR ALL ENTRIES IN lt_mseg101
WHERE ebeln = lt_mseg101-ebeln
* and ebelp = lt_mseg101-ebelp
AND lfbnr = lt_mseg101-mblnr
AND lfgja = lt_mseg101-mjahr.
IF lt_rseg IS NOT INITIAL.
LOOP AT lt_mseg101 INTO DATA(lwa_mseg101).
READ TABLE lt_rseg INTO lwa_rseg
WITH KEY lfbnr = lwa_mseg101-mblnr.
IF sy-subrc = 0.
DELETE lt_mseg101 WHERE mblnr = lwa_rseg-lfbnr.
ENDIF.
ENDLOOP.
ENDIF.
*************** fetch GRN date
IF lt_mseg101 IS NOT INITIAL.
SELECT * FROM mkpf INTO TABLE lt_mkpf
FOR ALL ENTRIES IN lt_mseg101
WHERE mblnr EQ lt_mseg101-mblnr
AND mjahr EQ lt_mseg101-mjahr.
ENDIF.

IF lt_mkpf IS NOT INITIAL.


SORT: lt_mkpf ASCENDING BY mjahr cputm cpudt mblnr.
READ TABLE lt_mkpf INTO lwa_mkpf INDEX 1.
IF sy-subrc = 0 .
CLEAR: lv_basedate.
lv_basedate = lwa_mkpf-budat.
ENDIF.
ENDIF.

IF lv_basedate IS NOT INITIAL.

READ TABLE lt_date INTO lwa_date


WITH KEY zfbdt = lv_basedate.
IF sy-subrc EQ 0 AND ( lv_basedate NE i_rbkpv-zfbdt ).
e_zfbdt = i_rbkpv-zfbdt.

ELSE.
e_zfbdt = lv_basedate.

CLEAR: lwa_date.
lwa_date-zfbdt = lv_basedate.
APPEND lwa_date TO lt_date.
CLEAR: lwa_date.

ENDIF.

ELSE.
e_zfbdt = i_rbkpv-zfbdt.
ENDIF.

IF i_rbkpv-zterm IS NOT INITIAL.


SELECT SINGLE * FROM t052 INTO @DATA(lwa_t052)
WHERE zterm = @i_rbkpv-zterm.
IF lwa_t052-ztag1 IS NOT INITIAL.

ENDIF.
ENDIF.

e_zbd1t = i_rbkpv-zbd1t.
IF e_zbd1t IS INITIAL.
e_zbd1t = lwa_t052-ztag1. “passing payment term days
ENDIF.

e_zbd1p = i_rbkpv-zbd1p.
e_zbd2t = i_rbkpv-zbd2t.
e_zbd2p = i_rbkpv-zbd2p.
e_zbd3t = i_rbkpv-zbd3t.
e_zlspr = i_rbkpv-zlspr.

ENDMETHOD.

FM: MRMBADI_PAYMENT_TERMS:
Due to Badi, while simulating, baseline date is getting blank and throws following error,
Error: ‘Baseline date for payment does not exist ,message no-M8 356’.

SO, to avoid/fix issue this FM is used.

Code:

ENHANCEMENT 1 ZIEHN_BASELINE_DATE_MIRO. "active version


IF e_zfbdt is INITIAL and sy-tcode = 'MIRO'. "added by ajit on 16102024
e_zfbdt = i_rbkpv-zfbdt.
ENDIF.
ENDENHANCEMENT.

You might also like