2006 Dec 01 12:41 PM
How to set/ reset the dunning lock ( DUN_REASON)? This field appears in the transaction CAA2. Is there any function module for the same?
2006 Dec 01 12:54 PM
The below program is used for updating dunning lock and base status of CA...U can use the code which is required for ur requirement...
&----
*& Report ZFR_CA_UPDATE *
*& *
&----
REPORT ZFR_CA_UPDATE LINE-SIZE 120
LINE-COUNT 60
MESSAGE-ID ZF_CD.
*----type-pools
TYPE-POOLS:SLIS.
*TYPES
TYPES: BEGIN OF TY_CA_BP,
GPART TYPE GPART_KK,
END OF TY_CA_BP.
TYPES: BEGIN OF TY_LIQ_BP,
PARTNER TYPE BU_PARTNER,
ZZLIQSTATUS TYPE ZLIQSTATUS,
END OF TY_LIQ_BP.
TYPES: BEGIN OF TY_LOCK_OBJECT,
LOOBJ1 TYPE LOOBJ_KK,
END OF TY_LOCK_OBJECT.
TYPES: TY_CA_LOCKS TYPE STANDARD TABLE OF DFKKLOCKS,
TY_BASE_STATUS TYPE STANDARD TABLE OF ZZCATRANS.
TYPES: TY_CONTRACT_ACCOUNT TYPE STANDARD TABLE OF FKKVKP.
DATA: IT_CA TYPE STANDARD TABLE OF FKKVKP,
IT_CA_BP TYPE STANDARD TABLE OF TY_CA_BP,
IT_LOCK_OBJECT TYPE TABLE OF TY_LOCK_OBJECT,
IT_CA_LOCKS TYPE STANDARD TABLE OF DFKKLOCKS,
IT_LIQ_BP TYPE STANDARD TABLE OF TY_LIQ_BP.
*----Internal tables
DATA:BEGIN OF IT_OUT OCCURS 0,
VKONT TYPE VKONT_KK,
GPART TYPE GPART_KK,
ZZBASE_STATUS TYPE ZZBASE_STATUS,
TEXT TYPE CHAR16,
END OF IT_OUT.
DATA IT_FCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
*----Work area
DATA: WA_OUT LIKE LINE OF IT_OUT,
WA_CA TYPE FKKVKP,
WA_CA_BP TYPE TY_CA_BP,
WA_LOCK_OBJECT TYPE TY_LOCK_OBJECT,
WA_LIQ_BP TYPE TY_LIQ_BP.
*----Variable
DATA:W_YESTER_DATE TYPE SYDATUM,
W_LOOBJ TYPE LOOBJ_KK.
SELECT-OPTIONS:S_DATE FOR SY-DATUM.
INITIALIZATION.
W_YESTER_DATE = SY-DATUM - 1.
MOVE: 'BT' TO S_DATE-OPTION,
W_YESTER_DATE TO S_DATE-LOW,
SY-DATUM TO S_DATE-HIGH.
APPEND S_DATE.
*----start-of-selection
START-OF-SELECTION.
Get Contract Account Details
PERFORM GET_CA USING S_DATE[]
CHANGING IT_CA.
*Update Base Status and Dunning Lock of Contract Account
PERFORM UPD_BASE_ST_AND_LOCK USING IT_CA.
*----end of selection
END-OF-SELECTION.
*Display output
PERFORM DISPLAY_OUTPUT.
&----
*& Form DISPLAY_OUTPUT
&----
Display the output
----
FORM DISPLAY_OUTPUT .
DATA:L_REPID LIKE SY-REPID.
IF IT_FCAT[] IS INITIAL.
CLEAR IT_FCAT.
IT_FCAT-TABNAME = 'IT_OUT'.
IT_FCAT-FIELDNAME = 'VKONT'.
IT_FCAT-SELTEXT_L = TEXT-001.
IT_FCAT-COL_POS = 1.
IT_FCAT-OUTPUTLEN = 18.
IT_FCAT-DO_SUM = 'X'.
APPEND IT_FCAT.
CLEAR IT_FCAT.
IT_FCAT-TABNAME = 'IT_OUT'.
IT_FCAT-FIELDNAME = 'GPART'.
IT_FCAT-SELTEXT_L = TEXT-002.
IT_FCAT-OUTPUTLEN = 21.
IT_FCAT-COL_POS = 2.
APPEND IT_FCAT.
CLEAR IT_FCAT.
IT_FCAT-TABNAME = 'IT_OUT'.
IT_FCAT-FIELDNAME = 'ZZBASE_STATUS'.
IT_FCAT-SELTEXT_L = TEXT-003.
IT_FCAT-OUTPUTLEN = 2.
IT_FCAT-COL_POS = 3.
APPEND IT_FCAT.
CLEAR IT_FCAT.
IT_FCAT-TABNAME = 'IT_OUT'.
IT_FCAT-FIELDNAME = 'TEXT'.
IT_FCAT-SELTEXT_L = TEXT-004.
IT_FCAT-OUTPUTLEN = 17.
IT_FCAT-COL_POS = 4.
APPEND IT_FCAT.
ENDIF.
L_REPID = SY-REPID.
IF IT_OUT[] IS INITIAL.
MESSAGE I004 WITH TEXT-006.
ELSE.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = L_REPID
IT_FIELDCAT = IT_FCAT[]
TABLES
T_OUTTAB = IT_OUT[]
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDFORM. " DISPLAY_OUTPUT
&----
*& Form GET_CA
&----
Get Contract Accounts from FKKVKP table and Liquidation Status
of the Buisness Partners of the Contract Accounts from BUT000
table
----
-->P_DATE Date
<--P_CA Internal table storing Contract Accounts
----
FORM GET_CA USING P_DATE LIKE S_DATE[]
CHANGING P_CA TYPE TY_CONTRACT_ACCOUNT.
CLEAR: P_CA, IT_CA_BP, IT_LIQ_BP.
*Get Contract Account from FKKVKP table
SELECT *
INTO TABLE P_CA
FROM FKKVKP
WHERE ERDAT IN P_DATE.
CHECK SY-SUBRC = 0.
SORT P_CA BY GPART.
*Store the distinct Business Partners from Internal table IT_CA in
*Internal table IT_CA_BP
LOOP AT P_CA INTO WA_CA.
WA_CA_BP-GPART = WA_CA-GPART.
APPEND WA_CA_BP TO IT_CA_BP.
CLEAR WA_CA_BP.
CLEAR W_LOOBJ.
W_LOOBJ = WA_CA-VKONT.
W_LOOBJ+12(10) = WA_CA-GPART.
WA_LOCK_OBJECT-LOOBJ1 = W_LOOBJ.
APPEND WA_LOCK_OBJECT TO IT_LOCK_OBJECT.
CLEAR WA_LOCK_OBJECT.
ENDLOOP.
IF NOT IT_CA_BP IS INITIAL.
SORT IT_CA_BP BY GPART.
DELETE ADJACENT DUPLICATES FROM IT_CA_BP.
*Get Liquidation Status of the Business Partner from BUT000 table
SELECT PARTNER ZZLIQSTATUS
INTO TABLE IT_LIQ_BP
FROM BUT000
FOR ALL ENTRIES IN IT_CA_BP
WHERE PARTNER = IT_CA_BP-GPART.
IF SY-SUBRC = 0.
SORT IT_LIQ_BP BY PARTNER.
ENDIF.
CLEAR IT_CA_BP.
ENDIF.
IF NOT IT_LOCK_OBJECT IS INITIAL.
SORT IT_LOCK_OBJECT BY LOOBJ1.
DELETE ADJACENT DUPLICATES FROM IT_LOCK_OBJECT
COMPARING LOOBJ1.
*Get all the Dunning Locks for the Contract Account in Internal table
*IT_CA_LOCKS
SELECT * FROM DFKKLOCKS
INTO TABLE IT_CA_LOCKS
FOR ALL ENTRIES IN IT_LOCK_OBJECT
WHERE LOOBJ1 = IT_LOCK_OBJECT-LOOBJ1
AND LOTYP = '06'
AND PROID = '01'.
IF SY-SUBRC = 0.
SORT IT_CA_LOCKS BY LOOBJ1 LOCKR.
ENDIF.
CLEAR IT_LOCK_OBJECT.
ENDIF.
ENDFORM. " GET_CA
&----
*& Form UPD_BASE_ST_AND_LOCK
&----
Update Base Status and Dunning Lock of the Contract Accounts
----
-->P_CA Internal table storing Contract Accounts
----
FORM UPD_BASE_ST_AND_LOCK USING P_CA TYPE TY_CONTRACT_ACCOUNT.
DATA: PW_CA TYPE FKKVKP.
CLEAR IT_OUT.
REFRESH IT_OUT.
LOOP AT P_CA INTO PW_CA.
*Get the Liquidation Status of the Business Partner corresponding to
*the Contract Account
READ TABLE IT_LIQ_BP INTO WA_LIQ_BP
WITH KEY PARTNER = PW_CA-GPART
BINARY SEARCH.
CHECK SY-SUBRC = 0.
For 'Liquidated' and 'In Liquidation' Status, add Liquidation Dunning
Lock to the Contract Account and Update Base Status to Liquidation
PERFORM ADD_LIQ_LOCK_AND_BASE_ST USING IT_CA_LOCKS
WA_LIQ_BP
PW_CA.
For Business Partner which are not Liquidated, remove Liquidation
Dunning Lock from the Contract Account if it already has one and
update Base Status according to the Dunning Locks present
PERFORM REM_LIQ_LOCK_AND_BASE_ST USING IT_CA_LOCKS
WA_LIQ_BP
PW_CA.
ENDLOOP.
ENDFORM. " UPD_BASE_ST_AND_LOCK
&----
*& Form ADD_LIQ_LOCK_AND_BASE_ST
&----
If Liquidation Status of the Business Partner is 'Liquidated' or
'In Liquidation', this subroutine adds Liquidation Dunning Lock
to the Contract Account if it does not already exist and update
the Base Status of the Contract Account to Liquidation
----
-->P_CA_LOCKS Internal table to store the Dunning Locks of CA
-->P_LIQ_BP Structure to store Liq status of the BP
-->P_CA Structure to store Contract Account
----
FORM ADD_LIQ_LOCK_AND_BASE_ST USING P_CA_LOCKS TYPE TY_CA_LOCKS
P_LIQ_BP TYPE TY_LIQ_BP
P_CA TYPE FKKVKP.
DATA: PW_CA_LOCKS TYPE DFKKLOCKS.
CHECK ( P_LIQ_BP-ZZLIQSTATUS = '001' ) OR
( P_LIQ_BP-ZZLIQSTATUS = '002' ).
CLEAR W_LOOBJ.
W_LOOBJ = P_CA-VKONT.
W_LOOBJ+12(10) = P_CA-GPART.
*Check whether Lquidation Dunning Lock already exists for the Contract
*Account
READ TABLE P_CA_LOCKS INTO PW_CA_LOCKS
WITH KEY LOOBJ1 = W_LOOBJ
LOCKR = '4'
BINARY SEARCH.
*If Lquidation dunning lock does not exist for the CA
IF SY-SUBRC <> 0.
*Create Liquidation Dunning Lock for the Contract Account
CALL FUNCTION 'FKK_S_LOCK_CREATE'
EXPORTING
I_LOOBJ1 = W_LOOBJ
I_GPART = P_CA-GPART
I_VKONT = P_CA-VKONT
I_PROID = '01'
I_LOTYP = '06'
I_LOCKR = '4'
I_FDATE = SY-DATUM
I_TDATE = '99991231'
EXCEPTIONS
ALREADY_EXIST = 1
IMP_DATA_NOT_COMPLETE = 2
NO_AUTHORITY = 3
ENQUEUE_LOCK = 4
WRONG_DATA = 5
OTHERS = 6.
IF SY-SUBRC <> 0.
MESSAGE I004(ZF_CD) WITH TEXT-005 P_CA-VKONT.
ELSE.
WA_OUT-TEXT = 'LIQ LOCK CREATED'.
WA_OUT-VKONT = P_CA-VKONT.
WA_OUT-GPART = P_CA-GPART.
ENDIF.
ENDIF.
*Check whether Base Status is not set to Liquidation
IF P_CA-ZZBASE_STATUS <> '4'.
*If Base Status is not set to Liquidation, update it with the same.
PERFORM UPD_BASE_STATUS USING P_CA
'4'.
ENDIF.
*Populate Internal table for display
CHECK NOT WA_OUT IS INITIAL.
IF WA_OUT-ZZBASE_STATUS IS INITIAL.
WA_OUT-ZZBASE_STATUS = P_CA-ZZBASE_STATUS.
ENDIF.
APPEND WA_OUT TO IT_OUT.
CLEAR WA_OUT.
ENDFORM. " ADD_LIQ_LOCK_AND_BASE_ST
&----
*& Form REM_LIQ_LOCK_AND_BASE_ST
&----
If the Business Partner is not liquidated and if the CA has
Liquidation dunning lock, this subroutine removes the
Liquidation Lock and updates the Base Status as per the Dunning
Lock present
----
-->P_CA_LOCKS Internal table to store locks of the CA
-->P_LIQ_BP Structure to store Liquidation status of BP
-->P_CA Structure to store Contract Account
----
FORM REM_LIQ_LOCK_AND_BASE_ST USING P_CA_LOCKS TYPE TY_CA_LOCKS
P_LIQ_BP TYPE TY_LIQ_BP
P_CA TYPE FKKVKP.
DATA: PW_CA_LOCKS TYPE DFKKLOCKS,
WA_BASE_STAT_TMP TYPE ZZCATRANS,
WA_BASE_STAT TYPE ZZCATRANS,
IT_BASE_STAT TYPE STANDARD TABLE OF ZZCATRANS.
*Check whether the Business Partner is not Liquidated
CHECK ( P_LIQ_BP-ZZLIQSTATUS <> '001' ) AND
( P_LIQ_BP-ZZLIQSTATUS <> '002' ).
CLEAR W_LOOBJ.
W_LOOBJ = P_CA-VKONT.
W_LOOBJ+12(10) = P_CA-GPART.
*Check whether Contract Account has Liquidation Dunning Lock
READ TABLE P_CA_LOCKS INTO PW_CA_LOCKS
WITH KEY LOOBJ1 = W_LOOBJ
LOCKR = '4'
BINARY SEARCH.
IF SY-SUBRC = 0.
*Remove the Liquidation Dunning Lock
CALL FUNCTION 'FKK_S_LOCK_DELETE'
EXPORTING
I_LOOBJ1 = W_LOOBJ
I_GPART = P_CA-GPART
I_VKONT = P_CA-VKONT
I_PROID = '01'
I_LOTYP = '06'
I_LOCKR = '4'
I_FDATE = PW_CA_LOCKS-FDATE
I_TDATE = PW_CA_LOCKS-TDATE.
DELETE TABLE P_CA_LOCKS FROM PW_CA_LOCKS.
WA_OUT-TEXT = 'LIQ LOCK REMOVED'.
WA_OUT-VKONT = P_CA-VKONT.
WA_OUT-GPART = P_CA-GPART.
ENDIF.
IF ( P_CA_LOCKS IS INITIAL ) AND ( P_CA-ZZBASE_STATUS <> SPACE ).
*Update Base Status to Space
PERFORM UPD_BASE_STATUS USING P_CA
SPACE.
ELSE.
READ TABLE P_CA_LOCKS INTO PW_CA_LOCKS
WITH KEY LOOBJ1 = W_LOOBJ
LOCKR = '3'
BINARY SEARCH.
IF ( SY-SUBRC = 0 ) AND ( P_CA-ZZBASE_STATUS <> '3' ).
*Update Base Status to Commutation
PERFORM UPD_BASE_STATUS USING P_CA
'3'.
ELSE.
READ TABLE P_CA_LOCKS INTO PW_CA_LOCKS
WITH KEY LOOBJ1 = W_LOOBJ
LOCKR = '2'
BINARY SEARCH.
IF ( SY-SUBRC = 0 ) AND ( P_CA-ZZBASE_STATUS <> '2' ).
*Update Base Status to Legal Dispute
PERFORM UPD_BASE_STATUS USING P_CA
'2'.
ENDIF.
ENDIF.
ENDIF.
CHECK NOT WA_OUT IS INITIAL.
APPEND WA_OUT TO IT_OUT.
CLEAR WA_OUT.
ENDFORM. " REM_LIQ_LOCK_AND_BASE_ST
&----
*& Form UPD_BASE_STATUS
&----
Update Base Status with the Lock Reason value
----
-->P_CA Internal table to store Contract Account
-->P_LOCK Lock Reason
----
FORM UPD_BASE_STATUS USING P_CA TYPE FKKVKP
VALUE(P_LOCK).
DATA: WA_BASE_STAT_TMP TYPE ZZCATRANS,
WA_BASE_STAT TYPE ZZCATRANS,
IT_BASE_STAT TYPE STANDARD TABLE OF ZZCATRANS.
CLEAR WA_BASE_STAT_TMP.
CALL FUNCTION 'NO_DATA_INITIALIZE'
EXPORTING
I_STRUCTURE = 'ZZCATRANS'
I_NODATA = '/'
CHANGING
E_DATA = WA_BASE_STAT_TMP.
CLEAR: IT_BASE_STAT, WA_BASE_STAT.
*Update Base Status of the Contract Account with the value in
*P_LOCK
WA_BASE_STAT_TMP-AKTYP = '02'.
WA_BASE_STAT_TMP-VKONT = P_CA-VKONT.
WA_BASE_STAT_TMP-GPART = P_CA-GPART.
WA_BASE_STAT_TMP-PARTNER = P_CA-GPART.
WA_BASE_STAT_TMP-OPBUK = P_CA-OPBUK.
WA_BASE_STAT_TMP-TOGRU = P_CA-TOGRU.
WA_BASE_STAT_TMP-VKPBZ = P_CA-VKPBZ.
WA_BASE_STAT_TMP-STDBK = P_CA-STDBK.
WA_BASE_STAT_TMP-ZZBASE_STATUS = P_LOCK.
APPEND WA_BASE_STAT_TMP TO IT_BASE_STAT.
CALL FUNCTION 'ZZ_CACCOUNT_MAINTAIN'
TABLES
T_CA = IT_BASE_STAT.
WA_OUT-ZZBASE_STATUS = P_LOCK.
WA_OUT-VKONT = P_CA-VKONT.
WA_OUT-GPART = P_CA-GPART.
ENDFORM. " UPD_BASE_STATUS
2006 Dec 01 1:29 PM
Hi Ramesh..
I think that should be useful..I'll check it out. Meanwhile, I have another issue :
How can we reset the dunning level to 0? Any function module to do the same?? Thanks in advance.
2006 Dec 01 3:04 PM