ABAP开发:如何在Loop循环中访问嵌套内表字段fstyl-style?
Hey there! Let's sort out how to correctly access the style field in your fstyl table. The key issue here is that fstyl is defined as an internal table (lvc_t_styl is a standard table type for ALV cell styles), not a single structure—so you can't directly reference wa_main-fstyl-style like you would with a regular field.
Here are two common ways to handle this, depending on your use case:
1. Loop through all style entries in each main record
If each ty_main entry might have multiple style records, you'll need to nest a loop to iterate through the fstyl table inside your main loop:
TYPES: BEGIN OF ty_main, bukrs LIKE bseg-bukrs, fstyl TYPE lvc_t_styl, END OF ty_main. DATA: it_main TYPE TABLE OF ty_main, wa_main LIKE LINE OF it_main, wa_fstyl LIKE LINE OF wa_main-fstyl. " Work area for the style table entries LOOP AT it_main INTO wa_main. " Loop through the style table inside each main record LOOP AT wa_main-fstyl INTO wa_fstyl WHERE style = cl_gui_alv_grid=>mc_style_disabled. " Add your processing logic here (e.g., log, modify, display) WRITE: / wa_main-bukrs, wa_fstyl-style. ENDLOOP. ENDLOOP.
2. Read a single style entry (if only one exists per main record)
If you're sure each ty_main entry has exactly one style record, use READ TABLE to fetch that single entry:
TYPES: BEGIN OF ty_main, bukrs LIKE bseg-bukrs, fstyl TYPE lvc_t_styl, END OF ty_main. DATA: it_main TYPE TABLE OF ty_main, wa_main LIKE LINE OF it_main, wa_fstyl LIKE LINE OF wa_main-fstyl. LOOP AT it_main INTO wa_main. " Read the first (and only) entry from the style table READ TABLE wa_main-fstyl INTO wa_fstyl INDEX 1. IF sy-subrc = 0 AND wa_fstyl-style = cl_gui_alv_grid=>mc_style_disabled. " Your processing logic here WRITE: / wa_main-bukrs, wa_fstyl-style. ENDIF. ENDLOOP.
A quick reminder: lvc_t_styl is based on the structure lvc_s_styl, which includes fields like style, fieldname, and row_id. You always need to work with individual entries of this internal table—you can't access fields directly from the table itself.
内容的提问来源于stack exchange,提问作者ekekakos

