Advertisement
depth1

SmartForm Multi-language

Feb 20th, 2019
1,116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 5.94 KB | None | 0 0
  1. * -----------------------------------------------------------------
  2. * GLOBAL DEFINITIONS
  3. * -----------------------------------------------------------------
  4. GS_TXT_L1   TYPE    TY_TXT
  5. GS_TXT_L2   TYPE    TY_TXT
  6.  
  7. * -----------------------------------------------------------------
  8. * TYPES DEFINITIONS
  9. * -----------------------------------------------------------------
  10. TYPES:
  11.   BEGIN OF ty_txt,
  12.     lang     TYPE sy-langu,
  13.     txt_1    TYPE tdline,
  14.     txt_2    TYPE tdline,
  15.     txt_3    TYPE tdline,
  16.     txt_4    TYPE tdline,
  17.     txt_5    TYPE tdline,
  18.     txt_6    TYPE tdline,
  19.     txt_7    TYPE tdline,
  20.     txt_8    TYPE tdline,
  21.     txt_9    TYPE tdline,
  22.     txt_10   TYPE tdline,
  23.     txt_11   TYPE tdline,
  24.     txt_12   TYPE tdline,
  25.     txt_13   TYPE tdline,
  26.     txt_14   TYPE tdline,
  27.     txt_15   TYPE tdline,
  28.     txt_16   TYPE tdline,
  29.     txt_17   TYPE tdline,
  30.     txt_18   TYPE tdline,
  31.     txt_19   TYPE tdline,
  32.     txt_20   TYPE tdline,
  33.     txt_21   TYPE tdline,
  34.     txt_22   TYPE tdline,
  35.     txt_23   TYPE tdline,
  36.     txt_24   TYPE tdline,
  37.     txt_25   TYPE tdline,
  38.     txt_26   TYPE tdline,
  39.     txt_27   TYPE tdline,
  40.     txt_28   TYPE tdline,
  41.     txt_29   TYPE tdline,
  42.     txt_30   TYPE tdline,
  43.     txt_31   TYPE tdline,
  44.     txt_32   TYPE tdline,
  45.     txt_33   TYPE tdline,
  46.     txt_34   TYPE tdline,
  47.     txt_35   TYPE tdline,
  48.     txt_36   TYPE tdline,
  49.     txt_37   TYPE tdline,
  50.     txt_38   TYPE tdline,
  51.     txt_39   TYPE tdline,
  52.     txt_40   TYPE tdline,
  53.     txt_41   TYPE tdline,
  54.     txt_42   TYPE tdline,
  55.     txt_43   TYPE tdline,
  56.     txt_44   TYPE tdline,
  57.     txt_45   TYPE tdline,
  58.     txt_46   TYPE tdline,
  59.     txt_47   TYPE tdline,
  60.     txt_48   TYPE tdline,
  61.     txt_49   TYPE tdline,
  62.     txt_50   TYPE tdline,
  63.     txt_51   TYPE tdline,
  64.     txt_52   TYPE tdline,
  65.     txt_53   TYPE tdline,
  66.     txt_54   TYPE tdline,
  67.     txt_55   TYPE tdline,
  68.     txt_56   TYPE tdline,
  69.     txt_57   TYPE tdline,
  70.     txt_58   TYPE tdline,
  71.     txt_59   TYPE tdline,
  72.     txt_60   TYPE tdline,
  73.     txt_61   TYPE tdline,
  74.     txt_62   TYPE tdline,
  75.     txt_63   TYPE tdline,
  76.     txt_64   TYPE tdline,
  77.     txt_65   TYPE tdline,
  78.     txt_66   TYPE tdline,
  79.     txt_67   TYPE tdline,
  80.     txt_68   TYPE tdline,
  81.     txt_69   TYPE tdline,
  82.     txt_70   TYPE tdline,
  83.     txt_71   TYPE tdline,
  84.     txt_72   TYPE tdline,
  85.     txt_73   TYPE tdline,
  86.     txt_74   TYPE tdline,
  87.     txt_75   TYPE tdline,
  88.     txt_76   TYPE tdline,
  89.     txt_77   TYPE tdline,
  90.     txt_78   TYPE tdline,
  91.     txt_79   TYPE tdline,
  92.     txt_80   TYPE tdline,
  93.     txt_81   TYPE tdline,
  94.     txt_82   TYPE tdline,
  95.     txt_83   TYPE tdline,
  96.     txt_84   TYPE tdline,
  97.     txt_85   TYPE tdline,
  98.     txt_86   TYPE tdline,
  99.     txt_87   TYPE tdline,
  100.     txt_88   TYPE tdline,
  101.     txt_89   TYPE tdline,
  102.     txt_90   TYPE tdline,
  103.     txt_91   TYPE tdline,
  104.     txt_92   TYPE tdline,
  105.     txt_93   TYPE tdline,
  106.     txt_94   TYPE tdline,
  107.     txt_95   TYPE tdline,
  108.     txt_96   TYPE tdline,
  109.     txt_97   TYPE tdline,
  110.     txt_98   TYPE tdline,
  111.     txt_99   TYPE tdline,
  112.   END OF ty_txt.
  113.  
  114. * -----------------------------------------------------------------
  115. * INITIALIZATION
  116. * -----------------------------------------------------------------
  117. PERFORM load_static_txt
  118.   USING
  119.     'TEXTMODULE_NAME'
  120.     iv_lang_1
  121.     iv_lang_2
  122.   CHANGING
  123.     gs_txt_l1
  124.     gs_txt_l2.
  125.  
  126. * -----------------------------------------------------------------
  127. * FORM ROUTINES
  128. * -----------------------------------------------------------------
  129. FORM load_static_txt
  130.               USING
  131.                 iv_name   TYPE tdsfname
  132.                 iv_l1     TYPE spras
  133.                 iv_l2     TYPE spras
  134.               CHANGING
  135.                 es_txt_l1 TYPE ty_txt
  136.                 es_txt_l2 TYPE ty_txt.
  137.  
  138.   DATA:
  139.     ls_l1 TYPE ssfrlang,
  140.     ls_l2 TYPE ssfrlang,
  141.     lv_l1 TYPE spras,
  142.     lv_l2 TYPE spras.
  143.  
  144.   DATA:
  145.     lt_line_l1 TYPE tsftext,
  146.     lt_line_l2 TYPE tsftext,
  147.     ls_line    TYPE tline.
  148.  
  149.   DATA:
  150.     lv_line_l1_size TYPE i,
  151.     lv_line_l2_size TYPE i,
  152.     lv_index        TYPE i.
  153.  
  154.   FIELD-SYMBOLS :
  155.     <fs_field> TYPE any.
  156.  
  157.   ls_l1-langu1 = iv_l1.
  158.   ls_l1-langu2 = 'E'.
  159.  
  160.   IF iv_l2 EQ iv_l1.
  161.     ls_l2-langu1 = 'E'.
  162.   ELSE.
  163.     ls_l2-langu1 = iv_l2.
  164.     ls_l2-langu2 = 'E'.
  165.   ENDIF.
  166.  
  167.   CALL FUNCTION 'SSFRT_READ_TEXTMODULE'
  168.     EXPORTING
  169.       i_textmodule       = iv_name
  170.       i_languages        = ls_l1
  171.     IMPORTING
  172.       o_langu            = lv_l1
  173.       o_text             = lt_line_l1
  174.     EXCEPTIONS
  175.       error              = 1
  176.       language_not_found = 2
  177.       OTHERS             = 3.
  178.   IF sy-subrc <> 0.
  179. * Implement suitable error handling here
  180.   ENDIF.
  181.  
  182.   CALL FUNCTION 'SSFRT_READ_TEXTMODULE'
  183.     EXPORTING
  184.       i_textmodule       = iv_name
  185.       i_languages        = ls_l2
  186.     IMPORTING
  187.       o_langu            = lv_l2
  188.       o_text             = lt_line_l2
  189.     EXCEPTIONS
  190.       error              = 1
  191.       language_not_found = 2
  192.       OTHERS             = 3.
  193.   IF sy-subrc <> 0.
  194. * Implement suitable error handling here
  195.   ENDIF.
  196.  
  197.   es_txt_l1-lang = lv_l1.
  198.   es_txt_l2-lang = lv_l2.
  199.  
  200.   DESCRIBE TABLE:
  201.     lt_line_l1 LINES lv_line_l1_size,
  202.     lt_line_l2 LINES lv_line_l2_size.
  203.  
  204.   IF lv_line_l1_size <> lv_line_l2_size.
  205.     " TODO
  206.   ENDIF.
  207.  
  208.   WHILE lv_index LE lv_line_l1_size.
  209.     ADD 1 TO lv_index.
  210.  
  211.     UNASSIGN:
  212.       <fs_field>.
  213.  
  214.     CLEAR:
  215.       ls_line.
  216.  
  217.     READ TABLE lt_line_l1 INTO ls_line INDEX lv_index.
  218.     CHECK sy-subrc EQ 0.
  219.  
  220.     ASSIGN COMPONENT |txt_{ lv_index }| OF STRUCTURE es_txt_l1 TO <fs_field>.
  221.  
  222.     <fs_field> = ls_line-tdline.
  223.  
  224.     "---------------------------------------------------
  225.     UNASSIGN:
  226.       <fs_field>.
  227.  
  228.     CLEAR:
  229.       ls_line.
  230.  
  231.     IF lv_l1 <> lv_l2.
  232.       READ TABLE lt_line_l2 INTO ls_line INDEX lv_index.
  233.       CHECK sy-subrc EQ 0.
  234.  
  235.       ASSIGN COMPONENT |txt_{ lv_index }| OF STRUCTURE es_txt_l2 TO <fs_field>.
  236.  
  237.       <fs_field> = ls_line-tdline.
  238.     ENDIF.
  239.  
  240.   ENDWHILE.
  241. ENDFORM.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement