Category Archive ABAP code

Change paragraph text width

Convert table text to another lenght :


  CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
    EXPORTING
      line_width_src              = 79
      line_width_dst              = 255
    TABLES
      content_in                  = li_input_text_79
      content_out                 = li_input_text_whished_at_255
    EXCEPTIONS
      err_line_width_src_too_long = 1
      err_line_width_dst_too_long = 2
      err_conv_failed             = 3
      OTHERS                      = 4.

 

Convert string char to table :


  CALL FUNCTION 'SO_STRING_TO_TAB'
    EXPORTING
      content_str = lw_string
    TABLES
      content_tab = li_input_text_whished_at_255.

 

Search tag: convert, conversion, text, texte

 

Convert date to local timezone

Check code example below :


  DATA : lw_timestamp     TYPE timestamp,
         lw_date_syst     TYPE datum,
         lw_time_syst     TYPE uzeit,
         lw_date_local    TYPE datum,
         lw_time_local    TYPE uzeit,
         lw_syst_timezone TYPE tznzone.

  " Retrieve system timezone
  " ------------------------
  SELECT SINGLE tzonesys
       FROM ttzcu
       INTO lw_syst_timezone.

  " Convert date / time to system timestamp
  " ---------------------------------------
  CONVERT DATE lw_date_syst
          TIME lw_time_syst
          DAYLIGHT SAVING TIME 'X'           " Manage summer/winter time
          INTO TIME STAMP lw_timestamp
          TIME ZONE lw_syst_timezone.

  " Convert timestamp to local date/time
  " ------------------------------------
  CONVERT TIME STAMP lw_timestamp TIME ZONE sy-zonlo
  INTO DATE lw_date_local
       TIME lw_time_local.

Search tag: fuseau horaire, heure, convertir,

Convert text in UTF-8

When opening data in UTF-8, the transfered text must also be converted to UTF-8.
Check method described :
https://archive.sap.com/discussions/thread/1401493
Read More

Read / write file with ABAP

Read file :



  DATA : lo_error  TYPE REF TO cx_root,
         lw_error  TYPE string.

*                    ENCODING DEFAULT = ANSCII on main SAP system.
  OPEN DATASET lw_fullname FOR INPUT IN TEXT MODE ENCODING DEFAULT. 
  IF sy-subrc <> 0.
    " Manage erreur
  ENDIF.

* For each line
  DO.
*   Read line
    TRY.
          READ DATASET lw_fullname INTO lw_string.

       CATCH cx_sy_conversion_codepage INTO lo_error.  " En cas d'erreur d`encodage, 
        lw_error = lo_error->get_text( ).              " fichier en UTF-8 alors que 
        WRITE / lw_error.                              " lu en mode défaut par exemple
        EXIT.       
    ENDTRY.

    IF sy-subrc = 0.
      " Treat data
      APPEND lw_string TO li_string.
    ELSE.
      EXIT.
    ENDIF.

  ENDDO.
  
  CLOSE DATASET lw_fullname.

Assign screen variable to ABAP

Example :


  DATA : li_xvepo TYPE TABLE OF VEPOVB.

  FIELD-SYMBOLS: <fi_xvepo> TYPE ANY.

  ASSIGN ('(SAPLV51P)GT_XVEPO') TO <fi_xvepo>.
  IF <fi_xvepo> IS ASSIGNED.
    MOVE <fi_xvepo> TO li_xvepo.
  ENDIF.

 

Search tag: dynpro, structure, table, dynamique, dynamic, global data

 

Function to read Excel file

Use FM ALSM_EXCEL_TO_INTERNAL_TABLE to read Excel file

Caution, this use OLE_Objects and can’t be run in background.

Read More

Convert date to posting date

Posting date = date comptable.
Use the FM below :


  CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'
    EXPORTING
      i_gjahr        = gv_gjhar
      i_periv        = gc_24
      i_poper        = gv_poper
    IMPORTING
      e_date         = s_fkdat-low
    EXCEPTIONS
      input_false    = 1
      t009_notfound  = 2
      t009b_notfound = 3
      OTHERS         = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
    EXPORTING
      i_gjahr        = gv_gjhar
      i_periv        = gc_24
      i_poper        = gv_poper
    IMPORTING
      e_date         = s_fkdat-high
    EXCEPTIONS
      input_false    = 1
      t009_notfound  = 2
      t009b_notfound = 3
      OTHERS         = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

 

Search tag: date comptable, conversion

 

EXPORT / IMPORT internal_table TO / FROM MEMORY ID

Export :


DATA : li_table_imported TYPE TABLE OF db_dable.

EXPORT my_table FROM li_table_imported TO MEMORY ID 'MEM_TAB'.

 

Import:


DATA : li_table_exported TYPE TABLE OF db_dable.

IMPORT my_table TO li_table_exported FROM MEMORY ID 'MEM_TAB'.

 

Clear:


 FREE MEMORY ID 'MEM_TAB'.

USER EXIT for sales order (VA01 / VA02)

Use forms in this include: MV45AFZZ.

Check also includes : MV45AFZA and MV45AFZB.

Read More

WBS elements and projects

Table for :

  • WBS elements : PRPS
  • WBS projects : PROJ.

Search tag: OTP