cancel
Showing results for 
Search instead for 
Did you mean: 

how to use the FOR/NEXT loop and its parameters

Former Member
0 Kudos

hi all,

Can anyone tell me how to use the for loop condition in cbta and how to give the parameters values to repeat the steps for 'n' number of times usng the loop.

Regards,

Eswari

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

hi Venkata,

thanks for the reply. Now I tried with the FOR LOOP and it looks like we are able to do the for loop and the looping is working in the same row, but we want that loop to work for the next n number of lines also.

For eg: In the above screenshot, we are have used the for loop to iterate for 2 times but its iterating at the same row as shown below (this is the VA01 tcodes) and we want to repeat the materiel  for the 2 I

times or say as create 3 materials on the whole in the single Sales order . Please let me know to make it create the material for 3 times in 1 ssales order.

Reagrds,

Eswari

Former Member
0 Kudos

hi Eswari,

   sorry for the delay. You can try the syntax as below

  use syntax:

    FOR

    EXIT_FOR

    NEXT

  

thanks and regards,

venkat

Former Member
0 Kudos

hi Venkat,

Thanks for your  reply.

I want to iterate for n number of times. Can you please let me know the parameter values to be used for the above example.

Regards,

Eswari
.

Former Member
0 Kudos

Hi Eswari,

Following is the example for parameter setting:

Keyword: LOOP

It defines the end of the loop and must be used together with the DO keyword which defines where the loop starts.

EXAMPLE – PROCESS LINE ITEMS IN SALES ORDER

The following scripts was created for transaction VA02 (Change Sales Order) to add shipping information for each line item of an existing sales order.

With DO Keyword the loop starts and the counter is set to ‘1’.

To be able address the row number starting at ‘0’ we take the counter number minus ‘1’ using the CBTA_A_SETINEXECUTIONCTXT component.

Then the scripts reads the value of the first row in the first column to check if an entry exists.

If the value is empty we exit the loop with the EXIT_DO keyword.

Otherwise the scripts performs the required actions for the current row

  • Select row

  • Menu Goto --> Item --> Shipping
  • Enter the required shipping information using the related screen component
  • Go back to main screen

With the LOOP keyword the script goes back to the DO keyword while increasing the counter and processing further line items of that sales order.

Former Member
0 Kudos

hi,

But the given example is for the do while loop r8?I need to kno the parameter setting for the FOR LOOP condition.

Regards,
Eswari

Former Member
0 Kudos

Hi Eswari,

I hope you are able to use for loop but now the issue is that it is iterating for the same row.

So there will be a default component which is specifying values in row.In URI of that component (CBTA_GUI_SETTEXT) you will see row number related field, you need to specify the variable of current row instead of that fixed row number.

So every time row number will be different based on your current row.

If "CBTA_GUI_SETTEXT" does not have row number in URI, you need you different default components like "SetCellData" which has row number as input inside FOR loop.

Hope this works for you!

Former Member
0 Kudos

Hi Eswari,

the following keywords are the ones used to define loops and iterations.

  • DO 
  • LOOP 
  • EXIT_DO

If you want to have {n}-times execution, please use :

"DO"

...

"EXITDO"

...

"LOOP" in your CBTA script.

DO defines a counterparameter : "MYCOUNTER" and starts the structure.

EXITDO has a 3 parameters for defining a condition:

<LEFTVALUE> <OPERAND> <RIGHTVALUE>:

e.g.:

%MYCOUNTER% > 5 (n - times)


LOOP is the ending command for the structure.


Kind regards,

Christoph


Former Member
0 Kudos

hi Christoph,

Thanks for the reply. The above said is for the DO WHILE loop. Can we use this for the FOR LOOP also or give us some steps like above to use the for loop.Let me kown if any document is available.

Regards,

Eswari

Former Member
0 Kudos

Hi Eswari,

The following keywords are the ones used to iterate when the number of iterations is known in advance.

  • FOR
  • NEXT 
  • EXIT_FOR

you can access the documentation in SAP-SCN:

https://support.sap.com/content/dam/library/SAP%20Support%20Portal/support-programs-services/solutio...

Kind regards,

Christoph

Former Member
0 Kudos

hi,

  use syntax:

    FOR

    NEXT

    EXIT_FOR

thanks and regards,

venkat

Former Member
0 Kudos

check this url: