Query SAP tables

hi,

I need to create an SQL query that is performed by my application on SAP tables.  

The tables are:    
LTBP - Transfer order Item
LTBK - Transfer order header


Here's the existing code:

The following code is the driver for bringing back the open TR’s for the specified material. The is the LTBP (item table):

  sWhere = "SELECT TBNUM, TBPOS, MATNR, CHARG, MENGA, TAMEA, ALTME FROM LTBP WHERE " & _
                sMaterialClause & sBatchClause & " AND " & _
                "LGNUM = '" & mobjUser.Warehouse & "' AND ELIKZ <> 'X'"


New pseudo code:

Add a join to the header table to include the movement types:  101 and 103.
The movement type is in the header table.

  sWhere = "SELECT TBNUM, TBPOS, MATNR, CHARG, MENGA, TAMEA, ALTME FROM LTBP WHERE " & _
                sMaterialClause & sBatchClause & " AND " & _
                "LGNUM = '" & mobjUser.Warehouse & "' AND ELIKZ <> 'X'"    
JOIN TO THE HEADER TABLE (LTBK) field BWLVS (movement type is 101 OR 103)
SmashAndGrabAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SmashAndGrabAuthor Commented:
I have been working on this today and have come up with this..

sWhere = "SELECT TBNUM, TBPOS, MATNR, CHARG, MENGA, TAMEA, ALTME FROM LTBP AS p JOIN LTBK AS k ON k.LGNUM = p.LGNUM and k.TBNUM = p.TBNUM WHERE  " & _
                sMaterialClause & sBatchClause & " AND " & _
                "p.LGNUM = '" & mobjUser.Warehouse & "' AND p.ELIKZ <> 'X'"  & _    
                  " AND ( k.BWLVS = '101' or  k.BWLVS = '103')"


however - it does not seem to be working at the moment.
SmashAndGrabAuthor Commented:
I think its on the right lines however.
SmashAndGrabAuthor Commented:
Screenshot of debugging..
SmashAndGrabAuthor Commented:
I had to use a different query as this join would not work.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.