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: 

Read statement from 2 different internal table.

Former Member
0 Kudos

Hello,

I am new to ABAP and try to work out these statements. Please can someone help me in correcting the code.

Requirement is

1. I have Sales Header Table

2. Sales Item Table.

Both the above table has Doc_number as the key filed and both has CREATEDON date . While reading the Data from SALES ITem table i have copy the CREATEON Date from SAles Header Table.

For the above requirment i have used the following code which is going for unending loop.

Tables: /BIC/ASALHDR0100,/BIC/ASALORD0100.

DATA: CHDATE like /BIC/ASALHDR0100 occurs 0 with header line,
      WA_CHDATE type /BIC/ASALHDR0100,
      CiDATE like /BIC/ASALORD0100 occurs 0 with header line,
      WA_CiDATE type /BIC/ASALORd0100.


      SELECT * from /BIC/ASALORD0100 into table CIDATE.
  

      select * from /BIC/ASALHDR0100 into CHDATE for all entries in CIDATE where DOC_NUMBER = CIDATE-DOC_NUMBER.
Append CHDATE.
      endselect.



loop at CHDATE INTO WA_CHDATE.
    LOOP at CIDATE into WA_CIDATE.

    if WA_CHDATE-DOC_NUMBER = WA_CIDATE-DOC_NUMBER.
Read table CHDATE into WA_CHDATE with KEY doc_number = WA_CIDATE-doc_number .

          write: WA_CHDATE-DOC_NUMBER,
                  WA_chdate-createdon,
                 WA_CIDATE-DOC_NUMBER.
                 ENDIF.
                 ENDLOOP.

          endloop.

Thanks

Edited by: Rob Burbank on Jul 26, 2010 9:34 AM

3 REPLIES 3

Former Member
0 Kudos

HI,

try thsi code.

]

TABLES: /bic/asalhdr0100,/bic/asalord0100.

DATA: chdate LIKE /bic/asalhdr0100 OCCURS 0 WITH HEADER LINE,
wa_chdate TYPE /bic/asalhdr0100,
cidate LIKE /bic/asalord0100 OCCURS 0 WITH HEADER LINE,
wa_cidate TYPE /bic/asalord0100.


SELECT * FROM /bic/asalord0100 INTO TABLE cidate.

SELECT * FROM /bic/asalhdr0100 INTO TABLE chdate FOR ALL ENTRIES IN cidate WHERE doc_number = cidate-doc_number.

LOOP AT chdate INTO wa_chdate.
  LOOP AT cidate INTO wa_cidate.

    IF wa_chdate-doc_number = wa_cidate-doc_number.
      READ TABLE chdate INTO wa_chdate WITH KEY doc_number = wa_cidate-doc_number .

      WRITE: wa_chdate-doc_number,
      wa_chdate-createdon,
      wa_cidate-doc_number.
    ENDIF.
  ENDLOOP.

ENDLOOP.

Regards,

Pravin

0 Kudos

 
DATA: chdate type table of  /bic/asalhdr0100 
wa_chdate TYPE /bic/asalhdr0100,
cidate type table of  /bic/asalord0100 ,
wa_cidate TYPE /bic/asalord0100.
 
 
SELECT * FROM /bic/asalord0100 INTO TABLE cidate.
 
if cidate[] is not initial
SELECT * FROM /bic/asalhdr0100 INTO TABLE chdate FOR ALL ENTRIES IN cidate WHERE doc_number = cidate-doc_number.
endif.
 
LOOP AT chdate INTO wa_chdate.
  LOOP AT cidate INTO wa_cidate where doc_number = wa_chdate-doc_number.
 

      WRITE: wa_chdate-doc_number,
      wa_chdate-createdon,
      wa_cidate-doc_number.

  ENDLOOP.
 
ENDLOOP.

Also you can go for parallel cursor method.For that you have to sort the internal tables and go for loop.Performance point of view, parallel cursor method is very good.

Regards,

Nikhil

kesavadas_thekkillath
Active Contributor
0 Kudos
 
DATA: CHDATE type table of /BIC/ASALHDR0100,
      WA_CHDATE type /BIC/ASALHDR0100,
      CiDATE type sorted table of /BIC/ASALORD0100 with unique key doc_number doc_item,  "<--Use as required
      WA_CiDATE type /BIC/ASALORd0100.
 
       SELECT * from /BIC/ASALORD0100 into table CIDATE.
      if cidate[] is not initial.
 	sort cidate by doc_number.
      select * from /BIC/ASALHDR0100 into table CHDATE
	 for all entries in CIDATE
         where DOC_NUMBER = CIDATE-DOC_NUMBER.
      endif.

loop at CHDATE INTO WA_CHDATE.
    LOOP at CIDATE into WA_CIDATE where doc_number = wa_chdate-doc_number.
           write: WA_CHDATE-DOC_NUMBER,
                  WA_chdate-createdon,
                 WA_CIDATE-DOC_NUMBER.
	   skip 1.
    ENDLOOP.
 endloop.