Adressenaufbereitung mit CUSTOMER_ADDRESS_TO_ITF

DATA: lv_address TYPE bapiaddr3.
DATA: it_bapi_return TYPE STANDARD TABLE OF bapiret2 WITH DEFAULT KEY.
 
CALL FUNCTION 'BAPI_USER_GET_DETAIL'
  EXPORTING
    username = sy-uname
  IMPORTING
    address  = lv_address
  TABLES
    return   = it_bapi_return.

DATA: lv_customer TYPE scustom.
lv_customer-name = lv_address-fullname.
lv_customer-street = lv_address-street.
lv_customer-postbox = lv_address-po_box.
lv_customer-postcode = lv_address-postl_cod1.
lv_customer-city   = lv_address-city.
lv_customer-country = lv_address-country.
lv_customer-region = lv_address-region.
lv_customer-telephone = lv_address-tel1_numbr.
lv_customer-email = lv_address-e_mail.

DATA: lv_sender_country TYPE szad_field-send_cntry.
lv_sender_country = 'US'.

DATA: it_address_lines TYPE tline_tab.

CALL FUNCTION 'CUSTOMER_ADDRESS_TO_ITF'
  EXPORTING
    is_customer        = lv_customer
    iv_sending_country = lv_sender_country
*   IV_NUMBER_OF_LINES = 5
  IMPORTING
    et_address         = it_address_lines.

cl_demo_output=>write_data( lv_address ).
cl_demo_output=>write_data( lv_customer ).
cl_demo_output=>write_data( lv_sender_country ).
cl_demo_output=>write_data( it_address_lines ).
cl_demo_output=>display( ).

Adressenaufbereitung mit ADDRESS_INTO_PRINTFORM

* https://www.berater-wiki.de/Adressenaufbereitung#Funktionsbaustein_ADDRESS_INTO_PRINTFORM

DATA: lv_address TYPE bapiaddr3.
DATA: it_bapi_return TYPE STANDARD TABLE OF bapiret2 WITH DEFAULT KEY.

CALL FUNCTION 'BAPI_USER_GET_DETAIL'
  EXPORTING
    username = sy-uname
  IMPORTING
    address  = lv_address
  TABLES
    return   = it_bapi_return.

DATA: ls_address TYPE  adrs1.
ls_address-title_text = lv_address-title_p.
ls_address-name1      = lv_address-fullname.
ls_address-street     = lv_address-street.
*  ls_address-po_box     = is_customer-postbox.
ls_address-post_code1 = lv_address-postl_cod1.
*  ls_address-region     = is_customer-region.
ls_address-city1      = lv_address-city.
ls_address-country    = lv_address-country.
DATA: lv_sender_country TYPE land1.
lv_sender_country = 'US'.

DATA: it_address_lines TYPE szadr_printform_table.
CALL FUNCTION 'ADDRESS_INTO_PRINTFORM'
  EXPORTING
    address_1               = ls_address
    address_type            = '1' "normal/company
    sender_country          = lv_sender_country
    *    number_of_lines         = 5
  IMPORTING
    address_printform_table = it_address_lines.
    
cl_demo_output=>write_data( ls_address ).
cl_demo_output=>write_data( lv_sender_country ).
cl_demo_output=>write_data( it_address_lines ).
cl_demo_output=>display( ).

[ABAP] Neue / obsolete Transaktionscodes für S/4 HANA suchen

* https://thinkdoforward.com/neue-transaktionen-mit-s-4hana-so-einfach-findest-zu-sie/
PARAMETERS: p_rel TYPE saprl DEFAULT '751'.
SELECT-OPTIONS: so_ta FOR lv_s_tcode.

START-OF-SELECTION.

  SELECT c~rel_name, c~s_tcode, c~t_tcode, tx~ttext
    INTO TABLE @DATA(it_prgn_corr2)
    FROM prgn_corr2 AS c
    INNER JOIN tstc AS t ON ( c~t_tcode = t~tcode )
    RIGHT OUTER JOIN tstct AS tx ON ( t~tcode = tx~tcode )
    WHERE c~rel_name >= @p_rel
      AND c~s_tcode IN @so_ta
      AND tx~sprsl = @sy-langu.

  SORT: it_prgn_corr2 BY s_tcode rel_name.


  TRY.
* SALV-Table
      DATA: o_salv TYPE REF TO cl_salv_table.

      cl_salv_table=>factory( IMPORTING
                                r_salv_table = o_salv
                              CHANGING
                                t_table      = it_prgn_corr2 ).

* Grundeinstellungen
      o_salv->get_functions( )->set_all( abap_true ).
      o_salv->get_columns( )->set_optimize( abap_true ).
      o_salv->get_display_settings( )->set_list_header( 'Überschrift' ).
      o_salv->get_display_settings( )->set_striped_pattern( abap_true ).
      o_salv->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ).

      LOOP AT o_salv->get_columns( )->get( ) ASSIGNING FIELD-SYMBOL(<c>).
        DATA(o_col) = <c>-r_column.
        o_col->set_short_text( || ).
        o_col->set_medium_text( || ).
        o_col->set_long_text( |{ o_col->get_columnname( ) } [{ o_col->get_long_text( ) }]| ).
      ENDLOOP.

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

[ABAP] Textpatterns in Strings mittles Vergleichsoperator CP (Covers Pattern) suchen

* https://www.berater-wiki.de/Vergleichsoperatoren_Zeichen
* Variante 1 (Wildcard)
DATA(lv_test) = |abc-123|.

IF lv_test CP '*-*'.
  WRITE: / '- in der Mitte.'.
ELSE.
  WRITE: / 'kein - in der Mitte'.
ENDIF.

* Variante 2 (bestimmtes Zeichen)
DATA(lv_test) = |abc-123|.

IF lv_test CP 'ABC-*'.
  WRITE: / 'Schema ABC-XXX'.
ELSE.
  WRITE: / 'kein Schema ABC-XXX'.
ENDIF.

* Variante 3 (bestimmtes Zeichen)
DATA(lv_test) = |abc-1234|.

IF lv_test CP '+++-+++'.
  WRITE: / 'Schema XXX-XXX'.
ELSE.
  WRITE: / 'kein Schema XXX-XXX'.
ENDIF.

[ABAP] Fixkontentabelle (T030) auslesen

* Kontenplan
DATA: lv_ktopl TYPE ktopl.
* Vorgangsschlüssel
DATA: lv_ktosl TYPE ktosl.
* Bewertungsmodifikationskonstante
DATA: lv_bwmod TYPE bwmod.
* Konto-Modifikation
DATA: lv_komok TYPE komok.
* Bewertungsklasse
DATA: lv_bklas TYPE bklas.
* Nummer des Sachkontos
DATA: lv_konts TYPE saknr.
* Nummer des Sachkontos
DATA: lv_konth TYPE saknr.

SELECT-OPTIONS: so_ktopl FOR lv_ktopl.
SELECT-OPTIONS: so_ktosl FOR lv_ktosl.
SELECT-OPTIONS: so_bwmod FOR lv_bwmod.
SELECT-OPTIONS: so_komok FOR lv_komok.
SELECT-OPTIONS: so_bklas FOR lv_bklas.
SELECT-OPTIONS: so_konts FOR lv_konts.
SELECT-OPTIONS: so_konth FOR lv_konts.

START-OF-SELECTION.

* T030 (Fixkontentabelle)
  SELECT *
    INTO TABLE @DATA(it_t030)
    FROM t030
    WHERE ktopl IN @so_ktopl.
*      ktosl IN @so_ktosl
*      bwmod IN @so_bwmod
*      komok IN @so_komok
*      bklas IN @so_bklas
*      konts IN @so_konts
*      konth IN @so_konth.

  IF sy-subrc = 0.
    TRY.
        DATA: o_salv TYPE REF TO cl_salv_table.

        cl_salv_table=>factory( EXPORTING
                                  r_container  = cl_gui_container=>default_screen
                                IMPORTING
                                  r_salv_table = o_salv
                                CHANGING
                                  t_table      = it_t030 ).

        o_salv->get_display_settings( )->set_striped_pattern( abap_true ).
        o_salv->get_columns( )->set_optimize( abap_true ).
        o_salv->get_functions( )->set_all( ).
        o_salv->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ).
        o_salv->display( ).

        WRITE: / space.
      CATCH cx_root INTO DATA(e_text).
        WRITE: / e_text->get_text( ).
    ENDTRY.
  ENDIF.

[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] Felder im Selektionsbild manuell setzen

DATA: pernr TYPE persno.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE title.

PARAMETERS: pa_bukrs TYPE pa0001-bukrs.
SELECT-OPTIONS: so_pernr FOR pernr.

TYPES: ty_it_screen TYPE STANDARD TABLE OF screen WITH DEFAULT KEY.
DATA: it_screen TYPE ty_it_screen.

SELECTION-SCREEN END OF BLOCK b1.

INITIALIZATION.

  title = 'Testblock'.

* SCREEN-Felder auslesen
  LOOP AT SCREEN INTO DATA(lv_screen).
    APPEND lv_screen TO it_screen.
  ENDLOOP.

  %_pa_bukrs_%_app_%-text = 'Par'.
  %_so_pernr_%_app_%-text = 'SelOpt'.

START-OF-SELECTION.
*SSCRFIELDS-UCOMM
*TITLE
*%_PA_BUKRS_%_APP_%-TEXT
*PA_BUKRS
*%_SO_PERNR_%_APP_%-TEXT
*%_SO_PERNR_%_APP_%-OPTI_PUSH
*SO_PERNR-LOW
*%_SO_PERNR_%_APP_%-TO_TEXT
*SO_PERNR-HIGH
*%_SO_PERNR_%_APP_%-VALU_PUSH
*%_17SNS0000194656_%_%_%_%_%_%_

* SCREEN-Felder ausgeben
  cl_demo_output=>display_data( it_screen ).

[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.