Application Development 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: 

the Value 'X' is not found in internal table.

1190_5939_439
Active Participant
0 Kudos

Function I will do a check for program. When the material is marked by X. It will be stopped. Method I create an internal table. And I will take data from MARA to internal table. Then I do logic judgement. But it failed. I don't know why the Value 'X' is not found in internal table.

The code is following:

" 检查删除标识   ADD IT BY JINGGUL
LOOP AT lt_up.
MOVE-CORRESPONDING lt_up TO lt_LVORM.
append lt_LVORM.
ENDLOOP.
SELECT SINGLE LVORM INTO lt_LVORM-LVORM1 FROM MARA WHERE matnr =  lt_LVORM-matnr.
SELECT SINGLE LVORM INTO lt_LVORM-LVORM2 FROM MARC WHERE matnr =  lt_LVORM-matnr.


IF lt_LVORM-LVORM1  IS NOT INITIAL.
 MESSAGE '提示物料不存在' TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE PROGRAM.
ENDIF.
IF lt_LVORM-LVORM1  IS NOT INITIAL.
MESSAGE '提示物料不存在' TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE PROGRAM.
ENDIF.

I have a screenshot for you .

21 REPLIES 21

Abinathsiva
Active Contributor
0 Kudos

Hi,

Internal table field can't be updated like this (Select single), read the information and append or modify the table and then check is not initial

mateuszadamus
Active Contributor

Hello 1190_5939_439

LOOP AT lt_up.
  MOVE-CORRESPONDING lt_up TO lt_LVORM.
  append lt_LVORM.
ENDLOOP.

" this selects a record for the last LT_LVORM entry
" is that what you wanted?
SELECT SINGLE LVORM INTO lt_LVORM-LVORM1 FROM MARA WHERE matnr =  lt_LVORM-matnr.

" this selects a record for the last LT_LVORM entry
" is that what you wanted?
SELECT SINGLE LVORM INTO lt_LVORM-LVORM2 FROM MARC WHERE matnr =  lt_LVORM-matnr.

IF lt_LVORM-LVORM1  IS NOT INITIAL.
 MESSAGE '提示物料不存在' TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE PROGRAM.
ENDIF.

" it should be LVORM2 here - copy paste error probably
IF lt_LVORM-LVORM1  IS NOT INITIAL.
MESSAGE '提示物料不存在' TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE PROGRAM.
ENDIF.

If you want to read LVORM for all LT_LVORM records then you have to read it into internal table with FOR ALL ENTRIES, like so:

IF lt_lvorm[] IS NOT INITIAL.
  SELECT matnr LVORM
    INTO TABLE DATA(lt_mara) 
    FROM MARA 
    FOR ALL ENTRIES IN lt_lvorm
    WHERE matnr = lt_LVORM-matnr.
ENDIF.

" then
LOOP AT lt_lvorm REFERENCE INTO DATA(ld_lvorm).
  READ TABLE lt_mara REFERENCE INTO DATA(ld_mara)
    WITH KEY matnr = ld_lvorm->matnr.
  CHECK sy-subrc = 0
    AND ld_mara->lvorm IS NOT INITIAL.

  MESSAGE '提示物料不存在' TYPE 'S' DISPLAY LIKE 'E'.
  LEAVE PROGRAM.
ENDLOOP.

Kind regards,

Mateusz

0 Kudos

At present I need do 3 process actually.

1.move matnr's record to lt_lvorm[];

2.move lvorm's record to lt_lvorm[] ;

3. judgement it .


" I need create a internal table (lt_mara)?
IF lt_lvorm[] IS NOT INITIAL.
  SELECT SINGLE matnr LVORM
    INTO TABLE DATA(lt_mara) 
    FROM MARA 
    FOR ALL ENTRIES IN lt_lvorm
    WHERE matnr = lt_LVORM-matnr.
ENDIF.
" I need create a internal table (ld_lvorm)?
" then
LOOP AT lt_lvorm REFERENCE INTO DATA(ld_lvorm).
  READ TABLE lt_mara REFERENCE INTO DATA(ld_mara)
    WITH KEY matnr = ld_lvorm->matnr.
  CHECK sy-subrc = 0
    AND ld_mara->lvorm IS NOT INITIAL.

  MESSAGE '提示物料不存在' TYPE 'S' DISPLAY LIKE 'E'.
  LEAVE PROGRAM.
ENDLOOP.
 LOOP AT lt_up.
  MOVE-CORRESPONDING lt_up TO lt_LVORM.
  append lt_LVORM.
ENDLOOP.

" this selects a record for the last LT_LVORM entry
" is that what you wanted?(you are right. a record is inserted  in the LT_LVORM. LT_LVORM is an internal table.)
SELECT SINGLE LVORM INTO lt_LVORM-LVORM1 FROM MARA WHERE matnr =  lt_LVORM-matnr.

" this selects a record for the last LT_LVORM entry
" is that what you wanted? (you are right. a record is inserted  in the LT_LVORM. LT_LVORM is an internal table.)
SELECT SINGLE LVORM INTO lt_LVORM-LVORM2 FROM MARC WHERE matnr =  lt_LVORM-matnr.

IF lt_LVORM-LVORM1  IS NOT INITIAL.
 MESSAGE '提示物料不存在' TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE PROGRAM.
ENDIF.

" it should be LVORM2 here - copy paste error probably )( you  are right)
IF lt_LVORM-LVORM1  IS NOT INITIAL.
MESSAGE '提示物料不存在' TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE PROGRAM.
ENDIF.

0 Kudos

If you want to read LVORM1 and LVORM2 for all records in the LT_LVORM table, then yes, you have to SELECT them into internal tables and then read record by record for LT_LVORM records.

LD_LVORM is a reference to a record from LT_LVORM table. More about it here: https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abendata_reference_type.htm

If you want to move values to LT_LVORM you can do as follows:

IF lt_lvorm[] IS NOT INITIAL.
  SELECT matnr LVORM
    INTO TABLE DATA(lt_mara) 
    FROM MARA 
    FOR ALL ENTRIES IN lt_lvorm
    WHERE matnr = lt_LVORM-matnr.

  SELECT matnr LVORM 
    INTO TABLE DATA(lt_marc) 
    FROM MARC 
    FOR ALL ENTRIES IN lt_lvorm
    WHERE matnr =  lt_LVORM-matnr.
ENDIF.

LOOP AT lt_lvorm REFERENCE INTO DATA(ld_lvorm).
  READ TABLE lt_mara REFERENCE INTO DATA(ld_mara)
    WITH KEY matnr = ld_lvorm->matnr.
  IF sy-subrc = 0.
    ld_lvorm->lvorm1 = ld_mara->lvorm.
  ENDIF.

  READ TABLE lt_marc REFERENCE INTO DATA(ld_marc)
    WITH KEY matnr = ld_lvorm->matnr.
  IF sy-subrc = 0.
    ld_lvorm->lvorm2 = ld_marc->lvorm.
  ENDIF.
ENDLOOP.

MARC has a Plant (WERKS) in its primary key so you might want to have this in your selection criteria, too.

Kind regards,

Mateusz

typo:

SELECT SINGLE matnr LVORM  -->   SELECT matnr, LVORM

Alternative:

DATA lv_matnr TYPE mara-matnr.
IF lt_up IS NOT INITIAL.
  SELECT matnr FROM MARA INTO lv_matnr FOR ALL ENTRIES IN lt_up
    WHERE matnr = lt_up-matnr
      AND lvorm = 'X'.
    MESSAGE '提示物料不存在' TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE PROGRAM.  
  ENDSELECT.
ENDIF.

Open issue: no specification for the MARC-LVORM check. As it is, the OP's code does not check MARC-WERKS.

JNN

0 Kudos

Yeah, already fixed that.

I think you can't use lt_up IS NOT INITIAL because the table has a header. This way you're checking the header, not the records. You have to use lt_up[].


Kind regards,
Mateusz

0 Kudos

IF lt_lvorm[] IS NOT INITIAL.

"  lt_mara(it is result_Tab?  Where is lt_mara from ? What is the result_tab?  how to give  LVORM to LVORM1 or LVORM2 ? )
  SELECT matnr LVORM
    INTO TABLE DATA(lt_mara) 
    FROM MARA 
    FOR ALL ENTRIES IN lt_lvorm
    WHERE matnr = lt_LVORM-matnr.
" lt_marc(it is result_Tab?  Where is lt_marc from ? What is the result_tab?  how to give  LVORM to  LVORM1 or LVORM2 ?)
  SELECT matnr LVORM 
    INTO TABLE DATA(lt_marc) 
    FROM MARC 
    FOR ALL ENTRIES IN lt_lvorm
    WHERE matnr =  lt_LVORM-matnr.
ENDIF.

LOOP AT lt_lvorm REFERENCE INTO DATA(ld_lvorm).
  READ TABLE lt_mara REFERENCE INTO DATA(ld_mara)
    WITH KEY matnr = ld_lvorm->matnr.
  IF sy-subrc = 0.
    ld_lvorm->lvorm1 = ld_mara->lvorm.      " I don't understand it . I think it is  ld_mara->lvorm  = ld_lvorm->lvorm1.
  ENDIF.

  READ TABLE lt_marc REFERENCE INTO DATA(ld_marc)
    WITH KEY matnr = ld_lvorm->matnr.
  IF sy-subrc = 0.
    ld_lvorm->lvorm2 = ld_marc->lvorm.            " I don't understand it .          
  
  ENDIF.
ENDLOOP.

0 Kudos

When I run your code .The error is following: I am not sure if my sap version is low.

0 Kudos

IF I only run MARA-LVORM check. I think following code is ok .

DATA lv_matnr TYPE mara-matnr.
IF lt_up[] IS NOT INITIAL.
  SELECT matnr FROM MARA INTO lv_matnr FOR ALL ENTRIES IN lt_up
    WHERE matnr = lt_up-matnr
      AND lvorm = 'X'.
    IF SY-subrc = 0 .
    MESSAGE '提示物料不存在' TYPE 'S' DISPLAY LIKE 'E'.
    ENDIF.
    LEAVE PROGRAM.
  ENDSELECT.
ENDIF.

0 Kudos
" IF Plant (WERKS) is  added, the full code is following:

TYPES: BEGIN OF wa_excel,
         matnr LIKE zrpp002_t1-matnr,
         plnmg LIKE zrpp002_t1-plnmg,
       END OF wa_excel.
DATA: lt_up TYPE STANDARD TABLE OF wa_excel WITH HEADER LINE.

DATA: BEGIN OF lt_LVORM OCCURS 0.          " add it by jinggl
      INCLUDE STRUCTURE lt_up.
DATA: LVORM1 like mara-LVORM ,
      LVORM2 like marc-LVORM,
      LVORM3 like marc-LVORM,
      LVORM4 like marc-LVORM,
     END OF lt_LVORM.
LOOP AT lt_up.
MOVE-CORRESPONDING lt_up TO lt_LVORM.
append lt_LVORM.
ENDLOOP.
SELECT SINGLE LVORM INTO lt_LVORM-LVORM1 FROM MARA WHERE matnr =  lt_LVORM-matnr.
SELECT SINGLE LVORM INTO lt_LVORM-LVORM2 FROM MARC WHERE matnr =  lt_LVORM-matnr AND WERKS = '2100'.
SELECT SINGLE LVORM INTO lt_LVORM-LVORM3 FROM MARC WHERE matnr =  lt_LVORM-matnr AND WERKS = '2200'.
SELECT SINGLE LVORM INTO lt_LVORM-LVORM4 FROM MARC WHERE matnr =  lt_LVORM-matnr AND WERKS = '2300'.      

IF lt_LVORM-LVORM1  IS NOT INITIAL.
 MESSAGE '提示物料不存在' TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE PROGRAM.
ENDIF.
IF lt_LVORM-LVORM2  IS NOT INITIAL.
MESSAGE '提示物料不存在' TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE PROGRAM.
ENDIF.
IF lt_LVORM-LVORM3  IS NOT INITIAL.
MESSAGE '提示物料不存在' TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE PROGRAM.
ENDIF.
IF lt_LVORM-LVORM4  IS NOT INITIAL.
MESSAGE '提示物料不存在' TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE PROGRAM.
ENDIF.



One by one.

"  lt_mara(it is result_Tab?  Where is lt_mara from ? What is the result_tab?  how to give  LVORM to LVORM1 or LVORM2 ? )
  SELECT matnr LVORM
    INTO TABLE DATA(lt_mara) 

LT_MARA is created using an inline declaration. You can read about it her: https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abendata_inline.htm

" lt_marc(it is result_Tab?  Where is lt_marc from ? What is the result_tab?  how to give  LVORM to  LVORM1 or LVORM2 ?)
  SELECT matnr LVORM 
    INTO TABLE DATA(lt_marc) 

Same as LT_MARA - inline declaration.

LOOP AT lt_lvorm REFERENCE INTO DATA(ld_lvorm).
  READ TABLE lt_mara REFERENCE INTO DATA(ld_mara)
    WITH KEY matnr = ld_lvorm->matnr.
  IF sy-subrc = 0.
    ld_lvorm->lvorm1 = ld_mara->lvorm.      " I don't understand it . I think it is  ld_mara->lvorm  = ld_lvorm->lvorm1.
  ENDIF.

In your original code you're trying to read LVORM from MARA and MARC tables and assign these values to LVORM1 and LVORM2 fields.

SELECT SINGLE LVORM INTO lt_LVORM-LVORM1 FROM MARA WHERE matnr =  lt_LVORM-matnr.
SELECT SINGLE LVORM INTO lt_LVORM-LVORM2 FROM MARC WHERE matnr =  lt_LVORM-matnr.

In my code the MARA and MARC records are read beforehand, all in one read, for better performance. The data is stored in the LT_MARA and LT_MARC internal tables. Later, and this is the part you asked about, for each of your records a record from LT_MARA (and LT_MARC) is read and data from this record is moved to your record. Hence the:

ld_lvorm->lvorm1 = ld_mara->lvorm.

LD_LVORM is again inline declared in the LOOP statement and contains a reference to one of your records.

LOOP AT lt_lvorm REFERENCE INTO DATA(ld_lvorm).

Later, the assignment moves data from LVORM from MARA to LVORM1 field.

If the inline declaration is not possible to in the place where I put it, raises an error, then find a better place for it. It might be that the at signs (@) are missing in variables of the SELECT statement. It might also be that the inline declaration statement should be at the end of the SELECT statement. Please use your own time and try to figure this issue on your own. It's the best way to learn something.

You clearly don't understand the difference between SELECT SINGLE and SELECT INTO TABLE. These are basics that you have to know if you want to smoothly program in ABAP. Please read about it, here some info: https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abapselect.htm

Also, about internal tables with and without headers:

https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abenitab_header_line.htm <- OBSOLETE, DO NOT USE, ERROR PRONE

https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abenitab_guidl.htm

Kind regards,

Mateusz

SELECT matnr, lvorm
    INTO TABLE @DATA(lt_mara) ...

(inline declaration can be used only with strict Open SQL)

0 Kudos

Thanks, My sap version is 7.40. I am not sure if it is supported inline declaration.

0 Kudos

Inline declaration is just a shortcut, to something that can be achieved with standard TYPES and DATA declarations.

In other words, you can define a type with TYPES and an internal table with DATA decalrations and then use this internal table as a target for your SELECT query.


Kind regards,
Mateusz

0 Kudos

HI Mateus

As lt_mara an example . How do I define a type "types" and an internal table with "data" in declaration? Thanks. The following

code is found in the sap help.

  TYPES t_itab TYPE TABLE OF i WITH NON-UNIQUE KEY table_line.

 DATA(itab) = VALUE t_itab( ( 1 ) ( 2 ) ( 3 ) ).

 LOOP AT itab INTO DATA(wa).   ... ENDLOOP.<br>

0 Kudos

all in one read, for better performance ? Why is your performance better? But I think it is a check. Perhaps I need a record. But you will search all data.

0 Kudos

SAP ABAP Help example of type definition: https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abaptypes_struc.htm

Below is an example of defining a structure and table types in ABAP code.

TYPES:
  BEGIN OF yls_structure_type,
    field1 TYPE belnr,
    field2 TYPE string,
  END OF yls_structure_type,
  ylt_table_type TYPE TABLE OF yls_structure_type,
  ylt_unique_sorted_table_type TYPE SORTED TABLE OF yls_structure_type WITH UNIQUE KEY belnr,
  ylt_non_unique_sorted_table_type TYPE SORTED TABLE OF yls_structure_type WITH NON-UNIQUE KEY belnr,
  ylt_hashed_table_type TYPE HASHED TABLE OF yls_structure_type WITH UNIQUE KEY belnr.

DATA:
  ls_structure TYPE yls_structure_type,
  lt_table TYPE ylt_table_type.
  " etc

It's always better to have less DB queries than more. One is it better? Less work for DB. Less data transferred through network.

If you can do a SELECT SINGLE in a LOOP, then you can probably replace it with a SELECT INTO TABLE and READ TABLE statements.


Kind regards,
Mateusz

ClausB
Active Participant

Please, don't use internal table with header lines. It is a obsolete Syntax

Are you sure that lt_lvorm-matnr has the correct value?

1190_5939_439
Active Participant
0 Kudos

it is correct.

Sandra_Rossi
Active Contributor

Your code, and the code you have just posted in the comments, work correctly, but only for one material.

Moreover, please stop using header lines anymore, it's ERROR-prone, especially for beginners. You also incorrectly use LIKE.

From now on, use this kind of declaration:

TYPES: BEGIN OF ty_material,
         matnr TYPE mara-matnr,
         lvorm TYPE mara-lvorm,
     END OF ty_material.

DATA materials TYPE TABLE OF ty_material. " <===== no header line
...
LOOP AT materials REFERENCE INTO DATA(material). " <===== reference to each line
  ...
ENDLOOP.

1190_5939_439
Active Participant
0 Kudos

but only for one material ? you means that I must put code in the loop ?