[SAP ABAP] - Custome Create/Change Long Text

*&---------------------------------------------------------------------*
*& Report  YO_CC_TEST04
*&
*&---------------------------------------------------------------------*
*& Module : All Module
*&
*&---------------------------------------------------------------------*

REPORT  yo_cc_test04.

PARAMETERS pa_name LIKE stxh-tdname DEFAULT '5625000002',
             pa_id LIKE stxh-tdid DEFAULT 'Y011',
             pa_obj LIKE stxh-tdobject DEFAULT 'VBBK',
             pa_text LIKE tline-tdline.


START-OF-SELECTION.

PERFORM fm_insert_text_single USING pa_name
                                 pa_id
                                 pa_obj
                                 pa_text
                                 'X'.



*&---------------------------------------------------------------------*
*&      Form  fm_insert_text_single
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->FU_NAME    text
*      -->FU_ID      text
*      -->FU_OBJ     text
*      -->FU_TEXT    text
*      -->FU_DELOLD  text
*----------------------------------------------------------------------*
FORM fm_insert_text_single USING fu_name
                                 fu_id
                                 fu_obj
                                 fu_text
                                 fu_delold.

  DATA lv_line_count TYPE i,
         lv_ltxa1 LIKE plpo-ltxa1,
         lv_ltxa2 LIKE plpo-ltxa2,

         lw_stxh LIKE stxh,
         lw_textheader LIKE thead.

  DATA li_text LIKE STANDARD TABLE OF tline WITH HEADER LINE.

  "Check Text
  SELECT SINGLE INTO lw_stxh FROM stxh
     WHERE tdobject fu_obj
       AND tdname   fu_name
       AND tdid     fu_id
       AND tdspras  sy-langu.
  IF sy-subrc 0.

    CALL FUNCTION 'READ_TEXT'
      EXPORTING
        id       fu_id
        language sy-langu
        name     fu_name
        object   fu_obj
      IMPORTING
        header   lw_textheader
      TABLES
        lines    li_text.
  ELSE.
    CALL FUNCTION 'INIT_TEXT'
      EXPORTING
        id       fu_id
        language sy-langu
        name     fu_name
        object   fu_obj
      IMPORTING
        header   lw_textheader
      TABLES
        lines    li_text.
  ENDIF.

  "Insert or Delete Text
  IF fu_delold 'X'.
    REFRESH li_text.
  ENDIF.

  li_text-tdformat '*'.
  li_text-tdline   fu_text.
  APPEND li_text.


  "Save New Long Text
  lw_textheader-tdlinesize 72.
  lw_textheader-tdtxtlines lv_line_count.
  CALL FUNCTION 'SAVE_TEXT'
    EXPORTING
      header          lw_textheader
      savemode_direct 'X'
    TABLES
      lines           li_text.
  IF sy-subrc 0.
    "
  ENDIF.

ENDFORM.                    "fm_insert_text_single

Comments