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

Assignment Number

Former Member
0 Likes
1,621

I have a table ztable with one field numm that I need to use as an assignment number. In my custom report I need to pick up with value ztable-numm and add one to it and use this value in my report. Then I need to update ztable-numm with the new value

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,580

Hi,

How many records do you need to update with incremental?

One record or all record? If one record, is it the last one?

If you want to modify all records, please try this.


DATA: it_zasscit TYPE STANDARD TABLE OF zasscit.
DATA: wa_zasscit LIKE LINE OF it_zasscit.
DATA: v_numm LIKE zasscit-numm.
 
 
SELECT * FROM zasscit INTO TABLE it_zasscit.
 
SORT it_zasscit BY numm DESCENDING.
 
READ TABLE it_zasscit into wa_zasscit index 1.
 
v_numm =  wa_zasscit-numm.
 
LOOP AT it_zasscit INTO wa_zasscit.
  v_numm = v_numm + 1.
  wa_zasscit-numm = v_numm.
  MODIFY it_zasscit FROM  wa_zasscit-numm.
ENDLOOP.
 
MODIFY zasscit from table it_zasscit.

Regards,

Ferry Lianto

18 REPLIES 18
Read only

Former Member
0 Likes
1,580

select max( * ) from ztable where <condtion>.

v_numm = ztable-numm + 1.

Regards,

Ravi

Read only

Former Member
0 Likes
1,580

Hi,

Try this..

TABLES ZTABLE.

SELECT SINGLE * FROM ZTABLE.

YVTOL_TEST-NUMM = ZTABLE-NUMM + 1.

MODIFY ZTABLE.

Thanks,

Naren

Read only

Former Member
0 Likes
1,580

SELECT MAX(numm) FROM ztable INTO v_numm WHERE <condition> ORDER BY numm.

v_numm = v_numm + 1.

ztable-numm = v_numm.

ztable-field1 = somevalue.

....rest of the fields

MODIFY ztable FROM work_area_for_ztable.

Read only

Former Member
0 Likes
1,580

Hi,

Please try this.


data: wa_ztable like ztable,
      wa_numm like ztable-numm.

select single * into wa_ztable 
from ztable 
where <condition>.

wa_numm = wa_ztable-numm + 1.


...


wa_ztable-numm = wa_numm.

modify ztable from wa_ztable transporting wa_ztable-numm.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
1,580

I need to append the new value for numm to the ztable

and also i need to select the last row in ztable as the value of numm

Read only

0 Likes
1,580

hi megan,

u can also use this stmt.

Add 1 to numm.

Regards...

Arun.

Reward points if useful.

Read only

Former Member
0 Likes
1,580

Hi,

Try this..

TABLES: ZTABLE.

SELECT MAX( NUMM ) FROM ZTABLE

INTO ZTABLE.

ZTABLE-NUMM = ZTABLE-NUMM + 1.

INSERT ZTABLE.

Thanks,

Naren

Read only

0 Likes
1,580

Narendra

Unknown column name "MAX(NUMM)". not determined until runtime,

Read only

Former Member
0 Likes
1,580
select * from ztable into wa1.
v_numm = wa1-numm.
endselect.

add 1 to v_numm.

Now I just need to append v_numm to ztable

Read only

0 Likes
1,580

Hi,

loop at ztable into wa1.

wa1-numm = wa1-numm + 1.

append wa1 to ztable.

endloop.

Paisante

Read only

Former Member
0 Likes
1,580
SELECT * FROM zasscit INTO wa1.
  v_numm = wa1-numm.
  ADD 1 TO wa1-numm.
ENDSELECT.

ADD 1 TO v_numm.
WRITE:/ v_numm.

INSERT INTO zasscit VALUES wa1.

Guys the wierdest thing is happening

It inserts until numm goes to 0004, after that it stops inserting. Is there something wrong with my code ?

Read only

0 Likes
1,580

Ok, I'm going to try to steer you in the RIGHT direction. What you are doing is trying to simulate an internally assigned number. You should be using a number range to do this instead of trying to find the last number used. You create the number range using the transaction SNRO. Give it a name and allow for buffering or not. Then give the number range, this is client specific, so when you move your changes to production, you will need to visit SNRO in production and create the number range interval(just the interval). In your program, you simply use a function module to get the next available number. Here is an example, which I just did for my project just a couple minutes ago..

So here ZCTPL_NUM is the name of the number range i created in SNRO. 01 is the name of the interval which I defined. XCTPLN is the variable whic recieves the new number.



data: xctpln type zcmptrk-ctpln.

  call function 'NUMBER_GET_NEXT'
       exporting
            nr_range_nr             = '01'
            object                  = 'ZCTPL_NUM'
       importing
            number                  = xctpln
       exceptions
            interval_not_found      = 1
            number_range_not_intern = 2
            object_not_found        = 3
            quantity_is_0           = 4
            quantity_is_not_1       = 5
            interval_overflow       = 6
            buffer_overflow         = 7
            others                  = 8.

Please keep in mind that this is how most(if not all) numbering is done within SAP, For example, internal assign material numbers.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,580

Hi,

Please try this.


DATA: it_zasscit  TYPE STANDARD TABLE OF zasscit .
DATA: wa_zasscit LIKE LINE of zasscit.


SELECT * FROM zasscit INTO TABLE it_zasscit  
ENDSELECT.

SORT it_zasscit BY numm descending.

READ TABLE it_zasscit  INDEX 1.

v_numm =  it_zasscit-numm. 

LOOP AT it_zasscit INTO wa_zasscit. 
  v_numm = v_numm + 1. 
  wa_zasscit-numm = v_numm.
 modify it_zasscit from  wa_zasscit-numm.
ENDLOOP. 

INSERT zasscit FROM TABLE it_zasscit.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
1,580

Hi Ferry Lianto

Should it not be

wa_zasscit LIKE LINE of it_zasscit.

Changing that gives me many more errors though

Read only

Former Member
0 Likes
1,580

Still struggling with this one. All I need to do is read zasscit-numm, add 1 to it and update the new value back to the table

I have been working on 2 solutions now and neither seem to work

TABLES: zasscit.
DATA:   wa TYPE STANDARD TABLE OF zasscit,
        wa1 LIKE LINE OF wa,
        v_numm LIKE zasscit-numm.

SELECT * FROM zasscit INTO wa1.
  v_numm = wa1-numm.
  ADD 1 TO wa1-numm.
*  modify wa from wa1-numm.
ENDSELECT.

ADD 1 TO v_numm.
WRITE:/ v_numm.

INSERT zasscit from table wa.


DATA: it_zasscit TYPE STANDARD TABLE OF zasscit.
DATA: wa_zasscit LIKE LINE OF it_zasscit.
DATA: v_numm LIKE zasscit-numm.


SELECT * FROM zasscit INTO TABLE it_zasscit.

SORT it_zasscit BY numm DESCENDING.

READ TABLE it_zasscit into wa_zasscit index 1.

v_numm =  wa_zasscit-numm.

LOOP AT it_zasscit INTO wa_zasscit.
  v_numm = v_numm + 1.
  wa_zasscit-numm = v_numm.
  MODIFY it_zasscit FROM  wa_zasscit-numm.
ENDLOOP.

INSERT into zasscit values wa_zasscit-numm.

Read only

0 Likes
1,580

What are the other fields of the table?

Is this a key field and if yes is this the only key field?

As I explained before, you will have to first get the latest NUMM value using MAX (ORDER BY numm DESCENDING is important). You then increment it, and fill the rest of the fields of the work area (like Z table). Then use either INSERT FROM wa or MODIFY FROM wa options depending on whether NUMM is part of the key. Look at the help of INSERT and MODIFY and you will understand how to do it from work area.

Read only

Former Member
0 Likes
1,581

Hi,

How many records do you need to update with incremental?

One record or all record? If one record, is it the last one?

If you want to modify all records, please try this.


DATA: it_zasscit TYPE STANDARD TABLE OF zasscit.
DATA: wa_zasscit LIKE LINE OF it_zasscit.
DATA: v_numm LIKE zasscit-numm.
 
 
SELECT * FROM zasscit INTO TABLE it_zasscit.
 
SORT it_zasscit BY numm DESCENDING.
 
READ TABLE it_zasscit into wa_zasscit index 1.
 
v_numm =  wa_zasscit-numm.
 
LOOP AT it_zasscit INTO wa_zasscit.
  v_numm = v_numm + 1.
  wa_zasscit-numm = v_numm.
  MODIFY it_zasscit FROM  wa_zasscit-numm.
ENDLOOP.
 
MODIFY zasscit from table it_zasscit.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
1,580

Thanks Ferry !!!