-1

I am developing a SAP program to obtain information about a reference from the material table (MARA).

First I take certain references and then using a loop I need to make other query for every iteration:

SELECT
  MARA~BISMT
FROM mara
WHERE mara~matnr = @ref
INTO @var.

I know that the problem is that the types conflict (mara~matnr is characters and ref is string), how can I convert both to the same type and see the results?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
usr1990
  • 21
  • 2
  • 7
  • I think that you're talking about external (`ref`) and internal values (`mara~matnr`), you go from one value to the other via [conversion routines](https://help.sap.com/doc/abapdocu_753_index_htm/7.53/en-US/index.htm?file=abenconversion_exits.htm), either with function module `RS_CONV_EX_2_IN` or with statement `WRITE` (internal to external). – Sandra Rossi May 01 '20 at 19:03

2 Answers2

4

You can also use ABAP string templates instead of conversion exits suggested by mkysoft:

DATA: ref TYPE string VALUE '2'.

ref = |{ CONV matnr( ref ) ALPHA = in  }|.

SELECT SINGLE bismt
  FROM mara
 WHERE matnr = @ref
  INTO @DATA(var).
Suncatcher
  • 10,355
  • 10
  • 52
  • 90
0

You can use field symbol for dynamic type and CONVERSION_EXIT_ALPHA_INPUT function module for formatting value for db.

TABLES: mara.

DATA: ref TYPE string,
      var TYPE string.

FIELD-SYMBOLS: <fs_ref> TYPE any.

ref = '11'.

ASSIGN ('mara-matnr') TO <fs_ref>.
CHECK sy-subrc IS INITIAL.

<fs_ref> = ref.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input   = <fs_ref>
 IMPORTING
   output   = <fs_ref>.


SELECT SINGLE mara~bismt
  FROM mara
  INTO @var
 WHERE mara~matnr = @<fs_ref>.
mkysoft
  • 5,392
  • 1
  • 21
  • 30