Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem about casting in internal tables

Former Member
0 Likes
1,228

Hello,

TYPES:
  BEGIN OF ts_matnr,
    matnr TYPE matnr,
    objct TYPE cuobj,
  END   OF ts_matnr.
  tables: mara.
DATA:
  myStatus(20) type c,
  mySTANDARDCLASS(20) type c,
  gt_matnr TYPE STANDARD TABLE OF ts_matnr WITH DEFAULT KEY,
  gs_matnr LIKE LINE OF gt_matnr,
  gs_mara  TYPE mara. 

SELECT-OPTIONS:
  pr_matnr FOR gs_mara-matnr.

START-OF-SELECTION.
SELECT matnr
       matnr AS objct 
       FROM mara
       INTO CORRESPONDING FIELDS OF TABLE gt_matnr WHERE matnr IN pr_matnr.

I want to write both the normal String and the value as object into the table. But there is a error at the select saying the fields can't be converted to target field.

I don't know what the problem is. Can you see it?

Edited by: Daniel Gerne on Apr 23, 2008 2:31 PM

12 REPLIES 12
Read only

Former Member
0 Likes
1,176

Hi Daniel,

you can write the Select query as

SELECT matnr
       matnr
       FROM mara
       INTO CORRESPONDING FIELDS OF TABLE gt_matnr WHERE matnr IN pr_matnr.

  LOOP AT gt_matnr INTO gs_matnr.
    gs_matnr-objct = gs_matnr-matnr.
    write:
      / gs_matnr-matnr,
        gs_matnr-objct.
    MODIFY gt_matnr FROM gs_matnr.
  ENDLOOP.

Regards ,

Sunil

Read only

Former Member
0 Likes
1,176

MATNR has type CHAR 18, CUOBJ has type NUMC 18 - how should this work? i.e. How should a letter (let´s say 'Z') be converted to e numeric?

Read only

Former Member
0 Likes
1,176

Hi,

You are calling Matnr twice and your internal table is having only one matnr.

Error is becoz of that.

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Apr 23, 2008 9:57 AM

Read only

Former Member
0 Likes
1,176

Hello Daniel-

Instead of gt_matnr TYPE STANDARD TABLE OF ts_matnr WITH DEFAULT KEY,

Try gt_matnr type table of ts_matnr.

Cheers,

~Srini....

Read only

Former Member
0 Likes
1,176

Hi,

Y dont you try using your select statement as follws:

SELECT matnr

objct

FROM mara

INTO CORRESPONDING FIELDS OF TABLE gt_matnr WHERE matnr IN pr_matnr.

The reason for this error is the data type mismatch b/w the source and target.

Hope this helps.

Regards

Sourabh

Read only

0 Likes
1,176

can you tell us detailed requirment, maybe we can give you more suggestion.

Read only

Former Member
0 Likes
1,176

Hi,

1.The main problem is type conflict in the source to target.

This cuobj is NUM 18,matnr is CHAR 18.

2.If you do with same type .Then.

TYPES:

BEGIN OF ts_matnr,

matnr TYPE matnr,

objct TYPE bismt,

END OF ts_matnr.

tables: mara.

DATA:

myStatus(20) type c,

mySTANDARDCLASS(20) type c,

gt_matnr TYPE STANDARD TABLE OF ts_matnr WITH DEFAULT KEY,

gs_matnr LIKE LINE OF gt_matnr,

gs_mara TYPE mara.

SELECT-OPTIONS:

pr_matnr FOR gs_mara-matnr.

START-OF-SELECTION.

SELECT matnr

matnr AS objct

FROM mara

INTO CORRESPONDING FIELDS OF TABLE gt_matnr WHERE matnr IN pr_matnr.

loop at gt_matnr into gs_matnr.

write:/ gs_matnr.

endloop.

Regards,

Shiva.

Read only

0 Likes
1,176

Hi shiva,

your code seems to be working. What is this type bismt anyway?

thank you.

Read only

0 Likes
1,176

unfortunately, I just saw that I just walked around my problem instead of solving it. The reason I want to have this MATNR is that I need to use it as Objectkey for a BAPI call:

LOOP AT gt_matnr INTO gs_matnr.

CALL FUNCTION 'BAPI_OBJCL_GETDETAIL_KEY'
  EXPORTING
*    CLOBJECTKEY           = gt_matnr-objct "nicht Tabelle, sondern Arbeitsbereich
    CLOBJECTKEY           = gs_matnr-objct "hat Typ OBJCT <=> BAPI1003_KEY-OBJECT_GUID
    CLASSNUM              = 'FARBIGE_UNTERLAGEN'
*   KEYDATE               = SY-DATUM
*   LANGUAGE              = SY-LANGU
 IMPORTING
   STATUS                = myStatus
   STANDARDCLASS         = mySTANDARDCLASS.
*  TABLES
*    ALLOCVALUESNUM        =
*    ALLOCVALUESCHAR       =
*    ALLOCVALUESCURR       =
*    RETURN                =.
ENDLOOP.

But with the type from Shiva's code the debugger says that the given parameter has a wrong type.I just can't get this BAPI to work. I want to use it to get the classification information about a material.

Read only

0 Likes
1,176

Why don´t you do it that way?:


DATA:
  gt_matnr TYPE STANDARD TABLE OF matnr,
  gw_matnr TYPE matnr,
  gv_objkey TYPE cuobj.

SELECT matnr
  FROM mara
  INTO OF TABLE gt_matnr WHERE matnr IN pr_matnr.

LOOP AT gt_matnr INTO gw_matnr.
* type conversion
  MOVE gw_matnr TO gv_objkey.

* call bapi
  CALL FUNCTION 'BAPI_OBJCL_GETDETAIL_KEY'
    EXPORTING
      CLOBJECTKEY           = gv_objkey
      CLASSNUM              = 'FARBIGE_UNTERLAGEN'
*      KEYDATE               = SY-DATUM
*      LANGUAGE              = SY-LANGU
   IMPORTING
     STATUS                = myStatus
     STANDARDCLASS         = mySTANDARDCLASS.
*     TABLES
*       ALLOCVALUESNUM        =
*       ALLOCVALUESCHAR       =
*       ALLOCVALUESCURR       =
*       RETURN                =.
ENDLOOP.

Read only

0 Likes
1,176

Hello Mike,

thank you for the code. But there are a few syntax errors in it.

About:

INTO OF TABLE gt_matnr WHERE matnr IN pr_matnr.

It doesn't know pr_matnr. It says it wants to have a table it can walk through, so I thought maybe you meant gt_matnr. But there the debugger says: Table pr_matnr has the wrong Linestructure.

Read only

0 Likes
1,176

Sorry, than just add the missing statement:


SELECT-OPTIONS:
  pr_matnr FOR gs_mara-matnr.

I posted this coding just to show you how ist should work. My intention was not to do your job!