Skip to Content
1

how do I reverse parse field VAKEY in table KONH for a material

Oct 19, 2017 at 08:23 AM

420

avatar image

We have a need to detect changes in materials in order to update other systems with the changes. We already have working code that gets the proper CDHDR and CDPOS records and then finds the appropriate KONH record that changed which in turn references a material. These records have an OBJECTCLAS of COND_A. We have no trouble getting to the point of finding the correct KONH entry for any particular change either.

The problem we are having is how SAP "encodes" the material number within the VAKEY field in the KONH table. Over the years our users keep on creating new condition types (field KOTANBR) to use and SAP stores the material number differently within the VAKEY field depending on the value in KOTANBR thus necessitating a program change and all the paperwork and overhead that goes with it (and figuring out where the material number actually is and then updating the code.

What we are looking for is either a FM or data or a combination of both or anything that allows us to "parse" VAKEY for the material number no matter what condition type (KOTANBR) is on the record. I found a discussion on a particular function module in the RV_CONDITION area, but none seemed to be the one.

Basically right now we have a large CASE statement that keeps on growing and has to be manually maintained and I am hoping someone knows how SAP "encodes" the material number so that we can decode it without having to know every possible condition type. I have to think there is master data somewhere that drives this process and/or a FM that does it - one for encoding and one for decoding. We hit another new condition type last week, thus the question.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Rob Ariaans Oct 19, 2017 at 09:47 AM
1

What you could do, is check table DD03K for the table (KVEWE+KOTABNR) found from KONH. Then you will get a list of fields used including their length. Search in which position (TABPOS) the MATNR is and add together all lengths of the fields with lower TABPOS and you know at which position the material number starts in the VAKEY. Check if you maybe need to exclude MANDT, KAPPL and KSCHL from the calculation.

Show 2 Share
10 |10000 characters needed characters left characters exceeded

This looks very promising and this was the information I was hoping to get from this post. If this solves it, I will post a code snippet here which shows what I did.

0

Rob - looks like I do need to exclude all three - it fits the pattern - THANK YOU SO MUCH!. As an example for everyone else, here's A306's values:

A306 1 MANDT MANDT MANDT CLNT 3
A306 2 KAPPL KAPPL KAPPL CHAR 2
A306 3 KSCHL KSCHA KSCHL CHAR 4
A306 4 VKORG VKORG VKORG CHAR 4
A306 5 VTWEG VTWEG VTWEG CHAR 2
A306 6 PLTYP PLTYP PLTYP CHAR 2
A306 7 WAERK WAERK WAERS CUKY 5
A306 8 MATNR MATNR MATNR CHAR 18
A306 9 KFRST KFRST KFRST CHAR 1
A306 10 DATBI KODATBI DATUM DATS 8

I had in my code that the material number was at +13, so if you exclude the first three you get 4 + 2 + 2 + 5 = 13
1
Thomas Liebl Oct 19, 2017 at 09:49 AM
1

Just convert the VAKEY to structure KOMG and access the field MATNR there.

  DATA l_program TYPE trdir-name.

  PERFORM set_access_program IN PROGRAM sapmv130
               USING p_kvewe p_kotabnr l_program.
  PERFORM fill_komg_from_vakey IN PROGRAM (l_program)
                 USING p_komg
                 p_vakey.

btw. not every condition table will have a field matnr, but some will surely do at your end :-)

Best regards, Tom

Share
10 |10000 characters needed characters left characters exceeded
Raymond Giuseppi
Oct 19, 2017 at 11:59 AM
1

You could analyze the Customizing tables or functions of group V64C like COND_BUILD_VAKEY_FROM_COMMUNIC.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

I will look at this and this along with Rob Ariaans answer above should solve this - I bet that routine is how it's "encoded" so to speak and then maybe they have a decode too.

0
Jyoti Prakash
Oct 19, 2017 at 09:52 AM
0

Hello Bruce,

Did you try TCode V/LD with Pricing Report No. 15 - /1SDBF12L/RV14AK15?

Thanks,
JP

Share
10 |10000 characters needed characters left characters exceeded