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

populating final itab

Former Member
0 Likes
1,557

i have internal table it_actual which has 2 records for every ebeln.......i want to get it final internal table it_final

LOOP AT it_final .

READ TABLE it_actual WITH KEY ebeln = it_final-ebeln.

it_final-wrbtr = it_actual-wrbtr.

it_final-beznk = it_actual-beznk.

it_final-lifnr = it_actual-lifnr.

MODIFY it_final.

ENDLOOP.

i get first record twice.i counldnt get 2nd record of it_actual for every ebeln.

any help?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,523

hi

Read statement read first line of the record.In read statement add line item. Use within loop

Try the following code

loop at it_actual ebeln = it_final-ebeln

it_final-wrbtr = it_actual-wrbtr.

it_final-beznk = it_actual-beznk.

it_final-lifnr = it_actual-lifnr.

MODIFY it_final.

endloop.

Edited by: dharma raj on Jan 21, 2010 3:34 PM

18 REPLIES 18
Read only

Former Member
0 Likes
1,523

Hello

increase key like:


LOOP AT it_final .
READ TABLE it_actual WITH KEY ebeln = it_final-ebeln
                              ebelp =  it_final-ebeln. " add this
it_final-wrbtr = it_actual-wrbtr.
it_final-beznk = it_actual-beznk.
it_final-lifnr = it_actual-lifnr.
MODIFY it_final.
ENDLOOP.

Read only

0 Likes
1,523
DATA:BEGIN OF it_vbak OCCURS 0, 
     vbelnLIKE vbak-vbeln,
     bukrs_vf LIKE vbak-bukrs_vf,data,
     END OF it_vbak.

DATA: BEGIN OF it_vbap OCCURS 0,
       vbeln TYPE vbap-vbeln,  "SALES ORDER NUMBER
       posnr TYPE vbap-posnr,
        END OF it_vbap.

 DATA:BEGIN OF it_final OCCURS 0,
             vbeln LIKE vbak-vbeln,
             bukrs_vf LIKE vbak-bukrs_vf,data,
             posnr TYPE vbap-posnr,
          END OF it_final.


SELECT-OPTIONS:s_vbeln FOR it_vbak-vbeln.
            

SELECT vbeln bukrs_vf vkorg FROM vbak INTO TABLE it_vbak WHERE vbeln IN s_vbeln.

  IF NOT it_vbak[] IS INITIAL.
    SELECT vbeln posnr FROM vbap INTO TABLE it_vbap FOR ALL ENTRIES IN it_vbak WHERE vbeln = it_vbak-vbeln .
ENDIF.
       
  LOOP AT it_vbak.
    it_final-vbeln = it_vbak-vbeln.
    it_final-bukrs_vf = it_vbak-bukrs_vf.
    APPEND it_final.
    ENDLOOP.


    loop at it_final.
      read table it_vbap with key vbeln = it_final-vbeln.
      it_final-posnr = it_vbap-posnr.
      modify it_final.
    endloop.

i get posnr which is 10 always...how to get 10 20 30 40 (posnr )......

Read only

0 Likes
1,523

Hi,

You need to apply the same logic again:


    loop at it_final.
      loop at it_vbap where vbeln = it_final-vbeln.
      it_final-posnr = it_vbap-posnr.
      modify it_final.
    endloop.
    endloop.

Regards,

Swarna Munukoti

Read only

0 Likes
1,523

Hi Raghu,

The same logic applies here, first you have to loop into vbap able and read the vbak data. see below,

LOOP AT it_vbap.

read table it_vbak with key vbeln = it_vbap-vbeln.

if sy-subrc eq 0.

it_final-vbeln = it_vbak-vbeln.

it_final-bukrs_vf = it_vbak-bukrs_vf.

it_final-posnr = it_vbap-posnr.

APPEND it_final.

endif.

ENDLOOP.

Hope this will solve your problem.

Regards,

Dinakar.

Read only

0 Likes
1,523

I dont wanna loop it_vbap and get the data ..... any other technique plz...

Read only

0 Likes
1,523

>

> I dont wanna loop it_vbap and get the data ..... any other technique plz...

You have to. If you want to get all the records, you can't use the READ TABLE sentence, you need to loop. But if what you really mean is that you don't want to loop over the entire internal table, then you should use a sorted table instead of a standard one. You then just use the sentence LOOP AT... WHERE... with the corresponding table key and that's all.

Nag's solution should also work if you are certain that the records you need to read are just 2 and consecutive.

Read only

0 Likes
1,523

what is preventing you to loop at vbap?

this is the best way of coding. else you are ending up with two loop statements which can hamper the performance. and in both the loops, you are building ur final itab only. then why not do it all at once by looping at vbap?

Thanks,

Kiran

Read only

Former Member
0 Likes
1,524

hi

Read statement read first line of the record.In read statement add line item. Use within loop

Try the following code

loop at it_actual ebeln = it_final-ebeln

it_final-wrbtr = it_actual-wrbtr.

it_final-beznk = it_actual-beznk.

it_final-lifnr = it_actual-lifnr.

MODIFY it_final.

endloop.

Edited by: dharma raj on Jan 21, 2010 3:34 PM

Read only

Former Member
0 Likes
1,523

Hi,

I don't seem to understand what you want.

But, READ TABLE returns just one record. If there are multiple records for the same EBELN in the internal table it_actual, then READ on this internal table will always return the first record for that EBELN.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,523

Please debug.

Read only

Former Member
0 Likes
1,523

Hi,

1. Sort it_Actual by ebelen.

2. and Try this code



LOOP AT it_final .
READ TABLE it_actual WITH KEY ebeln = it_final-ebeln.
WF_TABIX = SY-TABIX    " Ins
it_final-wrbtr = it_actual-wrbtr.
it_final-beznk = it_actual-beznk.
it_final-lifnr = it_actual-lifnr.
MODIFY it_final.

* Second read
wf_tabix = wf_tabix + 1.
READ TABLE IT_aCTUAL with index = wf_tabix.
* Process your data
ENDLOOP.

Hope this Helps

Nag

Read only

Former Member
0 Likes
1,523

Hi,

In you it_actual internal table add one more filed as flag char (1), then

modify your code as

LOOP AT it_final .

READ TABLE it_actual WITH KEY ebeln = it_final-ebeln flag ne ' '.

it_actual-flag = 'Y'.

modify it_actual index sy-tabix transporting flag.

it_final-wrbtr = it_actual-wrbtr.

it_final-beznk = it_actual-beznk.

it_final-lifnr = it_actual-lifnr.

MODIFY it_final.

ENDLOOP.

This will Help you

Rani

Read only

Former Member
0 Likes
1,523

Hi,

Try the below code.

LOOP AT it_actual .

READ TABLE it_final WITH KEY ebeln = it_actual-ebeln.

if sy-subrc eq 0.

it_final-wrbtr = it_actual-wrbtr.

it_final-beznk = it_actual-beznk.

it_final-lifnr = it_actual-lifnr.

MODIFY it_final.

endif.

ENDLOOP.

But i have a question, Do u want the it_final internal table to have all the records as of it_actual or just modify the existing records in it_final with corresponding values from it_actual records.

The above code will modify the existing records from it_final.

Regards,

Dinakar.

Read only

0 Likes
1,523

hi dinakar ...

i dont wanna modify ..i want all the records of it_actual.

Read only

0 Likes
1,523

Hi Raghu,

This logic doesn't modify but appends all the records to final internal table.

Regards,

Dinakar.

Read only

0 Likes
1,523

hi

Please cehk the code

LOOP AT it_vbak.

loop at it_vbap where vebln = it_vbak-vbeln.

it_final-vbeln = it_vbak-vbeln.

it_final-bukrs_vf = it_vbak-bukrs_vf.

it_final-posnr = it_vbap-posnr.

APPEND it_final.

endloop.

ENDLOOP.

debug the code and if u r getting posnr always 10 means check te table entry.

Read only

Former Member
0 Likes
1,523

hey...

Try this Before the loop.

SORT it_actual BY ebeln, ebelp.

AND if you want only the Order Num. You could do this:

DELETE ADJACENT RECORDS FROM it_actual COMPARING ebeln.

Read only

Former Member
0 Likes
1,523

Thanks to everyone