Debugging a CAP project in SAP Business Application Studio (BAS) is quite easy, as BAS provides built-in debugging support for the Node.js runtime.
Watch the video to see how to switch on debug mode.
Objective
Debugging a CAP project in SAP Business Application Studio (BAS) is quite easy, as BAS provides built-in debugging support for the Node.js runtime.
Watch the video to see how to switch on debug mode.
Breakpoints can be set by clicking on the left edge of the editor or by pressing F9 in the current line. A red dot appears to indicate that a breakpoint has been set for this line.
If you click on a set breakpoint again, it will be removed.
As soon as a request hits a line with a breakpoint, the debugger in BAS pauses execution and allows you to check variables, watch expressions and control the flow.
In the Run and Debug view, the following sections are displayed, among others, which can contain helpful information when debugging:
The Variables section shows the current values of the variables in scope.
In the Watch section, you can add any expressions that you want to keep an eye on when stepping through the code.
The Call Stack section shows the current call stack.
The toolbar displayed in debugging mode allows you to control the flow of the application during debugging (see following figure).
Buttons are available to continue, step over, step in, and step out.
You can also restart the debugging session via the toolbar if you have made changes to the code.
To stop the debugging session, click on the red square button in the toolbar.
Note
As exercise, carry out the step-by-step instructions in the following demonstration yourself in the SAP Business Application Studio.
As a starting point for the exercise, use the outcome of the previous exercise Provide a .before Event Handler if you have successfully completed it. Alternatively, you can also use the branch 11_.before_event_handler from the following GitHub repository as a starting point:
https://github.com/SAP-samples/cap-development-learning-journey
Detailed information on the content of the repository and how to use it can be found here.
Watch the video to see how to debug a custom event handler.
Log in to track your progress & complete quizzes