상세 컨텐츠

본문 제목

Sap Program Naming Conventions

카테고리 없음

by sandmatchsmelrai1985 2020. 2. 21. 18:28

본문

Looking through this project one topic I have so far not found any discussion on is namespaces and naming conventions. Not in regards to source code but to the development objects themselves. If I start a project which I want to share as freely available to install on anyone's system (and to contribute to) I also want to make sure the objects do not conflict with any of the ones already on the system. Not sure how ababgit handles conflicts right now.This seems to be especially problematic in SAP development because packages do not restrict the namespaces of the objects they contain but rather every object has to be named in a unique way. Renaming objects and their uses is also extremely painful / impossible (dynamic programming).

Another restricting factor is the limit length object identifiers (think of database tables).The normal / proposed solution by SAP of reserving namespaces (/namspc/) seems to not be an option in this regard. People wanting to contribute to a project cannot do it because the namespace is reserved (and all their changes would be modifications). So only the customer namespaces Z and Y can be used which customer development on the system as well as all abapGit projects (!) share.

In the old days of the SAP/ABAP code exchange there were a namespace /CEX/ reserved, however I think it is not used/possible anymore.Namespaces is the SAP solution to this problem. However, a S user is required to register a namespace, so this is typically not possible for open source projects.abapGit currently does not enforce any naming scheme for objects, but if an object exists in a different package than expected it shows a warning when trying to overwrite the object.I have not seen a name-clash yet in the wild ABAP open source world, but hopefully over time we will see more ABAP open source projects, and it might become a problem.

If we see a lot of ABAP open source projects, I guess SAP will be forced into having an opinion on name clashes(eg. Provide namespaces for open source projects).For my projects I typically just prefix the objects with some fixed characters, to reduce the chance of clashes,Z(CL)?AOC forZ(CL)?AGS forand others also follow this scheme:Z(CL)?EXCEL forWorking with open source projects, then if there is a name clash, I'm sure the community will figure out to rename objects in order to fix the issue.

Abap naming conventions

This document was created to outline severalnaming standards, programming standards, and best practices in ABAP programming andprovide guidelines for ABAP development for MIT. These are not 'The Official ABAP/4Standards', however they do contain MIT-specific programming conventions andtechniques.The topics included are general codingstandards, performance standards, naming conventions, tips & tricks, and sampleprograms. As standards are developed, this guide will be updated on an ongoing basis.The document is intended for use by ABAPdevelopers as a guide for MIT-specific developments and enhancements to R/3. The user ofthis document should be familiar with basic concepts of R/3 and should have taken atraining class equivalent to SAP20 R/3 Overview.To request clarification of these issues orto suggest other topics to be covered, please contact David Rosenberg ( ).If you have questions about topics in this guide, would like to suggest changes,or provide new topics to be included, please submit the topics and details about theupdates to David Rosenberg. RevisionDateDescription of Changes105/15/98Initial(post-review) distributed version205/22/98Document layoutchanges and spelling corrections39/17/98Performance Sectionupdate, New Tips & Tricks, Application abbreviations added (PM, RQ, BP), New documentlayout and navigation features. Note that new or modified sections are highlighted in the table of contents with a.The ABAP/4 language is an 'event driven', 'top-down'programming language.

The execution of an event is controlled by the ABAP/4 processor. Forexample, the event AT SELECTION-SCREEN is executed when the user hits ENTER on theselection screen and the event START-OF-SELECTION is executed when the user presses ENTERto start the program. 1.One command perlineEach ABAP/4 command consists of a sentenceending with a period. Multiple commands can be on one line; however, as a standard starteach new command on a new line. This will allow for easier deleting, commenting, anddebugging.2.Indented sourcecodeThe ABAP/4 editor has a 'PrettyPrinter' command to indent by 2 positions specific lines of code and add subroutinecomments. Event keywords are typically not indented.DATA: BEGIN OF tab OCCURS 100,f1 LIKE sg-field1,f2 LIKE sg-field2,END OF tab.DATA: f1 TYPE I,f2 TYPE I.START-OF-SELECTION.GET table.IF f1 = f2.f1 = 0.ELSE.f1 = 1.ENDIF.SELECT.

FROM tabl WHEREfield1 EQ sg-field2 ANDfield2 BETWEEN sg-field5 AND sg-field6.MOVE.APPEND.ENDSELECT.END-OF-SELECTION.LOOP AT tab.AT NEW f1.CASE F1.WHEN. WRITE:/.ENDCASE.ENDAT.WRITE:/ f1, f2.ENDLOOP.3.Variable namingABAP/4 variable names can be up to 30characters for DATA fields and subroutines and up to 8 characters for SELECT-OPTIONS andPARAMETERS, therefore, as a standard make the names descriptive.

Since SAPsegment/table-field names are hyphenated with a '-' (dash), use an ' (underline) toseparate the words for program-specific variables. Whenever possible, the LIKE parametershould be used to define work fields.DATA: MATDT LIKE SY-DATUM,DAYS TYPE I,HOLDACCTNO LIKE sg-field1,GROSSAMT(10) TYPE P DECIMALS 2,GROSSPERCENT(3) TYPE P DECIMALS 2,NET%(3) TYPE P DECIMALS 2.A good rule-of-thumb is to differentiatebetween DATA fields, SELECT-OPTIONS and PARAMETERS by prefixing selection fields with 'S'or 'P'. SELECT-OPTIONS: SUSER FOR sg-fieldx,SDATE FOR sg-fieldy.PARAMETERS: PDEST(4).Subroutine examples: FORM CALCULATEMATURITYDATE.MATDT = SY-DATUM + DAYS.ENDFORM.or for COBOL-like standards FORM F100CALCULATEMATURITYDATE.4.Reusable codeIf a block of code is executed more thanonce, it should be placed in a subroutine at the bottom of the code. This makes the codemore readable, requires less indentation, and is easier to debug since the debugger canjump through an entire subroutine via a PF key. Also, when possible parameters should bepassed to and from subroutines to make the purpose easier to understand and reduce theneed for global variables. Always document the purpose of each parameter.5.Parameter passingin subroutinesWhenever possible use a TYPE or LIKEstatement when specifying the formal parameters of a subroutine. This is a goodprogramming style, plus it allows the ABAP compiler to generate more efficient code (whichcan increase performance up to a factor of 2x).

For example: form tables ptab1 like using pparam1 like pparam2 like pparam3 like pparam4 type pparam5 type.endform.6.Text handlingLiteral text which is printed on the reportcan be handled two ways.One wayis to hard code the literal in the code and give the option of maintaining Text Elementsfor multi-lingual clients. WRITE:/ 'Grand Total:'(001).Another way is to always use TextElements. WRITE:/ TEXT-001.The advantages to the first way arereadability and the Text Element only needs to be maintained for multi-lingual clients.The advantage to the second way is easier maintainability if TEXT-001 is coded severaltimes in the program and it needs to be changed. The editor command REPLACE does notchange contents inside single quotes.7.Program AnalysisUtilityTo determine the usage of variables andsubroutines within a program, you can use the ABAP utility called ‘ProgramAnalysis’ included in transaction SE38. To do so, execute transaction SE38, enteryour program name, then use the path Utilities - Program Analysis8.Usage of UserIDs inprogramsIn no case should a production program orfunction contain a UserID as either literal or constant data.

Examples

Naming Conventions Examples

In the development system itmay be necessary to code temporary breakpoints for specific UserIDs, however, thesedebugging techniques must be removed before the program will be transported.Authorization Groups permit users access toexecute report-type programs from transaction SA38 (or SE38). Programs that can beexecuted by all MIT users must be configured using the Authorization Group 'ZOPN2ALL' forApplication '.'

. This configuration is done by the developer of the report programin the 'Attributes' screen of SE38.If a program DOES NOT have the 'ZOPN2ALL'authorization group configured for it, we assume that only certain users should be able toexecute it and that other methods of authorization, such as authorization objects arebeing used to prevent improper use.

SFor any custom programming usingauthorization checks, developers must determine whether a standard SAP authorizationobject should be used, or if a custom object should be developed. Since theauthorization object implementation typically comprises more business-related thantechnical issues, developers should consult with the business analysts responsible for theapplication in making this decision.The preferred formats for representing a date in a printed report are eitherMM/DD/YYYY or DD-MM-YYYY. In any case, use of a 4-digit year is a requirement.The R/3 system is already year 2000 compliant. To preserve that compliance,whenever a date is written or read, the year field should contain four digits. The onlyexception to this standard is reading from or writing to external files, where the year2000 restriction in the external system may be different. However, even in this case, ifit is at all possible, it is desirable to allocate four digits for the year in the filelayout.For applications that require dialogprogramming, the SAP Style Guide should be used as a basis for development. Usingthis guide for screen design and ergonomics will insure consistency in MIT developedtransactions.

The SAP Style Guide is available in the help documentation using thefollowing path: Help - R/3 Library - Basis Components - ABAP/4Development Workbench - SAP Style Guide.The MIT user community is, in general, standardized on systems capable of800x600 resolution. Hence, any screen painter development should insure that all fieldsare viewable within that screen size. This corresponds to the SAP default screen size of21 lines by 83 columns. Note that SAP does not include the title, menu bar, status line,and OKCode box in this area.All external file layouts used for interfaces to and from the R/3 system shouldbe discussed with and approved by the Bridges Team before the layout is finalized. This isto insure consistency in field conventions and file processing standards. The requirementsfor the following data elements are. DatesAs indicated in thesection 'Writing dates in reports,' dates should use a 4-digit year with certainexceptions.Cost ObjectsCost objects should beleft-aligned in a 12-character field with trailing blanks.

(Optionally, a 7-characterfield followed by 5 characters of blank filler is acceptable)Cost ElementsCost elements should beleft-aligned in a 10-character field with trailing blanks. (Optionally, a 6-characterfield followed by 4 characters of blank filler is acceptable)The dropbox is the standard method for data providers to automatically deliverfiles created outside of SAP as feeds into MITs SAP R/3 environments.

Data providers mustbe registered with the dropbox. These providers FTP data files to the dropbox.

Based on acombination of file naming conventions and registered dropbox userids, the files areautomatically delivered to the appropriate MIT SAP R/3 environment.Detailed documentation on how to use this mechanism is located atdetermination from eventWhen an inbound interface is initiated by triggering an SAP event, the filenamecan be sent as an event parameter which can then be read by the interface program. Anexample of using this triggering and parameter passing method is shown here. Data: infile like rlgrap-filename. ZPROGDOCABAP/4 Program documentationZSYSTDOCSystem documentationZFUNCDOCFunction Module documentationZINCLDOCInclude documentationZRPRPDOCReport Painter reportdocumentationIt is mandatory to complete a documentation template prior totransporting your program to the production system.In addition to documentation via the templates, brief comments within the codecan be very helpful for ongoing program maintenance. For example, you shoulddocument the major steps in the program source, such as: do 16 times.

'why are we doing this 16 times instead of 12??? Enddo.For the example of CASE statements, each case value should be documented: case. 'explain what 'Y' actually means. 'explain what 'H' actually means. Endcase.When modifying a program, to document within the source code, you can use thefollowing convention.-.

Purpose:.-. Author:.

Date:.-. Modification Log:.

11/2/96 -Joe Q. Programmer SF2K900002. Added.

6/14/96 -Joe Q. Programmer SF2K900001. Changed.-.DATA: BEGIN OF rec, 'SF2K900001ind, 'interface type ind.f1 LIKE MA-IDNRA, 'material numberf2 LIKE MA-KTX01, 'material short textf3(16), 'filler 'SF2K900002.END OF rec.Always note of which lines were changed oradded by appending the transport (change request) number to the line. (This is theconvention used by SAP developers)The import and export parameters of function modules should be documented withbrief descriptions of the fields and their typical contents.

Also, any specialrequirements or usage should be noted. At the minimum, the documentation 'Short Text'should be completed for each parameter. This is found by selecting the 'Documentation'radio button on the main function module transaction, SE37. INSERT D030L-TYPE D030L-DDNAME D030T-DDTEXT D030L-CBNAMED030L-SEGMENTID D030L-DOCTYPE INTO HEADER.SELECT. FROM D030L WHERE 'SF2K900001DDNAME BETWEEN TABLEFR AND TABLETO. 'SF2K900001CHECK D030L-DDMODIFY NE USR. 'SF2K900001SELECT.

FROM D030T WHERE 'SF2K900001DDLANGUAGE EQ SY-LANGU AND 'SF2K900001DDNAME EQ D030L-DDNAME. 'SF2K900001EXTRACT HEADER. 'SF2K900001Because of the nature of the impact ofchanges in validation rules to the entire SAP system operation, any developer who isconsidering altering a validation rule must send a message to as early in thedevelopment process as possible. At a minimum this notification must be sent oneweek before any development is transported to the test and integration system (SF5).As with changes to validation rules, anyconfiguration changes that alter any transaction field, must be submitted in a mailmessage to as early as possiblewith a minimum of one week notification before transport to the test and integrationsystem. Configuration changes that alter the 'required','optional', or 'not permitted' status of fields is included in thisspecification.

Dead'codeAvoid leaving 'dead' code in theprogram. Comment out variables that are not referenced and code that is not executed. Toanalyze the program, use the Program Analysis function in SE38 - Utilities -Program Analysis.2.Use logicaldatabasesChoose the most efficient logical data basepossible. Study the selection criteria and which secondary indexes are used for that view.Provide the appropriate selection criteria to limit the number of data base reads.

Forceusers to provide selection criteria by evaluating the selection criteria entered on theselection screen during the AT SELECTION-SCREEN event. Finally, when possible takeadvantage of the matchcodes to increase speed.3.Subroutine usageFor good modularization, the decision ofwhether or not to execute a subroutine should be made before the subroutine is called.

Forexample:This is better: IF f1 NE 0.PERFORM sub1.ENDIF.FORM sub1.ENDFORM.Than this: PERFORM sub1.FORM sub1.IF f1 NE 0.ENDIF.ENDFORM.4.IF statementsWhen coding IF tests, nest the testingconditions so that the outer conditions are those which are most likely to fail. Forlogical expressions with AND, place the mostly likely false first and for the OR, placethe mostly likely true first.5.CASE vs.

Sap Program Naming Conventions

NestedIFsWhen testing fields 'equal to'something, one can use either the nested IF or the CASE statement. The CASE is better fortwo reasons. It is easier to read and after about five nested IFs the performance of theCASE is more efficient.6.MOVE-ing structuresWhen records a and b have the exact samestructure, it is more efficient to MOVE a TO b than to MOVE-CORRESPONDING a TO b. MOVE BSEG TO.BSEG.is better than MOVE-CORRESPONDING BSEG TO.BSEG.7.SELECT and SELECTSINGLEWhen using the SELECT statement, study thekey and always provide as much of the left-most part of the key as possible. If the entirekey can be qualified, code a SELECT SINGLE not just a SELECT.

If you are onlyinterested in the first row or there is only one row to be returned, using SELECT SINGLEcan increase performance by up to 3x.8.Small internaltables vs. Complete internal tablesIn general it is better to minimize thenumber of fields declared in an internal table. While it may be convenient todeclare an internal table using the LIKE command, in most cases, programs will not use allfields in the SAP standard table. For example:Instead of this: data: tvbak like vbak occurs 0 with header line.Use this: data: begin of tvbak occurs 0,vbeln like vbak-vbeln.end of tvbak.9.Row-levelprocessing of a tableSelecting data into an internal table usingan array fetch versus a SELECT-ENDELECT loop will give at least a 2x performanceimprovement.

After the data has been put into the internal data, then row-levelprocessing can be done. For example, use: select.

From table into (corresponding fields of itab) where. Loop at endloop.instead of using: select. From table where. Endselect.10.Row-levelprocessing and SELECT SINGLESimilar to the processing of aSELECT-ENDSELECT loop, when calling multiple SELECT-SINGLE commands on a non-bufferedtable (check Data Dictionary - Technical Info), you should do the following to improvepreformance: Use the SELECT into to buffer the necessary rows in aninternal table, next sort the rows by the key fields, then use a READ TABLE WITH KEY.BINARY SEARCH in place of the SELECT SINGLE command. Note that this only make sensewhen the table you are buffering is not too large (this must be made on a case by casedecision basis).11.READing singlerecords of internal tablesWhen reading a single record in an internaltable, the READ TABLE WITH KEY is not a direct READ. Therefore, SORT the table and useREAD TABLE WITH KEY BINARY SEARCH.12.SORTing internal tablesWhen SORTing internal tables, specify thefields to SORTed. SORT ITAB BY FLD1 FLD2.is more efficient than SORT ITAB.13.Number of entries in aninternal tableTo find out how many entries are in aninternal table use DESCRIBE.

DESCRIBE TABLE ITAB LINES CNTLNS.is more efficient than LOOP AT ITAB.CNTLNS = CNTLNS + 1.ENDLOOP.14.Length of a fieldTo find out the length of a field use thestring length function. FLDLEN = STRLEN (FLD).is more efficient than IF FLD CP ‘. #’.ENDIF.FLDLEN = SY-FDPOS.15.PerformancediagnosisTo diagnose performance problems, it isrecommended to use the SAP transaction SE30, ABAP/4 Runtime Analysis. The utility allowsstatistical analysis of transactions and programs.16.Nested SELECTsversus table viewsSince OPEN SQL does not allow table joins,often a nested SELECT loop will be used to accomplish the same concept. However, theperformance of nested SELECT loops is very poor in comparison to a join.

Sap Naming Conventions Pdf

ExamplesZFCCMTOPCredit card TOP IncludeZFCCMF01Credit card FORM IncludeSince classification objects and class typesare more like programming data constructs than they are like configuration data, MITnaming conventions should be followed when creating new classification objects or classtypes. To differentiate between SAP supplied classes and MIT developed classes theprefix 'MIT' should be used followed by either the SAP data element or a descriptiveabbreviation. For example, when creating a characteristic for a 'Profit Center'where the data element is 'PRCTR' the name would be 'MITPRCTR'. In addition, SAPrecommends to use only letters from A-Z, numbers 0-9, and the underscore character in thename.Development classes should only be created when a specific new project requires allcomponents to be linked for organizational purposes. Before creating a new developmentclass, please consult with the R3 Admin team ( ).Most SAP system interfaces using flat ASCII files for input or output should use thefollowing directory paths for temporary and permanent interface files. To R/3 from an EXTERNAL SYSTEM:/usr/bridges/environment name/sapin/To an EXTERNAL SYSTEM from R/3:/usr/bridges/environment name/sapout/Files written by one ABAP program and read by another:/usr/bridges/environment name/saptmp/Files already used by R/3:/usr/bridges/environment name/archive/The variable environment name should be determined at run-time by the program.

Togenerate this name, use the function ZDETERMINEFUNCAREA. This function will identifythe environment name section of the path based on the system id and the client of thecalling R/3 system.Sample code follows. Data: begin of myfile,part1(13) value '/usr/bridges/',part2(15), 'dev2 or tst1 or prodpart3(9) value '/saptmp/',part4(30) value 'flname',end of myfile.initialization.call function 'ZDETERMINEFUNCAREA'importingfunc = myfile-part2exceptionsunknownsysid = 1unknownmandt = 2.if sy-subrc eq 0.condense myfile no-gaps.endif.Since there is a limited amount of logical naming space available for function groups,generally new groups should only be created when it is not possible to add functions toexisting groups.Function Groups are named using the following convention. PositionUsage1'M' as required bythe system to denote online modules2'Z' to denotecustomer named object3-4Application NameAbbreviation (see Appendix B)5Sequential Number(0-9) corresponding to main program6'I' for PAImodules, 'O' for PBO modules, 'F' for subroutines7-8Sequential Number(00-99)6-8'TOP' if theinclude is the global data includeTypically function modules must specify the exact structure of each parameter they arepassed, hence runtime structures cannot be handled easily in normal function modulecreation. However, by using the ABAP programming construct ASSIGN COMPONENT idx OFSTRUCTURE record to, a function can determine the structure of a record. For anexample of how to develop a function to do this refer to function ZLISTSELECTOPTIONSwhich reads the structure of a RANGES table in a SELECT-OPTION parameter.Support for one and two-dimensional arrayswithin ABAP is provided through the use of internal tables.

However, in the case ofa 3-dimensional array, ABAP has no naitive programming constucts. While a methodcould be devised to index a 3-dimensional array via internal tables, the following codefragment demonstrates an alternative approach using field symbols as pointers into datastructures. This code fragment illustrates the use of a field symbol and an. ASSIGN statement to get the effect of having multi-dimensional. subscripted arrays.

There are several costs of this method. One is. performance and the other is that EVERY cell in the multi-dimensional. array must be declared in a DATA (or CONSTANT, etc.) statement at the.

beginning of the program. Using this method, you would have to have DATA statements like the. following four for EACH CELL of the multi-dimensional array.DATA: VARA001005006(11) VALUE 'Some value!' .DATA: VARA002005006(11) VALUE 'Other value'.DATA: VARA003005006(11) VALUE 'Next value!' .DATA: VARA004005006(11) VALUE 'The target!' .DATA: BEGIN OF POINTER,STEM(5) TYPE C VALUE 'vara',PART1(3) TYPE N,SEP1(1) TYPE C VALUE ',PART2(3) TYPE N,SEP2(1) TYPE C VALUE ',PART3(3) TYPE N,END OF POINTER.DATA POINTERDEFAULT(11) VALUE 'The default'.FIELD-SYMBOLS:. This is the example of using the multi-dimensional array in the body.

of a program. Data: begin of hex,byte type x,end of hex.data: char type c.data: temp like sy-index.do 224 times.temp = sy-index + 31.hex-byte = temp.char = hex.write: / 'Decimal =', temp.write: 'Hex =', hex-byte.write: 'View =', char.enddo.When writing BDCs that read dates to be entered into SAP transactions problems occurwhen determining what date format to use when entering the data into its correspondingfield. REPORT ZSKELREP.-. Purpose:.-. Author:. Date:.-. Modification Log:.-TABLES.DATA.SELECT-OPTIONS.PARAMETERS.FIELD-GROUPS: HEADER.FIELD-SYMBOLS.

Event which occurs before the selection screen is shown to. the user.INITIALIZATION. Event which occurs each time the user hits enter on the. selection screen. This event is ignored in background processing.AT SELECTION-SCREEN.TOP-OF-PAGE.END-OF-PAGE.START-OF-SELECTION.

Definition of fields for FIELD-GROUP extractINSERT. INTO HEADER.GET.END-OF-SELECTION.SORT.LOOP.AT FIRST.ENDAT.AT NEW.ENDAT.AT END OF.ENDAT.AT LAST.ENDAT.ENDLOOP. Subroutines.-.-FORM.ENDFORM.

REPORT ZSKELINT.-. Purpose:.-. Author:. Date:.-. Modification Log:.-TABLES.DATA.SELECT-OPTIONS.PARAMETERS.FIELD-SYMBOLS.FIELD-GROUPS. Event which occurs before the selection screen is shown to.

the user.INITIALIZATION. Event which occurs each time the user presses F2 or double-clicks. on the line in the selection screen. This event is ignored in. background processing.AT SELECTION-SCREEN.TOP-OF-PAGE.

Top of page for sublistsTOP-OF-PAGE DURING LINE-SELECTION.END-OF-PAGE.START-OF-SELECTION.GET.END-OF-SELECTION. Produce main list report SY-LSIND = 0.SORT.LOOP.WRITE:/. Hide specific fields which are if importance to the lineHIDE.ENDLOOP. Event which occurs when user hits a particular PF key, i.e. PF6.

The hide area and SY-LISEL are automatically available. Produces a sublist SY-LSIND = 1-9.

PF3 is automatic, will always. take the user back one list level, (SY-LSIND - 1).AT PF. Event which occurs when a user types =LIST in the OK code. The hide area and SY-LISEL are automatically available. Produces a sublist SY-LSIND = 1-9. PF3 is automatic, will always.

take the user back one list level, (SY-LSIND - 1).AT USER-COMMAND.CASE SY-UCOMM.WHEN 'LIST'.ENDCASE. Event which occurs when the user places the cursor to a specific. line on the report and hits enter. The hide area and SY-LISEL are automatically available. Produces a sublist SY-LSIND = 1-9. PF3 is automatic, will always.

take the user back one list level, (SY-LSIND - 1).AT LINE-SELECTION. Subroutines.-.-FORM.ENDFORM. REPORT ZSKELOUT.-. Purpose:.-. Author:. Date:.-. Modification Log:.-TABLES.DATA.SELECT-OPTIONS.PARAMETERS.FIELD-SYMBOLS.START-OF-SELECTION.GET.MOVE.

TO.END-OF-SELECTION. Subroutines.-.-FORM.ENDFORM.