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

GET_MAX_INDEX( )

Former Member
0 Likes
439

Hi Experts,

Now Im studying ABAP Objects.

I want to know that the use of command , <b>GET_MAX_INDEX( )</b>

and I want to what are the commands are there like this GET_MAX_INDEX( ).

Thanks,

Points assured.

Hi Experts,

Now Im studying ABAP Objects.

I want to know that the use of command , <b>GET_MAX_INDEX( )</b>

and I want to what are the commands are there like this GET_MAX_INDEX( ).

Thanks,

Points assured.

2 REPLIES 2
Read only

Former Member
0 Likes
409

This Method is used to get the Max. index number.

Generally we need to develop class with some tale functionalities like SAVE_NAME,WRITE_NAMES,CLEAR_TABLE,GET_MAX_INDEX etc.

In that methods we need to develop code.

In case of GET_MAX_INDEX()

METHOD get_max_index.

DATA id TYPE i.

SELECT MAX( id ) FROM mytable INTO id.

maximal = id.

ENDMETHOD.

return parameter MAXIMAL of type i.

Regards,

Ashok.N

Read only

Former Member
0 Likes
409

GET_MAX_INDEX( ) supplies you with the highest index value of the database table. This ensure that the new entry gets a unique index value.In the two next lines.

Means when you want to insert an Data entry in the Database table through SAVE...then in the Method SAVE_NAME see the GET_MAX_INDEX( ) .



METHOD save_name.
DATA struc_my_table TYPE mytable.
struc_my_table-id = get_max_index( ) + 1.
struc_my_table-firstname = p_name-firstname.
struc_my_table-secondname = p_name-secondname.
INSERT INTO mytable VALUES struc_my_table.
ENDMETHOD.

In the second line, you can see perfectly how easy it is to get a work area in an ABAP program for the work with a database table Assign to a data field the type of the database table as data type. You get a structure wit the line type of the database table.In the next line, the function GET_MAX_INDEX( ) supplies you with the highest index value of the database table. This ensure that the new entry gets a unique index value.In the two next lines, you fill in the respective components of the work area structurewith the appropriate components of the input parameter, and then you enter the line into the database table.

The method GET_MAX_INDEX with the return parameter MAXIMAL of type i:


METHOD get_max_index.
DATA id TYPE i.
SELECT MAX( id ) FROM mytable INTO id.
maximal = id.
ENDMETHOD.

Reward points if it is usefull ...

Girish