将Excel文件中检索到的值显示到ALV中

发布于 2024-12-06 15:12:10 字数 2311 浏览 0 评论 0原文

大家好,

我一直在 abap 中尝试练习,那就是通过将 excel 文件中的值检索到内部表中来显示 ALV 中的列数据。我已经尝试调试我的程序有一段时间了,但我似乎无法解决它所指出的错误“字段符号尚未分配”,请指导我。我已经对如何解决这个短转储错误进行了一些研究,但是网上发布的大多数其他问题都是从某些带有列字段的特定表中选择的。我只是想知道也许我的情况与其他人有点不同。

从 Excel 检索值的函数工作正常,我在显示它们时完全没有问题。下面是我构建的代码。

TYPE-POOLS: truxs,
        slis.

TYPES: BEGIN OF t_itab,
      col1 TYPE char20,
      col2 TYPE char20,
      col3 TYPE char20,
      col4 TYPE char20,
      col5 TYPE char20,
   END OF t_itab,
   t_it_itab type STANDARD TABLE OF t_itab.

Data: gt_tab TYPE t_it_itab,
  wa_tab TYPE t_itab,
  g_numrows TYPE i.

PARAMETERS: p_fname TYPE c LENGTH 50.

INITIALIZATION.

AT SELECTION-SCREEN OUTPUT.

AT SELECTION-SCREEN.
AT SELECTION-SCREEN on VALUE-REQUEST FOR p_fname.
DATA: l_filename LIKE  IBIPPARMS-PATH.
CALL FUNCTION 'F4_FILENAME'
 EXPORTING
   PROGRAM_NAME        = SYST-CPROG
   DYNPRO_NUMBER       = '1000'
 IMPORTING
   FILE_NAME           = l_filename
        .
p_fname = l_filename.

START-OF-SELECTION.

DATA: lc_fname TYPE RLGRAP-FILENAME,
  lt_tab TYPE TRUXS_T_TEXT_DATA.

  lc_fname = p_fname.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
  EXPORTING
    I_TAB_RAW_DATA             = lt_tab
    I_FILENAME                 = lc_fname
  TABLES
    I_TAB_CONVERTED_DATA       = gt_tab
  EXCEPTIONS
    CONVERSION_FAILED          = 1
  OTHERS                       = 2
      .
IF SY-SUBRC <> 0.
  WRITE 'Error'.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

" Delete First Row / HEADER
DELETE gt_tab INDEX 1.

IF gt_tab[] is INITIAL.
  MESSAGE 'No Record(s) found' TYPE 'I'.
  EXIT.
ELSE.
  PERFORM DisplayALv.
ENDIF.

FORM DISPLAYALV.
 DATA: l_it_fcat type SLIS_T_FIELDCAT_ALV,
       l_wa_fcat TYPE SLIS_FIELDCAT_ALV.

 l_wa_fcat-fieldname = 'col1'.
 l_wa_fcat-ref_tabname = 'gt_tab'.
 l_wa_fcat-reptext_ddic = 'Column 1'.
 l_wa_fcat-outputlen = '30'.
 APPEND l_wa_fcat TO l_it_fcat.
 CLEAR l_wa_fcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    I_CALLBACK_PROGRAM       = sy-repid
    IT_FIELDCAT              = l_it_fcat
    I_DEFAULT          = 'X'
    I_SAVE             = 'A'
  TABLES
    T_OUTTAB           = gt_tab[].

IF SY-SUBRC <> 0.
  WRITE: 'SY-SUBRC: ', SY-SUBRC .
ENDIF.

ENDFORM.

我的计划中的任何提示、技巧和建议都将受到高度欢迎。提前致谢

Good Day Everyone,

There is this something i've been trying to exercise in abap and that is the Displaying of column datas in ALV by retrieving the values from excel file into an internal table. I've been trying to debug my program for quite some time now and i can't seem to solve the error it's been stating which is "Field symbol has not yet been assigned" please guide me. I already made some research on how to solve this short dump error but most of the other issues posted on the net is selected from some specific table with column fields. I was just wondering that maybe my case is a little bit different from others.

The function that retrieved the values from excel is properly working and i have no problem at all in displaying them.Below is the code i constructed.

TYPE-POOLS: truxs,
        slis.

TYPES: BEGIN OF t_itab,
      col1 TYPE char20,
      col2 TYPE char20,
      col3 TYPE char20,
      col4 TYPE char20,
      col5 TYPE char20,
   END OF t_itab,
   t_it_itab type STANDARD TABLE OF t_itab.

Data: gt_tab TYPE t_it_itab,
  wa_tab TYPE t_itab,
  g_numrows TYPE i.

PARAMETERS: p_fname TYPE c LENGTH 50.

INITIALIZATION.

AT SELECTION-SCREEN OUTPUT.

AT SELECTION-SCREEN.
AT SELECTION-SCREEN on VALUE-REQUEST FOR p_fname.
DATA: l_filename LIKE  IBIPPARMS-PATH.
CALL FUNCTION 'F4_FILENAME'
 EXPORTING
   PROGRAM_NAME        = SYST-CPROG
   DYNPRO_NUMBER       = '1000'
 IMPORTING
   FILE_NAME           = l_filename
        .
p_fname = l_filename.

START-OF-SELECTION.

DATA: lc_fname TYPE RLGRAP-FILENAME,
  lt_tab TYPE TRUXS_T_TEXT_DATA.

  lc_fname = p_fname.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
  EXPORTING
    I_TAB_RAW_DATA             = lt_tab
    I_FILENAME                 = lc_fname
  TABLES
    I_TAB_CONVERTED_DATA       = gt_tab
  EXCEPTIONS
    CONVERSION_FAILED          = 1
  OTHERS                       = 2
      .
IF SY-SUBRC <> 0.
  WRITE 'Error'.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

" Delete First Row / HEADER
DELETE gt_tab INDEX 1.

IF gt_tab[] is INITIAL.
  MESSAGE 'No Record(s) found' TYPE 'I'.
  EXIT.
ELSE.
  PERFORM DisplayALv.
ENDIF.

FORM DISPLAYALV.
 DATA: l_it_fcat type SLIS_T_FIELDCAT_ALV,
       l_wa_fcat TYPE SLIS_FIELDCAT_ALV.

 l_wa_fcat-fieldname = 'col1'.
 l_wa_fcat-ref_tabname = 'gt_tab'.
 l_wa_fcat-reptext_ddic = 'Column 1'.
 l_wa_fcat-outputlen = '30'.
 APPEND l_wa_fcat TO l_it_fcat.
 CLEAR l_wa_fcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    I_CALLBACK_PROGRAM       = sy-repid
    IT_FIELDCAT              = l_it_fcat
    I_DEFAULT          = 'X'
    I_SAVE             = 'A'
  TABLES
    T_OUTTAB           = gt_tab[].

IF SY-SUBRC <> 0.
  WRITE: 'SY-SUBRC: ', SY-SUBRC .
ENDIF.

ENDFORM.

Any tips, tricks and advice in my program would be highly sought. Thanks in Advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枫以 2024-12-13 15:12:10

您使用的类型未在数据字典中定义。创建 ALV fieldcat 时需要采用不同的方法。试试这个:

l_wa_fcat-fieldname = 'COL1'.
l_wa_fcat-inttype = 'C'.
l_wa_fcat-outputlen = '30'.
l_wa_fcat-text_fieldname = 'Column 1'.
l_wa_fcat-seltext_s = 'Column 1'.

另外请确保输入的字段名称值使用大写字母。

You're using a type which is not defined in the data dictionary. This requires a different approach when creating the ALV fieldcat. Try this:

l_wa_fcat-fieldname = 'COL1'.
l_wa_fcat-inttype = 'C'.
l_wa_fcat-outputlen = '30'.
l_wa_fcat-text_fieldname = 'Column 1'.
l_wa_fcat-seltext_s = 'Column 1'.

Also make sure you enter the fieldname value with capitalized letters.

土豪 2024-12-13 15:12:10

我不是 ABAP 专家,但我注意到您发布的代码中的两件事:

  • 您说错误是“尚未分配字段符号”,但您的代码中没有字段符号。也许它在您调用的功能模块之一内使用。如果是这样,请尝试发布错误弹出位置的代码;
  • 你使用 gt_tab[] ,如果我没记错的话,这是访问带有标题行的内部表主体的方法。在您的代码中 gt_tab 不是带有标题行的内部表,但您使用它来存储带有函数 'TEXT_CONVERT_XLS_TO_SAP' 的内部表;

尝试发布生成错误的代码。

问候,
塞尔吉乌

I'm no ABAP expert but I noticed 2 things in the code you posted:

  • you said the error is "Field symbol has not yet been assigned" but you have no field symbol in your code. Maybe it's used inside one of the function modules you call. If so, try to post the code where the error pops up;
  • you use gt_tab[] which, if I remember well, is the way to access the body of an internal table with header line. In your code gt_tab is not an internal table with header line, but you use it to store one with function 'TEXT_CONVERT_XLS_TO_SAP' ;

Try to post the code where the error is being generated.

Regards,
Sergiu

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文