英文:
Query for apha field using string literal
问题
使用字符串文字来查询表格,如果表格中的原始值与字符串文字中使用的值不同,该怎么办?
我创建了一个名为 Z 表的表格,使用 MATNR
和其他 2 个字段作为主键。在一个虚拟程序中,我使用以下代码向表格中填充了 4 行数据。
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.
这些代码用于创建虚拟行。当我查询该表格以获取 MATNR = '4711'
时,可以正常工作,但一旦我使用该值查询 MARA 表,却没有返回任何行。我发现这是由于 MARA 表内部存储值的方式不同。如果我在 SE16N
中打开 MARA 表,可以看到原始值看起来像 '000000000000004711'
,但向用户显示为 '4711'
。
英文:
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.
答案1
得分: 2
The domain MATNR
uses the conversion routine MATN1
, and it works as follows:
Input value from screen to DB
如果您从屏幕输入字段(例如:MM01),则会在写入数据库之前自动应用函数 CONVERSION_EXIT_MATN1_INPUT
,将 4711
转换为 000000000000004711
。
Output value from DB to screen
当从数据库读取并显示屏幕上的 MATNR
字段时,将自动调用函数 CONVERSION_EXIT_MATN1_OUTPUT
,显示值 4711
而不是内部格式 000000000000004711
。
简而言之:屏幕上显示的 MATNR
为 4711
,但将其写入数据库表时为 000000000000004711
。
在您的情况下
您将值 4711
插入数据库,而没有使用 MATN1
例程。因此,您在 MARA
中找不到匹配的值:Z_TEST_DB
中的值为 4711
,而 MARA
中的值为 000000000000004711
。
尝试使用以下代码修复:
data lv_matnr type matnr.
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 ).
call function 'CONVERSION_EXIT_MATN1_INPUT'
exporting
input = ls_tab-matnr
importing
output = ls_tab-matnr
exceptions
length_error = 1
others = 2.
这将把 MATNR
转换为 000000000000004711
,然后您将能够在 MARA
中找到与之相关的链接。
英文:
The domain MATNR
uses the conversion routine MATN1
and 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_INPUT
is automatically applied before writing in DB converting 4711
into 000000000000004711
Output value from DB to screen
When the MATNR
field is read from DB and displayed on the screen, the function CONVERSION_EXIT_MATN1_OUTPUT
is called automatically, showing the value 4711
instead of the internal format 000000000000004711
In short: MATNR
is shown as 4711
on screen but the DB table is written with 000000000000004711
In your case
you're inserting in DB the value 4711
without using the MATN1
routine. For this reason you are not finding the value in MARA
:
values 4711
in Z_TEST_DB
and 000000000000004711
in MARA
don't match.
Try fix the code with:
data lv_matnr type matnr.
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 ).
call function 'CONVERSION_EXIT_MATN1_INPUT'
exporting
input = ls_tab-matnr
importing
output = ls_tab-matnr
exceptions
length_error = 1
others = 2.
This converts the MATNR
into 000000000000004711
and you'll find the link with MARA
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论