-1
TABLES: VBRK.

DATA: BEGIN OF it_test,
      BUKRS LIKE VBRK-BUKRS,
      FKDAT LIKE VBRK-FKDAT,
END OF it_test.

DATA: wa_test LIKE it_test.


SELECT * FROM VBRK INTO CORRESPONDING FIELD OF wa_test.

IF wa_test-BUKRS = 'xxxx'.
   wa_test-BUKRS = 'XXXXX' "Problem occurs here as the BUKRS allow 4 value
   APPEND wa_test TO it_test.
ENDIF.

Then I want to map the internal table to output as ALV table. Is they any way to change the field length afterwards?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
RamonC
  • 31
  • 7
  • For anyone reading this: This an excellent example of how NOT, under ANY CIRCUMSTANCES, code in ABAP. – vwegert Feb 19 '16 at 08:39
  • 1
    Especially why ? Ok, the Select is silly. But besides ? I agree, that I would not do it, like the op did, though, debug QM and You will see a lot of those stuff.... – icbytes Feb 19 '16 at 09:40
  • Can you give us a more specific example? –  Feb 19 '16 at 09:48
  • @icbytes TABLES is completely unnecessary, SELECT * where only two fields are needed, ENDSELECT missing / deliberately left out, implicit data type declaration in 1980's style. – vwegert Feb 19 '16 at 10:32
  • Does this code compile? The SELECT should be 'SELECT SINGLE ...' or ENDSELECT is missing. – Nelson Miranda Feb 19 '16 at 13:35

3 Answers3

0

Apart from multiple issues in your code, you can't. If you need something similar to that, add an additional field to the structure with whatever size you require and copy the values over.

vwegert
  • 18,371
  • 3
  • 37
  • 55
  • 1
    This is just an example, my real program is without issues. Ya, your suggestion work because in the first place I thought that the ALV fields must output all IT fields. Thanks. – RamonC Feb 19 '16 at 08:47
0

If the objective is to output something to the screen that is different(or differently formatted) that what is stored internally(or in the database), then the use of a data element with a conversion exit maybe the way to go.

For an example, look at the key fields of table PRPS.

Thomas Matecki
  • 629
  • 5
  • 20
0

Expanding the answer of vwegert:

The MOVE-CORRESPONDINGcommand (and SELECT ... INTO CORRESPONDING FIELDS) don't need the same field type. The content is converted. So you could define a 5-character field in your internal structure and copy the BUKRS-value into this 5-character field:

TABLES: VBRK.

DATA: BEGIN OF it_test,
      BUKRS(5), "longer version of VBRK-BUKRS,
      FKDAT LIKE VBRK-FKDAT,
END OF it_test.
DATA: tt_test TYPE STANDARD TABLE OF it_test.

* I would strongly recommend to set a filter!
SELECT * FROM VBRK INTO CORRESPONDING FIELD OF it_test.

  IF it_test-BUKRS = 'xxxx'.
     it_test-BUKRS = 'XXXXX'.
     APPEND it_test to tt_test.
  ENDIF.
ENDSELECT.

A pitfall: When you use it with ALV you will loose the field description. (on the other side, the field description of the original field will not fit any longer the new field.)

Community
  • 1
  • 1
knut
  • 27,320
  • 6
  • 84
  • 112