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: 

VBAK AUDAT...?

Former Member
0 Kudos
304

Hi All,

From vbak table I would like to select all AUDATu2019s and I have to display some thing like this.

Say I have dates like as below in SAP

11.03.2005

17.03.2005

13.06.2005

29.09.2005

29.09.2005

29.09.2005

I want to display like only (Year and month) and no.of records in each Month.

Like this

2005-03 2

2005-06 1

2005-09 3

Please let me know how..?

Puppy.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
95

Hi,

Try below logic in your code.

wa_date1-date1 = '13062005'.

APPEND wa_date1 TO li_date1.

wa_date1-date1 = '29092005'.

APPEND wa_date1 TO li_date1.

wa_date1-date1 = '29092006'.

APPEND wa_date1 TO li_date1.

wa_date1-date1 = '29092006'.

APPEND wa_date1 TO li_date1.

LOOP AT li_date1 INTO wa_date1.

wa_date3-zdate = wa_date1-date1+0(2).

wa_date3-zmonth = wa_date1-date1+2(2).

wa_date3-zyear = wa_date1-date1+4(4).

APPEND wa_date3 TO li_date3.

APPEND wa_date3 TO li_date4.

CLEAR wa_date3.

ENDLOOP.

SORT li_date3 BY zyear zmonth zdate.

SORT li_date4 BY zyear zmonth zdate.

DELETE ADJACENT DUPLICATES FROM li_date3 COMPARING zyear.

LOOP AT li_date3 INTO wa_date3.

LOOP AT li_date4 INTO wa_date4 WHERE zyear = wa_date3-zyear.

temp = temp + 1.

IF temp <> 1.

AT NEW zmonth.

WRITE:/ wa_date4-zyear, '-', zmonth_temp, ' = ', count.

clear: count.

ENDAT.

ENDIF.

count = count + 1.

zmonth_temp = wa_date4-zmonth.

ENDLOOP.

WRITE:/ wa_date4-zyear, '-', zmonth_temp, ' = ', count.

CLEAR: count, temp.

ENDLOOP.

7 REPLIES 7

Sandeep_Kumar
Product and Topic Expert
Product and Topic Expert
0 Kudos
95

try this:

loop at itab.

on change of year.

loop at itab again where year = on change of year.

at new month.

collect records.

end at.

endloop.

end on .

endloop.

0 Kudos
95

Could you pls little bit clear...

how to divide the date and how to count no.of records..

pls let me know

puppy.

Sandeep_Kumar
Product and Topic Expert
Product and Topic Expert
0 Kudos
95

For month you can take the two char of the string based on type of string.

Count number of records for each month and put in another internal table.

Former Member
0 Kudos
96

Hi,

Try below logic in your code.

wa_date1-date1 = '13062005'.

APPEND wa_date1 TO li_date1.

wa_date1-date1 = '29092005'.

APPEND wa_date1 TO li_date1.

wa_date1-date1 = '29092006'.

APPEND wa_date1 TO li_date1.

wa_date1-date1 = '29092006'.

APPEND wa_date1 TO li_date1.

LOOP AT li_date1 INTO wa_date1.

wa_date3-zdate = wa_date1-date1+0(2).

wa_date3-zmonth = wa_date1-date1+2(2).

wa_date3-zyear = wa_date1-date1+4(4).

APPEND wa_date3 TO li_date3.

APPEND wa_date3 TO li_date4.

CLEAR wa_date3.

ENDLOOP.

SORT li_date3 BY zyear zmonth zdate.

SORT li_date4 BY zyear zmonth zdate.

DELETE ADJACENT DUPLICATES FROM li_date3 COMPARING zyear.

LOOP AT li_date3 INTO wa_date3.

LOOP AT li_date4 INTO wa_date4 WHERE zyear = wa_date3-zyear.

temp = temp + 1.

IF temp <> 1.

AT NEW zmonth.

WRITE:/ wa_date4-zyear, '-', zmonth_temp, ' = ', count.

clear: count.

ENDAT.

ENDIF.

count = count + 1.

zmonth_temp = wa_date4-zmonth.

ENDLOOP.

WRITE:/ wa_date4-zyear, '-', zmonth_temp, ' = ', count.

CLEAR: count, temp.

ENDLOOP.

Former Member
0 Kudos
95

Hi Puppy,

Go through this Code.

REPORT YTEST12.

data: begin of itab occurs 0,

audat like vbak-audat,

end of itab.

data: begin of jtab occurs 0,

monyear type char7,

count type i,

end of jtab.

data jtab1 like table of jtab with header line.

data: wa_itab like line of itab,

lv_count type i value 2.

start-of-selection.

select audat from vbak into table itab.

sort itab by audat.

loop at itab.

concatenate itab-audat0(4) '-' itab-audat4(2) into jtab-monyear.

append jtab.

endloop.

loop at jtab.

lv_count = lv_count + 1.

on change of jtab-monyear.

move jtab-monyear to jtab1-monyear.

jtab1-count = lv_count.

clear lv_count.

append jtab1.

endon.

endloop.

Regards,

Santosh Kumar Mukka.

Former Member
0 Kudos
95

Hi,

Try like this

DATA: w_date TYPE string,
      w_month TYPE string,
      w_year TYPE string,
      count TYPE string VALUE '1',
      w_prev_date TYPE sy-datum.
LOOP AT it_vbak INTO wa_vbak.

  w_month = wa_vbak-audat+4(2).
  w_year = wa_vbak-audat+0(4).

  IF w_prev_date = wa_vbak-audat.
    count = count + 1.
    CLEAR w_date.
    CONCATENATE w_year '-' w_month INTO w_date .
    CONCATENATE w_date count INTO w_date SEPARATED BY space.
  ENDIF.

  w_prev_date = wa_vbak-audat.


ENDLOOP.

WRITE:w_date.

Thanks & Reagrds,

Anagha Deshmukh

Former Member
0 Kudos
95

HI PUPPY,

take this one. its working.


data : begin of it_date OCCURS 0,
         year_mon(7) type c,
         count type i,
         end of it_date.

       data : begin of it_final OCCURS 0,
         year_mon(7) type c,
         count type i,
         end of it_final.

*suppose ur date is audat =  11.03.2005  ie. 20050311

data : lv_year(4) type c,
         lv_mon(2) type c.
data : it_vbak TYPE vbak OCCURS 0 WITH HEADER LINE.
select * from vbak into TABLE it_vbak
  where auart = 'ZIO2'
  AND VKORG = 'IN12'.
  data : lv_year_mon(7) type c.

Loop at it_vbak.

lv_year = it_vbak-audat(4).
lv_mon = it_vbak-audat+4(2) .

CONCATENATE lv_year '-' lv_mon into lv_year_mon .
move lv_year_mon to it_date-year_mon.
append it_date .
endloop.

*then u will get all data in it_date.
data : count type i.
count = 0.

Loop at it_date.

if it_final-year_mon = it_date-year_mon.
count = count + 1.
it_final-count = count .
it_final-year_mon = it_date-year_mon.
append it_final.
ELSE.
  count = 1.
it_final-count = 1.
it_final-year_mon = it_date-year_mon.
append it_final.
endif.
endloop.



break mtabap.
*sort it_final DESCENDING BY COUNT.

 data : begin of it_final1 OCCURS 0,
         year_mon(7) type c,
         count type i,
         end of it_final1.
DATA : FLAG(1) TYPE C.


LOOP AT IT_FINAL.
 AT END OF YEAR_MON.
   FLAG = 'X'.
 ENDAT.

IF FLAG = 'X'.
  IT_FINAL1-YEAR_MON = IT_FINAL-YEAR_MON.
  IT_FINAL1-COUNT = IT_FINAL-COUNT.
  APPEND IT_FINAL1.
  CLEAR FLAG.
ENDIF.
ENDLOOP.

TYPE-POOLS : SLIS.

*DATA Declaration

DATA: i_sflight TYPE TABLE OF sflight,
      i_fcat type slis_t_fieldcat_alv,
      wa_fcat TYPE slis_fieldcat_alv.


wa_fcat-tabname = 'IT_FINAL'.
WA_FCAT-COL_POS = 1.
WA_FCAT-FIELDNAME = 'YEAR_MON'.
WA_FCAT-SELTEXT_L = 'YERA/MON'.

APPEND WA_FCAT TO I_FCAT.



WA_FCAT-COL_POS = 2.
WA_FCAT-FIELDNAME = 'COUNT'.
WA_FCAT-SELTEXT_L = 'COUNT'.

APPEND WA_FCAT TO I_FCAT.


   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          IT_FIELDCAT          = I_FCAT
        TABLES
          T_OUTTAB            = it_final1.