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: 

Unable to fill data in Structure

Former Member
0 Kudos

Hello,

i am new to ABAP, started learning a week ago. i am trying to create a structure with 3 fields from two sap tables. Later, i need to fetch data from sap table to populate the structure and display. i am getting an error like "workarea does not contain corresponding components" and when i execute data will be populated in structure but the number of rows is shown (number of rows is 20 but all blank values) i write my code as follows.

TABLES vbak.

TABLES vbap.

SELECT-OPTIONS: so_vbeln FOR vbap-vbeln.

TYPES: BEGIN OF ty_item,

   salesdoch TYPE vbak-vbeln,

   salesdoci TYPE vbap-vbeln,

   materno TYPE vbap-matnr,

   END OF ty_item.

DATA: gt_vbak TYPE STANDARD TABLE OF vbak,

       gs_vbak TYPE vbak,

       gt_vbap TYPE STANDARD TABLE OF vbap,

       gs_vbap TYPE vbap,

       gt_item TYPE STANDARD TABLE OF ty_item,

       gs_item TYPE ty_item.

SELECT vbeln FROM vbak INTO CORRESPONDING FIELDS OF TABLE gt_vbak

   WHERE vbeln IN so_vbeln.

IF gt_vbak IS NOT INITIAL.

   SELECT vbeln matnr FROM vbap INTO CORRESPONDING FIELDS OF TABLE gt_item

     FOR ALL ENTRIES IN gt_vbak

     WHERE vbeln EQ gt_vbak-vbeln.

ENDIF.

LOOP AT gt_item INTO gs_item.

   WRITE: gs_item-salesdoci.

ENDLOOP.



can you please help me how can i fix this issue.

6 REPLIES 6

former_member186746
Active Contributor
0 Kudos

Hi when using into corresponding, the abap compiler matches the exact same names of the fields. So check if the name of the fields in your structure type correspond to the ones in the database.

I would assume that salesdoch TYPE vbak-vbeln, should be salesdoch TYPE vbak-salesdoch (if it exists).


Kind regards, Rob Dielemans

0 Kudos

Thanks a lot for the help. It worked.

matt
Active Contributor
0 Kudos

1) Don't use FOR ALL ENTRIES. Use INNER JOIN. Get into the habit.

2) At no point have you actually specified that you want the table salesdoci selected from the database, so, naturally enough, it's not selected.

Go and read carefully the ABAP help for SELECT.

Also, I suggest you get hold of a (recently published) ABAP tutorial book and work your way through it.

0 Kudos

To add to that. Press F1 frequently when the cursor is positioned on a keyword. Plus pressing CTRL+F8 you can select ABAP examples for various topics.

Former Member
0 Kudos

Thanks for the suggestions. I will certainly follow.

Former Member
0 Kudos

Hi Prasad,

In below query your are retrieving data from field VBELN and MATNR of table VBAP, but if you check structure of internal table gt_item, its filds are salesdoch,  salesdoci,

materno . So system gets confused as in which fields of iternal table gt_item it has to place the records.

   SELECT vbeln matnr FROM vbap INTO CORRESPONDING FIELDS OF TABLE gt_item

     FOR ALL ENTRIES IN gt_vbak

     WHERE vbeln EQ gt_vbak-vbeln.

To resolve above issue you need to mention VBLEN, POSNR and MATNR instead of

   salesdoch,  salesdoci,  materno fields in structure  ty_item.

Thanks & Regards,

Padmakar Kudtarkar