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: 

Problem in filling the final internal table

Former Member
0 Kudos

Hi,

I am working on a code in which i have to fill up the final internal table which will store the values coming form different internal tables.Here's the code which i am trying to do but it is not giving the execat functionality.In this code ITOUTPUT is the final itab which is storing the values of all other internal tables.

Here's the code:-



loop at itab1.

  select single maktx into v_item from makt where matnr = itab1-matnr.

      ITOUTPUT-banfn = ITab1-banfn.
      ITOUTPUT-badat = ITab1-badat.
      ITOUTPUT-meins = ITab1-meins.
      ITOUTPUT-menge = ITab1-menge.
      ITOUTPUT-lfdat = ITab1-lfdat.


  IF ITAB1-MEINS = 'KG'.
    V_TOTREQ = V_TOTREQ + ITAB1-MENGE.
  ELSEIF ITAB1-MEINS = 'TO'.
    V_TOTREQ = V_TOTREQ + ( ITAB1-MENGE * 1000 ).
  ELSEIF ITAB1-MEINS = 'G'.
    V_TOTREQ = V_TOTREQ + ( ITAB1-MENGE / 1000 ).
  ENDIF.
  v_tpo = 0.
  v_por = 0.

  LOOP AT ITPO WHERE BANFN = ITAB1-BANFN AND bnfpo = ITAB1-bnfpo.
    if v_por <> '0'.
      write : / '  '.
    endif.

      ITOUTPUT-ebeln = ITPO-ebeln.
      ITOUTPUT-aedat = ITPO-aedat.
      ITOUTPUT-lifnr = ITPO-lifnr.
      ITOUTPUT-menge = ITPO-menge.
      ITOUTPUT-EINDT = ITPO-EINDT.

    IF ITAB1-MEINS = 'KG'.
      V_TOTPO = V_TOTPO + ITPO-MENGE.
    ELSEIF ITPO-MEINS = 'TO'.
      V_TOTPO = V_TOTPO + ( ITPO-MENGE * 1000 ).
    ELSEIF ITPO-MEINS = 'G'.
      V_TOTPO = V_TOTPO + ( ITPO-MENGE / 1000 ).
    ENDIF.

    v_tpo = v_tpo + itpo-menge.
    v_tgr = 0.
    v_por = 1.
    v_grr = 0.

    loop at itmrn where ebeln = itpo-ebeln and ebelp = itpo-ebelp.
      if v_grr <> '0'.
        write : / '  '.
      endif.

      select single budat from mkpf into v_grdate where MBLNR = itmrn-MBLNR.
      write: 143 Itmrn-menge,v_grdate .

        itoutput-PMENGE = itmrn-menge.

      v_tgr = v_tgr + itmrn-menge.
      v_grr = 1.

    endloop.
    p_po = itpo-menge - v_tgr.
   write: 173 p_po.

  ENDLOOP.
  p_req = itab1-menge - v_tpo.
  write :  195 p_req.

endloop.


loop at itoutput.

  write:/ itoutput-banfn,12 itoutput-badat,24 v_item,50 itoutput-meins,53 itoutput-menge,itoutput-lfdat,
          89 ITPO-ebeln,100 ITPO-aedat,111 ITPO-lifnr,(10) itpo-menge, ITPO-eindt.

  MODIFY itoutput.

endloop.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

YA Modify statement needed to be moved in upper loop.

You placed it at wrong place.Change its place , code will work fine.

17 REPLIES 17

Former Member
0 Kudos

Hi,

Not satisfying the functionality menas how do we know what functionality you want .

Then try debugging and check how the value is coming ...then change as per your requirement.

Its difficult to get the answer in sdn as per your specific logic...Better you can try it out ..

Former Member
0 Kudos

Hello


loop at itab1.

......

  ENDLOOP.
  p_req = itab1-menge - v_tpo.
  write :  195 p_req.
  MODIFY itoutput. " <- add this
endloop.
 
 
loop at itoutput.
 
  write:/ itoutput-banfn,12 itoutput-badat,24 v_item,50 itoutput-meins,53 itoutput-menge,itoutput-lfdat,
          89 ITPO-ebeln,100 ITPO-aedat,111 ITPO-lifnr,(10) itpo-menge, ITPO-eindt.
 
  MODIFY itoutput. " <- remove this
 
endloop.

0 Kudos

Hi,

Ok,i ha d checked my code by using your logic and giving the run time error ......

i had debugged my code (orignal onementioned in above thread with little modification) in which i am able to see that finaloutput (intrenal table) is getting filled properly and the problem arises when the cursor comes to the write statement ... it is repeating some of the values when output is displayed where as before displaying output this iternal table is having the correct data. i am using the following code :-

  • append itoutput.

ENDLOOP.

p_req = itab1-menge - v_tpo.

write : 195 p_req.

append itoutput. ,<--- added this

clear itoutput. <--- added this

endloop.

loop at itoutput.

write:/ itoutput-banfn,12 itoutput-badat,24 v_item,50 itoutput-meins,53 itoutput-menge,itoutput-lfdat,

89 ITPO-ebeln,100 ITPO-aedat,111 ITPO-lifnr,(10) itpo-menge, ITPO-eindt.

MODIFY itoutput. <------ not removed

endloop.

0 Kudos

Hi,

Thats because you are appending itoutput instead of modifying. Also the modify after the write statement is unnecessary. Change the code this way and check



ENDLOOP.
p_req = itab1-menge - v_tpo.
write : 195 p_req.

modify it_output.       ---------> "Add this instead of append

*append itoutput. ,<--- added this    " Remove these. Here duplicate values will be populated if you use
*clear itoutput. <--- added this         " Remove

endloop.

loop at itoutput.


write:/ itoutput-banfn,12 itoutput-badat,24 v_item,50 itoutput-meins,53 itoutput-menge,itoutput-lfdat,
89 ITPO-ebeln,100 ITPO-aedat,111 ITPO-lifnr,(10) itpo-menge, ITPO-eindt.

MODIFY itoutput. <------ not removed   " First remove this. Its unnecessary

endloop.

Regards,

Vikranth

0 Kudos

Hi

Remove the modify statement . it should work fine ...If u re still getting the dump paste the description of the dump.

loop at itoutput.

write:/ itoutput-banfn,12 itoutput-badat,24 v_item,50 itoutput-meins,53 itoutput-menge,itoutput-lfdat,

89 ITPO-ebeln,100 ITPO-aedat,111 ITPO-lifnr,(10) itpo-menge, ITPO-eindt.

MODIFY itoutput. <------ not removed - remove this

endloop.

0 Kudos

Hi,

Ok i agree with you all i am making the changes as you had said but it is giving the dump as when the cursor reaches the MODFIY ITOUTPUT.

Here is the following dump:-




Short text
    Error in an ABAP/4 statement when processing an internal table.

What happened?
    Error in the ABAP Application Program

    The current ABAP program "ZNEW04" had to be terminated because it has
    come across a statement that unfortunately cannot be executed.

Error analysis
    You attempted to change, delete or create a line in the
    internal table "\PROGRAM=ZNEW04\DATA=T_FCAT", but no valid cursor exists
    for the table.
    Possible reasons:
    1. The relevent ABAP/4 statement does not include the addition
       "...INDEX...", although the statement is not
       inside a "LOOP...ENDLOOP" loop processing this table.
    2. The relevent ABAP/4 statement was called from within a
       "LOOP...ENDLOOP" loop after a DELETE "\PROGRAM=ZNEW04\DATA=T_FCAT".

0 Kudos

Hey

We all ve suggested you so many times to remove the modify statement . why dont you do that ?

Also when pasting paste the dump info fully including the place where the dump occurs.

Then only we could analyse.

0 Kudos

post the code which you have changed

0 Kudos

First of all please read what i have written in the previous thread that i had removed the MODIFY statement form the final output internal table and i had placed it where you all have mentioned.. Ok, only then it is giving the runtime error.



  385   p_req = itab1-menge - v_tpo.
  386   write :  195 p_req.
  387
  390   modify itoutput.
         endloop.(runtime error occurs here)
  392
  393
  394 loop at itoutput.
  395
  396   write:/ itoutput-banfn,12 itoutput-badat,24 v_item,50 itoutput-meins,53 itoutput-menge,it
  397           89 ITPO-ebeln,100 ITPO-aedat,111 ITPO-lifnr,(10) itpo-menge, ITPO-eindt.
  398
  399 endloop.

Hi,Vikranth.Reddy i have pasted the code in which changes have been made and it is leading to run time error.

Edited by: nav009 on Sep 22, 2009 7:45 AM

Edited by: nav009 on Sep 22, 2009 7:45 AM

0 Kudos

Don comment append since ur populating fields for first time in ITOUTPUT ...Remove the modify and uncomment the append statement..It will work

0 Kudos

Hi,

The endloop after the modify statement should correspond to loop at itoutput. If it is not change the code like this



385   p_req = itab1-menge - v_tpo.
  386   write :  195 p_req.
  387
  390   modify itoutput index sy-tabix.       ".(runtime error occurs here)---> Now you wont get the run time error.  
  391  endloop.
  392
  393
  394 loop at itoutput.
  395
  396   write:/ itoutput-banfn,12 itoutput-badat,24 v_item,50 itoutput-meins,53 itoutput-menge,it
  397           89 ITPO-ebeln,100 ITPO-aedat,111 ITPO-lifnr,(10) itpo-menge, ITPO-eindt.
  398
  399 endloop.

Regards,

Vikranth

0 Kudos

Thats right. If you are populating itoutput for the first time, then use append


385   p_req = itab1-menge - v_tpo.
  386   write :  195 p_req.
  387
  390   append itoutput.
           clear itoutput.
  391  endloop.
  392
  393
  394 loop at itoutput.
  395
  396   write:/ itoutput-banfn,12 itoutput-badat,24 v_item,50 itoutput-meins,53 itoutput-menge,it
  397           89 ITPO-ebeln,100 ITPO-aedat,111 ITPO-lifnr,(10) itpo-menge, ITPO-eindt.
  398
  399 endloop.

0 Kudos

Hi,

Thanks for the guideance,actually i was doing the same way previously but the correction was that of the MODIFY STATEMENT which i was using in the last loop.

But it is again in the same situation, that the finaloutput itab is filling correctly but when i reach the cursor reach the write statement it is just repeating the last values of few columns present in the itouput.

i am not using any modify statement in it.....

0 Kudos

Hi,

Well if you are getting duplicate values in write statement, you may have to delete them before writing them.



sort itoutput by banfn badat meins menge.
delete adjacent duplicates from itoutput comapring banfn badat.

sort itpo by ebeln aedat lifnr.
delete adjacent duplicates from itpo comapring ebeln aedat lifnr.

Also you are not using the loop at itpo in the write statement. Change it to like this.


loop at itoutput.

read table itpo with key menge = itoutput-menge.

if sy-subrc = 0.
write:/ itoutput-banfn,12 itoutput-badat,24 v_item,50 itoutput-meins,53 itoutput-menge,it
            89 ITPO-ebeln,100 ITPO-aedat,111 ITPO-lifnr,(10) itpo-menge, ITPO-eindt.
endif.
endloop.

Regards,

Vikranth

0 Kudos

Hi

This is your code

loop at itoutput.

395

396 write:/ itoutput-banfn,12 itoutput-badat,24 v_item,50 itoutput-meins,53 itoutput-menge,it

397 89 ITPO-ebeln,100 ITPO-aedat,111 ITPO-lifnr,(10) itpo-menge, ITPO-eindt.

398

399 endloop.

I ve jus aligned it like this

loop at itoutput.

write: / itoutput-banfn,

12 itoutput-badat,

24 v_item,

50 itoutput-meins,

53 itoutput-menge,

it

89 ITPO-ebeln,

100 ITPO-aedat,

111 ITPO-lifnr,

(10) itpo-menge,

IITPO-eindt.

endloop.

The above code is wrong.

How can u output the value of ITPO table when ur not looping it.In this loop u can output ony contenets of ITOUTPUT table.

Since u already have fields ebeln , aedat , lifnr & menge in ITOUTPUT u need not read ITPO again also .

Please change the write statement .it ll work fine !

Edited by: Martina Floriette on Sep 22, 2009 8:20 AM

0 Kudos

Hi,

Thanks for your help...It was my fault that i had not seen the write statement and morever the problem of modify statement was there and now by making the modifications in the code,i am getting the desiered output.

Martina Floriette and Vikranth Reddy i am really thanks ful for your help...

Problem solved and i am closing this thread.

Former Member
0 Kudos

YA Modify statement needed to be moved in upper loop.

You placed it at wrong place.Change its place , code will work fine.