‎2014 Mar 28 6:57 AM
hi all,
I wrote below code to select the maximum value of field cust_id from table ZPND_CUST_TAB,
but its not working as i required its giving last entry of the table.
can any one tell me what should i change in below code to get maximum value from cust_id field of ZPND_CUST_TAB table.
DATA temp_cust_id TYPE ZPND_CUST_TAB-CUST_ID.
SELECT MAX( CUST_ID ) FROM ZPND_CUST_TAB
INTO temp_cust_id
WHERE CUST_ID > 0.
WRITE temp_cust_id.
‎2014 Mar 28 7:11 AM
DATA it_temp_cust_id TYPE table of ZPND_CUST_TAB-CUST_ID.
data wa_temp_cust_id TYPEZPND_CUST_TAB-CUST_ID.
SELECT MAX( CUST_ID ) FROM ZPND_CUST_TAB
INTO table it_temp_cust_id
WHERE CUST_ID > 0.
sort the internal table it_temp_cust_id in Descending order.
read table it_temp_cust_id into wa_temp_cust_id index 1.
if sy-subrc = 0.
WRITE wa_temp_cust_id-cust_id.
endif.
‎2014 Mar 28 7:29 AM
hi raji ,
this code is also not working.
DATA it_temp_cust_id TYPE table of ZPND_CUST_TAB.
data wa_temp_cust_id TYPE ZPND_CUST_TAB-CUST_ID.
SELECT MAX( CUST_ID ) FROM ZPND_CUST_TAB
INTO table it_temp_cust_id
WHERE CUST_ID > 0.
sort it_temp_cust_id Descending.
read table it_temp_cust_id into wa_temp_cust_id index 1.
if sy-subrc = 0.
WRITE wa_temp_cust_id.
endif.
‎2014 Mar 28 7:52 AM
Hi,
once try this.
sort the internal table based on cust__id.
sort it_temp_cust_id Descending by cust_id.
‎2014 Mar 28 7:11 AM
Hi,
what data type have u used for cust_id?
while creating in entries you must follow the sequence. Like crate imp id with no 1 as first then 2 and so on.
Regards -
Makarand
‎2014 Mar 28 7:34 AM
‎2014 Mar 28 7:41 AM
‎2014 Mar 28 7:41 AM
Hi santosh,
then you must create imp id in ascending order. Else it will return the last entry of the table.
You will find almost all the fields in standard table which holds the value from number range
like ebeln vbeln are of char type. But because of number range, system generates numbers in ascending order.
You can check by deleting the data of your ztable and create entries with increasing imp id number.
If the imp is sequence is not fixed.
then, use select * from table.
Get it sorted in descending order.
and read the table with index 1.
And you can get the max number.
Regards-
Makarand
‎2014 Mar 28 11:16 AM
‎2014 Mar 28 7:12 AM
What is the issue ..? What is the data in the table...? and type of the field..?
‎2014 Mar 28 7:50 AM
Hi,
in your code, please remove the WHERE clause in the SELECT statement.
Regards,
Klaus
‎2014 Mar 28 8:00 AM
Rather than saying the code is not working kindly put up your table data and output which is coming as a screen shot.
Nabehet
‎2014 Mar 28 8:03 AM
Quite. My telepathic skills dwindle towards the end of the week.
‎2014 Mar 28 11:20 AM
Here is my problem,
in image as shown ,
program-1 is giving the value of variable temp_cust_id(numc type) that is '202' but in program-2 when i assign that value to parameters variable cust_id it is not filling the cust_id parameters with 202.
if you get my problem please reply me with solution.
‎2014 Mar 28 11:28 AM
Santosh
First of all one is selection screen other is output both are different.
If you would have simply pressed F1 on default key word you would have come to know the reason. Move your code under the event LOAD-OF-PROGRAM.
SAP HELP
"When an executable program is started using SUBMIT, all the values val specified at program start using DEFAULT are passed between the events LOAD-OF-PROGRAM and INITIALIZATION to the associated parameters para. "
Nabheet
‎2014 Mar 28 11:49 AM
Totally confused.
If you are giving the cust_id in select option, they why are you coding select max ?.
that cust_id should be in where cluase of select query.