Category Archive ABAP code

Upload file with UTF8 or ANSi encoding

EDIT : Warning, solution below will work only if there is an accentuated caracter in first line.

Wrong encoding format file is a reccurent issue, especially when working on Windows.
If you don’t want to impose to end used an encoding format for text files, you can use the code below.

Read More

Get fullname from User-id

Use code below :


" ADRP-NAME_FIRST : First name
" ADRP-NAME_LAST  : Last name
" ADRP-NAME_TEXT  : Full name

DATA : lv_usrid     TYPE XUBNAME,
       lv_name_text TYPE ADRP-NAME_TEXT.

" [...]

SELECT SINGLE adrp~name_text INTO lv_name_text
  FROM usr21 JOIN adrp ON usr21~persnumber = adrp~persnumber
                      AND adrp~date_from   = '00010101'
                      AND adrp~nation      = ''
  WHERE usr21~bname = lv_usrid.

Insert break line in ABAP string

To insert a BR in a string char, use the following constant :


cl_abap_char_utilities=>cr_lf

Search tag : CrLf, retour chariot, ligne, newline, new, carriage return

Convert standard texts to string

The method below enables to convert standard texts to string (with carriage returns). It can be useful when standard texts need to be changed or completed before being printed on Adobe forms.
(Otherwise, it is recommanded to use the standard text objet for Adobe forms).

Read More

Catch HTML events with ABAP

Check program SAPHTML_EVENTS_DEMO.

Dropdown list in selection-screen

Sample code :


  PARAMETERS : p_field TYPE ztype AS LISTBOX VISIBLE LENGTH 25.
* If the  ZTYPE has a domain with values, values will be autmatically
* displayed.

If your type has no values in domain or if you want to change the dropdown list values use FM VRM_SET_VALUES in initialization:

Read More

Hide a subform according to context node value

To hide a subform using javascript according a context node value in Adobe form :


// data.MAIN.SUBFORM_TO_HIDE::ready:form - (JavaScript, client)
var fieldToCheck= xfa.resolveNode("$record.MAIN.FIELD_VALUE");
if(fieldToCheck.value == null || fieldToCheck.value == "") {
    this.presence = "hidden";
}

Adobe form, count number of elements in a subform with JS

The goal here is to define of there are data into the table, if not, we hide the subform. That means, we hide the whole table (border and header line).
There are several ways to proceed, this is one :

Table from context is binded like :

  • TABLE_TEXT_HEADER_PO binded with $.TABLE_HEADER
  • LINE_TEXT_HEADER_PO binded with $.DATA[*] (repeat subform for each data item is ticked)
  • HEADER_PO_TEXT binded with $.TEXT_CONTENT
Read More