Let’s Web Dynpro. Part ZZ

Share on Facebook7Share on LinkedIn5Tweet about this on TwitterShare on Google+2
Please Share!!

The topic we would like to discuss today is definitely not Part III. Therefore we have named it ZZ. We would have taken this later in our Web Dynpro series, but on one day, two of our friends needed the same requirement. And, we did not find much documentation in this internet world. Therefore we decided to post this page before its due date.. 🙂

Requirement: Export an EXCEL file with data in cell formatted excel sheet with colors, borders, filters in Web Dynpro.

[adToAppearHere]

This is a very common requirement in Web Dynpro Reports. But, strangely, not much is there in any forum.

There might be number of ways to achieve it, but the easiest way we figured out is elaborated in this post.

Step 1. Create your Web Dynpro component and application, extract all your data and prepare a final table(s) which you want to download in excel.

Step 2. For the ease of demonstration, we have created a simple WD application with just one button (LinkToAction) UI element in main view. In the action ‘DOWNLOAD’ we have added a small logic to fetch few columns from MARA. Final table (i_mara) to be displayed in excel is ready.

1517

Step 3. Create one Transformation program in SE80 or t-code XSLT_TOOL. Simple Transformation is needed. When you save the Transformation program, xml code would be generated.01

Step 4. Replace the generated xml code with the code in the template xml attached below. We have created this template for the ease of we developers. Places are highlighted in the template where you need to add/change your formats.

2

Link for xml template: Please look for SAPYard Tip in the template to find the hints.

Word Doc:  SAPYard Transformation Program Template

Text File:   SAPYard Transformation Template

PS: This template can be used for any excel download/formatting. It should be changed / enhanced for extra features. But this template can be used as starting point.

Step 5. Prepare a sample excel page you want as output from Web Dynpro, with all formatting, coloring, borders etc. Make sure you have all the formatting done.

34

Step 6. Save that excel as .XML. Open that saved XML in notepad/wordpad. You will see XML codes. Scan through the code to get the STYLES. Different Styles will have different format for different rows, cells or columns.

56

Step 7. Go back to Transformation program XML which is the copy of the XML template attached. Now copy all your STYLES from excel XML to program XML.

11

Step 8. At the top of Transformation program, define the tables and variables / workareas which would be imported. TABLE is your internal table which would be sent from Web Dynpro. Make sure to add your TABLE and variables. And remove unwanted.

10

Step 9. Now, we need to differentiate between hard coding and dynamic value.
For example: ‘Reported By’ is hard coding. This would be same every time excel is downloaded. But the value of Reported By would be different depending on who executed it. In this case Reported by value is in V_NAME variable.

712

So, make a note of hard coding and values and replace the values with your variable name.

Step 10. Similarly check the Header line of the table ( hard coding). For example Material#, Created By, Material Type, Material Group. This would be hard coded. The styles for this may or may not be same to that of the body of table. We need to check the excel XML to figure out the style and copy the same style to our Transformation Program.

813

Step 11. The TABLE body is to be populated in LOOP. The values would be assigned from the field name (always UPPER CASE). The sequence in which you call the fields, the structure of the Table is created in that way. See the figure for the fields called and the structure created.

14 9

Make sure, your TABLE in transformation program and your Web Dynpro internal table are same.

PS: LOOP has to be closed with </tt:loop>

Please check the link below for excel XML code and the final Transformation program code after making change to the Template. Scan through it to see how we enhanced the template.

Raw Excel XML code                  Final Transformation XML code

Step 12. Call the Transformation program in your WD method. It would import the xml in STRING variable. Convert it to XSTRING. Call WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE as shown in figure (code in link below).

16

Link for the code snippets related to Transformation call:    Sample code in Method

Step 13. Lets test our development. Check, the color, border, text format bold etc are there.

18

Hope we were able to guide you through. If you still have any queries / suggestions / doubts, please leave your comment or contact us, we would be happy to respond.

If you want to get such practical issues and resolutions straight to your inbox, please SUBSCRIBE. We respect your privacy and take protecting it seriously.

If you liked this post, please hit the share button at the left side of your screen.

Thank you very much for your time!!

Our series on Web Dynpro ABAP

1. Let’s Web Dynpro. Part I : Overview of Web Dynrpo
2. Let’s Web Dynpro. Part II : Create your first Web Dynpro Application
3. Let’s Web Dynpro. Part II : Display a simple tabular output in Web Dynpro
4. Let’s Web Dynpro. Part IV : Show and hide UI elements dynamically in Web Dynpro
5. Let’s Web Dynpro. Part V : ALV display explaining Component Usage in Web Dynpro
6. Let’s Web Dynpro. Part VI : Add custom buttons programmatically to the ALV output tool bar/header
7. Let’s Web Dynpro. Part VII : Personalization and Customization in Web Dynpro
8. Let’s Web Dynpro. Part ZZ : Export an EXCEL file with data in cell formatted excel sheet with colors, borders, filters in Web Dynpro
9. Is data element WDY_BOOLEAN and Flag (Char1) same for Web Dynpro ALV? : Trick to create checkbox in ALV
10. Taking one step back after EhP7.4, does it make sense for Web Dynpro UI? : Getting back the old look and feel after EhP740 upgrade
11. Can we avoid Table Type declaration for Attributes section in Web Dynpro?

Share on Facebook7Share on LinkedIn5Tweet about this on TwitterShare on Google+2
Please Share!!

11 Comments on "Let’s Web Dynpro. Part ZZ"

  1. Warren Bjorkman | September 26, 2016 at 1:06 pm |

    Hi, hope you can help me as I cannot get this to work. 🙁
    I am getting ST22 dump message “Error when accessing variables during execution of ST program.”
    I haven’t declared any variables as I do not need these. My transformation looks like this:

    *… no variables are declared
    * then lower down i have:

    * etc…
    In the webdynpro i have:
    data: lt_loc_cmpy type table of zloc_cmpy.
    data: lv_xtext type xstring,
    lv_report type string,
    lv_rep_ty type string,
    lv_xmlstr type string.

    select * from zloc_cmpy
    into table lt_loc_cmpy.

    if lt_loc_cmpy[] is not initial.
    * Call Transformation Program
    call transformation zz_format_excel
    source table = lt_loc_cmpy
    * v_name = v_user_name
    * v_date = v_run_date
    result xml lv_xmlstr.

    This call is however returning the dump message.

    Any help greatly appreciated.

    One last qeustion, in your blog you have a screenshot which appears just above the comment “Make sure, your TABLE in transformation program and your Web Dynpro internal table are same”. Please can you tell me how you get to this screenshot as I cannot see anyway from the STRANS transaction to get to this type of screen?

    Thank you

    • Dear Warren,

      Thank you very much for stopping by and leaving your question.

      There might be some type mismatch in the transformation call. I will try to simulate your code and get back.

      Regarding the last question to check the fields of tables in the transformation, in the T-Code STRANS, check on the top right there is a wizard icon (Edit Simple Transformation Graphically). It is on the left of Tag Library and right of [i] Online Manual icon.

      Please let us know if you are still not able to find that icon.

      Regards,
      Team SAPYard.

    • Dear Warren – Can you please download your transformation xml to text file and mail the file to mailsapyard@gmail.com.

      We will check the xml and let you know the tentative issue.

      Regards,
      Team SAPYard.

  2. Nice tutorial. There’s also a framework that allows easier excel download available in below link.
    https://wiki.scn.sap.com/wiki/display/ABAP/abap2xlsx

  3. Hello,

    Very nice post.. But I have an issue. I am doing same steps. But when I download the excel, the file is showing a warning message saying,” The file you are trying to open is in a different format than specified by the extension. Verify that file is not corrupted and is from a trusted source before opening the file.”

    why is this warning coming? Nobody is explaining about this warning message… 🙁

  4. Steve Oldner | November 5, 2014 at 6:09 pm |

    Great! After our upgrade, I will do one.
    Good site, by the way…

Comments are closed.