Hello,
I have created one program which helps Basis team to do a mass test on printers, choosing random printers in a loop of defined count.
It prints one specific spool to any printer which is specified in the selection screen.
I believe such a program is not present in SCN and it would help new ABAPers to work on printers.
Output : Written on screen, so if program is run in background mode also, output can be captured in spool.
Code:
*&---------------------------------------------------------------------* *& Report ZBC_SPOOL_MASSREPRINT *& *&---------------------------------------------------------------------* REPORT ZBC_SPOOL_MASSREPRINT. INCLUDE ZBC_SPOOL_MASSTOP. " Decalartions *****************Declaration of Selection Screen***************************** SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. PARAMETERS : p_spool TYPE TSP01-RQIDENT OBLIGATORY, " Spool Request p_count TYPE int4 OBLIGATORY. " Number of Count SELECT-OPTIONS : s_device FOR TSP03-PADEST NO INTERVALS OBLIGATORY. " Device (Printers) SELECTION-SCREEN END OF BLOCK b1. *****************End of Declaration of Selection Screen*********************** INCLUDE ZBC_SPOOL_MASSDATAFM. " Include which has FM to print spool START-OF-SELECTION. PERFORM get_set_data. " FM to print spool on printers *&---------------------------------------------------------------------* *& Include ZBC_SPOOL_MASSTOP *&---------------------------------------------------------------------* TABLES : TSP01, TSP03. " Tables Dec. TYPES : BEGIN OF ty_output, " Type Output rqident TYPE TSP01-rqident, count TYPE int4, padest(10) TYPE c, message(20) TYPE c, END OF ty_output. DATA : it_output TYPE STANDARD TABLE OF ty_output, " Internal Table and Work Area Dec. wa_output TYPE ty_output, it_padest TYPE STANDARD TABLE OF TSP03, wa_padest TYPE TSP03, v_random TYPE int4, v_string TYPE string, v_count type int4 VALUE 0, v_spool TYPE TSP01-RQIDENT. *&---------------------------------------------------------------------* *& Include ZBC_SPOOL_MASSDATAFM *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form GET_SET_DATA *&---------------------------------------------------------------------* FORM get_set_data . IF p_count > 500 OR p_count < 1. " Loop count should be >= 1 and <= 500 MESSAGE text-003 TYPE 'I'. LEAVE LIST-PROCESSING AND RETURN TO SCREEN 0. ENDIF. SELECT * INTO TABLE it_padest " Check if printers exists FROM TSP03 WHERE padest IN s_device. IF sy-subrc <> 0. MESSAGE text-004 TYPE 'I'. LEAVE LIST-PROCESSING AND RETURN TO SCREEN 0. ENDIF. SELECT SINGLE rqident INTO v_spool " Check if spool exists FROM TSP01 WHERE RQIDENT = p_spool. IF sy-subrc <> 0. MESSAGE text-006 TYPE 'I'. LEAVE LIST-PROCESSING AND RETURN TO SCREEN 0. ENDIF. v_count = 1. WHILE v_count LE p_count. DESCRIBE TABLE it_padest LINES v_lines. CALL FUNCTION 'RANDOM_I4' " Generate a random INT4 number EXPORTING RND_MIN = 1 RND_MAX = v_lines IMPORTING RND_VALUE = v_random. READ TABLE it_padest INTO wa_padest INDEX v_random. " Pick a random printer IF sy-subrc <> 0. CONTINUE. ENDIF. CALL FUNCTION 'DIALOG_SET_NO_DIALOG'. CALL FUNCTION 'RSPO_OUTPUT_SPOOL_REQUEST' " Print Spool on Printer EXPORTING DEVICE = wa_padest-padest spool_request_id = p_spool EXCEPTIONS ARCHIVE_DEST_INVALID = 1 ARCHIVE_DEST_NOT_FOUND = 2 ARCHIVE_DEST_NO_RIGHT = 3 CANNOT_ARCHIVE = 4 CHANGE_ARCHDEST_NO_RIGHT = 5 CHANGE_COPIES_NO_RIGHT = 6 CHANGE_DEST_NO_RIGHT = 7 CHANGE_DEVTYPE_NO_RIGHT = 8 CHANGE_PRIO_NO_RIGHT = 9 CHANGE_TELENUM_NO_RIGHT = 10 CHANGE_TITLE_NO_RIGHT = 11 DEST_INVALID = 12 DEST_NOT_FOUND = 13 DEST_NO_RIGHT = 14 INTERNAL_PROBLEM = 15 INVALID_FAX_ATTRIBUTE = 16 INVALID_PARAMETERS = 17 NON_OWNER_NO_RIGHT = 18 NO_LAYOUT = 19 NO_SPOOL_REQUEST = 20 OUT_AGAIN_NO_RIGHT = 21 SPOOLER_PROBLEM = 22 OTHERS = 23. wa_output-rqident = p_spool. CALL FUNCTION 'CONVERSION_EXIT_SPDEV_OUTPUT' " Change printer name to full descrip. EXPORTING input = wa_padest-padest IMPORTING OUTPUT = wa_output-padest. IF sy-subrc <> 0. " Not Successful. Write Log CASE sy-subrc. WHEN 1. v_msg = 'ARCHIVE_DEST_INVALID'. WHEN 2. v_msg = 'ARCHIVE_DEST_NOT_FOUND'. WHEN 3. v_msg = 'ARCHIVE_DEST_NO_RIGHT'. WHEN 4. v_msg = 'CANNOT_ARCHIVE'. WHEN 5. v_msg = 'CHANGE_ARCHDEST_NO_RIGHT'. WHEN 6. v_msg = 'CHANGE_COPIES_NO_RIGHT'. WHEN 7. v_msg = 'CHANGE_DEST_NO_RIGHT'. WHEN 8. v_msg = 'CHANGE_DEVTYPE_NO_RIGHT'. WHEN 9. v_msg = 'CHANGE_PRIO_NO_RIGHT'. WHEN 10. v_msg = 'CHANGE_TELENUM_NO_RIGHT'. WHEN 11. v_msg = 'CHANGE_TITLE_NO_RIGHT'. WHEN 12. v_msg = 'DEST_INVALID'. WHEN 13. v_msg = 'DEST_NOT_FOUND'. WHEN 14. v_msg = 'DEST_NOT_FOUND'. WHEN 15. v_msg = 'INTERNAL_PROBLEM'. WHEN 16. v_msg = 'INVALID_FAX_ATTRIBUTE'. WHEN 17. v_msg = 'INVALID_PARAMETERS'. WHEN 18. v_msg = 'NON_OWNER_NO_RIGHT'. WHEN 19. v_msg = 'NO_LAYOUT'. WHEN 20. v_msg = 'NO_SPOOL_REQUEST'. WHEN 21. v_msg = 'OUT_AGAIN_NO_RIGHT'. WHEN 22. v_msg = 'SPOOLER_PROBLEM'. WHEN OTHERS. v_msg = 'Cannot Print on this device. Error.'. ENDCASE. wa_output-message = v_msg. DELETE it_padest WHERE padest = wa_padest-padest. " deleting error printer from list of printers WRITE : wa_output-rqident, wa_output-padest, wa_output-message. ELSE. " Successful. Write Log wa_output-count = v_count. v_count = v_count + 1. wa_output-message = text-005. WRITE :/ wa_output-rqident, wa_output-padest, wa_output-count, wa_output-message. ENDIF. CLEAR : wa_output, v_msg, v_random, v_lines. " Clear temporary variables ENDWHILE. ENDFORM. " GET_SET_DATA
Thanks & Regards,
Rajat Bothra
ABAPer