Long Text example in sap abap
Some time Requirement to give long text in sap abap programming so we can add one container
and behalf of container give long text below logic for long text in pbo include adding below logic
DATA: lv_text2 TYPE char256.
PERFORM gettext.
PERFORM cleartext.
PERFORM setblank.
PERFORM lengthcheck.
lv_text2 = text
FORM gettext .
CALL METHOD text_editor->get_textstream
* EXPORTING
* only_when_modified = FALSE
IMPORTING
text = text
* is_modified =
EXCEPTIONS
error_cntl_call_method = 1
not_supported_by_gui = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
FORM cleartext .
CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
cntl_system_error = 1
cntl_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.
ENDFORM.
FORM setblank .
DATA : lv_blank TYPE string.
CALL METHOD text_editor->set_textstream
EXPORTING
text = lv_blank
EXCEPTIONS
error_cntl_call_method = 1
not_supported_by_gui = 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.
ENDFORM.
FORM lengthcheck .
lv_length = strlen( text ).
IF lv_length > 255.
MESSAGE 'Long Text should be less than 255 no of characters' TYPE 'E'.
CLEAR: text_editor.
ENDIF.
ENDFORM.
and behalf of container give long text below logic for long text in pbo include adding below logic
top include
DATA: line_length TYPE i VALUE 254,
line TYPE i VALUE 35,
editor_container TYPE REF TO cl_gui_custom_container,
text_editor TYPE REF TO cl_gui_textedit,
lv_length TYPE i,
text TYPE string.
line TYPE i VALUE 35,
editor_container TYPE REF TO cl_gui_custom_container,
text_editor TYPE REF TO cl_gui_textedit,
lv_length TYPE i,
text TYPE string.
in PBO MODULE
IF text_editor IS INITIAL .
CREATE OBJECT editor_container
EXPORTING
container_name = 'TEXTEDITOR'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CREATE OBJECT text_editor
EXPORTING
wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
wordwrap_position = line
wordwrap_to_linebreak_mode = cl_gui_textedit=>true
parent = editor_container.
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 METHOD text_editor->set_toolbar_mode
EXPORTING
toolbar_mode = cl_gui_textedit=>false.
CALL METHOD text_editor->set_statusbar_mode
EXPORTING
statusbar_mode = cl_gui_textedit=>false.
ENDIF.
CREATE OBJECT editor_container
EXPORTING
container_name = 'TEXTEDITOR'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CREATE OBJECT text_editor
EXPORTING
wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
wordwrap_position = line
wordwrap_to_linebreak_mode = cl_gui_textedit=>true
parent = editor_container.
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 METHOD text_editor->set_toolbar_mode
EXPORTING
toolbar_mode = cl_gui_textedit=>false.
CALL METHOD text_editor->set_statusbar_mode
EXPORTING
statusbar_mode = cl_gui_textedit=>false.
ENDIF.
DATA: lv_text2 TYPE char256.
PERFORM gettext.
PERFORM cleartext.
PERFORM setblank.
PERFORM lengthcheck.
lv_text2 = text
FORM gettext .
CALL METHOD text_editor->get_textstream
* EXPORTING
* only_when_modified = FALSE
IMPORTING
text = text
* is_modified =
EXCEPTIONS
error_cntl_call_method = 1
not_supported_by_gui = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
FORM cleartext .
CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
cntl_system_error = 1
cntl_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.
ENDFORM.
FORM setblank .
DATA : lv_blank TYPE string.
CALL METHOD text_editor->set_textstream
EXPORTING
text = lv_blank
EXCEPTIONS
error_cntl_call_method = 1
not_supported_by_gui = 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.
ENDFORM.
FORM lengthcheck .
lv_length = strlen( text ).
IF lv_length > 255.
MESSAGE 'Long Text should be less than 255 no of characters' TYPE 'E'.
CLEAR: text_editor.
ENDIF.
ENDFORM.
Comments
Post a Comment