As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
Options

Assistance with ABAP (SAP)

Bwah?Bwah? Registered User regular
edited January 2011 in Help / Advice Forum
I know it's a long shot to ask for help, but perhaps we have some SAP members in the forum?

Please note-I can describe the problem in further detail if needed.

My problem relates to querying data to create a report in SAP utilizing ABAP, however my prof has not even touched on the subject or attempted to explain how this would be achieved. Additionally we don't have a textbook of any kind.

Currently, I'm trying to create a report which lists several things (ex: order #, sales #, mat#,etc) from tables already present in SAP (VBAK,MARAV). The assignment requires I call certain fields within these tables (specifically material numbers for my materials). The problem with this is we have only learned how to select everything from a table..for example-
select * from VBAK.
WRITE / VBAK-VBELN.
ENDSELECT.
I've tried sql and similar languages, however I just don't know ABAP well enough to know what I'm doing.

I appreciate any thoughts or input..Hopefully.

MGSsig.jpg
Bwah? on

Posts

  • Options
    taliosfalcontaliosfalcon Registered User regular
    edited January 2011
    err..are you sure you're supposed to be doing this? it's just a pretty big jump from sleect * from wherever, write whatever to gathering data from multiple tables, and writing it with no documentation =0.

    i'd do it like

    TYPES: BEGIN OF vbak_data,
    d_vbakid LIKE vbak-part_id,
    *all other data types you want from the table goes in here*
    END OF vbak_data.


    DATA: itab_vbak_data TYPE STANDARD TABLE OF vbak_data,
    wa_vbak_data TYPE vbak_data.

    SELECT vbak~part-id
    INTO TABLE itab_vbak_data
    FROM vbak

    LOOP AT vbak_inventory_data INTO vbak_inventory_data.
    WRITE : / wa_vbak_data-d_vbakid.
    endloop.


    and of course you'd need to make a seperate new table (mine was wa_vbak_data) for each seperate SAP table you'd want to grab them from, and write them all out.
    This is the only way I know how to do it, but like I said it seems pretty complicated compared to what you've done so far so I might be over complicating things

    edit: you can also do joins on your select statements when selecting from multiple tables with
    SELECT vbak~part-id, vbak2~wookie
    INTO TABLE itab_vbak_data
    FROM vbak JOIN vbak2

    but it can get a bit tricky, looking at your examples you could try
    select vbak~order#, marav~sales#
    from vbak join marav
    on vbak~order# = marav~order#. (these will be like your sql primary/foreign key relationship)
    write: / vbak-order#.
    write:/marav-order#.

    not pulling them into an internal table first is something you'd never do in a real app, but for an assignment, why not

    taliosfalcon on
    steam xbox - adeptpenguin
  • Options
    Bwah?Bwah? Registered User regular
    edited January 2011
    Thank you for spending the time to type up that reply! I definitely appreciate it.

    And yes, that's what I am "suppose to be doing", welcome to the hell that is my professor.

    I can depict some things from your statements, however I'm not really familiar with the syntax. We've only recently been introduced to data types of integer and packed, additionally setting variables "like" eachother and "DATA" as a means of performing simple calculations (+ - / mod). With some work in databases. (se11 and the like)

    I'm not sure of the significance of the ~ in SAP, so I can't really begin to attempt utilization of it. Perhaps some insight could be given if I show you what I've got thus far.
    REPORT ZKMS_P2_SALESANDOTHERREPORTS.
    TABLES MARAV.
    Tables VBAK.
    WRITE 'Ord # '. write 'Item # '.
    Write 'Mat. # '. write 'Description'.
    uline.

    select * from VBAK.
    WRITE / VBAK-VBELN.
    ENDSELECT.

    With this being the output. However, I only need Sales Order #11.



    Regardless, thanks for your time thus far.

    Bwah? on
    MGSsig.jpg
  • Options
    taliosfalcontaliosfalcon Registered User regular
    edited January 2011
    Bwah? wrote: »
    Thank you for spending the time to type up that reply! I definitely appreciate it.

    And yes, that's what I am "suppose to be doing", welcome to the hell that is my professor.

    I can depict some things from your statements, however I'm not really familiar with the syntax. We've only recently been introduced to data types of integer and packed, additionally setting variables "like" eachother and "DATA" as a means of performing simple calculations (+ - / mod). With some work in databases. (se11 and the like)

    I'm not sure of the significance of the ~ in SAP, so I can't really begin to attempt utilization of it. Perhaps some insight could be given if I show you what I've got thus far.
    REPORT ZKMS_P2_SALESANDOTHERREPORTS.
    TABLES MARAV.
    Tables VBAK.
    WRITE 'Ord # '. write 'Item # '.
    Write 'Mat. # '. write 'Description'.
    uline.

    select * from VBAK.
    WRITE / VBAK-VBELN.
    ENDSELECT.

    With this being the output. However, I only need Sales Order #11.



    Regardless, thanks for your time thus far.
    ~ is just used to denote what rows of the table you're selecting for select statements instead of doing a * and grabbing everything. From your picture it looks like your write vbak-vbeln isn't writing anything? if that's true i'd check the database w/ the data explorer and make sure vbak-vbeln actually exists. that aside to just select sales order #11 you'd do

    select * from VBAK
    WHERE vbak-order#(i don't know what your order# column is actually named in vbak,so substitute it here)= '11'.

    to get things from two tables you'd go
    select *
    from vbak join marav
    on vbak~(whatever column is in both vbak and marav) join marav~(whatever column is in both vbak and marav)
    WHERE vbak-order#(i don't know what your order# column is actually named in vbak,so substitute it here)= '11'.
    WRITE / VBAK-VBELN.

    taliosfalcon on
    steam xbox - adeptpenguin
Sign In or Register to comment.