Showing posts with label SAP ABAP Tips and Tricks. Show all posts
Showing posts with label SAP ABAP Tips and Tricks. Show all posts

Thursday, December 20, 2007

Building A Binary Table

This program demonstarte how to build and print a binary tree of random numbers.

There is a separate process for storing random numbers and sorting them to compare with print tree results.

The code has explanatory comments.

Code:

*&---------------------------------------------------------------------*
*& Report YBINTREE - Build/Print Binary Tree of numbers *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

REPORT YBINTREE .



types: begin of stree,
value type i,
left type ref to data,
right type ref to data,
end of stree.


data: tree type stree.
data: int type i.

data: begin of rnd occurs 0,
num type i,
end of rnd.

start-of-selection.


do 100 times.

* generate random number between 0 and 100
CALL FUNCTION 'RANDOM_I4'
EXPORTING
RND_MIN = 0
RND_MAX = 100
IMPORTING
RND_VALUE = int.

* store numbers
rnd-num = int.
append rnd.

* build binary tree of random numbers
perform add_value using tree int.

enddo.

* stored numbers are sorted for comparison
sort rnd by num.

* print sorted random numbers
write: / 'Sorted Numbers'.
write: / '=============='.
skip.
loop at rnd.
write: rnd-num.
endloop.

skip.

* print binary tree. This should give the same result
* as the one listed from the internal table
write: / 'Binary Tree List'.
write: / '================'.
skip.


perform print_value using tree.
skip.

*&---------------------------------------------------------------------*
*& Form add_value
*&---------------------------------------------------------------------*
* text - Build tree with value provided
*----------------------------------------------------------------------*
* -->TREE text
* -->VAL text
*----------------------------------------------------------------------*

form add_value using tree type stree val type i.

field-symbols: type any.
data: work type stree.

if tree is initial. "When node has no values
tree-value = val. " assign value
clear: tree-left, tree-right.
create data tree-left type stree. "Create an empty node for left
create data tree-right type stree. "create an empty node for right
else.
if val le tree-value. "if number is less than or equal
assign tree-left->* to . "assign the left node to fs
* call add_value recursively with left node
perform add_value using val.
else. "if number is greater
assign tree-right->* to . "assign the right node to fs
* call add_value recursively with right node
perform add_value using val.
endif.

endif.


endform. "add_value




*&---------------------------------------------------------------------*
*& Form print_value
*&---------------------------------------------------------------------*
* text - traverse tree from left-mid-right order
* automatically this will be sorted list
*----------------------------------------------------------------------*
* -->TREE text
*----------------------------------------------------------------------*
form print_value using tree type stree.
field-symbols: type any.


if tree is initial. "node is empty
else. "non-empty node
assign tree-left->* to . "left node
perform print_value using . "print left
write: tree-value. "print the current value
assign tree-right->* to . "right node
perform print_value using . "print right
endif.

endform. "print_value

how can we change the font for weite statement

any answer

Import graphics to SAP

Use transaction SE78 to import graphics to SAP.

To Include graphics in the form there are two ways-
1. In the form painter,use menu Edit->Graphic->Create
2. Using the INCLUDE statement in a window.

To use an INCLUDE statment, in the script editor and use menu Include->Graphic. The include can look like this for a bitmap:
/: BITMAP MYLOGO OBJECT GRAPHICS ID BMAP TYPE BMON

Uploading Graphics TTF files into SAp Script Text

Using Program RSTXLDMC(Upload TTF files into SAP Script Text), the graphics file .ttf can be uploaded from Desktop to individual standard text.

Execute the program RSTXLDMC and provide input to the select screen like file name, type standard text etc..
Press F8

Schedule Background Job

ABAP Editor transaction SE38 can be used to execute program in the background. In SE38 selection screen click on Program -> Execute -> Background and specify the name of the variant. You can schedule the program to run once at a certain time or periodically every month, week, days, hours or minutes.

Moreover Transaction SM36 can be used to Schedule Background Job without selections parameters.

Click on the steps, A popup window will open, Click on ABAP/4 button. The fields ABAP/4 Program name, Variant and Language will become input enable. Type the program name and save it by pressing on save Icon. Now Click on start condition, a popu up will appear asking about start date or Immediate etc.. pls provide applicable details and press on save Icon. and now finally press on Save Icon

From 4.6c onwards you will also see one more button "Job Wizard", this option can also be used to define the Job steps. Also Transaction SM36WIZ is the same as "Job Wizard".

How to change Package name/Development class for any object

Using program RSWBO052 (Change Object Directory Entries), We can change package name/Development class for any object like SAP Script or TAble or Program etc...

Execute the Report RSWBO052.
Provide selection parameter values
Press F8
Select a line or Object name
Press F6
Than go to Objects->Change Object Directory

Useful User Paramters

Useful User Paramters
GR8 - File Download Path default
GR9 - File Upload Path default
TTD - SAPScript Form Debugger (X = start debugger)

Finding a transaction code via SE93

Go to Transaction SE93 and press F4 and then Press All selections button. It will give you a better search to look for a transaction than directly going to table TSTC.

Standard Conversion Exits

Most conversion exits used in screens by SAP are actually function modules. You can find them by searching for CONVERSION_EXIT_name_INPUT and CONVERSION_EXIT_name_OUTPUT.

How to transport Standard Texts

Either execute the Program RSTXTRAN
or

Enter directly in transport:
R3TR TEXT TEXT,Text Name,ST,Language

Search SAP Menu

To search SAP menu on the initial screen, there is a transaction code SEARCH_SAP_MENU,

This transaction invokes a dialog for Search Text Entry :
You can enter TCODE or Menu text here, wildcards are allowed.
This transaction comes handy when you have to locate Tcodes or Menu text

A FM which can create internal session

There is a function module called 'SAPGUI_SET_FUNCTIONCODE' that will create a new session dynamically from a program.
Expample:
Report ABAPmaster.
call function 'SAPGUI_SET_FUNCTIONCODE'
EXPORTING
functioncode = '/oSE38'
EXCEPTIONS
function_not_supported = 1
others = 2.

Procedure for uploading Font

1. Get the 'TTF' file of required font.
2. Go to Txn SE73 and click on 'True type font installation'.
3. Enter font name and path of 'ttf' file with both the checkboxes of attributes = blank.
4. Enter RTF text and Press continue, and the font will be available for SmartForm and SapScript.
5. Repeat the procedure for all the combination of Checkboxes of attributes, so that font with all styles will get installed.

Save content of internal tables in Excel format during debugging

Starting in R/3 release 4.7, it is possible to save the content of an internal table during debugging:

1. Display the content of the internal table in the debugger.
2. Then press ctrl-F11 or right-mouse and click "Save As Excel Worksheet".
3. Enter the From-index and To-index for the lines you want to save.
4. Choose folder/filename and save.

Where all SAP ABAP programs get stored!!

ALL ABAP program are stored in table D010S (Till 4.6C). However, you will not able to see this table via SE11/12/16. But you can
read/update this table using native sql.
Example:

exec sql .
select * into :i_tab from D010S where PROG =
'Y000001'
endexec.

NOTE: This table is very IMPORTANT and Sensitive. So please do not play with this table. This may cause adverse affect on your program/system.

Debugging a popup window

To debug a popup, create a text file on your local computer with below texts
[FUNCTION]
Command=/H
Title=Debugger
Type=SystemCommand

Place file on your desktop. To debug a popup drag and drop this file over the popup.

Spool Conversion tp PDF

Program RSTXPDFT4 can be used to convert spool into PDF file

A tips on error message while writting a BDC program

Many SAP transactions behave differently in online mode and in Batch mode and this mode is determined by the SY-BINPT variable that can be controlled using the OPTIONS command in addition to the CALL TRANSACTION.

For example, the error message that usually comes in status bar while you are running the transaction online might appear in a popup window when you are running that in batch. This will make your fields disabled for input. This OPTIONS addition will remove this problem.

The way to use the OPTIONS addition.

Declare a work area of type CTU_PARAMS.
Fill the fields of CTU_PARAMS. The field NOBINPT should be set to �X�.
This will set the SY-BINPT to space. So now the transaction which you will be calling will run in online mode.

Example.

clear X_OPTIONS.

X_OPTIONS-DISMODE = 'E'.
X_OPTIONS-UPDMODE = 'S'.
X_OPTIONS-CATTMODE = ' '.
X_OPTIONS-DEFSIZE = ' '.
X_OPTIONS-RACOMMIT = ' '.
X_OPTIONS-NOBINPT = 'X'.
X_OPTIONS-NOBIEND = ' '.

call transaction 'BP' using T_BDCDATA[] options from X_OPTIONS.

Note:
Do not use the MODE & UPDATE additions when you are using OPTIONS. The mode & update values are passed in the CTU_PARAMS structure.

Blog Archive