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

Sorting internal table with line types

Former Member
0 Likes
1,238

Hi,

I have internal table juts for an example with four entries as below:

A[]

Line.....Line Types

444001.....P

New York...C

Evershine..B

Mary.......N

I want to sort the internal table with line types in order of lin types NBCP.

How can i do this ?

Please help.

Note: Above example is just with four entries, there might be internal table with ten entries and ten defined sorting order for line types.

1 ACCEPTED SOLUTION
Read only

Manohar2u
Active Contributor
0 Likes
1,072

sort internal table with field line types should work

else

You should remake/new internal table with

Line types....Line...

then sort it.

8 REPLIES 8
Read only

Manohar2u
Active Contributor
0 Likes
1,073

sort internal table with field line types should work

else

You should remake/new internal table with

Line types....Line...

then sort it.

Read only

Former Member
0 Likes
1,072

You missed my point completely. The sort order is not going to be always as I said in example.

It can be anything which I will write in program.

I cannot use sort by line types

Read only

Former Member
0 Likes
1,072

Hi Tushar,

Is there any way that you can add a new field to your internal table .

Counter : Type I.

Counter Line.....Line Types

4 444001.....P

3 New York...C

2 Evershine..B

1 Mary.......N

Thensort your internal table by Counter. You can assign value to the counter while writng the program to populate the data in internaltable.

May be this is use ful for you.

Lanka

Read only

Former Member
0 Likes
1,072

have another field in the itab where you would specify the sort order(that field will be populated by you) and sort based on that field...

thanks,

Renjith

Read only

Former Member
0 Likes
1,072

Hi,

I am using following code.

The data gets automatically populated in gt_address with some predefined sap LINE_TYPE ORDER.

But when I print the data I want it in 1S678ITHOL order.

TYPES: BEGIN OF szadr_printform_table_line,

line_type TYPE ad_line_tp,

address_line LIKE adrs-line0,

END OF szadr_printform_table_line.

TYPES: szadr_printform_table TYPE szadr_printform_table_line OCCURS 0.

DATA: gt_line TYPE szadr_printform_table_line.

DATA: gt_address TYPE szadr_printform_table.

CALL FUNCTION 'ADDRESS_INTO_PRINTFORM'

EXPORTING

ADDRESS_TYPE = '1'

ADDRESS_NUMBER = '0000022786'

SENDER_COUNTRY = 'US'

NUMBER_OF_LINES = '10'

IMPORTING

ADDRESS_PRINTFORM_TABLE = gt_address[].

Read only

Former Member
0 Likes
1,072

Hi Tushar,

Try this :

TYPES: BEGIN OF szadr_printform_table_line,

line_type TYPE ad_line_tp,

address_line LIKE adrs-line0,

END OF szadr_printform_table_line.

TYPES: szadr_printform_table TYPE szadr_printform_table_line OCCURS 0.

DATA: gt_line TYPE szadr_printform_table_line.

DATA: gt_address TYPE szadr_printform_table.

TYPES: BEGIN OF szadr_printform_table_line1,

Counter type sy-tabix,

line_type TYPE ad_line_tp,

address_line LIKE adrs-line0,

END OF szadr_printform_table_line1.

TYPES: szadr_printform_table1 TYPE szadr_printform_table_line1 OCCURS 0.

DATA: gt_line1 TYPE szadr_printform_table_line1.

DATA: gt_address1 TYPE szadr_printform_table1.

CALL FUNCTION 'ADDRESS_INTO_PRINTFORM'

EXPORTING

ADDRESS_TYPE = '1'

ADDRESS_NUMBER = '0000023153'

SENDER_COUNTRY = 'US'

NUMBER_OF_LINES = '10'

LINE_PRIORITY = '1SLO'

IMPORTING

ADDRESS_PRINTFORM_TABLE = gt_address[].

Loop at gt_address into gt_line.

move-corresponding gt_line to gt_line1.

if gt_line-line_type = 'S'.

Move '1' to gt_line1-counter.

elseif --

-


endif.

append gt_line1 to gt_address1 .

endloop.

Sort GT_ADDRESS1 by COUNTER

Lanka

Read only

Former Member
0 Likes
1,072

Hi Lanka,

Thanks for your reply and efforts you are helping me out. I am just wondering why do we need push a counter value and do sorting again. Can't we use define our line_priority in the function and get the address in the way we want ?

Thanks

Read only

Former Member
0 Likes
1,072

Hi Tushar,

Please note that we can't changes the mandatory sequence of the address format as defined in the country specif address format. We can change the sequence of others fields by line_priority.

Try to change the address type :

ADDRESS_TYPE - Address type (from 3.0C)

There are three types of address:

Address type '1': addresses of firms or organizations; the address structure which is used in most SAP applications as 'Address'.

Address type '2': address of a person

Address type '3': work address, usually the address of a contact person in a company

Please use T/code "OY01"> Select Country> Example :AU"--> Display --> Select address key and press F1. You will find SAP 's Address format configuration .

sap help:

Formatting Routine Key for Printing Addresses

For printing addresses, there are country-specific routines which in each case copy the correct postal formatting of the address.

The three-character "Address Layout Key" for the recipient country controls which of the routines available for formatting addresses in the relevant country is used.

These routines are programmed into the ADDRESS_INTO_PRINTFORM function module.

They are based on different national and international guidelines and norms, including:

ISO 11180,

contracts of the World Postal Union (Seoul 1994),

international address samples from the World Postal Union

as well as the available rules of the individual countries.

Below you will find an overview of the country-specific formats currently implemented.

Customers can program their own formatting routines using a customer exit. The SZAD0001 SAP enhancement has been defined in the package SZAD for this (-> transaction CMOD).

General formatting rules

The following parameters are used depending on the transaction:

whether the company address (street/house number) or the P.O. Box address is printed if both exist,

how many lines are available for printing,

which is the sender country.

If there are not enough lines, then lines are left out according to a standard sequence.

The address format depends on whether the sender country is the same as, or different from, the recipient country. The country is always specified from abroad, either as a text name, or as an identification code of up to three characters (license plate code or country key).

Where the country name is written out in full, it is written in the language of the sender country. If a language is not specified for the sender country, or the sender country itself is not specified, the logon language is used instead.

Exception: the language for the country code can be explicitly overwritten by a parameter in the print program (e.g. when the country code for customs transit papers is always to be specified in a particular language, such as English). if the "Print country name in recipient language" flag is set in the print program, the recipient language is used.

Other language-dependent components such as the title and the word 'PO Box' are printed in the recipient language or the recipient country language. If this cannot be determined, the logon language is again used.

For all formats except Great Britain (006), Japan (013), and South Korea (017), the core of the address is formatted as follows (without empty lines, except for the compulsory empty line:)

title line (if applicable)

name block (differs depending on the address type, see below)

street address or PO Box

(compulsory empty line, if applicable)

city line with postal code

country code (if applicable)

The city line and the country name are always printed in upper case for foreign addresses (only for the complete address, not for short forms).

The name block generally consists of the following:

"Normal" addresses (address type SPACE and address type 1):

NAME1

NAME2

NAME3

NAME4

Personal addresses (address type 2):

Title of person and name of person

Business address with department and contact person (address type 3):

NAME1

NAME2

NAME3

NAME4

department

title of person and name of person

In addresses entered using Business Address Services (central address management) (see Release notes Central Address Management for Release 4.0 and Central Address Management for Release 4.5 ), the street address can comprise several lines (see Print street address), otherwise street and house number are maintained in the Street field.

Some countries do not have a compulsory empty line (see notes below). The city and district are printed in the city line, connected by a hyphen (exceptions: 004 USA, 006 Great Britain/Ireland, 013 Japan, 015 Germany, 017 South Korea, 019 Denmark), provided that the total length does not exceed 35 characters. If a different city is specified for the PO Box (PFORT), this is used in the PO Box address.

In all formats which use a country code (currently 001 European standard format 002 Italy, 011 Switzerland and 014 Austria ), the license plate code for that country is used. If this is not maintained, the country key in table T005 is used.

If the "Print country name in foreign addresses" flag is set for the sender country in table 005, the country code is not used; the country name is printed in the last line of the address.

Formats 004 (USA), 005 (Canada) and 008 (Singapore) contain a line ('F') for the function of the contact person in the company (if address type = '3'). This line comes immediately after the line 'N' (Name (and title) of the natural person).

In formats 002 (Italy), 004 (USA), 005 (Canada), 006 (Great Britain), 007 (Brazil) and Australia (009), the REGIO field (Region, State, Province, County) is formatted. For the USA, Canada, Brazil and Australia, the key from table T005S is used; for Great Britain the text name from table T005U.

In all countries for which no "Address structure key" is maintained, a standard format is used which corresponds to format "010".

Hope this may help you.

Lanka