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

Problem in sorting of table

Former Member
0 Likes
654

Hi Friends:

Below are the records in my table:

a...|b|c...... |d.....|e................|f

100||25000|......|0000012998|0002259999

100|*|25000|1405|0000012998|0002251405

100|*|25000|1406|0000012998|0002251406

100|*|25000|1407|0000012998|0002251407

100|*|25000|1409|0000012998|0002251409

100|*|25000|1410|0000012998|0002251410

100|*|25000|1411|0000012998|0002251411

100|*|25000|1419|0000012998|0002251419

100|*|25000|1420|0000012998|0002251420

100|*|25000|1421|0000012998|0002251421

a = client

b= Leg.Dept Code

c= Legacy Product

d= Legacy Location

e= Cost Center

f= Profit Center

Please consider '.' as space.

The problem arises in the sorting of the table records. The first record shown in the record set above has the following entry:

a...|b|c...... |d.....|e................|f

100||25000|......|0000012998|0002259999

This is the default entry that is to be used if there is no Leg.Location (where Leg. Location = *). If there is an entry for the specific Leg. Location, then it should be used prior to using this record.

Problem appears to be that the ABAP program locates this default record prior to encountering the specific record, for example:

a...|b|c...... |d.....|e................|f

100|*|25000|1419|0000012998|0002251419

Because the program encounters the wildcard one first, even if the Leg. Location that the program is searching for is 1419 (which appears in the table, just lower in the listing) the program returns a Profit Center of 2259999 instead of the correct value of 2251419.

Is it possible to change the native sort of this table so that the wildcard entries appear at the bottom of the listing instead of the top? If yes, can it be done permanently.

This would allow the program to encounter the specific entries prior to encountering the wildcard ones.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
628

hi,

you have to use READ statement to fetch the appropriate record after sorting. even if u sort..how can u expect the 1419 record to appear first? as it doesnt have any value that will put this record as the first one !!

regards,

madhu

4 REPLIES 4
Read only

Former Member
0 Likes
629

hi,

you have to use READ statement to fetch the appropriate record after sorting. even if u sort..how can u expect the 1419 record to appear first? as it doesnt have any value that will put this record as the first one !!

regards,

madhu

Read only

Former Member
0 Likes
628

The problem in getting the default record to the top is the fact you are using an *. In hex this has a value of 42, which will sort before

all letter and numbers.

Change your * to one of the characters { | } ~ or _. these have hex values of 123 to 127, all of which come after the last number/letter which is z at 122.

If you need to use *, try converting it to one of the other characters before the sort using TRANSLATE, then after the sort, TRANSLATE it back.

Edited by: Paul Chapman on Jun 3, 2008 7:19 AM

Read only

0 Likes
628

Hi Paul:

Thanks for your response. Can you please look at the code below. Actually I've got this issue in the form of a ticket.

FORM resolve_product_code TABLES pt_accntmap TYPE gtty_accntmap

USING p_structraw TYPE gty_structraw.

DATA: lwa_structraw TYPE gty_structraw,

lwa_accntmap TYPE gty_accntmap,

lt_accntmap TYPE gtty_accntmap.

MOVE p_structraw TO lwa_structraw.

lt_accntmap[] = pt_accntmap[].

LOOP AT lt_accntmap INTO lwa_accntmap.

CLEAR: lwa_accntmap-accntcompstr,

lwa_accntmap-fndtype,

lwa_accntmap-posi2.

IF lwa_accntmap-z_product CA '*_'.

TRANSLATE lwa_accntmap-z_product USING '_+'.

  • SEARCH lwa_structraw-proddiv FOR lwa_accntmap-z_product.

IF lwa_structraw-proddiv CP lwa_accntmap-z_product.

  • IF sy-subrc EQ 0.

lwa_accntmap-accntcompstr = lwa_structraw-proddiv.

lwa_accntmap-fndtype = '*'.

lwa_accntmap-posi2 = sy-fdpos.

ENDIF.

ELSE.

  • Must be a full match to win

IF lwa_structraw-proddiv EQ lwa_accntmap-z_product.

lwa_accntmap-accntcompstr = lwa_structraw-proddiv.

lwa_accntmap-fndtype = space.

lwa_accntmap-posi2 = 6.

ENDIF.

ENDIF.

MODIFY lt_accntmap FROM lwa_accntmap

TRANSPORTING accntcompstr fndtype posi2.

ENDLOOP.

IF sy-subrc EQ 0.

  • Remove any unresolved entries based on Natural Account Code

DELETE lt_accntmap WHERE accntcompstr NE lwa_structraw-proddiv.

ENDIF.

pt_accntmap[] = lt_accntmap[].

ENDFORM. " resolve_product_code

Can you please help me with the exact problem in this code.Or if you can give me some idea. It would be a great help.

Read only

0 Likes
628

Not really sure what I'm looking for as an issue.

If this is code you put in at my suggestion, then it is not correct.


IF lwa_accntmap-z_product CA '*_'.
TRANSLATE lwa_accntmap-z_product USING '_+'.

What you would have to do is loop thru the table like this


  LOOP AT lt_accntmap INTO lwa_accntmap.
    IF lwa_accntmap-z_product CA '*'.
      TRANSLATE lwa_accntmap-z_product USING '*_'.
      modify lt_accntmap from lwa_accntmap.
    endif.
  endloop.
  
  sort lt_accntmap.

  LOOP AT lt_accntmap INTO lwa_accntmap.
    IF lwa_accntmap-z_product CA '_'.
      TRANSLATE lwa_accntmap-z_product USING '_*'.
      modify lt_accntmap from lwa_accntmap.
    endif.
  endloop.

now the table is sorted the way you requested originally.

It may even be wiser to check like this


IF lwa_accntmap-z_product+0(1) eq '*'.
  lwa_accntmap-z_product+0(1) = '_'.

Even better


  LOOP AT lt_accntmap INTO lwa_accntmap
    where z_product+0(1) eq '*'.
      lwa_accntmap-z_product+0(1) = '_'.
      modify lt_accntmap from lwa_accntmap.
  endloop.
  
  sort lt_accntmap.

  LOOP AT lt_accntmap INTO lwa_accntmap
    where z_product+0(1) eq '_'.
      lwa_accntmap-z_product+0(1) = '*'.
      modify lt_accntmap from lwa_accntmap.
  endloop.

Edited by: Paul Chapman on Jun 3, 2008 7:57 AM