SAP ABAP TEXT
From SapWiki
Contents
Cuadro de texto en dynpro ( Clase cl_gui_textedit )
REPORT ytest_texto. *--------------------------------------------------------------------* * Datos para cuadro de texto *--------------------------------------------------------------------* *Variables extras Control Custom DATA: container TYPE REF TO cl_gui_custom_container, editor TYPE REF TO cl_gui_textedit. DATA: line TYPE tdline, text_tab type STANDARD TABLE OF TDLINE. ********************************************************************** DATA ok_code TYPE sy-ucomm. START-OF-SELECTION. line = 'Hola Mundo'. append line to text_tab. CALL SCREEN 0100. *&---------------------------------------------------------------------* *& Module STATUS_0100 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'STATUS'. "Crear con 'BACK' 'EXIT' 'CANC' de tipo comando exit y 'SAVE' SET TITLEBAR 'T01'. "Editar Texto ENDMODULE. " STATUS_0100 OUTPUT *&---------------------------------------------------------------------* *& Module EXIT INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE exit INPUT. DATA l_ok_code TYPE sy-ucomm. l_ok_code = ok_code. CLEAR ok_code. CASE l_ok_code. WHEN 'BACK' OR 'EXIT' OR 'CANC'. * free editor de texto CLEAR: text_tab[]. IF editor IS BOUND. FREE editor. CALL METHOD container->free EXCEPTIONS cntl_error = 1 cntl_system_error = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. FREE container. ENDIF. SET SCREEN 0. LEAVE SCREEN. ENDCASE. ENDMODULE. " EXIT INPUT *&---------------------------------------------------------------------* *& Module TEXTO OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE texto OUTPUT. IF editor IS NOT BOUND. * create control container CREATE OBJECT: container EXPORTING container_name = 'CC_01', "crear custom container CC_01 en dynpro 0100 editor EXPORTING parent = container. * show toolbar and statusbar on this screen CALL METHOD editor->set_toolbar_mode EXPORTING toolbar_mode = editor->true. "true(saca la barra de herramienta). CALL METHOD editor->set_statusbar_mode EXPORTING statusbar_mode = editor->false. "true(saca la barra de status). * if f_mode = c_display. * call method editor->set_readonly_mode * exporting * readonly_mode = editor->true. * * endif. * CALL METHOD editor->set_visible * EXPORTING * visible = ' '. * CALL METHOD editor->set_enable_editing_protected * EXPORTING * MODE = 0. ENDIF. CALL METHOD editor->set_text_as_stream EXPORTING text = text_tab. ENDMODULE. " TEXTO OUTPUT MODULE refresh_txt INPUT. CALL METHOD editor->get_text_as_stream IMPORTING text = text_tab. ENDMODULE. *&---------------------------------------------------------------------* *& Module EXIT_0100 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE exit_0100 INPUT. l_ok_code = ok_code. CLEAR ok_code. CASE l_ok_code. WHEN 'SAVE'. BREAK-POINT. PERFORM save. ENDCASE. ENDMODULE. " EXIT_0100 INPUT FORM save. *text data DATA: lt_tlinetab type STANDARD TABLE OF tline, lt_text type STANDARD TABLE OF TDLINE, ls_theader type thead, ls_tlinetab type tline, l_key TYPE tdobname. IF editor IS NOT INITIAL. * cuadro texto CALL METHOD editor->get_text_as_r3table IMPORTING table = lt_text[] EXCEPTIONS error_dp = 1 error_cntl_call_method = 2 error_dp_create = 3 potential_data_loss = 4. CLEAR lt_tlinetab[]. LOOP AT lt_text into data(ls_text). MOVE ls_text TO ls_tlinetab-tdline. APPEND ls_tlinetab to lt_tlinetab. ENDLOOP. ENDIF. ls_theader-tdid = 'Z001'. ls_theader-tdspras = sy-langu. ls_theader-tdname = l_key. ls_theader-tdobject = 'ZMYOBJ'. * CALL FUNCTION 'SAVE_TEXT' * EXPORTING * header = ls_theader * insert = 'X' * savemode_direct = 'X' * IMPORTING ** FUNCTION = SD_FUNCTION * newheader = ls_theader * TABLES * lines = lt_tlinetab * EXCEPTIONS * id = 01 * language = 02 * name = 03 * object = 04. * IF sy-subrc <> 0. ** MESSAGE A017. * ENDIF. ENDFORM.
dynpro 0100
PROCESS BEFORE OUTPUT. MODULE status_0100. MODULE texto. * PROCESS AFTER INPUT. MODULE exit AT EXIT-COMMAND. MODULE refresh_txt. MODULE exit_0100.
Como leer textos de infotipo
Crear/editar objetos de textos y ID
Leer descripción de objeto OM
FM. READ_TEXT
FORM read_text. DATA: lt_tlinetab TYPE STANDARD TABLE OF tline, ls_theader TYPE thead, l_id TYPE thead-tdid, l_name TYPE thead-tdname, l_object TYPE thead-tdobject. l_id = 'Z000'. "obs esp l_object = 'VBBK'. l_name = es_dlv_delnote-hd_gen-deliv_numb. REFRESH lt_tlinetab. CALL FUNCTION 'READ_TEXT' EXPORTING client = sy-mandt id = l_id language = sy-langu name = l_name object = l_object IMPORTING header = ls_theader TABLES lines = lt_tlinetab EXCEPTIONS id = 01 language = 02 name = 03 not_found = 04 object = 05 reference_check = 06 wrong_access_to_archive = 07. ENDFORM.
Tablas STXH & STXL
ejemplo con clase CL_RSTX_TABLE_VIEW=> READ_STXH_INTERNAL & IMPORT_STXL
data: l_stxh type stxh. * Read normal table select single (l_select_fields) from stxh client specified "#EC DBACCESS_OK into corresponding fields of l_stxh where mandt = i_mandt and tdobject = i_tdobject and tdname = i_tdname and tdid = i_tdid and tdspras = i_tdspras. ************************************************* data E_TEXT_LINES type T_TLINE_TABLE. data: begin of l_stxl_id, tdobject type stxl-tdobject, tdname type stxl-tdname, tdid type stxl-tdid, tdspras type stxl-tdspras, end of l_stxl_id. * Read normal table import tline to e_text_lines from database stxl(tx) "#EC DBACCESS_OK client i_mandt id l_stxl_id accepting truncation "important for Unicode->Nonunicode ignoring conversion errors.
ejemplo ID TDOBJECT TEXT TDNAME 1111111111 TDID ST TDSPRAS P
Convertir string a tabla
DATA: lt_lines TYPE STANDARD TABLE OF tline. DATA lv_text_plain TYPE string. lv_text_plain = |Starro hizo su debut original en la década de 1960 en The Brave and the Bold # 28, el número que también presentó| && | a los lectores de cómics a la Liga de la Justicia de América. Mientras que el DCEU y los cómics contemporáneos de| && | DC representan a Darkseid como la amenaza omnipresente que reúne a los héroes más poderosos de la Tierra por primera vez,| && | en el pasado, una estrella de mar psíquica gigante era el único llamado a la acción de Wonder Woman, Aquaman, Flash,| && | Green Lantern y Martian Manhunter (Batman y Superman no podían ser molestados).|. CALL FUNCTION 'VB_CP_CONVERT_STRING_2_ITF' EXPORTING i_string = lv_text_plain TABLES et_table = lt_lines.