How to identify the first item line in SO

Question: Hi expert,

I need to do an user exit in SO that when user key in the storage location at the first line item system automatically copy it to all following line.
I use read table xvbap with key posnr = '000010'. However, sometimes user may delete the line 10 so the first line may not always 10 and hard to know which line item is the first line. Any idea how to determine the first line item.

By the way, I did the program like this:
read table xvbap with key posnr = '000010'.
if sy-subrc eq space.
move xvbap-lgort to vbak-bstnk.
endif.
move vbak-bstnk to vbap-lgort.
endif.

The system works but seems not a very good way (I borrow fields PO number to store the value that didn't really overwrite user maitained PO number) . Any suggestion on do it a better way?

Thanks a lot!
Susan

Answer:
if you sort XVBAP by po number and item ascending order and then doing a read XVBAP by PO number should give you the FIRST po item.
_________________
Still learning...... Will it ever stop ?

Answer:
Hello George,

Thanks a lot for help. Sorry I am not professional ABAPer. May I know how write this to sort it with xvbap, before "read table"?

Also before sorting I need to first exclude the XVBAP-UPDKZ = 'D' (ignore the item be deleted and then take the first line sort by item no.

Thanks again.

Susan

Answer:
You could write
 SORT XVBAP BY VBELN POSNR ASCENDING.

As far as the exclusion of UPDKZ, you could write
 DELETE XVBAP WHERE UPDKZ = 'D'.
after you append the table, or better yet, exclude those entries prior to your append.

I am not by any stretch of the imagination an ABAP expert, but that's what I would do.

Answer:
thanks a lot Tseug,

I am working on xvbap, guess I can not append it to another internal table ? because at the moment order can be during creation.

Is it safe to just say DELETE XVBAP WHERE UPDKZ = 'D'.


Thanks,
Susan

Answer:
I guess I'm not totally clear on what you're doing. Pardon me if I'm not seeing the obvious but is xvbap an internal table within the ABAP, or is it a copy of VBAP itself you're storing the system data in?

Answer:
Perhaps, in the user exit, you may append the lines of the xvbap table into a temporary table. Sort then exclude the records according to your filter (UPDKZ = 'D').

Upon reading the temporary table with INDEX 1, you will be able to check the first line. If it has the storage location, store it in a variable. Then, loop at xvbap and move the storage location to the following lines, and use modify statement so as the changes would take effect on xvbap.

Answer:
Hi sappy_SAPer,

Thanks for help. I was trying to do like this:

Data: Begin of itab occurs 1.
INCLUDE STRUCTURE xvbap.
DATA: END OF itab.


SELECT * FROM xvbap
APPENDING CORRESPONDING FIELDS OF TABLE itab
where vbeln = xvbap-vbeln and posnr = xvbap-posnr.

but system say xvbap is not a table. Is there something wrong in this coding. And this user exit is usually used during order creation, order no. not yet generate. not sure if I can use vbeln (SO no.) as link.

Thanks again.

Susan

Answer:
DATA: l_lgort LIKE vbap-lgort.
CLEAR l_lgort.

SORT xvbap BY posnr.
LOOP AT xvbap WHERE updkz NE 'D'.
* This is first non-deleted line..
  l_lgort = xvbap-lgort.
  EXIT.
ENDLOOP.

IF l_lgort IS NOT INITIAL.
  LOOP AT xvbap WHERE updkz NE 'D'
                  AND lgort IS INITIAL.
    xvbap-lgort = l_lgort.
    MODIFY xvbap.
  ENDLOOP.
ENDIF.I have not checked syntax.

Answer:
Thanks very much Bipin,

I tried with the proposed codes, at first didn't work, then I did a little modification, add vbap-lgort = l_lgort:



DATA: l_lgort LIKE vbap-lgort.
CLEAR l_lgort.

SORT xvbap BY posnr.
LOOP AT xvbap WHERE updkz NE 'D'.
  l_lgort = xvbap-lgort.
  EXIT.
ENDLOOP.

IF l_lgort IS NOT INITIAL.
  LOOP AT xvbap WHERE updkz NE 'D'.
                  AND lgort IS INITIAL.
    xvbap-lgort = l_lgort.
     vbap-lgort = l_lgort.
*    xvbap-updkz = 'U'.
    MODIFY xvbap.
  ENDLOOP.
*ENDIF


Then in fron end the storage location is copied into other lines. However, system doesn't really take it into account. incompletion check still saying storage location is missing for line 20.

Any idea how to correct?

Thanks every one for kind help so far.

Susan

Answer:
Seeing your modification of changing vbap, then I guess you would have to work on the vbap internal table and not on the xvbap.

Answer:
Hi Sappy_SAPer,

can I know how I can work with vbap internal table?

like this:
Data: Begin of itab occurs 1.
INCLUDE STRUCTURE vbap.
DATA: END OF itab.

SELECT * FROM vbap
APPENDING CORRESPONDING FIELDS OF TABLE itab
....

?

Just I am not sure how to select the current processing data if not using xvbap, the vbeln is not yet created?

Answer:

DATA: l_lgort LIKE vbap-lgort.
CLEAR l_lgort.

SORT xvbap BY posnr.
LOOP AT xvbap WHERE updkz NE 'D'.
  l_lgort = xvbap-lgort.
  EXIT.
ENDLOOP.

IF l_lgort IS NOT INITIAL.
  LOOP AT xvbap WHERE updkz NE 'D'.
                  AND lgort IS INITIAL.
    xvbap-lgort = l_lgort.
     vbap-lgort = l_lgort.
*    xvbap-updkz = 'U'.
    MODIFY xvbap.
  ENDLOOP.
*ENDIF


Seeing your modification on adding "vbap-lgort = l_lgort.", it seems that there are 2 internal tables - XVBAP and VBAP, that's why you mentioned that it kinda worked.

So perhaps, you can just manipulate the VBAP internal table.


DATA: l_lgort LIKE vbap-lgort.
CLEAR l_lgort.

SORT vbap BY posnr.
LOOP AT vbap WHERE updkz NE 'D'.
  l_lgort = vbap-lgort.
  EXIT.
ENDLOOP.

IF l_lgort IS NOT INITIAL.
  LOOP AT vbap WHERE updkz NE 'D'.
                           AND lgort    IS INITIAL.
     vbap-lgort = l_lgort.
     MODIFY vbap.
  ENDLOOP.
ENDIF.
[/code][/quote]
Copyright ?2007 - 2008 www.jt77.com