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

Scripts

Former Member
0 Likes
1,173

Hello Friends,

I have a script for invoice and in the main window i have to print the line item details of a invoice, Material no, material description, quantity and the price.

In the same window after the dtails i want to sum the price and display the price as

Total -- and then the total price.

My problem is my invoce has 3 materials. so what is happening now is after every material its printing the total and the price. after the second line its printing the sum of first 2 items and after the third line its printing the sum of all the 3 lines.

How can i solve this problem.

I am using a main window to do all this.

Madhu.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,151

Hi,

Ok...Let's the sample code that I had given earlier..

Bascially you will be using two different elements ..One for printing the line items and one for printing the total...

In the below example..I am using LINE_ITEM element to print the line item details..And using the element TOTAL to print the total..

Also it depends on the sequence of when you are calling the element..If you call the element TOTAL..Which means WRITE_FORM FM is called with the element TOTAL first..Then the WRITE_FORM FM is called with the element LINE_ITEM ...In the output you will see the totals first and then the line items..

LOOP AT ITAB.

***Print the line items..

CALL FUNCTION 'WRITE_FORM'

WINDOW = 'MAIN'

ELEMENT = <b>'LINE_ITEM'</b>

    • calculate the total..

ENDLOOP.

**Print the total.

CALL FUNCTION 'WRITE_FORM'

WINDOW = 'MAIN'

ELEMENT = <b>'TOTAL'</b>.

Hope this is what you want??

Thanks,

Naren

12 REPLIES 12
Read only

Former Member
0 Likes
1,151

seems you gotta code a group-change in your print program.

Read only

0 Likes
1,151

Thanks Florian,

Could you please elaborate on what u mean.

Madhu.

Read only

Former Member
0 Likes
1,151

Hi,

The Mian window will be Printed in between the LOOP and ENDLOOP. so there in the Driver program declare a filed in the top. and in side the loop add that filed to this newly created the field.

LOOP at <table>

NewField = Price + NewField.

ENDLOOP.

And print this fled in the Script at the place of Total

Regards

Sudhee

Read only

0 Likes
1,151

Thanks Sudheer,

I am doing the same thing as what you specified.

But since it is between the loop...endloop..it printing many times in the script layout.

eg....if i have 3 line items for a invoice,

so after everyline item it prints thr total.

Hope i am clear,

Madhu.

Read only

Former Member
0 Likes
1,151

Hi,

Print the sum after the ENDLOOP..

LOOP AT ITAB.

***Print the line items..

    • calculate the total..

ENDLOOP.

**Print the total.

CALL FUNCTION 'WRITE_FORM'

WINDOW = 'MAIN'

ELEMENT = 'TOTAL'.

Thanks,

Naren

Read only

0 Likes
1,151

Thanks Naren.

This problem is solved.

I have one more question..

Since i am using the same Main Window for printing the line items as well as the total, so I am using multiple elements.

How would the program know the lines associated to a particular element.

I hope i am clear with my question.

Madhu.

Read only

0 Likes
1,151

Hi,

Regardless of how many elements you use in the MAIN window and the order of those element declarations, Elements will be executed in the same order how you call them in the driver program.

The sequence of elements play an important role, if you are not calling any element while calling the MAIN/any window. For Eg:

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'MAIN'.

The elements will be executed in the same order how they appear in the MAIN/any window

Hope this answers your question.

Rajasekhar

Read only

Former Member
0 Likes
1,151

HI,

I believe u need to validate to print the total only after the 3rd material.

just for ex:

/: If &itab-sy_tabix& = '3'.

PR &total&

/: endif.

u can write a subroutine to count the number of materials present in ITAB. If it is a Zprogram then use DESCRIBE to know the number of materials.

and provide the condition as shown in example.. to display total.

If u can paste a code then we might help in detail..

Regards

SAB

Read only

Former Member
0 Likes
1,151

Hi Madhu,

Use BOTTOM..ENDBOTTOM control command in the main window and display your TOTAL field variable here.

This may solve your problem.

<b>/: BOTTOM</b>

/: &V_TOTAL&

<b>/: ENDBOTTOM</b>

Thanks,

Vinay

Read only

Former Member
0 Likes
1,152

Hi,

Ok...Let's the sample code that I had given earlier..

Bascially you will be using two different elements ..One for printing the line items and one for printing the total...

In the below example..I am using LINE_ITEM element to print the line item details..And using the element TOTAL to print the total..

Also it depends on the sequence of when you are calling the element..If you call the element TOTAL..Which means WRITE_FORM FM is called with the element TOTAL first..Then the WRITE_FORM FM is called with the element LINE_ITEM ...In the output you will see the totals first and then the line items..

LOOP AT ITAB.

***Print the line items..

CALL FUNCTION 'WRITE_FORM'

WINDOW = 'MAIN'

ELEMENT = <b>'LINE_ITEM'</b>

    • calculate the total..

ENDLOOP.

**Print the total.

CALL FUNCTION 'WRITE_FORM'

WINDOW = 'MAIN'

ELEMENT = <b>'TOTAL'</b>.

Hope this is what you want??

Thanks,

Naren

Read only

0 Likes
1,151

Thanks All.

Madhu.

Read only

Former Member
0 Likes
1,151

Hi Madhu...

Do this way ..

Count the total with in the tool. in the script after the element which is printint the main winodw elements create a New element add write the new field there like &Total&.

After the LOOP and ENDLOOP call the function module WRITE_FORM .

***Print the line items..

CALL FUNCTION 'WRITE_FORM'

WINDOW = 'MAIN'

ELEMENT = 'NEW ELEMNT'

I hope you you will solve your Problem

Regards

Sudheer