[ABAP] Einkaufsbestelltext zum Material auslesen

* https://www.berater-wiki.de/SAPscript-Textbaustein_lesen_mit_Funktionsbaustein_READ_TEXT_und_speichern_mit_SAVE_TEXT
* Texte: Anwendungsobjekt
* siehe SE75
CONSTANTS: co_obj_type TYPE thead-tdobject VALUE 'MATERIAL'. " Materialtexte Einkauf/Lagerung
* Text-ID
* siehe SE75 --> Doppelklick auf Objekt
CONSTANTS: co_obj_id TYPE thead-tdid VALUE 'BEST'. " Einkaufsbestelltext

DATA: it_thead TYPE STANDARD TABLE OF thead WITH DEFAULT KEY.
DATA: it_lines TYPE tline_t.
DATA: it_ascii TYPE tdtab_c132.

* Materialnummer mit führenden Nullen
DATA(lv_matnr) = CONV matnr( '000000001122334455' ).

* erst 'SELECT_TEXT' zur Prüfung aufrufen (ob Text vorhanden)
* 'READ_TEXT' wirft sonst bei Nichtvorhandensein des Textes eine Abbruchmessage
* Texterstellung Text auswählen
CALL FUNCTION 'SELECT_TEXT'
  EXPORTING
    object                  = co_obj_type
    name                    = CONV thead-tdname( lv_matnr )
    id                      = co_obj_id
    language                = sy-langu
  TABLES
    selections              = it_thead   " Textheader der gefundenen Texte
  EXCEPTIONS
    wrong_access_to_archive = 1
    OTHERS                  = 2.

IF sy-subrc = 0.
  IF lines( it_thead ) > 0.
* Texterstellung Text lesen
    CALL FUNCTION 'READ_TEXT'
      EXPORTING
        id                      = co_obj_id
        language                = sy-langu
        name                    = CONV thead-tdname( lv_matnr )
        object                  = co_obj_type
      TABLES
        lines                   = it_lines " Textzeilen des gelesenen Textes
      EXCEPTIONS
        id                      = 1
        language                = 2
        name                    = 3
        not_found               = 4
        object                  = 5
        reference_check         = 6
        wrong_access_to_archive = 7
        OTHERS                  = 8.

    IF sy-subrc = 0.
      IF lines( it_lines ) > 0.
* Textkonvertierung ITF (SAPscript-Format) in ASCII
* Stile und Formatierungen aus SAP-Script-Text entfernen
        CALL FUNCTION 'CONVERT_ITF_TO_ASCII'
          EXPORTING
            formatwidth       = 132
          IMPORTING
            c_datatab         = it_ascii
          TABLES
            itf_lines         = it_lines
          EXCEPTIONS
            invalid_tabletype = 1
            OTHERS            = 2.
        IF sy-subrc = 0.
          cl_demo_output=>write_data( it_thead ).
          cl_demo_output=>write_data( it_lines ).
          cl_demo_output=>write_data( it_ascii ).
          cl_demo_output=>display( ).
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.
ENDIF.

[ABAP] Auslesen der Schnittstelle eines Funktionsbausteins

PARAMETERS: lv_func TYPE rs38l-name DEFAULT 'READ_TEXT'.

TYPES: ty_it_exeptions TYPE STANDARD TABLE OF rsexc WITH DEFAULT KEY.
TYPES: ty_it_exporting TYPE STANDARD TABLE OF rsexp WITH DEFAULT KEY.
TYPES: ty_it_importing TYPE STANDARD TABLE OF rsimp WITH DEFAULT KEY.
TYPES: ty_it_changing TYPE STANDARD TABLE OF rscha WITH DEFAULT KEY.
TYPES: ty_it_tables TYPE STANDARD TABLE OF rstbl WITH DEFAULT KEY.
TYPES: ty_it_p_docu TYPE STANDARD TABLE OF rsfdo WITH DEFAULT KEY.

DATA(lv_global_flag) = VALUE rs38l-global( ).
DATA(lv_remote_call) = VALUE rs38l-remote( ).
DATA(lv_update_task) = VALUE rs38l-utask( ).

DATA(it_exeptions) = VALUE ty_it_exeptions( ).
DATA(it_exporting) = VALUE ty_it_exporting( ).
DATA(it_importing) = VALUE ty_it_importing( ).
DATA(it_changing) = VALUE ty_it_changing( ).
DATA(it_tables) = VALUE ty_it_tables( ).
DATA(it_p_docu) = VALUE ty_it_p_docu( ).

* Bereitstellung der Schnittstelle eines Funktionsbausteins
CALL FUNCTION 'FUNCTION_IMPORT_INTERFACE'
  EXPORTING
    funcname           = lv_func
  IMPORTING
    global_flag        = lv_global_flag
    remote_call        = lv_remote_call
    update_task        = lv_update_task
  TABLES
    exception_list     = it_exeptions
    export_parameter   = it_exporting
    import_parameter   = it_importing
    changing_parameter = it_changing
    tables_parameter   = it_tables
    p_docu             = it_p_docu
  EXCEPTIONS
    error_message      = 1
    function_not_found = 2
    invalid_name       = 3
    OTHERS             = 4.

IF sy-subrc = 0.
  cl_demo_output=>write_data( lv_global_flag ).
  cl_demo_output=>write_data( lv_remote_call ).
  cl_demo_output=>write_data( lv_update_task ).
  cl_demo_output=>write_data( it_exeptions ).
  cl_demo_output=>write_data( it_exporting ).
  cl_demo_output=>write_data( it_importing ).
  cl_demo_output=>write_data( it_changing ).
  cl_demo_output=>write_data( it_tables ).
  cl_demo_output=>write_data( it_p_docu ).
  cl_demo_output=>display( ).
ENDIF.

[ABAP] Infos (Header + Interface) zu einem Funktionsbaustein lesen

* https://wiki.scn.sap.com/wiki/display/ABAP/Extracting+Function+Module+Details+using+Class+-+CL_FB_FUNCTION_UTILITY
TRY.
    DATA: lv_fm_name TYPE eu_lname VALUE 'BAPI_MATERIAL_GET_ALL'.

* Header des FB lesen
    DATA: lv_head TYPE header_fb.

    cl_fb_function_utility=>meth_get_header_fb( EXPORTING im_name   = lv_fm_name
                                                IMPORTING ex_header = lv_head ).

    cl_demo_output=>write_data( lv_head-name ).
    cl_demo_output=>write_data( lv_head-stext ).
    cl_demo_output=>write_data( lv_head-area ).
    cl_demo_output=>write_data( lv_head-progname ).

* Interface des FB lesen
    DATA: lv_interface TYPE rsfbintfv.

    cl_fb_function_utility=>meth_get_interface( EXPORTING im_name      = lv_fm_name
                                                IMPORTING ex_interface = lv_interface ).

    cl_demo_output=>write_data( lv_interface-import ).
    cl_demo_output=>write_data( lv_interface-export ).
    cl_demo_output=>write_data( lv_interface-change ).
    cl_demo_output=>write_data( lv_interface-tables ).
    cl_demo_output=>write_data( lv_interface-except ).
    cl_demo_output=>write_data( lv_interface-paramtext ).
    cl_demo_output=>write_data( lv_interface-source ).
    cl_demo_output=>write_data( lv_interface-interface ).
    cl_demo_output=>write_data( lv_interface-oparam ).
    cl_demo_output=>write_data( lv_interface-nparam ).
    cl_demo_output=>write_data( lv_interface-fparam ).
    cl_demo_output=>write_data( lv_interface-opdocu ).
    cl_demo_output=>write_data( lv_interface-npdocu ).
    cl_demo_output=>write_data( lv_interface-stub ).
    cl_demo_output=>write_data( lv_interface-frparam ).
    cl_demo_output=>write_data( lv_interface-enhanceparam ).
    cl_demo_output=>write_data( lv_interface-enhancedocu ).

* Anzeige
    cl_demo_output=>display( ).

  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.

[ABAP] Feldinfos zu Tabellenfeldern auslesen

* Infos zur Tabelle 'MARA' lesen
SELECT fieldname, rollname
  INTO TABLE @DATA(it_elements)
  FROM dd03l
  WHERE tabname  = 'MARA'
    AND comptype = 'E'
    AND as4local = 'A'.

IF sy-subrc = 0.

  DATA: lv_dtel TYPE rsddtel.

  LOOP AT it_elements ASSIGNING FIELD-SYMBOL(<e>).
* Infos zu Datenelement lesen, ruft implizit FuBa DDIF_FIELDINFO_GET
    CALL FUNCTION 'RSD_DTEL_GET'
      EXPORTING
        i_dtelnm       = <e>-rollname
      IMPORTING
        e_s_dtel       = lv_dtel
      EXCEPTIONS
        dtel_not_found = 1
        doma_not_found = 2
        illegal_input  = 3
        OTHERS         = 4.

    IF sy-subrc = 0.
* Daten  hinzufügen
      cl_demo_output=>write_data( lv_dtel ).
    ENDIF.
  ENDLOOP.

* Daten anzeigen
  cl_demo_output=>display( ).

ENDIF.

[ABAP] User-spezifische Festwerte und Benutzerparameter lesen

Variante 1 (Festwerte)

DATA: it_users TYPE STANDARD TABLE OF usdef WITH DEFAULT KEY.

* User, für den Parameter ermitteln werden sollen, zur Liste hinzufügen
APPEND VALUE #( bname = sy-uname ) TO it_users.

* Ermittlung der Festwerte zu einer Liste von Benutzern
CALL FUNCTION 'SUSR_GET_USER_DEFAULTS'
  EXPORTING
    langu = sy-langu
  TABLES
    users = it_users.

cl_demo_output=>display( it_users ).

Variante 2 (Benutzerparameter)

DATA: it_user_params TYPE ustyp_t_parameters.

* Benutzer: Lesen Benutzerparameter aus Puffer
* SM30, TPARA
CALL FUNCTION 'SUSR_USER_PARAMETERS_GET'
  EXPORTING
    user_name           = sy-uname
    with_text           = abap_true
  TABLES
    user_parameters     = it_user_params
  EXCEPTIONS
    user_name_not_exist = 1
    OTHERS              = 2.

IF sy-subrc = 0.
  cl_demo_output=>display( it_user_params ).
ENDIF.

Links

[ABAP] Quellcode im ABAP-Editor anzeigen und mit Pretty Print überarbeiten

* https://wiki.scn.sap.com/wiki/display/ABAP/Create+your+own+New+Editor+for+BOR+objects
DATA(it_source_code_in) = VALUE stringtab( ).
DATA(it_source_code_out) = VALUE stringtab( ).

* Quelltext des Reports in Stringtab einlesen
READ REPORT sy-repid INTO it_source_code_in.

* Pretty Print für Code durchführen
CALL FUNCTION 'PRETTY_PRINTER'
  EXPORTING
    inctoo             = space
  TABLES
    ntext              = it_source_code_out
    otext              = it_source_code_in
  EXCEPTIONS
    enqueue_table_full = 1
    include_enqueued   = 2
    include_readerror  = 3
    include_writeerror = 4
    OTHERS             = 5.

IF sy-subrc = 0.
* ABAP-Editor im cl_gui_container=>default_screen anzeigen
  DATA(o_editor) = NEW cl_gui_abapedit( parent = cl_gui_container=>default_screen ).
* ReadOnly setzen
  o_editor->set_readonly_mode( 1 ).
* Quelltext setzen
  o_editor->set_text( it_source_code_out ).

* cl_gui_container=>default_screen erzwingen
  WRITE space.
ENDIF.

[ABAP] SM30 mit Pflegedialog aufrufen

* Tabelle / Pflegeview
DATA(lv_tab) = CONV dd02v-tabname( 'V_T001' ).

* U - Ändern
* S - Anzeigen, Subset
* T - Transport
* X - gesetztes Flag
* R - read-only
DATA(lv_action) = 'U'.

* SM30: Aufruf der erweiterten Tabellenpflege (Viewpflege) oberste Einstiegsebene
CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
  EXPORTING
    action                       = lv_action
    view_name                    = lv_tab
  EXCEPTIONS
    client_reference             = 1
    foreign_lock                 = 2
    invalid_action               = 3
    no_clientindependent_auth    = 4
    no_database_function         = 5
    no_editor_function           = 6
    no_show_auth                 = 7
    no_tvdir_entry               = 8
    no_upd_auth                  = 9
    only_show_allowed            = 10
    system_failure               = 11
    unknown_field_in_dba_sellist = 12
    view_not_found               = 13
    maintenance_prohibited       = 14
    OTHERS                       = 15.

IF sy-subrc <> 0.
  WRITE: / sy-subrc.
ENDIF.

[ABAP] Email-Adresse validieren

DATA: lv_address_normal TYPE sx_address.
DATA: lv_local TYPE sx_addr.
DATA: lv_domain TYPE sx_addr.
DATA: lv_comment TYPE sx_addr.
DATA: lv_addr_normal_no_upper TYPE sx_address.
DATA: lv_addr_normal_no_up TYPE sx_address.

* Type
* FAX	Faxnummer
* INT	Internet Mail Adresse
* X40	X.400 Mail Adresse
* RML	SAPoffice Adresse
* PAG	Pager(SMS) Nummer
* PRT	Druckername
* *	Alle
DATA(lv_address_unstruct) = value sx_address( address = 'email (Test)@email.com'
                                              type    = 'INT' ).

WRITE: / lv_address_unstruct-type, lv_address_unstruct-address.

CALL FUNCTION 'SX_INTERNET_ADDRESS_TO_NORMAL'
  EXPORTING
    address_unstruct               = lv_address_unstruct
  IMPORTING
    address_normal                 = lv_address_normal        " Normalform: Local@DOMAIN
    local                          = lv_local                 " Lokaler Teil der Adresse
    domain                         = lv_domain                " Domäne (konvertiert zu Großbuchstaben)
    comment                        = lv_comment               " Kommentar der Adresse
    addr_normal_no_upper           = lv_addr_normal_no_upper  " Adresse: Local@Domain (Domäne unkonvertiert)
    addr_normal_no_up_with_comment = lv_addr_normal_no_up     " Normalform mit Kommentar
  EXCEPTIONS
    error_address_type             = 1
    error_address                  = 2
    error_group_address            = 3
    OTHERS                         = 4.

IF sy-subrc = 0.
  WRITE: / '                    Normalform:', lv_address_normal-type, lv_address_normal-address.
  WRITE: / '                  Lokaler Teil:', lv_local.
  WRITE: / '                        Domäne:', lv_domain.
  WRITE: / '                     Kommentar:', lv_comment.
  WRITE: / 'Adresse (Domäne unkonvertiert):', lv_addr_normal_no_upper-type, lv_addr_normal_no_upper-address.
  WRITE: / '      Normalform mit Kommentar:', lv_addr_normal_no_up-type, lv_addr_normal_no_up-address.
ELSE.
  WRITE: / 'Error:', sy-subrc.
ENDIF.

[ABAP] Schnittstelle zu Funktionsbaustein auslesen

* Name des Funktionsbausteins
DATA(lv_head) = VALUE header_fb( name = 'BAPI_MATERIAL_GET_ALL' ).
DATA(it_import) = VALUE rsfb_para( ).
DATA(it_export) = VALUE rsfb_para( ).
DATA(it_change) = VALUE rsfb_para( ).
DATA(it_tables) = VALUE rsfb_para( ).
DATA(it_except) = VALUE rsfb_para( ).

* Infos zum Funktionsbaustein holen
cl_fb_parameter_db=>read( IMPORTING
                            import = it_import
                            export = it_export
                            change = it_change
                            tables = it_tables
                            except = it_except
                          CHANGING
                            header = lv_head ).

* IMPORTING
LOOP AT it_import ASSIGNING FIELD-SYMBOL(<i>).
  WRITE: / '[IMPORT]', <i>-parameter, <i>-typefield, <i>-structure.
ENDLOOP.

* EXPORTING
LOOP AT it_export ASSIGNING FIELD-SYMBOL(<e>).
  WRITE: / '[EXPORT]', <e>-parameter, <e>-typefield, <e>-structure.
ENDLOOP.

* CHANGING
LOOP AT it_change ASSIGNING FIELD-SYMBOL(<c>).
  WRITE: / '[CHANGE]', <c>-parameter, <c>-typefield, <c>-structure.
ENDLOOP.

* TABLES
LOOP AT it_tables ASSIGNING FIELD-SYMBOL(<t>).
  WRITE: / '[TABLES]', <t>-parameter, <t>-typefield, <t>-structure.
ENDLOOP.

* EXCEPTIONS
LOOP AT it_except ASSIGNING FIELD-SYMBOL(<ex>).
  WRITE: / '[EXCEPTION]', <ex>-parameter, <ex>-typefield, <ex>-structure.
ENDLOOP.