Oct 8, 2011

How to Debug Popup Screen in ABAP

Debugging in ABAP for ABAP developers is a vital requirement during building application in SAP systems. There are numerous ways to debug ABAP code or debug SAP screens for ABAP developers. But many ABAP programmers who are new to ABAP development may not know how to debug popup screen in SAP platform. In this short ABAP tutorial, I'll try to share you ABAP trick to debug SAP popup screens.

Please note that, this tutorial does not cover debugging using "/H" option or using break points in ABAP code. I want to concentrate on developers requirement to debug an unknown ABAP code block which they want to discover.

First step is open your Notepad application and type or copy-paste the following commands in a new blank text file.

[FUNCTION]
Command=/H
Title=Debugger
Type=SystemCommand

Then save the above text file as a batch file. You can name it as debug.bat for example.

Now ABAP developers are ready to debug a modal popup SAP screen. Let's assume that you want to debug output processing log screen for an invoice output

ABAP debugging tips to debug popup screens in SAP

Now drag and drop debug.bat batch file from your Windows desktop onto the modal popup SAP screen.
Then the SAP GUI will inform you about the debugging status with message "Debugging switched on"

SAP screen debugging switched on

Now ABAP developers can easily activate debugging screen in ABAP on the modal popup SAP screen.



How to debug Smartforms

Debugging SmartForms using Function Module

If you want to debug Smartform document in non-modifiable client, then you can try debugging Smartforms Function Module using soft break point.

First you need to find the function module name of the target SmartForm for debugging.
If you do not know how to get the function module name of the SAP Smart Form, please read the Smart Form tutorial titled How to Find SAP SmartForms Function Module Name.
Without knowing the function module name, we can not debug SmartForms in non-modifiable clients.

After you find the function module name, we can now display the ABAP source codes of the SSF FM (Function Module) using the SAP Transaction SE37.

Within the ABAP codes of Smartform FM you can put a soft break-point any where suitable for your debugging Smartforms purposes.

It is better to copy the node name or some parts of the ABAP code in the SAP Smartform and search the text within the SE37 displayed source code of the Smartforms function module (FM).

You can place a soft break point in the source code using Ctrl+Shift+12 key combination or using the Stop icon sap-stop-icon-to-debug.

Let's assume that you want to debug Smartforms codes within program lines named '%CODE10' as seen in the followin Smartform screenshot,

search-code-node-in-sap-smart-form-function-module

First click on the Search button sap-search-icon-to-find-text-in-code, and not use the Ctrl+F since searc button has far more powerful functionalities than ordinary Ctrl+F search.

Enter the text you are searching in the Find text area.
You can search for the node name '%CODE10' as well as for a part of your SmartForm code.

What is important here in this Search is be sure that you selected the option "In main program".
Otherwise your search will take place only for a limited part of the Smartform function module codes.

search-code-node-in-sap-smart-form-function-module-main-program

When the place of the target code block is found, you can run the SAP Smart Form and start to debug Smartform document.

SAP Smartforms - How to Call Smartform within Example ABAP Program

Here is an SAP Smartforms step by step example to open and call Smartform within ABAP code.
Within ABAP programs an SAP Smartform can be called and opened by calling the ABAP function SSF_FUNCTION_MODULE_NAME, we will see in the example ABAP code which is included with this Smartforms tutorial.

First, create a SAP Smartform report using ABAP transaction code "smartforms" within ABAP Editor.
Or you can use an existing simple SAP Smartforms report to call from the example ABAP program.

In this SAP SmartForms tutorial, the example uses a SmartForm named "ZSMARTFORMS_SALES_DOCUMENTS".
The SmartForm application "ZSMARTFORMS_SALES_DOCUMENTS" takes a table valued parameter to use as an internal table within SmartForms ABAP codes.
This SmartForms parameter table is "it_vbak" which is declared in type table of VBAK SAP Sales and Distribution table.
SAP VBAK table is contains Sales Document header data.
As you will see in the below ABAP codes, the program select a range of VBAK Sales Document records into an internal table variable it_vbak.
Later the variable table is passed to the SAP SmartForm as a TABLE argument.

It is important that the table variable is correctly declared within the Smartform 's "Global Settings > Form Interface > Tables" section.
As you will see in the below screenshot, it_vbak is declared as :
IT_VBAK TYPE VBAK

sap-smartforms-global-settings-form-interface-tables-variable-declaration


Example ABAP Program to Call Smartform

Here is the example ABAP code to call SAP SmarForms from a program or an ABAP report.
Please note that we have ABAP codes which call ABAP function SSF_FUNCTION_MODULE_NAME with formname parameter is set to the target SAP Smartforms document.
The SSF_FUNCTION_MODULE_NAME ABAP call returns the FM_NAME which is the compiled ABAP program identifier and is in type rs38l_fnam.
The returned fm_name variable is then called using an ABAP Call Function method to open Smartform.
While calling Smartform, the Table parameter is passed as an input argument.

*&--------------------------------------------------------------*
*& Report Z_CALL_SMARTFORM *
*& Sample Function calls ZSMARTFORMS_SALES_DOCUMENTS smartform *
*&--------------------------------------------------------------*

REPORT Z_CALL_SMARTFORM.

DATA :
fm_name TYPE rs38l_fnam,
it_vbak TYPE TABLE OF vbak.

SELECT * FROM vbak into TABLE it_vbak
WHERE vbeln GE '0100000004'
AND vbeln LE '0100000010'.


CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZSMARTFORMS_SALES_DOCUMENTS'
IMPORTING
FM_NAME = fm_name
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3.

CALL FUNCTION fm_name
TABLES
it_vbak = it_vbak
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5.

I hope, SAP Smartforms developers will find this sample ABAP code useful as beginning to SAP Smartforms.


How to Spell Numbers using ABAP Spell_Amount Function Module

SAP professionals can use ABAP Spell_Amount function module in order to spell numbers and currency values into string variables. It is very easy in different languages the answer of "How to Spell Numbers in SAP" using Spell_Amount ABAP function module.

In this ABAP tutorial, developers will find a sample ABAP report using Spell_Amount to convert numeric value or currency amount entered in the selection screen into string and display on the screen using Write command

What makes Spell_Amount perfect for spelling price, amount fields and number values is it can spell in different languages. The Spell_Amount function module excepts a Language input parameter and returns the spell in the input language. Either German, English, Turkish, Spanish, Russian, ABAP developers can easily return decimal values and integer part of the number seperately easily.

Since the Spell_Amount return a SPELL type structure, developers should be aware of both fields word and decword of the output structure. The decword will return limited values from 0 to 99 for example. But the integer part word can handle greater numeric values.

Here is the ABAP report source code that ABAP developers can use in order to convert numeric values, numbers and currencies into string. The following ABAP report is using Spell_Amount in order to spell numbers into string variables and display on the output screen.

PARAMETERS:
pLANGU LIKE T002-SPRAS DEFAULT SY-LANGU,
pCURR LIKE TCURC-WAERS DEFAULT 'USD',
pAMOUNT LIKE VBAP-MWSBP ,
pFILLER(1) TYPE C DEFAULT ' '.

DATA :
WS_SPELL TYPE SPELL.

CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
AMOUNT = pAMOUNT
CURRENCY = pCURR
FILLER = pFILLER
LANGUAGE = pLANGU "SY-LANGU
IMPORTING
IN_WORDS = WS_SPELL
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 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.
ELSE.
WRITE :/ WS_SPELL-word , WS_SPELL-decword.
ENDIF.

Here is the selection screen of the ABAP report ZSPELLAMOUNT.

spell_amount function module

And this is the output screen displaying the spelling of input number value in given language

ABAP Spell Amount FM



Create Number Range Object using SAP Transaction Code SNRO

ABAP developers and SA professionals require an auto number field especially in the key fields of a database table during ABAP coding in their SAP applications.

Actually an auto incrementa field is a general requirement for al developers in all development environments and platforms
In SAP environment the solution is creating to create number range object and use number range object in ABAP codes for ABAP developers
Actually, database providers like Microsoft SQL Server and Oracle have more advanced solutions for such requirements that does not require maintanence and so much steps in number range creation process.

Let's start our task in this SAP tutorial, number range creation using SNRO SAP Transaction code.


Step by step Number Range Creation using SNRO SAP Transaction

In SAP Easy Access screen, call SAP transaction code SNRO

sap-transaction-code-snro-for-number-range

Enter Number Range name in the Number Range Object input text field.

sap-transaction-code-snro-number-range-screen

Enter Short Text and Long Text descriptive texts for Number Range Object.

Enter a number length domain for the number range object

If you want a warning define an integer smaller than 100 in the Warning % field.
You can enter 5 or 10 as common warning percentage values.

sap-transaction-code-snro-create-number-range-for-auto-number

Click on the Save button sap-save-button to save the number range definition.

sap-buffering-methods

Click on Yes button to continue.
The next screen displayed is Create Object Directory Entry screen.

sap-abap-create-object-directory-entry-for-number-range

I select Local Object

Now the Change documents and Number ranges buttons are displayed in the Number Range Object : Change SAP screen.

Click on "Number ranges" button.

change-number-range-object-abap

Click on Change Intervals buttons.

sap-change-intervals-in-number-range-object

Click on "Add Interval" button sap-number-range-add-interval-button

sap-maintain-number-range-intervals-screen

Enter an integer number like 1 at interval number and a range of numbers with integer values identifying from number and to number. If you have entered required fields press Enter button.

insert-interval-for-number-range-intervals-in-sap

Click on "Save" button. And the number range interval you have just declared will be listed in the Number Range object 's number intervals list.

snro-number-range-object-number-intervals-list

The following "Transport number range intervals" warning screen is displayed.

snro-abap-transport-number-range-intervals

The number range intervals are not included in automatic recording of customizing changes. Transport of all the changes made within number range interval maintenance must be triggered manually.

In the initial screen for number range interval maintenance choose the function Interval -> Transport.

Please note the information that you get when transporting number range intervals.

Here is the display screen of the Number Range object.

sap-snro-display-number-range-object


SAP professionals and ABAP developers have seen how to create Number Range Object till this point in this SAP tutorial.
Now ABAP developers are readyto go further and learn how to use number range objects in ABAP code.
Key ABAP function for implementing and using a number range in ABAP codes is NUMBER_GET_NEXT ABAP function.
In order to use a number range for auto increment column numbers safely in SAP, NUMBER_GET_NEXT ABAP function is used with NUMBER_RANGE_ENQUEUE and NUMBER_RANGE_DEQUEUE.

ABAP developers can copy and paste the following ABAP report source code and execute the ABAP program in their development and test environments.
The sample ABAP report reads the next number in an SAP Number Range Object and displays the auto number value on the screen.
The ABAP NUMBER_RANGE_ENQUEUE function sets a lock on the number range object.
If the lock is successfully set on the SAP number range, using NUMBER_GET_NEXT function call the next number in the number range interval is read and passed into an ABAP variable.
The last step is calling NUMBER_RANGE_DEQUEUE function and removing the loc on the relate SAP number range object.

REPORT ztreenodes .

" INRI : Number ranges function module interface structure
CONSTANTS :
" Name of number range object - CHAR 10
c_rangeobj LIKE inri-object VALUE 'Z_TREENODE',
" Number range number - CHAR 2
c_rangeno LIKE inri-nrrangenr VALUE '1'.

DATA : " NodeId from Number Generator Object
gv_nodeid TYPE i.


START-OF-SELECTION.

PERFORM nextnum USING gv_nodeid c_rangeobj c_rangeno.
WRITE gv_nodeid.

END-OF-SELECTION.

FORM nextnum USING

le_nextnum TYPE i
le_rangeobj LIKE inri-object
le_rangeno LIKE inri-nrrangenr.

DATA :
lv_nextnum TYPE i.

CALL FUNCTION 'NUMBER_RANGE_ENQUEUE'
EXPORTING
object = le_rangeobj
EXCEPTIONS
foreign_lock = 1
object_not_found = 2
system_failure = 3
OTHERS = 4.
IF sy-subrc NE 0.
* message e086 with 'Lock error' sy-subrc.
ENDIF.

CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = le_rangeno
object = le_rangeobj
* QUANTITY = '1'
* SUBOBJECT = ' '
* TOYEAR = '0000'
* IGNORE_BUFFER = ' '
IMPORTING
number = lv_nextnum " Number generated by Range Generator Object
* QUANTITY =
* RETURNCODE = lv_returncode
EXCEPTIONS
interval_not_found = 1
number_range_not_intern = 2
object_not_found = 3
quantity_is_0 = 4
quantity_is_not_1 = 5
interval_overflow = 6
buffer_overflow = 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.

CALL FUNCTION 'NUMBER_RANGE_DEQUEUE'
EXPORTING
object = le_rangeobj.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

le_nextnum = lv_nextnum.

ENDFORM. " NEXTNUM

I hope ABAP developers will fing this number range and NUMBER_GET_NEXT function call implementation useful.