Friday, April 12, 2013

One stop answers

1. The types of tables in SAP?
  1. Transparent table
  2. Pooled table
  3. Cluster table
Pooled and cluster tables are generally used when large volumes of data needs to be stored. This tables are primarily used by SAP. These tables are used to improve performance in scenarios where same kind of tables or tables with same primary key fields are grouped together because SAP extraction becomes easy.
Pool and cluster tables are the tables that are assigned to table pool and cluster pools.
SE11->Utilities->Other dictionary objects->Select radio button cluster/pool name and give a pool name->give the tabname and varkey lengths and data type->save and activate.
Now goto SE11->create a ztable and choose table category option from the menu and choose table type as pooled table-> in delivery maintenance option in technical settings give pool/cluster name.
This is how a pool table is created.

2. Is there a way to set up a sequence to the implementations of a multiple-use BADI?

BADI_SORTER is the answer.  Create a new implementation to this BADI. Now for this BADI set up a filter with the field being BADI_NAME and the value being the name of the BADI you want to set up the sort sequence for. Implement the method IF_BADI_SORTER according to your sort criterion.

3. What is a dynamic internal table and its advantages?

A dynamic internal table is used when the number or rows required are decided only at runtime.
Advantages:
1. Very flexible
2. Avoids Redundancy
Some of the important attributes of an internal table which can be set dynamically are
  • Column position
  • Field name of internal table field
  • Column width
  • Reference field
  • Reference table
  • Data type of the fields
  • Domain name of the fields
  • Check table
4. What are field symbols?

Field symbols are like the pointers in C. They are direct pointers to the address of the value in a field. These are very much useful in performance improvement.
Field symbols can be used inside the loop too. And are particularly useful in the append statements to avoid declaring extra work areas.
Ex:
<fs_1>-name = gv_name.
<fs_1>-num = gv_num.
append <fs_1> to gt_num.

Field symbols are also useful in extracting data from other programs.
Identify the program which  can give you your desired value.
gv_val = (PROGRAM)evbak-vbeln.
ASSIGN gv_val to <fs_1>.
gv_val1 = <fs_1>.
Here gv_val is a variable of type char and gv_val1 is of the required field type or table type. Since field symbol can be of any type it will automatically take the field or the table type when the value is assigned to it. Hence gv_val1 which is of the exact field type or table type could accept the data from the field symbol.

5. What is a Update function module?
Update function modules are necessary when you want a certain part of your program to run after DB updates. That is, lets say your program is updating a DB after a particular occurrence and as soon as the DB updates you want a indicator to be set for further processing, in this case you can use a update function module which will run only after a COMMIT WORK appears.
Syntax: CALL FUNCTION 'func' IN UPDATE TASK
            Exp
When the compiler sees this statement, it wont go into the function module to execute it but skips and goes to the next line of code. At the end of the program when it sees the COMMIT WORK statement all the update tasks begin to execute.
To function module to run in update task the process type of the function module should be set to one of the below -
Update with immediate start
Update with immediate start and no restart
Update with delayed start.

6. What is a LUW?
A logical unit of work is an inseparable sequence of DB actions that either must be fully completed or completely rolled back. They are those sequence of actions that together form one business transaction. Also in other words its the span of time during which 2 DB operations are performed. It is primarily useful in keeping the DB integrity.
There are 3 types of LUW -
DB transaction which is otherwise called LUW -
Its the time between the operation initiated must be either completed as a unit or no operation should happen. When we are talking of LUW it generally is because of the implicit COMMIT WORK statements.
Update transaction which is also call the SAP LUW -
SAP LUW is a bundle of different LUWs. To avoid errors SAP bundles all the LUWs into a single LUW and commits them in a single go to the DB. Generally an SAP LUW ends with an explicit COMMIT WORK statement.

7. What is SAP memory and ABAP memory?
SAP memory is like the global data which all the main sessions have access to. To extract data from SAP memory use SET/GET parameters.
SET PARAMETER ID ' ' field ' ',
CALL TRANSACTION ' ' .
ABAP memory is the local data. It is the memory that all the programs within the same internal session can access using the EXPORT and IMPORT statements.
Ex: During a particular execution of a program or a transaction, two exits are being called. You want to use a value from exit1 in exit2. So in exit1 you can use a EXPORT statement to a memory id and import the same from the same memory id in exit2. Here you are the local ABAP memory.

8. Transport request TCodes?
To organize transport requests SE09 , SE10
To move TRs from one client to other SCC1.

9. How to debug a background job?
Go to SM37, select your job and in the transaction screen give /JDBG. Make sure you put a breakpoint in your program. The compiler will stop in your program at the breakpoint.
Note: This debugging will only help you to traverse through your program for the previously ran test data. Particularly useful to find out the reason for a job cancel.

10. Difference between CLEAR, REFRESH and FREE?
CLEAR: This statement clears the workarea
REFRESH: Clears the internal table contents.
FREE: Clears the contents and also frees the allocated memory to the table.





 

Monday, April 8, 2013

Understanding RICEFW - Interfaces

Interface programming is responsible of making SAP communicate with external systems. 
How does SAP do this?
1. File Interface for reading and writing files.
2. RFC
3. BAPI
4. ALE & EDI

File system:
This is a good way to exchange data between 2 systems. The legacy system writes data to a file, this file is transported into the target SAP system, the target system reads the data in the file and writes it to the DB.  SAP has many such importing programs like -
CALL TRANSACTION:
How do you use one?
CALL TRANSACTION <TCODE>
USING <BDC_TAB>
MODE <MOD>
UPDATE<UPDATE>
MESSAGES INTO <TABLE>

1. Prepare a DB table with bdcdata specific to the transaction
<bdc_tab>-prognam
<bdc_tab>-dynpro
<bdc_tab>-dynbegin
 append <bdc_dat>

2. MODE can be A, N, E. Where in you can mention how you want the data transfer process be displayed.
A - Display All (All screens and the data)
N - No display (Even if there are errors, the screens are processed invisibly)
E - Display only errors.

3. UPDATE
A - Asynchronous - COMMIT WORK
S - Synchronous - COMMIT WORK AND WAIT
L - Local - SET UPDATE TASK LOCAL

BATCH INPUT:
The main advantage of batch input is the controlling and correction of errors.
BDC Programming is the batch interface technique in sap. But the batch input is little slower compared to the call transaction. The batch input is especially advantageous when transferring large amounts of data.
SHDB is the transaction, to perform a session recording.

RFC:
The ABAP function modules can be called from external systems using the RFC function protocol.
All the parameters in an RFC must be referenced to the ABAP dictionary and all of them must be passed by value. From version 6.0 RFCs also include changing parameters. The destination parameter is the one which lets the rfc function modules be called from other external systems. To create a destination use the tcode SM59.

BAPI:
Business Object (BO) gives an object oriented view of the business data and transactions. A BOR consists of the object types of these BO. To maintain a BOR SW0 and SW01 are to be used. The methods of some object types are identified as BAPI, and BAPIs are commonly used for RFC purposes.
The reason why BAPIs amongst all the methods of BO types have become so famous is
BAPIs have stable interface, meaning the interface is not changed by any new release of SAP.
BAPIs do not trigger exceptions, they only give return parameters.
DBs are updated in an update task, meaning BAPIs perform updates by calling an update module  CALL FUNCTION IN BACKGROUND TASK. A commit work or a rollback work is not committed in a BAPI.

EDI:
EDI is used for exchanging data between 2 systems for which an IDOC structure is required. An IDOC consists of DATA, CONTROL and STATUS records.
ALE is also a similar technology, but it is used to transfer data internally, but if it is data transfer between SAP and an external system EDI is the one which is generally preferred.
IDOC:
To create segments - WE31
To create IDOC - WE30
Create or assign message type - WE81/WE82
Partner profile set up - WE20

RSNAST00 program is used when batch input process is set.
Ex: In a sales order output the processing mode should be set to 1 and not to 4 which is immediate processing. RSNAST00 program picks up all the outputs whose processing mode is set to 1 from the NAST table and executes the data and gives an outbound idoc.

CHANGE POINTERS:
It is the process in SAP which triggers every time there is a change in the master data. Change pointer is something similar to the CDPOS and CDHDR.
BD50- Activate change pointer in a message type
BD52- Create change document item
BD61- Activate change pointer globally
Change pointers are captured in table BDCPS and BDCP
BD20 - To create IDOC from change pointers. (Report RBDMIDOC)
BD20 - To delete change pointer entries.

Sunday, April 7, 2013

Understanding RICEFW - Reports

Learning RICEFW is essentially learning the technical part of SAP.

R ->  Reports
I  ->  Interfaces
C ->  Conversions
E ->  Extensions
F ->  Forms
W-> Workflows
 
Important concepts of each of these 6 categories.
 
Reports:
Reporting is used so that large amount of consolidated data which is essentially stored in multiple tables can be viewed in one go based on any selection criteria one might need.
Reports are executable programs, meaning in SE38 when you are creating a program,  
select the program type as Executable program.
 
SAP provides as basic as the write statements letting one program their own reports to as advanced as direct function modules which when fed by the respective input internal table will display the report.
 
The various function modules that we have for reporting are
- REUSE_ALV_LIST_DISPLAY - This displays the output in the format of an ALV LIST
- REUSE_ALV_GRID_DISPLAY - This displays the output in the format of an ALV GRID
- REUSE_ALV_GRID_DIPLAY_TREE - For when information is needed to be displayed in the form of tree.
 
The same can be done in OOPS, where in there are many methods to perform the same functionalities like the SET_TABLE_FOR_FIRST_DISPLAY in the class CL_GUI_ALV_GRID.
 
SAP also supports interactive reporting, where in navigation can be done between the report output and its details screen (Details screen meaning, if the user clicks on a particular line of the report a new report opens up with the respective details as per requirement. Ex: Consider in a particular report user clicks on the field sold-to-party on a row, then another screen appears giving details about all the sales orders of this sold-to-party's name).
 
REPORT EVENTS:
 
Reports are event driven. And the different events in-sequence that a report execution encounters are as below -

1. LOAD-OF-PROGRAM -
As the name says this event is used to load the module pool, function module, subroutine pool programs into the executable program. This event occurs only once during a particular execution. And this program is pretty much something like a constructor of a class.

2. INITIALIZATION -
This event is executed before the selection screen is displayed, and this provides an opportunity to initialize values on selection screen.

3. AT SELECTION-SCREEN -
This event is processed after the initialization, and it is primarily used to validate the selection screen values. In other words, as soon as the user enters values in the selection screen and executes this event is processed which validates the values entered by the user and displays any error message if the values entered are not appropriate.

The types of selection screen events are -
  • At Selection-Screen Output.
  • At Selection-Screen On Value Request For <Field>.
  • At Selection-Screen On Help Request For <Field>.
  • At Selection-Screen On <field- select-options>.
  • At Selection-Screen On <field-Parameter>.
  • At Selection-Screen On Block <blockname>.
  • At Selection-Screen On Radiobutton Group <groupname>.
  • At Selection-Screen.
  •  
    AT SELECTION SCREEN OUTPUT -
    Actually this event occurs in between INITIALIZATION and AT SELECTION-SCREEN. This event is used to dynamically change the properties of the selection screen. In other words, this event allows us to modify the selection screen even before it is displayed for the first time. For ex: When the selection screen first appears the user wants to see few fields intensified ON and few intensified OFF, this can be achieved by this event.
     
    AT SELECTION SCREEN ON VALUE REQUEST FOR <FIELD> -
    This event gets triggered when the F4 option is pressed on a field. This is particularly useful if you have your own set of data that you want to display when user presses F4.
    Note: If this F4 is for select option, It needs to be mentioned twice once for low and other for the high.
    Ex: Prepare a table with all the values you want to display when the user presses F4.
    Say the table is gt_kna1,
    AT SELECTION SCREEN ON VALUE REQUEST FOR s_kunnr-low.
     
    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
    retfield = 'KUNNR'
    dynprofield = 'S_KUNNR'
    dynpprog = sy-prog
    dynpnr = sy-dynnr
    value_org = 'S'
    TABLES
    value_tab = gt_kna1.
    Similarly for the high field that is s_kunnr-high.
     
    AT SELECTION SCREEN ON HELP REQUEST FOR <FIELD> -
    This is very similar to the above value request, except that a help documentation is provided when the user presses F1.
    Note: In both cases, because the selection screen parameters are of the data type the corresponding data element the default F4 and F1 help appear. If these events are used the standard F1 and F4 helps are overwritten.
     
    Now prepare the Help table with attributes -

    gt_help-tabname = ''.
    gt_help-fieldname = ''.
    gt_help-keyword = ''.
    gt_help-length = ''.
    gt_help-value = ''
    APPEND gt_help.
     
    CALL FUNCTION 'HELP_GET_VALUES'
    EXPORTING
    popup_title = ''
    TABLES
    fields = gt_help
    EXCEPTIONS
    no_entries = 1
    OTHERS = 2.
     
    AT SELECTION-SCREEN ON -
    This is pretty much same like the AT SELECTION-SCREEN used to validate the selection screen values, except that the AT SELECTION-SCREEN validates all the values but the AT SELECTION-SCREEN ON validates only the field it is used on -
    Ex:
    AT SELECTION-SCREEN ON s_kunnr.
    If s_kunnr is initial.
    MESSAGE 'Please enter the sold-to-party value', TYPE 'E'.
    Endif.
     
    4. START-OF-SELECTION -
        Data selection from the data base tables is done here.

    5. END-OF-SELECTION -
        From the start-of-selection one output table which is a consolidation of all the data
        (the final internal table) is prepared and at the end-of-selection this output is written
        to display.

    6. AT LINE-SELECTION -
        This event is specific to interactive reporting. On the primary screen of an output, if
        the user clicks on a row or a field and expects an event to happen, code for this can be
        written under this event. The AT LINE-SELECTION populates few system fields which
        will help capturing the row or the field that has been selected.
        SY-LSIND is tone such system field which holds the number of the detail list.
        For Basic or primary list SY-LSIND is zero, for first detail list SY-LSIND = 1.
        A particular report can have 0 to 22 details screens.
        GET CURSOR FIELD fname value fval - this give the value on which the user has clicked.
        HIDE - Hide is a keyword which stores values of specific key fields in the memory along 
        with the sy-linno system field.
        This statement is used within a loop while displaying that is in END-OF-SELECTION. All  
        the fields that you think you might use can be displayed using this keyword, and can
        be used to display the interactive report.
        Interactive reporting can as well be done using the I_CALLBACK_USER_COMMAND of the
        reuse_alv function module.
       
             Unlike the topics discussed earlier, there are other process control events that can be used to extract data and prepare the final internal table.
    AT FIRST - Beginning of the loop
    AT NEW - At every new occurrence of the field
    AT END OF - At the end of a particular occurrence
    AT LAST - At the end of the loop.
    All these events are to used within a loop.

    TOP-OF-PAGE -
    This event is triggered when the first write statement is seen. When the controller sees the first write statement, it will go and check if top-of-page event is present, If yes it will execute whatever is present in there like the title, column headings etc.
    Ex:
    TOP-OF-PAGE
    FORMAT COLOR 1.
    WRITE: ' Customer Details'.
    FORMAT COLOR 1 OFF.
    ULINE.

    TOP_OF_PAGE DURING LINE_SELECTION -
    This keyword lets us provide TOP-OF-PAGE for secondary lists
    Ex:
    TOP_OF_PAGE DURING LINE_SELECTION
    If sy-lsind = 1. (First detail list)


    Endif.

    Few important notes to remember about reporting -
     
    1. Report  <ZMNS_CUSTOMER_ORDERS> This is the first line of any report.
     
    2. KEYWORDS to format the report layout -
    • To avoid heading - NO STANDARD PAGE HEADING is the keyword  
              Syntax: Report  <ZMNS_CUSTOMER_ORDERS> NO STANDARD PAGE HEADING
     
    • To specify the length of the column in a report - LINE-SIZE
             Syntax: Report  <ZMNS_CUSTOMER_ORDERS> LINE-SIZE 40
             The system field sy-linsz is set with this keyword.
    • To specify the length of the page in a report - LINE-COUNT page_lines(footer_lines)
             Syntax: Report  <ZMNS_CUSTOMER_ORDERS>  LINE-COUNT 0(2)
             The page_lines if mentioned 0 is by default set to 60000 by the system and the 2 
             meaning 2 lines are reserved for the footer. Note, a footer cannot be set for the
             detail list.
             The system field sy-linct is set with this keyword.
             The footer must be set under END_OF_PAGE keyword.
    • NEW-PAGE - If all the above settings, like the count, title, header and all need to be valid only for the first page, new settings for the next individual page can be set using the NEW-PAGE keyword.
    • Syntax: NEW-PAGE <NO-TITLE> <NO-HEADING>
     
    Selection screen:
     
    Syntax:
    Selection screen begin of screen <>
     
    Selection screen end of screen <>
     
    Selection screen parameters can be either PARAMETERS or SELECT-OPTIONS.
     
    PARAMETERS are single valued entries:
    Ex: PARAMETER  pa_kunnr type kunnr DEFAULT '108183'. 
    The default keyword is optional, in case you want to run the report for the same value always.

    PARAMETER as checkbox:
    Ex: PARAMETER pa_c AS CHECKBOX DEFAULT 'X'.
     
    PARAMETER as radio button:
    Ex: PARAMETER: pa_rb1 radio button group rad1 DEFAULT 'X'
                             pa_rb2 radio button group rad1.
     
    SELECT_OPTIONS :
    Ex: s_vbeln for vbak-vbeln.
    Used when range of values are to be used.
     
    LAYOUT TIPS :
    - For color use syntax - FORMAT COLOR n, n is the number of the color.

    - HOTSPOT - If the requirement is to call a detail screen when the user clicks on a specific
      field, and to indicate this, a hand symbol can be made to appear when the mouse is
      hovered over that field, this can be achieved by the above keyword.
     
    - The layout of the grid can also be set by setting some values in the field catalog like -
      output length, hotspot on, sel_text etc.
     
    - Also the layout exporting parameter can also be used to perform layout settings like  
      no_toolbar, grid_title etc. See CL_GUI_ALVGRID class for the structure of any of these 
      fields.
     
    - Its worth noting about a variable IT_EXCLUDING in the function module  
      REUSE_ALV_GRID_DISPLAY which can be used in cases when the requirement is to display
      only certain buttons on alv grid. Obtain the function codes of the button that are needed
      to be displayed, and add the function codes of those buttons to the it_excluding
      table and pass it on to the function module.
     
    Interactive reporting using OOPS:
    The concept of interactive reporting is pretty much same either using the Standard function module approach or the OOPS approach. In OOPS we have  a method SET_TABLE_FOR_FIRST_DISPLAY to display the report in ALV grid.

    Syntax:

    ** Declare an event class with double click handling method which is of type double_click 
       of CL_GUI_ALV_GRID.

    CLASS event_class DEFINITION.
    PUBLIC SECTION.
       METHODS: handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
                       IMPORTING e_row .
    ENDCLASS.

    As can be seen above this method is for the event DOUBLE_CLICK in the class CL_GUI_ALV_GRID, and e_row is the parameter which will give information about
    the row selected. Once the class is declared, write the respective code under this method that you want to see happen when the user double clicks.

    EX: CLASS event_class IMPLEMENTATION.
           METHOD handle_double_click.
              READ TABLE gt_kunnr INDEX e_row-index INTO gw_kunnr.
              SELECT * FROM kna1
              INTO CORRESPONDING FIELDS OF TABLE gw_kna1
              WHERE kunnr EQ gw_kunnr-kunnr.
              CALL SCREEN 101.
           ENDMETHOD.
         ENDCLASS.

    Now that the method is ready, calling the method is remaining. This will happen after the SET_TABLE_FOR_FIRST_DISPLAY method is called.

    Event_receiver TYPE REF TO event_class.

    CREATE OBJECT event_receiver.

    SET HANDLER Event_receiver->handle_double_click FOR c_alv1.

    This should take care of the interactive reporting. 
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    Friday, April 5, 2013

    Understanding RICEFWs - Enhancements

           Enhancements are the means by which the SAP standard code can be customized as per the clients requirement. This does not require access key as code will be written in SAP provided slots for custom code.

    The type of enhancements:
    1. User exits
    2. Customer exits
        a. Function exits
        b. Screen exits
        c. Menu exits
    3. BADI
    4. Enhancement frameworks
        a. Implicit enhancements
        b. Explicit enhancements

    User Exits:
    The naming convention for user exits is FORM USEREXIT_001 These can be found in SE80. User exits are generally includes which are collected together and added to the SAP standard program. But the disadvantage with the user exits are it needs access key to add/change any code in the exit.

    How to find a user exit?
    Get the package name of the transaction/program etc. Go to SMOD, press F4 in the enhancement field. Press information systems button. Give the package name in the popup and a list of user exits are displayed pertinent to the package.

    Customer exits:
    Customer exits are also pre existing slots provided by SAP, but the advantage with the customer exits is they do not need any access key.
    A basic check to see if a particular program has any customer exits is the keyword
    CALL CUSTOMER-FUNCTION 001. Digging deep into this function, we can find the customer exits available.

    Screen exits:
    Like the CALLL CUSTOMER FUNCTION '001' for function exits, there is CALL CUSTOMER-SUBSCREEN for the screen exits. If this particular keyword is present in the screen program of the screen to be modified it means that a screen exit is available for us to modify the screen.
    Once we have the package the screen exit can be found in SE80, or in SMOD.

    How to find the enhancement for a particular  exit/screen area/menu entries -
    After the customer/function exit is found, go to SMOD and press f4 in the enhancements field, press the button to expand the search options in the search popup. And uncheck all the check boxes except exits function and in the name of the component-field give the exit name. Then the enhancement screen in the SMOD tcode will be populated with the enhancement of that exit. Now go to CMOD and generate the project to code the exit.
    Similarly for screen uncheck exit functions and menu entries and for menu uncheck the exit functions and screen area.

    Another common way to find out exits/BADIs -
    Put a break point in the get_instance method of the class CL_EXITHANDLER, and run the prog/tcode etc. The execution stops at this method every time it finds a BADI or an exit. This way the list of all the exits and BADIs in the executed program can be found.

    BADIs:
    These are also predefined exit points available for developers where code can be written without the necessity of any access key. Unlike the exits most of the BADIs can have multiple implementations, meaning you have a particular slot which is appropriate to insert a certain piece of code but it already has an implementation which will be triggered if a particular condition is satisfied, in this case you can create another implementation to this BADI and set up your own conditions to trigger the BADI.

    Setting up a condition to a BADI can be done using filters.

    Filter dependent BADI:
    A filter dependent BADI is very much useful if want your code in the BADI to be triggered for only certain conditions. A BADI filter is SPECIFIC to the IMPLEMENTATION, meaning filter can be set on any one field that you wish and for any number of values of that field values. 

    How to set a filter?
    Select the checkbox filter-depend, and in the field type choose a data element and below insert a value in the defined filters section. ( insert field appears after the filter-depend checkbox is selected and the badi is activated).
    Note1 : When the filter-depend box is checked and after the badi is activated, an importing parameter fil_val is automatically added to the interface of the badi. Also this parameter is added to all the methods of that particular implementation.

    So when calling this BADI, this new import parameter should also be passed -
    CALL METHOD l_badi_instance ->get_cust_name
    exporting
    kunnr = '300014'
    flt_val = 'DEFAULT_ID'
    importing
    name = lv_name.

    IMPLICIT ENHANCEMENTS:
    Are the ones that we generally use. There are pre-existing locations in an SAP program where the user is allowed to include their code piece. These are very well carried over during upgrade to higher versions.
    In the program, click on the circle button and then go to Edit -> Enhancement operations -> Show implicit enhancement options.
    The general locations for these options are
    - At the beginning and end of a form
    - At the end of the function modules etc.

    EXPLICIT ENHANCEMENTS
    There are 2 types of explicit enhancements
    1. Enhancement point
    2. Enhancement section

    The main difference between both is, enhancement point can have multiple implementations and it exists along with the SAP standard code where as the enhancement section replaces the new code with the existing SAP standard code. Enhancement section can have only one active implementation, this is especially used when we have certain code in the standard SAP program which we want to avoid. And enhancement point can have multiple implementations and hence it can exist along with the standard code.

    How to create an explicit enhancement?
    Goto SE80 and select the desired package and right click on it to create enhancement spot. Create an implementation for this spot and save and activate.
    Now go to your program, place the cursor where you want to create the enhancement spot and in the create enhancement option give your spot and package name.With this the enhancement point gets added to your program.
    Click on the ENHANCE button on the top, enhancement options - > create ->give enhancement impl name -> Place the code and activate.