Wednesday, June 3, 2015

AUTO invoice create using BAPI with the reference of sales order



 data : i_bapivbrk like bapivbrk occurs 0 with header line.
  data i_bapiret1 like bapiret1 occurs 0 with header line.
  data : i_bapivbrksuccess like bapivbrksuccess occurs 0 with header line.


  i_bapivbrk-doc_number = zsalesdocument.
  i_bapivbrk-ref_doc = zsalesdocument.
  i_bapivbrk-ref_doc_ca = 'C'.
  append i_bapivbrk.


   call function 'BAPI_BILLINGDOC_CREATEMULTIPLE'
    tables
    billingdatain         = i_bapivbrk
    return                = i_bapiret1
    success               = i_bapivbrksuccess.

   invoice_no = i_bapivbrksuccess-bill_doc.

    call function 'BAPI_TRANSACTION_COMMIT'
    exporting
      wait          = 'X'.

Purcahse order create using BAPI with the reference of purchase requisition



  "---DATA DECALRATION FOR AUTO PO CREATION
tables: bapimepoheader,
        bapimepoheaderx
.

data: it_bapimepoitem type bapimepoitem occurs 0 with header line,
      it_bapimepoitemx 
type bapimepoitemx occurs 0 with header line,
      it_poaccount 
type bapimepoaccount occurs 0 with header line,
      it_poaccountx 
type bapimepoaccountx occurs 0 with header line.
data: it_return2 like bapiret2 occurs 0 with header line.
data: flines like tline occurs 0 with header line,
      string
(132) type c, fobject like thead-tdobject, fname  like thead-tdname.

data: line_no type i.
data: vendor_no type lifnr.

data: ntgew type ekpo-ntgew.
data: brgew type ekpo-brgew.

data: str type string.
data: str1 type string.

data: v_plant(4) type c,
      v_whno
(3) type c,
      v_sorg
(4) type c,
      v_dplnt
(4) type c,
      v_ccode
(4) type c,
      v_curr
(3) type c,
      v_shippt
(4) type c,
      v_country
(2) type c.

data: temp_char(200) type c.

data: banfn type vbep-banfn. " for purchase requisition number.

  
select single banfn into banfn from vbep where vbeln = zsalesdocument. " fetching purchse requisition number

  
" for PO Header data fill

   bapimepoheader
-comp_code = t001-bukrs.
   bapimepoheader
-doc_type = 'ZCOM'.
   bapimepoheader
-item_intvl = '00010'.

   bapimepoheader
-vendor = VENDOR.
   bapimepoheader
-pmnttrms = '0001'.
   bapimepoheader
-purch_org = ‘ABC’.
   bapimepoheader
-pur_group = 'E15'.
   bapimepoheader
-currency = 'USD'.
   
"bapimepoheader-ref_1 = wa_asntab-asnnumber.
   bapimepoheader
-incoterms2 = 'inco2'.

   bapimepoheaderx
-comp_code = 'X'.
   bapimepoheaderx
-doc_type = 'X'.
   bapimepoheaderx
-item_intvl = 'X'.
   bapimepoheaderx
-vendor = 'X'.
   bapimepoheaderx
-pmnttrms = 'X'.
   bapimepoheaderx
-purch_org = 'X'.
   bapimepoheaderx
-pur_group = 'X'.
   bapimepoheaderx
-currency = 'X'.
   
"bapimepoheaderx-ref_1 = 'X'.
   bapimepoheaderx
-incoterms2 = 'X'.

  
" for PO Line item Data FIll

    line_no 
= line_no + 10.
    it_bapimepoitem
-po_item = '00010'.
    it_bapimepoitem
-material = material.
    it_bapimepoitem
-plant = PLANT.
    it_bapimepoitem
-quantity = '1'.
    it_bapimepoitem
-free_item = 'X'.
    it_bapimepoitem
-conf_ctrl = '0004'.
    it_bapimepoitem
-incoterms2 = 'inco2'.

    it_bapimepoitem
-gross_wt = brgew.  “ gross weight

    it_bapimepoitem
-preq_no = banfn. “ purchase requisition number

    it_bapimepoitem
-net_weight = ntgew. “ net weight

    
append it_bapimepoitem to it_bapimepoitem.
    
clear it_bapimepoitem.

    it_bapimepoitemx
-po_item = '00010'.
    it_bapimepoitemx
-material = 'X'.
    it_bapimepoitemx
-plant = 'X'.
    it_bapimepoitemx
-quantity = 'X'.
    it_bapimepoitemx
-free_item = 'X'.
    it_bapimepoitemx
-conf_ctrl = 'X'.
    it_bapimepoitemx
-incoterms2 = 'X'.
    it_bapimepoitemx
-gross_wt = 'X'.
    it_bapimepoitemx
-preq_no  = 'X'.
    it_bapimepoitemx
-net_weight = 'X'.
    
append it_bapimepoitemx to it_bapimepoitemx.
    
clear it_bapimepoitemx.
    
clear: temp_char.

    it_poaccount
-po_item = '00010'.
    it_poaccount
-serial_no = '01'.
    it_poaccount
-quantity = '1'.

    it_poaccount
-costcenter = cost_center.
    
append it_poaccount to it_poaccount.

    it_poaccountx
-po_item = '00010'.
    it_poaccountx
-serial_no = '01'.
    it_poaccountx
-quantity = 'X'.
    it_poaccountx
-costcenter = 'X'.
    
append it_poaccountx to it_poaccountx.


    
clear po_number.

    
call function 'BAPI_PO_CREATE1'
    
exporting
      poheader         
= bapimepoheader
      poheaderx        
= bapimepoheaderx
    
importing
      exppurchaseorder 
= po_number
    
tables
      
return           = it_return2
      poitem           
= it_bapimepoitem
      poitemx          
= it_bapimepoitemx
      poaccount        
= it_poaccount
      poaccountx        
= it_poaccountx.

   
call function 'BAPI_TRANSACTION_COMMIT'
    
exporting
      
wait   = 'X'
    
importing
      
return = return.

CREATE TABLE VALUE REQUEST FOR INPUT PARAMETERS IN MODULE POOL PROGRAM




process before output.
 
module status_0100.

process after 
input.
 
module user_command_0100.
 process 
on value-request.
 
field: t001-bukrs module zsearch_company.

“”””””’’’’’’’’’’’’Start  main module program”””””””””””””””
module zsearch_company input.

  
data: begin of t_company occurs 0,
    bukrs 
type t001-bukrs,
    butxt 
type t001-butxt,
      
end of t_company.

select   bukrs  butxt
  
from  t001 into corresponding fields of table t_company
        
where  bukrs  = 'COM1'


  
call function 'F4IF_INT_TABLE_VALUE_REQUEST'
    
exporting
      retfield    
= 'BUKRS' "field name
      dynpprog    
= sy-cprog "Program name
      dynpnr      
= sy-dynnr   " screen number
      dynprofield 
= 'T001-BUKRS' "screen field name
      value_org   
= 'S'

    
tables
      value_tab   
=  t_company.

endmodule.                 " ZSEARCH_COMPANY  INPUT


“”””””’’’’’’’’’’’’end  main module program”””””””””””””””

Monday, January 12, 2015

find duplicate material from a sap table

select
           count(*) as c
           v~vhilm

      from likp as l inner join vekp as v on l~vbeln = v~vbeln_gen
      into corresponding fields of table t_likp
      where l~vkorg = v_plant
      and   l~lgnum = v_wh
      and   l~erdat in s_grdat
          group by
           v~vhilm.

Sunday, December 28, 2014

Mass deletion of sales orders

Go to TCode MASS, input Object Type BUS2032 and execute.
There select Sales Order Item Data  and click on Fields.
Again select Field Name MASSVBAP-ABGRU  and execute.  Key in those sale orders and execute.
Maintain some reason for rejection and execute, so that the status of the sale orders would be changed to completed.

Saturday, November 22, 2014

Removing specified characters from string

* Remove all occurrences of single and double quotes
  REPLACE ALL OCCURRENCES OF SUBSTRING '''' IN lv_all_params WITH ''.
  REPLACE ALL OCCURRENCES OF SUBSTRING '"' IN lv_all_params WITH ''.

Replace/Remove Specified Characters From String

DATA : legal_chars TYPE string
      VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789.,-*_!?'.
DATA : lv_char_value(255). " give max length

lv_char_value = gv_string.
CHECK NOT ( lv_char_value CO legal_chars ).

lv_length = strlen( gv_string ).

DO lv_length TIMES.
  lv_i = sy-index - 1.
  IF NOT lv_char_value+lv_i(1) CO legal_chars.
    "We get the illegal char , do what you want
    lv_char_value+lv_i(1) = ' '.
  ENDIF.
ENDDO.

CLEAR : gv_string.
gv_string = lv_char_value.

Wednesday, July 23, 2014

How to get Cancel invoice from VBRK table.

TO get the cancelled invoice the query will be like below:

if FKSTO EQ 'X'
and VBTYP EQ 'N' OR FKART EQ 'S1'.


AND SFAKN is for getting cancelled invoice number.

Sunday, June 29, 2014

Example Code For Selection Screen Output

REPORT ZSELECTION_SCREEN.

selection-screen :begin of block test with frame title text-001. 
parameters:a radiobutton group one user-command test, 
                 b radiobutton group one. 
selection-screen:end of block test. 
selection-screen:begin of block test2 with frame title text-002. 
parameters:input1(10) TYPE C MODIF ID TL, 
                 input2(10) TYPE C MODIF ID TT. 
selection-screen:end of block test2. 
   
AT SELECTION-SCREEN OUTPUT. 
  IF a = 'X'. 
      LOOP AT SCREEN. 
          CHECK SCREEN-GROUP1 = 'TT'. 
          SCREEN-INPUT = '0'. 
          MODIFY SCREEN. 
      ENDLOOP. 
  ENDIF.

  IF b = 'X'. 
      LOOP AT SCREEN. 
         CHECK SCREEN-GROUP1 = 'TL'. 
         SCREEN-INPUT = '0'. 
         MODIFY SCREEN. 
      ENDLOOP. 
  ENDIF.