阿里狼 发表于 2015-9-20 04:59:31

SAP的校验和替代(validations and substitutions)



SAP的校验和替代(validations and substitutions)
(2011-04-20 23:06:16)
http://blog.sina.com.cn/s/blog_785d5b820100qpjx.html










I. Creating, activating and transporting validations and substitutions
1. Which transactions arerequired to use validation or substitution functions?
GGB0 Validation Maintenance GGB1 SubstitutionMaintenance GCVZ Rule Maintenance GGB4 Action selection forvalidation/substitution, for example, activation of application areas, use ofall messages or substituted fields GCX2 Definition of the Includes for userexits
OB28 Activation of FI validations OBBHActivation of FI substitutions OBBZ Activation of cost of sales accountingsubstitution (in the FI area) OKC7 Activation of CO validations OKC9Activation of CO substitutions
GCT9 Transport: Validations GCT0Transport: Substitutions

2. What must I take into account when using the formulaeditor?
a) Validation GGB0
If you create the first validation for a callup point, for example'financial accounting - document header', you have to define a message class.This is then valid for ALL validations for this callup point.
Not allfields can be used for validations on certain callup points, for example'Complete document in FI'. This is because there are several rows there and itis not clear on which row the check is to be carried out. You can only usenumeric fields here. (Note 413956) You should use a user exit if you needmore checks on this callup point.
b) Substitution GGB1
If you create a substitution, for example 'financial accountingdocument line item', only certain fields are authorized for the substitution.This is because problems can occur with the documents or inconsistencies canoccur between different applications. You can release more fields forsubstitution but this can be critical as serious problems can occur as aresult. This is why you should regard the following change as a modification(Note 170183): The GB01 table contains information about which table fieldscan or cannot be substituted for which callup point. You can make a fieldsubstitutable by changing the BEXCLUDE field to ' '.
For example:'Complete document' callup point in the FI In accordance with the default, nofield is released for substitution on this callup point. You can see this in thefollowing entries:
BOOLCLASS CLASSTYPE BCLTAB BCLFIELD BEXCLUDE 015 SBKPF * X 015 S BSEG * X
BOOLCLASS - Specifies the Boolean class.This is determined in the application area and callup point in each case, forexample: 008 - Document header (FI) 009 - Line item (FI) 015 - Completedocument (FI) 016 - Cost of sales accounting 100 - Document header(CO) CLASSTYPE Specifies if the field can be used in the case of validations(B), substitutions (S) or both BCLTAB - Table that is used BLCFIELD -Field of this table BEXCLUDE - Can be used ' ' or cannot be used'X'.
As mentioned above, you should equate this change with amodification. Problems that occur as a result of this change cannot be handledin the 'standard' support.

3. What must I take into account when activating validations orsubstitutions?
You can activate validations and substitutions in twoways. Activation level: 1 - Active 2 - Active, except during 'batch input'processing
Because the activation in the financial accounting (FI) iscompany-code-specific, the validations or substitutions should be activated inboth company codes in the case of cross-company code transactions.

4. What must I take into account when transporting validationsor substitutions?
Usually, only table entries are transported when validations orsubstitutions are transported. The generated source code should not betransported, since this can cause problems. After the import into the targetsystem, the source code is generated automatically when the RGUGBR00 report isstarted.
If you would like to delete a validation/substitution, and donot want to do this in each system individually, proceed as described in Note840981.


II. Using user exits in validations orsubstitutions
1. Where can I maintain user exits forvalidations and substitutions?
The exits for validations and substitutions are stored in anInclude of your choice. The following Includes are delivered as examples bydefault: RGGBR000 Val/Sub: Exits for rules RGGBS000 Val/Sub: Exits forsubstitutions You should copy these into the customer namespace, for exampleZGGBR000. The length of the name you choose should not exceed 8 characters.This is because the name is also generated in the source code, and so a certainline length may be exceeded as a result. You can also create a separateInclude per client as this can improve performance.
In Transaction GCX2,you should then define where your Include is used. To do this, enter the name ofyour Include as a form pool in the relevant application area.

2. How should I create a user exit?
Define your user exit in the FORM Routine GET_EXIT_TITLES with thecorrect exit category (EXITS-PARAM). You can use the existing sample entries asa model for this.
The exit types required in the FORM RoutineGET_EXIT_TITLES are organized as follows:
· C_EXIT_PARAM_NONE No parameter
Apart from the return value (B_TRUE or B_FALSE), you do not needany parameters for the validation. If you do not want to substitute a field, usethis parameter in the substitution (select "Only exit").
However, youmust then use a TABLE statement in the formpool (not in the actual form) toidentify the structure concerned.
· C_EXIT_PARAM_FIELD A Field is transferred as a parameter
You only use this type in the substitution. Exactly one field issubstituted. Enter user exits of this type in the substitution maintenanceinstead of assigning a constant value.
· C_EXIT_PARAM_CLASS A complete type is transferred as aparameter
Matrix validations/substitutions ("Only exit"). This exit type canonly be used in the case of callup points with complete documents, for examplein the FI and the LC. You cannot use this exit category on any other calluppoints. The transferred type contains all information of a class. An example isthe use of the document header and all corresponding line items in the FIarea.
In the FORM routine GET_EXIT_TITLES, change the NAME and TEXT fieldof the EXITS internal table to the values you want.
Use one of the sampleroutines as a model and copy these to the names you selected. You can nowimplement the functions you want in this form routine. After you havefinished creating the user exit, you can use it in your validations orsubstitutions.
3. What must I take into account when implementing the userexit?
  No dialog boxes, warning messages, information messages and error messagescan be issued in an exit nor can a "COMMIT WORK" be rejected. This would, forexample, interrupt the batch processing or cause problems with the documents tobe posted. If you find a serious error in the field contents in the exit, send atermination message (A or X), which will ensure that the transaction isterminated.
Do not use any ABAP commands that cause the exit to be leftdirectly, for example 'LEAVE (TO) SCREEN ...' or 'SUBMIT ...' or 'CALLTRANSACTION ...'
In an exit, use only structure fields that belong to theBoolean class of the calling substitution, validation or rule. The otherstructure fields are not filled or are not filled properly on the callup pointof the calls of the substitution, validation or rule.
Changes to fieldcontents may only be made in a substitution exit if this field can besubstituted in the Boolean class. You can display such fields by selecting the"Add entry" function in the substitution maintenance.
In the Includes ofthe substitution exits, you must not use the commands MODIFY, INSERT orDELETE in the internally used structures such as BSEG or BKPF. These structuresare interpreted internally as database tables because they are defined by aTABLES statement. As a result, database records are written, deleted or changedwhen you use the commands mentioned above. This can cause seriousinconsistencies and problems in the document processing.
If you wantto change field contents in Exit Types C_EXIT_PARAM_CLASS, you should make thechanges in the internal table BOOL_DATA (for example BOLL_DATA-BSEG).
  
  
III. Problem analysis
1. Whatmust I take into account before I analyze the problem?
Before you analyze a problem with validations/substitutions, makesure that the generated source code is up-to-date. You can use Report 'RGUGBR00'to do this. Call this report in Transaction SE38. You receive the followingselection screen:
Application area ' ' Application callup point ''
' ' Regenerate main program ' ' Generate table file ' ' Generaterules ' ' Generate validations ' ' Generate substitutions ' ' Generatesets ' ' Generate rule use ' ' Generate validation use ' ' Generatesubstitution usage ' ' Generate substitution export routines ' ' Generatesubstitution routines in all clients ' ' Generate trace programcalls
Now update the source code for the application area and applicationcallup point in which the validation or substitution was created. To do this,enter the application area, for example FI, and the application callup point(0003/complete document), and set all indicators except for 'Generatesubstitution routine in all clients' and 'Generate trace program calls'. Thenexecute the report.
The source code is now at its current status.

2. How can the validation and substitution trace beused?
a) Validation trace
You created and activated a validation. You can now activatethe trace, for example in Transaction GGBO. To do this, place the cursor on thevalidation and select 'Extras -> Activate trace'. Example: You createdan FI validation on the 'Line item' callup point. To test the validation,execute, for example, Transaction FB01. The trace is displayed as soon as thevalidation is run. You can now see different things in the trace, for examplethe values contained in the fields of the various structures. From this, you candeduce whether additional checks are required, or tell what the cause of aproblem is.
b) Substitution trace
Activate the trace in the same way as you activatevalidations. Example: You created a substitution in the same way as youactivated the trace in the case of the validation. The trace for substitutionshas an additional function, in that you can view the field contents before thesubstitution as well as after the substitution. There, problems can bereproduced in the same way.

3. How can I use the DEBUGGER to analyze a problem?
a) Basic information
All Includes for validations and substitutions are created in thisform: GBTmmaa0. mm stands for two digit client key. You can use theG_CLIENT_ENCODE function module to convert a three-digit client (>099) to atwo-digit client, for example: client 100 --> AA client 800 -->TQ AA stands for the application area, for example FI --> FinancialAccounting CO --> Cost Accounting You will find this abbreviation inthe maintenance transaction. Therefore, GBTAAFI0 is the Include in client 100for FI validations and substitutions.
b) Structure of the Includes and form routines for validations andsubstitutions and tips on how to 'debug'
The above-mentioned Includes are structured in the followingway (sample Include in FI, Client 800):
INCLUDE GBTTQFIA. "Rules INCLUDE GBTTQFIB. " Substitutions INCLUDE GBTTQFIC. " Substitutionconditions INCLUDE GBTTQFID. " Validations INCLUDE GBTTQFIE. " Validationconditions INCLUDE GBTTQFIF. " Validation checks INCLUDE GBTTQFII. "Application rules INCLUDE GBTTQFIJ. " Substitution export routines INCLUDEGBTTQFIM. " Trace/simulation INCLUDE GBTTQFIS. " Substitution importroutines
c) The form routines for validations have the following samplestructure (sample validation with the name VAL01):
FORM VAL_VAL01. G_BFOUND = B_TRUE. DATA: COND LIKED_BOOL, CHECK LIKE D_BOOL, NVALSEVEREST LIKE SY-SUBRC VALUE-1.
G_STEP = '001'. PERFORMVALCOND_1VAL01##001 CHANGING COND.
IF COND = B_TRUE . PERFORMVALCHCK_2VAL01##001 CHANGING CHECK.
IF CHECK = B_FALSE . PERFORMMESSAGE_OUTPUT USING "...Nachrichtenparameter CHANGING NVALSEVEREST. ENDIF. ENDIF. ENDFORM." VAL_VAL01
Statement G_STEP = '001' indicates the step that isexecuted. The prerequisite of the step is defined in Form RoutineVALCOND_..., the form routine VALCHCK_... checks the validation step.
Toanalyze this step, you should create breakpoints on these two PERFORM statementsand also on the code line 'IF CHECK = FALSE'. In doing so, you can determinewhether your prerequisite or the check is causing the problem you have, forexample a field that is to be checked does not contain the value that youexpect.
d) The form routines for substitutions have the following samplestructure (sample substitution with the name SUB01):
FORM SUB_SUB01. G_BFOUND = B_TRUE. DATA: COND LIKED_BOOL. G_CLASSID = '009'. G_SUBST_PERFORMED = B_FALSE.
IFG_TAB_FLAG-BSEG <> B_TRUE . PERFORMREAD_MASTER_DATA USING 'BSEG' G_BFOUND. IF G_BFOUND = B_FALSE. MESSAGE E083 WITH 'BSEG'. ENDIF. ENDIF.
G_STEP ='001'. PERFORM SUBCON_3SUB01##001 CHANGING COND.
IF COND =B_TRUE . BSEG-SGTXT = 'This is a Test'. " Text G_SUBST_PERFORMED =B_TRUE. ENDIF. ENDFORM. " SUB_SUB01
As mentioned above forvalidations, 'G_STEP = '001' indicates the step, and the prerequisite of thesubstitution is defined in Form Routine SUBCON_.... The actual substitution iscarried out by the statements in the 'IF COND = B_TRUE --> ENDIF' structure.These statements vary depending on the 'type' of substitution created (fieldallocation, constant value, user exit).
In the substitutions, you shouldalso set a breakpoint on the PERFORM on the prerequisite and the statement 'IFCOND = B_TRUE'.

4. Function modules that call validations andsubstitutions
Validations - Function module G_VSR_VALIDATION_CALL Thedifferent structures/tables, the name of the validation, callup point andapplication area are assigned to this function module. Substitutions -Function module G_VSR_SUBSTITUTION_CALL The parameters transferred tovalidations are also transferred to this function module. However,structures/tables that contain the changed values are also returned.
Youcould set a breakpoint to analyze both function modules. In doing so, you couldsee which data was transferred, which data the validation or substitutionattains, and which values are returned.

5. What must I take into account during the set usage?
When sets are used in validations or substitutions, source code isgenerated from the values in the sets. Performance problems can occur if aset is of a certain size, since the generated source code causes longerruntimes. A runtime error can also occur.
To reduce the size of thesource code of the sets used, you can proceed as follows:
Use a smallerset in the validation, substitution or rule. To do so, group single values inthe set into intervals (for example, instead of the single values 0001, 0002 and0003, use the interval 0001 - 0003)
Instead of " IN SET", use the rule "(IN SET1 OR IN SET2)" in which SET1 and SET2 contain the values from SET (forexample, subhierarchies on the highest hierarchy level).
The simplest wayto determine the number of single values or intervals in a set hierarchy is toexecute Program RGSEX000. Enter the name of the set and execute the program.All contained sets and values/intervals are listed and the sequential number ofthe entries is contained in the first column.

6. Why does a validation or substitution work in thedevelopment system, but not work in another system after a transport?
  You should make sure that validations and substitutions are activated in thetarget system. You can also use Report RGUGBR00 to execute the regeneration ofthe source code again.
There could be another cause in the case ofsubstitutions: You try to substitute a field that is not released as adefault by SAP. To substitute a field, you have adjusted Table GB01 in yourdevelopment system. However, this did not occur in the target system. Thegenerated source code is correct and the value was changed in the substitution,but the change was not returned to the calling application via the exportroutines.

页: [1]
查看完整版本: SAP的校验和替代(validations and substitutions)