Archive

Posts Tagged ‘ABAP API’

SAP ABAP – Transfer number to chinese character function module

January 9th, 2012 No comments

Only Chinese Project will use this funtion module.Usually in account document print.

To english character,we can use spell_amout.

FUNCTION z_convert_numeric_to_chinese.
*";----------------------------------------------------------------------
*";*";Local interface:
*";  IMPORTING
*";     REFERENCE(PI_MONEY) LIKE  BSEG-DMBTR
*";  EXPORTING
*";     REFERENCE(PO_CHINESE)
*";  EXCEPTIONS
*";      WRONG_MONEY
*";----------------------------------------------------------------------
  IF pi_money = 0.
    po_chinese = '零'.
    EXIT.
  ENDIF.
  DATA:money_str(13).
  money_str = pi_money.
  IF money_str CN '0123456789. '.
    RAISE wrong_money.
  ENDIF.
  DATA:i TYPE i.
  IF money_str CS '.'.
    i = sy-fdpos + 1.
 
    money_str+sy-fdpos = money_str+i.
  ENDIF.
  CONDENSE money_str NO-GAPS.
  DATA:units_off TYPE i,
         curnt_off TYPE i.
  DATA:lastd TYPE n,curntd TYPE n.
  DATA:cword(2),weight(2).
  DATA:units(30) VALUE ' 分 角 元 拾 佰 仟 万 拾 佰 仟 亿 拾 佰 仟 万',
         digts(20) VALUE ' 零 壹 贰 叁 肆 伍 陆 柒 捌 玖'.
  CLEAR:po_chinese,units_off.
  lastd = 0.
  units_off = 0.
  curnt_off = STRLEN( money_str ) - 1.
  WHILE curnt_off >;= 0.
    curntd = money_str+curnt_off(1).
    i = curntd * 2.
    cword = digts+i(2).
 
    weight = units+units_off(2).
 
    i = units_off / 2.
    IF curntd = 0.             ";Current digit is 0
      IF i = 2 OR i = 6 OR i = 10.
        CLEAR:cword.
        IF curnt_off = 0.
          CLEAR:weight.
        ENDIF.
      ELSEIF lastd = 0.
        CLEAR:cword,weight.
      ELSE.
        CLEAR:weight.
      ENDIF.
    ENDIF.
    CONCATENATE cword weight po_chinese INTO po_chinese.
    lastd = curntd.
    SUBTRACT 1 FROM curnt_off.
    ADD 2 TO units_off.
  ENDWHILE.
  IF po_chinese NS '分'.
    CONCATENATE po_chinese '整' INTO po_chinese.
  ELSE.
    cword = po_chinese.
    IF cword = '零'.
      SHIFT po_chinese BY 2 PLACES.
    ENDIF.
  ENDIF.
*-----------------BEGIN----------------------------
*&; 当数值为100,000,000.01 时,调用该函数
*&; ,显示出来为壹亿万元零壹分,加上该段
*&; ,则读为壹亿元零壹分。
  SEARCH po_chinese FOR '亿 万'.
  IF sy-subrc = 0.
    REPLACE '亿 万' WITH '亿' INTO po_chinese.
  ENDIF.
*-----------------END------------------------------
  CONDENSE po_chinese NO-GAPS.
 
 
 
ENDFUNCTION.

SAP BAPI – BAPI_SALESORDER_CREATEFROMDAT2

August 4th, 2011 No comments

BAPI – BAPI_SALESORDER_CREATEFROMDAT2 is designed to create sales order from external system. It belongs to object type BUS2032.

Note

If you fill the target_qty field in the item table but the sales order created with the quantity ‘0’. – You need to fill the schedule line table and maintain the req_quantity field as well. Below code snip can be used to create sales order.

Read more…

How to find document for BAPI or Function Modules

February 28th, 2011 No comments

One of my blog reader asked me to send him some documentations on BAPI and function modules. No central API documentation repository seems the pain for all the Abapers. Below is my personal understanding on this question. If you have any other viewpoints, please kindly share them with everyone.

Read more…

ALSM_EXCEL_TO_INTERNAL_TABLE

April 29th, 2010 1 comment

Many customers need a function that allows them to transfer values from an Excel table to the SAP system. Up to now there has been no formally released interface for this.

For the Asset Accounting legacy data transfer, a module was written to transfer the Excel data using the clipboard of the Windows system by OLE (Object Linking and Embedding. This module is called ALSM_EXCEL_TO_INTERNAL_TABLE. The module was only designed for the requirements of the Asset Accounting legacy data transfer. This leads to some restrictions, including the following:

Read more…

Common ABAP Function Modules – 1

March 3rd, 2010 2 comments

Application Area – BC

Overview

In daily ABAP programming, we often need to use plenty of function modules. SAP doesn’t provide the detail API cookbook for these function modules. ABAPer always need to use their experience to use them freely. I try to list some common and useful fuction modules to my best and attach a short piece of description. For detail usage of these function modules, you can refer to the documentation as well as web resources. I plan to group the function modules to different functionalities, This post deals with the function module related to dynpro programming.

Function Modules Detail – Dynpro Programming

a) VIEW_MAINTENANCE_CALL – Call Extended Table Maintenance (View Maint) Highest Level like SM30.

b) DYNP_VALUES_READ – Read screen field values before PAI field transport. This function module reads screen field contents that are to be processed by the help modules.

c) DYNP_VALUES_UPDATE – Reset selected screen field contents. You can use this function module to reset selected help processor field contents in the corresponding screen fields. The module DYNP_GET_STEPL must first be called in strp-loop or table control to set the correct step-loop.

Read more…

Pop up messages when user logons SAP system

February 4th, 2010 1 comment

Sometimes we need to configure the sap server to pop up a message to the users when they logon to the system. Generally, there are two methods to meet this requirement.

  1. Go to transaction SM02 – System Messages. You can maintain the system message here. If user refreshes or open the window, the system message will be displayed.
  2. But business wants only part of user will receive such messages when user logon, above method doesn’t work very well. Some enhancement needs to be done. Use customer exit ‘SUSR0001’. Below are the detail steps.
  • Transaction SMOD, enter exit name ‘SUSR0001’.

Read more…

SAP Status Management

January 27th, 2010 2 comments

Status is very important and useful in SAP. It is used to record current status of different business objects, such as sales order, quality notification and purchase order etc. It comprises user status and system status. The system status cannot be set by user. It is determined by system automatically. The user status can be set manually.

Status doesn’t just show the business transaction status, it can also be the trigger point of the workflow. For example, a workflow can be started according the status change.

Read more…

Long Text in SAP

January 26th, 2010 No comments

Long text is used in various components to store comments or additional text freely. It is stored in ITF (Interchange Text Format) format and comprises of text header and text lines.

The text header contains all administrative information on a long text. Below diagram shows some important fields in the text header.

Text name (TDNAME): Customer-defined name of a text. It can be a maximum of 70 characters in length.

Language (TDSPRAS): The language key is an abbreviation for the language of the object being processed.

Text ID (TDID): The text ID defines the various types of texts related to a text object. The text ID must be defined in table TTXID together with the text object.

Text Object (TDOBJECT): It contains the name of the text object to which the text is allocated. This object must be defined in table TTXOB.

Read more…

ABAP Email Traditional API

January 7th, 2010 No comments

SAP provides several function modules to send email to the external world. The interfaces of them are more or less the same, just with some minor difference.

Function Group: SOI1 – API Function Modules for Externals

Function Module:

SO_DOCUMENT_SEND_API1 – SAPoffice: Send new document with attachments using RFC
SO_NEW_DOCUMENT_SEND_API1 – SAPoffice: Send new document
SO_NEW_DOCUMENT_ATT_SEND_API1 - SAPoffice: Send new document with attachments using RFC

In the implementation, all above function modules will call another function module ‘SO_OBJECT_SEND’ to send email.

Differences among these function modules:

SO_DOCUMENT_SEND_API1 - In this FM u can specify the sender address. Means u can hardcode any ID and system will display that sender only irrespective of who is running the report.

SO_NEW_DOCUMENT_SEND_API1 – Through this system will pick sender based on from which id running the program. This function module also enables you to send a new document, which has not yet been created, internally and externally. During the send process the document is created, along with the attributes and content that is to be transferred.

SO_NEW_DOCUMENT_ATT_SEND_API1 - This function module enables you send a new document including any existing attachments. The document and the attachments are transferred in the same table. They are created when sent and can also be placed in the sender’s outbox.

Except these function modules, SAP provides a simplified one named HR_FBN_GENERATE_SEND_EMAIL. If you check the function module interface, you will find it is quite easy to use.

I will give some useful examples with actual scenario recently. But above function modules are more or less not state of the art and difficult to handle. Meanwhile, SAP introduced the BCS (Business Communication Services), a much more flexible and future-oriented OO attempt to Mail. We will discuss it later.

ALV Tips – Display column as Icon

December 30th, 2009 2 comments

We may need to display traffic light or some other icons in the ALV output to highlight some lines. Here is an example.

To use icons, you need to use types-pool: icon or include the include file <ICON> in the program.

Read more…