‎2009 Mar 24 5:07 AM
Hi Experts..............
i have used the first loop to delete the document with the condition as '101,
and in next loop it has the details such as decription quantity etc etc.....
and my second loop (it_lips to wa_lips) only has the final table to be populated in
my ALV....
My requirement is that i want to link the first loop and the next loop in such a way
that watever document number is there, in my first loop that alone has to go to next loop to
fill the field rest should not come,
I have added this peice of code in loop it_lips further to check and update which satisfies
the loop it_vbfa i dont know how to do....
read table it_vbfa into wa_vbfa with key vbeln = wa_lips-vbeln.
if sy-subrc = 0.
wa_final-vbeln = wa_lips-vbeln.
Endif.
I dont know how to link and make the updation....
Pls do help me out
Thanx in advance
Rachel
Code as follows
=======================
*****For deleting movement typ 101
loop at it_vbfa into wa_vbfa where bwart = '101'.
delete it_vbfa where vbelv = wa_vbfa-vbelv .
Endloop.
*******Final looping
loop at it_lips into wa_lips .
read table it_vbfa into wa_vbfa with key vbeln = wa_lips-vbeln.
if sy-subrc = 0.
wa_final-vbeln = wa_lips-vbeln.
Endif.
read table it_ekpo into wa_ekpo with key ebeln = wa_lips-vgbel.
If sy-subrc = 0.
wa_final-recp = wa_ekpo-werks.
wa_final-rec = wa_ekpo-lgort.
read table it_likp into wa_likp with key vbeln = wa_lips-vbeln.
If sy-subrc = 0.
wa_final-stno = wa_likp-vbeln.
Endif.
Endif.
Append wa_final to it_final.
Endloop.
clear: wa_vbfa, wa_final.
‎2009 Mar 24 5:41 AM
Hi Rachel...
Change the read statemnt which i have given..and check out..
read table it_vbfa into wa_vbfa with key vbeln = wa_lips-vbeln.
if sy-subrc = 0.
wa_final-vbeln = wa_lips-vbeln.
else.
continue.
Endif.
I have added 'ELSE' and 'CONTINUE'.
..cheers..
‎2009 Mar 24 5:19 AM
Hi,
in such cases we usually go for parallel curosor method:
Eg:
loop at it_vbfa into wa_vbfa where bwart = '101'.
delete it_vbfa where vbelv = wa_vbfa-vbelv .
loop at it_lips into wa_lips WHERE vbeln = wa_vbfa-vbeln.
do required calculations here for final looping.
endloop. "Exit for it_lips
endloop. "exit for it_vbfa
Hope it helps!!
Regards,
Pavan
‎2009 Mar 24 5:28 AM
i have the required document number in my first loop after deletion
i want to modify only in the second loop such that it has to fetch the details
only for my first loop doc number ....other doc no should not get append to my final
table , which is the problem iam currently facing.............
‎2009 Mar 24 6:03 AM
Hi,
if you code it like in my earilier thread...i hope it will meet your requirement.
Eg: LOOP AT it_vbfa INTO wa_vbfa.
LOOP AT it_lips INTO wa_lips where vbeln = wa_vbfa-vbeln.
wa_final-vbeln = wa_vbfa-vbeln.
similarly move the other field values to ur final wa structure and append it to final internal table.
append wa_final to it_final.
clear : wa_lips, wa_final.
ENDLOOP.
ENDLOOP.
Hope it works!!
Regards,
Pavan
‎2009 Mar 24 5:24 AM
hey what u want exactly...
u want only the records present in it_vbfa.....?
m i right?
if s then
loop at it_vbfa into wa_vbfa where bwart = '101'.
delete it_vbfa where vbelv = wa_vbfa-vbelv .
loop at it_lips into wa_lips .
read table it_vbfa into wa_vbfa with key vbeln = wa_lips-vbeln.
if sy-subrc = 0.
wa_final-vbeln = wa_lips-vbeln.
Endif.
read table it_ekpo into wa_ekpo with key ebeln = wa_lips-vgbel.
If sy-subrc = 0.
wa_final-recp = wa_ekpo-werks.
wa_final-rec = wa_ekpo-lgort.
read table it_likp into wa_likp with key vbeln = wa_lips-vbeln.
If sy-subrc = 0.
wa_final-stno = wa_likp-vbeln.
Endif.
Endif.
Append wa_final to it_final.
Endloop. -
for it_lips
Endloop.----for vbfa.
clear: wa_vbfa, wa_final.
‎2009 Mar 24 5:31 AM
sorry monica the one u have specified is not satisfying......iam getting double the record items
‎2009 Mar 24 5:35 AM
hi,
define third it and then move ur first it data into third it using tansporting fields and then loop it with ut second table.
‎2009 Mar 24 5:31 AM
Hi,
Try to use for all entries.
According to me the logic would be:
1. Create final table with the final fields which u want in ur ALV display.
2. fetch all fields by using for all entries.
Check out the syntex of for all entries from SDN.
and for field from loop1 alone move to next use 'Transporting fields'.
Cheers,
Rudhir
‎2009 Mar 24 5:33 AM
hi rudhir...
thanx for the reply
i want to know only this part
and for field from loop1 alone move to next use 'Transporting fields'.
how to do in the next loop???
‎2009 Mar 24 5:31 AM
hi:
you have 2 ways like
1. keep master table a main loop and under it, the item loop would be there for further processing.
2. by using join, you can select only fields which is required for final table
Where the relationship is concerned, please find the link
[SAP Relationship|http://www.abap.es/Descargas/TAB%20-%20Relacion%20de%20las%20tablas%20por%20modulos.PDF]
Regards
Shashi
‎2009 Mar 24 5:41 AM
Hi Rachel...
Change the read statemnt which i have given..and check out..
read table it_vbfa into wa_vbfa with key vbeln = wa_lips-vbeln.
if sy-subrc = 0.
wa_final-vbeln = wa_lips-vbeln.
else.
continue.
Endif.
I have added 'ELSE' and 'CONTINUE'.
..cheers..
‎2009 Mar 24 6:17 AM
hi
thanks for the reply , i tried the code but then when it goes to the second loop my sy-subrc = 4
thou
read table it_vbfa into wa_vbfa with key vbeln = wa_lips-vbeln. has a value from first loopp value
‎2009 Mar 24 6:21 AM
Rachel...
I guess thats fine.. are you getting the correct output ??
and yeah..one more thing..rachel..
Clear the WA_FINAL and WA_VBFA....before the ENDLOOP statement.... this is jus good programming practice.. so now they will not have values of first loop when the loop is executed for the second time..
Edited by: SubZero on Mar 24, 2009 7:23 AM
‎2009 Mar 24 6:23 AM
and yeah..one more thing..rachel..
Clear the WA_FINAL and WA_VBFA....before the ENDLOOP statement.... this is jus good programming practice.. so now they will not have values of first loop when the loop is executed for the second time..
‎2009 Mar 24 6:33 AM
‎2009 Mar 24 6:36 AM
‎2009 Mar 24 6:40 AM
‎2009 Mar 24 5:58 AM
Hi Rachel,
Sorry actually i thought u need only one fields from loop1. Transporting fields will not work. By using for all entries only u can solve ur problem.
Dont use loop inside loop. It decreases the performance.
-
*****For deleting movement typ 101 """" According to me this section is OK
loop at it_vbfa into wa_vbfa where bwart = '101'.
delete it_vbfa where vbelv = wa_vbfa-vbelv .
Endloop.
'''''''''''''''''''''''''Now u want the data in final table according to the vbelv in first table.
*******Final looping
SORT it_vbfa by vbeln.
loop at it_lips into wa_lips .
read table it_vbfa into wa_vbfa with key vbeln = wa_lips-vbeln.
''''''''' the whole code should come under the block so that it should fetch the only data relevent to vbeln of loop1. """"""""""""""""""""""""""""""
************************block B1 started with IF********************
if sy-subrc = 0.
wa_final-vbeln = wa_lips-vbeln.
read table it_ekpo into wa_ekpo with key ebeln = wa_lips-vgbel.
If sy-subrc = 0.
wa_final-recp = wa_ekpo-werks.
wa_final-rec = wa_ekpo-lgort.
read table it_likp into wa_likp with key vbeln = wa_lips-vbeln.
If sy-subrc = 0.
wa_final-stno = wa_likp-vbeln.
Endif.
Endif.
Append wa_final to it_final.
Endif.
************************block B1 ENDED with ENDIF********************
Clear wa_final, wa_vbfa.
Endloop.
hope this will help u.
Cheers,
Rudhir
‎2009 Mar 24 6:13 AM
take a look of this . one of thesimplest code.
first define onefinal table like
TYPES : BEGIN OF TY_REPORT,
KUNNR LIKE VBAK-KUNNR, " Customer No.
NAME1 LIKE KNA1-NAME1, " Customer Name.
KDAUF LIKE AFPO-KDAUF, " Sales Order No.
DWERK LIKE AFPO-DWERK, " Plant
AUFNR LIKE AFKO-AUFNR, " Production Order No.
MATNR LIKE AFPO-MATNR, " Material
MAKTX LIKE MAKT-MAKTX, " Material Desc
GAMNG LIKE AFKO-GAMNG, " Target Qty
IGMNG LIKE AFKO-IGMNG, " Confirm QTY
OPEN_QTY LIKE AFKO-GAMNG, " Open Order Qty
END OF TY_REPORT.
*&---------------------------------------------------------------------*
*& Internal tables Begin with it_
*&---------------------------------------------------------------------*
DATA : IT_REPORT type TY_REPORT OCCURS 0 WITH HEADER LINE.
then fetch all data using for all entries like
SELECT * FROM VBAK INTO TABLE IT_VBAK
WHERE KUNNR IN SO_KUNNR
AND ERDAT IN SO_DAT1.
IF SY-SUBRC EQ 0.
SELECT * FROM KNA1 INTO TABLE IT_KNA1
FOR ALL ENTRIES IN IT_VBAK
WHERE KUNNR = IT_VBAK-KUNNR.
SELECT * FROM AFPO INTO TABLE IT_AFPO
FOR ALL ENTRIES IN IT_VBAK
WHERE KDAUF = IT_VBAK-VBELN.
SELECT * FROM AFKO INTO TABLE IT_AFKO
FOR ALL ENTRIES IN IT_AFPO
WHERE AUFNR = IT_AFPO-AUFNR .
SELECT * FROM MAKT INTO TABLE IT_MAKT " Get Raw Material Desc
FOR ALL ENTRIES IN IT_AFPO
WHERE MATNR = IT_AFPO-MATNR.
and then do looping simply like
LOOP AT IT_AFPO.
READ TABLE IT_VBAK WITH KEY VBELN = IT_AFPO-KDAUF.
IT_REPORT-KUNNR = IT_VBAK-KUNNR.
IT_REPORT-KDAUF = IT_AFPO-KDAUF.
IT_REPORT-DWERK = IT_AFPO-DWERK.
IT_REPORT-AUFNR = IT_AFPO-AUFNR.
IT_REPORT-MATNR = IT_AFPO-MATNR.
READ TABLE IT_KNA1 WITH KEY KUNNR = IT_VBAK-KUNNR.
IT_REPORT-NAME1 = IT_KNA1-NAME1.
READ TABLE IT_MAKT WITH KEY MATNR = IT_AFPO-MATNR.
IT_REPORT-MAKTX = IT_MAKT-MAKTX.
READ TABLE IT_AFKO WITH KEY AUFNR = IT_AFPO-AUFNR.
IT_REPORT-GAMNG = IT_AFKO-GAMNG.
IT_REPORT-IGMNG = IT_AFKO-IGMNG.
OPEN_QTY1 = IT_AFKO-GAMNG - IT_AFKO-IGMNG.
IT_REPORT-OPEN_QTY = OPEN_QTY1.
SORT IT_REPORT.
IF IT_REPORT-OPEN_QTY > 0.
APPEND IT_REPORT.
hope u will get idea.