Skip to Content
0

Offset for Double Width Japanese Characters

Oct 03, 2017 at 04:43 AM

67

avatar image

Hello Experts,

I am working with Offsets for Japanese Characters. Below is sample data.

JP34HE38理論健康保険料(総報酬)

Below is the logic that I am using for Splitting the above string:

  "get abap type for the data
  lo_typedescr = cl_abap_typedescr=>describe_by_data( wa_upload_file ).
  lo_structdescr ?= lo_typedescr.
  lt_components_in = lo_structdescr->get_components( ).

  LOOP AT lt_components_in INTO ls_component.
    UNASSIGN <ls_field>.
    ASSIGN COMPONENT ls_component-name OF STRUCTURE wa_upload_file TO <ls_field>.
    IF lv_input_data IS INITIAL.
      lv_input_data = <ls_field>.
    ELSE.
      CONCATENATE lv_input_data <ls_field> INTO lv_input_data.
    ENDIF.
  ENDLOOP.

  CLEAR: lo_typedescr, lo_structdescr.
  lo_typedescr = cl_abap_typedescr=>describe_by_data( wa_kyuyono ).
  lo_structdescr ?= lo_typedescr.
  lt_components_out = lo_structdescr->get_components( ).

  CLEAR: lv_offset, lv_offset_str.
  LOOP AT lt_components_out INTO ls_component.
    l_tabix = sy-tabix.
    CLEAR: lo_elemdescr, lv_offset_data.
      lo_elemdescr ?= ls_component-type.
      IF lo_elemdescr->type_kind EQ 'D'.
        l_length = '8'.
      ELSE.
        l_length = lo_elemdescr->output_length.
      ENDIF.

        cl_abap_list_utilities=>read_from_display_layout(
                                          EXPORTING
                                            display_data   = lv_input_data
                                            display_offset = lv_total_offset
                                            display_length = l_length
                                          IMPORTING
                                            field = lv_offset_data ).
  
      lv_offset = l_length.
      ADD lv_offset TO lv_total_offset.
      "assign data to structure
      UNASSIGN <ls_field>.
      ASSIGN COMPONENT ls_component-name OF STRUCTURE wa_kyuyono TO <ls_field>.
      IF <ls_field> IS ASSIGNED.
        <ls_field> = lv_offset_data.
      ENDIF.
    ENDIF.
  ENDLOOP.

Below is how it should split,

Var1 is 4 Character, Var2 is 3 Character, Var3 is 1 Character, and Var4 is 20 Character.

Issue:

Var4 is 20 Character. However, the method cl_abap_list_utilities=>read_from_display_layout returns only 10 Characters. This is because the character width occupied is more than 20.

How can we work with Offset for these type of Characters? Suppose, if we have another variable, then this would be an issue.

Thanks in advance!

BR,
Kiran Kerudi

10 |10000 characters needed characters left characters exceeded

I see nowhere how the ABAP list intervenes in your code. It seems that you are just transferring the data from a file into a variable.

Please explain the context, what are you trying to achieve? (more details than just "splitting")

0

Hi Sandra,

Yes, I am transferring Fixed Length File Data (SJIS File) with GUI_UPLOAD FMs. The above program was just for reference to the context of Offsetting.

Best Regards,

Kiran

0

Why don't you simply read the file by using the code page 8000 ? (SJIS)

0

Without using code page 8000 I would not be able to read SJIS File. So its already in place.

Here, the issue is not about the file. I have contents already in the internal table.

0

That was the goal of my initial question, to know what you are trying to achieve. So, your problem is not about reading the file, but about transferring WA_UPLOAD_FILE to WA_KYUYONO.

As you have a Unicode system, every Japanese character is one character (2 bytes), so WA_UPLOAD_FILE+8(20) will take 20 characters, i.e. 20 Japanese characters for instance or 20 any kind of characters, so I don't understand your complex algorithm. It seems just useless.

The question is: what is the goal of this transfer?

PS: it's normal that cl_abap_list_utilities=>read_from_display_layout returns 10 characters for Japanese text displayed on 20 columns of an ABAP list. What do you exactly need?

I also tested your code + added the declarations of variables, at the end WA_KYUYONO is equal to WA_UPLOAD_FILE, it's why I said I don't understand what is your goal (compilable code copied here for further discussion):

REPORT.
DATA: BEGIN OF wa_upload_file, var1(4), var2(3), var3(1), var4(20), END OF wa_upload_file,
      lo_typedescr TYPE REF TO cl_abap_typedescr,
      lo_structdescr TYPE REF TO cl_abap_structdescr,
      lt_components_in TYPE cl_abap_structdescr=>component_table,
      ls_component TYPE abap_componentdescr,
      lv_input_data TYPE string,
      BEGIN OF wa_kyuyono, var1(4), var2(3), var3(1), var4(20), END OF wa_kyuyono,
      lt_components_out TYPE cl_abap_structdescr=>component_table,
      lv_offset TYPE i,
      lv_offset_str TYPE string,
      l_tabix TYPE sytabix,
      lo_elemdescr TYPE REF TO cl_abap_elemdescr,
      lv_offset_data TYPE string,
      l_length TYPE i,
      lv_total_offset TYPE i.
FIELD-SYMBOLS:
               <ls_field> TYPE any.
wa_upload_file = 'JP34HE38理論健康保険料(総報酬)'.
"get abap type for the data
lo_typedescr = cl_abap_typedescr=>describe_by_data( wa_upload_file ).
lo_structdescr ?= lo_typedescr.
lt_components_in = lo_structdescr->get_components( ).
LOOP AT lt_components_in INTO ls_component.
  UNASSIGN <ls_field>.
  ASSIGN COMPONENT ls_component-name OF STRUCTURE wa_upload_file TO <ls_field>.
  IF lv_input_data IS INITIAL.
    lv_input_data = <ls_field>.
  ELSE.
    CONCATENATE lv_input_data <ls_field> INTO lv_input_data.
  ENDIF.
ENDLOOP.
CLEAR: lo_typedescr, lo_structdescr.
lo_typedescr = cl_abap_typedescr=>describe_by_data( wa_kyuyono ).
lo_structdescr ?= lo_typedescr.
lt_components_out = lo_structdescr->get_components( ).
CLEAR: lv_offset, lv_offset_str.
LOOP AT lt_components_out INTO ls_component.
  l_tabix = sy-tabix.
  CLEAR: lo_elemdescr, lv_offset_data.
  lo_elemdescr ?= ls_component-type.
  IF lo_elemdescr->type_kind EQ 'D'.
    l_length = '8'.
  ELSE.
    l_length = lo_elemdescr->output_length.
  ENDIF.
  cl_abap_list_utilities=>read_from_display_layout(
                                    EXPORTING
                                      display_data   = lv_input_data
                                      display_offset = lv_total_offset
                                      display_length = l_length
                                    IMPORTING
                                      field = lv_offset_data ).
  lv_offset = l_length.
  ADD lv_offset TO lv_total_offset.
  "assign data to structure
  UNASSIGN <ls_field>.
  ASSIGN COMPONENT ls_component-name OF STRUCTURE wa_kyuyono TO <ls_field>.
  IF <ls_field> IS ASSIGNED.
    <ls_field> = lv_offset_data.
  ENDIF.
ENDLOOP.
0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

avatar image
Former Member Oct 03, 2017 at 12:37 PM
0

Hi Kiran,

There are two reasons for this.

First you need to check your SAP environment for encoding and if not use the unicode environment.

Second if you use unicode environment then try by creating a structure of your type.

Use move statement and then I will move the first 4 characters to the first field of structure and so on.

This will solve the multilangual issue.

Regards,

Ankit Mahajan

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Ankit,

My SAP Environment is Unicode. Now since its Unicode all characters are two bytes and they are either half-width or full-width. Japanese characters are full-width. So, for Var4 when we move 8(20), it moves characters that are occupying the full.half-width and not the number of characters.

Best Regards,
Kiran

0
Former Member

Hi Kiaran,

Then I think we have a solution.

Given that the first 8 characters will be EN, we need to move 8(20) which will be Japanease.

We know as in Unicode all characters are eighter half-width of full width.

And for Japanese it will always be of full width.

So instead of 8(20), use 8(40).

0