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

select statement issue

Former Member
0 Likes
1,223

Dear Experts,

I have 2 tables..VBRP and ZDOX.

I fetch data from vbrp table like below....

SELECT VBELN FKIMG VGBEL VGPOS MATNR ARKTX WERKS ERDAT VSTEL

               FROM VBRP

               INTO TABLE IT_VBRP

               WHERE MATNR IN S_MATNR

               AND      ERDAT IN S_ERDAT.

NOW AFTER EXECUTION DATA COMES TO IT_VBRP...

IF IT_VBRP IS NOT INITIAL.

SELECT WERKS MATNR CREATED_ON FINAL DOCTYP DOCNO FINALQTY

              

               FROM ZDOX

               INTO TABLE IT_ZDOX

               WHERE WERKS = IT_VBRP-WERKS

               AND       MATNR  = IT_VBRP-MATNR

               AND       CREATED_ON = IT_VBRP-ERDAT

               AND      DOCTYP = 'A'.

MY PROBLEM  IS : WHEN I EXECUTE DATA IS NOT COME TO IT_ZDOX.

WERKS, MATNR, CREATED_ON, ARE NOT THE KEY FIELDS OF ZDOX.

SO HOW I CAN FETCH DATA FROM ZDOX TABLE PLEASE SUGGEST ME...

IS THERE ANY CHANGE TO MAKE IN SELECT STATEMENT PLEASE EXPLAIN.

KIND   REGARDS,

AJIT

1 ACCEPTED SOLUTION
Read only

former_member187748
Active Contributor
0 Likes
1,180

Hi Ajit,

if there is not having mandatory data in any of the field werks, matnr and created-on,

then you have to change your AND operation to OR operation,

First check that, the data is present in your ZDOCS, tables or not,

if it is present and any of the fields maynot have data then use as shown below.

SELECT WERKS MATNR CREATED_ON FINAL DOCTYP DOCNO FINALQTY

             

               FROM ZDOX

               INTO TABLE IT_ZDOX

               WHERE WERKS = IT_VBRP-WERKS

              OR       MATNR  = IT_VBRP-MATNR

               OR       CREATED_ON = IT_VBRP-ERDAT

               AND      DOCTYP = 'A'.

9 REPLIES 9
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
1,180

Make this change

SELECT WERKS MATNR CREATED_ON FINAL DOCTYP DOCNO FINALQTY

             

               FROM ZDOX

               INTO TABLE IT_ZDOX

FOR ALL ENTRIES IN IT_VBRP

               WHERE WERKS = IT_VBRP-WERKS

               AND       MATNR  = IT_VBRP-MATNR

               AND       CREATED_ON = IT_VBRP-ERDAT

               AND      DOCTYP = 'A'.

Read only

0 Likes
1,180

@NABNEET...

I USED FOR ALL ENTRIES STATEMENT BUT SORRY FOR GOT TO WRITE HERE.

STILL NO RESULT.

REGARDS,

AJIT

Read only

0 Likes
1,180

First of all dont use CAPITAL letters it does not look good. Secondly did you check in SE16 was their any data available for the data in IT_VBRP which you have given in where clause?  If you say yes then please add the screen shot highlighting IT_VBRP contents for which data is available in Z table. Check carefully the leading zeros also

Nabheet

Read only

Former Member
0 Likes
1,180

Hi Ajit,

Try for all entries in concept. It fetches the data from database table(ZDOX) based on each entry in driver table(IT_VBRP is driver table in your example).

NOTE: While using 'for all entries in' in your select statement, the driver table should not be empty.

Please go through the following code.

SELECT VBELN FKIMG VGBEL VGPOS MATNR ARKTX WERKS ERDAT VSTEL
                FROM VBRP
                INTO TABLE IT_VBRP
                WHERE MATNR IN S_MATNR
                AND      ERDAT IN S_ERDAT.

IF IT_VBRP IS NOT INITIAL.
SELECT WERKS MATNR CREATED_ON FINAL DOCTYP DOCNO FINALQTY
                FROM ZDOX
                INTO TABLE IT_ZDOX
                FOR ALL ENTRIES IN IT_VBRP
                WHERE WERKS = IT_VBRP-WERKS
                AND       MATNR  = IT_VBRP-MATNR
                AND       CREATED_ON = IT_VBRP-ERDAT
                AND      DOCTYP = 'A'.
ENDIF.

Read only

former_member187748
Active Contributor
0 Likes
1,181

Hi Ajit,

if there is not having mandatory data in any of the field werks, matnr and created-on,

then you have to change your AND operation to OR operation,

First check that, the data is present in your ZDOCS, tables or not,

if it is present and any of the fields maynot have data then use as shown below.

SELECT WERKS MATNR CREATED_ON FINAL DOCTYP DOCNO FINALQTY

             

               FROM ZDOX

               INTO TABLE IT_ZDOX

               WHERE WERKS = IT_VBRP-WERKS

              OR       MATNR  = IT_VBRP-MATNR

               OR       CREATED_ON = IT_VBRP-ERDAT

               AND      DOCTYP = 'A'.

Read only

Former Member
0 Likes
1,180

Hi Ajit ,

First to add For all entries in second query ,use sy-subrc  and debug your program and check sy-subrc value .Hopefully you get it .

Regards

Vivek

Read only

Former Member
0 Likes
1,180

Hi Ajit,

           I think may be for your second select query there are no entries corresponding to your WHERE condition.

You can also try.......

                     First select a WERKS, MATNR and ERDAT for  a particular entry from VBRP in SE11 or SE16n t-code and try putting those entries for table ZDOX in SE11 or SE16n just to make sure there are entries available for any document.

Then when you execute place a breakpoint after first SELECT statement and ensure it is not INITIAL atleast some data comes into IT_VBRK. Then for that data try in SE11 or SE16n.

Hope this helps!

Happy Coding,

Santhosh Yadav

Read only

former_member187748
Active Contributor
0 Likes
1,180

Hi Ajit,

if there are entries against the selection fields in your ZDOX, this simply means your

select option is wrong, please put a breakpoint on it and see what is the value of sy-subrc,

if it is 0, and still you are not getting values , means there is no data for the specified

selection range.

Please debug your code, it will gives you the clear idea.

Read only

Former Member
0 Likes
1,180

Dear ,

Thank you @sanjeev, as you said to change AND to OR, I did and now my data is coming to it_zdox itab.