Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to add column based on existing columns to existing table without header line?

Romy_A_98
Explorer
0 Kudos
813

Good day!

I know this is an absolute beginner question, but I ca't find the right answer. I was playing around with some code and made a new table that has a new column based on two columns from an existing table. Now I want to take this new table and add another column to it based on two of its columns, one of them being a new column.
How do I best do this?
ChatGPT came up with some code but it's not working yet. So far i have this:

 

SELECT FROM /DMO/flight
    fields flight_date,
           seats_max,
           seats_occupied,
           seats_max - seats_occupied as seats_available,
           ( CAST( seats_occupied as FLTP ) / CAST( seats_max as FLTP ) ) * CAST( 100 as FLTP ) as percentage_occupied

    INTO TABLE @DATA(results).
 
"This is the part I'm stuck at and the part generated by CHATGPT. 
LOOP AT results ASSIGNING FIELD-SYMBOL(<line>).
  <line>-percentage_available = ( <line>-seats_available / <line>-seats_max  ) * 100 .
ENDLOOP. 

OUT->WRITE( EXPORTING
            data = results
            name = 'My_results' ).

 

 The problem is that I thought (and ChatGPT too I guess) that <line>-percentage_available would make a new column, but in the error it says that that column is unknown (and so that it should already be existing). Then I also tried something else, i don't remember what, and the error said you can't do it with a table without header lines. So do I need to somehow add header lines then? 

 

Thank you so much in advance!

6 REPLIES 6

Sandra_Rossi
Active Contributor
789

Look again at the name given in the error message, and the names you have in the code... 😉

0 Kudos
777

Ok I feel like I'm missing something here and I'm just being dense, but I genuinely don't see it😅. This is the specific error I get now (and i should have just copy pasted it here honestly):
The data object "<LINE>" does not have a component called "PERCENTAGE_AVAILABLE".
but I thought in my code it was making the 'percentage_available' component and adding things to that instead of looking for that component.

The seats_available name seems to be correct, as does seats_max, and the only name in the error is percentage_available which is (supposed to be) made at that moment. Honestly feels like I'm looking for a missing dot at this point and I'm sure once I see the mistake I'm gonna feel incredibly dumb, but I literally can't find it😅😂

743

Sandra_Rossi_0-1713881627935.png

 

0 Kudos
612

Aah thank you! That's what I thought but then I figured it couldnt be the case because I thought that '<line>-percentage_available =' meant that you were adding a new column to the table called 'percentage_available'. So then it would make sense that until now it didn't exist. But if it doesn't do that, what does it actually do? 

0 Kudos
604

The code is just incorrect, so "it does nothing". Why do you think it should do something?

0 Kudos
592

@Romy_A_98 wrote:

Aah thank you! That's what I thought but then I figured it couldnt be the case because I thought that '<line>-percentage_available =' meant that you were adding a new column to the table called 'percentage_available'. So then it would make sense that until now it didn't exist. But if it doesn't do that, what does it actually do? 


For the future tasks try ChatGPT 4 + Code Interpreter