Wednesday, 22 September 2021

Adjustment of Withholding Tax Information to Relevant Types

 

Error: Auto Payment (F110)

    สาเหตุที่ระบบไม่สามารถเลือก Invoice มาตัดจ่ายได้ที่ Step: Proposal  เนื่องจากมีการเปลี่ยนแปลงบางข้อมูลของ Invoice เช่น Payment method, House bank, Withholding tax information ฯลฯ  ดังนั้นวิธีการแก้ไข ให้ทำตาม 2 ขั้นตอนด้านล่างก่อน



ขั้นตอนการแก้ไข

ขั้นตอนที่ 1 - เข้า T-Code:  SA38 และกรอกข้อมูลตามภาพ


ขั้นตอนที่ 2 - Delete Proposal เดิม และทำการ Run Proposal ใหม่อีกครั้ง

Sunday, 15 August 2021

SAP ABAP - Generating Excel file for downloading or sending over email

 Creating excel content from data in an internal table? 

Getting the following message when opening an excel created out of SAP - "The file you are trying to open, ‘filename.xls’ is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?"


Below is the best solution. This solution is based on the approach used by standard SAP to created excel content from ALV. Once any ALV is displayed, you can get the data into excel using the menu bar option LIST -> EXPORT -> SPREADSHEET. 

If there are any questions, put them in the comments. 


Sample working code:


*&---------------------------------------------------------------------*
*& Report Y_EXCEL
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Y_EXCEL.

DATAlo_data         TYPE REF TO data,
      lt_fieldcatalog 
TYPE lvc_t_fcat,
      l_flavour       
TYPE string,                              " Flavour for XML conversion
      l_version       
TYPE string,                              " XML Version
      lo_result_data  
TYPE REF TO cl_salv_ex_result_data_table" Result data reference
      l_file_type     
TYPE salv_bs_constant,
      lt_xml_choice   
TYPE if_salv_bs_xml=>t_type_xml_choice,
      ls_xml_choice   
TYPE if_salv_bs_xml=>s_type_xml_choice.

DATAg_xstring  TYPE xstring.

*-- Get data from database into internal table
SELECT FROM mara INTO TABLE @DATA(lt_maraUP TO 20 ROWS.

*-- Get object reference of the internal table holding the data
GET REFERENCE OF lt_mara INTO lo_data.

*-- Get the FieldCatalog
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
  
EXPORTING
    i_structure_name       
'MARA'      " The fields in the structure should match with those of the internal table
  
CHANGING
    ct_fieldcat            
lt_fieldcatalog
  
EXCEPTIONS
    inconsistent_interface 
1
    program_error          
2
    
OTHERS                 3.
.
IF sy-subrc EQ 0.

*-- Prepare result data object using final table data reference
*-- and the fieldcatalog
  
CALL METHOD cl_salv_ex_util=>factory_result_data_table
    
EXPORTING
      r_data              
lo_data
      t_fieldcatalog      
lt_fieldcatalog
    RECEIVING
      r_result_data_table 
lo_result_data.

  
IF lo_result_data IS NOT INITIAL.

*--- Get version of XML
    
CASE cl_salv_bs_a_xml_base=>get_version( ).
      
WHEN if_salv_bs_xml=>version_25.
        l_version 
if_salv_bs_xml=>version_25.
      
WHEN if_salv_bs_xml=>version_26.
        l_version 
if_salv_bs_xml=>version_26.
      
WHEN OTHERS.
        
" Do nothing
    
ENDCASE.

*--- Filetype: XLSX
    l_file_type 
if_salv_bs_xml=>c_type_xlsx.
*--- Flavour: Export
    l_flavour 
if_salv_bs_c_tt=>c_tt_xml_flavour_export.

*--- Transformation of data to excel
*--- GXSTRING will be used to send the email
    
CALL METHOD cl_salv_bs_tt_util=>if_salv_bs_tt_util~transform
      
EXPORTING
        xml_type      
l_file_type
        xml_version   
l_version
        r_result_data 
lo_result_data
        xml_flavour   
l_flavour
        gui_type      
if_salv_bs_xml=>c_gui_type_gui
      
IMPORTING
        xml           
g_xstring.


*-- Using Function Module "SCMS_XSTRING_TO_BINARY" we can convert G_XSTRING to Binary format and use that to send
*-- email using class CL_BCS


*-- Below is Sample code to download excel file
    lt_xml_choice 
=  cl_salv_export_xml_dialog=>get_gui_spreadsheet_formats( ).

    
READ TABLE lt_xml_choice INTO ls_xml_choice WITH KEY xml_type l_file_type.
    
IF sy-subrc EQ 0.
      cl_salv_export_xml_dialog
=>downloadEXPORTING s_xml_choice ls_xml_choice
                                                     xml          
g_xstring ).
    
ENDIF.

  
ENDIF.

ENDIF.


Ref: https://quick-drop.blogspot.com/2021/07/sap-abap-generating-xlsx-file-for.html

Wednesday, 4 November 2020

SAP PO/PI sFTP FileName

 

In SFTP server folder, files will be dropped with same original name by enabling ‘Adapter Specific Message-Attributes‘ and using %FileName% in ‘FileName’ input field

Filepath always start with symbol “~”, follow by the path.



Advanced tab:

Tick Use ASMA and Filename. Put namespace “http://sap.com/xi/XI/System/File” and Filename sttribute name “FileName”. This have the flexibility to put any namespace and attributes.


https://blogs.sap.com/2017/11/03/sap-pi-sftp-server-authentication/?utm_source=dlvr.it&utm_medium=facebook


Monday, 9 September 2019

Implement standard source code from SAP Note

How to implement standard source code from SAP Note
1. Open Link : KBA/SAP Note
2. Download : SAR File
3. Tcode : SNOTE


4. Navigate to the menu Goto -> Download SAP Note

5. Enter the Note Number and Execute

How to use sub total in ALV Report

REPORT z_demo_alv_sort.
*---------------------------------------------------------------------*
* This program lists orders (VBAK) with sort and sub-total for        *
* 'sold-to-party' (KUNNR) and 'Sales organization' (VKORG)            *
*---------------------------------------------------------------------*

TABLES : vbak.

TYPE-POOLS: slis.                      " ALV Global types

SELECT-OPTIONS :
  s_vkorg FOR vbak-vkorg,              " Sales organization
  s_kunnr FOR vbak-kunnr,              " Sold-to party
  s_vbeln FOR vbak-vbeln.              " Sales document

SELECTION-SCREEN :
  SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.
PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
SELECTION-SCREEN END OF LINE.

DATA:
  BEGIN OF gt_vbak OCCURS 0,
    vkorg LIKE vbak-vkorg,             " Sales organization
    kunnr LIKE vbak-kunnr,             " Sold-to party
    vbeln LIKE vbak-vbeln,             " Sales document
    netwr LIKE vbak-netwr,             " Net Value of the Sales Order
    waerk LIKE vbak-waerk,             " Document currency
  END OF gt_vbak.

*---------------------------------------------------------------------*
INITIALIZATION.

  v_1 = 'Maximum of records to read'.

*---------------------------------------------------------------------*
START-OF-SELECTION.

  PERFORM f_read_data.

  PERFORM f_display_data.

*---------------------------------------------------------------------*
*      Form  f_read_data
*---------------------------------------------------------------------*
FORM f_read_data.

  SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak
           FROM vbak
             UP TO p_max ROWS
          WHERE kunnr IN s_kunnr
            AND vbeln IN s_vbeln
            AND vkorg IN s_vkorg.

ENDFORM.                               " F_READ_DATA
*---------------------------------------------------------------------*
*      Form  f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.

  DEFINE m_fieldcat.
    add 1 to ls_fieldcat-col_pos.
    ls_fieldcat-fieldname   = &1.
    ls_fieldcat-ref_tabname = 'VBAK'.
    ls_fieldcat-do_sum      = &2.
    ls_fieldcat-cfieldname  = &3.
    append ls_fieldcat to lt_fieldcat.
  END-OF-DEFINITION.

  DEFINE m_sort.
    add 1 to ls_sort-spos.
    ls_sort-fieldname = &1.
    ls_sort-up        = 'X'.
    ls_sort-subtot    = &2.
    append ls_sort to lt_sort.
  END-OF-DEFINITION.

  DATA:
    ls_fieldcat TYPE slis_fieldcat_alv,
    lt_fieldcat TYPE slis_t_fieldcat_alv,
    lt_sort     TYPE slis_t_sortinfo_alv,
    ls_sort     TYPE slis_sortinfo_alv,
    ls_layout   TYPE slis_layout_alv.

  m_fieldcat 'VKORG' ''  ''.
  m_fieldcat 'KUNNR' ''  ''.
  m_fieldcat 'VBELN' ''  ''.
  m_fieldcat 'NETWR' 'X' 'WAERK'.
  m_fieldcat 'WAERK' ''  ''.

  m_sort 'VKORG' 'X'.                  " Sort by vkorg and subtotal
  m_sort 'KUNNR' 'X'.                  " Sort by kunnr and subtotal
  m_sort 'VBELN' ''.                   " Sort by vbeln

  ls_layout-cell_merge = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            is_layout   = ls_layout
            it_fieldcat = lt_fieldcat
            it_sort     = lt_sort
       TABLES
            t_outtab    = gt_vbak.

ENDFORM.                               " F_DISPLAY_DATA

Credit : raam [https://answers.sap.com/questions/4088805/how-to-use-subtotal-in-alv-report.html]