Wednesday, October 15, 2014

Rules for Better SQL Programming

Tip #1 :Always try to keep the hit list small by using the where clause were ever required or by describing the full search condition in the where clause.
Select Query #1

Wrong

SELECT * FROM sflight INTO xflight.
CHECK xflight-carrid = 'LH '.
CHECK xflight-connid = '0300'.
CHECK xflight-fldate(4) = '2002'.
WRITE: / xflight-fldate.
ENDSELECT.
 
Right

SELECT * FROM sflight INTO xflight
WHERE carrid = 'LH ' AND
connid = '0300' AND
fldate LIKE '2002%'.
WRITE: / xflight-fldate.
ENDSELECT.

Select Query #2

Wrong

SELECT * FROM sflight INTO xflight
WHERE carrid = 'LH ' AND connid = '0300'.
CHECK xflight-fldate(4) = '2002'.
WRITE: / xflight-fldate.
ENDSELECT.

Right
SELECT * FROM sflight INTO xflight
WHERE carrid = 'LH ' AND
connid = '0300' AND
fldate LIKE '2002%'.
WRITE: / xflight-fldate.
ENDSELECT.

Tip #2 : Minimize the Amount of Transferred Data

Minimize the amount of data transferred between the database and the application server.

Wrong

SELECT * FROM sflight INTO xflight WHERE carrid = 'LH '
AND connid = '0300'
AND fldate LIKE '2002%'.
WRITE: / xflight-fldate.
ENDSELECT.

Right

SELECT fldate FROM sflight INTO (xflight-fldate) WHERE carrid = 'LH '
AND connid = '0300'
AND fldate LIKE '2002%'.
WRITE: / xflight-fldate.
ENDSELECT.


Apply UP TO n ROWS.

Wrong

SELECT ID NAME discount FROM scustom INTO (xid, xname, xdiscount)
WHERE custtype = 'B'
ORDER BY discount.
IF sy-dbcnt > 10. EXIT. ENDIF.
WRITE: / xid, xname, xdiscount.
ENDSELECT.

Right

SELECT ID NAME discount
FROM scustom UP TO 10 ROWS
INTO (xid, xname, xdiscount)
WHERE custtype = 'B'
ORDER BY discount.
WRITE: / xid, xname, xdiscount.
ENDSELECT.

or how about using SELECT SINGLE instead of SELECT UP TO 1 ROWS.

Use the UPDATE … SET Statement

Wrong

SELECT * FROM sflight
INTO xflight
WHERE carrid ='LH '.
xflight-seatsocc = xflight-seatsocc + 1.
UPDATE sflight FROM xflight.
ENDSELECT.

Right


UPDATE sflight
SET seatsocc = seatsocc + 1
WHERE carrid = 'LH '.

Use aggregate functions

Wrong

SUM = 0.
SELECT seatsocc
FROM sflight INTO xseatsocc
WHERE fldate LIKE '2002%'.
SUM = SUM + xseatsocc.
ENDSELECT.
WRITE: / SUM.

Right

SELECT SINGLE SUM( seatsocc )
FROM sflight INTO SUM
WHERE fldate LIKE '2002%'.
WRITE: / SUM.

Apply Having Clause

Wrong

SELECT carrid connid fldate MAX( luggweight )
INTO (xcarrid, xconnid, xfldate, MAX)
FROM sbook
GROUP BY carrid connid fldate.
CHECK MAX GT 20.
WRITE: / xcarrid, xconnid, xfldate, MAX.
ENDSELECT.

Right

SELECT carrid connid fldate MAX( luggweight )
INTO (xcarrid, xconnid, xfldate, MAX)
FROM sbook
GROUP BY carrid connid fldate
HAVING MAX( luggweight ) GT 20.
WRITE: / xcarrid, xconnid, xfldate, MAX.
ENDSELECT.

Tip #3: Keep the number of round trips between the database and the application server small.

Use high-speed array operations with UPDATE, INSERT, DELETE, MODIFY.

Wrong

LOOP AT itab INTO wa.
INSERT INTO sbook VALUES wa.
ENDLOOP.

Right

INSERT sbook FROM TABLE itab.

Apply the INNER JOIN. Avoid nested SELECT-ENDSELECT loops

Wrong

SELECT * FROM sflight INTO xflight WHERE planetype = '727-200'.
SELECT * FROM sbook INTO xbook
WHERE carrid = xflight-carrid AND
connid = xflight-connid AND
fldate = xsflight-fldate.
WRITE: / xflight-carrid, xflight-connid, xbook-bookid.
ENDSELECT.
ENDSELECT.

Right

SELECT f~carrid f~connid b~bookid
INTO (xcarrid, xconnid, xbookid)
FROM sflight AS f INNER JOIN sbook AS b
ON f~carrid = b~carrid AND
f~connid = b~connid AND
f~fldate = b~fldate
WHERE planetype = '727-200'.
WRITE: / xcarrid, xconnid, xbookid.
ENDSELECT.

Apply the OUTER JOIN

Wrong

SELECT * FROM sflight INTO xflight WHERE planetype = '727-200'.
SELECT * FROM sbook INTO xbook
WHERE carrid = xflight-carrid
AND connid = xflight-connid
AND fldate = xflight-fldate.
WRITE: / xflight-carrid, xflight-connid, xflight-fldate,
xbook-bookid.
ENDSELECT.
IF sy-dbcnt = 0.
CLEAR xbook-bookid.
WRITE: / xflight-carrid, xflight-connid, xflight-fldate,
xbook-bookid.
ENDIF.
ENDSELECT.

Right

SELECT f~carrid f~connid f~fldate b~bookid
INTO (xcarrid, xconnid, xfldate, xbookid)
FROM sflight AS f LEFT OUTER JOIN sbook AS b
ON f~carrid = b~carrid AND f~connid = b~connid
AND f~fldate = b~fldate.
WHERE planetype = '727-200'.
WRITE: / xcarrid, xconnid, xfldate, xbookid.
ENDSELECT.

Use subqueries

Wrong

SELECT carrid connid MAX( seatsocc )
FROM sflight
INTO (xcarrid, xconnid, MAX)
GROUP BY carrid connid
ORDER BY carrid connid.
SELECT fldate FROM sflight
INTO yfldate
WHERE carrid = xcarrid AND
connid = xconnid AND
seatsocc = MAX
ORDER BY fldate.
WRITE: / xcarrid, xconnid, yfldate.
ENDSELECT.
ENDSELECT.

Right

SELECT carrid connid fldate
FROM sflight AS f
INTO (xcarrid, xconnid, xfldate)
WHERE seatsocc IN
( SELECT MAX( seatsocc ) FROM sflight
WHERE carrid = f~carrid AND connid = f~connid )
ORDER BY carrid connid fldate.
WRITE: xcarrid, xconnid, xfldate.
ENDSELECT.

For frequently used INNER JOINs, you can create a database view in the ABAP Dictionary

Wrong

SELECT f~carrid f~connid b~bookid
INTO (xcarrid, xconnid, xbookid)
FROM sflight AS f INNER JOIN sbook AS b
ON f~carrid = b~carrid AND f~connid = b~connid
AND f~fldate = b~fldate.
WRITE: / xcarrid, xconnid, xbookid.
ENDSELECT.

Right

SELECT carrid connid bookid
INTO (xcarrid, xconnid, xbookid)
FROM sflightbook.
WRITE: / xcarrid, xconnid, xbookid.
ENDSELECT.

Tuesday, October 14, 2014

Certification v/s Real Time Experience





certification1 Another famous discussion in IT industry in India lies in whether to do Certification or not. Would it add any meaningful value to my resume? Would it give me any monetary benefit in my current or future Organization? Would it help me in getting a Job?

Well, it depends on who you are currently and at what stage of your career. If you are just out of college without any experience and counting only on Certification to fetch your first Job, I guess you are being rather highly optimistic! For fresher’s entry recruiters look for aptitude and basic technology understanding. It can be in any technology because your first project may not be on something which you already know. It will be decided “as per the business requirement”.

If you are into a domain job and would like to make a career in IT, perhaps the best thing to do is get Certified. It will give you that confidence and also know how of the nomenclature with somewhat a deeper understanding. It would be easier for any Organization to take you and utilize your Domain as well as hone your newly acquired skills.

images (1)If you are already into real time Projects and are well into your IT career, again I think it makes no sense to go for certification. Although there are Organizations wherein there is a culture to get certified but then they are also partners of the certifying Organization. They also have to fulfill a certain criteria to be an esteemed partner.


Real Time Experience is always far better than the information collected during Certification. After all, you may get a driving license while doing your exercise on a Simulator but the test of nerves happens when you actually drive on a Highway! Or park in a multi-level car parking with vehicles ahead and behind you!!

Automatic Population of Values during Table Maintenance

When we need to maintain values for a custom table in a table maintenance generator, certain situations may arise where we need to automatically populate another field in a table depending on the value of one field. Or we may some custom requirement like validating a particular entry before it is saved. There can be various other specific requirements which we may face when we are maintaining data a custom table

Now for example say we have a custom table ZTEST_MAT.

Now we can all create the table maintenance generator for this table using menu Path Utilities --> table maintenance generator.

After the TMG is successfully created, then open it again in display mode and get the source code name for the TMG. It will be a module pool program.



Now open the source code SAPLZTEST_MAT. And open the screen flow logic.

Put your custom module in the PAI Module. Here MODULE MODIFY_RECORD is the module in which we have put our code.

Now in this custom module we can write our code to say automatically populate the material description when the material number is entered.

In the sample code, you would notice we have the internal table total which contains all the table records and also in extract, we have the selected records which are being displayed currently. The field <vim_xtotal_key> contains the key. For changing the current record, we need to modify both the corresponding extract and total table values.
The <action> field indicates the current user action for that field – new insertion or updation or deletion.

*& Code for automatic population of values ***

module MODIFY_RECORD input.
DATA: l_index TYPE sytabix, " Index to note the lines found
l_tabix TYPE sytabix. " Index of total table

DATA: l_matnr TYPE matnr.
FIELD-SYMBOLS: <record> TYPE ANY. " Work area for table

* Modify changed by and changed on fields for any updates
LOOP AT total.
l_tabix = sy-tabix.
* Assign the table header line to the work area
ASSIGN total TO <record>.
IF sy-subrc = 0. " If assigning is successful.
* Check if data was changed and get the corresponding line index
IF <action> = 'U' " Updated entry
OR <action> = 'N'. " New entry

READ TABLE extract WITH KEY <vim_xtotal_key>. " Key field

IF sy-subrc = 0.
* Clears the variables after updation.
l_index = sy-tabix.

SELECT SINGLE maktx
FROM makt
INTO <record>+21(40)
WHERE matnr = <record>+3(18).

* Modify total table
MODIFY total FROM <record> INDEX l_tabix.

CHECK l_index > 0.
extract = <record>.

* Modify extract table
MODIFY extract INDEX l_index.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.

endmodule. " MODIFY_RECORD INPUT

We have also made the material text field display only. Now in SM30, when we try to maintain new material nos. in the table, the corresponding text gets pulled in automatically. Add new entries to the table.



Now when we press Enter.



The material text is populated automatically. This is a simple example of how we can add useful features to the standard table maintenance.

ABAP Program to Send Mail with Attachment

This ABAP program use the function module ‘SO_NEW_DOCUMENT_ATT_SEND_API1′ to send the email with attachment. There are five steps involved in sending the email with attachment.

  1. Add Recipients

  2. Put in the mail contents

  3. Create the attachment

  4. Pack the mail contents and attachment

  5. Finally, send the mail out.

Before we start writing the code, ensure that everything is configured correctly in the SCOT. Get in touch with the basis team and they will help you configure it.

Declare the following


DATA: lt_mailrecipients  TYPE STANDARD TABLE OF somlrec90 WITH HEADER LINE,
      lt_mailtxt         TYPE STANDARD TABLE OF soli      WITH HEADER LINE,
      lt_attachment      TYPE STANDARD TABLE OF solisti1  WITH HEADER LINE,
      lt_mailsubject     TYPE sodocchgi1,
      lt_packing_list    TYPE STANDARD TABLE OF sopcklsti1 WITH HEADER LINE,
      gv_cnt             TYPE i.



Now, lets start formatting the mail.

Add Recipients


lt_mailrecipients-rec_type  = 'U'.
lt_mailrecipients-com_type  = 'INT'.
lt_mailrecipients-RECEIVER  = 'someone@erpdb.info'.
APPEND lt_mailrecipients .
CLEAR lt_mailrecipients .



Put in the Mail Contents


lt_mailtxt = 'Hi How are you'.      APPEND lt_mailtxt. CLEAR lt_mailtxt.
lt_mailtxt = 'Here is a test mail'. APPEND lt_mailtxt. CLEAR lt_mailtxt.
lt_mailtxt = 'Thanks'.              APPEND lt_mailtxt. CLEAR lt_mailtxt.



Create the attachment


  DATA: BEGIN OF lt_po_data_cons OCCURS 0,
         ebeln LIKE ekpo-ebeln,
         ebelp LIKE ekpo-ebelp,
        END OF lt_po_data_cons.

  SELECT ebeln ebelp INTO TABLE lt_po_data_cons
  UP TO 10 ROWS
  FROM ekpo.   

  CLASS cl_abap_char_utilities DEFINITION LOAD.
  CONCATENATE 'PO' 'PO Line'
              INTO lt_attachment SEPARATED BY
              cl_abap_char_utilities=>horizontal_tab.
  APPEND lt_attachment. CLEAR lt_attachment.

  LOOP AT lt_po_data_cons.
  CONCATENATE lt_po_data_cons-ebeln lt_po_data_cons-ebelp
              INTO lt_attachment SEPARATED BY
              cl_abap_char_utilities=>horizontal_tab.

  CONCATENATE cl_abap_char_utilities=>newline lt_attachment
              INTO lt_attachment.

  APPEND lt_attachment. CLEAR lt_attachment.
 ENDLOOP.



Pack the mail contents and attachment


  lt_packing_list-transf_bin  = SPACE.
  lt_packing_list-head_start  = 1.
  lt_packing_list-head_num    = 0.
  lt_packing_list-body_start  = 1.
  lt_packing_list-body_num    = LINES( lt_mailtxt ).
  lt_packing_list-doc_type    = 'RAW'.
  APPEND lt_packing_list. CLEAR lt_packing_list.

  lt_packing_list-transf_bin  = 'X'.
  lt_packing_list-head_start  = 1.
  lt_packing_list-head_num    = 1.
  lt_packing_list-body_start  = 1.
  lt_packing_list-body_num    = LINES( lt_attachment ).
  lt_packing_list-doc_type    = 'XLS'. " You can give RAW incase if you want just a txt file.
  lt_packing_list-obj_name    = 'data.xls'.
  lt_packing_list-obj_descr   = 'data.xls'.
  lt_packing_list-doc_size    = lt_packing_list-body_num * 255.
  APPEND lt_packing_list. CLEAR lt_packing_list.

  lt_mailsubject-obj_name     = 'MAILATTCH'.
  lt_mailsubject-obj_langu    = sy-langu.
  lt_mailsubject-obj_descr    = 'You have got mail'.
  lt_mailsubject-sensitivty   = 'F'.
  gv_cnt = LINES( lt_attachment ).
  lt_mailsubject-doc_size     = ( gv_cnt - 1 ) * 255 + STRLEN(
  lt_attachment ).



Finally, send the mail out.
That’s it. You are all done. Just call the function module to send the mail out.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = lt_mailsubject
    TABLES
      packing_list               = lt_packing_list
      contents_bin               = lt_attachment
      contents_txt               = lt_mailtxt
      receivers                  = lt_mailrecipients
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      document_type_not_exist    = 3
      operation_no_authorization = 4
      parameter_error            = 5
      x_error                    = 6
      enqueue_error              = 7
      OTHERS                     = 8.
  IF sy-subrc EQ 0.
    COMMIT WORK.
    SUBMIT rsconn01 WITH MODE = 'INT' AND RETURN.
  ENDIF.


Analyzing expensive SQLs using SM50/SM66

This article explains the following query :

How to analyze expensive SQL statement using SM50/SM66 ?

Go to transaction SM66 and have a look at the global workprocess overview.

i) Have a look at Action column and identify any long running Sequential read/ direct read /insertion /updation etc

ii) If so, please note the respective report that is being run and the table that is being used for the same. From the report we can make whether it is SAP standard report or customized report. If it is customized, we can take help of ABAPer to see if the report can be finetuned in cases of bad programming. Table details can be used to figure out the size of the table and whether statistics are upto date for the table or not.

Please note :  "Updatestats job should run daily so that system will have recent statistics about all the tables. These statistics will be useful for Cost based optimizer to identify optimized execution plan for an SQL statement"

iii)  Also, please note the user who is running that process. So that, later user can be approached and a trace(ST05) can be kept for his activity to understand his transaction in detail which would help for finetuning.

iv) SM50 transaction can be used to view the detailed display of the process and the SQL statement that is being executed

For example, Please refer below screenshot of SM66 :

In the below screenshot,

i) Highlighted user is running ZFI_TDS* report on RBKP table in dialog mode and sequential read action is happening on the same.

ii) user DDIC is running RBDMONI_* report (in  background mode) on table BDCP2 and direct read is happening on the same. It has already consumed 783 seconds of CPU time.



To analyze point i) scenario in the above case, please note the server name on which this process is running. Go to that server through SM51 and have a look at SM50 transaction.

Identify the respective PID of the process which you have suspected as expensive SQL from the overview and double click on that process which opens up detailed display as below:



How to troubleshoot a background job running for long duration in sap?

How to troubleshoot a background job running for long duration in sap?

This article answers how to troubleshoot a background job running for a long duration

-------------------------------------------------------------------------------------------

1) First of all identify the job that is long running and identify details like job class, work process that is executing the job

How to find out long running jobs in SAP 



Goto SM37 transaction and select the active job status between any 2 given date/time and list them. In the output, sort the jobs based on duration column in descending order and identify the jobs that are running for longer duration



All other questions can be answered from the below :

Goto transaction SM37 and list the jobs based on status and time interval.

Select any job for which you want to figure out the details. Double click on the job,  which pops up "display job screen". In that screen, click on job details tab to view

  • Job name

  • Job class (i.e A, B and C)

  • Status of the job

  • Exec. Target (server/instance on which job is being run currently)

  • Job frequency (hourly, monthly , weekly etc)

  • Work process that is executing the job

  • Client on which job is running

  • Release time of the job

  • Schedule start of the job



2) Click on the job to view the display job screen. In the screen, click on job log to understand what is being performed by the job currently. This may give details like job is currently extracting some data packages or processing data packages etc

3) Identify the executing server and process id of the job from the step 1 and goto transaction SM50 of the respective executing server to view more details about the background job running.

Figure out the status of the job like On Hold or running from the process overview. If the job is On Hold, find out the reason for On Hold by examing the "Reason" column of SM50 transaction. Reason for On Hold could be due to CPIC/RFC/DEBUG/ENQ/PRIV/UPD etc.

Double click on the reason column for detailed information on the same and troubleshoot accordingly. If reason is RFC, check out which RFC it is referring to and cross check whether destination system is up or not and any other problems with that system.

  • If it is ENQ, check out any lock issues like lock overflow etc

  • If it is PRIV, check out for memory bottlenecks

  • If it is UPD, check out whether any update issues

  • If it is CPIC, check out for any network , gateway, message server and other communication problems

4) After performing step3, if you figure out job is not on Hold and it is in running state, then examine report column to identify what report/program is being executed by the job. Once you got the report/program details, figure whether it sap program or custom program and take actions accordingly.

5) Also examine Action and table columns in SM50 transaction of respective executing server to identify what is the action( roll in/roll out /Sequential read/Physical read/insert/update/delete etc)  being carried out by the job currently and what is the table on which action is being carried out.

If it is sequential read, figure out the cost of that sequential etc and consider for indexing etc. If it is physical read, check out whether there are too many swaps and consider resizing buffers accordingly. If you observed delay is due to high roll in/roll out, identify reasons for the same and tune buffer/memory parameters accordingly.

6) Once you get the table details on which action is being carried out, figure out

  • How many records are existing in the table?

  • Is this taking long time due to volume of records?

  • Are there proper indexes on the table ?(If no proper index, consider index creation by taking help of DBA )

  • Is the table having up to date statistics? (If statistics are out of date, consider updating statistics of that table)

7) Consider debugging the process in SM50 (Program/Session -> Program ->   Debugging) to figure out the issue

8) Using ST05 or ST12, a trace can be taken for background job to figure out where exactly time is being consumed and to identify various CPU/memory bottlenecks or any buffer issues.

9) STAT/STAD transaction can be used to figure out what is the reason for high response time and actions can be taken accordingly

10) By taking help of ABAP er, even ABAP run time analysis can be done using SE30 transaction

By following the above steps, you can pin point the issue and take actions accordingly to minimize runtime of long running background jobs.



SAP Web Dynpro ABAP Interview Questions with Answers


Controllers in Web Dynpro:



Question 1: What are the types of Controllers in Web Dynpro ABAP?
The types of controllers are listed in the screenshot below:

Types of Controllers in Webdynpro ABAP
Types of Controllers in webdynpro ABAP

Question 2: What is Component Controller?

Component Controller is the King of all Controllers. It is the backbone of your Web Dypro Component . It is like a Global or Top Include for you program . It controls the entire activity of your Web Dynpro Component.

Question 3: What is an Interface Controller?
Whenever we want views , nodes or methods of a particular web dynpro component to be available to other the outside world ( i.e. other webdynpro components) , we make use of Interface controller . Interface Controller is created by default when a webdynpro component is created.Interface Controller would generally come into picture when you are doing component usage of some sort in web dynpro i.e. re-using views/methods/nodes of one WD component in another.
Question 4: What is a Custom Controller?
When your Component Controller grows big in size ( say more than 10-15 views and corresponding context nodes , methods , events , event handlers etc) , it might become tough to handle everything in the Component Controller . In such a scenario , you can create one or more custom controllers and modularize or segregate the logic into separate parts using Custom Controller.

Question 5: Would you prefer creating multiple Custom Controllers OR would you go for separate Web Dynpro components and then do Component usage.

This would actually depend on the requirement , but ideally separate Web dynpro components should be created and reused.One can also use the assistance class for segregating business logic.

Question 6: How many component controllers can a Web Dynpro Component have ?

Component Controller is only one . You can create multiple controllers , but those are called Custom Controllers.

Note: If you are asked about the Web Dynpro architecture , you should talk about both the MVC framework and the controllers.
Question 7: Suppose your Web Dynpro has 10 nodes in the Component Context . Will all 10 the nodes be available in the Interface controller?
Nodes from the Component context are available to the interface controller only when the nodes are declared as interface nodes.To create an interface node , set the interface property to yes as shown in the screenshot below:











Interface node in Interface controller
Interface Node in Webdynpro ABAP

To create an interface node , set the interface property to yes as shown in the screenshot to the right :

Once created , the interface node is indicated by a special symbol as shown in the figure below and the property Interface Node is set to yes:









Interface Node in Webdynpro ABAP
Interface Node in Webdynpro ABAP

Question 8: When do views become available in the interface Controller ?

Whenever we embed any view in a window , at the moment that view becomes automatically available to the Interface Controller and shows up as an interface view in the Interface Controller. You do not have to declare a view as an interface view as is the case with interface nodes.

Question 9: Is it true that each controller has its own Context node ?
Yes , Each controller has it's own context , methods , and Events.

Question 10: At design time how do you decide whether to declare a node in the Component Controller or in the View Controller?
This again depends on the requirement: If the node is going to be accessed in multiple views , it should be declared at the Component Controller level . However , If the node is absolutely specific to only one view , it can be defined in the View Controller. As the size of Webdynpro development grows , it starts becoming complex and the need to define attributes,nodes,methods etc. at the Component Controller increases.

Hook Methods in Web Dynpro:


Question 11:What are Hook Methods in Web Dynpro ABAP ?


Hook methods in webdynpro are standard web dynpro methods that are called at different time in the web dynpro lifecycle.These methods are listed in the screenshot below: These methods start with WD*.


hook methods in web dynpro
Hook Methods in Webdynpro ABAP

Question 12:Are all the hook methods available to all the Controllers?
No . They are specific to controllers. See the details in the image above:

Question 13:Sequence in which web dynpro hook methods are called:
If you want to understand the sequence , put breakpoints in all these methods.Execute the web dynpro application , then do some action on the view , then close the application window:
Have a look at how the control passes from component to window and then to view:


1.WDDOINIT                                    ( Component Controller )
2.WDDOINIT                                    ( Window Controller ) --> Handle default method of the window is called.
3.WDDOBEFORENAVIGATION          ( Component Controller )
4.WDDOINIT                                 ( View Controller )
5.WDDOMODIFYVIEW                   ( View Controller )
6.WDDOPOSTPROCESSING      ( Component Controller )

Now view is displayed . Suppose user does some action on the view:


7. WDDOAFTERACTION               ( View Controller )
8. WDDOBEFOREACTION           ( View Controller )
9. WDDOBEFORENAVIGATION  ( Component Controller )
WDDOINIT                                  ( View Controller ) is not called this time.
10.WDDOMODIFYVIEW                ( View Controller )
11.WDPOSTPROCESSING         ( Component Controller )


View is displayed again.Now close button is clicked on the browser.


12.WDDOEXIT                                ( View Controller )
13.WDDOEXIT                                ( Component Controller )


Application is closed.

So now if you are being asked "What is called first : WDDOINIT or WDDOMODIFY?"  OR
"What is called first WDDOINIT for Window controller or WDDOINIT for View Controller" ?
You should be able to answer the such questions.


Question 14: If one view is called 10 times in the lifespan of a webdynpro component , how many times will the method WDDOINIT be called and how may times will WDDOMODIFYVIEW be called ?
WDDOINIT will be called only once.
WDDOMODIFYVIEW will be called 10 times.


WDDOMODIFYVIEW has a parameter FIRST_TIME . If this is 'X' , then the view is getting called first_time.

Question 15: What are PRE POST and OVERWRITE exit methods in web dynpro?


Whenever a web dynpro component is enhanced , these 3 methods become available for all methods in Webdynpro. Lets take an example of these methods for WDDOINIT.PRE exit: This method is called before WDDOINIT is called.
POST exit: This method is called after WDDOINIT is called.
OVERWRITE exit: In this case , WDDOINIT is not called . Instead , OVERWRITE exit method is called.



Pre exit Post exit and overwrite exit methods in web dynpro






Question 16:What is an Assistance class in webdynpro ABAP? Where do you define an assistance class? How many assistance classes can a webdynpro component have?


Assistance class helps you achieve two things:
1) Segregation of business specific logic (one of the purpose of MVC).
2) Performance benefit.

We can write the business logic in the methods of the View, Window or even the Component controller. But it is not a good practice to load all the business  logic in the views or windows. So SAP has provided an option of assistance class where you can write all your business logic. By this way, you are still in the framework of your webdynpro and also avoid loading too much logic in the components of webdynpro itself. Assistance class methods are much better from a performance point of view than calls of Web Dynpro controller methods.A web dynpro component will have only one assistance class and it is defined at the component level as per the screenshot below. The assistance class is automatically instantiated when a component is called. You can access the instance of this class with the attribute wd_assist, which is created when you create the assistance class in web dynpro.









 Assistance class in web dynpro ABAP
Imp* 
Question 17: What is Singleton Property of a Context Node?

Understanding Singleton property of a context node and how it works in conjunction with the lead selection event can be a bit complicated. If you do not already know what a Singleton set is , I recommend you going through an example of Cars(Parent node with cardinality 0..n ) and Customers ( Nested child node with cardinality 0...n ) on Singleton Node by clicking on the link. This is not that tough , just spend some time with it and you should be okay.


The best way to answer this question is by taking an example.
Say there are two ALV's on a View:
ALV1 ---> NODE_SO_HEADER----> Displays all the Sales Orders.
ALV2 ---> NODE_SO_ITEMS ------> Displays all the line items for the Sales Order selected in ALV1.NODE_SO_ITEMS is the child node for NODE_SO_HEADER and is declared as Singleton node.
Since this node is declared as singleton , at runtime , it holds the line item data only for the Lead Selected Sales Order from NODE_SO_HEADER and not for all the Sales Orders from the parent node.
Whenever the lead selection changes for the parent node, line item data for that lead selected order is fetched from database and populated in the child node.

As a result great performance optimization is achieved.

I hope you get this one :).



Question 18: What is a supply function? When is it called?

You can assign a supply function to a context node when you create a node. In simple terms, supply function is used to populate data records in the context node. A supply function is called when one or more elements of the node are accessed for the first time.












 Supply function in web dynpro
Supply function in web dynpro

To give you an analogy, we all know that a constructor method of a class is called whenever an object of that class is instantiated. In the same way, a supply function for a context node is called when the node is accessed for the first time.


The supply function is generally used in combination with singleton nodes.So whenever the lead selection of the parent node changes , the supply function of the singleton node recalculates and repopulates the child node.


 Question 19: What is lead selection? Is it an event?

Yes , the lead selection is an event in web dynpro.
At run time a context node may contain many records , but only one of those is selected .
The user can select any record from the Table/ALV and this selection is called lead selection.









 Lead selection in web dynpro
Lead Selection in Web Dynpro


Question 20: What is Cardinality of a context node?

Cardinality simply indicates the minimum and the maximum no. of entries the node can have.
The 4 cardinalities are 0:1, 0:n, 1:1, and 1:n .




Question 21: Is there any relation between Cardinality and Lead selection?


Yes , If the cardinality is set to 0:1 or 1:1 , the user cannot select multiple records on the view.
So if you want the user to be able to select multiple records on the screen , the cardinality of that particular node must be set to 0:n or 1:n.


Question 22: Some important Web Dynpro attributes that you should know:

Some attribute in webdynpro that are used very frequently and some of those that you must know are :


Wd_this

Wd_context


Each controller has the above two mentioned attributes.

To elaborate, if you are using the above two attributes say in a method of a View Controller, then WD_CONTEXT is the reference to the Context node of the View and WD_THIS is the reference to the View Controller itself.



Wd_comp_controller
is the reference to the Component Controller. View and Window controller have this attribute defined by default and methods/attributes of the Component Controller can be accessed by using this attribute.

For example:



Wd_assist:
This attribute is created when the assistance class is saved and activated for a web dynpro component. All the methods of the assistance class can be accesses by using this attribute.



Question 23: What are layouts in Web Dynpro ABAP?

Flow layout, Row Layout, Grid Layout, Matrix layout and the form layout.
The layout can be set at a Container level.



 layouts in web dynpro


Question 24: Can you use multiple layouts in one view?


Layouts can be assigned at the container level. For example, you define the layout for your view at the ROOTUIELEMENT container level.
So if at all you want to use multiple layouts in one view, you can create multiple transparent containers and assign different layouts to them.


Question 25: How do you introduce line break for a UI element in any layout?

Say if you are using matrix layout, you will say Matrix Head data for the UI element for which you need a line break.




Question 26:Can you call/launch one web dynpro application from another webdynpro application?

Yes, you can launch one webdynpro application from another webdynpro application.
First, you should get the URL of the web dynpro component that you want to launch and second, call that URL in an external window.
To get the URL of any web Dynpro component, you use the FM
CALL METHOD cl_wd_utilities=>construct_wd_url
EXPORTING
application_name = 'ZDEMO’
IMPORTING
out_absolute_url = str.

Once you get the URL in str, you can call this web dynpro using 'str' and fm: create_external_window.




Question 27: Can you create a Tcode for Webdynpro Application?












 How to create tcode for webdynro ABAP
Creating Transaction code for Web dynpro ABAP

Yes, you can create a Tcode for webdynpro application. Go to SE93 , create Tcode, choose the last option and maintain default values as shown in the screenshot:



How to create tcode for webdynro ABAP



Question 28: Can you pass parameters in a webdynpro URL?

Yes, you can pass parameters in webdynpro URL and read them too in your web dynpro component.


Example: http://domainname.com:8000/sap/bc/webdynpro/sap/zdemo_webdynpro?sap-language=EN&var1=4500000001&var2=00010


Question 29: How do you read parameters passed in the Web Dynpro URL?


First lets understand how a typical webdynpro application looks like:
When you create a web dynpro application , you can see the link URL generated by web dynpro.
It will be something like: http://domainname.com:8000/sap/bc/webdynpro/sap/zdemo_webdynpro?sap-language=EN&sap-client=100.

Whatever comes after the ‘?’ and is followed by ‘&’ is an URL parameter. You can see sap-language and sap-client as default parameters whenever you launch your web dynpro in browser. The cool thing is you can add some custom variables too. http://domainname.com:8000/sap/bc/webdynpro/sap/zdemo_webdynpro?sap-language=EN&sap-client=100&var1=4500000001&var2=00010.


So var1 and var2 are custom webdynpro URL parameters and you can read them in the HANDLEDEFAULT method of your main window:


How to read url parameters in Web Dynpro ABAP


Question 30:
 Can you run a Webdynpro Application in background?

This is a tricky question. It doesn’t make sense to run a webdynpro application in background because in that case you are beating the purpose of the MVC controller architecture for webdynpro. However, you can build logic to create background jobs from a Web Dynpro Application. 


So we have by now put a bunch of questions here . Let me know how do you find these questions.
We haven't yet covered Web Dynpro component usage , ALV, Select Options , OVS , the coding part in web dynpro, Web dynpro enhancements etc.



Question 31: What is Web Dynpro Component Usage?
Real world business scenarios are quite complex and may involve multiple Web Dynpro Components.
While dealing with multiple WD components, you may come across a situation where you need to reuse already developed parts of an existing Web dynpro component.The Web Dynpro framework provides you with a technique called ‘Component Usage’, with the help of which you can reuse the events, methods, and context of one WD component into another WD component.
Standard examples of Component Usage: Select Options , ALV , OVS.
You declare component usage both at the Component and at the view levels:

@Component Level:



 Component Usage in Web Dynpro


@View Level:



 Web Dynpro Component Usage

Question 32: Briefly explain how will you use implement Select Options in Web Dynpro?
1) Declare Component Usage for Standard WD component WDR_SELECT_OPTIONS both at component and view level.
 Select Options in Web Dynpro


Select Options Component Usage in Web Dynpro



2) Place a VIEWCONTAINER on your main view and embed the view ‘WND_SELECTION_SCREEN’ of component WDR_SELECT_OPTIONS in it.
 Select Options in Web Dynpro


3) Use the methods CREATE_RANGE_TABLE and ADD_SELECTION_FIELD for your fields on Selection screen.


4) Use method GET_RANGE_TABLE_OF_SEL_FIELD to read user input before you do a SELECT.


Question 33: What is the Web Dynpro Phase model?
Whenever a roundtrip occurs from the client (browser) to the server, a sequence of processing steps is executed. This sequence of processing steps in web Dynpro is called the ‘Phase Model’.
Executing all the tasks in the phase model is the responsibility of the Web Dynpro framework.
Each step is executed only once and errors if any are captured.If you want to get into the details , have a look at the webinar from Chris Whealy: Understanding the Web Dynpro Phase model. 

Important



Question 34: What is OVS? Can you explain the different phases used in OVS?
First we should understand the difference between Value help and OVS i.e. object Value Selector.
We use generic Value Help only for the field to which it is bound.
OVS is used when we want to populate multiple fields based on one field on the screen.

 OVS in Web Dynpro

So as per the screenshot , If I select Userid from OVS help, First name and Last name will be populated automatically. The standard component WDR_OVS is used for implementing OVS.

OVS works on the PHASE MODEL and different tasks are performed during different phases.
The current phase is indicated by the parameter PHASE_INDICATOR.

Phase 1:

In this phase you have the possibility to define the texts, if you do not want to use the defaults: So You can play around with the highlighted texts in the screenshot below in this phase.
Here we call the method ovs_callback_object->Set_Configuration
 Phase 1 in OVS in Web Dynpro




Phase 2:


If you do not want the filter fields, you can do that in this phase and the table will be displayed directly. Refer screenshot below. The table is displayed directly. I have blurred some results.Here you can call the method ovs_callback_object->Set_Input_Structure


 OVS Phase 2 web dynpro



Phase 3:
In this Phase, You write the select queries that should run as per user input when the user hits ‘Start Search’ button and finally set the output table.You can call the method ovs_callback_object->Set_Output_Table for that purpose.Phase 4:
In this phase , you pass the selected record to the Web dynpro Fields.
i.e. set the attributes using  ovs_callback_object->context_element->Set_Attribute
 OVS - Object Value Selector in Web Dynpro


 Question 35: Briefly explain how will you implement ALV in Web Dynpro?

To implement ALV in Web Dynpro, you need to use the Standard WD component SALV_WD_TABLE.
We need to use:
a) the view ‘TABLE’ of component SALV_WD_TABLE
b) the node ‘DATA’ of component SALV_WD_TABLE.
Here is the brief process:1) Declare component Usage for SALV_WD_TABLE at the WD component level and the view level.
@ Component Level:



 


@ View Level:


 


2) Put a VIEWCONTAINER UI element on the MAIN view and ember the view ‘TABLE’ of
SALV_WD_TABLE
into it.

 




3) Let’s say the ALV data is to be populated in NODE_FLIGHT.
Write the logic to select the ALV Data and bind it to NODE_FLIGHT:
node_flight_alv->BIND_TABLE( lt_node_flight_alv ).

4) Do a Context mapping between NODE_ALV and the node ‘DATA’ of SALV_WD_TABLE.


 




Question 36: How to make columns in a table editable?
While doing the Binding for the Table, just choose 'Input field' instead of 'Textview'.
Refer the Screenshot below:

 table in web dynpro


editable table in web dynpro



Question 37:
How will you delete selected rows in a Table / ALV?
Get the Table / ALV data in an internal table.
Delete the row selected by the user from the internal table.
Re-bind the internal table to the node bound to the Table/ALV.Question 38: How do you generate POP UP in WD?
This can be easily done using the Wizard:
The CREATE_WINDOW method is used in this case.



 Pop Up in web dynpro


Question 39: How do you close a window in Web Dynpro?

There is a special outbound plug called ‘Exit Plug’ that can be used for this purpose.
wd_this->fire_to_exit_plg( url = url close_window = close_window ).

Exit plug in Web DynproAlso explore other Plug Types:

Inbound Plug Types for Window in Web dynpro ABAP

I am going to add some more questions to part 3 :
Let me know if you need answers to the below questions by putting your comments below:

Question:
What is the difference between Drop down by key and drop down by index ?

Question: How do you display error / success / warning messages in Web Dynpro ?

Question: How do you access methods of component controller in a view ?

Question: Have you worked on roadmap UI element ? Elaborate .

Question: What is dynamic ALV in web dynpro ?

Question: Can you have Totals and Subtotals in Web dynpro ALV ? How ?
Hint: First get the reference of the ALV. Then get the columns.
By looping at lt_columns , get to the required column.
Once you achieve this, check methods create_aggr_rule and create_sort_rule of the class
cl_salv_wd_field.

Question:
 Can you have TOP OF PAGE and END OF PAGE ? How ?
Hint: Check TOP_OF_LIST and END_OF_LIST events.

Question: Have you worked on events in ALV in web dynpro? 
                  Which events do you know?
 Events in web dynpro ALV

Question: Can you add custom buttons on Web Dynpro ALV toolbar ? How?

 custom buttons in web dynpro ALV

Question: Can you add custom buttons in Web Dynpro ALV cells ? How?

custom buttons in ALV cells in web dynpro



Question: Can you add Image / Icons in Web Dynpro ALV cells ? How?
How do you define and implement action handlers for them?
 icons and images in web Dynpro ALV


Question: Can you add links in Web Dynpro ALV cells ? How?  

I hope this blog helps you crack your web dynpro interview









How to activate a Trace for a user in SAP system ?

How to activate a Trace for a user in SAP system ?


This article answers the following queries :

  • What are the different types of traces in SAP ?

  • How to activate a Trace for a user in SAP system ?

  • How to do performance analysis in SAP system ?

What are the different types of traces in SAP ?

  • SQL Trace (Trace for SQL statements)


  • Enqueue Trace (Trace for enqueue/lock requests, waiting etc)


  • RFC Trace


  • Table Buffer Trace

How to activate a Trace for a user in SAP system ?

Goto transaction ST05  and you will get the below screen :



Select the type of trace you would like to activate and press activate trace to start tracing.

Please find below functionality of various functions in the above screenshot :

Activate Trace : This is used to activate the trace for the same user who is starting the trace



Activate Trace with Filter :  This functionality is used to trace the activity of a different user(other than the user who is starting the trace) and filter can be done to trace a  specific transaction or program.



Deactivate Trace :  This functionality is used to deactivate the trace




Display Trace :   This functionality is used to display trace



Click on tick mark to display the trace



Click on Yes to display the trace as below:



Enter SQL Statement : This functionality is used to analyse an SQL statement

Click on this pushbutton to view the below screen :



Trace Status : This area is used to inform about the status of the trace at that point of time like traces activated, deactivated etc