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

Issue in sorting the date

Former Member
0 Likes
2,989

i have sorted the internal table by ascending date_field

if i give the date in selection options as 25.02.2014 to 25.03.2014..

It is printed as 01.03.2014

                       .to

                       .

                      24.03.2014

from next line it is printed as 25.02.2014

                                           25.03.2014

                                          

                                           26.02.2014

                                           26.03.2014

How to rectify this issue...

i need to display it as 25.02.2014 to 25.03.2014 by ascending

16 REPLIES 16
Read only

Former Member
0 Likes
2,907

Hi Vishwaroop,

Can you please post your code here to let us know which technique you are following and where exactly is the problem.

Regards,

Rachna

Read only

bernat_loscos
Explorer
0 Likes
2,907

Hi,

I would like to see your code. Could you paste it here?

Regards

Read only

Former Member
0 Likes
2,907

SORT lT_S1 DESCENDING BY MATNR WERKS SPTAG.

     LOOP AT lt_S1 INTO ls_S1.

       ASSIGN COMPONENT 'WERKS' OF STRUCTURE <DYNWA> TO <L_FIELD>.

       <L_FIELD> = ls_S1-WERKS.

       ASSIGN COMPONENT 'MATNR' OF STRUCTURE <DYNWA> TO <L_FIELD>.

       <L_FIELD> = ls_S1-MATNR.

       ASSIGN COMPONENT 'MAKTX' OF STRUCTURE <DYNWA> TO <L_FIELD>.

       READ TABLE lt_MAKT INTO ls_MAKT WITH KEY MATNR = LS_S1-MATNR.

       IF SY-SUBRC EQ 0.

         <L_FIELD> = LS_MAKT-MAKTX.

       ENDIF.

       ASSIGN COMPONENT 'BASME' OF STRUCTURE <DYNWA> TO <L_FIELD>.

       <L_FIELD> = ls_S1-BASME.

       CALCDAT = LS_S1-SPTAG.

       CONCATENATE CALCDAT+6(2) '.' CALCDAT+4(2) '.' CALCDAT(4) INTO  g_SPTAG.

       ASSIGN COMPONENT 'SPTAG' OF STRUCTURE <DYNWA> TO <L_FIELD>.

       <L_FIELD> = g_SPTAG.

       ASSIGN COMPONENT 'MZUBB' OF STRUCTURE <DYNWA> TO <L_FIELD>.

       <L_FIELD> = ls_S1-MZUBB.

       ASSIGN COMPONENT 'MAGBB' OF STRUCTURE <DYNWA> TO <L_FIELD>.

       <L_FIELD> = ls_S1-MAGBB.

       CALCDAT = LS_S1-SPTAG.

       CALCDAT = CALCDAT - 1.

       CONCATENATE CALCDAT+6(2) '.' CALCDAT+4(2) '.' CALCDAT(4) INTO  G_SPTAG.

       ASSIGN COMPONENT 'OPEN_STOCK' OF STRUCTURE <DYNWA> TO <L_FIELD>.

       IF LS_S1-SPTAG EQ TODAY1.

         READ TABLE LT_MBEW INTO LS_MBEW WITH KEY MATNR = LS_S1-MATNR BWKEY = LS_S1-WERKS.

         IF SY-SUBRC EQ 0.

           OPEN LS_MBEW-LBKUM + LS_S1-MAGBB - LS_S1-MZUBB.

           <L_FIELD> = OPEN.

         ENDIF.

       ELSE.

         OPEN = OPEN + LS_S1-MAGBB - LS_S1-MZUBB.

         <L_FIELD> = OPEN.

       ENDIF.

       CALCDAT = LS_S1-SPTAG.

       CALCDAT = CALCDAT - 1.

       CONCATENATE CALCDAT+6(2) '.' CALCDAT+4(2) '.' CALCDAT(4) INTO  G_SPTAG.

       ASSIGN COMPONENT 'CLOSE_STOCK' OF STRUCTURE <DYNWA> TO <L_FIELD>.

       IF LS_S1-SPTAG EQ TODAY1.

         READ TABLE LT_MBEW INTO LS_MBEW WITH KEY MATNR = LS_S1-MATNR BWKEY = LS_S1-WERKS.

         IF SY-SUBRC EQ 0.

           CLOS = OPEN - LS_S1-MAGBB + LS_S1-MZUBB.

           <L_FIELD> = CLOS.

         ENDIF.

       ELSE.

         CLOS = OPEN - LS_S1-MAGBB + LS_S1-MZUBB.

         <L_FIELD> = CLOS.

       ENDIF.

       APPEND <DYNWA> TO <DYNTABLE>.

       CLEAR<DYNWA>.

     endloop.

     SORT <DYNTABLE> ASCENDING. ( here i gets the problem)

   endmethod.

Read only

0 Likes
2,907

Hi Prathap,

sort <<DYNTABLE> ASCENDING by date_field , make sure that length and data type of it and see how is the format like 'YYYYMMDD' or 'DDMMYYYY'

Can you try declaring the date field as below

data: date_field type sy-datum.

Thanks,

Siva

Read only

0 Likes
2,907

Hi,

Keep one more field in your internal table where you can keep the date in the format - YYYYMMDD or DDMMYYYY without dot (.) and sort the table based on this field.

It should work hopefully. 

Regards,

Munesh.

Read only

former_member188827
Active Contributor
0 Likes
2,907

Make sure that you are declaring the variable as type d instead of type c. Do not refer to your field as Character type variable.

Regards

Read only

0 Likes
2,907

i declared the variable as type d only.

Read only

0 Likes
2,907

But you are assigning the value of G_SPTAG to field symbol which is type c variable. Please check this again.

Regards

Read only

0 Likes
2,907

Yes Sorry i gave it as type c...but if i give it as type d also am getting the same problem

Read only

0 Likes
2,907

Hi Vishwaroop,


You try to change your line "SORT <DYNTABLE> ASCENDING. ( here i gets the problem)"

for this:

SORT <DYNTABLE> ASCENDING BY ('SPTAG').


Regards.

Read only

0 Likes
2,907

tried that also...but still getting same problem

Read only

0 Likes
2,907

Hi Prathap,

Have you tried that ?

Thanks,

Siva

Read only

0 Likes
2,907

DATA: lv_data TYPE dats.

CONCATENATE calcdat(4) calcdat+4(2) calcdat+6(2) INTO lv_data.

* ...

<l_field> = lv_data.

" instead of

* CONCATENATE CALCDAT+6(2) '.' CALCDAT+4(2) '.' CALCDAT(4) INTO  G_SPTAG.

Read only

0 Likes
2,907

Tried siva...its in 'DDMMYYYY'

Read only

0 Likes
2,907

Prathap,

Your G_SPTAG is an string and your assigning those value to some other value ( date_field ) which you have declared it as data type 'C' but now you changed to 'D' right ?

Read only

himanshu_gupta13
Product and Topic Expert
Product and Topic Expert
0 Likes
2,907

Hi Vishwaroop,

Take the date into the internal table having the numeric type of field and then take data in format of YYYYMMDD and sort it and use it as per your requirement.

As I think your date is available iin format DDMMYYYY..

Many Thanks / Himanshu Gupta