Substitution User Exit

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14
At a glance
Powered by AI
The document describes various SAP user exits, their purposes, and how to define new user exits. It provides information on standard user exits, parameter types used by exits, and how to include new exits.

The user exits described are used for tasks like substituting fields, validating values, and reading additional data from database tables. They allow customizing SAP applications by modifying fields or adding additional logic at specific points in business processes.

The parameter types that can be used by user exits include no parameters, a single field, or a data type. This determines how the exit is called and what data it can access.

Substitution user exit

1.
2.
3.
4.
5.

Made this program to RGGBS000 to Z program.

ZRGGBS000

PROGRAM ZRGGBS000 .
*---------------------------------------------------------------------*
* Corrections/ repair
* wms092357 070703 Note 638886: template routines to be used for
* workaround to substitute bseg-bewar from bseg-xref1/2
*---------------------------------------------------------------------*
* *
* Substitutions: EXIT-Formpool for Uxxx-Exits *
* *
* This formpool is used by SAP for testing purposes only. *
* *
* Note: If you define a new user exit, you have to enter your *
* user exit in the form routine GET_EXIT_TITLES. *
* *
*---------------------------------------------------------------------*
INCLUDE FGBBGD00. "Standard data types

*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*
* PLEASE INCLUDE THE FOLLOWING "TYPE-POOL" AND "TABLES" COMMANDS *
* IF THE ACCOUNTING MODULE IS INSTALLED IN YOUR SYSTEM *
TYPE-POOLS: GB002. " TO BE INCLUDED IN "wms092357
TABLES: BKPF, " ANY SYSTEM THAT "wms092357
BSEG, " HAS 'FI' INSTALLED "wms092357
COBL, "wms092357
CSKS, "wms092357
ANLZ, "wms092357
GLU1. "wms092357
*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*

*----------------------------------------------------------------------*
* FORM GET_EXIT_TITLES *
*----------------------------------------------------------------------*
* returns name and title of all available standard-exits *
* every exit in this formpool has to be added to this form. *
* You have to specify a parameter type in order to enable the *
* code generation program to determine correctly how to *
* generate the user exit call, i.e. how many and what kind of *
* parameter(s) are used in the user exit. *
* The following parameter types exist: *
* *
* TYPE Description Usage *
* ------------------------------------------------------------ *
* C_EXIT_PARAM_NONE Use no parameter Subst. and Valid. *
* except B_RESULT *
* C_EXIT_PARAM_FIELD Use one field as param. Only Substitution *
* C_EXIT_PARAM_CLASS Use a type as parameter Subst. and Valid *
* *
*----------------------------------------------------------------------*
* --> EXIT_TAB table with exit-name and exit-titles *
* structure: NAME(5), PARAM(1), TITEL(60)
*----------------------------------------------------------------------*
FORM GET_EXIT_TITLES TABLES ETAB.

DATA: BEGIN OF EXITS OCCURS 50,


NAME(5) TYPE C,
PARAM LIKE C_EXIT_PARAM_NONE,
TITLE(60) TYPE C,
END OF EXITS.

EXITS-NAME = 'U100'.
EXITS-PARAM = C_EXIT_PARAM_NONE.
EXITS-TITLE = TEXT-100. "Cost center from CSKS
APPEND EXITS.

EXITS-NAME = 'U101'.
EXITS-PARAM = C_EXIT_PARAM_FIELD.
EXITS-TITLE = TEXT-101. "Cost center from CSKS
APPEND EXITS.

* begin of insertion "wms092357


EXITS-NAME = 'U200'.
EXITS-PARAM = C_EXIT_PARAM_FIELD.
EXITS-TITLE = TEXT-200. "Cons. transaction type
APPEND EXITS. "from xref1/2
* end of insertion "wms092357

EXITS-NAME = 'RAMA'.
EXITS-PARAM = C_EXIT_PARAM_FIELD.
EXITS-TITLE = TEXT-
200. "Cons. transaction type
APPEND EXITS. "from xref1/2

************************************************************************
* PLEASE DELETE THE FIRST '*' FORM THE BEGINING OF THE FOLLOWING LINES *
* IF THE ACCOUNTING MODULE IS INSTALLED IN YOUR SYSTEM: *
* EXITS-NAME = 'U102'.
* EXITS-PARAM = C_EXIT_PARAM_CLASS.
* EXITS-TITLE = TEXT-102. "Sum is used for the reference.
* APPEND EXITS.

***********************************************************************
** EXIT EXAMPLES FROM PUBLIC SECTOR INDUSTRY SOLUTION
**
** PLEASE DELETE THE FIRST '*' FORM THE BEGINING OF THE FOLLOWING LINE
** TO ENABLE PUBLIC SECTOR EXAMPLE SUBSTITUTION EXITS
***********************************************************************
INCLUDE RGGBS_PS_TITLES.

REFRESH ETAB.
LOOP AT EXITS.
ETAB = EXITS.
APPEND ETAB.
ENDLOOP.
ENDFORM. "GET_EXIT_TITLES

*&---------------------------------------------------------------------*
*& Form U100
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->IM_PRCTR text
*----------------------------------------------------------------------*
FORM RAMA USING IM_PRCTR.
****************************************************************
****
*********************Declaring local Structure
TYPES: BEGIN OF TY_VBAK,
VBELN TYPE VBAK-VBELN,
VKORG TYPE VBAK-VKORG,
KUNNR TYPE VBAK-KUNNR,
NETWR TYPE VBAK-NETWR,
ERDAT TYPE VBAK-ERDAT,
END OF TY_VBAK,
BEGIN OF TY_CAN,
VBELN TYPE VBAK-VBELN,
VKORG TYPE VBAK-VKORG,
KUNNR TYPE VBAK-KUNNR,
VBTYP TYPE VBAK-VBTYP, "SD document categ.
AUART TYPE VBAK-AUART, "Sales Document Type
AUGRU TYPE VBAK-AUGRU, "Order reason
VGBEL TYPE VBAK-VGBEL,
ERDAT TYPE VBAK-ERDAT,
END OF TY_CAN.
****************************************************************
*******************
********Declaring Variable, interal table , work-
area******************************
DATA : LV_PRCTR TYPE PRCTR.

DATA : GW_PRPS TYPE PRPS,


GV_PSPNR TYPE COBL-PS_PSP_PNR,
GV_MEM TYPE SY-UNAME,
GV_PRCTR TYPE PRPS-PRCTR,
GV_GSBER TYPE COBL-GSBER,
GV_KUNNR TYPE BSEG-KUNNR,
GV_MATNR TYPE VBAP-MATNR,
GV_VBELN TYPE VBAK-VBELN,
WA_WBS TYPE ZEX_RAM_WBS,
WA_VKORG TYPE ZSD_VKORG,

IT_CAN TYPE TABLE OF TY_CAN,


WA_CAN TYPE TY_CAN,
IT_VBAK TYPE TABLE OF TY_VBAK,
WA_VBAK TYPE TY_VBAK.

DATA : OBJECT TYPE AUSP-OBJEK ,


LV_MATNR TYPE MARA-MATNR ,
IT_AUSP TYPE TABLE OF AUSP WITH HEADER LINE ,
IT_SCLASS TYPE TABLE OF SCLASS WITH HEADER LINE
,
IT_CLOBJDAT TYPE TABLE OF CLOBJDAT WITH HEADER LIN
E,
GV_SALESPHASE TYPE AUSP-ATWRT,
LV_SALESPHASE TYPE AUSP-ATINN,
LV_KUNNR TYPE KNA1-KUNNR.
****************************************************************
******************
*********************Defining Range for sales org.
RANGES: R_VKORG FOR ZSD_VKORG.
**********************************************

CLEAR:WA_WBS-WBS, GW_PRPS, GV_SALESPHASE, OBJECT, GV_VBELN,


GV_KUNNR, GV_GSBER, GV_MATNR,IT_SCLASS, IT_CLOBJDAT,LV_S
ALESPHASE,
R_VKORG,WA_VKORG,LV_KUNNR.

REFRESH:IT_SCLASS, IT_CLOBJDAT,R_VKORG,R_VKORG[].

MOVE COBL-GSBER TO GV_GSBER.


MOVE BSEG-KUNNR TO GV_KUNNR.

R_VKORG-SIGN = 'I'.
R_VKORG-OPTION = 'EQ'.
R_VKORG-LOW = GV_GSBER.
APPEND R_VKORG.

IF GV_KUNNR IS NOT INITIAL.


*******Checking for Ramrajya customer
SELECT SINGLE * FROM ZSD_VKORG INTO WA_VKORG WHERE VKORG = R
_VKORG-LOW.
IF WA_VKORG-PFACH IS NOT INITIAL.
*****Fetching data using PO BOX
SELECT SINGLE KUNNR FROM KNA1 INTO LV_KUNNR WHERE KUNNR =
GV_KUNNR AND PFACH = WA_VKORG-PFACH.
*******Compare entered customer and fechted customer.
IF LV_KUNNR EQ GV_KUNNR.
********Finding sales order.
SELECT VBELN VKORG KUNNR NETWR ERDAT FROM VBAK INTO TA
BLE IT_VBAK
WHERE KUNNR = GV_KUNNR AND VKORG = WA_VKORG-VKORG
AND AUART = 'ZNOR' AND VBTYP = 'C'.

IF IT_VBAK[] IS NOT INITIAL.


SELECT VBELN
VKORG
KUNNR
VBTYP
AUART
AUGRU
VGBEL FROM VBAK INTO CORRESPONDING FIELDS OF TABLE I
T_CAN
FOR ALL ENTRIES IN IT_VBAK WHERE VGBEL = IT_VBAK-
VBELN AND
KUNNR = IT_VBAK-KUNNR AND VKORG = IT_VBAK-
VKORG AND AUGRU = '011'
OR AUGRU = '009' AND AUART = 'G2'.
***********deleteing cancled Order
LOOP AT IT_CAN INTO WA_CAN.
DELETE IT_VBAK WHERE VBELN = WA_CAN-VGBEL.
CLEAR: WA_CAN.
ENDLOOP.
ENDIF.

READ TABLE IT_VBAK INTO WA_VBAK INDEX 1.


IF SY-SUBRC = 0.
SELECT SINGLE MATNR FROM VBAP INTO GV_MATNR WHERE
VBELN = WA_VBAK-VBELN.

IF GV_MATNR IS NOT INITIAL.


MOVE GV_MATNR TO OBJECT .
********************Fetching Classification details using materi
al
CALL FUNCTION 'CONVERSION_EXIT_ATINN_INPUT'
EXPORTING
INPUT = 'ZRAM_SALESPHASE'
IMPORTING
OUTPUT = LV_SALESPHASE.

SELECT SINGLE ATWRT FROM AUSP INTO GV_SALESPHASE


WHERE ATINN = LV_SALESPHASE AND OBJEK = OBJECT .

IF GV_SALESPHASE IS NOT INITIAL.


SELECT SINGLE * FROM ZEX_RAM_WBS INTO
WA_WBS WHERE VKORG = COBL-
GSBER AND PHASE = GV_SALESPHASE .
IF WA_WBS-WBS IS NOT INITIAL.
SELECT SINGLE PSPNR OBJNR PRCTR POSID FROM PRPS
INTO CORRESPONDING FIELDS OF GW_PRPS
WHERE PSPNR EQ WA_WBS-WBS.

IF GW_PRPS-OBJNR IS NOT INITIAL.


COBL-PS_PSP_PNR = WA_WBS-WBS.
ENDIF.

ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
CLEAR:WA_WBS-WBS, GW_PRPS, GV_SALESPHASE, OBJECT, GV_VBELN,
GV_KUNNR, GV_GSBER, GV_MATNR,IT_SCLASS, IT_CLOBJDAT.

REFRESH:IT_SCLASS, IT_CLOBJDAT.

ENDFORM. "U100

* eject
*---------------------------------------------------------------------*
* FORM U100 *
*---------------------------------------------------------------------*
* Reads the cost-center from the CSKS table . *
*---------------------------------------------------------------------*
FORM U100.

*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* PLEASE DELETE THE FIRST '*' FORM THE BEGINING OF THE FOLLOWING LINES *
* IF THE ACCOUNTING MODULE IS INSTALLED IN YOUR SYSTEM: *
* SELECT * FROM CSKS
* WHERE KOSTL EQ COBL-KOSTL
* AND KOKRS EQ COBL-KOKRS.
* IF CSKS-DATBI >= SY-DATUM AND
* CSKS-DATAB <= SY-DATUM.
*
* MOVE CSKS-ABTEI TO COBL-KOSTL.
*
* ENDIF.
* ENDSELECT.

ENDFORM. "U100

* eject
*---------------------------------------------------------------------*
* FORM U101 *
*---------------------------------------------------------------------*
* Reads the cost-center from the CSKS table for accounting *
* area '0001'. *
* This exit uses a parameter for the cost_center so it can *
* be used irrespective of the table used in the callup point. *
*---------------------------------------------------------------------*
FORM U101 USING COST_CENTER.

*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* PLEASE DELETE THE FIRST '*' FORM THE BEGINING OF THE FOLLOWING LINES *
* IF THE ACCOUNTING MODULE IS INSTALLED IN YOUR SYSTEM: *
* SELECT * FROM CSKS
* WHERE KOSTL EQ COST_CENTER
* AND KOKRS EQ '0001'.
* IF CSKS-DATBI >= SY-DATUM AND
* CSKS-DATAB <= SY-DATUM.
*
* MOVE CSKS-ABTEI TO COST_CENTER .
*
* ENDIF.
* ENDSELECT.

ENDFORM. "U101

* eject
*---------------------------------------------------------------------*
* FORM U102 *
*---------------------------------------------------------------------*
* Inserts the sum of the posting into the reference field. *
* This exit can be used in FI for the complete document. *
* The complete data is passed in one parameter. *
*---------------------------------------------------------------------*

*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* PLEASE DELETE THE FIRST '*' FORM THE BEGINING OF THE FOLLOWING LINES *
* IF THE ACCOUNTING MODULE IS INSTALLED IN YOUR SYSTEM: *
*FORM u102 USING bool_data TYPE gb002_015.
*DATA: SUM(10) TYPE C.
*
* LOOP AT BOOL_DATA-BSEG INTO BSEG
* WHERE SHKZG = 'S'.
* BSEG-ZUONR = 'Test'.
* MODIFY BOOL_DATA-BSEG FROM BSEG.
* ADD BSEG-DMBTR TO SUM.
* ENDLOOP.
*
* BKPF-XBLNR = TEXT-001.
* REPLACE '&' WITH SUM INTO BKPF-XBLNR.
*
*ENDFORM.

***********************************************************************
** EXIT EXAMPLES FROM PUBLIC SECTOR INDUSTRY SOLUTION
**
** PLEASE DELETE THE FIRST '*' FORM THE BEGINING OF THE FOLLOWING LINE
** TO ENABLE PUBLIC SECTOR EXAMPLE SUBSTITUTION EXITS
***********************************************************************
*INCLUDE rggbs_ps_forms.

*eject
* begin of insertion "wms092357
*&---------------------------------------------------------------------*
*& Form u200
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM U200 USING E_RMVCT TYPE BSEG-BEWAR.
PERFORM XREF_TO_RMVCT USING BKPF BSEG 1 CHANGING E_RMVCT.
ENDFORM. "u200

*&---------------------------------------------------------------------*
*& Form xref_to_rmvct
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM XREF_TO_RMVCT
USING IS_BKPF TYPE BKPF
IS_BSEG TYPE BSEG
I_XREF_FIELD TYPE I
CHANGING C_RMVCT TYPE RMVCT.

DATA L_MSGV TYPE SYMSGV.


STATICS ST_RMVCT TYPE HASHED TABLE OF RMVCT WITH UNIQUE DEFAULT KEY.

* either bseg-xref1 or bseg-xref2 must be used as source...


IF I_XREF_FIELD <> 1 AND I_XREF_FIELD <> 2.
MESSAGE X000(GK) WITH 'UNEXPECTED VALUE I_XREF_FIELD ='
I_XREF_FIELD '(MUST BE = 1 OR = 2)' ''.
ENDIF.
IF ST_RMVCT IS INITIAL.
SELECT TRTYP FROM T856 INTO TABLE ST_RMVCT.
ENDIF.
IF I_XREF_FIELD = 1.
C_RMVCT = IS_BSEG-XREF1.
ELSE.
C_RMVCT = IS_BSEG-XREF2.
ENDIF.
IF C_RMVCT IS INITIAL.
WRITE I_XREF_FIELD TO L_MSGV LEFT-JUSTIFIED.
CONCATENATE TEXT-M00 L_MSGV INTO L_MSGV SEPARATED BY SPACE.
* cons. transaction type is not specified => send an error message...
MESSAGE E123(G3) WITH L_MSGV.
* Bitte geben Sie im Feld &1 eine Konsolidierungsbewegungsart an
ENDIF.
* c_rmvct <> initial...
READ TABLE ST_RMVCT TRANSPORTING NO FIELDS FROM C_RMVCT.
CHECK NOT SY-SUBRC IS INITIAL.
* cons. transaction type does not exist => send error message...
WRITE I_XREF_FIELD TO L_MSGV LEFT-JUSTIFIED.
CONCATENATE TEXT-M00 L_MSGV INTO L_MSGV SEPARATED BY SPACE.
MESSAGE E124(G3) WITH C_RMVCT L_MSGV.
* KonsBewegungsart &1 ist ungültig (bitte Eingabe im Feld &2 korrigieren
ENDFORM. "xref_to_rmvct
* end of insertion "wms092357

HINT: https://www.saptutorial.org/use-substitution-user-exit-change-fi-doc-field-migo/

You might also like