Wednesday, February 2, 2011

Printing Attachments Of Work Order Via IW32


· Business requirement is to display all the attachments related to work order and print the selected attachments via tcode IW32.

· This can be done manually from IW32, but it requires lot of efforts as each time required attachment needs to be opened and printed. So, it’s a time consuming procedure.

· So, in this tutorial we demonstrate how we can achieve this using custom functionality using Enhancement.

Manual printing of the attachments:

1. Go to IW32 and open the work order.

2. Select ‘services for object’.

3. Select attachment list, it will display the attachments for the work order.

4. In current scenario, for printing the attachments, user have to follow the above procedure, open the document and then print it. Every time, user must to open the document manually and then print it.

5. So, the procedure becomes time consuming and also involves lots of efforts.

6. In order to achieve this functionality, I have used Enhancement IW010018 to display all the attachments related to work order and we can print as all the attachments at the same time.

7. Below I have demonstrated this functionality.

Enhancement IW010018:

Function exit used for this object is ‘EXIT_SAPLCOIH_018’ and screen exit ‘SAPLXWOC’ shown below.

Data declaration for the exits:

We are using function pool ‘SAPLXWOC’ to create the custom Subscreen and to write logic for populating the table control and printing the attachments.

Include ‘ZXWOCTOP’ must be used for data declaration.

The internal tables being used in the function exit as well as in the screen exit must be declared in this include.

Include ‘ZXWOCZZZ’ must be used to write any logic in the PBO and PAI of the screen.

Coding for Function exit:

We need to start with the function exit ‘EXIT_SAPLCOIH_018’.

1. Double click on include ‘ZXWOCU15’ and create it.

2. Create a function module and call it in this include.

Ø We have CAUFVD structure available in this Function exit. Based on the work order number (CAUFVD-AUFNR), Equipment number (CAUFVD-EQUNR), functional location (CAUFVD-TPLNR), task lists (CAUFVD-PLNTY, CAUFVD-PLNNR, CAUFVD-PLNAL) we can fetch the related attachment names.

Ø For that we need to use 2 tables, ‘SRGBTBREL’ and ‘SOOD’.

Ø Table SRGBTBREL will fetch the unique identification number for each attachment (INSTID_B). Using this number, we can fetch attachment name and its details.

Ø Below is the screenshot of the data fetching from these 2 tables. Internal table I_OBJECTS, will be populated with the attachment details. We can take the desired fields from the internal table into new internal table I_WORK and pass it to screen exit.

So, I_WORK will be populated with the details of the attachments of the work order.

1. Create a screen ‘0900’ in program ‘SAPLXWOC’, which is called in the program ‘SAPLCOIH’.

Create it as a subscreen type.

2. Go to layout and create a table control, which will display the list of attachments.

Create a pushbutton to print the selected attachments. Function code for pushbutton should be ‘ENT1’. No other function code works for the pushbutton in the enhancement tab.

3. Now, go to flow logic tab and in PBO of the screen, write a logic to to fill the table cotrol. We will use the internal table (I_WORK) populated in the function exit.

Loop at the internal table I_WORK and populate the table control (ZATTACHMENT).

In tcode IW32, when we goto enhancement tab, the list of attachment present for that order will be displayed. Then, user can select the attachments to be printed and press ‘Print’ button.

So, we need to check the selected entries and print them, this logic will be written in PAI of the screen.

4. Below is the screenshot of the coding for PAI, Module STATUS_0900. It will fetch the selected attachments.

5. MODULE F_USER_COMMAND_0900_AFTER_LOOP witll check the sy-ucomm and print the attachments.

For printing the attahcments, we need to read the contents of the attachment using FM ‘SO_DOCUMENT_READ_API1' into internal table.

We need to pass the unique identification number for the attachment (I_WORK-INSTID_B) to the FM and fetch the contents of the attachment into internal table ‘I_TAB_OBJCONTX’.

6. We are using class ‘CL_GUI_FRONTEND_SERVICES’ to get the attachment path and to print them.

So , we need to call METHOD ‘CL_GUI_FRONTEND_SERVICES=>GET_SAPGUI_WORKDIR’ to fetch the path/name of the attachment.

If attachment is of URL type, then this FM will give us the full path of the attachment else if attachment is of external type, then name of the attachment will be fetched.

After that we need to download it on the local system using FM ‘GUI_DOWNLOAD’.

Then print the attachment using method ‘CL_GUI_FRONTEND_SERVICES=>EXECUTE’ with document path and ‘Print’ command.

The selected attachments will be printed.

Demo of printing attachments via IW32:

Now, let’s see how enhancement tab displays the attachment details.

1. Go to IW32. Open work order having attachments.

2. Go to enhancement tab, it will display attachment list.

3. Select the attachment and press ‘Print’ button.

4. It will display message at the bottom after download is completed.

5. Once downloading of the attachment is done, attachment is opened for printing and once printed it is closed.

6. So, the required attachments are printed.

No comments:

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)


Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

Blog Archive