Skip to Content
0
Former Member
Nov 22, 2006 at 06:57 AM

Badi and Business event( Urgent)

102 Views

Hi experts,

I am new to badi and business event 1120P. Please post how this business event exactly comes in to picture in this badi. also how to find this business event?

And also Post the logic or code. The requirement is given below . Pls Post the solution. Its very urgent.

Enhancement Summary

Two user exits are needed to determine the correct G/L Account and Cost Center on Shipment Cost documents and post the Material Group on the Accounting document. BADI_SCD_ACCTG and Business Event 1120P can be used to accommodate the new functionality.

Business Process

Specific G/L Accounts and Cost Centers have to be determined to post on the Shipment Cost document. This is needed to provide accurate management reporting capabilities on shipments for Sales Order or Stock Transfer Order. A new custom table must be created which contains the following information: Distribution, Mode of Transport, Account, Cost Center Material group. Distribution is an identifier here if this shipment originated from an SO or STO.

There are no screens involved in this enhancement.

Components

Table: ZTABLE1

Field Data Element Type Length Description

MANDT MANDT CLNT (key) 3 Client

DISTRIBUTION Z_DISTRIBUTION CHAR (key) 1 Distribution

MOT ZZDEF_MOT CHAR (key) 2 Mode of Transportation

MATKL MATKL CHAR (key) 9 Material group

SAKNR SAKNR CHAR 10 G/L Account Number

KOSTL KOSTL CHAR 10 Cost Center

This table gets updated manually by the FI team.

Values for Distribution are:

‘1’ = Primary Distribution to Refinery

‘2’ = Primary and Secondary– Excluding refinery

All entries must be checked against SAP config and master tables

User exit BADI BADI_SCD_ACCTG will be used to determine the correct G/L Account, Cost Center and Product Group based on Distribution and Mode of Transport. This BADI gets called only when a new Shipment Cost document get created.

Once the BADI determined the new values it populates field c_vfkn-sakto with the G/L account, field c_vfkn-kostl with the Cost Center and exports the Product group to memory.

There is no field on the Shipment Cost Document to store the Product group. Therefore another mechanism must be used to get the Product Group on the accounting document.

Business Event 1120P can be used to import the Product group out of memory and put it on BSEG-MATNR. Structure BSEG_SUBST must be enhanced with field MATNR for this purpose.

Function, Rules, Exits Description of Functionality, Rules, Exits

BADI_SCD_ACCTG Business Add-In for Shipment Cost Account Assignment

Business Framework Business Event 1120P can be used to import the Product Group from memory and to populate field BSEG_SUBST-MATNR.

This event gets called from different places. It needs to be ensured that it only populates the value when it was called from BADI_SCD_ACCTG.

Custom Table A look-up Table needs to be maintained for Distribution, Mode of Transport, G/L Account, Cost Center and Material Group

Transaction code To maintain the new table

Append Structure To enhance structure BSEG_SUBST with MATNR

Business Add-In BADI_SCD_ACCTG can be used to determine the account assignments for a shipment cost item to set the G/L Account and Cost Center. All data needed to determine the new information gets provided in this BADI.

Logic:

• Determine if STO or SO based on Document Category from internal table I_REFOBJ-VTRLP field VGTYP If is C then Distribution type is Sales Order (Primary and Secondary – Excluding Refinery – ‘2’ ) else we need to check the receiving plant. If the receiving plant (I_REFOBJ-VTRLK field WERKS) is a refinery the Distribution type is Primary (1) else it’s a (Primary and Secondary – Excluding Refinery – ‘2’ ). Refineries can be identified via Function Module ZPLANTCLASSIFICATION. The plant must be passed into Import Parameter IP_SAPPLANT and field INT_PLANTCHAR-ATNAM must be looked up with value SAPTYPE. If it exists and field ATWRT contains ‘RFY’, the plant is a refinery.

• Product Group can be determined from the Material master through Material group field MARA-MATKL.

• Mode of Transport will be passed in the BADI in VTRLK-OIC_MOT.

• Select single entry from table ZTABLE1based on Distribution, Mode of Transport and Material Group. If nothing gets selected, error message ‘No entry exists in table ZTABLE1for Distribution (distribution), MOT (MOT) & Mat. Group (material group)’ should be triggered.

• Move ZTABLE1-SAKNR to c_vfkn-sakto and ZTABLE1-KOSTL to c_vfkn-kostl

• The Material group must be exported to memory in BADI_SCD_ACCTG

• The Material group must be imported from memory in Business Event BP1120P

• Free Memory in Business Event BP1120P

This is VI01 – Creation of Freight Cost Item screen

and also code for function module ZPLANTCLASSIFICATION below

FUNCTION zplantclassification .

*"----


""Local interface:

*" IMPORTING

*" REFERENCE(IP_SAPPLANT) LIKE AUSP-OBJEK OPTIONAL

*" REFERENCE(IP_CPSPLANT) LIKE AUSP-ATWRT OPTIONAL

*" REFERENCE(IP_SISLOC) LIKE AUSP-ATWRT OPTIONAL

*" EXPORTING

*" VALUE(EP_SAPPLANT) LIKE AUSP-OBJEK

*" VALUE(EP_CPSPLANT) LIKE AUSP-ATWRT

*" VALUE(EP_SISLOC) LIKE AUSP-ATWRT

*" VALUE(EP_OWNERSHIP) LIKE AUSP-ATWRT

*" VALUE(EP_SMISTYPE) LIKE AUSP-ATWRT

*" VALUE(EP_SPOTREF) LIKE AUSP-ATWRT

*" VALUE(EP_SUBTYPE) LIKE AUSP-ATWRT

*" VALUE(EP_SUPPLYREGION) LIKE AUSP-ATWRT

*" VALUE(EP_TYPE) LIKE AUSP-ATWRT

*" VALUE(EP_DISTAREA) LIKE AUSP-ATWRT

*" VALUE(EP_GEOGAREA) LIKE AUSP-ATWRT

*" VALUE(EP_HMF) LIKE AUSP-ATWRT

*" VALUE(EP_IATACODE) LIKE AUSP-ATWRT

*" VALUE(EP_IRSTCN) LIKE AUSP-ATWRT

*" VALUE(EP_OPSAREA) LIKE AUSP-ATWRT

*" VALUE(EP_PLANTSTAT) LIKE AUSP-ATWRT

*" VALUE(EP_PORTCODE) LIKE AUSP-ATWRT

*" VALUE(EP_REFAREA) LIKE AUSP-ATWRT

*" VALUE(EP_SAPTYPE) LIKE AUSP-ATWRT

*" VALUE(EP_MFGWARRANTY) LIKE AUSP-ATWRT

*" VALUE(EP_USERTYPE) LIKE AUSP-ATWRT

*" VALUE(EP_TRMCENTER) LIKE AUSP-ATWRT

*" VALUE(EP_TRANSCENTER) LIKE AUSP-ATWRT

*" VALUE(EP_FEIN) LIKE AUSP-ATWRT

*" TABLES

*" INT_PLANTCHAR STRUCTURE ZPLANTCLASSIFICATION OPTIONAL

*" EXCEPTIONS

*" NO_OBJEK_FOUND

*" NO_CPSPLANT_FOUND

*" NO_SISLOC_FOUND

*" NO_INPUT_FOUND

*" VALID_PLANT_NO_CHARACTERISTIC

*" ONE_TO_MANY_ISSUE

*" PLANT_NOT_FOUND_ZDEF_DELPLANT

*" UNKNOWN_ERRORS

*"----


************************************************************************

----


  • FM Name: ZPLANTCLASSIFICATION

  • Created By : SYUB *

----


  • Description : Function Module to retrieve plant characteristics *

  • The function module has two capabilities:

  • 1. Retrieve only the necessary characteristics

  • 2. Retrieve the whole characteristics into an internal table.

----


  • Parameter Description *

  • In the future, if there is a new characteristic added to the

  • plant classification tables, the characteristic has to be added

  • to the list of the export parameters and the loop statement.

TABLES: ausp, cabn, ksml, zdef_delplant.

DATA: ws_objek LIKE ausp-objek,

ws_countchar TYPE i,

ws_countplant TYPE i.

*Internal table for SAP plant

DATA: BEGIN OF int_plant OCCURS 0,

plant LIKE ausp-objek,

END OF int_plant.

*sap plant code is the input parameter.Move objek, atnam, and atwrt to

*internal table PLANTCHAR using inner join of AUSP, CABN, and KSML to

*synch up the internal characteristic numbers throughout the 3 tables.

IF NOT ip_sapplant IS INITIAL.

SELECT auspobjek cabnatnam ausp~atwrt

INTO CORRESPONDING FIELDS OF TABLE int_plantchar

FROM ksml AS ksml

INNER JOIN cabn AS cabn

ON cabnatinn = ksmlimerk

INNER JOIN ausp AS ausp

ON ausp~objek = ip_sapplant

AND auspatinn = cabnatinn

AND ausp~mafid = 'O'

AND ausp~klart = 'Z01'.

*Checking the existence of ip_sapplant in the table, if it doesn't

*exist, raise the exception else if it exists, check if it has

*characteristic values.

IF sy-subrc NE 0.

RAISE no_objek_found.

ELSE.

DESCRIBE TABLE int_plantchar LINES ws_countchar.

IF ws_countchar LT 2.

RAISE valid_plant_no_characteristic.

ENDIF.

ENDIF.

*cps plant code is the input parameter. Move objek from table AUSP to

*ws_objek using inner join of CABN and AUSP to match up the internal

*characteristic numbers from the 2 tables.

ELSEIF NOT ip_cpsplant IS INITIAL.

SELECT ausp~objek

INTO TABLE int_plant

FROM ausp AS ausp

INNER JOIN cabn AS cabn

ON cabn~atnam = 'OLDCODE'

WHERE auspatinn = cabnatinn

AND ausp~mafid = 'O'

AND ausp~klart = 'Z01'

AND ausp~atwrt = ip_cpsplant.

*Checking the existence of ip_cpsplant in the table

IF sy-subrc EQ 0.

*Counting the number of SAP plants in the internal table int_plant

DESCRIBE TABLE int_plant LINES ws_countplant.

*Moving the values of objek, atnam, and atwrt to PLANTCHAR using objek

*from ws_objek.

IF ws_countplant EQ 1.

LOOP AT int_plant.

SELECT auspobjek cabnatnam ausp~atwrt

INTO CORRESPONDING FIELDS OF TABLE int_plantchar

FROM ksml AS ksml

INNER JOIN cabn AS cabn

ON cabnatinn = ksmlimerk

INNER JOIN ausp AS ausp

ON ausp~objek = int_plant-plant

AND auspatinn = cabnatinn

AND ausp~mafid = 'O'

AND ausp~klart = 'Z01'.

ENDLOOP.

*If there more than one SAP Plants, then raise an exception.

ELSEIF ws_countplant GT 1.

RAISE one_to_many_issue.

ENDIF.

ELSE.

SELECT SINGLE werks FROM zdef_delplant

INTO ws_objek

WHERE cpsloc = ip_cpsplant.

SELECT auspobjek cabnatnam ausp~atwrt

INTO CORRESPONDING FIELDS OF TABLE int_plantchar

FROM ksml AS ksml

INNER JOIN cabn AS cabn

ON cabnatinn = ksmlimerk

INNER JOIN ausp AS ausp

ON ausp~objek = ws_objek

AND auspatinn = cabnatinn

AND ausp~mafid = 'O'

AND ausp~klart = 'Z01'.

if sy-subrc ne 0.

raise plant_not_found_zdef_delplant.

endif.

ENDIF.

*cps plant code is the input parameter. Move objek from table AUSP to

*ws_objek using inner join of CABN and AUSP to match up the internal

*characteristic numbers from the 2 tables.

ELSEIF NOT ip_sisloc IS INITIAL.

SELECT ausp~objek

INTO TABLE int_plant

FROM ausp AS ausp

INNER JOIN cabn AS cabn

ON cabn~atnam = 'SISLOC'

WHERE auspatinn = cabnatinn

AND ausp~mafid = 'O'

AND ausp~klart = 'Z01'

AND ausp~atwrt = ip_sisloc.

*Checking the existence of ip_sapplant in the table

IF sy-subrc EQ 0.

DESCRIBE TABLE int_plant LINES ws_countplant.

*Moving the values of objek, atnam, and atwrt to PLANTCHAR using objek

*from ws_objek.

IF ws_countplant EQ 1.

LOOP AT int_plant.

SELECT auspobjek cabnatnam ausp~atwrt

INTO CORRESPONDING FIELDS OF TABLE int_plantchar

FROM ksml AS ksml

INNER JOIN cabn AS cabn

ON cabnatinn = ksmlimerk

INNER JOIN ausp AS ausp

ON ausp~objek = int_plant-plant

AND auspatinn = cabnatinn

AND ausp~mafid = 'O'

AND ausp~klart = 'Z01'.

ENDLOOP.

*If there more than one SAP Plants, then raise an exception.

ELSEIF ws_countplant GT 1.

RAISE one_to_many_issue.

ENDIF.

ELSE.

SELECT SINGLE werks FROM zdef_delplant

INTO ws_objek

WHERE sisloc = ip_sisloc.

SELECT auspobjek cabnatnam ausp~atwrt

INTO CORRESPONDING FIELDS OF TABLE int_plantchar

FROM ksml AS ksml

INNER JOIN cabn AS cabn

ON cabnatinn = ksmlimerk

INNER JOIN ausp AS ausp

ON ausp~objek = ws_objek

AND auspatinn = cabnatinn

AND ausp~mafid = 'O'

AND ausp~klart = 'Z01'.

if sy-subrc ne 0.

raise plant_not_found_zdef_delplant.

endif.

ENDIF.

ELSE.

*Checking if there is an input parameter entered.

RAISE no_input_found.

ENDIF.

  • Modified 7/30 by RFOR to validate SAP plant is in plant master

data: wa_t001w like t001w.

read table int_plantchar.

SELECT SINGLE * from t001w into wa_t001w where

werks = int_plantchar-objek.

if sy-subrc ne 0.

raise NO_OBJEK_FOUND.

endif.

*Moving all the characteristic values to the export parameters

LOOP AT int_plantchar.

MOVE int_plantchar-objek TO ep_sapplant.

CASE int_plantchar-atnam.

WHEN 'OLDCODE'.

MOVE int_plantchar-atwrt TO ep_cpsplant.

WHEN 'SISLOC'.

MOVE int_plantchar-atwrt TO ep_sisloc.

WHEN 'OWNERSHIP'.

MOVE int_plantchar-atwrt TO ep_ownership.

WHEN 'SMISTYPE'.

MOVE int_plantchar-atwrt TO ep_smistype.

WHEN 'SPOTREF'.

MOVE int_plantchar-atwrt TO ep_spotref.

WHEN 'SUBTYPE'.

MOVE int_plantchar-atwrt TO ep_subtype.

WHEN 'SUPPLYREGION'.

MOVE int_plantchar-atwrt TO ep_supplyregion.

WHEN 'TYPE'.

MOVE int_plantchar-atwrt TO ep_type.

WHEN 'DISTAREA'.

MOVE int_plantchar-atwrt TO ep_distarea.

WHEN 'GEOGAREA'.

MOVE int_plantchar-atwrt TO ep_geogarea.

WHEN 'HMF'.

MOVE int_plantchar-atwrt TO ep_hmf.

WHEN 'IATACODE'.

MOVE int_plantchar-atwrt TO ep_iatacode.

WHEN 'IRSTCN'.

MOVE int_plantchar-atwrt TO ep_irstcn.

WHEN 'OPSAREA'.

MOVE int_plantchar-atwrt TO ep_opsarea.

WHEN 'PLANTSTAT'.

MOVE int_plantchar-atwrt TO ep_plantstat.

WHEN 'PORTCODE'.

MOVE int_plantchar-atwrt TO ep_portcode.

WHEN 'REFAREA'.

MOVE int_plantchar-atwrt TO ep_refarea.

WHEN 'SAPTYPE'.

MOVE int_plantchar-atwrt TO ep_saptype.

WHEN 'MFG_WARRANTY'.

MOVE int_plantchar-atwrt TO ep_mfgwarranty.

WHEN 'USER_TYPE'.

MOVE int_plantchar-atwrt TO ep_usertype.

WHEN 'TERMINALCENTER'.

MOVE int_plantchar-atwrt TO ep_trmcenter.

WHEN 'TRANSPORTATIONCENTER'.

MOVE int_plantchar-atwrt TO ep_transcenter.

when 'FEIN'.

move int_plantchar-atwrt to ep_fein.

ENDCASE.

ENDLOOP.

ENDFUNCTION.

Pls help me out from this problem its very urgent.

Thanks