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

how to usw while..endwhile as loop

Former Member
0 Likes
3,916

Hi,

My requirement is to find last no of sales order. I am taking latest no fron number range object. But suppose that order is deleted then i have to find previous no. I am using below code but it is not workng..can anyone give inputs.

DATA: V_VBELN LIKE VBAK-VBELN,

V_AUDAT LIKE VBAK-AUDAT.

DATA: IND(1) TYPE C.

V_VBELN = '1133720517'.

WHILE IND = 'X'.

SELECT SINGLE AUDAT FROM VBAK INTO V_AUDAT WHERE VBELN = V_VBELN.

IF SY-SUBRC = 0.

IND = 'X'.

ENDIF.

V_VBELN = V_VBELN - 1.

ENDWHILE.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,400

Hi,

I think till u dont get the order u want to fetch the record from vbak , so u can write the condition as

WHILE IND ne 'X'.

SELECT SINGLE AUDAT FROM VBAK INTO V_AUDAT WHERE VBELN = V_VBELN.

IF SY-SUBRC = 0.

IND = 'X'.

ENDIF.

V_VBELN = V_VBELN - 1.

ENDWHILE.

5 REPLIES 5
Read only

birendra_chatterjee
Active Participant
0 Likes
1,400

Hi,

Use the below code.

TYPES: BEGIN OF TY_VBELN,

VBELN TYPE VBELN_VA,

END OF TY_VBELN.

DATA: T_VBELN TYPE STANDARD TABLE OF TY_VBELN,

WA_VBELN TYPE TY_VBELN.

SELECT VBELN INTO TABLE T_VBELN FROM VBAK. "You can also add order type, Sales Area here....

SORT T_VBELN BY VBELN DESCENDING.

READ TABLE T_VBELN INTO WA_VBELN INDEX 1.

Hence You get the latest Sales Order in field WA_VBELN-VBELN...

Regards,

Birendra

Read only

0 Likes
1,400

Hi,

I can use this but in this performance issue will come. is there any other solution like conditional loop.

Read only

0 Likes
1,400

Hi,

try with

do.

write conditions...

exit.

endo.

zashok

Read only

Former Member
0 Likes
1,401

Hi,

I think till u dont get the order u want to fetch the record from vbak , so u can write the condition as

WHILE IND ne 'X'.

SELECT SINGLE AUDAT FROM VBAK INTO V_AUDAT WHERE VBELN = V_VBELN.

IF SY-SUBRC = 0.

IND = 'X'.

ENDIF.

V_VBELN = V_VBELN - 1.

ENDWHILE.

Read only

0 Likes
1,400

Hi,

Madhukar,

This resolve my problem..