Monday, July 23, 2007

BADI`S

What kind of enhancements are possible?

Depending on your release there a lot of ways to enhance your system.

  • BAdI
    • classic BAdIs
    • kernel-based BAdIs from Enhancement Framework since Netweaver 2004s
  • User Exits (also known as CMODs/SMODs)
  • Appends to structures and database tables
  • additional values in fixed-value domains

What is a BADI?

BADI stands for Business Add-In. These are like user exits but are implemented using ABAP Objects. BADI's can be implemented in every stage of the systems landscape. That means there are more than SAP and Customer specific views, but also country or language specific views.

How to Search BADI for a Transaction?

?Finding BADI Using CL_EXITHANDLER=>GET_INSTANCE
Go to the Transaction, for which we want to find the BADI,
Get the Program Name of Corresponding Transaction.
(Click on System->Status. Double Click on Program Name)
Once inside the program search for 'CL_EXITHANDLER=>GET_INSTANCE'.
Make sure the radio button "In main program" is checked.
A list of all the programs with call to the BADI's will be listed.
The export parameter 'EXIT_NAME' for the method GET_INSTANCE of class CL_EXITHANDLER will give you the BADI name for the Transaction.

?Finding BADI Using SQL Trace (TCODE-ST05).


HOW TO FIND BADI`S?


Introduction

There are multiple ways of searching for BAdIs. My favorite one is using the Performance Trace (formerly known as SQL trace) transaction code ST05.

This analyzing technique is based on the fact that all BAdIs are registrated in SAP database tables. So for each BAdI call these database tables will be accessed. The BAdI database tables are SXS_INTER, SXC_EXIT, SXC_CLASS and SXC_ATTR. These tables are always accessed by the views V_EXT_IMP and V_EXT_ACT. So these two ABAP views (T: SE11) will be the basis for the trace.

BADI

The procedure to discover BAdIs by a Performance Trace will be explained by using the example used below.

Example case

I want to know which BAdIs are called in the transaction "Maintain Business Partners" transaction code BP.

Pre checks

  • Check if no other users (T:SM04) or batch jobs (T: SM50) are using the same user as you do.
  • Trace Actions

    Start the Performance trace

  • Start transaction ST05 (Performance Analysis)
  • Set flag field "Buffer trace"
  • Remark: We need to trace also the buffer calls, because BAdI database tables are buffered. (especially view V_EXT_IMP and V_EXT_ACT)

  • Push button "Activate Trace"
  • Execute the Business transaction

  • Start transaction BP in a new GUI session
  • Push button "Organization"
  • Fill in your test data
  • Name NL4B
    Street Olympia
    House number 1a/1b
    Postal code 1213 NS
    City Hilversum
    Country NL
  • Push button Save
  • Performance trace

  • Go back to the Performance trace session
  • Push button "Deactivate Trace"
  • Analyzing the Trace List

    Showing the Trace List

  • Push button "Display Trace"
  • The popup screen "Set Restrictions for Displaying Trace" appears

    Now we are going to filter the trace on Objects: V_EXT_IMP and V_EXT_ACT.

  • Push button "Multiple selections" button behind field Objects
  • Fill: V_EXT_IMP and V_EXT_ACT
  • image

  • Push button "Copy (F8)"
  • Fill Operations: OPEN
  • Push button Enter
    See the result:
  • image

    Interpreting the Trace list

    All the interface class names of view V_EXT_IMP start with IF_EX_. This is the standard SAP prefix for BAdI class interfaces. The BAdI name is after the IF_EX_.

    So the BAdI name of IF_EX_ADDR_LANGU_TO_VERS is ADDR_LANGU_TO_VERS.

    In transaction SE18 you can see the BAdI definition.

    image

    (If you can’t find the BAdI definition name, search in table SXS_INTER.)

    Exporting the Trace list

    If you’d like to keep your analysis, you can export it to Excel file format.

    Actually the file will be saved in tab separated file format, but giving the file the extension .xls it will automatically be opened by Excel.

  • Start menu: List > Save > Local File
  • Select Spreadsheet
  • Push Enter
  • Fill your preferred file location and file name
  • image

  • Push button "Generate"
  • Open the file (in Excel)
  • image

  • Delete the columns and rows you don’t need and the result looks like:
  • image

    View V_EXT_IMP and V_EXT_ACT

    The reason for filtering the result not only on the view V_EXT_IMP but also on V_EXT_ACT is necessary, because not all BAdIs are implemented in the same way.

    For example:

    V_EXT_IMP catches BAdI BPTIME_BP001.

    V_EXT_ACT catches BAdI ADDRESS_SEARCH

    Tips

  • Make a full test entry in the Business transaction before starting the Performance analysis.
    So during the Performance trace you won’t make mistakes. Making mistakes during the recording will cause extra trace lines in your trace list.
  • Try to start with an empty Business transaction screen.
    This tip is best explained by an example.
    When I restart transaction BP after I have created, displayed or changed a business partner, the last opened business partner will be displayed automatically. This means also I will get extra trace lines in my trace list.
    To start again with an empty business partner screen you have to close all GUI sessions and login again.
  • In the Business transaction you need to fill all required fields so all BAdIs will be called.
  • Appendix BP analysis

    View Call BAdI
    V_EXT_ACT R 20 ADDR_LANGU_TO_VERS ADDR_LANGU_TO_VERS
    V_EXT_IMP R 30 IF_EX_ADDR_LANGU_TO_VERS ADDR_LANGU_TO_VERS
    V_EXT_ACT R 20 BUPR_FILTER_RELTYP BUPR_FILTER_RELTYP
    V_EXT_IMP R 30 IF_EX_BUPR_FILTER_RELTYP BUPR_FILTER_RELTYP
    V_EXT_ACT R 20 BUPR_FILTER_RELTYP BUPR_FILTER_RELTYP
    V_EXT_IMP R 30 IF_EX_BUPR_FILTER_RELTYP BUPR_FILTER_RELTYP
    V_EXT_ACT R 20 BUPR_FILTER_RELSHP BUPR_FILTER_RELSHP
    V_EXT_ACT R 20 BUPA_AUGRP BUPA_AUGRP
    V_EXT_IMP R 30 IF_EX_BUPA_AUGRP BUPA_AUGRP
    V_EXT_IMP R 30 IF_EX_BPTIME_BP001 BPTIME_BP001
    V_EXT_ACT R 20 ADDRESS_SUBSCREEN ADDRESS_SUBSCREEN
    V_EXT_ACT R 20 ADDRESS_SEARCH ADDRESS_SEARCH
    V_EXT_IMP R 30 IF_EX_ADDRESS_SUBSCREEN ADDRESS_SUBSCREEN
    V_EXT_IMP R 30 IF_EX_ADDRESS_SUBSCREEN ADDRESS_SUBSCREEN
    V_EXT_IMP R 30 IF_EX_ADDRESS_SUBSCREEN ADDRESS_SUBSCREEN
    V_EXT_IMP R 30 IF_EX_ADDRESS_SUBSCREEN ADDRESS_SUBSCREEN
    V_EXT_ACT R 20 ADDRESS_SEARCH ADDRESS_SEARCH
    V_EXT_ACT R 20 ADDRESS_CHECK ADDRESS_CHECK
    V_EXT_ACT R 20 ADDRESS_CHECK ADDRESS_CHECK
    V_EXT_ACT R 20 ADDR_TXJCD_CHECK ADDR_TXJCD_CHECK
    V_EXT_ACT R 20 ADDRESS_CHECK ADDRESS_CHECK
    V_EXT_ACT R 20 ADDR_PRINTFORM_SHORT ADDR_PRINTFORM_SHORT
    V_EXT_IMP R 30 IF_EX_ADDR_PRINTFORM_SHORT ADDR_PRINTFORM_SHORT
    V_EXT_ACT R 20 BUPA_ROLE_EXPORT BUPA_ROLE_EXPORT
    V_EXT_IMP R 30 IF_EX_BUPA_ROLE_EXPORT BUPA_ROLE_EXPORT
    V_EXT_ACT R 20 BUPA_BANK_EXPORT BUPA_BANK_EXPORT
    V_EXT_IMP R 30 IF_EX_BUPA_BANK_EXPORT BUPA_BANK_EXPORT
    V_EXT_ACT R 20 BUPA_CCARD_EXPORT BUPA_CCARD_EXPORT
    V_EXT_IMP R 30 IF_EX_BUPA_CCARD_EXPORT BUPA_CCARD_EXPORT
    V_EXT_ACT R 20 BUPA_INDSEC_EXPORT BUPA_INDSEC_EXPORT
    V_EXT_IMP R 30 IF_EX_BUPA_INDSEC_EXPORT BUPA_INDSEC_EXPORT
    V_EXT_ACT R 20 BUPA_ADDR_EXPORT BUPA_ADDR_EXPORT
    V_EXT_IMP R 30 IF_EX_BUPA_ADDR_EXPORT BUPA_ADDR_EXPORT
    V_EXT_ACT R 20 BUPA_GENERAL_EXPORT BUPA_GENERAL_EXPORT
    V_EXT_IMP R 30 IF_EX_BUPA_GENERAL_EXPORT BUPA_GENERAL_EXPORT
    V_EXT_ACT R 20 BUPA_GENERAL_UPDATE BUPA_GENERAL_UPDATE
    V_EXT_IMP R 110 IF_EX_BUPA_GENERAL_UPDATE BUPA_GENERAL_UPDATE
    V_EXT_ACT R 20 BUPA_BANK_UPDATE BUPA_BANK_UPDATE
    V_EXT_IMP R 110 IF_EX_BUPA_BANK_UPDATE BUPA_BANK_UPDATE
    V_EXT_ACT R 20 BUPA_CARDS_UPDATE BUPA_CARDS_UPDATE
    V_EXT_IMP R 30 IF_EX_BUPA_CARDS_UPDATE BUPA_CARDS_UPDATE
    V_EXT_ACT R 20 BUPA_ROLES_UPDATE BUPA_ROLES_UPDATE
    V_EXT_IMP R 30 IF_EX_BUPA_ROLES_UPDATE BUPA_ROLES_UPDATE
    V_EXT_ACT R 20 BUPA_INDSEC_UPDATE BUPA_INDSEC_UPDATE
    V_EXT_IMP R 30 IF_EX_BUPA_INDSEC_UPDATE BUPA_INDSEC_UPDATE
    V_EXT_ACT R 20 BUPA_IDENT_UPDATE BUPA_IDENT_UPDATE
    V_EXT_IMP R 30 IF_EX_BUPA_IDENT_UPDATE BUPA_IDENT_UPDATE
    V_EXT_ACT R 20 ADDRESS_UPDATE ADDRESS_UPDATE
    V_EXT_IMP R 30 IF_EX_ADDRESS_UPDATE ADDRESS_UPDATE
    V_EXT_IMP R 30 IF_EX_ADDRESS_UPDATE ADDRESS_UPDATE
    V_EXT_ACT R 20 BUPA_ADDR_UPDATE BUPA_ADDR_UPDATE
    V_EXT_IMP R 110 IF_EX_BUPA_ADDR_UPDATE BUPA_ADDR_UPDATE
    V_EXT_ACT R 20 BUPA_TAX_UPDATE BUPA_TAX_UPDATE
    V_EXT_IMP R 110 IF_EX_BUPA_TAX_UPDATE BUPA_TAX_UPDATE
    V_EXT_ACT R 20 FSBP_BPID_UPDATE FSBP_BPID_UPDATE
    V_EXT_IMP R 30 IF_EX_FSBP_BPID_UPDATE FSBP_BPID_UPDATE
    V_EXT_IMP R 30 IF_EX_BPTIME_BP001 BPTIME_BP001
    V_EXT_ACT R 20 FSBP_BP001_UPDATE FSBP_BP001_UPDATE
    V_EXT_IMP R 30 IF_EX_FSBP_BP001_UPDATE FSBP_BP001_UPDATE
    V_EXT_IMP R 30 IF_EX_BPTIME_BUT021_FS BPTIME_BUT021_FS
    V_EXT_ACT R 20 FSBP_BUT021_UPDATE FSBP_BUT021_UPDATE
    V_EXT_IMP R 30 IF_EX_FSBP_BUT021_UPDATE FSBP_BUT021_UPDATE
    V_EXT_ACT R 20 ADDRESS_SEARCH ADDRESS_SEARCH
    V_EXT_ACT R 20 PARTNER_UPDATE PARTNER_UPDATE
    V_EXT_IMP R 30 IF_EX_PARTNER_UPDATE PARTNER_UPDATE
    V_EXT_IMP R 30 IF_EX_PARTNER_UPDATE PARTNER_UPDATE
    V_EXT_IMP R 30 IF_EX_BPTIME_BP001 BPTIME_BP001
    V_EXT_IMP R 30 IF_EX_BPTIME_BUT021_FS BPTIME_BUT021_FS
    V_EXT_ACT R 20 GOS_SRV_SELECT GOS_SRV_SELECT
    V_EXT_IMP R 30 IF_EX_GOS_SRV_SELECT GOS_SRV_SELECT
    V_EXT_ACT R 20 ADDRESS_SEARCH ADDRESS_SEARCH


    ABAP Performance and Tuning

    What tools can be used to help with performance tuning?

    ST05 is the SQL Trace transaction and can be used to measure the performance of the select statements of the program. SE30 is the Runtime Analysis transaction and can be used to measure the application performance. It also gives some tips on how to improve the performance through efficient code.

    One of the best tools for static performance analyzing is Code Inspector (SCI). There are many options for finding common mistakes and possible performance bottleneck's.

    What are the steps to optimise the ABAP Code?

    1. Avoid using SELECT...ENDSELECT... construct and use SELECT ... INTO TABLE.
    2. Use WHERE clause in your SELECT statement to restrict the volume of data retrieved.
    3. Design your Query to Use as much index fields as possible from left to right in your WHERE statement
    4. Either enable buffering in your database table or create Indexes to speed up the query.
    5. Use FOR ALL ENTRIES in your SELECT statement to retrieve the matching records at one shot.
    6. Avoid using nested SELECT statement, SELECT within LOOPs.
    7. Avoid using INTO CORRESPONDING FIELDS OF TABLE. Instead use INTO TABLE.
    8. Avoid using SELECT * and Select only the required fields from the table.
    9. Avoid nested loops when working with large internal tables.
    10. Use assign instead of into in LOOPs for table types with large work areas
    11. When in doubt call transaction SE30 and use the examples and check your code
    12. Whenever using READ TABLE use BINARY SEARCH addition to speed up the search. Be sure to sort the internal table before binary search.
    13. Use "CHECK" instead of IF/ENDIF whenever possible.
    14. Use "CASE" instead of IF/ENDIF whenever possible.
    15. Use "MOVE" with individual variable/field moves instead of "MOVE-CORRESPONDING", creates more coding but is more effcient.

    back to top

    What is the difference between SELECT SINGLE and SELECT ... UP TO 1 ROWS?

    SELECT SINGLE returns the first matching row for the given condition and it may not be unique, if there are more matching rows for the given condition.

    SELECT ... UP TO 1 ROWS retrieves all the matching records and applies aggregation and ordering and returns the first record.

    Inorder to check for the existence of a record then it is better to use SELECT SINGLE than using SELECT ... UP TO 1 ROWS since it uses low memory and has better performance.

    back to top

    Which is the better - JOINS or SELECT... FOR ALL ENTRIES...?

    When using FOR ALL ENTRIES the number of matching records is restricted to the number of records in the internal table. If the number of records in the database tables is too large then join would cause overheads in performance. Additionally a JOIN bypasses the table buffering.

    back to top

    Does SAP publish guides and cookbooks on performance monitoring and testing?

    Yes it does. You'll find a collection of resources for Performance monitoring and testing under SAP NetWeaver Administration on SDN.

    back to top

    User Collect Statement to do Sum in the internal table.

    Instead of using logic to do summation use collect statement.

    Avoid use of nested loops :

    For example: if there is a loop like this:

    loop at itab1

    loop at itab2

    end loop.

    end loop.

    in the production environment it may be possible that such loop may take much time n get dump error.

    instead we can use

    loop at itab1

    Read itab2 key itab1-f1 '' f1 is any field of itab1

    itab1-f2

    v = sy-tabix.

    now

    loop at itab2 from v

    end loop.

    clear v.

    in this case we can save lot of time by checking only relevant rows.


    Test & Analysis Tools

    • ABAP Performance Trace (ST05)
    • ABAP Runtime Trace (SE30)
    • Coverage Analyzer (SCOV)
    • eCATT (SECATT)
    • Global Performance Analysis (ST30)
    • Memory Inspector (S_MEMORY_INSPECTOR)

    ABAP/4 Tuning Checklist


    General Considerations:

    1. Is the program YEAR 2000 compliant ?
    check date logic and make sure there are not any 2 digit year fields

    2. Is the program US ready ?

    taking into consideration the US volumes, will the program ever finish? Can data be selected for just the US - selection parameters at company code level, plant, purch org, sales div, etc...

    SQL SELECT statements:

    3. Is the program using SELECT * statements ?

    Convert them to SELECT column1 column2 or use projection views

    4. Are CHECK statements for table fields embedded in a SELECT ... ENDSELECT loop, or in a LOOP AT ... ENDLOOP ?

    Incorporate the CHECK statements into WHERE clause of the SELECT statement, or the LOOP AT statement

    5. Do SELECTS on non-key fields use an appropriate DB index or is table buffered ?

    Create an index for the table in the data dictionary or buffer tables if they are read only or read mostly

    6. Is the program using nested SELECTs to retrieve data ?

    Convert nested selects to database views, DB joins (4.0) or SELECT xxx FOR ALL ENTRIES IN ITAB Nested open select tatements are usually bad, and unless the amount of data is enormous, these types of reads should be avoided. They are usually used as they are the safest way to program - you will never have any memory issues. The technical explanation as to why this is bad follows - feel free to tune out for the remainder of the paragraph. Open selects read just one record from the database at a time. Each time you do this, the app server and database server need to communicate. The packet size of this communication is typically much larger than the size of the record, so most of the packet is waisted with this type of read. When system load is heavy, this can slow performance. Combine this with the overhead of accessing the database many times vs just once.

    7. Are there SELECTs without WHERE condition against files that grow constantly (BKPF/BSEG,MKPF/MSEG,VBAK/VBAP...) ?

    Program design is wrong - back to drawing board

    8. Are SELECT accesses to master data files buffered (no duplicate accesses with the same key) ?

    Buffer accesses to master data files by storing the data in an internal table and filling the table with READ TABLE...BINARY SEARCH method

    9. Is the program using SELECT ...APPEND ITAB ...ENDSELECT techniques to fill internal tables ?

    Change processing to read the data immediately into an internal table (SELECT VBELN AUART ... INTO TABLE IVBAK...)

    10. Is the program using SELECT ORDER BY statements ?

    Data should be read into an internal table first and then sorted, unless there is an appropriate index on the order by fields

    11. Is the programming doing calculations/summations that can be done on the database via SUM, AVG, MIN or MAX functions of the SELECT statement?

    use the calculation capabilities of the database via SELECT SUM...

    12. Do any SELECT statements contain fully-qualified keys (all keys are specified to match a single value in the WHERE clause) but not the keyword SINGLE?

    the syntax checker won't catch this & neither does the database optimizer! such an "incorrect" statement can take 5x longer

    13. Are there any SELECT or LOOP AT structures that are only attempting to retrieve the first match on a generic key lookup?

    use the EXIT statement, or UP TO 1 ROWS option in the case of SELECT, to break the loop & avoid unnecessary iterations

    14. Do UPDATE/INSERT/DELETE statements occur inside loops?

    save all accumulated changes in an internal table and then use the SQL array statements to perform the updates: INSERT FROM TABLE .

    15. Are only a few fields being changed by an UPDATE statement?

    use the SET = clause of the UPDATE statement rather than updating the entire record

    16. Is the program inserting/updating or deleting data in dialog mode (not via an update function module) ?

    Make sure that the program issues COMMIT WORK statements when one or more logical units of work (LUWS) have been processed

    Internal Table Processing:

    (also see 4 & 13 above)

    17. Are internal tables processed using READ TABLE itab WITH KEY ... BINARY SEARCH technique ?

    Change table accesses to use BINARY SEARCH method. Note that this is ONLY possible if the table is sorted by the access key! Add a SORT if not already there.

    18. Is a semi-sequential scan of a large, sorted internal table being performed by a LOOP AT ... WHERE, or LOOP AT ... with CHECK statements to continue/terminate the loop ?

    Use a READ TABLE with BINARY SEARCH to retrieve first record in the sequence matching the lookup keys, then LOOP AT ... FROM SY- TABIX + 1 until one of the key field values changes; this way you get only the records you need, rather than reading up to the starting point

    19. Is a condensed, summary internal table being built by READ TABLE... BINARY SEARCH and then sum, INSERT or APPEND?

    Use the COLLECT statement, and SORT the result after the table is complete

    20. Is a COLLECT statement being used simply to avoid duplicate entries in an all-character fields - no numeric fields: types I, P or F - internal table ?

    Use the READ TABLE ... WITH KEY ... BINARY SEARCH with an INSERT ... INDEX SY-TABIX to build the table

    21. Are internal tables being SORTed without any field qualifiers?

    Specify the actual fields to be used: SORT BY ... The fewer fields, the better!

    22. Are internal tables being copied or compared record-by-record?

    Use the "[]" option to refer to the entire table in one line of code:

    - TAB2[] = TAB1[] - copy TAB1 to TAB2

    - IF TAB1[] EQ TAB2[] - compare TAB1 to TAB2


    String Processing:

    23. Are strings being built up/broken down manually with code fragments?

    use the new CONCATENATE/SPLIT statements, with the SEPARATED BY SPACE option of CONCATENATE if desired

    24. Are the older, obsolete string handling functions for finding string length, or centering/right-justifying strings being called?

    use the newer "strlen( )", "WRITE...TO...CENTERED", "WRITE...TO...RIGHT-JUSTIFIED" statements

    25. Are field strings (records) being set to a special character, other than SPACE, via a CLEAR and then a TRANSLATE instruction?

    use the new CLEAR WITH statement (esp. useful with standard SAP batch input generation programs to set the "no value for this field" indicator, which has a default symbol of "/")

    Miscellaneous:

    26. Is an internal table filled with a massive amount of data (approx. 5000 to 10000 records or more, depending on record length), sorted and processed?

    - instead, use the FIELD-GROUPS declaration, and the INSERT, EXTRACT, SORT and LOOP instructions to define, create, sort and process such large volumes of data more efficiently

    27. Is a logical database-driven program taking too long to select data?

    - convert the program to specific SELECT statements, with more appropriate index usage and a minimized sequence of nested SELECTs; don't forget to remove the 'Logical database' name/application from the program's attributes

    28. Is a MOVE-CORRESPONDING statement used when it's not needed?

    - if moving a complete record with same structure, just use the simple assignment statement: XVBAP = VBAP or MOVE VBAP TO XVBAP

    and if moving only a handful of fields, use specific assignments

    29. Are there no OBLIGATORY specifications on the key PARAMETERS and/or SELECT-OPTIONS declarations?

    - enforce user entry of key fields, thus limiting database accesses to some degree. To read everything, however, the user could still enter "1" -"99999999..." (see next item though), but at least they start to think about what they really need to see.

    30. Are SELECT-OPTIONS fully open to the most complex searches even when they need not be?

    - Use the keywords NO-EXTENSION and/or NO INTERVALS of the SELECT-OPTIONS declaration, if possible, to limit the number of ranges to only 1 (NO-EXTENSION), or limit the entry to single values only (NO INTERVALS) if that's all that is really needed for the application, so that the SELECT statement's "IN" operation is less complex

    31. Producing information messages about "long run-times" can also be beneficial in reducing run-times

    -the user will think twice and hopefully re-starts the program with a smaller range; or in extreme situations, an error message preventing generic input or complete range input on a key field

    32. In especially difficult cases, where no amount of specific statement re- writing, indexing, or buffering increases performance enough, consider re- structuring the main SELECT sequence, if possible, to reduce the total number of records to a manageable size.

    - this technique is only possible with certain table sequences that are related via both forward and backward pointing foreign key relationships, and then only makes sense when reversing the logic will definitely reduce the total read accesses, and does not require a complete program re-write of all related routines, etc.var domainName = 'https://wiki.sdn.sap.com/wiki'; var entityId = '35836'; var spaceKey = 'Snippets'new Ajax.Autocompleter('labelName', 'labelsAutocompleteList', '35836',

    Unknown macro: { tokens}
    );

    RUNTIME:FAQ`S

    What does A BAP stand for?

    ABAP currently stands for Advanced Business Application Programming; however the original meaning was Allgemeiner Berichtsaufbereitungsprozessor, which is German for "generic report preparation processor"
    A different explanation is Anfänger Basteln An Programmen, which is german for "beginners tinker with programs"

    back to top

    What are the different types of internal tables?

    There are three types of internal tables in ABAP, standard table,
    sorted table, and hashed table.

    back to top

    What is the difference between SAP memory and ABAP memory?

    SAP Memory is a global memory area which all sessions within a
    SAPgui have access to. This allows for passing data between
    sessions. The SET PARAMETER ID and GET PARAMETER ID statements are
    used to manipulate the SAP Memory.

    SET PARAMETER ID 'MAT' field p_matnr.
    GET PARAMETER ID 'MAT' field p_matnr.

    ABAP Memory is a memory area which all programs in the call stack
    within the same internal session can access. The EXPORT and IMPORT
    statements are used here.

    export p_matnr = p_matnr to memory id 'ZTESTMAT'.
    import p_matnr = p_matnr from memory id 'ZTESTMAT'.

    back to top

    What are the events used in report programs?

    Load-of-Program
    Initialization
    At Selection-Screen
    At Selection-Screen on
    At Selection-Screen on block
    At Selection-Screen output
    At Line-Selection
    At User-Command
    Start-of-Selection
    End-of-Selection
    Top-of-Page
    End-of-Page
    Top-of-Page during line-selection

    back to top

    How are RANGES different from SELECT-OPTIONS?

    They are the same, except SELECT-OPTIONS will provide an interface
    on the selection screen for the user to input data.

    back to top

    Are header lines and the OCCURS extension obselete?

    In regard to internal tables, header lines and the OCCURS extension are obselete. These are actually not allowed in the OO context. The correct way to define internal tables and work areas is to use a TYPE statement to define the structure and the table type and then to use a DATA statement to define the internal table and work area.

    types:
    begin of ty_Item,
    fld1 type c length 10,
    fld2 type c length 10,
    end of ty_Item,
    ty_Items type standard table of ty_Item with default key.
    data: itab type ty_Items.
    data: wa like line of itab.

    back to top

    What is the difference between OCCURS n and INITIAL SIZE n?

    OCCURS n is obsolete in OO Context and it is advisable to use INITIAL SIZE instead. The difference between the two is that OCCURS n allocates memory to store specified number of rows in the internal table and also creates a header line, whereas INITIAL SIZE allocates memory for the specified number of rows without creating the header line.

    back to top

    How do I define a deep structure in modern ABAP?

    TYPES:
    BEGIN OF ty_Message,
    count TYPE sy-tabix,
    bdc_Messages TYPE STANDARD TABLE OF bdcmsgcoll WITH DEFAULT KEY,
    END OF ty_Message,
    ty_Messages TYPE STANDARD TABLE OF ty_Message WITH DEFAULT KEY.
    DATA: all_Messages TYPE ty_Messages.

    One thing need to be clarified is there are 3 terms are often mixed up, 1. Nested Structure, 2. Deep Structure, 3. Flat Structure. According to official training material BC402, they are explained like following:1. Nested Structure: Structure contains other structure as component.2. Deep Structure: Structure contains variable length components (string / xstring), or even an internal table.3. Flat Structure: Structure only contains fixed-length components. back to top

    What is the difference between "'" and "`" in a character literal?

    A character sequence within single quote characters (') is a char literal, while within (`) is a string literal. That get´s especially important for trailing spaces. A string literal presveres the trailing space while a char literal ignores them.

    Eg.:

    DATA v_char TYPE c LENGTH 32.
    v_char = 'This is a'.
    CONCATENATE v_char 'text ' INTO v_char SEPARATED BY space.
    *" v_char would be "This is a text"
    CONCATENATE v_char `text ` INTO v_char SEPARATED BY space.
    *" v_char would be "This is a text "

    back to top

    How can I access parameters to MACROS?

    The parameters in MACROS can be accessed by &1, &2 ...

    DATA sum TYPE i.

    "Macro definition
    DEFINE add_macro.
    sum = *&1 + &2*.
    END-OF-DEFINITION.

    START-OF-SELECTION.
    add_macro 10 20.
    WRITE sum.

    back to top

    DATA DICTIONARY:FAQ`S

    What types of objects can be created in the ABAP Dictionary?

    Tables
    Views
    Data Elements
    Structures
    Table Types
    Type Groups
    Domains
    Search Helps
    Lock Objects

    back to top

    What types of tables can be created in the ABAP Dictionary?

    Transparent Tables
    Pooled and Clustered Tables

    back to top

    Which field differentiates a table from client-dependent and client-independent?

    The MANDT field of the table specifies whether the table is client independent or not.

    back to top

    What is the difference between Pooled tables and Cluster tables?

    Cluster tables and Pooled tables have many to one relationship with the underlying database.

    A table pool corresponds to a table in the database in which all records from the pooled tables assigned to it are stored.
    Several logical data records from different cluster tables can be stored together in one physical record in a table cluster.

    • A pooled table cannot have the name having more than 10 characters.
    • All the key fields of the pooled table must be of character data type.
    • In pooled tables, the maximum length of the key field/data fields should not exceed the length of varkey/vardata of the pool respectively.
    • In cluster table the records having the same key are stored in a single key in the cluster.
    • If there is an overflow of the data records a continuation record is created with the same table key.

    back to top

    What is the difference between Database tables and Views?

    The Table has a physical storage of data whereas views do not have physical storage of data.

    The view is derived from one or more tables which is created only with the required fields from the database table(s). It can also be created with table inner joins and specifying conditions for data retrieval.

    back to top

    What are the different types of Views?

    • Projection view - Just retrieves some fields from a single table.
    • Help View - This is used for search help.
    • Database View - This is inner join view of one or more tables
    • Maintenance View - Helps in creating maintaining data of the application object. The data can be distributed among several tables.

    back to top

    Can I use all the views in the ABAP program ?

    No. You can use only projection view or database view in your ABAP program.

    back to top

    What is Table Maintenance Generator?

    The Table Maintenance Generator is used to create table maintenance program to add, modify or delete records in the database table. This can be accessed using transaction SE54 or in SE11 using the menu Utilities->Table Maintenance Generator.

    back to top

    What is One step, two step in Table Maintenance Generator?

    This specifies the screens to be created in the Table Maintenance Program.

    Single step: Only overview screen is created i.e. the Table Maintenance Program will have only one screen where you can add, delete or edit records.

    Two step: Two screens namely the overview screen and Single screen are created. The user can see the key fields in the first screen and can further go on to edit further details.

    back to top

    How do you activate the database table after making changes to it?

    After making changes to the table, inorder to reflect the changes go to transaction SE14 and Choose Edit and then choose Activate and Adjust Database.

    OR

    You can directly activate it from the SE11.

    back to top

    In which table are the programs stored in?

    The programs are stored in the table TADIR and the development class packages in TDEVC.

    back to top

    I have recently added a few fields to a custom table. But I don't get these fields in the table maintenance program?

    You have to delete and recreate your own existing table maintenance program to see your new fields.

    back to top

    What is the difference between INSERT and MODIFY?

    Whenever you need to create new records in the database table use INSERT. Whenever using INSERT be sure that a duplicate entry having the same values for the primary key fields are not present. Else it may throw a dump.

    When you use MODIFY it makes a check for the matching key field values. If present it modifies the matching record, else it creates a new record in the database table.

    back to top

    How do I create index on a database table?

    Go to transaction SE11, open your database table. Choose the menu, Goto->Indexes to create index. Give your index name and choose the fields of the table. Be careful, an additional index may vanish with the next upgrade or hotpackage.

    back to top

    What is the difference between Check Table and Value Table?

    The Check Table is the dependent table to which the relationship is defined using foreign keys. The contents of the check table field are shown in the input help for the referenced field.

    The Value table is the table attached to a field at the domain level, where the entry to the field can be only from the value table. They are not used in the Input Help.

    back to top

    What is the difference between Domain and Data Elements?

    The Domain specifies the Technical attributes of the field such as the data type, length and the value range.

    The data element is an elementary type defining the description/text for the field when displaying on the screen and Parameter ID.

    back to top

    When I create new entries in the table the field values are always in Uppercase. How do I get the data with mixed case?

    The reason for this is that the Domain for the field in the table might have Lowercase checkbox unchecked. Check the Lowercase checkbox to preserve the case of your data.

    back to top

    What is the need of reference table and reference field in Currency/Quantity fields?

    The reference table and reference field are the fields which specify the currency key or Unit of Measure. Suppose if the user specifies a currency amount say 1000$, the currency amount field would indicate the amount 1000 and the currency key indicates that the currency specified is in Dollars.

    back to top

    General: FAQ`S


    What is this new transaction 'n' all about?

    It is actually a quickstart transaction for se16n.

    Back to Top

    What does ABAP stand for?

    ABAP currently stands for Advanced Business Application Programming; however the original meaning was Allgemeiner Berichtsaufbereitungsprozessor, which is German for "generic report preparation processor"
    A different explanation is Anfänger Basteln An Programmen, which is german for "beginners tinker with programs"

    It is a structured language like C.

    Back to top

    How are RANGES different from SELECT-OPTIONS?

    They are the same, except SELECT-OPTIONS will provide an interface
    on the selection screen for the user to input data.

    Back to top

    How to convert a date to internal or external format?

    Use the functions modules CONVERT_DATE_TO_EXTERNAL or CONVERT_DATE_TO_INTERNAL
    to convert the date. When converting to external format, the date format from the user's user profile will be used. When converting to internal format, the result will be in YYYYMMDD format.

    Back to top

    How do I download data in my internal table in a CSV file?

    Use the Function Module SAP_CONVERT_TO_CSV_FORMAT to convert the internal table into Comma seperated format then download this internal table using the Function Module GUI_DOWNLOAD.

    See a sample program below:

    TYPE-POOLS: truxs.
    TYPES:
    BEGIN OF ty_Line,
    vbeln LIKE vbap-vbeln,
    posnr LIKE vbap-posnr,
    END OF ty_Line.
    ty_Lines TYPE STANDARD TABLE of ty_Line WITH DEFAULT KEY.
    DATA: itab TYPE ty_Lines.
    DATA: itab1 TYPE truxs_t_text_data.

    SELECT
    vbeln
    posnr
    UP TO 10 ROWS
    FROM vbap
    INTO TABLE itab.

    CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
    EXPORTING
    i_field_seperator = ';'
    TABLES
    i_tab_sap_data = itab
    CHANGING
    i_tab_converted_data = itab1
    EXCEPTIONS
    conversion_failed = 1
    OTHERS = 2.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    filename = 'C:\TEMP\test.txt'
    TABLES
    data_tab = itab1
    EXCEPTIONS
    OTHERS = 1.

    Back to top

    How can I get the IP address of the system programmatically?

    You can use cl_gui_frontend_services to get the system IP address.

    DATA ip_addr TYPE c LENGTH 50.
    CALL METHOD cl_gui_frontend_services=>get_ip_address
    RECEIVING
    ip_address = ip_addr
    EXCEPTIONS
    cntl_error = 1
    error_no_gui = 2
    not_supported_by_gui = 3
    OTHERS = 4.
    DATA terminal LIKE USR41-TERMINAL.
    CALL FUNCTION 'TERMINAL_ID_GET'
    EXPORTING
    USERNAME = sy-uname
    IMPORTING
    TERMINAL = terminal.

    Back to top

    How can I download my internal table into an Excel file?

    Use the function module SAP_CONVERT_TO_XLS_FORMAT to download the internal table to an excel file.

    PARAMETERS: p_file LIKE rlgrap-filename DEFAULT 'c:\tmp\test.xls'.
    DATA: t100_Lines TYPE STANDARD TABLE OF t001 WITH DEFAULT KEY.

    SELECT * FROM t001 INTO TABLE t100_Lines.

    CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
    EXPORTING
    i_filename = p_file
    TABLES
    i_tab_sap_data = t100_Lines.

    Or get much more control by creating an XML file

    Back to top

    How can I read an Excel file from presentation server?

    You can use the Function module ALSM_EXCEL_TO_INTERNAL_TABLE to read the Excel file into the internal table of type alsmex_tabline. From this internal table you can fill the target internal table.

    TYPES:
    BEGIN OF ty_upload,
    field1 TYPE c length 12,
    field2 TYPE c length 12,
    field3 TYPE c length 12,
    END OF ty_upload.
    DATA it_upload TYPE STANDARD TABLE OF ty_upload WITH DEFAULT KEY.
    DATA wa_upload TYPE ty_upload.
    DATA itab TYPE STANDARD TABLE OF alsmex_tabline WITH DEFAULT KEY.
    FIELD-SYMBOLS: <wa> type alsmex_tabline.

    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
    filename = filename
    i_begin_col = 1
    i_begin_row = 1
    i_end_col = 3
    i_end_row = 65535
    TABLES
    intern = itab.

    LOOP AT itab ASSIGNING <wa>.
    CASE <wa>-col.
    WHEN '0001'.
    wa_upload-field1 = <wa>-value.
    WHEN '0002'.
    wa_upload-field2 = <wa>-value.
    WHEN '0003'.
    wa_upload-field3 = <wa>-value.
    ENDCASE.
    APPEND wa_upload TO it_upload.
    CLEAR wa_upload.
    ENDLOOP.

    Back to top

    How can I convert numerals into the corresponding text?

    Use the Function Module SPELL_AMOUNT to convert the integer into text.

    DATA v_int TYPE i VALUE '1000'.
    DATA words LIKE SPELL.

    CALL FUNCTION 'SPELL_AMOUNT'
    EXPORTING
    AMOUNT = v_int
    LANGUAGE = SY-LANGU
    IMPORTING
    IN_WORDS = words
    .
    WRITE words-word.

    Back to top

    I am using a SELECT query on a database table. Since the number of records in the table is very large, the program dumps due to insufficient memory. How can I solve this?

    In this case you could use the PACKAGE SIZE addition in the SELECT query to process in limited amount of data, thus avoiding the memory overloads.

    Eg:

    SELECT *
    FROM <table>
    INTO TABLE itab
    PACKAGE SIZE <n>.

    IF sy-subrc EQ 0.
    *" Process the n records
    ENDIF.

    ENDSELECT.

    Back to top

    How can I import and export my ABAP developments?

    SAPlink is an opensource community project that makes it easy to share ABAP developments between programmers. It provides the ability to easily distribute and package custom objects.

    Back to top

    Where are the long texts of a document stored and how to access the same?*

    The long texts of a document are stored in a encrypted format in the STXH and STXL tables, where STXH stores the header information of the long text like TDOBJECT, which indicates which text object the long text belongs to, TDID which indicates the Text ID and TDNAME which is the actual name of the long text.

    As these texts are stored in a encrypted format, the text cannot be read using a SELECT statement. You will have to use the function READ_TEXT. The easiest way of getting to know the parameter values is to go to a document, open the long text in a full screen mode. For example, when you wan to see the long text for a Purchase order, go to transaction ME23n. Assume, you want to see the parameters for the Header Text. In the first Tab Strip Control, click on the Texts tab and select the Header Text node on the left hand side, which will display the text on the right hand side. Now, double click on the text editor on the right hand side. This will open the text in the full screen mode. In the menu Go To --> Header, you should be able to see the values for all the three parameters we discussed above. We will have to do the same thing for whichever text parameters we want to see.

    CALL FUNCTION 'READ_TEXT'
    EXPORTING
    * CLIENT = SY-MANDT
    ID =
    LANGUAGE =
    NAME =
    OBJECT =
    * ARCHIVE_HANDLE = 0
    * LOCAL_CAT = ' '
    * IMPORTING
    * HEADER =
    TABLES
    LINES =
    * EXCEPTIONS
    * ID = 1
    * LANGUAGE = 2
    * NAME = 3
    * NOT_FOUND = 4
    * OBJECT = 5
    * REFERENCE_CHECK = 6
    * WRONG_ACCESS_TO_ARCHIVE = 7
    * OTHERS = 8
    .
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    Back to top

    How do I create a long text for a document?*

    Please refer to the important parameters that are discussed in the previous question of reading texts. We will need the same parameters for saving the text as well. The function modules that you can use for this will be SAVE_TEXT followed by COMMIT_TEXT. The parameters play a very important roles as you might not see the saved text in the standard transaction if you give wrong parameter values.

    CALL FUNCTION 'SAVE_TEXT'
    EXPORTING
    * CLIENT = SY-MANDT
    HEADER =
    * INSERT = ' '
    * SAVEMODE_DIRECT = ' '
    * OWNER_SPECIFIED = ' '
    * LOCAL_CAT = ' '
    * IMPORTING
    * FUNCTION =
    * NEWHEADER =
    TABLES
    LINES =
    * EXCEPTIONS
    * ID = 1
    * LANGUAGE = 2
    * NAME = 3
    * OBJECT = 4
    * OTHERS = 5
    .
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    CALL FUNCTION 'COMMIT_TEXT'
    * EXPORTING
    * OBJECT = '*'
    * NAME = '*'
    * ID = '*'
    * LANGUAGE = '*'
    * SAVEMODE_DIRECT = ' '
    * KEEP = ' '
    * LOCAL_CAT = ' '
    * IMPORTING
    * COMMIT_COUNT =
    * TABLES
    * T_OBJECT =
    * T_NAME =
    * T_ID =
    * T_LANGUAGE =
    .

    Back to top

    How do I display / add the Terms and Conditions to the business document?

    I would suggest that you create separate SMART Form for the Terms and conditions and call that right after the PO main smart form. It gives the flexibility in calling the same smart form for other documents also, as generally these are the same Terms and Conditions for all the documents that a company uses.

    We can have the Terms and Conditions stored as long texts in SO10 (Standard Text, TDOBJECT - TEXT and TDID - ST and TEXTNAME - Whatever name you want to give). This way if you want to change the text, its easy to change and you can transport the changes using program RSTXTRAN.

    We have a text element in the smart form, and the general attributes of the text change the type to "Include Text". This will change the screen and you should be able enter the parameter values of Object, ID and name.

    This will automatically print the entire long text on the smart form, we just need to make sure that this is a part of the main window of the smart form as the text might run into multiple pages.

    Back to top

    How to convert from one currency value to other?

    We can Use the Following Function Module to convert from one Currency vale to other
    In following function module we need to pass Foreign currency, Local Currency type_rate:Type of rate M=Average rate G=Bank buying rate B=bank selling rate

    We Get Exchange rate for that day, foreign factor, Local factor.
    And Foreign currency can be calculated as below mentioned in IF ENDIF

    DATA: l_er TYPE tcurr-ukurs, "
    l_ff TYPE tcurr-ffact,
    l_lf TYPE tcurr-tfact,
    l_erate(12) TYPE c,

    CALL FUNCTION 'READ_EXCHANGE_RATE'
    EXPORTING
    date = sy-datum
    foreign_currency = wa_bseg-pswsl
    local_currency = c_euro
    type_of_rate = 'M'
    IMPORTING
    exchange_rate = l_er
    foreign_factor = l_ff
    local_factor = l_lf
    EXCEPTIONS
    no_rate_found = 1
    no_factors_found = 2
    no_spread_found = 3
    derived_2_times = 4
    overflow = 5
    OTHERS = 6.
    IF sy-subrc = 0.
    l_erate = l_er / ( l_ff / l_lf ).
    wa_itab-wrbtr = wa_itab-wrbtr * l_erate.

    ENDIF.

    Back to top

    How do I send e-mail?

    There are several methods to accomplish this:

    Sending E-Mail from ABAP - Version 610 and Higher - BCS Interface
    Sending E-Mail from ABAP - Version 46D and Lower - API Interface
    BCS interface in BSPs
    Develop a Web Service that sends an Email - in ABAP, Netweaver 04S

    Back to top

    How do I receive and process e-mail?

    Receiving E-Mail and processing it with ABAP - Version 610 and Higher

    Back to top

    How do I generate PDFs?

    BSP/HowTo: Generate PDF Output (from a BSP)

    Back to top

    ABAP:ABAP General

    How to change the deadline of the workitem programmatically in SAP?

    Following code is used to changes the deadline of any work item which is in WAITING state. The FMs needs the input like the object type for which the workflow has executed, the workflow ID to which the workitem belongs and the Task id of the standard task which is executed and in waiting state.

    DATA: lit_deadline TYPE TABLE OF swwdeadlin,
    lt_workitem TYPE TABLE OF swr_wihdr,
    lt_rel_wi TYPE TABLE OF swwwihead,
    w_workitem TYPE swr_wihdr,
    w_rel_wi TYPE swwwihead,
    w_deadline TYPE swwdeadlin,
    l_objkey TYPE swo_typeid,
    l_retcode TYPE sy-subrc.
    * Retrieve the work items executed for desired Object type
    CALL FUNCTION 'SAP_WAPI_WORKITEMS_TO_OBJECT'
    EXPORTING
    objtype = l_objtype
    objkey = l_objkey
    top_level_items = space
    selection_status_variant = '0001'
    IMPORTING
    return_code = l_ret_code
    TABLES
    worklist = lt_workitem.
    * Select the workitems executed for particular Workflow.
    SORT lt_workitem BY wi_rh_task wi_stat.
    READ TABLE lt_workitem
    INTO w_workitem
    WITH KEY wi_rh_task = 'WS91001143'
    wi_stat = 'STARTED'
    BINARY SEARCH.
    * Select the dependent workitems of 'WS91001143'.
    CALL FUNCTION 'SWI_GET_DEPENDENT_WORKITEMS'
    EXPORTING
    wi_id = w_workitem-wi_id
    TABLES
    dependent_wis = lt_rel_wi.
    * Select the workitems for which the deadline needs to be changed.
    SORT lt_rel_wi BY wi_rh_task wi_stat.
    READ TABLE lt_rel_wi
    INTO w_rel_wi
    WITH KEY wi_rh_task = 'TS91001414'
    wi_stat = 'WAITING'
    BINARY SEARCH.
    * Update the deadline of the waiting task.
    w_deadline-wi_dattype = 'DS'.
    w_deadline-wi_date = l_new_date.
    w_deadline-wi_time = '000001'.
    APPEND w_deadline TO lt_deadline.
    CALL FUNCTION 'SWW_WI_DEADLINES_CHANGE'
    EXPORTING
    wi_id = w_rel_wi-wi_id
    do_commit = 'X'
    TABLES
    deadline_attributes = lt_deadline
    EXCEPTIONS
    no_authorization = 1
    invalid_type = 2
    update_failed = 3
    invalid_status = 4
    OTHERS = 5.
    if sy-subrc <> 0.

    endif.

    Back to top

    When selection screen-screen output will use?

    Mostly selection screen will use for Repoting purpose.We can give range of inputs or particulat input or single input by selection screen.



    Smartforms: Frequently Asked Questions

    Smartforms: Frequently Asked Questions

    What are the differences between SAP Scripts and Smartforms?

    • SAP Scripts are client dependent whereas Smartforms are client independent.
    • SAP Scripts require a driver program to display the output whereas n smartforms the form routines can be written so that it is standalone.
    • An integrated Form Builder helps to design Smartforms more easily than SAP Scripts
    • An Table Painter and Smartstyles to assist in building up the smartforms
    • On activation a function module is generated for Smartforms
    • It is possible to create a Smartform without a main window
    • Smartforms generates XML output which can be viewed through the web
    • Multiple page formats is possible in smartforms

    How can I insert symbols in Smartforms?

    Select the Text node.
    Change Editor (Click the button above Check near the Editor)
    Go to menu Include->Characters->SAP Symbols
    Choose the SAP symbol that you want to insert.

    I have a smartform which works fine in DEV. After trasnsporting it to PROD, there is no Function module generated for this smartform. As a result my program dumps in PROD?

    The Smartform that is created in the Development may not have the same name in the Production server. So it is always advised to use the Function Module SSF_FUNCTION_MODULE_NAME to get the Function Module name by passing the Smartform name.

    DATA: fm_name TYPE rs38l_fnam.

    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
    formname = 'ZSMARTFORM'
    IMPORTING
    fm_name = fm_name
    EXCEPTIONS
    no_form = 1
    no_function_module = 2
    OTHERS = 3.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

    CALL FUNCTION fm_name
    EXCEPTIONS
    formatting_error = 1
    internal_error = 2
    send_error = 3
    user_canceled = 4
    OTHERS = 5.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

    How can I make the Smartforms to choose a printer name by default?

    In the CALL FUNCTION of the Smartform Function Module, set the output options parameter to set the printer name.

    The output options is of the type SSFCOMPOP which contains the field TDDEST. Set the TDDEST field to your default printer name.

    How can I make the Smartforms to display a print preview by default without displaying the popup for print parameters?

    In the SSF_OPEN function module,
    Set the OUTPUT OPTIONS paramter TDDEST to your printer name.
    Set the CONTROL PARAMETERS and control parameters as shown below,

    control-preview = 'X'.
    control-no_open = 'X'.
    control-no_close = 'X'.
    control-no_dialog = 'X'.
    control-device = 'PRINTER'.
    control_parameters-no_dialog = 'X'.
    control_parameters-no_open = 'X'.
    control_parameters-no_close = 'X'.
    OUTPUT_OPTIONS-TDDEST = 'PRINTER NAME'.
    OUTPUT_OPTIONS-TDNOPRINT = 'X'.

    CALL FUNCTION 'SSF_OPEN'
    EXPORTING
    output_options = output_options
    control_parameters = control
    user_settings = ' '
    EXCEPTIONS
    formatting_error = 1
    internal_error = 2
    send_error = 3
    user_canceled = 4
    OTHERS = 5.

    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

    How can I display the total number of pages in Smartforms?

    Use SFSY-FORMPAGES to display the total number of pages in the Smartforms

    &SFSY-PAGE& Current page number
    &SFSY-FORMPAGE& Total number of pages in the currently formatted layout set
    &SFSY-JOBPAGE& Total number of pages in the currently formatted print request
    &SFSY-COPYCOUNT& Original-1,1st copy-2
    &SFSY-DATE& Date
    &SFSY-TIME& Time
    &SFSY-USERNAME& Username

    I'm using the variable SFSY-FORMPAGES, I get a star "*" instead of the total number of pages.

    There may not be enough space in the window to display the variable, either increase the window dimensions or condense the spaces using &SFSY-FORMPAGES(C)&

    What are the various text formatting options in Smartforms?

    &symbol(Z)& Omit Leading Zeros
    &symbol(S)& Omit Leading Sign
    &symbol(<)& Display Leading Sign to the Left
    &symbol(>)& Display Leading Sign to the Right
    &symbol(C)& Compress Spaces
    &symbol(.N)& Display upto N decimal places
    &symbol(T)& Omit thousands separator
    &symbol(R)& Right justified
    &symbol(I)& Suppress output of the initial value

    How can I provide a background shading to the table?

    In the Table Painter, you can specify the color and shading for the table lines.

    Where can I provide the input parameters to the smartform?

    The input parameters for the smartform can be defined in Global Settings->Form Interface.
    The Associated Type must be defined in the ABAP Dictionary.

    Where can I define my own global types for the smartform?

    The global types(within the smartform) can be defined in Global Settings->Global Definitions->Types
    The types defined here will be global through the entire smartform.
    Also the form routines can be defined Global Settings->Global Definitions->Form Routines

    I have defined my own Program Lines, where I have used a global variable G_TEXT. I get an error G_TEXT is not defined?

    Whenever using the global variables in the Program Lines, enter the variable name in Input Parameters if you are going to use(read) the variable. If you are going to both read/write the variable value enter the same in Output Parameters.

    I have created a table node for display. Where can I check the condition which must satisfy to display the table?

    The conditions can be defined in the Conditions tab. In smartforms all the nodes have a condition tab where you can specify the condition to be satisfied to access the node.

    How can I define Page Protect in Smartforms?

    To define Page Protect for a node go to the Output options and check the Page Protection checkbox.

    What is the difference between Template and Table in Smartforms?

    The Template contains a fixed number of rows and columns, where the output is fixed.
    The Table can have variable number of rows

    Where can I define the paragraph and character format for the smartforms?

    The paragraph and character format for the smartforms can be defined in the transaction SMARTSTYLES

    How to add watermark to smartform output?

    Go to the properties of 'PAGE', tab 'Background Picture'. Add the grapic image name here.

    SAPScripts: Frequently Asked Questions



    SAPScripts: Frequently Asked Questions

    How do I create Boxes in SAPScript?

    You can create Boxes in the SAPScript using the BOX command specifying the x,y co-ordinates and the width and the height

    BOX XPOS '0' CM YPOS '0.5' CM WIDTH '9.2' CM HEIGHT '3.5' CM FRAME 8 TW

    How do I set tabs between the fields in display?

    In the Paragraph Format tab, create a new paragraph format. In the "Tabs" Tab, enter the tab position and the alignment for the fields.

    How do I create standard texts for the scripts?

    You can create standard texts using the transaction SO10. Then to insert these standard texts in the SAPScript choose the menu, Insert->Text->Standard and choose the standard text that you want to choose.

    Alternatively, you can display standard texts in your SAP Scripts using the command:
    INCLUDE ZSTEXT OBJECT TEXT ID ST LANGUAGE EN

    • where ZSTEXT refers to the Standard Text name.

    How can I debug my SAPScript?

    Go to the transaction SE71.
    Enter the form name.
    Choose the menu Utilities->Activate Debugger to enable debugging.

    I have created a script in language DE. Now I need to translate it to EN. How could I do this?

    Open your script in transaction SE71.
    In the Header screen, in the Language Attributes Option, choose Translate to... Option to translate to other languages.

    How can I Word Wrap the text being displayed in SAPScript?

    Use the Function Module RKD_WORD_WRAP to wrap the text and use this for output.

    How can I display barcodes in SAPScripts?

    Create a character format in the SAPScript.
    Choose the Bar Code for the character format.

    And finally to display barcodes, in the command enter:

    &vbeln&
    • where C1 is the character format created and vbeln is the variable for which the barcode is to be created.

    How can I print logos in SAPScripts?

    1. Convert the logo to a TIFF(*.tif) file.
      • Use the program RSTXLDMC to convert the TIFF file to standard text.
      • Print this using the INCLUDE command:
      • INCLUDE ZLOGO OBJECT TEXT ID ST
    2. For bitmaps (*.bmp)
      • Go to transaction SE78
      • Choose BMAP under GRAPHICS
      • Choose Import Graphic (F5)
      • Select the image and upload
      • In SE71 choose Insert->Graphics and then choose the image for display

    How can I copy SAPScripts from one client to another?

    In the transaction SE71, enter the Form name and choose the menu, Utilities->Copy from client to copy SAPScripts from one client to another.

    Use RSTXSCRP to import/export SAPScripts.

    How can I trigger new page in SAPScripts?

    Use the command NEW-PAGE to trigger a new page in SAPScript.

    How can I prevent page-break in the message that is to be displayed?

    Enclose the text that you want to prevent page-break in PROTECT... ENDPROTECT
    SAPscript will ensure that each line of this text is printed together on the same page.

    /: PROTECT
    * Text
    * Within
    * The same page
    /: ENDPROTECT

    How can I set the position of the leading sign to left/right?

    You can use the SET SIGN command to output the leading sign at the left or right.

    /: SET SIGN LEFT

    /: SET SIGN RIGHT

    What are the various text formatting options in SAPScript?

    &symbol(Z)& Omit Leading Zeros
    &symbol(S)& Omit Leading Sign
    &symbol(<)& Display Leading Sign to the Left
    &symbol(>)& Display Leading Sign to the Right
    &symbol(C)& Compress Spaces
    &symbol(.N)& Display upto N decimal places
    &symbol(T)& Omit thousands separator
    &symbol(R)& Right justified
    &symbol(I)& Suppress output of the initial value

    Frequently Used System Variables in SAPScript?

    &DATE& Currentdate
    &DAY& Day
    &MONTH& Month
    &YEAR& Year
    &TIME& Time of the day
    &HOURS& Hours
    &MINUTES& Minutes
    &SECONDS& Seconds
    &PAGE& Page
    &NEXTPAGE& Next page number
    &SPACE& Blank
    &ULINE& Underline
    &VLINE& Vertical line
    &NAME_OF_MONTH& Name of the Month
    &SAPSCRIPT-FORMPAGES& Total number of pages in currently formatted layout set
    &SAPSCRIPT-JOBPAGES& Total number of pages in currently formatted print request

    What are the different types of windows in SAP Scripts?

    Windows are defined in the Layout sets which define the position and the text to displayed.

    The different types of windows are:

    • MAIN - Main Window
      The main window is a continous window which can extend over several pages. If the text in the main window fills up a page, a new page is created.
      Only one main window can be defined in the SAP Script whereas upto 100 instances of main window can be created in a page.
    • VAR - Variable Window
      This window can have the variable contents displayed on them. The contents of the window cannot exceed the window size. The content can be formatted for each page.
    • CONST - Constant Window
      The constant window can have a fixed content and is formatted only once.

    How can I format the date being displayed in the SAP Script?

    The date fields in SAP Scripts can be formatted using the SET DATE MASK control command.
    Eg.:
    /: SET DATE MASK = 'MMMM DD, YY'
    This displays the date as : September 26, 07

    The following are the codes that can be used in the date mask:

    YY Year (2 digits)
    YYYY Year (4 Digits)
    MM Month (2 Digits)
    MMM Month Name (Abbreviated)
    MMMM Month Name (Full)
    DD Day as two digits
    DDD Day name (Abbreviated)
    DDDD Day name

    Using the SET DATE MASK causes the subsequent date fields to be displayed using the same formatting. To return to the default formatting use the following command:
    /: SET DATE MASK = ' '

    How can I format the time in the SAP Script?

    Similar to SET DATE MASK for date fields we can use SET TIME MASK for formatting time fields.
    Eg.:
    /: SET TIME MASK = 'HH hrs MM min SS sec'
    This displays the time as : 11 hrs 43 min 37 sec'

    The following are the codes that can be used in the time mask:

    HH Hours
    MM Minutes
    SS Seconds

    The time formatting can be reset to the default setting using:
    /: SET TIME MASK = ' '

    How can I apply shading for the BOXes in SAP Script?

    Use the addition INTENSITY in the BOX command to apply gray shading to the boxes.
    Eg:
    BOX XPOS '0' CM YPOS '0.5' CM FRAME 8 TW INTENSITY 10

    What is the difference between the SAP Script texts, 'Customer &KNA1-KUNNR&' and '&Customer KNA1-KUNNR&'?

    In the first case of 'Customer : &KNA1-KUNNR&',
    the text 'Customer : ' is displayed regardless of the variable KNA1-KUNNR even if it is having Initial value.

    In the second case of '&Customer : KNA1-KUNNR&',
    The text 'Customer :' and KNA1-KUNNR is displayed only when the variable KNA1-KUNNR has non-initial values.

    How can I change the page size of the layout?

    In the SAP Script, Goto -> Header -> Basic Settings
    Here you could configure the page settings and their orientation.

    How can I set the header and footer in the main window?

    The TOP...ENDTOP and BOTTOM...ENDBOTTOM commands are used to set the header and footer texts in the main window respectively.
    These texts will be displayed on the start and end of every new page in the output.

    To disable these texts enclose empty commands between the commands.
    Eg.:
    /: TOP
    /: ENDTOP

    What the conditional statements used in SAP Scripts?

    The following conditional statements are used in SAP Scripts:

    • IF..ELSE...ENDIF
    • CASE...ENDCASE

    What is the use of the POSITION and SIZE command in SAP Scripts?

    The POSITION command is used to x, y coordinate position which is used by the BOX command. The offset from the current window positions are specified which could be either positive or negative.
    /: POSITION XORIGIN YORIGIN WINDOW PAGE

    Eg.:
    /: POSITION XORIGIN '2' CM YORIGIN '-1.5' CM

    Similarly the SIZE command sets the width and height parameters.
    /: SIZE WIDTH HEIGHT WINDOW PAGE

    Eg.:
    /: SIZE WIDTH 10 TW HEIGHT 10 TW

    How to find the Driver Program for the given SAPscript ?

    Step:1: Goto to the Table TNAPR using SE11

    Step:2: Get the Contents of the Table(CNTRL+SHIFT+F10)

    Step:3: On the Table Content Selection Screen, Type the SAPScript Name for which we have find the Driver Program in the field FONAM and execute(F8)

    Step:4: PGNAM field of the result display contains the Driver Program Name for our SAPscript