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: 

about internal tables

Former Member
0 Kudos

hi i want to know how can u campre internal table values in a select statment if i am declaring the internal tables using types i.e i am declaring an internal table with out a header line and i am processing the internal table with work area.

find the code bellow. to b clear.

TYPES:BEGIN OF ty_mara,

matnr LIKE mara-matnr,

matart LIKE mara-mtart,

END OF ty_mara.

DATA:it_mara TYPE TABLE OF ty_mara,

wa_mara TYPE ty_mara.

TYPES:BEGIN OF ty_marc,

werks LIKE marc-werks,

END OF ty_marc.

DATA:it_marc TYPE TABLE OF ty_marc,

wa_marc TYPE ty_marc.

START-OF-SELECTION.

SELECT matnr mtart FROM mara INTO TABLE it_mara WHERE matnr IN s_matnr.

IF sy-subrc EQ 0.

SELECT werks FROM marc INTO TABLE it_marc WHERE matnr = the value i fetched from the first select stament

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hai Kiran,

Check this sample program.

To compare two internal table you must have one common field.

Just check this prg,

I have created two internal tables for two database tables.

than one output internal table to move the records

for 2 itab to one output itab.

TABLES : anla,

zcust_table_01.

************************************************************************

  • INTERNAL TABLE AND WORK AREA FOR FIELDS IN ANLA TABLE

************************************************************************

DATA : BEGIN OF itab_anla OCCURS 0,

bukrs LIKE anla-bukrs, "Company Code

anln1 LIKE anla-anln1, "Main Asset Number

anln2 LIKE anla-anln2, "Asset Subnumber

anlkl LIKE anla-anlkl, "Asset class

END OF itab_anla.

DATA : wa_anla LIKE LINE OF itab_anla.

************************************************************************

  • INTERNAL TABLE AND WORK AREA FOR FIELDS IN ZCUST_TABLE_01 TABLE *

************************************************************************

DATA : BEGIN OF itab_zcust_table_01 OCCURS 0,

bukrs LIKE zcust_table_01-bukrs,

anln1 LIKE zcust_table_01-anln1,

anln2 LIKE zcust_table_01-anln2,

anlkl LIKE zcust_table_01-anlkl,

z001 LIKE zcust_table_01-z001,

z002 LIKE zcust_table_01-z002,

z003 LIKE zcust_table_01-z003,

z004 LIKE zcust_table_01-z004,

END OF itab_zcust_table_01.

DATA : wa_zcust_table_01 LIKE LINE OF itab_zcust_table_01.

************************************************************************

  • OUTPUT INTERNAL TABLE *

************************************************************************

DATA : BEGIN OF itab_output OCCURS 0,

bukrs LIKE anla-bukrs,

anln1 LIKE anla-anln1,

anln2 LIKE anla-anln2,

anlkl LIKE anla-anlkl,

z001 LIKE zcust_table_01-z001,

z002 LIKE zcust_table_01-z002,

z003 LIKE zcust_table_01-z003,

z004 LIKE zcust_table_01-z004,

END OF itab_output.

***********************************************************************

SELECTION-SCREEN BEGIN OF BLOCK input WITH FRAME TITLE text-t01.

SELECT-OPTIONS : bukrs FOR anla-bukrs,

anln1 FOR anla-anln1,

anln2 FOR anla-anln2,

anlkl FOR anla-anlkl.

SELECTION-SCREEN END OF BLOCK input.

***********************************************************************

  • SELECTING RECORDS FORM ANLA TABLE *

***********************************************************************

SELECT bukrs anln1 anln2 anlkl

FROM anla INTO CORRESPONDING FIELDS OF TABLE itab_anla

WHERE bukrs IN bukrs AND

anln1 IN anln1 AND

anln2 IN anln2 AND

anlkl IN anlkl.

***********************************************************************

SELECT bukrs anln1 anln2 anlkl z001 z002 z003 z004

FROM zcust_table_01 INTO CORRESPONDING FIELDS OF

TABLE itab_zcust_table_01.

**********************************************************************

LOOP AT itab_anla.

READ TABLE itab_zcust_table_01 WITH KEY

bukrs = itab_anla-bukrs

anln1 = itab_anla-anln1

anln2 = itab_anla-anln2

anlkl = itab_anla-anlkl BINARY SEARCH.

IF sy-subrc EQ 0.

MOVE-CORRESPONDING itab_anla TO itab_output.

MOVE-CORRESPONDING itab_zcust_table_01 TO itab_output.

APPEND itab_output.

ENDIF.

ENDLOOP.

***********************************************************************

Reward for useful answers.

9 REPLIES 9

Former Member
0 Kudos

Hai Kiran,

Check this sample program.

To compare two internal table you must have one common field.

Just check this prg,

I have created two internal tables for two database tables.

than one output internal table to move the records

for 2 itab to one output itab.

TABLES : anla,

zcust_table_01.

************************************************************************

  • INTERNAL TABLE AND WORK AREA FOR FIELDS IN ANLA TABLE

************************************************************************

DATA : BEGIN OF itab_anla OCCURS 0,

bukrs LIKE anla-bukrs, "Company Code

anln1 LIKE anla-anln1, "Main Asset Number

anln2 LIKE anla-anln2, "Asset Subnumber

anlkl LIKE anla-anlkl, "Asset class

END OF itab_anla.

DATA : wa_anla LIKE LINE OF itab_anla.

************************************************************************

  • INTERNAL TABLE AND WORK AREA FOR FIELDS IN ZCUST_TABLE_01 TABLE *

************************************************************************

DATA : BEGIN OF itab_zcust_table_01 OCCURS 0,

bukrs LIKE zcust_table_01-bukrs,

anln1 LIKE zcust_table_01-anln1,

anln2 LIKE zcust_table_01-anln2,

anlkl LIKE zcust_table_01-anlkl,

z001 LIKE zcust_table_01-z001,

z002 LIKE zcust_table_01-z002,

z003 LIKE zcust_table_01-z003,

z004 LIKE zcust_table_01-z004,

END OF itab_zcust_table_01.

DATA : wa_zcust_table_01 LIKE LINE OF itab_zcust_table_01.

************************************************************************

  • OUTPUT INTERNAL TABLE *

************************************************************************

DATA : BEGIN OF itab_output OCCURS 0,

bukrs LIKE anla-bukrs,

anln1 LIKE anla-anln1,

anln2 LIKE anla-anln2,

anlkl LIKE anla-anlkl,

z001 LIKE zcust_table_01-z001,

z002 LIKE zcust_table_01-z002,

z003 LIKE zcust_table_01-z003,

z004 LIKE zcust_table_01-z004,

END OF itab_output.

***********************************************************************

SELECTION-SCREEN BEGIN OF BLOCK input WITH FRAME TITLE text-t01.

SELECT-OPTIONS : bukrs FOR anla-bukrs,

anln1 FOR anla-anln1,

anln2 FOR anla-anln2,

anlkl FOR anla-anlkl.

SELECTION-SCREEN END OF BLOCK input.

***********************************************************************

  • SELECTING RECORDS FORM ANLA TABLE *

***********************************************************************

SELECT bukrs anln1 anln2 anlkl

FROM anla INTO CORRESPONDING FIELDS OF TABLE itab_anla

WHERE bukrs IN bukrs AND

anln1 IN anln1 AND

anln2 IN anln2 AND

anlkl IN anlkl.

***********************************************************************

SELECT bukrs anln1 anln2 anlkl z001 z002 z003 z004

FROM zcust_table_01 INTO CORRESPONDING FIELDS OF

TABLE itab_zcust_table_01.

**********************************************************************

LOOP AT itab_anla.

READ TABLE itab_zcust_table_01 WITH KEY

bukrs = itab_anla-bukrs

anln1 = itab_anla-anln1

anln2 = itab_anla-anln2

anlkl = itab_anla-anlkl BINARY SEARCH.

IF sy-subrc EQ 0.

MOVE-CORRESPONDING itab_anla TO itab_output.

MOVE-CORRESPONDING itab_zcust_table_01 TO itab_output.

APPEND itab_output.

ENDIF.

ENDLOOP.

***********************************************************************

Reward for useful answers.

0 Kudos

hi vinoth,

thank u for ur reply,

what i wanted to know is..i am declaring the internal tables with types..so i need to use work area to process them.the thing is i have to use the field say eg:mtart..(fetched from the first select statement) in the where condition of the second select statment i.e i have to select the records only when the where condition is satisfied..now the thing is if i am declaring the internal table with begin of occurs 0 there is no problem i can directly give as "where mtart = itab1-mtart"..but how i can do this if i am declaring the intrnal table using the types statment (i.e here the table is with out header line) .

0 Kudos

Hello Kiran,

Check this code :-


TABLES:mara.
SELECT-OPTIONS:s_matnr FOR mara-matnr.

TYPES:BEGIN OF ty_mara,
        matnr LIKE mara-matnr,
        matart LIKE mara-mtart,
END OF ty_mara.

DATA: it_mara TYPE TABLE OF ty_mara,
      wa_mara TYPE ty_mara.

TYPES:BEGIN OF ty_marc,
        werks LIKE marc-werks,
END OF ty_marc.

DATA: it_marc TYPE TABLE OF ty_marc,
      wa_marc TYPE ty_marc.


START-OF-SELECTION.

  SELECT matnr mtart FROM mara INTO TABLE it_mara WHERE matnr IN s_matnr.
  IF it_mara[] IS NOT INITIAL.

    SELECT werks FROM marc INTO TABLE it_marc
           FOR ALL ENTRIES IN it_mara
           WHERE matnr = it_mara-matnr.
  ENDIF.

Regards,

Deepu.K

0 Kudos

There are two ways to do this. If you want to select the entries from MARC based on a single record, you would have to do this:

READ TABLE it_mara into wa_mara with key...

and then

SELECT werks FROM marc INTO TABLE it_marc WHERE matnr = wa_mara-matnr.

OR, if you want to select for all entries, you would have to give,

SELECT werks FROM marc INTO TABLE it_marc

FOR ALL ENTRIES IN it_mara WHERE matnr = it_mara-matnr.

Hope this helps.

Sudha

former_member873340
Active Participant
0 Kudos

Hi Kiran,

If u need to select the values based on the values from a first internal table then u can make use of FOR ALL ENTRIES keyword.

Hope this solves ur question.

Award points for all helpfull answers.

Regards

Gowri

Former Member
0 Kudos

Hi. Can you please a bit clear about the question do you want to compare the values in select statement? otherwise you can compare the value by simply loop at one table into work area( eg loop at it_mara into wa_ mara) and read other table inside that loop( eg read it_marc into wa_marc) and now you can simply compare the fields by WA_mara-field = wa_marc-field.

0 Kudos

Hello Kiran,

If I understand ur question correctly, U want to know how to fetch WERKS from MARC for all MATNR selected from MARA.

Use

IF it_mara IS NOT INITIAL.

SELECT werks FROM marc INTO TABLE it_marc

FOR ALL ENTRIES IN it_mara

WHERE matnr = it_mara-matnr

Endif.

Please reward points if helpful.

Johnson

aris_hidalgo
Contributor
0 Kudos

Hi,

Please check my example below.


REPORT z_aris_test_14.

TABLES: mara.

TYPES:BEGIN OF ty_mara,
       matnr LIKE mara-matnr,
       matart LIKE mara-mtart,
      END OF ty_mara.

DATA:it_mara TYPE TABLE OF ty_mara,
     wa_mara TYPE ty_mara.

TYPES:BEGIN OF ty_marc,
       werks LIKE marc-werks,
      END OF ty_marc.

DATA:it_marc TYPE TABLE OF ty_marc,
     wa_marc TYPE ty_marc.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
SELECT-OPTIONS: s_matnr FOR mara-matnr.
SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

* Method 1...
  SELECT matnr mtart
    FROM mara
    INTO TABLE it_mara
   WHERE matnr IN s_matnr.

  IF NOT it_mara[] IS INITIAL.
    SELECT werks
      FROM marc
      INTO TABLE it_marc
       FOR ALL ENTRIES IN it_mara
     WHERE matnr = it_mara-matnr.
  ENDIF.

* Method 2...
  REFRESH it_marc.
  LOOP AT it_mara INTO wa_mara.
    SELECT SINGLE werks
      FROM marc
      INTO wa_marc
     WHERE matnr = wa_mara-matnr.

    IF sy-subrc = 0.
      APPEND wa_marc TO it_marc.
    ENDIF.
  ENDLOOP.

END-OF-SELECTION.

  LOOP AT it_marc INTO wa_marc.
    WRITE: / wa_marc-werks.
  ENDLOOP.

Hope it helps...

P.S. Please award points if it helps...

Former Member
0 Kudos

thank u all it was answered