Sunday, 2 August 2020

Convert/Copy OTF spool to create new PDF spool.

                             
Code:

REPORT zr_spool_pdf LINE-SIZE 80.
*
* Read spool job contents (OTF or ABAP list) and convert
* to PDF, download PDF
TABLES: tsp01.
PARAMETERS:
  spoolno 
LIKE tsp01-rqident,
  p_dele  
AS CHECKBOX.

DATA otf LIKE itcoo OCCURS 100 WITH HEADER LINE.
DATA cancel.
DATA pdf LIKE tline OCCURS 100 WITH HEADER LINE.
DATA: numbytes   TYPE i,
      arc_idx    
LIKE toa_dara,
      pdfspoolid 
LIKE tsp01-rqident,
      jobname    
LIKE tbtcjob-jobname,
      jobcount   
LIKE tbtcjob-jobcount,
      is_otf
,
      txt
(80)    TYPE c.
DATA: client  LIKE tst01-dclient,
      name    
LIKE tst01-dname,
      objtype 
LIKE rststype-type,
      
type    LIKE rststype-type,
      spoolid 
TYPE rspoid,
      pages   
TYPE i,
      pdfstr  
TYPE string,
      pdfxstr 
TYPE xstring.
START-OF-SELECTION.
  
SELECT SINGLE * FROM tsp01 WHERE rqident = spoolno.
  
IF sy-subrc <> 0.
    
MESSAGE 'Spool not available' TYPE 'E' .
    
EXIT.
  
ENDIF.

  
client = tsp01-rqclient.
  name   
= tsp01-rqo1name.
  
CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
    
EXPORTING
      authority     
= 'SP01'
      
client        = client
      name          
= name
      part          
= 1
    
IMPORTING
      
type          = type
      objtype       
= objtype
    
EXCEPTIONS
      fb_error      
= 1
      fb_rsts_other 
= 2
      no_object     
= 3
      no_permission 
= 4.
  
IF objtype(3) = 'OTF' OR objtype+1(3) = 'OTF'.  "Script OTF

    
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
      
EXPORTING
        src_spoolid              
= spoolno
        no_dialog                
= ' '
*       DST_DEVICE               =
*       PDF_DESTINATION          =
      
IMPORTING
        pdf_bytecount            
= numbytes
        pdf_spoolid              
= pdfspoolid
*       OTF_PAGECOUNT            =
        btc_jobname              
= jobname
        btc_jobcount             
= jobcount
      
TABLES
        pdf                      
= pdf
      
EXCEPTIONS
        err_no_otf_spooljob      
= 1
        err_no_spooljob          
= 2
        err_no_permission        
= 3
        err_conv_not_possible    
= 4
        err_bad_dstdevice        
= 5
        user_cancelled           
= 6
        err_spoolerror           
= 7
        err_temseerror           
= 8
        err_btcjob_open_failed   
= 9
        err_btcjob_submit_failed 
= 10
        err_btcjob_close_failed  
= 11.
    
IF sy-subrc NE 0 .
      
MESSAGE 'Spool OTF to PDF Conversion errro' TYPE 'E' .
    
ENDIF.

  
ENDIF.

* ->Convert PDF output to XSTRING
  
FIELD-SYMBOLS:<p> TYPE x. " <p> type any.
  
LOOP AT pdf .

    
ASSIGN pdf TO <p> CASTING TYPE x.

    
CONCATENATE pdfxstr <p> INTO pdfxstr IN BYTE MODE.
  
ENDLOOP.

  pages 
= tsp01-rqapprule .

  
CALL FUNCTION 'ADS_CREATE_PDF_SPOOLJOB'
    
EXPORTING
*     printer           = 'ZMAIL'  "tsp03d-patype should be PDF use any one
      dest              
= 'ZMAI'   "tsp03d-patype should be PDF use any one
      pages             
= pages
      pdf_data          
= pdfxstr
    
IMPORTING
      spoolid           
= spoolid
    
EXCEPTIONS
      no_data           
= 1
      not_pdf           
= 2
      wrong_devtype     
= 3
      operation_failed  
= 4
      cannot_write_file 
= 5
      device_missing    
= 6
      no_such_device    
= 7
      
OTHERS            = 8.

  
WRITE: 'Old spool : ', spoolno .
  
WRITE: 'NEW spool : ', spoolid .

  
IF p_dele = 'X'.
    
CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
      
EXPORTING
        spoolid      
= spoolno
        allow_commit 
= 'X'  .
  
ENDIF.

Wednesday, 13 April 2016

BADI: Add Item Custom Fields Tab in VL01N,VL02N,VL03N ( Delivery )

BADI : LE_SHP_TAB_CUST_ITEM
Table  : LIPS
Append Structure Demo:

LIPS:
BADI Implementation:

T-Code : SE18
Select the menu Enhancement Implementation->Create 

Double click the method and start writing code like below.
        method if_ex_le_shp_tab_cust_item~activate_tab_page.

             ef_caption = text-000.                                                     "Tab Description
            ef_program = 'SAPLZSDVL01_ITEM'."                    "Program Name
            ef_position = 4.                                                                "Tab Position                             
           ef_dynpro  = '9000'.                                                        " Sub Screen Number
           cs_v50agl_cust = 'X'.

        endmethod.


Result:








BADI: Add Header Custom Fields Tab in VL01N,VL02N,VL03N ( Delivery )

BADI     : LE_SHP_TAB_CUST_HEAD
Table      : LIKP

Add filed in LIKP Table: 

BADI Implementation:

Select the menu Enhancement Implementation->Create 
Enter the enhancement name and press enter

Double click the method and start writing code like below.


method if_ex_le_shp_tab_cust_head~activate_tab_page.

    ef_caption = text-100. "Container Details                      "Tab Description
    ef_position = 5.                                                                  "Tab Display Position
    ef_program = 'ZDPL_CUS_TAB_DELIVERY'.           "Program Name 
    ef_dynpro  = '9000'.                                                          "SubScreen Number
    cs_v50agl_cust = 'X'.

endmethod.





Sub screen Details:

Result:






BADI: Add Item Tab Custom Fields in VA01,VA02,VA03( Sales Order ) with BAPI Extension

BADI                                                :  BADI_SLS_ITEM_SCR_CUS
Add field in following Table          :  VBAP
Add field in following structures :  (used for extension and Communication structure)

           BAPE_VBAP, BAPE_VBAPX, VBAPKOZ, VBAPKOZX
Append Structure Demo:


VBAP:
BADI Implementation:

T-Code : SE18
Enter the BADI name  and click display


Expand BADI_SLS_ITEM_SCR_CUS
Right Click implementation
Below popup will be appeared and click create button.


Enter the enhancement name, description and press enter .
Enter the package name and create the Transport request.

Double click on your enhancement name, below screen will be appeared. Enter the implementation name , description and class name, then press enter or click tick mark.
Below Screen will be appeared 

Expand BADI implementation and double click on implementation class which one highlighted on below screen short.

Double click on methods and start writing on code like below.


method if_ex_sls_item_scr_cus~activate_tab_page.
  data:ls_item_tab like line of ct_cus_item_tab.

    ls_item_tab-item_caption = 'Planing Details'.                                             "Tab Description
    ls_item_tab-item_program = 'ZDPL_CUS_TAB_SALES_ITEM'.           "Program name
    ls_item_tab-item_dynpro = '9100'.                                                               "Subscreen No
    append ls_item_tab to ct_cus_item_tab.

endmethod.




Note:  1. No need to write any code for data transfer.
            2. Screen should be sub screen.
Sub Screen Details:

Result:

Using BAPI to Update the filed:

BAPE_VBAPX:
Note:  Use data element as CHAR1 , don’t use BAPIUPDATE .

 BAPE_VBAP:


 VBAPKOZ:


 VBAPKOZX:

Note:  Use data element as CHAR1 , don’t use BAPIUPDATE .

Extension Structure Code:

While updating custom fields through BAPI, need to use below code.


data: bape_vbap  type bape_vbap ,
     bape_vbapx 
type bape_vbapx .
data: extensionin type table of bapiparex with header line.
  bape_vbap-vbeln    = vbeln.      “For creation make it blank (vbeln)
  bape_vbap
-posnr    = posnr.
  bape_vbap
-zzrunno  = runno .
  bape_vbap
-zzryear  = ryear .

  bape_vbapx
-vbeln   = vbeln.     “For creation make it blank (vbeln)
  bape_vbapx
-posnr   = posnr.
  bape_vbapx
-zzrunno = 'X' .
  bape_vbapx
-zzryear = 'X' .

  
move 'BAPE_VBAP' to extensionin-structure.

  
call method cl_abap_container_utilities=>fill_container_c
    
exporting
      im_value     
= i_bape_vbap
    
importing
      ex_container 
= extensionin-valuepart1.
  
append extensionin to extensionin.

  
move 'BAPE_VBAPX' to extensionin-structure.
  
move bape_vbapx to extensionin-valuepart1.
  
append extensionin to extensionin .