Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Nagaraj
Explorer

Introduction:


Hello All, In these blog I am going to explain and discuss how to get the subtotals on adobe form based on some classification of data ( Example: Currency Wise )

Disclaimer: All the things showing on screenshots contains only dummy data.

Requirement:


I got the requirement of  adding subtotals on adobe forms based on the currency like below


It can be easily achieved . We can calculate subtotals currency wise on ABAP and will pass that data to adobe forms.

But Things got little changed for me. Instead of appending all subtotals at end, the requirement was like,at end of every currency subtotals has to be shown like this.


 

Steps to Achieve that:


1.Include one extra field in your item structure named subtotal_flag ( naming is your choice ) with character of length 1.


 

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



Note: I am HardCoding text "Total" in Invoice Number. Make sure you have to make your data element adaptable to this.

3. Once After this our form will look like this


4. Now we will change the appearance for subtotal row by using JavaScript.

  •        Make Full row Bold.

  •        Change The Background Color.

  •        Merge the Cell Invoice Row & Invoice Date and center the text there.


Our Pseudo Code is Simple.

         


 5. Before going to JavaScript include one more field on your adobe form TOTAL_RECORDS which will denote the Total No of items in line item table including subtotal row ( In Above Case it is 9 ).  It is used for looping on JavaScript. ( You can calculate the length on JavaScript if you want )



6. Enter the below script on the on initialize event on 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 will change according to your layout design . So modify it accordingly



 

7. Once after setting all things, the form  will look like this.


 

8. Now the subtotal_flag is actually not required on form. It is used for calculation only. If we remove that from final layout the script will not work. To tackle the thing remove the header description subtotal_flag( keep as empty ) and make the width as so small ( 0.0001 in ) like below.



 

9. Now the final output of form



Summary


In this blog, I have explained how to add subtotal based on currency wise. By using this methodology we can use it for showing subtotals based on some classification. ( Show totals according to materials, or date etc.. )

If line items contains 10K records, on adobe form the loop has to be run for 10K times which will cause bad performance. We can improve it by storing the index of subtotals row on ABAP and pass it to adobe forms. By using that index we can straightly change the subtotals row properties. So the loop will run exactly for how many subtotals rows are there. I will share that on next blog.

Sincerely appreciate any feedback/comments/questions.

 

Edited on 03/11/2023

Part 2 got published. Please have a look

https://blogs.sap.com/2023/11/02/subtotals-on-adobe-forms-part-2/

 

Regards

Nagaraj R
2 Comments
Labels in this area