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

report

Former Member
0 Likes
701

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-DATA

Use 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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
678

Hello

Refer this link:

6 REPLIES 6
Read only

Former Member
0 Likes
679

Hello

Refer this link:

Read only

Former Member
0 Likes
678

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

Read only

Former Member
0 Likes
678

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.

Read only

Former Member
0 Likes
678

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

Read only

Former Member
0 Likes
678

> 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

Read only

Former Member
0 Likes
678

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.