简体   繁体   中英

"MOVE" works for literal but doesn't for internal table

I am working on automation reports in SAP and I can't input the value of gt_output3-namev to gt_output-namev01 .

It works when I move only a string literal ('1' is set).

It doesn't work when I move gt_output3-namev (remains empty).

How can I fix that? Thanks

I tried debugging and I can see the value from gt_output3-namev is not written in gt_output-namev01 .

SELECT
      knvk~lifnr, knvk~namev, knvk~name1, knvk~titel_ap, knvk~telf1, knvk~abtnr
    FROM knvk
    WHERE  knvk~lifnr = @lv_lifnr AND knvk~abtnr = '0002'
    INTO TABLE @gt_output3.

  IF sy-subrc = '0'.
    MOVE gt_output3-namev TO gt_output-namev01. ---> doesn't work
    MOVE '1' TO gt_output-name101. ---> works
    MOVE '1' TO gt_output-titel_ap01.
    MOVE '1' TO gt_output-telf101.
    MOVE '1' TO gt_output-smtp_addr01.
  ENDIF.

  APPEND gt_output TO gt_final.

gt_output3 is a table with header line

This means you have a table and a structure with the same name. It is quite convenient, but obsolete now , as it led to many confusions.

It contains values as a table because of the SELECT, but in your case gt_output3 was never given value as a structure . This causes the problem with the MOVE (note: Moves are obsolete now too, use = instead):

MOVE gt_output3-namev TO gt_output-namev01.

You can get the values of gt_output3 by LOOPing through the table for example:

LOOP AT gt_output3 ASSIGNING FIELD-SYMBOL(<ls_output3>). 
  gt_output-namev01 = <ls_output3>-namev.

Caution: gt_output is considered here as a structure, not as an internal table (which is wrongly guessed from its naming convention). Probably you have defined it also as an internal table with a header line, so better remove the header line and declare/work with a separate structured variable ( data gs_output like line of gt_output and gs_output-namev01 ... for instance).

If you have ABAP 740 or newer, you can access rows directly by row number, for example to access the first row:

gt_output-namev01 = gt_output3[ 1 ]-namev.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM