‎2009 Mar 17 5:33 AM
Moved to correct forum.
Hi friends,
I have a problem to upload data in a Report,
My program i given below .
And my selection screen field is - vbeln. Value = 4970.
My problem is when i get the output it shows only 1 record, but in vbap table (value - 4970)
hold 4 record, and vbak hold 1 record.That means it shows 5 record.
but in my report it show 1 record.
why, please tell me .
I confuse.
TABLES : vbak,vbap.
DATA: BEGIN OF it_vbak OCCURS 0,
vbeln LIKE vbak-vbeln,
vkorg LIKE vbak-vkorg,
kunnr LIKE vbak-kunnr,
ernam LIKE vbak-ernam,
END OF it_vbak.
DATA: BEGIN OF it_vbap OCCURS 0,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
matkl LIKE vbap-matkl,
END OF it_vbap.
DATA: BEGIN OF it_final OCCURS 0,
vbeln LIKE vbak-vbeln,
vkorg LIKE vbak-vkorg,
kunnr LIKE vbak-kunnr,
ernam LIKE vbak-ernam,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
matkl LIKE vbap-matkl,
END OF it_final.
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_vbeln FOR vbak-vbeln No-Extension.
SELECTION-SCREEN : END OF BLOCK b1.
START-OF-SELECTION.
PERFORM data-selection.
PERFORM read-data.
FORM data-selection.
SELECT vbeln
vkorg
kunnr
ernam
FROM vbak INTO TABLE it_vbak
WHERE vbeln IN s_vbeln.
SELECT vbeln
posnr
matnr
matkl
FROM vbap INTO TABLE it_vbap
FOR ALL ENTRIES IN it_vbak
WHERE vbeln = it_vbak-vbeln.
ENDFORM. "DATA-SELECTION
*&---------------------------------------------------------------------*
*& Form READ-DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM read-data.
LOOP AT it_vbak.
it_final-vbeln = it_vbak-vbeln.
it_final-vkorg = it_vbak-vkorg.
it_final-kunnr = it_vbak-kunnr.
it_final-ernam = it_vbak-ernam.
READ TABLE it_vbap
WITH KEY vbeln = it_vbak-vbeln.
it_final-posnr = it_vbap-posnr.
it_final-matnr = it_vbap-matnr.
it_final-matkl = it_vbap-matkl.
APPEND it_final.
CLEAR it_final.
LOOP AT it_final.
WRITE: / it_final-vbeln,it_final-vkorg,it_final-kunnr ,it_final-ernam, it_final-posnr,it_final-matnr,
it_final-matkl.
ENDLOOP.
ENDLOOP.
ENDFORM. "READ-DATAUse meaningful Subject for your questions
Edited by: Vijay Babu Dudla on Mar 17, 2009 5:07 AM
Edited by: Matt on Mar 17, 2009 4:18 PM Added tags
‎2009 Mar 17 5:37 AM
‎2009 Mar 17 5:37 AM
‎2009 Mar 17 6:02 AM
Since you are looping at LOOP AT it_vbak which contains only one record. You then use READ TABLE it_vbap to read value of VBAP.
So VBAK loop will interate only once so you get only one record.
In case you want all the records of VBAP then select all the key fields of VBAP into internal table and then change your code.
LOOP AT IT_VBAP
read table IT_VBAK
append IT_FINAL
ENDLOOP.
LOOP AT IT_FINAL
write ......
ENDLOOP.
OR
LOOP AT IT_VBAP
read table IT_VBAK
WRITE ALL THE REQUIRED FIELDS.
ENDLOOP.
Edited by: Sunil Sawaikar on Mar 17, 2009 7:03 AM
‎2009 Mar 17 6:11 AM
Hi,
Use in this way
FORM read-data.
LOOP AT it_vbak.
it_final-vbeln = it_vbak-vbeln.
it_final-vkorg = it_vbak-vkorg.
it_final-kunnr = it_vbak-kunnr.
it_final-ernam = it_vbak-ernam.
loop at it_vbap where vbeln = it_vbak-vbeln.
it_final-posnr = it_vbap-posnr.
it_final-matnr = it_vbap-matnr.
it_final-matkl = it_vbap-matkl.
APPEND it_final.
CLEAR it_final.
endloop.
ENDLOOP.
LOOP AT it_final.
WRITE: / it_final-vbeln,it_final-vkorg,it_final-kunnr ,it_final-ernam, it_final-posnr,it_final-matnr,
it_final-matkl.
ENDLOOP.
ENDFORM. "READ-DATA
U'll all 4 records by this code.
‎2009 Mar 17 9:17 AM
Why do you unnecessary append the values ti any final itab and then looping it write the output.Loop the line item table values and pick up the corresponding header for that.
Do as below.
LOOP AT it_vbap.
it_final-vbeln = it_vbap-vbeln.
it_final-posnr = it_vbap-posnr.
it_final-matnr = it_vbap-matnr.
it_final-matkl = it_vbap-matkl.
READ TABLE it_vbak
WITH KEY vbeln = it_vbap-vbeln.
it_final-vkorg = it_vbak-vkorg.
it_final-kunnr = it_vbak-kunnr.
it_final-ernam = it_vbak-ernam.
WRITE: / it_final-vbeln,it_final-vkorg,it_final-kunnr ,it_final-ernam, it_final-posnr,it_final-matnr,
it_final-matkl.
CLEAR it_final.
ENDLOOP.
ENDFORM. "READ-DATA
‎2009 Mar 17 9:33 AM
> My problem is when i get the output it shows only 1 record, but in vbap table (value - 4970)
> hold 4 record, and vbak hold 1 record.That means it shows 5 record.
with 5 records it can not be a performance issue
If it becomes larger, then you should use BINARY SEARCH or a Sorted tables for the read.
The second LOOP is wrong as already said.
Siegfried
‎2009 Mar 17 10:11 AM
Instead of using two select quries you can join both the tables on the basis of key fields and if your first table holds large no of records then for all entries statement will always create a problem.
For large no of records for all entries statement give dump so better you join both the tables to fetch the records.