<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to split a string in byte mode? in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-split-a-string-in-byte-mode/m-p/12441183#M1998712</link>
    <description>&lt;P&gt;Please post the code as text instead of image + use the CODE button to colorize it.&lt;/P&gt;</description>
    <pubDate>Sun, 05 Sep 2021 06:55:08 GMT</pubDate>
    <dc:creator>Sandra_Rossi</dc:creator>
    <dc:date>2021-09-05T06:55:08Z</dc:date>
    <item>
      <title>How to split a string in byte mode?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-split-a-string-in-byte-mode/m-p/12441182#M1998711</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
  &lt;P&gt;In Japanese, there are haft-width character( 1 byte ) and full-width character( 2 byte ) and my customer has a requirement split a string into two strings in byte mode( x=x1+x2 &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; one string length is x1 bytes and the other string length is x2 bytes. Like '&lt;STRONG&gt;ｲｳ&lt;/STRONG&gt;&lt;STRONG&gt;城ｲｳ会ｶ株&lt;/STRONG&gt;' in this example:&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1971690-out-01.png" /&gt;&lt;/P&gt;
  &lt;P&gt;I've resolved this requirement as below program:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;CONSTANTS:
  GCF_BYTE_CUT TYPE INT1 VALUE 6. "x1
DATA:
    GDF_TEXT          TYPE AD_NAME2,    
    GDF_COUNT_BYTE    TYPE INT1,
    GDF_TEMP_BYTE     TYPE INT1,
    GDF_RESULT1_LENG  TYPE INT1,
    GDF_RESULT2_LENG  TYPE INT1,
    GDF_RESULT1       TYPE ZZSHIPTO_NAME2,
    GDF_RESULT2       TYPE ZZSHIPTO_NAME3
    .

GDF_TEXT = 'ｲｳ城ｲｳ会ｶ株'.   "Contains half and full-width CJK character

PERFORM GET_TEXT_BYTE USING    GDF_TEXT
                      CHANGING GDF_COUNT_BYTE.

IF GDF_COUNT_BYTE &amp;lt;= GCF_BYTE_CUT.         
  GDF_RESULT1 = GDF_TEXT.
ELSE.
  CLEAR GDF_COUNT_BYTE.
  GDF_RESULT1_LENG = GCF_BYTE_CUT / 2.  "Get min index to achive GCF_BYTE_CUT = 6 bytes
  PERFORM GET_TEXT_BYTE USING    GDF_TEXT+0(GDF_RESULT1_LENG)
                        CHANGING GDF_COUNT_BYTE.

  WHILE GDF_COUNT_BYTE &amp;lt; GCF_BYTE_CUT.
    PERFORM GET_TEXT_BYTE USING    GDF_TEXT+GDF_RESULT1_LENG(1)
                          CHANGING GDF_TEMP_BYTE.
    GDF_COUNT_BYTE   = GDF_COUNT_BYTE + GDF_TEMP_BYTE.
    GDF_RESULT1_LENG = GDF_RESULT1_LENG + 1.
  ENDWHILE.

  IF GDF_COUNT_BYTE = GCF_BYTE_CUT.      "When exists 6 bytes
    GDF_RESULT1     = GDF_TEXT+0(GDF_RESULT1_LENG).
  ELSEIF GDF_COUNT_BYTE &amp;gt; GCF_BYTE_CUT.  "When only exists 5 or 7 bytes
    GDF_RESULT1_LENG = GDF_RESULT1_LENG - 1.  "Set index to split string is 5 bytes
    GDF_RESULT1      = GDF_TEXT+0(GDF_RESULT1_LENG).
  ENDIF.

  GDF_RESULT2_LENG = STRLEN( GDF_TEXT ) - GDF_RESULT1_LENG.
  GDF_RESULT2      = GDF_TEXT+GDF_RESULT1_LENG(GDF_RESULT2_LENG).
ENDIF.

WRITE / : GDF_RESULT1, CL_ABAP_LIST_UTILITIES=&amp;gt;DYNAMIC_OUTPUT_LENGTH( GDF_RESULT1 ),
          GDF_RESULT2, CL_ABAP_LIST_UTILITIES=&amp;gt;DYNAMIC_OUTPUT_LENGTH( GDF_RESULT2 ).
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  GET_TEXT_BYTE
*&amp;amp;---------------------------------------------------------------------*
*      Get byte of a string
*----------------------------------------------------------------------*
*      --&amp;gt;PVF_TEXT
*      &amp;lt;--PRF_BYTE
*----------------------------------------------------------------------*
FORM GET_TEXT_BYTE  USING    PVF_TEXT  TYPE ANY
                    CHANGING PRF_BYTE  TYPE INT1.
  CLEAR PRF_BYTE.
  PRF_BYTE = CL_ABAP_LIST_UTILITIES=&amp;gt;DYNAMIC_OUTPUT_LENGTH(
                FIELD  =  PVF_TEXT
             ).
ENDFORM.                    " GET_TEXT_BYTE
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;But I know my solution is not really good in performance. Is there another solution?&lt;/P&gt;
  &lt;P&gt;Best regards,&lt;/P&gt;
  &lt;P&gt;LeoVu.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Sep 2021 03:55:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-split-a-string-in-byte-mode/m-p/12441182#M1998711</guid>
      <dc:creator>QuyVu</dc:creator>
      <dc:date>2021-09-05T03:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string in byte mode?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-split-a-string-in-byte-mode/m-p/12441183#M1998712</link>
      <description>&lt;P&gt;Please post the code as text instead of image + use the CODE button to colorize it.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Sep 2021 06:55:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-split-a-string-in-byte-mode/m-p/12441183#M1998712</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2021-09-05T06:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string in byte mode?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-split-a-string-in-byte-mode/m-p/12441184#M1998713</link>
      <description>&lt;P&gt;Hi Sandra,&lt;/P&gt;&lt;P&gt;Thanks for your advice. I've updated this QA.&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;LeoVu.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Sep 2021 07:55:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-split-a-string-in-byte-mode/m-p/12441184#M1998713</guid>
      <dc:creator>QuyVu</dc:creator>
      <dc:date>2021-09-05T07:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string in byte mode?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-split-a-string-in-byte-mode/m-p/12441185#M1998714</link>
      <description>&lt;P&gt;Thanks a lot, easier to test your code to understand what you want to achieve.&lt;/P&gt;&lt;P&gt;The issue is that you are mixing several notions which have different meanings. Bytes are places in memory, but what your code shows is that you are talking about CJK (Chinese, Japanese, Korean) characters displayed on two positions in ABAP lists.&lt;/P&gt;&lt;P&gt;Now, concerning your code, I don't understand why you do it so complex, this one-line program does exactly the same! Maybe I don't understand what you're trying to achieve.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;WRITE / : 'ab城ｲｳ', CL_ABAP_LIST_UTILITIES=&amp;gt;DYNAMIC_OUTPUT_LENGTH( 'ab城ｲｳ' ),&lt;BR /&gt;          '会ｶ株', CL_ABAP_LIST_UTILITIES=&amp;gt;DYNAMIC_OUTPUT_LENGTH( '会ｶ株' ).&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Sep 2021 09:09:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-split-a-string-in-byte-mode/m-p/12441185#M1998714</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2021-09-05T09:09:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string in byte mode?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-split-a-string-in-byte-mode/m-p/12441186#M1998715</link>
      <description>&lt;P&gt;Hi Sandra,&lt;/P&gt;&lt;P&gt;Thank you for your support.&lt;/P&gt;&lt;P&gt;I've updated for input data in this question. Sorry for this inconvenience.&lt;/P&gt;&lt;P&gt;But my aim in this question is to improve performance main processing instead of displaying result:&lt;/P&gt; 
&lt;PRE&gt;&lt;CODE&gt;GDF_TXT_LENGTH = STRLEN( GDF_TEXT ).
GDF_MIN_CHAR  = GCF_NUM_BYTE / 2.


IF GDF_TXT_LENGTH &amp;lt;= GDF_MIN_CHAR.
  GDF_RESULT1 = GDF_TEXT.
ELSE.
  PERFORM GET_TEXT_BYTE USING    GDF_TEXT+0(GDF_MIN_CHAR)
                        CHANGING GDF_COUNT_BYTE.
  IF GDF_COUNT_BYTE &amp;lt; GCF_NUM_BYTE.
    DO.
      IF GDF_COUNT_BYTE &amp;gt;= GCF_NUM_BYTE OR GDF_MIN_CHAR &amp;gt; GDF_TXT_LENGTH.
        GDF_RESULT1 = GDF_TEXT+0(GDF_MIN_CHAR).
        EXIT.
      ENDIF.
      PERFORM GET_TEXT_BYTE USING    GDF_TEXT+GDF_MIN_CHAR(1)
                            CHANGING GDF_COUNT_TEMP.
      GDF_COUNT_BYTE = GDF_COUNT_BYTE + GDF_COUNT_TEMP.
      GDF_MIN_CHAR = GDF_MIN_CHAR + 1.
    ENDDO.
  ELSE.
    GDF_RESULT1 = GDF_TEXT+0(GDF_MIN_CHAR).
  ENDIF.
ENDIF.


IF GDF_MIN_CHAR &amp;lt; GDF_TXT_LENGTH.
  GDF_NUMC_RESULT2 = GDF_TXT_LENGTH - GDF_MIN_CHAR. "x2
  GDF_RESULT2 = GDF_TEXT+GDF_MIN_CHAR(GDF_NUMC_RESULT2).
ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;LeoVu.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Sep 2021 09:52:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-split-a-string-in-byte-mode/m-p/12441186#M1998715</guid>
      <dc:creator>QuyVu</dc:creator>
      <dc:date>2021-09-05T09:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string in byte mode?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-split-a-string-in-byte-mode/m-p/12441187#M1998716</link>
      <description>&lt;P&gt;To help you improve the performance, I must first understand what you want to achieve, but sorry, I can't. I improved your algorithm by removing all the lines of your code, and keep only one.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Sep 2021 11:11:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-split-a-string-in-byte-mode/m-p/12441187#M1998716</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2021-09-05T11:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string in byte mode?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-split-a-string-in-byte-mode/m-p/12441188#M1998717</link>
      <description>&lt;P&gt;Hi Sandra,&lt;/P&gt;&lt;P&gt;Thank you for your continued support. &lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;LeoVu&lt;/P&gt;</description>
      <pubDate>Tue, 07 Sep 2021 08:40:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-split-a-string-in-byte-mode/m-p/12441188#M1998717</guid>
      <dc:creator>QuyVu</dc:creator>
      <dc:date>2021-09-07T08:40:47Z</dc:date>
    </item>
  </channel>
</rss>

