Wednesday, 5 November 2014

Making selection screen field's value as header of the output in SAP Query

SAP Query: SAP Query is basically a tool for functional people to generate a simple report without taking help of technical person. This report looks basically like an ALV report. However we do have different options as output format like SAP list viewer, ABAP List and many more. Please note that one should not expect a more customized report through SAP Query.

   In spite of the core purpose of facilitating the functional consultant with a tool to generate a simple report of their own, SAP query comes with functionality of doing slight changes, like we do have coding option at different events of classical report, to meet some basic need.

   One such need comes to me in recent past. The title of the SAP Query (which one gives when query was created first time) comes as header of it's output. User was wanting a field in selection screen and further this field's value in the selection screen must come as the header of the output. I have created a demo SAP query to demonstrate this. Here is the process to achieve this. Kindly note that this functionality only works with the output format "ABAP List".

1. Go to SQ01. Give your query name and press change. Make the first screen of SAP Query like below screen shot. Make sure the check box "With standard title" under block Print list, must not be checked. Otherwise the header of the output will always come as your query's standard title.

2. Go to select field screen using the right navigation arrow beside execute button on tool bar.

3. At first you will not be able to see this column of short name. You have to switch it on like below and then you will be able to see this short name column in edit mode.

4. Here the fields which are checked are the ones which are going to come as selection screen field. Create a short name of the field whose value you want in the output header. Like below.

5. Go to the “Basic list” option and give “&<short name>" (which you have created in previous step) in the header field.







6. Save it. Execute the query and make sure in selection screen you select the ABAP List as the output format.




Output:

              
                                                          
                                                                                                             By: Reetika Patel


Monday, 22 September 2014

Utility for searching in a report code for a string



Requirement:  Our requirement is to find a certain string in a code in given report. As per the requirement, we are having an excel file with a list of report names, and we have to figure out if a certain string is present in those reports or not.
Steps:
  1. Convert the excel file into internal table.
  2. Search in those reports for the string. And create an internal table for the report names which have those strings.
  3. Download that final internal table into excel file in presentation server.
Description:
Use function module 'ALSM_EXCEL_TO_INTERNAL_TABLE' for uploading the excel file into internal table. 


Loop into that internal table and using the syntax READ REPORT tries to find out whether string is there or not in the report code. If string is there keep that record else delete that record from internal table.





Later on download that fiinal internal table into an excel file in presentation server using the function module 'GUI_DOWNLOAD'.
 

                                                                                                             By: Reetika Patel


Tuesday, 12 August 2014

Creation of PDF from Standard text

Requirement: User wants a certain text to be send in mail as PDF attachment.

Solution: We create a SO10 standard text for that text. Further we can have 2 approaches.

            First approach: Embed that standard text in a window of a new script. Call that script in a usual manner using OPEN_FORM, WRITE_FORM, CLOSE_FORM function module. In the calling of CLOSE_FORM we will get the OTF format of that script in suitable type of internal table. Convert that OTF format into PDF format internal table and use that as an attachment in mailing functionality.
            Second approach: Our aim is to have the final text in PDF format in suitable in internal table so that we can use in attachment in mail. This we achieved through usual script manner in the previous approach. Now we will use another way. 
 
There are 2 facts that we will use in this second approach. First is whenever we write something on screen, a spool automatically get's created for that. We can see that spool no using the system variable SY-SPONO. Another is that we have Function module to convert any ABAP spool into PDF. So we will see how that works.

First we will read that text using READ_TEXT function module and get the text content in one internal table of type TLINE. Further we will use function module GET_PRINT_PARAMETERS following a loop on internal table and in each iteration print it's TDLINE column on screen. This will create a spool whose number we can have in system variable SY-SPONO. Further export that spool no using EXPORT TO DATABASE INDX. EXPORT TO MEMORY ID won't work here because we are going to call this program in background from the next program we will create.

Create another program. Here we will be creating a job in background. In that background job we will insert a process by submitting our earlier created program and finally we will close that  background job. Further we will use function module named 'CONVERT_ABAPSPOOLJOB_2_PDF' to convert the spool number, which we will be importing(which we have exported in our earlier program) in this program, into PDF format.
Below is the code snapshot.

REPORT 1:







REPORT 2:












Test  this report by executing it and checking the newly created entry in SOST.

                                                                                                             By: Reetika Patel

Wednesday, 23 July 2014

Printing a window in SAPSCRIPT without even calling it in driver program

Friends, lately 2-3 times I came across the situations where one window of script was coming into picture in print preview and while debugging also I could see it getting triggered. Tried putting break -point for every call of WRITE_FORM in order to find out from where exactly these windows are being called but to no avail.

On my recent encounter to this strange issue, I decided to go up to the bottom of the issue. Did a close analysis of the windows which were explicitly being called in driver program and those which were not. One thing was common among the windows, which were not being called in driver program, which was that there were no element in those windows. I google for it and Yes it was right.

So conclusion is, “We don't have to use WRITE_FORM explicitly for the windows which are having no element in it. We can go without caring for the calling of such windows. SAP standard code handles it automatically”.

Here I have developed one demo script and driver program to demonstrate it.
  1. Create a new script.
  2. Create 2 windows in it named Header and Main window.


  3. In the Header window, go inside and right something without using an element.


  4. Go inside the main window and write something under an element.


  1. Save and activate it.
  2. Create a diver program for this script and do the coding like below.


  3. Save it and activate it. Run it and choose output device as LOCL. Do the print preview

    Result:


  4. We are getting the content of Header window, while we have not used the WRITE_FORM for it.


                                                                                                                 By: Reetika Patel

Friday, 18 July 2014

Using checkbox in ALV Webdynpro with Messaging functionality

Requirement: Creation of ALV with Check box and messaging functionality

Prerequisite: Creation of simple Webdynpro ALV application.

Steps:

1. Create a webdynpro component.
2. In main screen in 'used component' tab create the component usage of the standard ALV component SALV_WD_TABLE.


3. Go to component controller and create the component usage here also by clicking on the button as below. It will show the component usage you have created earlier. Use this one and screen will look like the 2nd screen shot.






4. Go to context tab of component controller and create 3 nodes named Header, Item, select_option. Make their attribute as mentioned below.







As you can see in right hand side panel, there is the context of component SALV_WD_TABLE. If you check in that component, the context shown here in right hand side, are actually the interface nodes of SALV_WD_TABLE. This way interface node come to the custom component where they are used.

5. Create a structure named ZHEADER1 in SE11 like below. And create a table type Z_HEADER
where line type is ZHEADER1.


These structure and table type we are going to sue further in our coding.

6. Create 2 attributes in attribute tab of component controller like below.





7. Create the layout of main view like below.


8. Go into the window where main view is embed. Inside main window you will get to see the view container you have created in main view's layout. Right click on it and click on 'embed view'. There select the 'Table' view of the used component. The window tab will kook like this now.




9. Go to INTERFACECONTROLLER in component usage. There bind the HEADER node of component controller to  DATA node of interface controller




10. In MAIN view on display button, create an event on action named 'ONDISPLAY'. By doing this there would be one method created automatically in method tab of the view like below.



11. Our job now is to fill the internal table and then the HEADER context node in order to display it in ALV. For that, in ONACTIONDISPLAY method we will right the below code.











12. Now go to the method tab of main view. There create one event handler method named ONCLICK. In event column select ON_CELL_ACTION event of interface controller of component usage ALV_USAGE.




13. Going inside the code of ONCLICK method, you will find one parameter named R_PARAM. This parameter will have the required info to process the checked row. This parameter will have data ranging from index of checked table record, column name, column value and all.

14.  We are implementing the functionality of displaying information message on check /uncheck of
check box and displaying the information message containing the index of table row. Below code is used for that. That is very well using the R_PARAM parameter of the method.




Results:





                                                                                                             By: Reetika Patel