23-useful Abap Tips

  • Uploaded by: api-3823432
  • 0
  • 0
  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View 23-useful Abap Tips as PDF for free.

More details

  • Words: 5,624
  • Pages: 62
ABAP TIPS

ABAP TIPS USEFUL ABAP/4 INFORMATION TIP Area

1 Use of ON CHANGE in Loop Processing

ON CHANGE OF does seem to work in loop processing.However, it only works the first time the code is used, and on the second pass you may get unexpected results. Look at the code sample below.

ABAP TIPS DATA: ITAB LIKE MARA OCCURS 10 WITH HEADER LINE. ITAB-MATNR = '5'. APPEND ITAB. ITAB-MATNR = '6'. APPEND ITAB. PERFORM PRINT_ITAB. REFRESH ITAB. ITAB-MATNR = '6'. APPEND ITAB. ITAB-MATNR = '7'. APPEND ITAB. PERFORM PRINT_ITAB. FORM PRINT_ITAB. ON CHANGE OF MATNR. WRITE: ITAB-MATNR. ENDON. ENDFORM

ABAP TIPS Those of you who guessed that the output would be "5 6 6 7" are wrong! The actual output is simply "5 6 7." What happens during the ON CHANGE OF is that SAP holds the contents of the last ON CHANGE OF variable in memory, and this does not get refreshed or cleared during loop processing. For this reason you should avoid using ON CHANGE OF when processing loops. Another area to look out for in control statements for loop processing is the use of AT. Do not use this statement when using the loop additions FROM, TO, and WHERE. New programmers out there should remember that AT NEW compares the structure for anything that has changed starting at the left hand side of the structure all the way to the field that you are specifying.

ABAP TIPS TIP Area

2 Enhance performance of the SELECT statement

One of the most harmful things that I see nearly every day is SELECT * FROM _ when you are using only one or two fields from the table being read. This is usually the result of lazy coding practices. It can significantly slow the program and put an unnecessary load on the whole system. To understand why this is such a performance problem you have to understand a little about SAP hardware architecture and what happens when your ABAP processes the SELECT statement.

ABAP TIPS When you execute an ABAP program, it runs on an application server, which is usually a different physical box from the database server. When you write a SELECT * statement, the application server sends the request to the database server, which in turn must pass the entire structure for each row back to the application server. This consumes both CPU and networking resources, especially for tables with large structures. SELECT ing only the specific fields you need from the database means that the database server will only pass a small amount of data back. This will greatly increase the speed of the SELECT. The following example outlines this change: SELECT MATNR MTART FROM MARA INTO (L_MATNR, L_MTART). ... processing code ... ENDSELECT.

ABAP TIPS Another item to avoid with the SELECT statement is code like the following: SELECT MATNR MTART FROM MARA INTO L_MATNR, L_MTART. CHECK L_MTART <> 'KMAT'. ... processing code ... ENDSELECT. As in the previous SELECT * example, this will put an unnecessary load on the overall system because potentially many records that will not be processed are still going from the database 8server to the application server.

ABAP TIPS TIP Area

3 Generic routine to initialize all fields of a structure

It seems that whenever you have to write a tricky piece of code, you need a field symbol. The following code example will initialize all the fields of any structure to any character you want. The two assumptions here are that the structure comprises fields of the same type and that you can move IS_FILL into them. This routine is useful when building an ABAP program that will write a file for one of SAP's standard load programs. Typically, the header record these programs use has a NO-DATA field that you populate with a character you will use when you do not want SAP to touch a field. You then fill all fields in the data record with this character, except the ones you want SAP to process. Look at the material direct load header record BMM00 and data record BMMH1 for an example.

ABAP TIPS FORM INIT_STRUCTURE USING IS_STRUC IS_FILL. FIELD-SYMBOLS: , . ASSIGN (IS_STRUC) TO . DO. ASSIGN COMPONENT SY-INDEX OF STRUCTURE TO . IF SY-SUBRC NE 0. EXIT. ENDIF. = IS_FILL. ENDDO. ENDFORM. This routine is then simply called like this: TABLES: BMM00, BMMH1. PERFORM INIT_STRUCTURE USING: 'BMM00' '\', 'BMMH1' '\'. After the call to INIT_STRUCTURE is performed, all fields in BMM00 and BMMH1 are set to a \.

ABAP TIPS TIP Area

4 Generic Tips

 When you're working in the ABAP editor and you want to print out just a few lines of code, use the line command PR. This works same as the line command CC in that you put the PR at both the top line and bottom line of the section of code that you want to print and then press return. You can also use the WW command to copy sections of code to the window's clipboard.

 Do you want to make your printed ABAP look a little better? Use the

ABAP TIPS  Have you ever had a user ask you why a certain warning or error message is coming up in a transaction? If you're not familiar with the transaction, you'll probably slowly debug your way in until you get to the message in question. This can be time-consuming. A faster approach is to go into debug mode when you start the transaction and then set up a break point on the keyword MESSAGE. Go to the pull down menu once you're in the debugging screen and select BREAKPOINT-> BREAK-POINT-> KEYWORD in 3.x or BREAKPOINT->

ABAP TIPS  When you're working on a piece of code that several others are using (a customer exit, for example), use the macro BREAK followed by your user name instead of using the BREAK-POINT ABAP keyword. In the following example, the code will stop only when the user-id is DRABAP. This allows other users to use the transaction without ending up in the debug screen and having to press Continue. X = Y1. BREAK DRABAP. Z = SUM / X.

ABAP TIPS TIP Area

5 Database Optimizer Hints

It's true that in many cases the programmer knows exactly which index works best, which is one reason why different database system vendors provide so-called "optimizer hints."At first glance, it seems that optimizer hints could make the database optimizer obsolete. But a closer look shows that in order to select an optimal search method and index, the programmer needs a good idea of the value distribution of the related tables. Because R/3 is a highly configurable metaapplication used in many industries and countries by many customers, you can find very differently scaled customer-order and order-product relationships. Take the following query that returns all Lufthansa flights starting at Frankfurt:

ABAP TIPS DATA: xcarrid LIKE spfli-carrid, xconnid LIKE spfli-connid, xcityfrom LIKE spfli-cityfrom. SELECT carrid connid cityfrom FROM spfli INTO (xcarrid, xconnid, xcityfrom) WHERE carrid = 'LH ' AND cityfrom ='FRANKFURT'. WRITE: / xcarrid, xconnid, xcityfrom. ENDSELECT. Copy this ABAP code into a test program, and we'll take a look at SQL Trace - an important tool for programmers and system administrators. You'll need to follow these steps:

ABAP TIPS Start transaction ST05. On the initial screen, select the trace functions you want to switch on (SQL Trace). To switch on the trace under your user name, choose Trace on. Run the test program you just created. Select the trace functions you want to switch off. Choose Trace off. Now the system has recorded all the SQL calls being executed during this time. Choose Trace list to get a list of the calls. If you've never tried out this function, you'll probably experience some confusion:

ABAP TIPS The trace list obviously contains many lines that are not related to the SELECT statement in the ABAP program. Explanation: The execution of any ABAP program requires additional administrative SQL calls. To restrict the list output, you can use the filter introducing the trace list. The trace list contains different SQL statements simultaneously related to the one SELECT statement in the ABAP program. Explanation: The R/3 Database Interface - a sophisticated component of the R/3 Application Server - maps every Open SQL statement to one or a series of physical database calls and brings it to execution. This mapping, crucial to R/3s performance, depends on the particular call and database system. The WHERE clause in the trace list's SQL statement is different from the WHERE clause in the ABAP statement.

ABAP TIPS Explanation: In an R/3 system, a client is a self-contained unit with separate master records and its own set of table data (in commercial, organizational, and technical terms). With ABAP, every Open SQL statement automatically executes within the correct client environment. For this reason, a condition with the actual client code (here MANDT = '000') is added to every WHERE clause if a client field is a component of the searched table. Since release 4.5, you can provide optimizer hints for SELECT statements using the %_HINTS parameter that enables emergency repairs on the spot. Of course, this parameter only works for those database systems that support optimizer hints. Because optimizer hints are not covered by SQL standards, each database vendor is free to provide them. Note that parameters starting with "%_" are never published in the documentation and should be used with special care only in an emergency. This introduction is very simplified; for a detailed description, please refer to Note 129385 in OSS.

ABAP TIPS Using the %_HINTS parameter, the example becomes: SELECT carrid connid cityfrom FROM spfli INTO (xcarrid, xconnid, xcityfrom) WHERE carrid = 'LH ' AND cityfrom = 'FRANKFURT' %_HINTS ORACLE 'INDEX("SPFLI" "SPFLI~001")'. WRITE: / xcarrid, xconnid, xcityfrom. ENDSELECT. The optimizer's execution plan for the query has changed. Instead of performing a full table scan, the optimizer will perform an index range scan, which is almost always a more efficient operation, unless the table has a small number of rows. If you specify hints incorrectly, ABAP ignores them but doesn't return a syntax or runtime error. This lack of notification is the reason why you have to make sure that you specified the index's correct denotation.

ABAP TIPS TIP Area

6 Assign content to a field structure

The problem: You want to assign a special content to every field of a structure. What is the easiest routine to do that? REPORT ZFTER910. DATA I_BLFA1 LIKE BLFA1. FIELD-SYMBOLS: . DO. ASSIGN COMPONENT SY-INDEX OF STRUCTURE I_BLFA1 TO . IF SY-SUBRC <> 0. EXIT. ENDIF. = '/'. ENDDO.

ABAP TIPS TIP Area

7 Simple F4 selection from an internal tables

The problem: You want to select a value from an internal table within a popup like the F4-selection? DATA: FIELDTAB LIKE HELP_VALUE OCCURS 2 WITH HEADER LINE, VALUETAB(40) OCCURS 200 WITH HEADER LINE. FIELDTAB-TABNAME = 'AUSP'. FIELDTAB-FIELDNAME = 'ATWRT'. FIELDTAB-SELECTFLAG = 'X'. APPEND FIELDTAB. LOOP AT IT_TREE WHERE PPRICE NE SPACE. VALUETAB = IT_TREE-PPRICE. APPEND VALUETAB. ENDLOOP.

ABAP TIPS CALL FUNCTION 'HELP_VALUES_GET_WITH_TABLE' EXPORTING TITEL = 'Allowed Values' IMPORTING SELECT_VALUE = PVAR TABLES FIELDS = FIELDTAB VALUETAB = VALUETAB EXCEPTIONS FIELD_NOT_IN_DDIC = 1 MORE_THEN_ONE_SELECTFIELD = 2 NO_SELECTFIELD = 3 OTHERS = 4.

ABAP TIPS TIP Area

8 Tools and techniques to analyze performance problems

ABAP Runtime Analysis (SE30) ABAP Program Extended Syntax Check (SLIN) Process Overview (SM50) Performance workload Analysis (ST02, ST03) Performance workload Statistics Records (STAT) Miscellaneous database statistics (ST04, DB01, DB02) Trace Requests (ST05) ABAP Program Debugger (SE38). Fundamental Tools for Application Tuning When trying to improve the performance of your R/3 system, the toughest job is deciding what to tune. In order to make this decision, everyone must first agree on the objectives, costs, and benefits of the tuning the project.

ABAP TIPS PROBLEM DETERMINATION To find out what to tune, start by asking these questions: How many programs are slow ? Which programs are slow ? Are specific transactions or specific parts of a transaction slow ? What are average response times? Are response times high for all dialogs? Let’s start with problems that seem to affect everyone. TUNING THE SYSTEM I will list the basics I always cover and let you develop a path that works best for you. Rule number one is, don’t attempt to tune production systems based on statistics from development systems or from any time periods when data conversion, transport, or other one-time only processes were executing.

ABAP TIPS Here are some base-level tuning tips grouped by the five most common tuning transactions. 1. Base configuration: servers, work processes, and load balancing. The Process Overview (SM50, SM51, and SM66) is often the best way to gain a high-level view of your R/3 system. With SM50 you can watch programs execute in real time and see cumulative processing times for work processes Time statistics on work process activity will provide information on the types of jobs that are being processed and on the servers handling the heaviest loads, allowing you to quickly identify servers with too few or too many processes. When you see several servers with uneven distribution, review your logon load balancing schemes If you see work processes in PRIV mode, you need to analyze your memory management strategies and server profile parameters. Private mode is usually an indicator of serious or complex problems that should be entrusted to the SAP EarlyWatch team.

ABAP TIPS Work processes that stop or hang up will display a reason code and probably semaphores or other valuable system codes. For semaphore analysis, the SAP Online Support Services (OSS) Note 33873 provides a listing of codes and definitions. Semaphores are generally wait or conflict codes issued by the operating system. 2. Hardware and operating system. Although we hope nothing other than R/3 is running on the operating system, in reality processes are often contending for OS-level memory. These will have a dramatic effect on the R/3 System because SAP memory management is completely dependent on the resources allocated by the base operating system. So tuning is even more complicated: You have to decide when to analyze the operating system and when to concentrate on R/3.

These rough guidelines, and statistics from OS06/ST06, indicate reasons to suspect the hardware and operating system:

ABAP TIPS CPU idle time for a single server that consistently falls below 30 percent. “Pages out/second” that exceeds 10,000 per hour over a 24-hour period. Load average over the last 15 minutes that exceeds 3.00. Low values for “physical memory available.” (These values vary greatly by the operating system, R/3 release, and the server loads, but you should expect at least 1GB of memory to be available for R/3.) 3. SAP R/3 WorkLoad Analysis. The WorkLoad Analysis statistics found via transaction ST03 are the most popular indicators of R/3 performance. WorkLoad Analysis will show average response times for the entire environment or for individual servers. It also provides detailed statistics for specific transactions and programs within a given time period. Transaction RZ03 will generate some of these same statistics, as well as buffer usage, in real time.

ABAP TIPS Most background jobs are reported as a single dialog step and will have very high average response times. Response times for query or report programs should generally have a lower percentage of CPU time and higher percentage of database request time. Programs that perform complex calculations or routine scheduling (for example, Material Requirements Planning should have a higher percentage of CPU time and lower percentage of database request time). Programs with UPDATE LOCAL will have higher database request times. Custom programs that are not stored in the buffer and programs that generate code (for example, Batch Data Conversion programs [BDCs] will have higher load times).

ABAP TIPS 4. SAP R/3 buffer statistics. ST02 is used to tune system memory and buffers. Tuning memory and buffers is very complex, so don’t attempt to do it without extensive analysis and expertise. Additionally, memory must always be tuned as a unit, because changes to one parameter will always affect other areas. Several hundred profile parameters affect system performance, and the majority of these either directly affect memory or rely on proper memory management. Hitratio: The hitratio is an indication of the buffers’ efficiency. When an SAP user or system function module needs data or additional objects, the system will generally look in R/3 buffers first. When the system is initially started, buffers are empty; once objects are called for they are stored subsequently in each buffer. The buffers will start with a hitratio of zero and should improve over time to a maximum possible of 100 percent. A system must be active for a considerable length of time before the hitratios will be stable enough for analysis. For a stable system, investigate buffers that consistently show hit ratios below 95 percent or whose hitratios appear to be declining.

ABAP TIPS Directory entries: All buffers need free directory entries. Memory space requirements for storing directory entries is minimal, so don’t hesitate to increase the number of directory entries for any buffer. Object swaps: A large number of object swaps is generally an indication of poor tuning; however, some swaps are unavoidable. Object swap totals are cumulative from system startup; therefore, you should expect to see these numbers grow over time. Roll and paging area memory: Analyze roll and paging area memory in detail when the percentage of current use consistently exceeds 80 percent or when a large portion of processing occurs on disk rather than in real memory. Heap memory: Batch programs can use large amounts of heap memory and, therefore, cause OS-level swap space requirements to increase. When you see large amounts of heap memory being used, make sure you have enough OS swap space to keep from freezing your operating system.

ABAP TIPS Call statistics: You can use call statistics to analyze table buffers and how effectively ABAP programs use them. Investigate low hitratios and high numbers of fails. Unusually high numbers for SELECT are often caused by programs performing large numbers of table scans, improper use or unavailability of appropriate indexes, or improper search techniques. 5. SAP R/3 table statistics. Use transaction ST10 to review table call statistics. ST10 will show the number of table changes, direct reads, and sequential reads and the number of calls and rows affected. These statistics can be invaluable when you’re considering buffering a table, adding an alternate index, or stripping data and tablespaces.

TUNING SPECIFIC PROGRAMS The following tools and techniques can be used to analyze performance problems with a little more exacting science:

ABAP TIPS ABAP Runtime Analysis (SE30) ABAP Program Extended Syntax Check (SLIN) Process Overview (SM50) Performance workload Analysis (ST02, ST03) Performance workload Statistics Records (STAT) Miscellaneous database statistics (ST04, DB01, DB02) Trace Requests (ST05) ABAP Program Debugger (SE38).  The ABAP Program Extended System Check is able to: SLIN  Locate unused data fields and tables  Find dead code in programs  Check authorizations  Quick check interfaces and compatibility of calls to forms, modules, and external programs  Locate type conversions  Give details of errors or warnings.

ABAP TIPS  The Process Overview, transaction SM50 Is often the best way to observe a program during execution. By watching the function modules being processed in real time, you can see which areas are the most time consuming and decide what types of tracing or debugging is most appropriate.  Performance workload Analysis statistics from transaction ST02. You can use ST02 and ST03 to generate a nearly endless variety of statistics to tune individual programs or the entire system. For a more detailed breakdown of processing times for individual programs see Top Time, By Task, and other displays within ST03. ST02 and ST03 are very complex transactions with a multitude of performance statistics. For custom code or programs with user exits, use the dialog step counts to determine roughly how modifications affect standard SAP code. Comparing statistics from code before and after modifications have been made will tell you a lot about how efficiently the code was written.

ABAP TIPS  Database statistics Transaction DB01 can reveal exclusive lockwait situations, which can be used for both system-level and application tuning. (It can often explain why programs appear to be doing nothing.) Transaction DB02 shows table and index statistics. You can check for missing indexes, files with too little or too much space, extent problems, and a host of related items. These numbers will come in handy when you begin stripping data and tablespaces. Database transaction ST04 will provide high-level performance statistics. With ST04, you can make sure the database interface isn’t having problems servicing your program’s request for data.

ABAP TIPS  SQL trace For individual program tuning, try SQL, enqueue, and RFC tracing via transaction ST05 – Trace Requests. The traces will show step-by-step details of each and every function within your program. SQL trace will show database-level activity, as well as ABAP. The SQL trace will reveal full scans of tables, inappropriate index choice, any failure to load record keys, repetitive calls to the same data, and similar conditions that make tuning an application much easier.  ABAP Program Debugger This tool is best suited for program development and maintenance, but may be useful for tracing some difficult performance problems. The debugger allows you to watch particular sections of code or data fields during program execution. You can also generate lists of modules, calls, and other key commands to summarize program execution. You also have the ability to change data fields and processing routines in a real-time mode.

ABAP TIPS  Database statistics Transaction DB01 can reveal exclusive lockwait situations, which can be used for both system-level and application tuning. (It can often explain why programs appear to be doing nothing.) Transaction DB02 shows table and index statistics. You can check for missing indexes, files with too little or too much space, extent problems, and a host of related items. These numbers will come in handy when you begin stripping data and tablespaces. Database transaction ST04 will provide high-level performance statistics. With ST04, you can make sure the database interface isn’t having problems servicing your program’s request for data.

ABAP TIPS  Database statistics Transaction DB01 can reveal exclusive lockwait situations, which can be used for both system-level and application tuning. (It can often explain why programs appear to be doing nothing.) Transaction DB02 shows table and index statistics. You can check for missing indexes, files with too little or too much space, extent problems, and a host of related items. These numbers will come in handy when you begin stripping data and tablespaces. Database transaction ST04 will provide high-level performance statistics. With ST04, you can make sure the database interface isn’t having problems servicing your program’s request for data.

ABAP TIPS TIP Area

9 SAPscript upload/download

Use program RSTXSCRP to upload and download SAPscript data including: forms, styles, printers, character sets, etc.. Download to the front-end or application server.

ABAP TIPS TIP Area

10 Calculating Invoice due dates

Use function: FI_TERMS_OF_PAYMENT_PROPOSE.

ABAP TIPS TIP Area

11 Accessing the ABAP editors programmatically

To access the ABAP editors (as well as screen painter, menu painter) programmatically; use function: RS_TOOL_ACCESS.

ABAP TIPS TIP Area

12 Hiding ABAP source code

In SAP releases upto 4.6C you can place the special character sequence *@#@@[SAP] on the first line of an ABAP to hide the source code - it will still run and behave as normal. To bring the code back to visible you must upload it again from a file or put it into a Transport - release it, then edit the transport file and remove the character string. For 4.6C you can look at table: D010SINF This table includes a field SQLX. When this field is set to "X" the program source will not be viewable as for program: SAPMSYST.

ABAP TIPS TIP Area

13 Delivery due list for release 4.6

The delivery due list (VL10G) uses user-exits to enable extra data to be presented to the user in the ALV list - these are: LV50R_VIEWG03 for data from Sales and LV50R_VIEWG06 for data from Purchasing.

ABAP TIPS TIP Area

14 To change development class of a SAPscript

Use program RSWBO052

ABAP TIPS TIP Area

15 To transport Standard Texts

Use Program RSTXTRAN or enter directly in transport Put entry directly into the transport: R3TR TEXT TEXT,Text Name,ST,Language R3TR TEXT TEXT,Z_ALLERGAN_SWISS_DISTRIBUTOR,ST,E

ABAP TIPS TIP Area

16 Importing Graphics (Logos) into SAPscript

The program RSTXLDMC can be used to upload graphics (file extension .tif on PC files) into individual standard text.

ABAP TIPS TIP Area

17 Calling an ABAP form from SAPscript

In Layout Set: DEFINE &X& = ... DEFINE &Y& = ... DEFINE &Z& = ... PERFORM XXXXXX IN Zxxxxxxx USING &X& USING &Y& CHANGING &Z& In ABAP program Zxxxxxx FORM XXXXXX TABLES INPUT1 STRUCTURE ITCSY OUTPUT1 STRUCTURE ITCSY

ABAP TIPS *get input parameters LOOP AT INPUT1. CASE INPUT1-NAME. WHEN 'X'. INPUT_X = INPUT1-VALUE. WHEN 'Y'. INPUT_Y = INPUT1-VALUE. ENDCASE. ENDLOOP. {logic to use program variable input_x and input_y to set say program variable output_z} *set output variables: REFRESH OUTPUT1. OUTPUT1-NAME = 'Z'. OUTPUT1-VALUE = OUTPUT_Z. APPEND OUTPUT1.

ABAP TIPS TIP Area

18 Debug SAPscript

You can debug a SAPscript: Use Tools - Word Processing - Layout Set. Enter name of layout set and then Utilities - Activate Debugger. It is of no consequence which layout set you enter when selecting the SAPscript debugger. (Menu path: Tools-Word-processing - Forms, Utilities - Activate Debugger) The next layoutset called will invoke the debugger. This is quite handy when verifying which layoutset is being called (Verifying customizing settings). Another way to set the SAPscript debugger is to run program RSTXDBUG. Save Internal Table as File on the Presentation Server

ABAP TIPS TIP Area

19 Standard Conversion Exits

Most conversion exits used in screens by SAP are actually function modules. You can find them by searching for CONVERSION_EXIT_name_INPUT and CONVERSION_EXIT_name_OUTPUT.

ABAP TIPS TIP Area

20 List of ways to transport variants

There are at least three ways that you can transport a variant for a program. When you first transport a program, all elements of a program are transported along with the source code. This includes any variants that have been created at this time After the first time a program has been transported, there are two ways to move a variant. The first method is to manually add an entry to the transport for the variant you want to move. The format of the entry is LIMU VARX xxxxxxxxName_of_the_variant where xxxxxxxx is the program name. The last method is the easiest, in that you do not have to remember any arcane codes. Go to the ABAP editor, and go to the variant screen. Under the Utilities menu is Transport Variant. This allows you to choose the variants to transport, and the transport to put them in.

ABAP TIPS TIP Area

21 List of methods to FTP from within SAP

Write a UNIX script and call it via CALL SYSTEM Create a command through transaction SM69 (and execute via SXPG_CALL_SYSTEM) that call the script with parameters. Use the FILTER option on the OPEN DATASET command Have an external step in your job that runs after the dataset has been created. The external step will call a script with parameters to do the ftp. NOTE: ftp can accept commands from a file, and it is often useful to create a file containing the commands, and pipe the file into the ftp command.

ABAP TIPS TIP Area

22 User Status Tip

If you have several status' for a program that are nearly identical, it can be easier to setup and maintain a single status, and just hide parts of it as required. EG: DATA: BEGIN OF MTAB_UCOMM_EXCLUDE OCCURS 0, VALUE(4) TYPE C, END OF MTAB_UCOMM. AT USER-COMMAND. PERFORM SET_PF_STATUS.

ABAP TIPS *---------------------------------------------------------------------* * FORM SET_PF_STATUS * *---------------------------------------------------------------------* * Set up the menus/buttons for the report * *---------------------------------------------------------------------* FORM SET_PF_STATUS. CLEAR MTAB_UCOMM_EXCLUDE. REFRESH MTAB_UCOMM_EXCLUDE. CASE MI_CURRENT_PAGE. WHEN 1. *-- Do not want any pushbuttons that point to items to the right *-- since the list is at its rightmost position MTAB_UCOMM_EXCLUDE-UCOMM = 'FRST'. APPEND MTAB_UCOMM_EXCLUDE. MTAB_UCOMM_EXCLUDE-UCOMM = 'PREV'. APPEND MTAB_UCOMM_EXCLUDE.

ABAP TIPS WHEN MI_TOTAL_PAGES. *-- Do not want any pushbuttons that point to items to the left *-- since the list is at its leftmost position MTAB_UCOMM_EXCLUDE-UCOMM = 'LAST'. APPEND MTAB_UCOMM_EXCLUDE. MTAB_UCOMM_EXCLUDE-UCOMM = 'NEXT'. APPEND MTAB_UCOMM_EXCLUDE. WHEN OTHERS. *-- Want all pushbuttons to appear on any other page ENDCASE. SET PF-STATUS 'MAIN' EXCLUDING MTAB_UCOMM_EXCLUDE. ENDFORM. " SET_PF_STATUS Editor Tips (*EJECT and *$*$) *EJECT - If you put *EJECT at the start of a line, it will force a new page when you print your source code. This comes in real handy when you would like to have subroutines start at the top of a new page.

ABAP TIPS *$*$* - By placing *$*$ at the beginning of a comment line will lock the line for editing. You are able to edit the line until you hit the enter key.

ABAP TIPS TIP Area

23 Change the font on the X_65_255 paper size

This tip was taken from the SAP-R3 mailing list, and is by Sheila Tichener. If you need to use a large line-size to get all your data in I know the sap version of X_65_255 for hp laser jet 4 gives an unnecessarily small font . You can change it in SPAD (or copy to Y_65_255) as follows. Choose Device formats, Change hplj4 x_65_255 Execute Double click on printer initialization Change from:# select Courier 16.67 CPI normal font \e(s0p16.67h0s0b4099T to:# select Arial 24 CPI 15 point normal \e(s0p24h15v0s0b16602T

ABAP TIPS Also bold as follows:# select Arial 24 CPI 15 point bold \e(s0p24h15v0s3b16602T it still fits and looks better. Also the error you get when changing a format in the output screen is only a warning and can be overridden by pressing the green tick. If the sap standard formats don't fit your requirements you can create your own e.g. Y_65_170 . It seems to be the numbers in the name that somehow triggers which one the ABAP chooses.

ABAP TIPS TIP Area

24 To find a single quote within a string

Use 4 single quotes to find one quote in a string. The following code snippet will replace a single quote with a double quote. replace '''' with '"' into field

ABAP TIPS TIP Area

25 Helping the DBMS find the correct index

Sometime, you may find that the a SELECT that you have coded is very slow, even though you have put all the fields needed for an index in your where clause. Usually, this means that the DBMS is selecting the wrong index, you can tell if this is the case by doing an SQL trace (System - Utilities - SQL Trace). You can help the DBMS select the correct index by providing hints, include all fields from the index, and make sure that the fields are in the same order as they appear in the index.

ABAP TIPS TIP Area

26 Saving screens created with Screen Painter

You can not download code for the Screens (except for the ABAP part), but at least you can download a printout of what you set up. If you are in Object Browser looking at the module program, you can highlight the screens and click the print button. Click no to print immediately, then go into System -- Services -- Output Control to select the spool request and then go into List -- Save -- Local File. (Of course, you can send it to a printer to see documentation on your screen).

ABAP TIPS TIP Area

27 Help Views

For instance, in a Multi-language environment when you have a code and text combination you want to set up. Typically, you have to set up two tables: One with just the valid codes i.e. Zxxx where the only field is the code field, the second is ZxxxT which contains the code and language as the primary index with the description as the data field. In this case, then you usually define a view H_Zxxx which is a join on these two tables. The key thing is that the Foreign Key definition for the code field in the ZxxxT must have the must have the type "Key Fields of a Text Table". This results in the Table Maintenance generator (SM30) generating a screen that allows you to maintain the code and description together for the system language.

ABAP TIPS In a related note, to set up a customer transaction for a Table Maintenance generated dialog, use SE80 and enter the function group used for the table maintenance dialog. Then Create a transaction (Zxxx) of type parameter. Fill in text, specify Transaction SM30, click on "skip initial screen" and set up default values of VIEWNAME set to Zxxx and UPDATE set to X. * After defining a foreign key relation of type KEY FIELDS IN A TEXT TABLE the system automatically combines updates of the base table and the text table. Try defining two tables and the foreign key as stated above. So creating a help view is not needed for this purpose.

ABAP TIPS * The help view is useful when you want to have a matchcode-like F4 help on a specific field. Every field that is based on same domain automatically uses the help view if no other F4 help (Matchcode, Process on value request) is related. For a value table only one help view can be defined. Example: If you define in your abap a parameter or select-options 'parameters: pa_bukrs like t001-bukrs.' you will see that is automatically has a F4 help. This help is provided by helpview H_T001.

Related Documents

Abap Program Tips
May 2020 3
23-useful Abap Tips
November 2019 2
Abap
November 2019 25
Abap
August 2019 43
Abap
November 2019 22