How can I use string literal to query tables if the raw value in the table is different from the value I use in the string literal?
I made a Z table that uses MATNR and 2 other fields as primary keys. In a dummy programm I filled the table with 4 rows using this code
delete from z_test_db.
data ls_tab type z_test_db.
data now type timestamp.
get time stamp field now.
ls_tab = value #( matnr = '4711' vorne = 0010 terminal = 'AAA' etkpgm = 'XXX' drucker = 'MO-ED-01' voretkm = 1 etkcopy = 1 eruser = sy-uname ertime = now aeuser = '' aetime = 0 kzaktv = 'X' kzaaeu = '' kzaaet = 0 ).
insert z_test_db from ls_tab.
get time stamp field now.
ls_tab = value #( matnr = '4712' vorne = 0010 terminal = 'AAA' etkpgm = 'XXX' drucker = 'MO-ED-01' voretkm = 1 etkcopy = 1 eruser = sy-uname ertime = now aeuser = '' aetime = 0 kzaktv = 'X' kzaaeu = '' kzaaet = 0 ).
insert z_test_db from ls_tab.
get time stamp field now.
ls_tab = value #( matnr = '4711' vorne = 0010 terminal = 'BBB' etkpgm = 'XXX' drucker = 'MO-ED-01' voretkm = 1 etkcopy = 1 eruser = sy-uname ertime = now aeuser = '' aetime = 0 kzaktv = 'X' kzaaeu = '' kzaaet = 0 ).
insert z_test_db from ls_tab.
get time stamp field now.
ls_tab = value #( matnr = '4712' vorne = 0010 terminal = 'BBB' etkpgm = 'XXX' drucker = 'MO-ED-01' voretkm = 1 etkcopy = 1 eruser = sy-uname ertime = now aeuser = '' aetime = 0 kzaktv = 'X' kzaaeu = '' kzaaet = 0 ).
insert z_test_db from ls_tab.
to create some dummy rows.
When I query that table for MATNR = '4711' it works but as soon as I use that value to query MARA there are no rows returned. I found out this is due to how MARA stores the value internally. If I open MARA in SE16N I can see that the value looks like '000000000000004711' in raw but gets displayed as '4711' to the user.
The domain
MATNRuses the conversion routineMATN1and it works like this:Input value from screen to DB
If you input the field from a screen (eg: MM01) the function
CONVERSION_EXIT_MATN1_INPUTis automatically applied before writing in DB converting4711into000000000000004711Output value from DB to screen
When the
MATNRfield is read from DB and displayed on the screen, the functionCONVERSION_EXIT_MATN1_OUTPUTis called automatically, showing the value4711instead of the internal format000000000000004711In short:
MATNRis shown as4711on screen but the DB table is written with000000000000004711In your case
you're inserting in DB the value
4711without using theMATN1routine. For this reason you are not finding the value inMARA: values4711inZ_TEST_DBand000000000000004711inMARAdon't match.Try fix the code with:
This converts the
MATNRinto000000000000004711and you'll find the link withMARA.