简体   繁体   中英

Converting MATNR via conversion exit fails for custom table

I'm trying to select the latest date of a material movement from MSEG, but the material needs to be in stock and that is sourced from a bespoke table which uses unconverted Material names.

I've tried using the CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' (and INPUT ) but I'm not sure how to properly utilize it in a select statement.

IF MSEG-BWART = '101'.

  CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
    EXPORTING
      INPUT  = ZBJSTOCK-ZMAT10
    IMPORTING
      OUTPUT = WA2-MATNR.

  SELECT MAX( BUDAT_MKPF )
  FROM MSEG
  INTO GRDT
  WHERE MATNR = WA2-MATNR.

ENDIF.

Currently, WA2-MATNR seems to come out as blank and therefore is not pulling the data from MSEG.

You shouldn't use conversion exit here. Material number in SAP tables lays in internal (INPUT) format and you are converting it into readable format (OUTPUT) in order to query table. It is obvious you will not find anything.

Sample:

MATNR internal format (for OUT exits)

000000000000025567

MATNR external format (for IN exits)

25567

Conversions cases:

000000000000025567 -> CONVERSION_EXIT_MATN1_OUTPUT -> 25567 ✔️

25567 -> CONVERSION_EXIT_MATN1_OUTPUT -> 25567 ❌ nothing changes

25567 -> CONVERSION_EXIT_MATN1_INPUT -> 000000000000025567 ✔️

000000000000025567 -> CONVERSION_EXIT_MATN1_INPUT -> 000000000000025567 ❌ nng changes

Most likely, your bespoke table contains faulty material number so exit doesn't return anything. Or material number in format that exit doesn't expect, eg 19 characters instead of 18 and so on.

PS

Just for you info, you can use templates for conversion. It is the same as calling conversion FMs

SELECT SINGLE matnr FROM mara INTO @DATA(l_matnr) WHERE EXISTS ( SELECT * FROM mseg WHERE matnr = mara~matnr ).

l_matnr = | { l_matnr ALPHA = OUT } |. <<-- templating

SELECT SINGLE matnr, budat_mkpf
  FROM mseg
  INTO @DATA(l_mkpf)
  WHERE matnr = @l_matnr.

In the above sample SELECT will not return anything, but if you comment out the template line it will.

Unless you've added code into the user exits in that function, it's not going to do what you want. The standard purpose of that function is to format the material number for display on the screen.

The quickest way to do what you want is to select from your custom table to do the lookup.

That said, there is a user exit in that function where you can code the select to do the lookup. The extra benefit of doing that is that your users will be able to type in the legacy material number and the system will switch it with the new one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM