cancel
Showing results for 
Search instead for 
Did you mean: 

Loop in a SAPSCRIPT

Former Member
0 Kudos

Hi,

How do I write a loop inside a SAPSCRIPT?

I was trying the following but they do not work:

/: LOOP.

...

...

...

/: ENDLOOP.

/: DO.

...

...

...

/: ENDDO.

Please help.

Accepted Solutions (1)

Accepted Solutions (1)

sreelatha_gullapalli
Active Participant
0 Kudos

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

i would like to add a specific question here.

i have a case where in dunning, i would replace the rejected payment with the invoices related to that payment.

for each rejected payment (DD) there would be multiple invoices (2A).

my problem now is what is the best approach to retrieve the 2A documents and output it in the layout.

i am thinking of the following solutions:

A:

copy the f150 (dunning) program and modify the MHND and MHNK tables to include the 2A documents of each DD document.

(if this is not the only solution, I would prefer not to opt for this)

B:

is it possible to call a subroutine from sapscript and in that subroutine, i will get the 2A documents, and output these in form?

(considereing that i cant perform loop in the Form)

Regards,

R

mahaboob_pathan
Contributor
0 Kudos

hi,

u can not write loop in form text elements.

u can only write if statements in text elements.

if u need to print the data u need to fetch it from the driver program only.

and mention those fields in text elements.

with in &&.like &itab-fld1&.

and pass this text element name to the function module in driver program.

Former Member
0 Kudos

Hi Joseph,

Loop endloop doesnt work in a SAPscript, instead use a subroutine inside the script and get the data from the print program( here you can use loop endloop ) for that script. If u need any further explanation please mention that.

Former Member
0 Kudos

Hi,

Thanks for the response.

But my problem is that the print program is a standard program and I cannot modify it. It does not retrieve the data that I need for the SAPSCRIPT. So I tried to do the following inside the sapscript (which does not work):

LOOP.

PERFORM F_GET_DATA IN program ZTEST

USING &V_KEY&

CHANGING &COLUMN1&

CHANGING &COLUMN2&

CHANGING &COLUMN3&

ENDPERFORM.

  • Display COLUMNS

&COLUMN1& &COLUMN2& &COLUMN3&

ENDLOOP.

Do you have suggestions on how to solve my problem? Do I need to change the standard print program?

Former Member
0 Kudos

Hi,

As Nick and Avinash have rightly said the Loop and Endloop commands doesnt work in layouts. So the only alternate solution can be to modify the driver/print program.

Passing the subroutine to an external subroutine also will not work as you need a table.

Regards,

Narendra.

Sougata
Active Contributor
0 Kudos

Hi Joseph,

You need to copy the standard print program into a Z program then make changes to it i.e. add the custom application logic as per your requirement in this Z program.

Also you would need to change the related SapScript configuration via the IMG to replace the standard program name with your new Z program name so that when the Form is generated the system goes through your Z print program and not the standard print program.

Hope this answers your question.

Cheers,

Sougata.

Former Member
0 Kudos

Hi,

The LOOP logic of a SAPscript is held in the print program, not the form. Your ABAP print program will typically extract the data, open the form, loop through the data, call elements in the main window then close the form.

There is no LOOP statement in SAPscript.

Regards,

Nick