ABAP – Parsing VAKEY in SD pricing conditions

SAPIt is possible to parse VAKEY (100 chars) field to separated key fields manually, knowing the structure of each condition table (A004, A055, …).

But there much easier way: Function modules to generate VAKEY (a key for condition tables KONH – condition headers, KONP – condition details, KONM – quantity scale, KONW – value scale) and vice versa – parse key fields from given VAKEY knowing the condition table name.

DATA:
  ls_komg    TYPE komg,     " Allowed Fields for Condition Structures
  lv_vakey_1 TYPE vakey VALUE '106002B1050000 1097631S50',
  lv_vakey_2 TYPE vakey.

* 1. Get key fields for given VAKEY and condition table
CALL FUNCTION 'SD_CONDITION_KOMG_FILL'
  EXPORTING
    p_kotabnr = '005'   "table name is A005 (here we use '005')
    p_kvewe   = 'A'     "table name is A005 (here we use 'A')        
    p_vakey   = lv_vakey_1
  IMPORTING
    p_komg    = ls_komg.

* 2. Get VAKEY from given key fields and condition table
CALL FUNCTION 'SD_CONDITION_VAKEY_FILL'
  EXPORTING
    p_kotabnr = '005'
    p_kvewe   = 'A'
    p_komg    = ls_komg
  IMPORTING
    p_vakey   = lv_vakey_2.

* Just verify that generated VAKEY is equal to the original VAKEY
IF lv_vakey_1 = lv_vakey_2.
  WRITE 'OK'.

ENDIF. 

Leave a Reply