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

SmartForms: How to loop inside smartforms?

Former Member
0 Likes
1,594

Hi All,

I have the following scenario below:

kindly check the screenshot of my smartForm first: http://img10.imageshack.us/img10/9456/sflayout6cells.jpg

In the screenshot, in the right side is the screenshot of my SAP output, while on the left is the smartforms.

Let's say I have ITAB.


LOOP AT itab. 
   
ENDLOOP.

In my SF, i have 6 big cells, i want to pass itab-matnr in each of the 6 cells.

Now, if the number of rows in my ITAB is 12, I should pass 12 matnr in each of the cells but it should trigger my SF to produce a 2nd page to contain next set of 6 matnr.

How can I loop the page of my SF to contain the next loop pass from my ITAB?

Thanks.

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
1,400

Hi Jaime,

By first: I can see that you are using lots, really lots of secondary windows if not over 100 per page. I don't think it is a good idea at all. You could easily substitute them with 6 secondary windows which woudl use same template inside. It is like you were builting a program and rewrite 6 times same code, although you could encapulate it in some routine and use it 6 times.

Next time please consider avoiding such strcutures and take advantage of templates/tables It is much more difficult to handle it like that.

Nevetherless, in your case you could do following: in each secodary window (dedicated for MATNR) READ your ITAB with INDEX 1 -> then show MATNR -> then DELETE ITAB INDEX 1. When you proceed to next window you do same thing, and same for the following windows too. In the 6th window, after DELETE, check if any entries are left in ITAB. If so -> then trigger PAGE BREAK. Next page will act same way (reading first entry -> printing it out -> deleting).

Other way would be creating some global counter which would hold INDEX of read ITAB line. You would increment it after each read. At the end you would check whether INDEX = number of lines in ITAB. If no -> then proceed to next page.

The ways you can handle that are couple. Please remember it is always up to you what approach you take (it also applies to SF structure), so try making your life easier not harder

Cheers

Marcin

11 REPLIES 11
Read only

MarcinPciak
Active Contributor
0 Likes
1,401

Hi Jaime,

By first: I can see that you are using lots, really lots of secondary windows if not over 100 per page. I don't think it is a good idea at all. You could easily substitute them with 6 secondary windows which woudl use same template inside. It is like you were builting a program and rewrite 6 times same code, although you could encapulate it in some routine and use it 6 times.

Next time please consider avoiding such strcutures and take advantage of templates/tables It is much more difficult to handle it like that.

Nevetherless, in your case you could do following: in each secodary window (dedicated for MATNR) READ your ITAB with INDEX 1 -> then show MATNR -> then DELETE ITAB INDEX 1. When you proceed to next window you do same thing, and same for the following windows too. In the 6th window, after DELETE, check if any entries are left in ITAB. If so -> then trigger PAGE BREAK. Next page will act same way (reading first entry -> printing it out -> deleting).

Other way would be creating some global counter which would hold INDEX of read ITAB line. You would increment it after each read. At the end you would check whether INDEX = number of lines in ITAB. If no -> then proceed to next page.

The ways you can handle that are couple. Please remember it is always up to you what approach you take (it also applies to SF structure), so try making your life easier not harder

Cheers

Marcin

Read only

0 Likes
1,400

Hi Marcin,

Thanks with the quick understanding of my scenario.

How can I then now trigger the next page in the SF and pass the index greater than 6?

Let's say my ITAB has:

MATNR

1

2

3

4

5

6

7

8

In my SG, matnr 1-6 will fill the 6 individual cells, now I need matnr 7 and 8 to fill the 2nd page of the first 2 cells.

How can I automatically trigger the next page?

Read only

0 Likes
1,400

Hi Jaime,

At the end of printing 6 labels, check the condition as suggested by Marcin. To trigger the next page, use command node( Right click-> Flow logic-> Command Line.). Fill the next page field of this node to trigger the required page.

Regards,

Swarna Munukoti.

Read only

0 Likes
1,400

Hi Jaime,

For triggering dynamic page break proceed as Swarna suggested.

As for the counter (index), simply create global data object i.e. G_COUNTER (at Global definitions node -> Global data tab ) -> then in each of 6 cells (windows) you want the MATNR be shown, right click -> Create flow logic -> Program Lines .

Pass G_COUNTER both as input and output parameter of program lines. Inside that just icrement G_COUNTER.

If you reach the second page (which I believe will have same format as 1st one) you will not have to pass anything else. G_COUNTER is visible accross entire SF, so its value be passed to next page too. So after processing first page it will have value 6 -> then on next page will be icremented to 7,8,9,10...12 and so on.

Please note, you will need to have Main window defined in first page if you want to specify it as the following page too. It is required in order to avoid endless loop. So make sure you have one on you page, even if empty.

Regards

Marcin

Read only

0 Likes
1,400

@MARCIN

u201CNext time please consider avoiding such strcutures and take advantage of templates/tables It is much more difficult to handle it like that.u201D

[Question] My first was design but I changed to manual multiple secondary window since I have to maximize my space as much as possible.

u201COther way would be creating some global counter which would hold INDEX of read ITAB line. You would increment it after each read. At the end you would check whether INDEX = number of lines in ITAB. If no -> then proceed to next page.u201D

[Question]This is easier, in my screenshot: http://img10.imageshack.us/img10/9456/sflayout6cells.jpg

Letu2019s consider the 1st red box as my 1st data cell, here, youu2019ll notice that I have a lot of secondary window, it will not just only contain MATNR but it will also other contain other data, since G_COUNTER is a Global variable, I should increment it only after the last window read right?

The way SF works on how they read window(s) is sequential right?

Since I need to trigger a command line flow logic at the last read of ITAB, when should I insert this one?

In which window?

THANKS All.

Edited by: Jaime Cabanban on Feb 18, 2010 6:28 AM

Read only

0 Likes
1,400

@SWARNA

u201CAt the end of printing 6 labels, check the condition as suggested by Marcin. To trigger the next page, use command node( Right click-> Flow logic-> Command Line.). Fill the next page field of this node to trigger the required page.u201D

Question: So I only need to insert the command line on the last window in my SF? If you noticed, I have a lot of secondary windows, but not all them will have a data.

Read only

0 Likes
1,400

This message was moderated.

Read only

Former Member
0 Likes
1,400

U want that after every six iteration the page no should be changed and the next six matnr's should print on the next page. Please correct me if I am wrong?

In that case u do these things in main window. Create a template in main window to hold six rows.

rigt clk and create loop lines .

Now put one program line there and loop the internal table upto 6 rows.

take a local variable for storing the index no.

and write a case statement there

declare six global variables of type string

pass each of the matnr's in each of these six variables according to the index nos.

after the itab has looped six times.delete itab from 1 to 6.

and increase the page no by 1 everytime at the end. In this way u need not worry how many rows ur internal table contains.It will keep printing in multiples of six.

See the sample code below

DATA LV_INDEX.

CLEAR LV_INDEX.

CLEAR:GWA_VBAP,GV_STRING,GV_STRING1,GV_STRING2,GV_STRING3.

LOOP AT GIT_VBAP INTO GWA_VBAP FROM 1 TO 4.

CASE LV_INDEX.

WHEN 0.

GV_STRING = GWA_VBAP-MATNR.

CONDENSE GV_STRING.

WHEN 1.

GV_STRING1 = GWA_VBAP-MATNR.

CONDENSE GV_STRING1.

WHEN 2.

GV_STRING2 = GWA_VBAP-MATNR.

CONDENSE GV_STRING2.

WHEN 3.

GV_STRING3 = GWA_VBAP-MATNR.

CONDENSE GV_STRING3.

ENDCASE.

ADD 1 TO LV_INDEX.

ENDLOOP.

DELETE GIT_VBAP FROM 1 TO 4.

SFSY-PAGE = SFSY-PAGE + 1.

Read only

Former Member
0 Likes
1,400

U want that after every six iteration the page no should be changed and the next six matnr's should print on the next page. Please correct me if I am wrong?

In that case u do these things in main window. Create a template in main window to hold six rows.

rigt clk and create loop lines .

Now put one program line there and loop the internal table upto 6 rows.

take a local variable for storing the index no.

and write a case statement there

declare six global variables of type string

pass each of the matnr's in each of these six variables according to the index nos.

after the itab has looped six times.delete itab from 1 to 6.

and increase the page no by 1 everytime at the end. In this way u need not worry how many rows ur internal table contains.It will keep printing in multiples of six.

See the sample code below

DATA LV_INDEX.

CLEAR LV_INDEX.

CLEAR:GWA_VBAP,GV_STRING,GV_STRING1,GV_STRING2,GV_STRING3.

LOOP AT GIT_VBAP INTO GWA_VBAP FROM 1 TO 4.

CASE LV_INDEX.

WHEN 0.

GV_STRING = GWA_VBAP-MATNR.

CONDENSE GV_STRING.

WHEN 1.

GV_STRING1 = GWA_VBAP-MATNR.

CONDENSE GV_STRING1.

WHEN 2.

GV_STRING2 = GWA_VBAP-MATNR.

CONDENSE GV_STRING2.

WHEN 3.

GV_STRING3 = GWA_VBAP-MATNR.

CONDENSE GV_STRING3.

ENDCASE.

ADD 1 TO LV_INDEX.

ENDLOOP.

DELETE GIT_VBAP FROM 1 TO 4.

SFSY-PAGE = SFSY-PAGE + 1.

Read only

0 Likes
1,400

@FARKAN

Yes, youu2019re correct, in one SF page, it can only hold 6 MATNR since there are only 6 windows allocated for it, so if the ITAB is greater than 6, the rest of the ITAB-MATNR will be passed through the next page.

In your code sample, does this mean that I have to create command lines in each of the SF window for MATNR?

Read only

0 Likes
1,400

Yes you have two create 6 command lines &STRING1&

&STRING2&

&STRING3&

&STRING4&

&STRING5&

&STRING6&

clear these variables evrytime before the loop at itab statement.

You can use only the main window and create a template in that.

Edited by: FARKAN on Feb 18, 2010 6:34 AM