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: 

ALV output display based on date

satvik_panchal
Participant
0 Kudos

Hello Experts,

    I require your guidance regarding one select query.

The selection screen contains a date field only. That date is based on VBRK-AEDAT(Last Changed date). So the output is displayed based on AEDAT field. The condition is that if AEDAT field is blank in VBRK Table, then the output should be displayed based on FKDAT(Billing Date) field in VBRK Table.

The code snippet which I have written is:

types: begin of st_date,
         l_date like sy-datum,
         aedat like vbrk-aedat,
         fkdat like vbrk-fkdat,
         date type datum,
        end of st_date.

data : it_date type table of st_date,
        wa_date type st_date.


selection-screen : begin of block blk with frame title text-001.
  select-options : date for aedat.
selection-screen : end of block blk.


at selection-screen on date.
      select aedat
      from vbrk
      into corresponding fields of table it_date
      where aedat in date.

     if sy-subrc ne 0.
       select fkdat
       from vbrk
       into corresponding fields of table it_date
       where fkdat in date.
     endif.


    So when AEDAT is blank, it is not fetching data based on FKDAT.


  Kindly suggest some changes in the SELECT query.


Thanks and Regards,

Satvik

12 REPLIES 12

Former Member
0 Kudos

Hi Satvik,

In above code if date field is empty it will fetch all the records from vbrk based on fkdat.

Try with this code.

at selection-screen on date.

   if date is not initial.

     select aedat

     from vbrk

     into corresponding fields of table it_date

     where aedat in date.

   else.

     select fkdat

     from vbrk

     into corresponding fields of table it_date

     where fkdat in date.

   endif.

Former Member
0 Kudos

Hi Satvik,

check the date which you are giving that is there in the table vbrk and remove at selection -screen on date.

Regards,

Raman

Former Member
0 Kudos

Hi Satvik,

  The Code you written is correct as per your logic, Check with your VBRK table , whether it will have your Input date for the filed fkdat.

TABLES : VBRK.

types: begin of st_date,

          l_date like sy-datum,

          aedat like vbrk-aedat,

          fkdat like vbrk-fkdat,

          date type datum,

         end of st_date.

data : it_date type table of st_date,

         wa_date type st_date.

selection-screen : begin of block blk with frame title text-001.

   select-options : date for VBRK-aedat.

selection-screen : end of block blk.

at selection-screen .

       select aedat

              from

              vbrk

              into corresponding fields of table it_date

              where aedat in date.

BREAK-POINT.

      if it_date is initial.

        refresh it_date[].

        select fkdat

               from vbrk

        into corresponding fields of table it_date

        where fkdat in date.

      endif.

Regards,

Vijay

Former Member
0 Kudos

is your date select-options field blank, or initial?

0 Kudos

If AEDAT is blank, then it should go for FKDAT

0 Kudos

hi,

If the date AEDAT is blank and FKDAT which is will  not have the input date means???

Rgds,

Vijay SR

0 Kudos

IF AEDAT is blank in the VBRK Table, then the data should be fetched based on FKDAT.

mayur_priyan
Active Participant
0 Kudos

Hi,

Your logic is acting as a validation on the select-option date . As per the code if the Select on the VBRK for AEDAT fails i.e when no values are found for the provided date input, then it needs to select the FKDAT  from VBRK for the same date input.

1. Check whether data is maintained in VBRK for the provided date under FKDAT.

2. Check whether the input date provided is valid or in proper format.

Regards,

Mayur Priyan. S

0 Kudos

Under FKDAT, data is present in the table where AEDAT is blank

0 Kudos

Please let us know the remaining fields.

if VBLEN is also one field in that table, fetch the data from VBRK based on AEDAT and FKDAT into two different tables.

loop AEDAT table and check AEDAT is empty or not. if it is not empty pass AEDAT value to DATE field

else read FKDAT table based on VBELN and pass FKDAT value to DATE field.

i think it works. 🙂

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Try this.

If you need not have to validate, you can place the code after start of selection.

types: begin of st_date,

vbeln type vbrk-vbeln,

          aedat like vbrk-aedat,
         fkdat like vbrk-fkdat,
        end of st_date.

        select vblen aedat fkdat

     from vbrk

     into corresponding fields of table it_date

     where aedat in date.

  

Then check it_date and inside loop, output the date based on the available date.

loop at it_date ....

if it_date-aedat is not initial.

move this field to output.

else.

moved it_date-fkdat to output.

endif.

0 Kudos

Hi Satvik,

  You can do following steps

  1. Select from VBRK based on AEDAT IN date INTO ITAB1. In this query, you wont get any entries where    AEDAT = space.

  2. Select from VBRK based on FKDAT IN date INTO ITAB2.

  3. Append ITAB1 to ITAB3.

  4. Append ITAB2 to ITAB3 where AEDAT IS INITIAL.

Hope this will solve your problem.

Regards,

Peri