Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Nagaraj
Participant
9,772

Introduction:

Hello All, in this blog I am going to explain and discuss how to get the subtotals on an Adobe form based on some classification of data (example: currency-wise).

Disclaimer: All the things shown in the screenshots contain only dummy data.

Requirement:

I received the requirement to add subtotals on Adobe forms based on the currency, as shown below.

It can be easily achieved. We can calculate subtotals currency-wise in ABAP and pass that data to Adobe forms. But things changed a little for me. Instead of appending all subtotals at the end, the requirement was to show subtotals at the end of each currency, like this.

Steps to Achieve that:

1) Include an extra field in your item structure named subtotal_flag(you can choose the naming), with a character length of 1.

2)  While appending item data in ABAP, insert one extra row for each currency subtotal with the flag enabled, like this.

Note: I am hardcoding the text "Total" in the Invoice Number. Make sure your data element is adaptable to this

3)  Once this is done, our form will look like this.

4) Now we will change the appearance of the subtotal row using JavaScript.

    •        Make Full row Bold.
    •        Change The Background Color.
    •        Merge the Invoice Number and Invoice Date cells, and center the text within the merged cell.

Our pseudocode is simple.

 5)  Before moving on to JavaScript, include one more field in your Adobe form named TOTAL_RECORDS, which will denote the total number of items in the line item table, including the subtotal rows (in the above case, it is 9). It is used for looping in JavaScript. (You can also calculate the length in JavaScript if you prefer.)

6) Enter the script below in the On Initialize event of the item table.

    var length = xfa.resolveNode("$record.TOTAL_RECORDS").value;

    for( var i =0 ; i<length; i++)

    {

            if( ( xfa.resolveNode("data.MainSubform.ItemDetails.Item.FORM_DATA.DATA[" + i + "].SUBTOTAL_FLAG").rawValue == 'X' ) )

            {

                    // Merging Cells

                    xfa.resolveNode("data.MainSubform.ItemDetails.Item.FORM_DATA.DATA[" + i + "].INVOICE_NO").colSpan = "2";  

                    // Hiding the Column

                    xfa.resolveNode("data.MainSubform.ItemDetails.Item.FORM_DATA.DATA[" + i + "].INVOICE_DATE").presence = "hidden";

                     // Centering Content on Merged Cells

                     xfa.resolveNode("data.MainSubform.ItemDetails.Item.FORM_DATA.DATA[" + i + "].INVOICE_NO").para.hAlign = "center";

                    // Changing Background Color

                    xfa.resolveNode("data.MainSubform.ItemDetails.Item.FORM_DATA.DATA[" + i + "]").fillColor = "192,192,192"; 

                    // Changing weight to Bold

                    xfa.resolveNode("data.MainSubform.ItemDetails.Item.FORM_DATA.DATA[" + i + "].INVOICE_NO").font.weight = "bold";

                    xfa.resolveNode("data.MainSubform.ItemDetails.Item.FORM_DATA.DATA[" + i + "].INVOICE_CURRENCY").font.weight = "bold";

                    xfa.resolveNode("data.MainSubform.ItemDetails.Item.FORM_DATA.DATA[" + i + "].INVOICE_AMOUNT").font.weight = "bold";

            }



     }



Note: Path and variable name will change according to your form design. Change it accordingly.

Example:

data.MainSubform.ItemDetails.Item.FORM_DATA.DATA . It will change according to your layout design, so modify it accordingly.

7) Once everything is set, the form will look like this.


😎Now, the subtotal_flag is actually not required on the form; it is used for calculation only. If we remove it from the final layout, the script will not work. To handle this, remove the header description of  subtotal_flag(keep it empty) and set its width to be very small (0.0001 inches), like below.

 

9) Now, the final output of the form:

Summary

In this blog, I have explained how to add subtotals based on currency-wise classification. Using this methodology, we can also show subtotals based on other classifications (such as materials, dates, etc.).

If the line items contain 10K records, the loop on the Adobe form has to run 10K times, which can cause poor performance. We can improve this by storing the indexes of subtotal rows in ABAP and passing them to the Adobe form. Using these indexes, we can directly change the properties of the subtotal rows, so the loop will run only as many times as there are subtotal rows. I will share more on this in my next blog.

I sincerely appreciate any feedback, comments, or questions.

Edited on 03/11/2023
Part 2 has been published. Please have a look.
https://blogs.sap.com/2023/11/02/subtotals-on-adobe-forms-part-2/

Regards
Nagaraj R

3 Comments