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: 

Select Statement in report working but no data brought

Former Member
0 Kudos
229

Hello everybody,

Please I need your help, as I have the following code:

DATA: lw_001 TYPE ztranstab_001.

   SELECT MAX( date )
            FROM zmdmq_tr_t_001
            INTO lw_001-date
            WHERE  field1       EQ '2016'      AND
                   field2      EQ '11'     AND
                   field3     EQ 'xx'    AND
                  field4       EQ '21'.


The trouble is that, in DEV environment the program works well and founds and brings the wanted record (trying to obtain maximum date when certain field equals 11, xx and 21).


But, in QAS I have transported the program, and when executing, it indicates SY-SUBRC = 0 (which means a record was found), but in 'lw_001-date' it shows '000000', and when looking up the records manually in the table through SE16N and filtering by the fields specified before (gjahr, id_esp, especie and nivel) I can see that the maximum date, accomplishing all fields, is in this case '20160702'.


Is like the table would have records with '000000' or something like that but table is correctly filled. Could it be something about transport request or dynpro transport missing so program does not recognize table?

Thanks in advance.

Kleight.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
82

Ok, so I have figured out what was the problem. The issue is using sy-subrc after a SELECT MAX or SELECT SINGLE MAX. This statement brings the maximum value of a field even if no records are found. So, as no record was found, but statement still has to bring maximum value, it brings the maximum value of cero, which is, for this case, '00000000', but will still show sy-subrc as '0' or successful because it is indeed obtaining the maximum of null.

As a solution, I have created internal table, filled it with the one i was doing Select From, then sort by date and later reading the first result.

Thanks.

3 REPLIES 3

Sandra_Rossi
Active Contributor
0 Kudos
82

Does it really show '000000', with 6 zeroes? and not 8 zeroes? That must be a good clue for finding the problem...

0 Kudos
82

It actually shows 8 zeros

Former Member
0 Kudos
83

Ok, so I have figured out what was the problem. The issue is using sy-subrc after a SELECT MAX or SELECT SINGLE MAX. This statement brings the maximum value of a field even if no records are found. So, as no record was found, but statement still has to bring maximum value, it brings the maximum value of cero, which is, for this case, '00000000', but will still show sy-subrc as '0' or successful because it is indeed obtaining the maximum of null.

As a solution, I have created internal table, filled it with the one i was doing Select From, then sort by date and later reading the first result.

Thanks.