开发者

How to write structures?

开发者 https://www.devze.com 2023-03-24 06:11 出处:网络
How can I show the value inside a structure? see below the example: DATA: BEGIN OF line, 开发者_StackOverflow社区col1 TYPE i,

How can I show the value inside a structure? see below the example:

DATA: BEGIN OF line,
   开发者_StackOverflow社区     col1 TYPE i,
        col2 TYPE i,
      END OF line.

DATA: itab LIKE TABLE OF line,
      jtab LIKE TABLE OF line.

DO 3 TIMES.
  line-col1 = sy-index.
  line-col2 = sy-index ** 2.
  APPEND line TO itab.
ENDDO.

MOVE itab TO jtab.

line-col1 = 10. line-col2 = 20.
APPEND line TO itab.


IF itab GT jtab.
  WRITE / 'ITAB GT JTAB'.
ENDIF.

Write: itab, jtab.

because i want to know why itab is greater than jtab?.


If you want to see the contents of a field purely for debugging purposes you can also just put a break point in your code and look at the contents in debugger.

Just don't leave the break point in productive code!

break-point. 
"or use break yourusername  <= this use is safer

EDIT: You can also just use a session break-point, which does not require you to change the code (and will only be applicable to your user for the duration of the session):

In the system where you are running the program:

  • Open the Program
  • Select the line that you would like the program to stop on
  • Click the session Break-point button

    How to write structures?

The break-point icon will appear next to the line (you can also just click in the place where the icon appeared, to set/delete the break-point).

How to write structures?


I assume that this is just a quick example and you don't want to use (parts of) this in a productive environment - so I ignore the other potential issues there are in your code.

Down to your question, you need to loop over your itab to access its values. You can then access a value like so:

DATA: ls_current_line LIKE line.
" ...
LOOP AT itab INTO ls_current_line.
  WRITE / ls_current_line-col1.
ENDLOOP.


You could use function module REUSE_ALV_GRID_DISPLAY.

For example:

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  TABLES
    t_outtab = itab.


ITAB is greater than JTAB because it contains more lines; ITAB has 4 lines while JTAB has 3 lines.

When it comes to internal tables, the GT operator first takes a look at the number of lines in the tables. More details on the comparison operators (for internal tables) can be found at http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3841358411d1829f0000e829fbfe/content.htm. [I see that your example is also taken from this help page.]

0

精彩评论

暂无评论...
验证码 换一张
取 消