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

sort in table maintenance?

Former Member
0 Likes
4,574

Hi.

I wanted to add sort functionality in table maintenance.

I just don't know how to do it, why?

I founf there is a table called extract in PBO just b4 the loop with table control. The table is dynamic (??) and is defined as 128 char without fields so sort will not wotk .

moreover when I try to define a routine I can't access this 'EXTRACT', for some reason I can't find where it is defined, or how can I access it.

Ariel Fisher

PS

the solution of building dialog from scratch seemed to be tedious.

13 REPLIES 13
Read only

andreas_mann3
Active Contributor
0 Likes
2,508

Hi Ariel,

I guess , it's an extract defined with field-groups (-> F1 field-groups; extract) - pl. post a piece of code !

Grx Andreas

Read only

nablan_umar
Product and Topic Expert
Product and Topic Expert
0 Likes
2,508

Hi Ariel,

You can try do this.

1. Declare a global internal table with structure of the database table you are maintaining.

2. In your PBO before the loop on table control, call a module pool, name it SORT for example.

3. In this module port, copy EXTRACT to the global internal table you declared in 1. You can do GT_TAB[] = EXTRACT[].

4. Sort this global internal table according to the key you like.

5. Copy back the global internal table to EXTRACT. You can do something like this: EXTRACT[] = GT_TAB[].

You extract internal table is now sorted accordingly.

Read only

Former Member
0 Likes
2,508

Hi Ariel,

Via transaction SE54 enter the name of your table, select the 'Generated Objects' radiobutton and hit 'Change'.

In the next screen use the menu to navigate to Environment -> Modification - > Events.

More than 30 events have been defined to which you can react with your own coding. You might want to use event 'AA' to replace the standard reading routine with your own.

I think this might solve your problem?

Regards,

John.

Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
2,508

Hi Ariel

EXTRACTs are special structures used in ABAP programming.

Since internal tables have fixed line structures, they are not suited to handle data sets with varying structures. Instead, you can use extract datasets for this purpose.

An extract is a sequential dataset in the memory area of the program. You can only address the entries in the dataset within a special loop. The index or key access permitted with internal tables is not allowed. You may only create one extract in any ABAP program. The size of an extract dataset is, in principle, unlimited. Extracts larger than 500KB are stored in operating system files. The practical size of an extract is up to 2GB, as long as there is enough space in the filesystem.

<u>About your problem:</u>

So, you can add a sorting statement to the generated screen. Here is the procedure about sorting an extract.

<b>Sorting an Extract</b>

You can sort an extract dataset in much the same way as an internal table by using the following statement:

SORT [ASCENDING|DESCENDING] [AS TEXT] [STABLE]

BY <f1> [ASCENDING|DESCENDING] [AS TEXT]

...

<fn> [ASCENDING|DESCENDING] [AS TEXT].

The SORT statement terminates the creation of the extract dataset of a program and, at the same time, sorts its records. Without the BY option, the system sorts the dataset by the key specified in the HEADER field group.

You can sort an extract dataset as often as you like in a program, using any number of different keys. The only prerequisite is that all fields by which you want to sort are contained in the HEADER during the extraction process. You must not use the SORT statement between LOOP and ENDLOOP. However, you can sort and read the extract dataset in any sequence. No further EXTRACT statements may occur after the sort statement, otherwise a runtime error occurs.

You can find more information at:

http://help.sap.com/saphelp_47x200/helpdata/en/9f/db9f1235c111d1829f0000e829fbfe/frameset.htm

*--Serdar

Read only

Former Member
0 Likes
2,508

Hi there.

The point is I didn't find any field groups .

The EXTRACT is definietly a TABLE it is defined in the include LSVIMFTX..

More in detail:

1st it fills a table TOTAL (include LSVIMFTX)

SELECT * FROM (X_HEADER-MAINTVIEW) INTO TABLE TOTAL.

2nd it call the function

.... WHEN 'MIDDLE'.

CALL FUNCTION FUNCTION_NAME

EXPORTING

FCODE = TCF_FCODE

VIEW_ACTION = MAINT_MODE

VIEW_NAME = X_HEADER-VIEWNAME

CORR_NUMBER = CORR_NBR

IMPORTING

UCOMM = FUNCTION

UPDATE_REQUIRED = TCF_UPD_FLAG

TABLES

DBA_SELLIST = DBA_SELLIST

DPL_SELLIST = DPL_SELLIST

EXCL_CUA_FUNCT = EXCL_CUA_FUNCT

X_HEADER = X_HEADER

X_NAMTAB = X_NAMTAB

CORR_KEYTAB = E071K_TAB

EXTRACT = EXTRACT_M

TOTAL = TOTAL_M

EXCEPTIONS

MISSING_CORR_NUMBER = 01

SAVING_CORRECTION_FAILED = 03.

definition of extract_M: (include LSVIMTDT)

BEGIN OF EXTRACT_M OCCURS 0,

LINE(128),

END OF EXTRACT_M,

the function name is the one defined in se54 under generated function modules -> edit data.

The EXTRACT table is the 1 defined in the function above.

It is not an EXTRACT with field groups.

I will try to rephrase the question.

The table is char 128 and there are no fields !!!

I want to sort this table using "keys"(as if there were real table keys).

I found the above line and I can't really understand it.

SORT extract BY <vim_extract_key>.

when i looked at the contents of <> it contained values of one line ????

Hope it was enough info

Thanks

Ariel Fisher

Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
2,508

Hi Ariel

Here is what I did.

<b>Step 1:</b>

Insert a module line after the module "LISTE_INITIALISIEREN" .

e.g.

<i>PROCESS BEFORE OUTPUT.

MODULE LISTE_INITIALISIEREN.

<b> MODULE sort .</b>

LOOP AT EXTRACT ...

...</i>

<b>Step 2:</b>

In your new module (in my example "sort"), do the sorting as follows. I will sort my table by the field "f3" .Thank God because ABAP gives assignment regardless of structures of both sides. Here what I mean:

e.g.

<i>MODULE sort OUTPUT.

DATA gt_ztest LIKE ztest OCCURS 1 WITH HEADER LINE .

*--Getting the content of extract in an internal table

*-having the structure of my table.

gt_ztest[] = extract[] .

*--Sorting it

SORT gt_ztest BY f3 .

*--Restoring extract from my sorted table

extract[] = gt_ztest[] .

ENDMODULE. " sort OUTPUT</i>

Hope this helps...

*--Serdar

Read only

0 Likes
2,508

Hi

extract] = gt_ztest[ .

gt_ztest] = extract[ .

is showing error, 'The field "EXTRACT[" is unknown, but there is a field with the similarname "EXTRACT". .'

what can I do..

Regards,

Lakshmikanth

Read only

0 Likes
2,508

Hi ,

Thanks To ALL ,

My same proble solved I did the same as mentioned above .

Write code as mentioned below , it will definately solve your problem for sorting of maintanance table depends upon fields of table.

Insert " Module sort "

PROCESS BEFORE OUTPUT.

MODULE LISTE_INITIALISIEREN.

MODULE sort .

now ,

module SORT output.

data : gt_ztable like ztable OCCURS 1 WITH HEADER LINE .

gt_ztable[] = extract[].

sort gt_ztable by field1 field2 .

EXTRACT[] = gt_ztable[].

endmodule. " SORT OUTPUT

Read only

0 Likes
2,508

it is [] medium bracket not open bracket -[- .

symbol not coming properly check out .

Edited by: vishwassap on Jun 3, 2010 12:49 PM

Read only

0 Likes
2,507

The abovementioned code gives a problem when clicking the button "New Entries". To prevent sorting when this button is clicked, instead use this code:

     module SORT_EXTRACT output.
     data: gt_zarea like zarea OCCURS 1 WITH HEADER LINE .
     if not sy-ucomm = 'NEWL'.
       gt_zarea[] = extract[].
       sort gt_zarea by Z_AREA VKORG COUNTRY ZIPCODE_FROM ZIPCODE_TO.
       EXTRACT[] = gt_zarea[].
     endif.
     endmodule.                 " SORT_EXTRACT  OUTPUT

Best regards,

Tim van Steenbergen

Read only

Former Member
0 Likes
2,507

Hi.

I did use the events and changed the reading and added order by in the select clause, and it looked GR8!

BUT...

When I edited records sometimes it told me the record allready been saved and just didn't take my changes.

I guess that it didn't know on the new order, and the index is now not the same ???

Ariel Fisher

Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
2,507

Hi Ariel

Yes, this side effect may occur since it may backup the content at the beginning. It is the original code and you can modify to some extend...

*--Serdar

Read only

0 Likes
2,507

This has been a great help to me, as all the tips given by Nablan, John, Serdar were very useful. Thanks for the question and the answers.

Thanks.

Regards,

Subramanian V.