Tuesday, March 15, 2011

Easy steps for database checking from Abaper eye view

When The database problems occurred (Slowly, Crash, or Deadlock). What should Abaper do ? Basically we can check as step below to ensure that the problem does not come from our side :P


DB01 : Data base lock monitor. For normally, it should NOT contain any records as below because database acess is fast processing. However if it is show some records because of dead lock we will use PID to trace user and a deadlock transaction from TCode SM51.

ST04N : Database performance Analysis
Basically we can check quality of data buffer more than 95% is acceptable.

SM51 : SAP Server
When double click on some lines. It will call TCode SM50 to show process overview

SM50  : Show process overview that you can check detail of PID (if got from DB01). It will show user,report,table,Reason

Thursday, February 24, 2011

Change price of condition records by BAPI as VK12

VK12 is transaction to change condition records.

Requirement need a program to update pricing of condition records at table A914. For anyone who is finding a BAPI for modify pricing without BDC. I recommend to use standards function module RV_CONDITION_COPY and RV_CONDTION_SAVE to update it.

How to use it ?
Let's we go.

Before program update. at TCode VK12, we will see rate 107.64 EUR
When see data in table A914. Table will keep relationship between material, company code, validity date and condition records number (KNUMH)

Rate was keep in table KONP. Focus on field KBETR 107.64 EUR was shown.

Then try to create the program following coding below,


DATA : wa_key_fields LIKE komg,
lt_copy_records TYPE TABLE OF komv WITH HEADER LINE,
wa_konp TYPE konp.
CLEAR : wa_key_fields, lt_copy_records.
REFRESH : lt_copy_records.

select single * from konp
into wa_konp
where knumh = '0000016269'
and loevm_ko <> 'X'.

wa_key_fields-bukrs = '5730'.
wa_key_fields-matnr = '000000000100017001'.
lt_copy_records-knumv = '0000016269'.
lt_copy_records-kposn = wa_konp-kopos.
lt_copy_records-kappl = 'V'.
lt_copy_records-kschl = 'ZGA1'.
lt_copy_records-kbetr = '33.33'.

lt_copy_records-waers = wa_konp-konwa.
lt_copy_records-krech = wa_konp-krech.
lt_copy_records-stfkz = wa_konp-stfkz.
lt_copy_records-kpein = wa_konp-kpein.
lt_copy_records-kmein = wa_konp-kmein.
lt_copy_records-zaehk_ind = wa_konp-zaehk_ind.
APPEND lt_copy_records.
 
CALL FUNCTION 'RV_CONDITION_COPY'
EXPORTING
application = 'V'
condition_table = '914'
condition_type = 'ZGA1'
enqueue = 'X'key_fields = wa_key_fields
maintain_mode = 'B'
no_authority_check = 'X'
TABLES
copy_records = lt_copy_records
EXCEPTIONS
enqueue_on_record = 1
invalid_application = 2
invalid_condition_number = 3
invalid_condition_type = 4
no_authority_ekorg = 5
no_authority_kschl = 6
no_authority_vkorg = 7
no_selection = 8
table_not_valid = 9
no_material_for_settlement = 10
no_unit_for_period_cond = 11
no_unit_reference_magnitude = 12
invalid_condition_table = 13
OTHERS = 14
.
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 'RV_CONDITION_SAVE'.
COMMIT WORK.
CALL FUNCTION 'RV_CONDITION_RESET'.
COMMIT WORK.



From coding, I set new rate to 33.33 EUR. after execute it. The result was shown as below,
When VK12, Rate was changed to 33.33 EUR

let see at table A914.  There are nothing change!!
 But in table KONP. New rate was updated to 33.33 EUR

Tuesday, February 15, 2011

ME11,ME12 Userexit on save

For TCode ME11,ME12 Create/Change Purchasing Info record (PIR)

When modify conditions and SAVE it will call BADIs Class interface CL_EX_SD_COND_SAVE_A.

See detail at TCode SE24 : Class builder

Within the interface you will see a method CONDITION_SAVE_EXIT.

And when double click in the method, you will see standard coding to call the method and pass parameter as below capture,



 Then we can implement BADIs at TCode SE19 and definition SD_COND_SAVE_A and implement method CONDITION_SAVE_EXIT

Thursday, February 10, 2011

Add icon to button

When create a button on selection screen,

SELECTION-SCREEN PUSHBUTTON /10(25) b_test USER-COMMAND test.

INITIALIZATION.
b_test = 'TEST'.









We only got the plain button.




But I need a user-friendly button that has an icon in the button. We can do by call function 'ICON_CREATE' as example below,

SELECTION-SCREEN PUSHBUTTON /10(25) b_test2 USER-COMMAND test2.

INITIALIZATION.
* add text and icon to push buttonDATA: icon_str(255) TYPE c.
CALL FUNCTION 'ICON_CREATE'
EXPORTING
name = 'ICON_EXECUTE_OBJECT'
text = 'TEST2'
info = 'TEST2 INFO'
IMPORTING
result = icon_str
EXCEPTIONS
OTHERS = 0.

* place text and icon on button
b_test2 = icon_str.

Remove execute(F8) button from standard application toolbar

If your program has its own button to control any events. Then you no need the Execute button anymore. To prevent the error as "Selection screen XXXXX 1000 was not called using CALL SELECTION-SCREEN" occurred. Then we should to remove it.

add code to remove button ONLI as below,

DATA GT_EXCLUDE TYPE TABLE OF RSEXFCODE WITH HEADER LINE.
 
INITIALIZATION.
  T_EXCLUDE-FCODE  = 'ONLI'.
  APPEND T_EXCLUDE.
 
AT SELECTION-SCREEN OUTPUT.
 
  CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
       EXPORTING
            P_STATUS  = '%_00'
            P_PROGRAM = 'RSSYSTDB'
       TABLES
            P_EXCLUDE = T_EXCLUDE[].



Before
After

Hope it helps.