Tag Archive for 'SAP'

SAP: Dynamic Sapgui Progress Indicator

It is very easy to apply a progress indicator on your abap programs. This will enable the

user to determine how much long will he wait until the program finish its processing.

This is done by simply calling the function module SAPGUI_PROGRESS_INDICATOR.

 
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
  EXPORTING
    VALUE(PERCENTAGE) DEFAULT 0
    VALUE(TEXT) DEFAULT SPACE

PERCENTAGE is where you indicate the percentage of processing time and the TEXT is

where you indicate the text to be displayed on the status bar. This parameters can be

set with static values. But if you want, you could also add a few line of codes to make your

progress indicator dynamic and based on the actual number of records being process. This tip

is applicable when you are querying and processing a record from a database.

First you have to declare three decimal variables, see example below.

 
DATA:   v_percent    TYPE p DECIMALS 4,	"holds the actual percentage of process time
        v_increment  TYPE p DECIMALS 4, "holds the increment value per single loop
        v_mod        TYPE p DECIMALS 4. "used as indicator

Now refer to the lines below for the rest of the codes.

 
****Your select statement goes here******
 
* this will determine the increment value based on the result of the select statement
  v_increment = 100 / sy-dbcnt.
 
  LOOP AT it INTO wa.
*calculate the progress percentage on every single loop
    v_percent = v_percent + v_increment.
 
*this codes indicates that I want to update my progress indicator every 5% increase
*in percentage. you can change this anytime you want.
    v_mod = v_percent MOD 5.
    IF  v_mod  < 1.
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
        EXPORTING
          percentage = v_percent
          text       = 'Processing, please wait.'.
    ENDIF.

Creative Commons License

SAP: Setting Up Logon Rules

Go to transaction code RSPFPAR_LOGIN. It will give you a complete list of parameters for Logon Rules. Just refer to the Comment field for the parameter definition.

These parameters can be maintain through Profile Maintenance (RZ10). When SAP startup process reads a profile parameter, it checks first on the Instance Profile. If the parameter cannot be found on the instance profile then it will look on the Default profile. If neither profile contains the parameter, the default value is taken out of the startup program coding. With that, I suggest you to create or maintain parameters in Default Profile. Just ensure that a particular parameter appears only in the default and not in the instance profile.

For the profile to take effect, you have to restart your application server.

Creative Commons License

SAP: Clickable Icon Button in ALV fields


Adding a button inside an ALV fields is a very simple task to do which needs only a few line of codes. what I always do is I create a field on ALV and populate that field with an Icon of my choice and declare it as a Hotspot so it will react on a single click and it works perfectly just like a button.

First Thing to do is to specify a field in our internal table that we will use to hold the Icon(refer to code #1).

 
TYPES: BEGIN OF t_alvbutton,
          icon TYPE string,      "icon field
          kunnr LIKE kna1-kunnr,
	  name1 LIKE kna1-name1,
	END OF t_alvbutton.
 
DATA: it_alvbutton    TYPE STANDARD TABLE OF t_alvbutton,
      wa_alvbutton	TYPE t_alvbutton.

Proceed to the data retrieval and populate the it_alvbutton. I assume you know how to retrieve data from database so there’s no need to show you the select statement for our example. After that, loop on every records of it_alvbutton to specify the Icon that we want to display(refer to code #2).

 
LOOP AT it_alvbutton INTO wa_alvbutton.
	wa_alvbutton-icon =  '@0X@'.
	MODIFY it_alvbutton FROM wa_alvbutton.
ENDLOOP.

@0X@ is the code for print icon. For the complete list of icons, check it out here.

Now the important part is to define a field in ALV that will hold the icon. To show you how simple it is to do that, please refer to code #3.

 
DATA:	ls_fieldcat TYPE slis_fieldcat_alv,
	lt_fieldcat TYPE slis_t_fieldcat_alv.
 
DEFINE m_fieldcat.
	add 1 to ls_fieldcat-col_pos.
	ls_fieldcat-fieldname = &1.
	ls_fieldcat-seltext_l = &2.
	ls_fieldcat-outputlen = &3.
	ls_fieldcat-hotspot = &4.   "X to declare the field as a hotspot
	ls_fieldcat-icon = &5.      "X to declare the field as an icon
	append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
 
m_fieldcat 'ICON' 'Print' '20' 'X' 'X'.  "this specific field is a hotspot and an icon
m_fieldcat 'KUNNR' 'Customer No.' '10'.
m_fieldcat 'NAME1' 'Customer Name' '35'.
m_fieldcat . . .
m_fieldcat . . .
 
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
	. . .
	. . .

The figure below shows an example of print icon as a button.

Icon Button in ALV

Now refer to code #4 to handle the command when a user clicks on the icon button.

 
FORM f_user_command USING ucomm LIKE sy-ucomm
		  v_selfld TYPE slis_selfield.
 
IF ucomm = '&IC1' AND v_selfld-fieldname = 'ICON'.
	"code goes in here when user clicks on our print button
ENDIF.

Creative Commons License

SAP: List of Icons

I could show you here the complete list of icons with its corresponding code but I rather show you a couple line of codes that will provide you the list of icons. So please refer to the code #1.


TABLES: icon.
DATA: icontext(4) TYPE c.
SELECT * FROM icon.
  WRITE: / icon-id+1(2).
  CONCATENATE '@' icon-id+1(2) '@' INTO icontext.
  WRITE: 10 icontext AS ICON, icon-name.
ENDSELECT.

Create a blank program on transaction SE38 and add the code above. Just activate it and execute. You now have your own list of icons for your reference whenever you need it.

SAP: Basic of Lock Objects

Data inconsistency occurs when two or more users are editing/changing the same record on the same table at exactly the same time. To avoid this, we use Lock Objects.

Lock Objects enables the user to request a lock on a specific record before accessing it. In this way, changing/editing of records is only possible one at a time, thus avoiding data inconsistency.

There are three different lock modes:

exclusive lock/Write Lock (Mode ‘E’)
allow you to prevent data from being changed while you are changing it yourself. An exclusive lock, as its name suggests, locks an application object for exclusive use by the program that sets it. No other program can then set either a shared lock or an exclusive lock for the same application object.

Shared Lock/Read Lock (Mode ‘S’)
allow you to prevent data from being changed while you are reading it. They prevent other programs from setting an exclusive lock (write lock) to change the object. It does not, however, prevent other programs from setting further read locks.

Enhanced write lock (Mode ‘X’)
works like a write lock but are not accumulated while a program is being executed. It protects from further accesses within the same transaction.

To create a Lock Object, got to transaction SE11, click on Lock Object radio button and enter any name that starts with EZ or EY. (Example EZSAMPLE_LOCK)

When you activate a lock object, the system generates an ENQUEUE_ and a DEQUEUE_ function module that you can use on your ABAP programs.

ENQUEUE_<lockobject name> - adds the requested object in a queue(lock)
DEQUEUE_<lockobject name> - remove the requested object from being queued(unlock).

The basic procedure on requesting a lock:
1. Enqueue and lock the object for editing.
2. Read/write the data from the database.
4. dequeue and release the object.

To implement Lock Objects in ABAP programs, please refer to this post.