Friday, February 15, 2013

Text value with include text on same line in SAPScripts


Using Subrotine pool we can solve the issue.

Write the code in SAPScripts
/: PERFORM TEST IN PROGRAM ZTEST_XML
/: USING &T166A-TXNAM&
/: USING &T166A-TDOBJECT&
/: USING &T166A-TDID&
/: CHANGING &DES&
/: ENDPERFORM
*              &DES&

*Create a Report
REPORT  ztest_xml.
DATA: lv_name      TYPE thead-tdname.
DATA ls_input TYPE itcsy.
DATA ls_output TYPE itcsy.
DATA : c_id     TYPE thead-tdid,
       c_object TYPE thead-tdobject,
       lt_line TYPE TABLE OF tline,
       ls_line TYPE tline.

*&---------------------------------------------------------------------*
*&      Form  TEST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->INPUT      text
*      -->OUTPUT     text
*----------------------------------------------------------------------*
FORM test TABLES input STRUCTURE itcsy output STRUCTURE itcsy.

  READ TABLE input INTO ls_input  WITH KEY name = 'T166A-TXNAM'.
  lv_name = ls_input-value.
  READ TABLE input INTO ls_input  WITH KEY name = 'T166A-TDID'.
  c_id = ls_input-value.
  READ TABLE input INTO ls_input  WITH KEY name = 'T166A-TDOBJECT'.
  c_object = ls_input-value.

* Get long text
  CALL FUNCTION 'READ_TEXT'
    EXPORTING
      id                      = c_id
      language                = sy-langu
      name                    = lv_name
      object                  = c_object
    TABLES
      lines                   = lt_line
    EXCEPTIONS
      id                      = 1
      language                = 2
      name                    = 3
      not_found               = 4
      object                  = 5
      reference_check         = 6
      wrong_access_to_archive = 7
      OTHERS                  = 8.
  DATA lv_long_text TYPE string.
  LOOP AT lt_line INTO ls_line.
    CONCATENATE  ls_line-tdline lv_long_text INTO lv_long_text
    SEPARATED BY space.
    CLEAR ls_line.
  ENDLOOP.
  CONCATENATE 'Text you want:' lv_long_text INTO lv_long_text
  SEPARATED BY space.
  READ TABLE output INTO ls_output  WITH KEY name = 'DES'.

  IF sy-subrc = 0.
    ls_output-value = lv_long_text.
    MODIFY output FROM ls_output INDEX 1.
  ENDIF.
ENDFORM.                    "TEST

Note: Check the text length.